aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-18 23:08:45 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-18 23:08:45 +1000
commit24a90e5d86441fc345356eb3767e5a6880dcedbd (patch)
treedbf14c684b7802c2f2876fc8b11636bec26abc3d /sway/commands
parentMerge pull request #2868 from emersion/xcursor-env (diff)
downloadsway-24a90e5d86441fc345356eb3767e5a6880dcedbd.tar.gz
sway-24a90e5d86441fc345356eb3767e5a6880dcedbd.tar.zst
sway-24a90e5d86441fc345356eb3767e5a6880dcedbd.zip
Remove cursor warping from seat_set_focus
Because cursor warping was the default behaviour in seat_set_focus, there may be cases where we may have been warping the cursor unintentionally. This patch removes cursor warping from seat_set_focus and only does it in the focus command. This is managed by a static function in focus.c. To know whether to warp or not, we need to know which node had focus previously. To keep track of this easily, seat->prev_focus has been introduced and is set to the previous in seat_set_focus.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/focus.c29
-rw-r--r--sway/commands/swap.c4
2 files changed, 26 insertions, 7 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 44adb95b..46304ae0 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -34,6 +34,24 @@ static bool parse_movement_direction(const char *name,
34 return true; 34 return true;
35} 35}
36 36
37static void consider_warp_to_focus(struct sway_seat *seat) {
38 struct sway_node *focus = seat_get_focus(seat);
39 if (config->mouse_warping == WARP_NO || !focus || !seat->prev_focus) {
40 return;
41 }
42 if (config->mouse_warping == WARP_OUTPUT &&
43 node_get_output(focus) == node_get_output(seat->prev_focus)) {
44 return;
45 }
46
47 if (focus->type == N_CONTAINER) {
48 cursor_warp_to_container(seat->cursor, focus->sway_container);
49 } else {
50 cursor_warp_to_workspace(seat->cursor, focus->sway_workspace);
51 }
52 cursor_send_pointer_motion(seat->cursor, 0, false);
53}
54
37/** 55/**
38 * Get node in the direction of newly entered output. 56 * Get node in the direction of newly entered output.
39 */ 57 */
@@ -181,7 +199,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
181 } 199 }
182 if (new_focus) { 200 if (new_focus) {
183 seat_set_focus_container(seat, new_focus); 201 seat_set_focus_container(seat, new_focus);
184 cursor_send_pointer_motion(seat->cursor, 0, true); 202 consider_warp_to_focus(seat);
185 } else { 203 } else {
186 return cmd_results_new(CMD_FAILURE, "focus", 204 return cmd_results_new(CMD_FAILURE, "focus",
187 "Failed to find a %s container in workspace", 205 "Failed to find a %s container in workspace",
@@ -214,7 +232,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
214 free(identifier); 232 free(identifier);
215 if (output) { 233 if (output) {
216 seat_set_focus(seat, seat_get_focus_inactive(seat, &output->node)); 234 seat_set_focus(seat, seat_get_focus_inactive(seat, &output->node));
217 cursor_send_pointer_motion(seat->cursor, 0, true); 235 consider_warp_to_focus(seat);
218 } 236 }
219 237
220 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 238 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -235,6 +253,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
235 253
236 if (argc == 0 && container) { 254 if (argc == 0 && container) {
237 seat_set_focus_container(seat, container); 255 seat_set_focus_container(seat, container);
256 consider_warp_to_focus(seat);
238 cursor_send_pointer_motion(seat->cursor, 0, true); 257 cursor_send_pointer_motion(seat->cursor, 0, true);
239 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 258 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
240 } 259 }
@@ -264,7 +283,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
264 struct sway_node *focus = seat_get_active_tiling_child(seat, node); 283 struct sway_node *focus = seat_get_active_tiling_child(seat, node);
265 if (focus) { 284 if (focus) {
266 seat_set_focus(seat, focus); 285 seat_set_focus(seat, focus);
267 cursor_send_pointer_motion(seat->cursor, 0, true); 286 consider_warp_to_focus(seat);
268 } 287 }
269 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 288 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
270 } 289 }
@@ -284,7 +303,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
284 struct sway_node *node = 303 struct sway_node *node =
285 get_node_in_output_direction(new_output, direction); 304 get_node_in_output_direction(new_output, direction);
286 seat_set_focus(seat, node); 305 seat_set_focus(seat, node);
287 cursor_send_pointer_motion(seat->cursor, 0, true); 306 consider_warp_to_focus(seat);
288 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 307 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
289 } 308 }
290 309
@@ -292,7 +311,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
292 node_get_in_direction(container, seat, direction); 311 node_get_in_direction(container, seat, direction);
293 if (next_focus) { 312 if (next_focus) {
294 seat_set_focus(seat, next_focus); 313 seat_set_focus(seat, next_focus);
295 cursor_send_pointer_motion(seat->cursor, 0, true); 314 consider_warp_to_focus(seat);
296 } 315 }
297 316
298 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 317 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index 9cc0d5c2..8a6dfdbd 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -61,13 +61,13 @@ static void swap_focus(struct sway_container *con1,
61 enum sway_container_layout layout2 = container_parent_layout(con2); 61 enum sway_container_layout layout2 = container_parent_layout(con2);
62 if (focus == con1 && (layout2 == L_TABBED || layout2 == L_STACKED)) { 62 if (focus == con1 && (layout2 == L_TABBED || layout2 == L_STACKED)) {
63 if (workspace_is_visible(ws2)) { 63 if (workspace_is_visible(ws2)) {
64 seat_set_focus_warp(seat, &con2->node, false); 64 seat_set_focus(seat, &con2->node);
65 } 65 }
66 seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1); 66 seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1);
67 } else if (focus == con2 && (layout1 == L_TABBED 67 } else if (focus == con2 && (layout1 == L_TABBED
68 || layout1 == L_STACKED)) { 68 || layout1 == L_STACKED)) {
69 if (workspace_is_visible(ws1)) { 69 if (workspace_is_visible(ws1)) {
70 seat_set_focus_warp(seat, &con1->node, false); 70 seat_set_focus(seat, &con1->node);
71 } 71 }
72 seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2); 72 seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2);
73 } else if (ws1 != ws2) { 73 } else if (ws1 != ws2) {