diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2021-09-08 13:18:17 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2021-09-08 13:26:33 +0900 |
commit | 3e5dc71f01b5dcfae65b7b4dc0dfa43540cf975a (patch) | |
tree | f3bbd52aa4fddf4c7635bc03a20a013cc47442a6 | |
parent | 2bc4ef9a54e16c3f1be9ab3ba3ad32bd35eca9e1 (diff) | |
download | thotkeys-3e5dc71f01b5dcfae65b7b4dc0dfa43540cf975a.tar.gz |
Another benefit of using XI2 is that we're now allowed to monitor all
devices at the same time, not just a single device.
If --device option is not specified, it by default monitors all master
devices.
-rw-r--r-- | thotkeys.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -84,12 +84,15 @@ static XIDeviceInfo *get_device_info(Display *display, const char *name) static void prepare_monitor(Display *display, const char *device_name) { - XIDeviceInfo *info = get_device_info(display, device_name); - if (!info) - fatal("unable to find device '%s'\n", device_name); + XIDeviceInfo *info = NULL; + if (device_name) { + info = get_device_info(display, device_name); + if (!info) + fatal("unable to find device '%s'\n", device_name); + } XIEventMask mask; - mask.deviceid = info->deviceid; + mask.deviceid = info ? info->deviceid : XIAllMasterDevices; mask.mask_len = XIMaskLen(XI_LASTEVENT); mask.mask = xcalloc((size_t)mask.mask_len, 1); XISetMask(mask.mask, XI_RawKeyPress); @@ -132,9 +135,9 @@ static void command_help(void) fprintf(stderr, "Commands:\n"); fprintf(stderr, " thotkeys --help\n"); fprintf(stderr, " Show this message\n"); - fprintf(stderr, " thotkeys --device <device> --monitor\n"); + fprintf(stderr, " thotkeys [--device <device>] --monitor\n"); fprintf(stderr, " Print key press and release events to stdout\n"); - fprintf(stderr, " thotkeys --device <device> --hotkey --key <key> " \ + fprintf(stderr, " thotkeys [--device <device>] --hotkey --key <key> " \ "[--key <key>...] --on-press <on-press> [--hotkey ...]\n"); fprintf(stderr, " Run <on-press> when <key> is pressed down. " \ "SIGTERM will be sent to the process when the hotkey is\n" \ @@ -338,10 +341,6 @@ int main(int argc, char **argv) .on_press = on_press, }; } - if (do_monitor || do_hotkeys) { - if (!device_name) - fatal("--device option is required\n"); - } if (optind != argc) fatal("unknown argument %s\n", argv[optind]); |