From 42131cd5a2cef8e6f14e8db4c2aea26a5a1c15c2 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Thu, 4 Jun 2020 14:29:46 -0400 Subject: [PATCH] input/tablet: allow moving floating tablet v2 surfaces by pen input Refs #5293. --- sway/input/seatop_default.c | 35 ++++++++++++++++++++++--------- sway/input/seatop_move_floating.c | 26 ++++++++++++++++------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index 048bad7544..4e17b05337 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -206,13 +206,34 @@ static void handle_tablet_tool_tip(struct sway_seat *seat, } struct sway_cursor *cursor = seat->cursor; - struct wlr_surface *surface = NULL; double sx, sy; struct sway_node *node = node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); - if (surface && node && node->type == N_CONTAINER) { + if (!sway_assert(surface, + "Expected null-surface tablet input to route through pointer emulation")) { + return; + } + + struct sway_container *cont = node && node->type == N_CONTAINER ? + node->sway_container : NULL; + + if (surface && node && cont) { + bool is_floating_or_child = container_is_floating_or_child(cont); + bool is_fullscreen_or_child = container_is_fullscreen_or_child(cont); + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); + bool mod_pressed = keyboard && + (wlr_keyboard_get_modifiers(keyboard) & config->floating_mod); + + // Handle beginning floating move + if (is_floating_or_child && !is_fullscreen_or_child && mod_pressed) { + seat_set_focus_container(seat, + seat_get_focus_inactive_view(seat, &cont->node)); + seatop_begin_move_floating(seat, container_toplevel_ancestor(cont)); + return; + } + seatop_begin_down(seat, node->sway_container, time_msec, sx, sy); } } @@ -334,10 +355,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, if (button == btn_move && (mod_pressed || on_titlebar)) { seat_set_focus_container(seat, seat_get_focus_inactive_view(seat, &cont->node)); - while (cont->parent) { - cont = cont->parent; - } - seatop_begin_move_floating(seat, cont); + seatop_begin_move_floating(seat, container_toplevel_ancestor(cont)); return; } } @@ -355,10 +373,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT; if (mod_pressed && button == btn_resize) { - struct sway_container *floater = cont; - while (floater->parent) { - floater = floater->parent; - } + struct sway_container *floater = container_toplevel_ancestor(cont); edge = 0; edge |= cursor->cursor->x > floater->x + floater->width / 2 ? WLR_EDGE_RIGHT : WLR_EDGE_LEFT; diff --git a/sway/input/seatop_move_floating.c b/sway/input/seatop_move_floating.c index a04fd45762..6e601d8bf6 100644 --- a/sway/input/seatop_move_floating.c +++ b/sway/input/seatop_move_floating.c @@ -9,20 +9,31 @@ struct seatop_move_floating_event { double dx, dy; // cursor offset in container }; +static void finalize_move(struct sway_seat *seat) { + struct seatop_move_floating_event *e = seat->seatop_data; + + // We "move" the container to its own location + // so it discovers its output again. + container_floating_move_to(e->con, e->con->x, e->con->y); + + seatop_begin_default(seat); +} + static void handle_button(struct sway_seat *seat, uint32_t time_msec, struct wlr_input_device *device, uint32_t button, enum wlr_button_state state) { if (seat->cursor->pressed_button_count == 0) { - struct seatop_move_floating_event *e = seat->seatop_data; - - // We "move" the container to its own location - // so it discovers its output again. - container_floating_move_to(e->con, e->con->x, e->con->y); - - seatop_begin_default(seat); + finalize_move(seat); } } +static void handle_tablet_tool_tip(struct sway_seat *seat, + struct sway_tablet_tool *tool, uint32_t time_msec, + enum wlr_tablet_tool_tip_state state) { + if (state == WLR_TABLET_TOOL_TIP_UP) { + finalize_move(seat); + } +} static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec, double dx, double dy) { struct seatop_move_floating_event *e = seat->seatop_data; @@ -42,6 +53,7 @@ static void handle_unref(struct sway_seat *seat, struct sway_container *con) { static const struct sway_seatop_impl seatop_impl = { .button = handle_button, .pointer_motion = handle_pointer_motion, + .tablet_tool_tip = handle_tablet_tool_tip, .unref = handle_unref, };