This commit is contained in:
hmpthcs 2024-02-24 15:51:25 -08:00 committed by GitHub
commit b702cff5ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 25 additions and 5 deletions

View File

@ -124,6 +124,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;

View File

@ -538,6 +538,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;

View File

@ -57,6 +57,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 },

13
sway/commands/drag_mode.c Normal file
View File

@ -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);
}

View File

@ -275,6 +275,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;

View File

@ -403,7 +403,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;
@ -455,7 +456,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;
}
@ -474,7 +475,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 ?
@ -488,11 +489,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);

View File

@ -50,6 +50,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',