aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/seat
diff options
context:
space:
mode:
authorMichael Weiser <michael.weiser@gmx.de>2020-02-16 00:40:18 +0100
committerBrian Ashworth <bosrsf04@gmail.com>2020-03-11 23:51:37 -0400
commit3ee5aace33f1b5673ab372afba38480338ba8b90 (patch)
treea91724f17a916a6075c71f555968fa046973fddd /sway/commands/seat
parenteeac0aa170d4ee19111df072ea361b56c802cf34 (diff)
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/seat')
-rw-r--r--sway/commands/seat/shortcuts_inhibitor.c96
1 files changed, 96 insertions, 0 deletions
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 @@
+#include "log.h"
+#include "sway/commands.h"
+#include "sway/input/seat.h"
+#include "sway/input/input-manager.h"
+#include "util.h"
+
+static struct cmd_results *handle_action(struct seat_config *sc,
+ struct sway_seat *seat, const char *action) {
+ struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor = NULL;
+ if (strcmp(action, "disable") == 0) {
+ sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_DISABLE;
+
+ wl_list_for_each(sway_inhibitor,
+ &seat->keyboard_shortcuts_inhibitors, link) {
+ wlr_keyboard_shortcuts_inhibitor_v1_deactivate(
+ sway_inhibitor->inhibitor);
+ }
+
+ sway_log(SWAY_DEBUG, "Deactivated all keyboard shortcuts inhibitors");
+ } else {
+ sway_inhibitor = keyboard_shortcuts_inhibitor_get_for_focused_surface(seat);
+ if (!sway_inhibitor) {
+ return cmd_results_new(CMD_FAILURE,
+ "No inhibitor found for focused surface");
+ }
+
+ struct wlr_keyboard_shortcuts_inhibitor_v1 *inhibitor =
+ sway_inhibitor->inhibitor;
+ bool inhibit;
+ if (strcmp(action, "activate") == 0) {
+ inhibit = true;
+ } else if (strcmp(action, "deactivate") == 0) {
+ inhibit = false;
+ } else if (strcmp(action, "toggle") == 0) {
+ inhibit = !inhibitor->active;
+ } else {
+ return cmd_results_new(CMD_INVALID, "Expected enable|"
+ "disable|activate|deactivate|toggle");
+ }
+
+ if (inhibit) {
+ wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor);
+ } else {
+ wlr_keyboard_shortcuts_inhibitor_v1_deactivate(inhibitor);
+ }
+
+ sway_log(SWAY_DEBUG, "%sctivated keyboard shortcuts inhibitor",
+ inhibit ? "A" : "Dea");
+ }
+
+ return cmd_results_new(CMD_SUCCESS, NULL);
+}
+
+// shortcuts_inhibitor [enable|disable|activate|deactivate|toggle]
+struct cmd_results *seat_cmd_shortcuts_inhibitor(int argc, char **argv) {
+ struct cmd_results *error =
+ checkarg(argc, "shortcuts_inhibitor", EXPECTED_EQUAL_TO, 1);
+ if (error) {
+ return error;
+ }
+
+ struct seat_config *sc = config->handler_context.seat_config;
+ if (!sc) {
+ return cmd_results_new(CMD_FAILURE, "No seat defined");
+ }
+
+ if (strcmp(argv[0], "enable") == 0) {
+ sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE;
+ // at runtime disable is an action that also deactivates all active
+ // inhibitors handled in handle_action()
+ } else if (strcmp(argv[0], "disable") == 0 && !config->active) {
+ sc->shortcuts_inhibit = SHORTCUTS_INHIBIT_DISABLE;
+ } else if (!config->active) {
+ return cmd_results_new(CMD_INVALID, "only enable and disable "
+ "can be used in the config");
+ } else {
+ if (strcmp(sc->name, "*") != 0) {
+ struct sway_seat *seat = input_manager_get_seat(sc->name, false);
+ if (!seat) {
+ return cmd_results_new(CMD_FAILURE,
+ "Seat %s does not exist", sc->name);
+ }
+ error = handle_action(sc, seat, argv[0]);
+ } else {
+ struct sway_seat *seat = NULL;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ error = handle_action(sc, seat, argv[0]);
+ if (error && error->status != CMD_SUCCESS) {
+ break;
+ }
+ }
+ }
+ }
+
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL);
+}