1
0
mirror of https://git.sr.ht/~thestr4ng3r/chiaki synced 2025-03-12 05:25:23 -07:00

Minor Setsu Fixes

This commit is contained in:
Florian Märkl 2020-07-02 21:37:52 +02:00
parent 57b0b683e8
commit a688974c89
No known key found for this signature in database
GPG Key ID: 125BC8A5A6A1E857
3 changed files with 30 additions and 4 deletions
setsu
include
src
test

@ -20,6 +20,10 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct setsu_t Setsu;
typedef struct setsu_device_t SetsuDevice;
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_height(SetsuDevice *dev);
#ifdef __cplusplus
}
#endif
#endif

@ -116,11 +116,20 @@ Setsu *setsu_new()
void setsu_free(Setsu *setsu)
{
if(!setsu)
return;
while(setsu->dev)
setsu_disconnect(setsu, setsu->dev);
if(setsu->udev_mon)
udev_monitor_unref(setsu->udev_mon);
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);
}

@ -22,6 +22,7 @@
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
Setsu *setsu;
@ -38,12 +39,13 @@ struct {
bool dirty = false;
bool log_mode;
volatile bool should_quit;
#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()
@ -155,15 +157,22 @@ int main(int argc, const char *argv[])
printf("Failed to init setsu\n");
return 1;
}
struct sigaction sa = {0};
sa.sa_handler = sigint;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
dirty = true;
while(1)
while(!should_quit)
{
if(dirty && !log_mode)
print_state();
dirty = false;
setsu_poll(setsu, event, NULL);
}
atexit(quit);
setsu_free(setsu);
printf("\nさよなら!\n");
return 0;
}