aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/gsr-global-hotkeys/README.md27
-rw-r--r--tools/gsr-global-hotkeys/hotplug.c3
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.c208
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.h3
-rw-r--r--tools/gsr-global-hotkeys/keys.c21
-rw-r--r--tools/gsr-global-hotkeys/keys.h10
-rw-r--r--tools/gsr-global-hotkeys/main.c14
-rw-r--r--tools/gsr-ui-cli/main.c30
8 files changed, 259 insertions, 57 deletions
diff --git a/tools/gsr-global-hotkeys/README.md b/tools/gsr-global-hotkeys/README.md
new file mode 100644
index 0000000..38585c1
--- /dev/null
+++ b/tools/gsr-global-hotkeys/README.md
@@ -0,0 +1,27 @@
+# About
+Global hotkeys for X11 and all Wayland compositors by using linux device api. Keyboards are grabbed and only the non-hotkey keys are passed through to the system.
+The program accepts text commands as input. Run the program with the option `--virtual` to only grab virtual devices. This is useful when using keyboard input mapping software such as
+kanata, otherwise kanata may fail to launch or this program may fail to launch.
+# Commands
+## Bind
+To add a key send `bind <action> <keycode+keycode+...><newline>` to the programs stdin, for example:
+```
+bind show_hide 56+44
+
+```
+which will bind alt+z. When alt+z is pressed the program will output `show_hide` (and a newline) to stdout.
+The program only accepts one key for each keybind command but accepts a multiple modifier keys.
+The keybinding requires at least one modifier key (ctrl, alt, super or shift) and a key to be used.
+The keycodes are values from `<linux/input-event-codes.h>` linux api header (which is the same as X11 keycode value minus 8).
+## Unbind
+To unbind all keys send `unbind_all<newline>` to the programs stdin, for example:
+```
+unbind_all
+
+```
+## Exit
+To close gsr-global-hotkeys send `exit<newline>` to the programs stdin, for example:
+```
+exit
+
+``` \ No newline at end of file
diff --git a/tools/gsr-global-hotkeys/hotplug.c b/tools/gsr-global-hotkeys/hotplug.c
index 5ea2978..2e8ca9f 100644
--- a/tools/gsr-global-hotkeys/hotplug.c
+++ b/tools/gsr-global-hotkeys/hotplug.c
@@ -65,9 +65,10 @@ static void hotplug_event_parse_netlink_data(hotplug_event *self, const char *li
/* Netlink uevent structure is documented here: https://web.archive.org/web/20160127215232/https://www.kernel.org/doc/pending/hotplug.txt */
void hotplug_event_process_event_data(hotplug_event *self, int fd, hotplug_device_added_callback callback, void *userdata) {
- const int bytes_read = read(fd, self->event_data, sizeof(self->event_data));
+ const int bytes_read = read(fd, self->event_data, sizeof(self->event_data) - 1);
if(bytes_read <= 0)
return;
+ self->event_data[bytes_read] = '\0';
/* Hotplug data ends with a newline and a null terminator */
int data_index = 0;
diff --git a/tools/gsr-global-hotkeys/keyboard_event.c b/tools/gsr-global-hotkeys/keyboard_event.c
index b8d94fd..4ff7f11 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.c
+++ b/tools/gsr-global-hotkeys/keyboard_event.c
@@ -1,4 +1,5 @@
#include "keyboard_event.h"
+#include "keys.h"
/* C stdlib */
#include <stdio.h>
@@ -68,7 +69,7 @@ static void keyboard_event_fetch_update_key_states(keyboard_event *self, event_e
if(ioctl(fd, EVIOCGKEY(KEY_STATES_SIZE), extra_data->key_states) == -1)
fprintf(stderr, "Warning: failed to fetch key states for device: /dev/input/event%d\n", extra_data->dev_input_id);
- if(!keyboard_event_has_exclusive_grab(self) || extra_data->grabbed)
+ if(!keyboard_event_has_exclusive_grab(self) || extra_data->grabbed || extra_data->is_non_keyboard_device)
return;
extra_data->num_keys_pressed = keyboard_event_get_num_keys_pressed(extra_data->key_states);
@@ -81,19 +82,19 @@ static void keyboard_event_fetch_update_key_states(keyboard_event *self, event_e
}
}
-static void keyboard_event_process_key_state_change(keyboard_event *self, struct input_event event, event_extra_data *extra_data, int fd) {
- if(event.type != EV_KEY)
+static void keyboard_event_process_key_state_change(keyboard_event *self, const struct input_event *event, event_extra_data *extra_data, int fd) {
+ if(event->type != EV_KEY)
return;
- if(!extra_data->key_states || event.code >= KEY_STATES_SIZE * 8)
+ if(!extra_data->key_states || event->code >= KEY_STATES_SIZE * 8)
return;
- const unsigned int byte_index = event.code / 8;
- const unsigned char bit_index = event.code % 8;
+ const unsigned int byte_index = event->code / 8;
+ const unsigned char bit_index = event->code % 8;
unsigned char key_byte_state = extra_data->key_states[byte_index];
const bool prev_key_pressed = (key_byte_state & (1 << bit_index)) != KEY_RELEASE;
- if(event.value == KEY_RELEASE) {
+ if(event->value == KEY_RELEASE) {
key_byte_state &= ~(1 << bit_index);
if(prev_key_pressed)
--extra_data->num_keys_pressed;
@@ -105,7 +106,7 @@ static void keyboard_event_process_key_state_change(keyboard_event *self, struct
extra_data->key_states[byte_index] = key_byte_state;
- if(!keyboard_event_has_exclusive_grab(self) || extra_data->grabbed)
+ if(!keyboard_event_has_exclusive_grab(self) || extra_data->grabbed || extra_data->is_non_keyboard_device)
return;
if(extra_data->num_keys_pressed == 0) {
@@ -119,14 +120,13 @@ static void keyboard_event_process_key_state_change(keyboard_event *self, struct
/* Return true if a global hotkey is assigned to the key combination */
static bool keyboard_event_on_key_pressed(keyboard_event *self, const struct input_event *event, uint32_t modifiers) {
- if(event->value != KEYBOARD_BUTTON_PRESSED)
- return false;
-
bool global_hotkey_match = false;
for(int i = 0; i < self->num_global_hotkeys; ++i) {
if(event->code == self->global_hotkeys[i].key && modifiers == self->global_hotkeys[i].modifiers) {
- puts(self->global_hotkeys[i].action);
- fflush(stdout);
+ if(event->value == KEYBOARD_BUTTON_PRESSED) {
+ puts(self->global_hotkeys[i].action);
+ fflush(stdout);
+ }
global_hotkey_match = true;
}
}
@@ -154,6 +154,28 @@ static uint32_t keycode_to_modifier_bit(uint32_t keycode) {
return 0;
}
+/* Returns true if the state changed */
+static bool keyboard_event_set_key_presses_grabbed(const struct input_event *event, event_extra_data *extra_data) {
+ if(event->type != EV_KEY)
+ return false;
+
+ if(!extra_data->key_presses_grabbed || event->code >= KEY_STATES_SIZE * 8)
+ return false;
+
+ const unsigned int byte_index = event->code / 8;
+ const unsigned char bit_index = event->code % 8;
+ unsigned char key_byte_state = extra_data->key_presses_grabbed[byte_index];
+ const bool prev_key_pressed = (key_byte_state & (1 << bit_index)) != KEY_RELEASE;
+ extra_data->key_presses_grabbed[byte_index] = set_bit(key_byte_state, bit_index, event->value >= 1);
+
+ if(event->value == KEY_PRESS)
+ return !prev_key_pressed;
+ else if(event->value == KEY_RELEASE || event->value == KEY_REPEAT)
+ return prev_key_pressed;
+
+ return false;
+}
+
static void keyboard_event_process_input_event_data(keyboard_event *self, event_extra_data *extra_data, int fd) {
struct input_event event;
if(read(fd, &event, sizeof(event)) != sizeof(event)) {
@@ -171,12 +193,18 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
//fprintf(stderr, "fd: %d, type: %d, pressed %d, value: %d\n", fd, event.type, event.code, event.value);
//}
- if(event.type == EV_KEY) {
- keyboard_event_process_key_state_change(self, event, extra_data, fd);
+ const bool keyboard_key = is_keyboard_key(event.code);
+ if(event.type == EV_KEY && keyboard_key) {
+ keyboard_event_process_key_state_change(self, &event, extra_data, fd);
const uint32_t modifier_bit = keycode_to_modifier_bit(event.code);
if(modifier_bit == 0) {
- if(keyboard_event_on_key_pressed(self, &event, self->modifier_button_states))
- return;
+ if(keyboard_event_on_key_pressed(self, &event, self->modifier_button_states)) {
+ if(keyboard_event_set_key_presses_grabbed(&event, extra_data))
+ return;
+ } else if(event.value == KEY_RELEASE) {
+ if(keyboard_event_set_key_presses_grabbed(&event, extra_data))
+ return;
+ }
} else {
self->modifier_button_states = set_bit(self->modifier_button_states, modifier_bit, event.value >= 1);
}
@@ -187,6 +215,20 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
if(write(self->uinput_fd, &event, sizeof(event)) != sizeof(event))
fprintf(stderr, "Error: failed to write event data to virtual keyboard for exclusively grabbed device\n");
}
+
+ if(!extra_data->is_possibly_non_keyboard_device)
+ return;
+
+ /* TODO: What if some key is being pressed down while this is done? will it remain pressed down? */
+ if(!extra_data->is_non_keyboard_device && (event.type == EV_REL || event.type == EV_ABS || (event.type == EV_KEY && !keyboard_key))) {
+ fprintf(stderr, "Info: device /dev/input/event%d is likely a non-keyboard device as it received a non-keyboard event. This device will be ignored\n", extra_data->dev_input_id);
+ extra_data->is_non_keyboard_device = true;
+ if(extra_data->grabbed) {
+ extra_data->grabbed = false;
+ ioctl(fd, EVIOCGRAB, 0);
+ fprintf(stderr, "Info: ungrabbed device: /dev/input/event%d\n", extra_data->dev_input_id);
+ }
+ }
}
/* Retarded linux takes very long time to close /dev/input/eventN files, even though they are virtual and opened read-only */
@@ -265,12 +307,53 @@ static bool dev_input_is_virtual(int dev_input_id) {
return is_virtual;
}
+static inline bool supports_key(unsigned char *key_bits, unsigned int key) {
+ return key_bits[key/8] & (1 << (key % 8));
+}
+
+static bool supports_keyboard_keys(unsigned char *key_bits) {
+ const int keys[2] = { KEY_A, KEY_ESC };
+ for(int i = 0; i < 2; ++i) {
+ if(supports_key(key_bits, keys[i]))
+ return true;
+ }
+ return false;
+}
+
+static bool supports_mouse_keys(unsigned char *key_bits) {
+ const int keys[2] = { BTN_MOUSE, BTN_LEFT };
+ for(int i = 0; i < 2; ++i) {
+ if(supports_key(key_bits, keys[i]))
+ return true;
+ }
+ return false;
+}
+
+static bool supports_joystick_keys(unsigned char *key_bits) {
+ const int keys[9] = { BTN_JOYSTICK, BTN_A, BTN_B, BTN_X, BTN_Y, BTN_SELECT, BTN_START, BTN_SELECT, BTN_TRIGGER_HAPPY1 };
+ for(int i = 0; i < 9; ++i) {
+ if(supports_key(key_bits, keys[i]))
+ return true;
+ }
+ return false;
+}
+
+static bool supports_wheel_keys(unsigned char *key_bits) {
+ const int keys[2] = { BTN_WHEEL, BTN_GEAR_DOWN };
+ for(int i = 0; i < 2; ++i) {
+ if(supports_key(key_bits, keys[i]))
+ return true;
+ }
+ return false;
+}
+
static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, const char *dev_input_filepath) {
const int dev_input_id = get_dev_input_id_from_filepath(dev_input_filepath);
if(dev_input_id == -1)
return false;
- if(self->grab_type == KEYBOARD_GRAB_TYPE_VIRTUAL && !dev_input_is_virtual(dev_input_id))
+ const bool is_virtual_device = dev_input_is_virtual(dev_input_id);
+ if(self->grab_type == KEYBOARD_GRAB_TYPE_VIRTUAL && !is_virtual_device)
return false;
if(keyboard_event_has_event_with_dev_input_fd(self, dev_input_id))
@@ -286,20 +369,21 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
unsigned long evbit = 0;
ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), &evbit);
- const bool is_keyboard = evbit & (1 << EV_KEY);
+ const bool is_keyboard = (evbit & (1 << EV_SYN)) && (evbit & (1 << EV_KEY));
if(is_keyboard && strcmp(device_name, GSR_UI_VIRTUAL_KEYBOARD_NAME) != 0) {
unsigned char key_bits[KEY_MAX/8 + 1] = {0};
ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), &key_bits);
- const bool supports_key_events = key_bits[KEY_A/8] & (1 << (KEY_A % 8));
- const bool supports_mouse_events = key_bits[BTN_MOUSE/8] & (1 << (BTN_MOUSE % 8));
- //const bool supports_touch_events = key_bits[BTN_TOUCH/8] & (1 << (BTN_TOUCH % 8));
- const bool supports_joystick_events = key_bits[BTN_JOYSTICK/8] & (1 << (BTN_JOYSTICK % 8));
- const bool supports_wheel_events = key_bits[BTN_WHEEL/8] & (1 << (BTN_WHEEL % 8));
- if(supports_key_events && !supports_mouse_events && !supports_joystick_events && !supports_wheel_events) {
+ const bool supports_key_events = supports_keyboard_keys(key_bits);
+ const bool supports_mouse_events = supports_mouse_keys(key_bits);
+ const bool supports_joystick_events = supports_joystick_keys(key_bits);
+ const bool supports_wheel_events = supports_wheel_keys(key_bits);
+
+ if(supports_key_events && (is_virtual_device || (!supports_joystick_events && !supports_wheel_events))) {
unsigned char *key_states = calloc(1, KEY_STATES_SIZE);
- if(key_states && self->num_event_polls < MAX_EVENT_POLLS) {
+ unsigned char *key_presses_grabbed = calloc(1, KEY_STATES_SIZE);
+ if(key_states && key_presses_grabbed && self->num_event_polls < MAX_EVENT_POLLS) {
//fprintf(stderr, "%s (%s) supports key inputs\n", dev_input_filepath, device_name);
self->event_polls[self->num_event_polls] = (struct pollfd) {
.fd = fd,
@@ -311,17 +395,28 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
.dev_input_id = dev_input_id,
.grabbed = false,
.key_states = key_states,
+ .key_presses_grabbed = key_presses_grabbed,
.num_keys_pressed = 0
};
- keyboard_event_fetch_update_key_states(self, &self->event_extra_data[self->num_event_polls], fd);
- if(self->event_extra_data[self->num_event_polls].num_keys_pressed > 0)
- fprintf(stderr, "Info: device not grabbed yet because some keys are still being pressed: /dev/input/event%d\n", dev_input_id);
+ if(supports_mouse_events || supports_joystick_events || supports_wheel_events) {
+ self->event_extra_data[self->num_event_polls].is_possibly_non_keyboard_device = true;
+ fprintf(stderr, "Info: device not grabbed yet because it might be a mouse: /dev/input/event%d\n", dev_input_id);
+ fsync(fd);
+ if(ioctl(fd, EVIOCGKEY(KEY_STATES_SIZE), self->event_extra_data[self->num_event_polls].key_states) == -1)
+ fprintf(stderr, "Warning: failed to fetch key states for device: /dev/input/event%d\n", dev_input_id);
+ } else {
+ keyboard_event_fetch_update_key_states(self, &self->event_extra_data[self->num_event_polls], fd);
+ if(self->event_extra_data[self->num_event_polls].num_keys_pressed > 0)
+ fprintf(stderr, "Info: device not grabbed yet because some keys are still being pressed: /dev/input/event%d\n", dev_input_id);
+ }
++self->num_event_polls;
return true;
} else {
fprintf(stderr, "Warning: the maximum number of keyboard devices have been registered. The newly added keyboard will be ignored\n");
+ free(key_states);
+ free(key_presses_grabbed);
}
}
}
@@ -361,9 +456,12 @@ static void keyboard_event_remove_event(keyboard_event *self, int index) {
if(index < 0 || index >= self->num_event_polls)
return;
- ioctl(self->event_polls[index].fd, EVIOCGRAB, 0);
- close(self->event_polls[index].fd);
+ if(self->event_polls[index].fd > 0) {
+ ioctl(self->event_polls[index].fd, EVIOCGRAB, 0);
+ close(self->event_polls[index].fd);
+ }
free(self->event_extra_data[index].key_states);
+ free(self->event_extra_data[index].key_presses_grabbed);
for(int i = index + 1; i < self->num_event_polls; ++i) {
self->event_polls[i - 1] = self->event_polls[i];
@@ -389,14 +487,22 @@ static int setup_virtual_keyboard_input(const char *name) {
success &= (ioctl(fd, UI_SET_EVBIT, EV_SYN) != -1);
success &= (ioctl(fd, UI_SET_EVBIT, EV_MSC) != -1);
success &= (ioctl(fd, UI_SET_EVBIT, EV_KEY) != -1);
+ success &= (ioctl(fd, UI_SET_EVBIT, EV_REP) != -1);
+ success &= (ioctl(fd, UI_SET_EVBIT, EV_REL) != -1);
+ //success &= (ioctl(fd, UI_SET_EVBIT, EV_LED) != -1);
+
+ success &= (ioctl(fd, UI_SET_MSCBIT, MSC_SCAN) != -1);
for(int i = 1; i < KEY_MAX; ++i) {
- success &= (ioctl(fd, UI_SET_KEYBIT, i) != -1);
+ // TODO: Check for joystick button? if we accidentally grab joystick
+ if(is_keyboard_key(i) || is_mouse_button(i))
+ success &= (ioctl(fd, UI_SET_KEYBIT, i) != -1);
}
-
- success &= (ioctl(fd, UI_SET_EVBIT, EV_REL) != -1);
- success &= (ioctl(fd, UI_SET_RELBIT, REL_X) != -1);
- success &= (ioctl(fd, UI_SET_RELBIT, REL_Y) != -1);
- success &= (ioctl(fd, UI_SET_RELBIT, REL_Z) != -1);
+ for(int i = 0; i < REL_MAX; ++i) {
+ success &= (ioctl(fd, UI_SET_RELBIT, i) != -1);
+ }
+ // for(int i = 0; i < LED_MAX; ++i) {
+ // success &= (ioctl(fd, UI_SET_LEDBIT, i) != -1);
+ // }
// success &= (ioctl(fd, UI_SET_EVBIT, EV_ABS) != -1);
// success &= (ioctl(fd, UI_SET_ABSBIT, ABS_X) != -1);
@@ -461,6 +567,7 @@ bool keyboard_event_init(keyboard_event *self, bool exclusive_grab, keyboard_gra
.dev_input_id = -1,
.grabbed = false,
.key_states = NULL,
+ .key_presses_grabbed = NULL,
.num_keys_pressed = 0
};
@@ -478,6 +585,7 @@ bool keyboard_event_init(keyboard_event *self, bool exclusive_grab, keyboard_gra
.dev_input_id = -1,
.grabbed = false,
.key_states = NULL,
+ .key_presses_grabbed = NULL,
.num_keys_pressed = 0
};
@@ -507,14 +615,18 @@ void keyboard_event_deinit(keyboard_event *self) {
self->num_global_hotkeys = 0;
if(self->uinput_fd > 0) {
+ ioctl(self->uinput_fd, UI_DEV_DESTROY);
close(self->uinput_fd);
self->uinput_fd = -1;
}
for(int i = 0; i < self->num_event_polls; ++i) {
- ioctl(self->event_polls[i].fd, EVIOCGRAB, 0);
- close(self->event_polls[i].fd);
+ if(self->event_polls[i].fd > 0) {
+ ioctl(self->event_polls[i].fd, EVIOCGRAB, 0);
+ close(self->event_polls[i].fd);
+ }
free(self->event_extra_data[i].key_states);
+ free(self->event_extra_data[i].key_presses_grabbed);
}
self->num_event_polls = 0;
@@ -554,6 +666,13 @@ static int parse_u8(const char *str, int size) {
return result;
}
+static bool is_key_alpha_numerical(uint8_t key) {
+ return (key >= KEY_1 && key <= KEY_0)
+ || (key >= KEY_Q && key <= KEY_P)
+ || (key >= KEY_A && key <= KEY_L)
+ || (key >= KEY_Z && key <= KEY_M);
+}
+
static bool keyboard_event_parse_bind_keys(const char *str, int size, uint8_t *key, uint32_t *modifiers) {
*key = 0;
*modifiers = 0;
@@ -588,13 +707,13 @@ static bool keyboard_event_parse_bind_keys(const char *str, int size, uint8_t *k
break;
}
- if(key == 0) {
+ if(*key == 0) {
fprintf(stderr, "Error: can't bind hotkey without a non-modifier key\n");
return false;
}
- if(modifiers == 0) {
- fprintf(stderr, "Error: can't bind hotkey without a modifier\n");
+ if(*modifiers == 0 && is_key_alpha_numerical(*key)) {
+ fprintf(stderr, "Error: can't bind hotkey without a modifier unless the key is a non alpha-numerical key\n");
return false;
}
@@ -645,8 +764,11 @@ static void keyboard_event_parse_stdin_command(keyboard_event *self, const char
}
self->num_global_hotkeys = 0;
fprintf(stderr, "Info: unbinded all hotkeys\n");
+ } else if(strncmp(command, "exit", 4) == 0) {
+ self->stdin_failed = true;
+ fprintf(stderr, "Info: received exit command\n");
} else {
- fprintf(stderr, "Warning: got invalid command: \"%s\", expected command to start with either \"bind\" or \"unbind_all\"\n", command);
+ fprintf(stderr, "Warning: got invalid command: \"%s\", expected command to start with either \"bind\", \"unbind_all\" or \"exit\"\n", command);
}
}
diff --git a/tools/gsr-global-hotkeys/keyboard_event.h b/tools/gsr-global-hotkeys/keyboard_event.h
index a86b3dd..4a4c1fd 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.h
+++ b/tools/gsr-global-hotkeys/keyboard_event.h
@@ -39,7 +39,10 @@ typedef enum {
typedef struct {
int dev_input_id;
bool grabbed;
+ bool is_non_keyboard_device;
+ bool is_possibly_non_keyboard_device;
unsigned char *key_states;
+ unsigned char *key_presses_grabbed;
int num_keys_pressed;
} event_extra_data;
diff --git a/tools/gsr-global-hotkeys/keys.c b/tools/gsr-global-hotkeys/keys.c
new file mode 100644
index 0000000..3b8fc8a
--- /dev/null
+++ b/tools/gsr-global-hotkeys/keys.c
@@ -0,0 +1,21 @@
+#include "keys.h"
+#include <linux/input-event-codes.h>
+
+bool is_keyboard_key(uint32_t keycode) {
+ return (keycode >= KEY_ESC && keycode <= KEY_KPDOT)
+ || (keycode >= KEY_ZENKAKUHANKAKU && keycode <= KEY_F24)
+ || (keycode >= KEY_PLAYCD && keycode <= KEY_MICMUTE)
+ || (keycode >= KEY_OK && keycode <= KEY_IMAGES)
+ || (keycode >= KEY_DEL_EOL && keycode <= KEY_DEL_LINE)
+ || (keycode >= KEY_FN && keycode <= KEY_FN_B)
+ || (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT10)
+ || (keycode >= KEY_NUMERIC_0 && keycode <= KEY_LIGHTS_TOGGLE)
+ || (keycode == KEY_ALS_TOGGLE)
+ || (keycode >= KEY_BUTTONCONFIG && keycode <= KEY_VOICECOMMAND)
+ || (keycode >= KEY_BRIGHTNESS_MIN && keycode <= KEY_BRIGHTNESS_MAX)
+ || (keycode >= KEY_KBDINPUTASSIST_PREV && keycode <= KEY_ONSCREEN_KEYBOARD);
+}
+
+bool is_mouse_button(uint32_t keycode) {
+ return (keycode >= BTN_MOUSE && keycode <= BTN_TASK);
+}
diff --git a/tools/gsr-global-hotkeys/keys.h b/tools/gsr-global-hotkeys/keys.h
new file mode 100644
index 0000000..4f31882
--- /dev/null
+++ b/tools/gsr-global-hotkeys/keys.h
@@ -0,0 +1,10 @@
+#ifndef KEYS_H
+#define KEYS_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+bool is_keyboard_key(uint32_t keycode);
+bool is_mouse_button(uint32_t keycode);
+
+#endif /* KEYS_H */
diff --git a/tools/gsr-global-hotkeys/main.c b/tools/gsr-global-hotkeys/main.c
index 41e5ca5..c7e0403 100644
--- a/tools/gsr-global-hotkeys/main.c
+++ b/tools/gsr-global-hotkeys/main.c
@@ -44,42 +44,42 @@ int main(int argc, char **argv) {
} else if(strcmp(grab_type_arg, "--virtual") == 0) {
grab_type = KEYBOARD_GRAB_TYPE_VIRTUAL;
} else {
- fprintf(stderr, "Error: expected --all or --virtual, got %s\n", grab_type_arg);
+ fprintf(stderr, "gsr-global-hotkeys error: expected --all or --virtual, got %s\n", grab_type_arg);
usage();
return 1;
}
} else if(argc != 1) {
- fprintf(stderr, "Error: expected 0 or 1 arguments, got %d argument(s)\n", argc);
+ fprintf(stderr, "gsr-global-hotkeys error: expected 0 or 1 arguments, got %d argument(s)\n", argc);
usage();
return 1;
}
if(is_gsr_global_hotkeys_already_running()) {
- fprintf(stderr, "Error: gsr-global-hotkeys is already running\n");
+ fprintf(stderr, "gsr-global-hotkeys error: gsr-global-hotkeys is already running\n");
return 1;
}
const uid_t user_id = getuid();
if(geteuid() != 0) {
if(setuid(0) == -1) {
- fprintf(stderr, "Error: failed to change user to root\n");
+ fprintf(stderr, "gsr-global-hotkeys error: failed to change user to root, global hotkeys will not work. Make sure to set the correct capability on gsr-global-hotkeys\n");
return 1;
}
}
keyboard_event keyboard_ev;
if(!keyboard_event_init(&keyboard_ev, true, grab_type)) {
- fprintf(stderr, "Error: failed to setup hotplugging and no keyboard input devices were found\n");
+ fprintf(stderr, "gsr-global-hotkeys error: failed to setup hotplugging and no keyboard input devices were found\n");
setuid(user_id);
return 1;
}
- fprintf(stderr, "Info: global hotkeys setup, waiting for hotkeys to be pressed\n");
+ fprintf(stderr, "gsr-global-hotkeys info: global hotkeys setup, waiting for hotkeys to be pressed\n");
for(;;) {
keyboard_event_poll_events(&keyboard_ev, -1);
if(keyboard_event_stdin_has_failed(&keyboard_ev)) {
- fprintf(stderr, "Info: stdin closed (parent process likely closed this process), exiting...\n");
+ fprintf(stderr, "gsr-global-hotkeys info: stdin closed (parent process likely closed this process), exiting...\n");
break;
}
}
diff --git a/tools/gsr-ui-cli/main.c b/tools/gsr-ui-cli/main.c
index bcb5c81..feb5247 100644
--- a/tools/gsr-ui-cli/main.c
+++ b/tools/gsr-ui-cli/main.c
@@ -44,12 +44,26 @@ static void usage(void) {
printf("Run commands on the running gsr-ui instance.\n");
printf("\n");
printf("COMMANDS:\n");
- printf(" toggle-show Show/hide the UI.\n");
- printf(" toggle-record Start/stop recording.\n");
- printf(" toggle-pause Pause/unpause recording. Only applies to regular recording.\n");
- printf(" toggle-stream Start/stop streaming.\n");
- printf(" toggle-replay Start/stop replay.\n");
- printf(" replay-save Save replay.\n");
+ printf(" toggle-show\n");
+ printf(" Show/hide the UI.\n");
+ printf(" toggle-record\n");
+ printf(" Start/stop recording.\n");
+ printf(" toggle-pause\n");
+ printf(" Pause/unpause recording. Only applies to regular recording.\n");
+ printf(" toggle-stream\n");
+ printf(" Start/stop streaming.\n");
+ printf(" toggle-replay\n");
+ printf(" Start/stop replay.\n");
+ printf(" replay-save\n");
+ printf(" Save replay.\n");
+ printf(" replay-save-1-min\n");
+ printf(" Save 1 minute replay.\n");
+ printf(" replay-save-10-min\n");
+ printf(" Save 10 minute replay.\n");
+ printf(" take-screenshot\n");
+ printf(" Take a screenshot.\n");
+ printf(" take-screenshot-region\n");
+ printf(" Take a screenshot of a region.\n");
printf("\n");
printf("EXAMPLES:\n");
printf(" gsr-ui-cli toggle-show\n");
@@ -65,6 +79,10 @@ static bool is_valid_command(const char *command) {
"toggle-stream",
"toggle-replay",
"replay-save",
+ "replay-save-1-min",
+ "replay-save-10-min",
+ "take-screenshot",
+ "take-screenshot-region",
NULL
};