mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 22:43:58 +01:00
input/seatop_default: refactor move/resize button logic
Make it so config->floating_mod_inverse only applies when pressing mod, not when clicking on titlebars. Centralize logic into shared variables.
This commit is contained in:
parent
8363699f14
commit
35d8adefc4
@ -355,6 +355,13 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
||||||
uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
|
uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
|
||||||
|
|
||||||
|
bool mod_pressed = modifiers & config->floating_mod;
|
||||||
|
uint32_t mod_move_btn = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
|
||||||
|
uint32_t mod_resize_btn = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT;
|
||||||
|
bool mod_move_btn_pressed = mod_pressed && button == mod_move_btn;
|
||||||
|
bool mod_resize_btn_pressed = mod_pressed && button == mod_resize_btn;
|
||||||
|
bool titlebar_left_btn_pressed = on_titlebar && button == BTN_LEFT;
|
||||||
|
|
||||||
// Handle mouse bindings
|
// Handle mouse bindings
|
||||||
if (trigger_pointer_button_binding(seat, device, button, state, modifiers,
|
if (trigger_pointer_button_binding(seat, device, button, state, modifiers,
|
||||||
on_titlebar, on_border, on_contents, on_workspace)) {
|
on_titlebar, on_border, on_contents, on_workspace)) {
|
||||||
@ -403,12 +410,8 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle tiling resize via mod
|
// Handle tiling resize via mod
|
||||||
bool mod_pressed = modifiers & config->floating_mod;
|
if (cont && !is_floating_or_child && mod_pressed && mod_resize_btn_pressed &&
|
||||||
if (cont && !is_floating_or_child && mod_pressed &&
|
|
||||||
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
uint32_t btn_resize = config->floating_mod_inverse ?
|
|
||||||
BTN_LEFT : BTN_RIGHT;
|
|
||||||
if (button == btn_resize) {
|
|
||||||
edge = 0;
|
edge = 0;
|
||||||
edge |= cursor->cursor->x > cont->pending.x + cont->pending.width / 2 ?
|
edge |= cursor->cursor->x > cont->pending.x + cont->pending.width / 2 ?
|
||||||
WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
|
WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
|
||||||
@ -430,7 +433,6 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
seatop_begin_resize_tiling(seat, cont, edge);
|
seatop_begin_resize_tiling(seat, cont, edge);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle changing focus when clicking on a container
|
// Handle changing focus when clicking on a container
|
||||||
if (cont && state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
if (cont && state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
@ -454,13 +456,11 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
|
|
||||||
// Handle beginning floating move
|
// Handle beginning floating move
|
||||||
if (cont && is_floating_or_child && !is_fullscreen_or_child &&
|
if (cont && is_floating_or_child && !is_fullscreen_or_child &&
|
||||||
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
state == WL_POINTER_BUTTON_STATE_PRESSED &&
|
||||||
uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
|
(mod_move_btn_pressed || titlebar_left_btn_pressed)) {
|
||||||
if (button == btn_move && (mod_pressed || on_titlebar)) {
|
|
||||||
seatop_begin_move_floating(seat, container_toplevel_ancestor(cont));
|
seatop_begin_move_floating(seat, container_toplevel_ancestor(cont));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle beginning floating resize
|
// Handle beginning floating resize
|
||||||
if (cont && is_floating_or_child && !is_fullscreen_or_child &&
|
if (cont && is_floating_or_child && !is_fullscreen_or_child &&
|
||||||
@ -473,9 +473,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Via mod+click
|
// Via mod+click
|
||||||
uint32_t btn_resize = config->floating_mod_inverse ?
|
if (mod_resize_btn_pressed) {
|
||||||
BTN_LEFT : BTN_RIGHT;
|
|
||||||
if (mod_pressed && button == btn_resize) {
|
|
||||||
struct sway_container *floater = container_toplevel_ancestor(cont);
|
struct sway_container *floater = container_toplevel_ancestor(cont);
|
||||||
edge = 0;
|
edge = 0;
|
||||||
edge |= cursor->cursor->x > floater->pending.x + floater->pending.width / 2 ?
|
edge |= cursor->cursor->x > floater->pending.x + floater->pending.width / 2 ?
|
||||||
@ -489,18 +487,15 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle moving a tiling container
|
// Handle moving a tiling container
|
||||||
if (config->tiling_drag && (mod_pressed || on_titlebar) &&
|
if (config->tiling_drag && (mod_move_btn_pressed || titlebar_left_btn_pressed) &&
|
||||||
state == WL_POINTER_BUTTON_STATE_PRESSED && !is_floating_or_child &&
|
state == WL_POINTER_BUTTON_STATE_PRESSED && !is_floating_or_child &&
|
||||||
cont && cont->pending.fullscreen_mode == FULLSCREEN_NONE &&
|
cont && cont->pending.fullscreen_mode == FULLSCREEN_NONE) {
|
||||||
button == (config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT)) {
|
|
||||||
|
|
||||||
// If moving a container by its title bar, use a threshold for the drag
|
// 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 && config->tiling_drag_threshold > 0) {
|
||||||
seatop_begin_move_tiling_threshold(seat, cont);
|
seatop_begin_move_tiling_threshold(seat, cont);
|
||||||
} else {
|
} else {
|
||||||
seatop_begin_move_tiling(seat, cont);
|
seatop_begin_move_tiling(seat, cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user