From 10adccfa024e7de40d8821bb892a3bd38eb2c7a1 Mon Sep 17 00:00:00 2001
From: Philipp Jungkamp
Date: Thu, 1 Jul 2021 16:20:17 +0200
Subject: [PATCH] add drag_mode command to move/resize window without
floating_modifier
---
include/sway/commands.h | 1 +
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 +
7 files changed, 25 insertions(+), 5 deletions(-)
create mode 100644 sway/commands/drag_mode.c
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 29a6bec3f..fb2bd35f6 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -121,6 +121,7 @@ sway_cmd cmd_create_output;
sway_cmd cmd_default_border;
sway_cmd cmd_default_floating_border;
sway_cmd cmd_default_orientation;
+sway_cmd cmd_drag_mode;
sway_cmd cmd_exec;
sway_cmd cmd_exec_always;
sway_cmd cmd_exit;
diff --git a/include/sway/config.h b/include/sway/config.h
index 254fbad00..1f373e288 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -518,6 +518,8 @@ struct sway_config {
bool tiling_drag;
int tiling_drag_threshold;
+ bool drag_mode;
+
bool smart_gaps;
int gaps_inner;
struct side_gaps gaps_outer;
diff --git a/sway/commands.c b/sway/commands.c
index b09a04c71..286ffac56 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -56,6 +56,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 000000000..dc035a50a
--- /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);
+}
diff --git a/sway/config.c b/sway/config.c
index 390138652..ec85146ce 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -266,6 +266,7 @@ static void config_defaults(struct sway_config *config) {
config->title_align = ALIGN_LEFT;
config->tiling_drag = true;
config->tiling_drag_threshold = 9;
+ config->drag_mode = false;
config->smart_gaps = false;
config->gaps_inner = 0;
diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c
index f9eb8c8ad..59953f848 100644
--- a/sway/input/seatop_default.c
+++ b/sway/input/seatop_default.c
@@ -396,7 +396,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;
@@ -428,7 +429,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)) {
seat_set_focus_container(seat,
seat_get_focus_inactive_view(seat, &cont->node));
seatop_begin_move_floating(seat, container_toplevel_ancestor(cont));
@@ -448,7 +449,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 ?
@@ -461,7 +462,7 @@ 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) {
struct sway_container *focus = seat_get_focused_container(seat);
@@ -472,7 +473,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
}
// If moving a container by it's 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 1402db154..c10899f6f 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -49,6 +49,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',