Skip to content

Commit

Permalink
Add an option to specify the chain abortion keysym
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Jan 15, 2019
1 parent a58bec5 commit 0a8644a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
11 changes: 8 additions & 3 deletions doc/sxhkd.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: sxhkd
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 03/28/2018
.\" Date: 01/15/2019
.\" Manual: Sxhkd Manual
.\" Source: Sxhkd 0.5.9
.\" Source: Sxhkd 0.5.9-1-ga58bec5
.\" Language: English
.\"
.TH "SXHKD" "1" "03/28/2018" "Sxhkd 0\&.5\&.9" "Sxhkd Manual"
.TH "SXHKD" "1" "01/15/2019" "Sxhkd 0\&.5\&.9\-1\-ga58bec5" "Sxhkd Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -73,6 +73,11 @@ Redirect the commands output to the given file\&.
.RS 4
Output status information to the given FIFO\&.
.RE
.PP
\fB\-a\fR \fIABORT_KEYSYM\fR
.RS 4
Name of the keysym used for aborting chord chains\&.
.RE
.SH "BEHAVIOR"
.sp
\fBsxhkd\fR is a daemon that listens to keyboard events and execute commands\&.
Expand Down
3 changes: 3 additions & 0 deletions doc/sxhkd.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Options
*-s* _STATUS_FIFO_::
Output status information to the given FIFO.

*-a* _ABORT_KEYSYM_::
Name of the keysym used for aborting chord chains.


Behavior
--------
Expand Down
18 changes: 12 additions & 6 deletions src/sxhkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ int main(int argc, char *argv[])
timeout = TIMEOUT;
grabbed = false;
redir_fd = -1;
abort_keysym = ESCAPE_KEYSYM;

while ((opt = getopt(argc, argv, "hvm:t:c:r:s:")) != -1) {
while ((opt = getopt(argc, argv, "hvm:t:c:r:s:a:")) != -1) {
switch (opt) {
case 'v':
printf("%s\n", VERSION);
exit(EXIT_SUCCESS);
break;
case 'h':
printf("sxhkd [-h|-v|-m COUNT|-t TIMEOUT|-c CONFIG_FILE|-r REDIR_FILE|-s STATUS_FIFO] [EXTRA_CONFIG ...]\n");
printf("sxhkd [-h|-v|-m COUNT|-t TIMEOUT|-c CONFIG_FILE|-r REDIR_FILE|-s STATUS_FIFO|-a ABORT_KEYSYM] [EXTRA_CONFIG ...]\n");
exit(EXIT_SUCCESS);
break;
case 'm':
Expand All @@ -75,6 +76,11 @@ int main(int argc, char *argv[])
case 's':
fifo_path = optarg;
break;
case 'a':
if (!parse_keysym(optarg, &abort_keysym)) {
warn("Invalid keysym name: %s.\n", optarg);
}
break;
}
}

Expand Down Expand Up @@ -110,7 +116,7 @@ int main(int argc, char *argv[])
setup();
get_standard_keysyms();
get_lock_fields();
escape_chord = make_chord(ESCAPE_KEYSYM, XCB_NONE, 0, XCB_KEY_PRESS, false, false);
abort_chord = make_chord(abort_keysym, XCB_NONE, 0, XCB_KEY_PRESS, false, false);
load_config(config_file);
for (int i = 0; i < num_extra_confs; i++)
load_config(extra_confs[i]);
Expand Down Expand Up @@ -186,7 +192,7 @@ int main(int argc, char *argv[])

ungrab();
cleanup();
destroy_chord(escape_chord);
destroy_chord(abort_chord);
xcb_key_symbols_free(symbols);
xcb_disconnect(dpy);
return EXIT_SUCCESS;
Expand Down Expand Up @@ -236,10 +242,10 @@ void mapping_notify(xcb_generic_event_t *evt)
if (e->request == XCB_MAPPING_POINTER)
return;
if (xcb_refresh_keyboard_mapping(symbols, e) == 1) {
destroy_chord(escape_chord);
destroy_chord(abort_chord);
get_lock_fields();
reload_cmd();
escape_chord = make_chord(ESCAPE_KEYSYM, XCB_NONE, 0, XCB_KEY_PRESS, false, false);
abort_chord = make_chord(abort_keysym, XCB_NONE, 0, XCB_KEY_PRESS, false, false);
if (mapping_count > 0)
mapping_count--;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sxhkd.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ int timeout;

hotkey_t *hotkeys_head, *hotkeys_tail;
bool running, grabbed, toggle_grab, reload, bell, chained, locked;
chord_t *escape_chord;
xcb_keysym_t abort_keysym;
chord_t *abort_chord;

uint16_t num_lock;
uint16_t caps_lock;
Expand Down
4 changes: 2 additions & 2 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel
if (num_active > 0) {
chained = true;
put_status(BEGIN_CHAIN_PREFIX, "Begin chain");
grab_chord(escape_chord);
grab_chord(abort_chord);
}
} else if (num_active == 0 || match_chord(escape_chord, event_type, keysym, button, modfield)) {
} else if (num_active == 0 || match_chord(abort_chord, event_type, keysym, button, modfield)) {
abort_chain();
return find_hotkey(keysym, button, modfield, event_type, replay_event);
}
Expand Down

0 comments on commit 0a8644a

Please sign in to comment.