commit 8433918de3acf026a3c134a63af631e60d76837f
parent 4c272a59b2d388bb8d84f26294a2348dc5374a7f
Author: Bastien Dejean <nihilhill@gmail.com>
Date: Thu, 16 Jul 2015 22:00:44 +0200
Toggle input grabbing on SIGUSR2
Diffstat:
5 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/doc/sxhkd.1 b/doc/sxhkd.1
@@ -2,12 +2,12 @@
.\" Title: sxhkd
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\" Date: 05/17/2015
+.\" Date: 07/16/2015
.\" Manual: Sxhkd Manual
.\" Source: Sxhkd 0.5.5
.\" Language: English
.\"
-.TH "SXHKD" "1" "05/17/2015" "Sxhkd 0\&.5\&.5" "Sxhkd Manual"
+.TH "SXHKD" "1" "07/16/2015" "Sxhkd 0\&.5\&.5" "Sxhkd Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -96,7 +96,7 @@ It reads its configuration file from \fB$XDG_CONFIG_HOME/sxhkd/sxhkdrc\fR by def
.sp
Additional configuration files can be passed as arguments\&.
.sp
-If \fBsxhkd\fR receives a \fISIGUSR1\fR signal, it will reload its configuration file\&.
+If \fBsxhkd\fR receives a \fISIGUSR1\fR (resp\&. \fISIGUSR2\fR) signal, it will reload its configuration file (resp\&. toggle the grabbing state of all its bindings)\&.
.sp
The commands are executed via \fBSHELL\fR \fI\-c\fR \fBCOMMAND\fR (hence you can use environment variables)\&.
.sp
diff --git a/doc/sxhkd.1.txt b/doc/sxhkd.1.txt
@@ -63,7 +63,7 @@ It reads its configuration file from *$XDG_CONFIG_HOME/sxhkd/sxhkdrc* by default
Additional configuration files can be passed as arguments.
-If *sxhkd* receives a _SIGUSR1_ signal, it will reload its configuration file.
+If *sxhkd* receives a _SIGUSR1_ (resp. _SIGUSR2_) signal, it will reload its configuration file (resp. toggle the grabbing state of all its bindings).
The commands are executed via *SHELL* _-c_ *COMMAND* (hence you can use environment variables).
diff --git a/grab.c b/grab.c
@@ -28,8 +28,11 @@
void grab(void)
{
+ PUTS("grab");
for (hotkey_t *hk = hotkeys_head; hk != NULL; hk = hk->next)
grab_chord(hk->chain->head);
+ xcb_flush(dpy);
+ grabbed = true;
}
void grab_chord(chord_t *chord)
@@ -95,4 +98,6 @@ void ungrab(void)
PUTS("ungrab");
xcb_ungrab_key(dpy, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_ANY, root, XCB_MOD_MASK_ANY);
+ xcb_flush(dpy);
+ grabbed = false;
}
diff --git a/sxhkd.c b/sxhkd.c
@@ -46,6 +46,7 @@ int main(int argc, char *argv[])
config_path = NULL;
mapping_count = 0;
timeout = TIMEOUT;
+ grabbed = false;
sock_address.sun_family = AF_UNIX;
sock_address.sun_path[0] = 0;
snprintf(motion_msg_tpl, sizeof(motion_msg_tpl), "%s", MOTION_MSG_TPL);
@@ -140,6 +141,7 @@ int main(int argc, char *argv[])
signal(SIGHUP, hold);
signal(SIGTERM, hold);
signal(SIGUSR1, hold);
+ signal(SIGUSR2, hold);
signal(SIGALRM, hold);
setup();
@@ -156,7 +158,7 @@ int main(int argc, char *argv[])
fd_set descriptors;
- reload = bell = chained = locked = false;
+ reload = toggle_grab = bell = chained = locked = false;
running = true;
xcb_flush(dpy);
@@ -195,6 +197,12 @@ int main(int argc, char *argv[])
reload = false;
}
+ if (toggle_grab) {
+ signal(SIGUSR2, hold);
+ toggle_grab_cmd();
+ toggle_grab = false;
+ }
+
if (bell) {
signal(SIGALRM, hold);
abort_chain();
@@ -352,12 +360,24 @@ void reload_cmd(void)
grab();
}
+void toggle_grab_cmd(void)
+{
+ PUTS("toggle grab");
+ if (grabbed) {
+ ungrab();
+ } else {
+ grab();
+ }
+}
+
void hold(int sig)
{
if (sig == SIGHUP || sig == SIGINT || sig == SIGTERM)
running = false;
else if (sig == SIGUSR1)
reload = true;
+ else if (sig == SIGUSR2)
+ toggle_grab = true;
else if (sig == SIGALRM)
bell = true;
}
diff --git a/sxhkd.h b/sxhkd.h
@@ -64,7 +64,7 @@ double motion_interval;
xcb_timestamp_t last_motion_time;
hotkey_t *hotkeys_head, *hotkeys_tail;
-bool running, reload, bell, chained, locked;
+bool running, grabbed, toggle_grab, reload, bell, chained, locked;
chord_t *escape_chord;
uint16_t num_lock;
@@ -77,6 +77,7 @@ void mapping_notify(xcb_generic_event_t *evt);
void setup(void);
void cleanup(void);
void reload_cmd(void);
+void toggle_grab_cmd(void);
void hold(int sig);
void put_status(char c, const char *s);