From 635ee1e85dd477e6dc02874dc7b03bcf060e0699 Mon Sep 17 00:00:00 2001 From: hmpthcs <106286734+hmpthcs@users.noreply.github.com> Date: Sun, 16 Apr 2023 03:17:19 -0400 Subject: [PATCH] drag_mode_test1 --- include/sway/config.h | 2 ++ sway/commands.c | 1 + sway/commands/drag_mode.c | 13 +++++++++++++ sway/config.c | 1 + sway/input/seatop_default.c | 11 ++++++----- sway/meson.build | 1 + 6 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 sway/commands/drag_mode.c diff --git a/include/sway/config.h b/include/sway/config.h index aa58da53..a16ddf57 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -537,6 +537,8 @@ struct sway_config { bool tiling_drag; int tiling_drag_threshold; + bool drag_mode; + enum smart_gaps_mode smart_gaps; int gaps_inner; struct side_gaps gaps_outer; diff --git a/sway/commands.c b/sway/commands.c index 55eda183..99f8b506 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -58,6 +58,7 @@ static const struct cmd_handler handlers[] = { { "client.urgent", cmd_client_urgent }, { "default_border", cmd_default_border }, { "default_floating_border", cmd_default_floating_border }, + { "drag_mode", cmd_drag_mode }, { "exec", cmd_exec }, { "exec_always", cmd_exec_always }, { "floating_maximum_size", cmd_floating_maximum_size }, diff --git a/sway/commands/drag_mode.c b/sway/commands/drag_mode.c new file mode 100644 index 00000000..9de9393f --- /dev/null +++ b/sway/commands/drag_mode.c @@ -0,0 +1,13 @@ +#include "sway/commands.h" +#include "util.h" + +struct cmd_results *cmd_drag_mode(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "drag_mode", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + config->drag_mode = parse_boolean(argv[0], config->drag_mode); + + return cmd_results_new(CMD_SUCCESS, NULL); +} \ No newline at end of file diff --git a/sway/config.c b/sway/config.c index 8c8c148d..c9d810ef 100644 --- a/sway/config.c +++ b/sway/config.c @@ -274,6 +274,7 @@ static void config_defaults(struct sway_config *config) { config->tiling_drag = true; config->tiling_drag_threshold = 9; config->primary_selection = true; + config->drag_mode = false; config->smart_gaps = SMART_GAPS_OFF; config->gaps_inner = 0; diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index 5a55c186..853b7da4 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -399,7 +399,8 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, // Handle tiling resize via mod bool mod_pressed = modifiers & config->floating_mod; - if (cont && !is_floating_or_child && mod_pressed && + bool drag_mode = config->drag_mode; + if (cont && !is_floating_or_child && (drag_mode || mod_pressed) && state == WLR_BUTTON_PRESSED) { uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT; @@ -451,7 +452,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, if (cont && is_floating_or_child && !is_fullscreen_or_child && state == WLR_BUTTON_PRESSED) { uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT; - if (button == btn_move && (mod_pressed || on_titlebar)) { + if (button == btn_move && (mod_pressed || on_titlebar || drag_mode)) { seatop_begin_move_floating(seat, container_toplevel_ancestor(cont)); return; } @@ -470,7 +471,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, // Via mod+click uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT; - if (mod_pressed && button == btn_resize) { + if ((mod_pressed || drag_mode) && button == btn_resize) { struct sway_container *floater = container_toplevel_ancestor(cont); edge = 0; edge |= cursor->cursor->x > floater->pending.x + floater->pending.width / 2 ? @@ -484,11 +485,11 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, } // Handle moving a tiling container - if (config->tiling_drag && (mod_pressed || on_titlebar) && + if (config->tiling_drag && (mod_pressed || on_titlebar || drag_mode) && state == WLR_BUTTON_PRESSED && !is_floating_or_child && cont && cont->pending.fullscreen_mode == FULLSCREEN_NONE) { // If moving a container by its title bar, use a threshold for the drag - if (!mod_pressed && config->tiling_drag_threshold > 0) { + if (!(mod_pressed || drag_mode) && config->tiling_drag_threshold > 0) { seatop_begin_move_tiling_threshold(seat, cont); } else { seatop_begin_move_tiling(seat, cont); diff --git a/sway/meson.build b/sway/meson.build index c6a27434..b362fd65 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -51,6 +51,7 @@ sway_sources = files( 'commands/default_border.c', 'commands/default_floating_border.c', 'commands/default_orientation.c', + 'commands/drag_mode.c', 'commands/exit.c', 'commands/exec.c', 'commands/exec_always.c',