From 8a56b699ad0074fe16a60068020b51461e134558 Mon Sep 17 00:00:00 2001 From: Tuyen Pham Date: Wed, 7 Jul 2021 16:37:15 +0000 Subject: [PATCH] Do not VTs switch, block tty access --- include/sway/commands.h | 1 + include/sway/config.h | 1 + sway/commands.c | 1 + sway/commands/ttyaccess.c | 23 +++++++++++++++++++++++ sway/config.c | 1 + sway/input/keyboard.c | 12 ++++++++++-- sway/meson.build | 1 + sway/sway.5.scd | 3 +++ 8 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 sway/commands/ttyaccess.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 29a6bec3f..b972489ee 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -104,6 +104,7 @@ sway_cmd cmd_exec_validate; sway_cmd cmd_exec_process; sway_cmd cmd_assign; +sway_cmd cmd_ttyaccess; sway_cmd cmd_bar; sway_cmd cmd_bindcode; sway_cmd cmd_bindswitch; diff --git a/include/sway/config.h b/include/sway/config.h index b8327e9cc..a2ef0f317 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -506,6 +506,7 @@ struct sway_config { enum focus_follows_mouse_mode focus_follows_mouse; enum mouse_warping_mode mouse_warping; enum focus_wrapping_mode focus_wrapping; + bool ttyaccess; bool active; bool failed; bool reloading; diff --git a/sway/commands.c b/sway/commands.c index b09a04c71..fbc79e045 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -44,6 +44,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type /* Keep alphabetized */ static const struct cmd_handler handlers[] = { { "assign", cmd_assign }, + { "ttyaccess", cmd_ttyaccess }, { "bar", cmd_bar }, { "bindcode", cmd_bindcode }, { "bindswitch", cmd_bindswitch }, diff --git a/sway/commands/ttyaccess.c b/sway/commands/ttyaccess.c new file mode 100644 index 000000000..187a6fdb8 --- /dev/null +++ b/sway/commands/ttyaccess.c @@ -0,0 +1,23 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/arrange.h" +#include "sway/tree/view.h" +#include "sway/tree/container.h" +#include "log.h" +#include "stringop.h" +#include "util.h" + +struct cmd_results *cmd_no_titlebars(int argc, char **argv) { + struct cmd_results *error = checkarg(argc, "ttyaccess", EXPECTED_EQUAL_TO, 1); + + if (error) { + return error; + } + + config->ttyaccess = parse_boolean(argv[0], config->ttyaccess); + + arrange_root(); + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index 390138652..dcc7f718c 100644 --- a/sway/config.c +++ b/sway/config.c @@ -254,6 +254,7 @@ static void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = FOLLOWS_YES; + config->ttyaccess = false; config->mouse_warping = WARP_OUTPUT; config->focus_wrapping = WRAP_YES; config->validating = false; diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index f258ac7d5..fe10aa775 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -500,14 +500,22 @@ static void handle_key_event(struct sway_keyboard *keyboard, // Compositor bindings if (!handled && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (config->ttyaccess) { + return; + } else { handled = keyboard_execute_compositor_binding( keyboard, keyinfo.translated_keysyms, keyinfo.translated_modifiers, keyinfo.translated_keysyms_len); + } } if (!handled && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (config->ttyaccess) { + return; + } else { handled = keyboard_execute_compositor_binding( keyboard, keyinfo.raw_keysyms, keyinfo.raw_modifiers, keyinfo.raw_keysyms_len); + } } if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) { @@ -970,10 +978,10 @@ static void sway_keyboard_group_add(struct sway_keyboard *keyboard) { wl_signal_add(&sway_group->wlr_group->keyboard.events.modifiers, &sway_group->keyboard_modifiers); sway_group->keyboard_modifiers.notify = handle_keyboard_group_modifiers; - + wl_signal_add(&sway_group->wlr_group->events.enter, &sway_group->enter); sway_group->enter.notify = handle_keyboard_group_enter; - + wl_signal_add(&sway_group->wlr_group->events.leave, &sway_group->leave); sway_group->leave.notify = handle_keyboard_group_leave; return; diff --git a/sway/meson.build b/sway/meson.build index 1402db154..2ce5075f1 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -41,6 +41,7 @@ sway_sources = files( 'config/input.c', 'commands/assign.c', + 'commands/ttyaccess.c', 'commands/bar.c', 'commands/bind.c', 'commands/border.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 02592b5f1..88920462a 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -154,6 +154,9 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). is now. If no argument is given, it does the same as _toggle_. If _global_ is specified, the view will be fullscreen across all outputs. +*ttyaccess* enable|disable + Do not switch VTs, block tty access. + *gaps* inner|outer|horizontal|vertical|top|right|bottom|left all|current set|plus|minus Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the