sxhkd-rc

[fork] simple X hotkey daemon (but for the rc shell)
Log | Files | Refs | README | LICENSE

commit 8787bec80f9ed5479e43e0723e8a821e98e1004c
parent 74e5454f0c45db4cdcce6c98f9ce95a6f4e9f1da
Author: Bastien Dejean <nihilhill@gmail.com>
Date:   Sat, 31 Dec 2016 15:55:30 +0100

Write to the status fifo when a chain begins/ends

Fixes #44.

Diffstat:
Mparse.c | 3++-
Msxhkd.c | 22++++++++++++++--------
Msxhkd.h | 18++++++++++--------
Mtypes.c | 4+++-
4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/parse.c b/parse.c @@ -2681,8 +2681,9 @@ bool parse_chain(char *string, chain_t *chain) event_type = key_to_button(event_type); chord_t *c = make_chord(keysym, button, modfield, event_type, replay_event, lock_chain); add_chord(chain, c); - if (status_fifo != NULL) + if (status_fifo != NULL) { snprintf(c->repr, sizeof(c->repr), "%s", chord); + } keysym = XCB_NO_SYMBOL; button = XCB_NONE; modfield = 0; diff --git a/sxhkd.c b/sxhkd.c @@ -93,10 +93,11 @@ int main(int argc, char *argv[]) if (fifo_path != NULL) { int fifo_fd = open(fifo_path, O_RDWR | O_NONBLOCK); - if (fifo_fd != -1) + if (fifo_fd != -1) { status_fifo = fdopen(fifo_fd, "w"); - else + } else { warn("Couldn't open status fifo.\n"); + } } signal(SIGINT, hold); @@ -164,9 +165,8 @@ int main(int argc, char *argv[]) if (bell) { signal(SIGALRM, hold); + put_status(TIMEOUT_PREFIX, "Timeout reached"); abort_chain(); - if (status_fifo != NULL) - put_status(TIMEOUT_PREFIX, "Timeout reached"); bell = false; } @@ -176,10 +176,14 @@ int main(int argc, char *argv[]) } } - if (redir_fd != -1) + if (redir_fd != -1) { close(redir_fd); - if (status_fifo != NULL) + } + + if (status_fifo != NULL) { fclose(status_fifo); + } + ungrab(); cleanup(); destroy_chord(escape_chord); @@ -201,8 +205,7 @@ void key_button_event(xcb_generic_event_t *evt, uint8_t event_type) hotkey_t *hk = find_hotkey(keysym, button, modfield, event_type, &replay_event); if (hk != NULL) { run(hk->command, hk->sync); - if (status_fifo != NULL) - put_status(COMMAND_PREFIX, hk->command); + put_status(COMMAND_PREFIX, hk->command); } } switch (event_type) { @@ -307,6 +310,9 @@ void hold(int sig) void put_status(char c, const char *s) { + if (status_fifo == NULL) { + return; + } fprintf(status_fifo, "%c%s\n", c, s); fflush(status_fifo); } diff --git a/sxhkd.h b/sxhkd.h @@ -31,14 +31,16 @@ #include "types.h" #include "helpers.h" -#define CONFIG_HOME_ENV "XDG_CONFIG_HOME" -#define SXHKD_SHELL_ENV "SXHKD_SHELL" -#define SHELL_ENV "SHELL" -#define CONFIG_PATH "sxhkd/sxhkdrc" -#define HOTKEY_PREFIX 'H' -#define COMMAND_PREFIX 'C' -#define TIMEOUT_PREFIX 'T' -#define TIMEOUT 3 +#define CONFIG_HOME_ENV "XDG_CONFIG_HOME" +#define SXHKD_SHELL_ENV "SXHKD_SHELL" +#define SHELL_ENV "SHELL" +#define CONFIG_PATH "sxhkd/sxhkdrc" +#define HOTKEY_PREFIX 'H' +#define COMMAND_PREFIX 'C' +#define BEGIN_CHAIN_PREFIX 'B' +#define END_CHAIN_PREFIX 'E' +#define TIMEOUT_PREFIX 'T' +#define TIMEOUT 3 xcb_connection_t *dpy; xcb_window_t root; diff --git a/types.c b/types.c @@ -44,7 +44,7 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel if (!chained) { snprintf(progress, sizeof(progress), "%s", c->state->repr); } else { - strncat(progress, LNK_SEP, sizeof(progress) - strlen(progress) - 1); + strncat(progress, ";", sizeof(progress) - strlen(progress) - 1); strncat(progress, c->state->repr, sizeof(progress) - strlen(progress) - 1); } put_status(HOTKEY_PREFIX, progress); @@ -86,6 +86,7 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel if (!chained) { if (num_active > 0) { chained = true; + put_status(BEGIN_CHAIN_PREFIX, "Begin chain"); grab_chord(escape_chord); } } else if (num_active == 0 || match_chord(escape_chord, event_type, keysym, button, modfield)) { @@ -218,6 +219,7 @@ void add_hotkey(hotkey_t *hk) void abort_chain(void) { PUTS("abort chain"); + put_status(END_CHAIN_PREFIX, "End chain"); for (hotkey_t *hk = hotkeys_head; hk != NULL; hk = hk->next) hk->chain->state = hk->chain->head; chained = false;