aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--examples/skhdrc6
-rw-r--r--src/hotkey.c13
-rw-r--r--src/hotkey.h1
-rw-r--r--src/parse.c18
-rw-r--r--src/tokenize.c2
-rw-r--r--src/tokenize.h2
7 files changed, 43 insertions, 6 deletions
diff --git a/README.md b/README.md
index b645b3b..a4ddf41 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,8 @@ keycode = 'apple keyboard kVK_<Key> values (0x3C)'
proc_map_lst = * <proc_map>
-proc_map = <string> ':' <command>
+proc_map = <string> ':' <command> | <string> ':' '~' |
+ '*' ':' <command> | '*' '~'
string = '"' 'sequence of characters' '"'
@@ -108,6 +109,10 @@ command = command is executed through '$SHELL -c' and
an EOL character signifies the end of the bind.
-> = keypress is not consumed by skhd
+
+* = matches every application not specified in <proc_map_lst>
+
+~ = application is unbound and keypress is forwarded per usual, when specified in a <proc_map>
```
A mode is declared according to the following rules:
diff --git a/examples/skhdrc b/examples/skhdrc
index 5336e71..e68433c 100644
--- a/examples/skhdrc
+++ b/examples/skhdrc
@@ -23,7 +23,8 @@
#
# proc_map_lst = * <proc_map>
#
-# proc_map = <string> ':' <command>
+# proc_map = <string> ':' <command> | <string> ':' '~' |
+# '*' ':' <command> | '*' '~'
#
# string = '"' 'sequence of characters' '"'
#
@@ -79,7 +80,9 @@
#
# cmd - n [
# "kitty" : echo "hello kitty"
+# * : echo "hello everyone"
# "qutebrowser" : echo "hello qutebrowser"
+# "terminal" ~
# "finder" : false
# ]
@@ -257,3 +260,4 @@ ctrl + alt - s : chunkc tiling::desktop --layout monocle
ctrl + alt - d : chunkc tiling::desktop --layout float
ctrl + alt - w : chunkc tiling::desktop --deserialize ~/.chunkwm_layouts/dev_1
+
diff --git a/src/hotkey.c b/src/hotkey.c
index 0c8b9f0..2f0df3a 100644
--- a/src/hotkey.c
+++ b/src/hotkey.c
@@ -145,14 +145,21 @@ should_capture_hotkey(uint32_t capture)
internal inline char *
find_process_command_mapping(struct hotkey *hotkey, uint32_t *capture, struct carbon_event *carbon)
{
+ char *result = NULL;
+ bool found = false;
+
for (int i = 0; i < buf_len(hotkey->process_name); ++i) {
if (same_string(carbon->process_name, hotkey->process_name[i])) {
- return hotkey->command[i];
+ result = hotkey->command[i];
+ found = true;
+ break;
}
}
- *capture &= ~HOTKEY_FOUND;
- return NULL;
+ if (!found) result = hotkey->wildcard_command;
+ if (!result) *capture &= ~HOTKEY_FOUND;
+
+ return result;
}
bool find_and_exec_hotkey(struct hotkey *k, struct table *t, struct mode **m, struct carbon_event *carbon)
diff --git a/src/hotkey.h b/src/hotkey.h
index 71d2e1d..641875d 100644
--- a/src/hotkey.h
+++ b/src/hotkey.h
@@ -73,6 +73,7 @@ struct hotkey
uint32_t key;
char **process_name;
char **command;
+ char *wildcard_command;
struct mode **mode_list;
};
diff --git a/src/parse.c b/src/parse.c
index a5760b7..760485d 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -92,8 +92,24 @@ parse_process_command_list(struct parser *parser, struct hotkey *hotkey)
if (parser_match(parser, Token_Command)) {
parse_command(parser, hotkey);
parse_process_command_list(parser, hotkey);
+ } else if (parser_match(parser, Token_Unbound)) {
+ buf_push(hotkey->command, NULL);
+ parse_process_command_list(parser, hotkey);
+ } else {
+ parser_report_error(parser, parser_peek(parser), "expected '~' or ':' followed by command\n");
+ }
+ } else if (parser_match(parser, Token_Wildcard)) {
+ if (parser_match(parser, Token_Command)) {
+ struct token command = parser_previous(parser);
+ char *result = copy_string_count(command.text, command.length);
+ debug("\tcmd: '%s'\n", result);
+ hotkey->wildcard_command = result;
+ parse_process_command_list(parser, hotkey);
+ } else if (parser_match(parser, Token_Unbound)) {
+ hotkey->wildcard_command = NULL;
+ parse_process_command_list(parser, hotkey);
} else {
- parser_report_error(parser, parser_peek(parser), "expected ':' followed by command\n");
+ parser_report_error(parser, parser_peek(parser), "expected '~' or ':' followed by command\n");
}
} else if (parser_match(parser, Token_EndList)) {
if (!buf_len(hotkey->process_name)) {
diff --git a/src/tokenize.c b/src/tokenize.c
index 8445a71..a0fd93d 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -146,6 +146,8 @@ get_token(struct tokenizer *tokenizer)
case ',': { token.type = Token_Comma; } break;
case '<': { token.type = Token_Insert; } break;
case '@': { token.type = Token_Capture; } break;
+ case '~': { token.type = Token_Unbound; } break;
+ case '*': { token.type = Token_Wildcard; } break;
case '[': { token.type = Token_BeginList; } break;
case ']': { token.type = Token_EndList; } break;
case '"': {
diff --git a/src/tokenize.h b/src/tokenize.h
index 73cdb30..ff82dee 100644
--- a/src/tokenize.h
+++ b/src/tokenize.h
@@ -49,6 +49,8 @@ enum token_type
Token_Dash,
Token_Arrow,
Token_Capture,
+ Token_Unbound,
+ Token_Wildcard,
Token_String,
Token_BeginList,