From ba735340dc79f6318aa0347add562e04e51f87b6 Mon Sep 17 00:00:00 2001 From: John Sullivan Date: Thu, 20 Aug 2020 15:53:22 -0700 Subject: [PATCH] Change orientation via sigqueue/SIGUSR1 --- lisgd.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lisgd.c b/lisgd.c index 5adfbfa..3dd0a4c 100644 --- a/lisgd.c +++ b/lisgd.c @@ -39,10 +39,12 @@ typedef struct { /* Globals */ Gesture *gestsarr; +Gesture *originalgestures; int gestsarrlen; Swipe pendingswipe; double xstart[MAXSLOTS], xend[MAXSLOTS], ystart[MAXSLOTS], yend[MAXSLOTS]; unsigned nfdown = 0, nfpendingswipe = 0; +unsigned orientationdirty = 0; struct timespec timedown; void @@ -141,6 +143,22 @@ swipereorient(Swipe swipe, int orientation) { return swipe; } +void +reorientgestures(int orientation) { + for (int i = 0; i < gestsarrlen; i++) + gestsarr[i].swipe = swipereorient(originalgestures[i].swipe, orientation); +} + +void +changeorientation(int _signal, siginfo_t *info, void *_none) { + int new_orientation = (info->si_value).sival_int; + + if (orientation != new_orientation) { + orientation = new_orientation; + orientationdirty = 1; + } +} + void touchdown(struct libinput_event *e) { @@ -212,6 +230,18 @@ touchup(struct libinput_event *e) } } +void +registerorientchange() { + struct sigaction action; + + action.sa_flags = SA_SIGINFO; + action.sa_sigaction = &changeorientation; + + if(sigaction(SIGUSR1, &action, NULL) == -1) { + die("Couldn't register reorient signal action."); + } +} + void run() { @@ -255,6 +285,10 @@ run() } else { libinput_dispatch(li); while ((event = libinput_get_event(li)) != NULL) { + if (orientationdirty) { + reorientgestures(orientation); + orientationdirty = 0; + } switch(libinput_event_get_type(event)) { case LIBINPUT_EVENT_TOUCH_DOWN: touchdown(event); break; case LIBINPUT_EVENT_TOUCH_UP: touchup(event); break; @@ -329,9 +363,15 @@ main(int argc, char *argv[]) memcpy(gestsarr, gestures, sizeof(gestures)); } - // Modify gestures swipes based on orientation provided - for (i = 0; i < gestsarrlen; i++) - gestsarr[i].swipe = swipereorient(gestsarr[i].swipe, orientation); + // Save original gestures for runtime orientation change + originalgestures = malloc(sizeof(Gesture) * gestsarrlen); + memcpy(originalgestures, gestsarr, sizeof(Gesture) * gestsarrlen); + + // Modify gestures swipes based on orientation provided + reorientgestures(orientation); + + // Change orientation at runtime (via SIGUSR1) + registerorientchange(); run(); return 0;