aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 15:32:29 -0400
committerLibravatar GitHub <noreply@github.com>2018-03-31 15:32:29 -0400
commit122b96abed9955f78e3f157167d34312f5bb551d (patch)
treefdcb6ffc0520145a029118aec443eb2199981d77 /sway/input/cursor.c
parentMerge pull request #1689 from emersion/destroy-output-segfaults (diff)
parentAddress review feedback (diff)
downloadsway-122b96abed9955f78e3f157167d34312f5bb551d.tar.gz
sway-122b96abed9955f78e3f157167d34312f5bb551d.tar.zst
sway-122b96abed9955f78e3f157167d34312f5bb551d.zip
Merge pull request #1684 from swaywm/follow-warp
Implement focus_follows_mouse, mouse_warping
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 67776f8f..d608a9cf 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -127,7 +127,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
127 struct wlr_seat *seat = cursor->seat->wlr_seat; 127 struct wlr_seat *seat = cursor->seat->wlr_seat;
128 struct wlr_surface *surface = NULL; 128 struct wlr_surface *surface = NULL;
129 double sx, sy; 129 double sx, sy;
130 container_at_cursor(cursor, &surface, &sx, &sy); 130 struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy);
131 if (c && config->focus_follows_mouse) {
132 sway_seat_set_focus_warp(cursor->seat, c, false);
133 }
131 134
132 // reset cursor if switching between clients 135 // reset cursor if switching between clients
133 struct wl_client *client = NULL; 136 struct wl_client *client = NULL;
@@ -158,8 +161,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
158 cursor_send_pointer_motion(cursor, event->time_msec); 161 cursor_send_pointer_motion(cursor, event->time_msec);
159} 162}
160 163
161static void handle_cursor_motion_absolute(struct wl_listener *listener, 164static void handle_cursor_motion_absolute(
162 void *data) { 165 struct wl_listener *listener, void *data) {
163 struct sway_cursor *cursor = 166 struct sway_cursor *cursor =
164 wl_container_of(listener, cursor, motion_absolute); 167 wl_container_of(listener, cursor, motion_absolute);
165 struct wlr_event_pointer_motion_absolute *event = data; 168 struct wlr_event_pointer_motion_absolute *event = data;
@@ -172,33 +175,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
172 struct sway_cursor *cursor = wl_container_of(listener, cursor, button); 175 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
173 struct wlr_event_pointer_button *event = data; 176 struct wlr_event_pointer_button *event = data;
174 177
175 if (event->button == BTN_LEFT) { 178 struct wlr_surface *surface = NULL;
176 struct wlr_surface *surface = NULL; 179 double sx, sy;
177 double sx, sy; 180 struct sway_container *cont =
178 struct sway_container *cont = 181 container_at_cursor(cursor, &surface, &sx, &sy);
179 container_at_cursor(cursor, &surface, &sx, &sy); 182 // Avoid moving keyboard focus from a surface that accepts it to one
180 // Avoid moving keyboard focus from a surface that accepts it to one 183 // that does not unless the change would move us to a new workspace.
181 // that does not unless the change would move us to a new workspace. 184 //
182 // 185 // This prevents, for example, losing focus when clicking on swaybar.
183 // This prevents, for example, losing focus when clicking on swaybar. 186 //
184 // 187 // TODO: Replace this condition with something like
185 // TODO: Replace this condition with something like 188 // !surface_accepts_keyboard_input
186 // !surface_accepts_keyboard_input 189 if (surface && cont && cont->type != C_VIEW) {
187 if (surface && cont && cont->type != C_VIEW) { 190 struct sway_container *new_ws = cont;
188 struct sway_container *new_ws = cont; 191 if (new_ws && new_ws->type != C_WORKSPACE) {
189 if (new_ws && new_ws->type != C_WORKSPACE) { 192 new_ws = container_parent(new_ws, C_WORKSPACE);
190 new_ws = container_parent(new_ws, C_WORKSPACE); 193 }
191 } 194 struct sway_container *old_ws = sway_seat_get_focus(cursor->seat);
192 struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); 195 if (old_ws && old_ws->type != C_WORKSPACE) {
193 if (old_ws && old_ws->type != C_WORKSPACE) { 196 old_ws = container_parent(old_ws, C_WORKSPACE);
194 old_ws = container_parent(old_ws, C_WORKSPACE); 197 }
195 } 198 if (new_ws != old_ws) {
196 if (new_ws != old_ws) {
197 sway_seat_set_focus(cursor->seat, cont);
198 }
199 } else {
200 sway_seat_set_focus(cursor->seat, cont); 199 sway_seat_set_focus(cursor->seat, cont);
201 } 200 }
201 } else {
202 sway_seat_set_focus(cursor->seat, cont);
202 } 203 }
203 204
204 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, 205 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec,