commit 41c46d12ca4558093ecbb961e29117ee03c297ae
parent dde1b8195300c5fe9c258f0c41d712ecf0f8d300
Author: Bastien Dejean <nihilhill@gmail.com>
Date: Sat, 5 Jan 2013 20:58:49 +0100
Ranges can be used in sequences
Diffstat:
4 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
@@ -34,7 +34,9 @@ The keysym names are those your will get from `xev` (minus the prefix if any).
Mouse hotkeys can be defined by using one of the following special keysym names: `button1`, `button2`, `button3`, ..., `button24`.
-`KEYSYM` can contain a sequence of the form `{STRING_1,STRING_2,...,STRING_N}`, in which case, `COMMAND` must also contain a sequence with *N* elements: the pairing of the two sequences generates *N* hotkeys.
+`KEYSYM` can contain a sequence of the form `{STRING_1,…,STRING_N}`, in which case, `COMMAND` must also contain a sequence with *N* elements: the pairing of the two sequences generates *N* hotkeys.
+
+In addition, the sequences can contain ranges of the form `A-Z` where *A* and *Z* are alphanumeric characters.
What is actually executed is `/bin/sh -c COMMAND`, which means you can use environment variables in `COMMAND`.
diff --git a/examples/sxhkdrc b/examples/sxhkdrc
@@ -1,14 +1,8 @@
-MonBrightnessDown
- backlight -1
+MonBrightness{Down,Up}
+ backlight {-1,+1}
-MonBrightnessUp
- backlight +1
-
-AudioPrev
- mpc -q prev
-
-AudioNext
- mpc -q next
+Audio{Prev,Next}
+ mpc -q {prev,next}
super + LaunchA
scrot
@@ -16,13 +10,16 @@ super + LaunchA
super + shift + @LaunchA
scrot -s
-super + shift + equal
- mosaic "$HOME/image"
-
button8
bspc toggle_visibility
+super + shift + equal
+ mosaic "$HOME/image"
+
super + {h,j,k,l}
bspc focus {left,down,up,right}
+super + alt + {0-9}
+ mpc -q seek {0-9}0%
+
# vim: set ft=conf:
diff --git a/keys.c b/keys.c
@@ -2576,15 +2576,35 @@ void unfold_hotkeys(char *folded_keysym, uint16_t modfield, xcb_event_mask_t eve
xcb_keysym_t keysym = XCB_NO_SYMBOL;
xcb_button_t button = XCB_NONE;
char *ks_ptr, *cmd_ptr;
- /* char ks_range_a = 0, ks_range_b = 0, cmd_range_a = 0, cmd_range_b = 0; */
+ char ks_a = 1, ks_z = 0, cmd_a = 1, cmd_z = 0;
+ char *ks_item = strtok_r(keysym_sequence, SEQ_SEP, &ks_ptr);
+ char *cmd_item = strtok_r(command_sequence, SEQ_SEP, &cmd_ptr);
- for (char *ks_item = strtok_r(keysym_sequence, SEQ_SEP, &ks_ptr), *cmd_item = strtok_r(command_sequence, SEQ_SEP, &cmd_ptr); ks_item != NULL && cmd_item != NULL; ks_item = strtok_r(NULL, SEQ_SEP, &ks_ptr), cmd_item = strtok_r(NULL, SEQ_SEP, &cmd_ptr)) {
- snprintf(unfolded_command, sizeof(unfolded_command), "%s%s%s", command_prefix, cmd_item, command_suffix);
- snprintf(unfolded_keysym, sizeof(unfolded_keysym), "%s%s%s", keysym_prefix, ks_item, keysym_suffix);
+ while ((ks_item != NULL || ks_a <= ks_z) && (cmd_item != NULL || cmd_a <= cmd_z)) {
+ if (ks_a > ks_z && sscanf(ks_item, "%c-%c", &ks_a, &ks_z) == 2 && ks_a >= ks_z)
+ ks_a = 1, ks_z = 0;
+ if (cmd_a > cmd_z && sscanf(cmd_item, "%c-%c", &cmd_a, &cmd_z) == 2 && cmd_a >= cmd_z)
+ cmd_a = 1, cmd_z = 0;
+ if (ks_a <= ks_z)
+ snprintf(unfolded_keysym, sizeof(unfolded_keysym), "%s%c%s", keysym_prefix, ks_a, keysym_suffix);
+ else
+ snprintf(unfolded_keysym, sizeof(unfolded_keysym), "%s%s%s", keysym_prefix, ks_item, keysym_suffix);
+ if (cmd_a <= cmd_z)
+ snprintf(unfolded_command, sizeof(unfolded_command), "%s%c%s", command_prefix, cmd_a, command_suffix);
+ else
+ snprintf(unfolded_command, sizeof(unfolded_command), "%s%s%s", command_prefix, cmd_item, command_suffix);
if (parse_key(unfolded_keysym, &keysym) || parse_button(unfolded_keysym, &button))
generate_hotkeys(keysym, button, modfield, event_mask, unfolded_command);
else
warn("Unknown sequence keysym: '%s'.\n", ks_item);
+ if (ks_a >= ks_z)
+ ks_item = strtok_r(NULL, SEQ_SEP, &ks_ptr), ks_a = 1, ks_z = 0;
+ else
+ ks_a++;
+ if (cmd_a >= cmd_z)
+ cmd_item = strtok_r(NULL, SEQ_SEP, &cmd_ptr), cmd_a = 1, cmd_z = 0;
+ else
+ cmd_a++;
}
}
diff --git a/sxhkd.1 b/sxhkd.1
@@ -54,6 +54,23 @@ The keysym names are those your will get from
Mouse hotkeys can be defined by using one of the following special keysym names:
.IR button1 ", " button2 ", " button3 ", ..., " button24 .
.PP
+.I KEYSYM
+can contain a sequence of the form
+.IR {STRING_1,…,STRING_N} ,
+in which case,
+.I COMMAND
+must also contain a sequence with
+.I N
+elements: the pairing of the two sequences generates
+.I N
+hotkeys.
+.PP
+In addition, the sequences can contain ranges of the form
+.I A-Z
+where
+.IR A " and " Z
+are alphanumeric characters.
+.PP
What is actually executed is
.IR "/bin/sh -c COMMAND" ,
which means you can use environment variables in