mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Minor Setsu Fixes
This commit is contained in:
parent
57b0b683e8
commit
a688974c89
3 changed files with 30 additions and 4 deletions
|
@ -20,6 +20,10 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct setsu_t Setsu;
|
typedef struct setsu_t Setsu;
|
||||||
typedef struct setsu_device_t SetsuDevice;
|
typedef struct setsu_device_t SetsuDevice;
|
||||||
typedef int SetsuTrackingId;
|
typedef int SetsuTrackingId;
|
||||||
|
@ -75,4 +79,8 @@ const char *setsu_device_get_path(SetsuDevice *dev);
|
||||||
uint32_t setsu_device_get_width(SetsuDevice *dev);
|
uint32_t setsu_device_get_width(SetsuDevice *dev);
|
||||||
uint32_t setsu_device_get_height(SetsuDevice *dev);
|
uint32_t setsu_device_get_height(SetsuDevice *dev);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -116,11 +116,20 @@ Setsu *setsu_new()
|
||||||
|
|
||||||
void setsu_free(Setsu *setsu)
|
void setsu_free(Setsu *setsu)
|
||||||
{
|
{
|
||||||
|
if(!setsu)
|
||||||
|
return;
|
||||||
while(setsu->dev)
|
while(setsu->dev)
|
||||||
setsu_disconnect(setsu, setsu->dev);
|
setsu_disconnect(setsu, setsu->dev);
|
||||||
if(setsu->udev_mon)
|
if(setsu->udev_mon)
|
||||||
udev_monitor_unref(setsu->udev_mon);
|
udev_monitor_unref(setsu->udev_mon);
|
||||||
udev_unref(setsu->udev);
|
udev_unref(setsu->udev);
|
||||||
|
while(setsu->avail_dev)
|
||||||
|
{
|
||||||
|
SetsuAvailDevice *adev = setsu->avail_dev;
|
||||||
|
setsu->avail_dev = adev->next;
|
||||||
|
free(adev->path);
|
||||||
|
free(adev);
|
||||||
|
}
|
||||||
free(setsu);
|
free(setsu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
Setsu *setsu;
|
Setsu *setsu;
|
||||||
|
|
||||||
|
@ -38,12 +39,13 @@ struct {
|
||||||
|
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
bool log_mode;
|
bool log_mode;
|
||||||
|
volatile bool should_quit;
|
||||||
|
|
||||||
#define LOG(...) do { if(log_mode) fprintf(stderr, __VA_ARGS__); } while(0)
|
#define LOG(...) do { if(log_mode) fprintf(stderr, __VA_ARGS__); } while(0)
|
||||||
|
|
||||||
void quit()
|
void sigint(int s)
|
||||||
{
|
{
|
||||||
setsu_free(setsu);
|
should_quit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_state()
|
void print_state()
|
||||||
|
@ -155,15 +157,22 @@ int main(int argc, const char *argv[])
|
||||||
printf("Failed to init setsu\n");
|
printf("Failed to init setsu\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sigaction sa = {0};
|
||||||
|
sa.sa_handler = sigint;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
while(1)
|
while(!should_quit)
|
||||||
{
|
{
|
||||||
if(dirty && !log_mode)
|
if(dirty && !log_mode)
|
||||||
print_state();
|
print_state();
|
||||||
dirty = false;
|
dirty = false;
|
||||||
setsu_poll(setsu, event, NULL);
|
setsu_poll(setsu, event, NULL);
|
||||||
}
|
}
|
||||||
atexit(quit);
|
setsu_free(setsu);
|
||||||
|
printf("\nさよなら!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue