aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Michael Weiser <michael.weiser@gmx.de>2020-02-16 00:40:18 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-03-11 23:51:37 -0400
commit3ee5aace33f1b5673ab372afba38480338ba8b90 (patch)
treea91724f17a916a6075c71f555968fa046973fddd /sway/commands
parentinput: Add support for keyboard shortcuts inhibit (diff)
downloadsway-3ee5aace33f1b5673ab372afba38480338ba8b90.tar.gz
sway-3ee5aace33f1b5673ab372afba38480338ba8b90.tar.zst
sway-3ee5aace33f1b5673ab372afba38480338ba8b90.zip
commands: Add shortcuts_inhibitor command
Add a command to influence keyboard shortcuts inhibitors. In its current form it can be used to activate, deactivate or toggle an existing inhibitor on the surface currently receiving input. This can be used to define an escape shortcut such as: bindsym --inhibited $mod+Escape seat - shortcuts_inhibitor deactivate It also allows the user to configure a per-seat default of whether keyboard inhibitors are honoured by default (the default) or not. Using the activate/toggle command they can then enable the lingering inhibitor at a later time of their choosing. As a side effect this allows to specifically address a named seat for actions as well, whatever use-case that might serve. Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/seat.c1
-rw-r--r--sway/commands/seat/shortcuts_inhibitor.c96
2 files changed, 97 insertions, 0 deletions
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index eba28cac..84c6ba53 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -22,6 +22,7 @@ static struct cmd_handler seat_handlers[] = {
22 { "idle_wake", seat_cmd_idle_wake }, 22 { "idle_wake", seat_cmd_idle_wake },
23 { "keyboard_grouping", seat_cmd_keyboard_grouping }, 23 { "keyboard_grouping", seat_cmd_keyboard_grouping },
24 { "pointer_constraint", seat_cmd_pointer_constraint }, 24 { "pointer_constraint", seat_cmd_pointer_constraint },
25 { "shortcuts_inhibitor", seat_cmd_shortcuts_inhibitor },
25 { "xcursor_theme", seat_cmd_xcursor_theme }, 26 { "xcursor_theme", seat_cmd_xcursor_theme },
26}; 27};
27 28
diff --git a/sway/commands/seat/shortcuts_inhibitor.c b/sway/commands/seat/shortcuts_inhibitor.c
new file mode 100644
index 00000000..7c7f99cf
--- /dev/null
+++ b/sway/commands/seat/shortcuts_inhibitor.c
@@ -0,0 +1,96 @@
1#include "log.h"
2#include "sway/commands.h"
3#include "sway/input/seat.h"
4#include "sway/input/input-manager.h"
5#include "util.h"
6
7static struct cmd_results *handle_action(struct seat_config *sc,
8 struct sway_seat *seat, const char *action) {
9 struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor = NULL;
10 if (strcmp(action, "disable") == 0) {
11 sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_DISABLE;
12
13 wl_list_for_each(sway_inhibitor,
14 &seat->keyboard_shortcuts_inhibitors, link) {
15 wlr_keyboard_shortcuts_inhibitor_v1_deactivate(
16 sway_inhibitor->inhibitor);
17 }
18
19 sway_log(SWAY_DEBUG, "Deactivated all keyboard shortcuts inhibitors");
20 } else {
21 sway_inhibitor = keyboard_shortcuts_inhibitor_get_for_focused_surface(seat);
22 if (!sway_inhibitor) {
23 return cmd_results_new(CMD_FAILURE,
24 "No inhibitor found for focused surface");
25 }
26
27 struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor =
28 sway_inhibitor->inhibitor;
29 bool inhibit;
30 if (strcmp(action, "activate") == 0) {
31 inhibit = true;
32 } else if (strcmp(action, "deactivate") == 0) {
33 inhibit = false;
34 } else if (strcmp(action, "toggle") == 0) {
35 inhibit = !inhibitor->active;
36 } else {
37 return cmd_results_new(CMD_INVALID, "Expected enable|"
38 "disable|activate|deactivate|toggle");
39 }
40
41 if (inhibit) {
42 wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor);
43 } else {
44 wlr_keyboard_shortcuts_inhibitor_v1_deactivate(inhibitor);
45 }
46
47 sway_log(SWAY_DEBUG, "%sctivated keyboard shortcuts inhibitor",
48 inhibit ? "A" : "Dea");
49 }
50
51 return cmd_results_new(CMD_SUCCESS, NULL);
52}
53
54// shortcuts_inhibitor [enable|disable|activate|deactivate|toggle]
55struct cmd_results *seat_cmd_shortcuts_inhibitor(int argc, char **argv) {
56 struct cmd_results *error =
57 checkarg(argc, "shortcuts_inhibitor", EXPECTED_EQUAL_TO, 1);
58 if (error) {
59 return error;
60 }
61
62 struct seat_config *sc = config->handler_context.seat_config;
63 if (!sc) {
64 return cmd_results_new(CMD_FAILURE, "No seat defined");
65 }
66
67 if (strcmp(argv[0], "enable") == 0) {
68 sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE;
69 // at runtime disable is an action that also deactivates all active
70 // inhibitors handled in handle_action()
71 } else if (strcmp(argv[0], "disable") == 0 && !config->active) {
72 sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_DISABLE;
73 } else if (!config->active) {
74 return cmd_results_new(CMD_INVALID, "only enable and disable "
75 "can be used in the config");
76 } else {
77 if (strcmp(sc->name, "*") != 0) {
78 struct sway_seat *seat = input_manager_get_seat(sc->name, false);
79 if (!seat) {
80 return cmd_results_new(CMD_FAILURE,
81 "Seat %s does not exist", sc->name);
82 }
83 error = handle_action(sc, seat, argv[0]);
84 } else {
85 struct sway_seat *seat = NULL;
86 wl_list_for_each(seat, &server.input->seats, link) {
87 error = handle_action(sc, seat, argv[0]);
88 if (error && error->status != CMD_SUCCESS) {
89 break;
90 }
91 }
92 }
93 }
94
95 return error ? error : cmd_results_new(CMD_SUCCESS, NULL);
96}