From dca02944ce91feae625e68d897d4caee025f7002 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Tue, 24 Jul 2018 18:41:08 -0400 Subject: [PATCH] Implement floating_modifier [inverse|normal] --- include/sway/config.h | 1 + sway/commands/floating_modifier.c | 12 +++++++++++- sway/config.c | 1 + sway/input/cursor.c | 8 +++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 032f4196..4a6bb780 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -320,6 +320,7 @@ struct sway_config { struct bar_config *current_bar; char *swaybg_command; uint32_t floating_mod; + bool floating_mod_inverse; uint32_t dragging_key; uint32_t resizing_key; char *floating_scroll_up_cmd; diff --git a/sway/commands/floating_modifier.c b/sway/commands/floating_modifier.c index 9432c9f1..f5d2b3fe 100644 --- a/sway/commands/floating_modifier.c +++ b/sway/commands/floating_modifier.c @@ -1,10 +1,11 @@ +#include "strings.h" #include "sway/commands.h" #include "sway/config.h" #include "util.h" struct cmd_results *cmd_floating_modifier(int argc, char **argv) { struct cmd_results *error = NULL; - if ((error = checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1))) { + if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { return error; } @@ -14,6 +15,15 @@ struct cmd_results *cmd_floating_modifier(int argc, char **argv) { "Invalid modifier"); } + if (argc == 1 || strcasecmp(argv[1], "normal") == 0) { + config->floating_mod_inverse = false; + } else if (strcasecmp(argv[1], "inverse") == 0) { + config->floating_mod_inverse = true; + } else { + return cmd_results_new(CMD_INVALID, "floating_modifier", + "Usage: floating_modifier [inverse|normal]"); + } + config->floating_mod = mod; return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/config.c b/sway/config.c index 90dfb9a9..2afffab1 100644 --- a/sway/config.c +++ b/sway/config.c @@ -180,6 +180,7 @@ static void config_defaults(struct sway_config *config) { list_add(config->modes, config->current_mode); config->floating_mod = 0; + config->floating_mod_inverse = false; config->dragging_key = BTN_LEFT; config->resizing_key = BTN_RIGHT; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 27597640..9eb11de1 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -449,15 +449,17 @@ static void dispatch_cursor_button_floating(struct sway_cursor *cursor, bool over_title = edge == WLR_EDGE_NONE && !surface; // Check for beginning move - if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED && + uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT; + if (button == btn_move && state == WLR_BUTTON_PRESSED && (mod_pressed || over_title)) { - seat_begin_move(seat, cont, BTN_LEFT); + seat_begin_move(seat, cont, btn_move); return; } // Check for beginning resize bool resizing_via_border = button == BTN_LEFT && edge != WLR_EDGE_NONE; - bool resizing_via_mod = button == BTN_RIGHT && mod_pressed; + uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT; + bool resizing_via_mod = button == btn_resize && mod_pressed; if ((resizing_via_border || resizing_via_mod) && state == WLR_BUTTON_PRESSED) { if (edge == WLR_EDGE_NONE) {