aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-31 10:47:04 -0400
committerDrew DeVault <sir@cmpwn.com>2018-03-31 10:47:04 -0400
commitccdcaa478f139736157da6bc7c648977027fac3c (patch)
treeb02b3f59807a81100ed7dea9e5c3d7fd63b8835d
parent8aa195e3116d7dbc897da50d2795e4a638c0b184 (diff)
Fix bug with previous commit
-rw-r--r--sway/input/cursor.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 6b8522bf..75c98836 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -175,11 +175,26 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
double sx, sy;
struct sway_container *cont =
container_at_cursor(cursor, &surface, &sx, &sy);
- // TODO: Actually test if the surface accepts keyboard input, rather
- // than assuming it does not
- // Layer surfaces with keyboard_interactive=true will change how this
- // works, for example.
- if (!surface || cont->type == C_VIEW) {
+ // 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->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);
}
}