diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 34 | ||||
-rw-r--r-- | sway/input/seat.c | 33 |
2 files changed, 57 insertions, 10 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 3b70b471..762b8081 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -215,6 +215,19 @@ static enum wlr_edges find_resize_edge(struct sway_container *cont, return edge; } +static void handle_down_motion(struct sway_seat *seat, + struct sway_cursor *cursor, uint32_t time_msec) { + struct sway_container *con = seat->op_container; + if (seat_is_input_allowed(seat, con->sway_view->surface)) { + double moved_x = cursor->cursor->x - seat->op_ref_lx; + double moved_y = cursor->cursor->y - seat->op_ref_ly; + double sx = seat->op_ref_con_lx + moved_x; + double sy = seat->op_ref_con_ly + moved_y; + wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy); + } + seat->op_moved = true; +} + static void handle_move_motion(struct sway_seat *seat, struct sway_cursor *cursor) { struct sway_container *con = seat->op_container; @@ -397,6 +410,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, if (seat->operation != OP_NONE) { switch (seat->operation) { + case OP_DOWN: + handle_down_motion(seat, cursor, time_msec); + break; case OP_MOVE: handle_move_motion(seat, cursor); break; @@ -726,13 +742,13 @@ void dispatch_cursor_button(struct sway_cursor *cursor, } // Via mod+click - struct sway_container *floater = cont; - while (floater->parent->layout != L_FLOATING) { - floater = floater->parent; - } uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT; - if (button == btn_resize) { + if (mod_pressed && button == btn_resize) { + struct sway_container *floater = cont; + while (floater->parent->layout != L_FLOATING) { + floater = floater->parent; + } edge = 0; edge |= cursor->cursor->x > floater->x + floater->width / 2 ? WLR_EDGE_RIGHT : WLR_EDGE_LEFT; @@ -743,6 +759,14 @@ void dispatch_cursor_button(struct sway_cursor *cursor, } } + // Handle mousedown on a container surface + if (surface && cont && state == WLR_BUTTON_PRESSED) { + seat_set_focus(seat, cont); + seat_pointer_notify_button(seat, time_msec, button, state); + seat_begin_down(seat, cont, button, sx, sy); + return; + } + // Handle clicking a container surface if (cont) { seat_set_focus(seat, cont); diff --git a/sway/input/seat.c b/sway/input/seat.c index fa41904a..d35c62a0 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -313,9 +313,6 @@ static void handle_new_drag_icon(struct wl_listener *listener, void *data) { static void collect_focus_iter(struct sway_container *con, void *data) { struct sway_seat *seat = data; - if (con->type > C_WORKSPACE) { - return; - } struct sway_seat_container *seat_con = seat_container_from_container(seat, con); if (!seat_con) { @@ -349,7 +346,8 @@ struct sway_seat *seat_create(struct sway_input_manager *input, // init the focus stack wl_list_init(&seat->focus_stack); - container_for_each_descendant(&root_container, collect_focus_iter, seat); + root_for_each_workspace(collect_focus_iter, seat); + root_for_each_container(collect_focus_iter, seat); wl_signal_add(&root_container.sway_root->events.new_container, &seat->new_container); @@ -954,6 +952,18 @@ struct seat_config *seat_get_config(struct sway_seat *seat) { return NULL; } +void seat_begin_down(struct sway_seat *seat, struct sway_container *con, + uint32_t button, double sx, double sy) { + seat->operation = OP_DOWN; + seat->op_container = con; + seat->op_button = button; + seat->op_ref_lx = seat->cursor->cursor->x; + seat->op_ref_ly = seat->cursor->cursor->y; + seat->op_ref_con_lx = sx; + seat->op_ref_con_ly = sy; + seat->op_moved = false; +} + void seat_begin_move(struct sway_seat *seat, struct sway_container *con, uint32_t button) { if (!seat->cursor) { @@ -1007,6 +1017,7 @@ void seat_begin_resize_tiling(struct sway_seat *seat, } void seat_end_mouse_operation(struct sway_seat *seat) { + enum sway_seat_operation operation = seat->operation; if (seat->operation == OP_MOVE) { // We "move" the container to its own location so it discovers its // output again. @@ -1015,7 +1026,19 @@ void seat_end_mouse_operation(struct sway_seat *seat) { } seat->operation = OP_NONE; seat->op_container = NULL; - cursor_set_image(seat->cursor, "left_ptr", NULL); + if (operation == OP_DOWN) { + // Set the cursor's previous coords to the x/y at the start of the + // operation, so the container change will be detected if using + // focus_follows_mouse and the cursor moved off the original container + // during the operation. + seat->cursor->previous.x = seat->op_ref_lx; + seat->cursor->previous.y = seat->op_ref_ly; + if (seat->op_moved) { + cursor_send_pointer_motion(seat->cursor, 0, true); + } + } else { + cursor_set_image(seat->cursor, "left_ptr", NULL); + } } void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec, |