From 9e58425cb3b61c4073f0789f23d0943bc87e424f Mon Sep 17 00:00:00 2001 From: Simon Plakolb Date: Mon, 2 Aug 2021 16:54:50 +0200 Subject: input: Use seatop_down on layer surface click This solves an issue where layer-shell items would not receive a button release event when the pointer left them while being pressed. The default seatop changes focus immediately while seatop_down defers any focus changes until the pointer is released or seatop_down is destroyed. --- include/sway/input/seat.h | 3 +++ sway/input/seatop_default.c | 3 +++ sway/input/seatop_down.c | 30 +++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index a2b5d2a1..78dbda6f 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -241,6 +241,9 @@ void seatop_begin_default(struct sway_seat *seat); void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, uint32_t time_msec, double sx, double sy); +void seatop_begin_down_on_layer_surface(struct sway_seat *seat, + struct wlr_surface *surface, uint32_t time_msec, double sx, double sy); + void seatop_begin_move_floating(struct sway_seat *seat, struct sway_container *con); diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index f9eb8c8a..7a3745d2 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -373,6 +373,9 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, seat_set_focus_layer(seat, layer); transaction_commit_dirty(); } + if (state == WLR_BUTTON_PRESSED) { + seatop_begin_down_on_layer_surface(seat, surface, time_msec, sx, sy); + } seat_pointer_notify_button(seat, time_msec, button, state); return; } diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c index 7607a598..cc54b90b 100644 --- a/sway/input/seatop_down.c +++ b/sway/input/seatop_down.c @@ -10,7 +10,8 @@ struct seatop_down_event { struct sway_container *con; - double ref_lx, ref_ly; // cursor's x/y at start of op + struct wlr_surface *surface; + double ref_lx, ref_ly; // cursor's x/y at start of op double ref_con_lx, ref_con_ly; // container's x/y at start of op }; @@ -40,8 +41,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { struct seatop_down_event *e = seat->seatop_data; - struct sway_container *con = e->con; - if (seat_is_input_allowed(seat, con->view->surface)) { + if (seat_is_input_allowed(seat, e->surface)) { double moved_x = seat->cursor->cursor->x - e->ref_lx; double moved_y = seat->cursor->cursor->y - e->ref_ly; double sx = e->ref_con_lx + moved_x; @@ -62,8 +62,7 @@ static void handle_tablet_tool_tip(struct sway_seat *seat, static void handle_tablet_tool_motion(struct sway_seat *seat, struct sway_tablet_tool *tool, uint32_t time_msec) { struct seatop_down_event *e = seat->seatop_data; - struct sway_container *con = e->con; - if (seat_is_input_allowed(seat, con->view->surface)) { + if (seat_is_input_allowed(seat, e->surface)) { double moved_x = seat->cursor->cursor->x - e->ref_lx; double moved_y = seat->cursor->cursor->y - e->ref_ly; double sx = e->ref_con_lx + moved_x; @@ -99,6 +98,7 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, return; } e->con = con; + e->surface = con->view->surface; e->ref_lx = seat->cursor->cursor->x; e->ref_ly = seat->cursor->cursor->y; e->ref_con_lx = sx; @@ -110,3 +110,23 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, container_raise_floating(con); transaction_commit_dirty(); } + +void seatop_begin_down_on_layer_surface(struct sway_seat *seat, + struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) { + seatop_end(seat); + + struct seatop_down_event *e = + calloc(1, sizeof(struct seatop_down_event)); + if (!e) { + return; + } + e->con = NULL; + e->surface = surface; + e->ref_lx = seat->cursor->cursor->x; + e->ref_ly = seat->cursor->cursor->y; + e->ref_con_lx = sx; + e->ref_con_ly = sy; + + seat->seatop_impl = &seatop_impl; + seat->seatop_data = e; +} -- cgit v1.2.3-54-g00ecf