aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 10:11:15 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 13:05:45 -0400
commit9b38ef950fcf293ba11f54c14d8b3a87f050b154 (patch)
tree22f499e690941f95dd47335b522208ae2d7eeac4 /sway/input/cursor.c
parentImplement mouse warping (diff)
downloadsway-9b38ef950fcf293ba11f54c14d8b3a87f050b154.tar.gz
sway-9b38ef950fcf293ba11f54c14d8b3a87f050b154.tar.zst
sway-9b38ef950fcf293ba11f54c14d8b3a87f050b154.zip
Implement focus_follows_mouse
Also contains two other small changes: - Clicking any button will focus the container clicked (not just left) - Remove seamless_mouse (doesn't make sense on wlroots)
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 9cdd66d8..35dd5dc8 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -125,7 +125,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
125 struct wlr_seat *seat = cursor->seat->wlr_seat; 125 struct wlr_seat *seat = cursor->seat->wlr_seat;
126 struct wlr_surface *surface = NULL; 126 struct wlr_surface *surface = NULL;
127 double sx, sy; 127 double sx, sy;
128 container_at_cursor(cursor, &surface, &sx, &sy); 128 struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy);
129 if (c && config->focus_follows_mouse) {
130 sway_seat_set_focus(cursor->seat, c);
131 }
129 132
130 // reset cursor if switching between clients 133 // reset cursor if switching between clients
131 struct wl_client *client = NULL; 134 struct wl_client *client = NULL;
@@ -170,33 +173,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
170 struct sway_cursor *cursor = wl_container_of(listener, cursor, button); 173 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
171 struct wlr_event_pointer_button *event = data; 174 struct wlr_event_pointer_button *event = data;
172 175
173 if (event->button == BTN_LEFT) { 176 struct wlr_surface *surface = NULL;
174 struct wlr_surface *surface = NULL; 177 double sx, sy;
175 double sx, sy; 178 struct sway_container *cont =
176 struct sway_container *cont = 179 container_at_cursor(cursor, &surface, &sx, &sy);
177 container_at_cursor(cursor, &surface, &sx, &sy); 180 // Avoid moving keyboard focus from a surface that accepts it to one
178 // Avoid moving keyboard focus from a surface that accepts it to one 181 // that does not unless the change would move us to a new workspace.
179 // that does not unless the change would move us to a new workspace. 182 //
180 // 183 // This prevents, for example, losing focus when clicking on swaybar.
181 // This prevents, for example, losing focus when clicking on swaybar. 184 //
182 // 185 // TODO: Replace this condition with something like
183 // TODO: Replace this condition with something like 186 // !surface_accepts_keyboard_input
184 // !surface_accepts_keyboard_input 187 if (surface && cont && cont->type != C_VIEW) {
185 if (surface && cont && cont->type != C_VIEW) { 188 struct sway_container *new_ws = cont;
186 struct sway_container *new_ws = cont; 189 if (new_ws && new_ws->type != C_WORKSPACE) {
187 if (new_ws && new_ws->type != C_WORKSPACE) { 190 new_ws = container_parent(new_ws, C_WORKSPACE);
188 new_ws = container_parent(new_ws, C_WORKSPACE); 191 }
189 } 192 struct sway_container *old_ws = sway_seat_get_focus(cursor->seat);
190 struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); 193 if (old_ws && old_ws->type != C_WORKSPACE) {
191 if (old_ws && old_ws->type != C_WORKSPACE) { 194 old_ws = container_parent(old_ws, C_WORKSPACE);
192 old_ws = container_parent(old_ws, C_WORKSPACE); 195 }
193 } 196 if (new_ws != old_ws) {
194 if (new_ws != old_ws) {
195 sway_seat_set_focus(cursor->seat, cont);
196 }
197 } else {
198 sway_seat_set_focus(cursor->seat, cont); 197 sway_seat_set_focus(cursor->seat, cont);
199 } 198 }
199 } else {
200 sway_seat_set_focus(cursor->seat, cont);
200 } 201 }
201 202
202 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, 203 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec,