diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 70 | ||||
-rw-r--r-- | sway/input/keyboard.c | 4 | ||||
-rw-r--r-- | sway/input/seat.c | 36 |
3 files changed, 82 insertions, 28 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 7390816f..d608a9cf 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -50,21 +50,23 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views; struct sway_view *view; wl_list_for_each_reverse(view, unmanaged, unmanaged_view_link) { - if (view->type == SWAY_XWAYLAND_VIEW) { - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - struct wlr_box box = { - .x = xsurface->x, - .y = xsurface->y, - .width = xsurface->width, - .height = xsurface->height, - }; - - if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { - *surface = xsurface->surface; - *sx = cursor->x - box.x; - *sy = cursor->y - box.y; - return view->swayc; - } + if (view->type != SWAY_XWAYLAND_VIEW) { + continue; + } + + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + struct wlr_box box = { + .x = xsurface->x, + .y = xsurface->y, + .width = xsurface->width, + .height = xsurface->height, + }; + + if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { + *surface = xsurface->surface; + *sx = cursor->x - box.x; + *sy = cursor->y - box.y; + return NULL; } } @@ -125,7 +127,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, struct wlr_seat *seat = cursor->seat->wlr_seat; struct wlr_surface *surface = NULL; double sx, sy; - container_at_cursor(cursor, &surface, &sx, &sy); + struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy); + if (c && config->focus_follows_mouse) { + sway_seat_set_focus_warp(cursor->seat, c, false); + } // reset cursor if switching between clients struct wl_client *client = NULL; @@ -156,8 +161,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { cursor_send_pointer_motion(cursor, event->time_msec); } -static void handle_cursor_motion_absolute(struct wl_listener *listener, - void *data) { +static void handle_cursor_motion_absolute( + struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, motion_absolute); struct wlr_event_pointer_motion_absolute *event = data; @@ -170,11 +175,30 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, button); struct wlr_event_pointer_button *event = data; - if (event->button == BTN_LEFT) { - struct wlr_surface *surface = NULL; - double sx, sy; - struct sway_container *cont = - container_at_cursor(cursor, &surface, &sx, &sy); + struct wlr_surface *surface = NULL; + double sx, sy; + struct sway_container *cont = + container_at_cursor(cursor, &surface, &sx, &sy); + // Avoid moving keyboard focus from a surface that accepts it to one + // that does not unless the change would move us to a new workspace. + // + // This prevents, for example, losing focus when clicking on swaybar. + // + // TODO: Replace this condition with something like + // !surface_accepts_keyboard_input + if (surface && cont && cont->type != C_VIEW) { + struct sway_container *new_ws = cont; + if (new_ws && new_ws->type != C_WORKSPACE) { + new_ws = container_parent(new_ws, C_WORKSPACE); + } + struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); + if (old_ws && old_ws->type != C_WORKSPACE) { + old_ws = container_parent(old_ws, C_WORKSPACE); + } + if (new_ws != old_ws) { + sway_seat_set_focus(cursor->seat, cont); + } + } else { sway_seat_set_focus(cursor->seat, cont); } diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 99685052..8d22b684 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -97,8 +97,8 @@ static void keyboard_execute_command(struct sway_keyboard *keyboard, config->handler_context.seat = keyboard->seat_device->sway_seat; struct cmd_results *results = execute_command(binding->command, NULL); if (results->status != CMD_SUCCESS) { - wlr_log(L_DEBUG, "could not run command for binding: %s", - binding->command); + wlr_log(L_DEBUG, "could not run command for binding: %s (%s)", + binding->command, results->error); } free_cmd_results(results); } diff --git a/sway/input/seat.c b/sway/input/seat.c index f969636a..9aa34aca 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 700 #include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_xcursor_manager.h> #include "sway/tree/container.h" #include "sway/input/seat.h" @@ -291,7 +292,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { seat->cursor->cursor->y); } -void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container) { +void sway_seat_set_focus_warp(struct sway_seat *seat, + struct sway_container *container, bool warp) { struct sway_container *last_focus = sway_seat_get_focus(seat); if (container && last_focus == container) { @@ -311,6 +313,11 @@ void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *containe if (container->type == C_VIEW) { struct sway_view *view = container->sway_view; view_set_activated(view, true); + if (view->type == SWAY_XWAYLAND_VIEW) { + struct wlr_xwayland *xwayland = + seat->input->server->xwayland; + wlr_xwayland_set_seat(xwayland, seat->wlr_seat); + } struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); if (keyboard) { @@ -327,15 +334,33 @@ void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *containe if (last_focus) { struct sway_container *last_ws = last_focus; if (last_ws && last_ws->type != C_WORKSPACE) { - last_ws = container_parent(last_focus, C_WORKSPACE); + last_ws = container_parent(last_ws, C_WORKSPACE); } if (last_ws) { - wlr_log(L_DEBUG, "sending workspace event"); ipc_event_workspace(last_ws, container, "focus"); if (last_ws->children->length == 0) { container_workspace_destroy(last_ws); } } + struct sway_container *last_output = last_focus; + if (last_output && last_output->type != C_OUTPUT) { + last_output = container_parent(last_output, C_OUTPUT); + } + struct sway_container *new_output = container; + if (new_output && new_output->type != C_OUTPUT) { + new_output = container_parent(new_output, C_OUTPUT); + } + if (new_output && last_output && new_output != last_output + && config->mouse_warping && warp) { + struct wlr_output *output = new_output->sway_output->wlr_output; + double x = container->x + output->lx + container->width / 2.0; + double y = container->y + output->ly + container->height / 2.0; + if (!wlr_output_layout_contains_point( + root_container.sway_root->output_layout, + output, seat->cursor->cursor->x, seat->cursor->cursor->y)) { + wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); + } + } } if (last_focus && last_focus->type == C_VIEW && @@ -347,6 +372,11 @@ void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *containe seat->has_focus = (container != NULL); } +void sway_seat_set_focus(struct sway_seat *seat, + struct sway_container *container) { + sway_seat_set_focus_warp(seat, container, true); +} + struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { struct sway_seat_container *current = NULL; struct sway_container *parent = NULL; |