mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-03-13 02:42:47 +01:00
main.c: add a real-time signal for toggling visibility of the keyboard
Previously it was only possible to either show or hide the keyboard. When you want to control the keyboard with a single button in, i.e. a window manager, this requires a separate script to keep track of state. This solves this by only needing one signal to toggle. Since there are only 2 USR signals, I had to use real-time signals, which are in the [POSIX standard](https://standards.ieee.org/standard/1003_1b-1993.html) and available in the [Linux kernel since 2.2](https://www.man7.org/linux/man-pages/man7/signal.7.html).
This commit is contained in:
parent
07b9f293c0
commit
e6c7d0ff2a
23
main.c
23
main.c
@ -45,6 +45,7 @@ static int cur_x = -1, cur_y = -1;
|
|||||||
static bool cur_press = false;
|
static bool cur_press = false;
|
||||||
static struct kbd keyboard;
|
static struct kbd keyboard;
|
||||||
static uint32_t height, normal_height, landscape_height;
|
static uint32_t height, normal_height, landscape_height;
|
||||||
|
static bool hidden = false;
|
||||||
|
|
||||||
/* event handler prototypes */
|
/* event handler prototypes */
|
||||||
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
||||||
@ -370,6 +371,8 @@ hide(int sigint) {
|
|||||||
wl_callback_destroy(draw_surf.cb);
|
wl_callback_destroy(draw_surf.cb);
|
||||||
draw_surf.cb = NULL;
|
draw_surf.cb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -396,6 +399,19 @@ show(int sigint) {
|
|||||||
|
|
||||||
wl_display_roundtrip(display);
|
wl_display_roundtrip(display);
|
||||||
drwsurf_flip(&draw_surf);
|
drwsurf_flip(&draw_surf);
|
||||||
|
|
||||||
|
hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
toggle_visibility(int sigint) {
|
||||||
|
signal(SIGRTMIN, toggle_visibility);
|
||||||
|
|
||||||
|
if (hidden) {
|
||||||
|
show(sigint);
|
||||||
|
} else {
|
||||||
|
hide(sigint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -427,8 +443,6 @@ main(int argc, char **argv) {
|
|||||||
keyboard.scheme1 = scheme1;
|
keyboard.scheme1 = scheme1;
|
||||||
keyboard.scheme1 = scheme1;
|
keyboard.scheme1 = scheme1;
|
||||||
|
|
||||||
bool starthidden = false;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; argv[i]; i++) {
|
for (i = 1; argv[i]; i++) {
|
||||||
if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--version"))) {
|
if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--version"))) {
|
||||||
@ -467,7 +481,7 @@ main(int argc, char **argv) {
|
|||||||
keyboard.print_intersect = true;
|
keyboard.print_intersect = true;
|
||||||
} else if ((!strcmp(argv[i], "-hidden")) ||
|
} else if ((!strcmp(argv[i], "-hidden")) ||
|
||||||
(!strcmp(argv[i], "--hidden"))) {
|
(!strcmp(argv[i], "--hidden"))) {
|
||||||
starthidden = true;
|
hidden = true;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
|
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
@ -515,7 +529,7 @@ main(int argc, char **argv) {
|
|||||||
draw_ctx.font_description =
|
draw_ctx.font_description =
|
||||||
pango_font_description_from_string(fc_font_pattern);
|
pango_font_description_from_string(fc_font_pattern);
|
||||||
|
|
||||||
if (!starthidden) {
|
if (!hidden) {
|
||||||
draw_surf.surf = wl_compositor_create_surface(compositor);
|
draw_surf.surf = wl_compositor_create_surface(compositor);
|
||||||
|
|
||||||
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
@ -536,6 +550,7 @@ main(int argc, char **argv) {
|
|||||||
signal(SIGUSR1, hide);
|
signal(SIGUSR1, hide);
|
||||||
signal(SIGUSR2, show);
|
signal(SIGUSR2, show);
|
||||||
signal(SIGPIPE, pipewarn);
|
signal(SIGPIPE, pipewarn);
|
||||||
|
signal(SIGRTMIN, toggle_visibility);
|
||||||
|
|
||||||
while (run_display) {
|
while (run_display) {
|
||||||
while (wl_display_dispatch(display) != -1 && layer_surface) {
|
while (wl_display_dispatch(display) != -1 && layer_surface) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user