diff options
-rw-r--r-- | sway/input/cursor.c | 25 |
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) { | |||
175 | double sx, sy; | 175 | double sx, sy; |
176 | struct sway_container *cont = | 176 | struct sway_container *cont = |
177 | container_at_cursor(cursor, &surface, &sx, &sy); | 177 | container_at_cursor(cursor, &surface, &sx, &sy); |
178 | // TODO: Actually test if the surface accepts keyboard input, rather | 178 | // Avoid moving keyboard focus from a surface that accepts it to one |
179 | // than assuming it does not | 179 | // that does not unless the change would move us to a new workspace. |
180 | // Layer surfaces with keyboard_interactive=true will change how this | 180 | // |
181 | // works, for example. | 181 | // This prevents, for example, losing focus when clicking on swaybar. |
182 | if (!surface || cont->type == C_VIEW) { | 182 | // |
183 | // TODO: Replace this condition with something like | ||
184 | // !surface_accepts_keyboard_input | ||
185 | if (surface && cont->type != C_VIEW) { | ||
186 | struct sway_container *new_ws = cont; | ||
187 | if (new_ws && new_ws->type != C_WORKSPACE) { | ||
188 | new_ws = container_parent(new_ws, C_WORKSPACE); | ||
189 | } | ||
190 | struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); | ||
191 | if (old_ws && old_ws->type != C_WORKSPACE) { | ||
192 | old_ws = container_parent(old_ws, C_WORKSPACE); | ||
193 | } | ||
194 | if (new_ws != old_ws) { | ||
195 | sway_seat_set_focus(cursor->seat, cont); | ||
196 | } | ||
197 | } else { | ||
183 | sway_seat_set_focus(cursor->seat, cont); | 198 | sway_seat_set_focus(cursor->seat, cont); |
184 | } | 199 | } |
185 | } | 200 | } |