summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/sway/input/seat.h4
-rw-r--r--sway/commands/focus.c29
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/input/cursor.c6
-rw-r--r--sway/input/seat.c29
5 files changed, 34 insertions, 38 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index be95567e..b3b98e8d 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -52,6 +52,7 @@ struct sway_seat {
52 bool has_focus; 52 bool has_focus;
53 struct wl_list focus_stack; // list of containers in focus order 53 struct wl_list focus_stack; // list of containers in focus order
54 struct sway_workspace *workspace; 54 struct sway_workspace *workspace;
55 struct sway_node *prev_focus;
55 56
56 // If the focused layer is set, views cannot receive keyboard focus 57 // If the focused layer is set, views cannot receive keyboard focus
57 struct wlr_layer_surface_v1 *focused_layer; 58 struct wlr_layer_surface_v1 *focused_layer;
@@ -121,9 +122,6 @@ void seat_set_focus_workspace(struct sway_seat *seat,
121 */ 122 */
122void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node); 123void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node);
123 124
124void seat_set_focus_warp(struct sway_seat *seat,
125 struct sway_node *node, bool warp);
126
127void seat_set_focus_surface(struct sway_seat *seat, 125void seat_set_focus_surface(struct sway_seat *seat,
128 struct wlr_surface *surface, bool unfocus); 126 struct wlr_surface *surface, bool unfocus);
129 127
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) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 925190d6..688fc230 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -597,7 +597,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
597 struct sway_output *focused_output = node_get_output(focus); 597 struct sway_output *focused_output = node_get_output(focus);
598 struct sway_output *output = node_get_output(node); 598 struct sway_output *output = node_get_output(node);
599 if (output != focused_output) { 599 if (output != focused_output) {
600 seat_set_focus_warp(seat, node, false); 600 seat_set_focus(seat, node);
601 } 601 }
602 } else if (node->type == N_CONTAINER && node->sway_container->view) { 602 } else if (node->type == N_CONTAINER && node->sway_container->view) {
603 // Focus node if the following are true: 603 // Focus node if the following are true:
@@ -607,14 +607,14 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
607 if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) && 607 if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) &&
608 node != prev_node && 608 node != prev_node &&
609 view_is_visible(node->sway_container->view)) { 609 view_is_visible(node->sway_container->view)) {
610 seat_set_focus_warp(seat, node, false); 610 seat_set_focus(seat, node);
611 } else { 611 } else {
612 struct sway_node *next_focus = 612 struct sway_node *next_focus =
613 seat_get_focus_inactive(seat, &root->node); 613 seat_get_focus_inactive(seat, &root->node);
614 if (next_focus && next_focus->type == N_CONTAINER && 614 if (next_focus && next_focus->type == N_CONTAINER &&
615 next_focus->sway_container->view && 615 next_focus->sway_container->view &&
616 view_is_visible(next_focus->sway_container->view)) { 616 view_is_visible(next_focus->sway_container->view)) {
617 seat_set_focus_warp(seat, next_focus, false); 617 seat_set_focus(seat, next_focus);
618 } 618 }
619 } 619 }
620 } 620 }
diff --git a/sway/input/seat.c b/sway/input/seat.c
index d8d2f3a4..60ee27d0 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -640,13 +640,13 @@ void seat_set_raw_focus(struct sway_seat *seat, struct sway_node *node) {
640 node_set_dirty(node_get_parent(node)); 640 node_set_dirty(node_get_parent(node));
641} 641}
642 642
643void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, 643void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
644 bool warp) {
645 if (seat->focused_layer) { 644 if (seat->focused_layer) {
646 return; 645 return;
647 } 646 }
648 647
649 struct sway_node *last_focus = seat_get_focus(seat); 648 struct sway_node *last_focus = seat_get_focus(seat);
649 seat->prev_focus = last_focus;
650 if (last_focus == node) { 650 if (last_focus == node) {
651 return; 651 return;
652 } 652 }
@@ -678,8 +678,6 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
678 } 678 }
679 } 679 }
680 680
681 struct sway_output *last_output = last_workspace ?
682 last_workspace->output : NULL;
683 struct sway_output *new_output = new_workspace->output; 681 struct sway_output *new_output = new_workspace->output;
684 682
685 if (last_workspace != new_workspace && new_output) { 683 if (last_workspace != new_workspace && new_output) {
@@ -774,21 +772,6 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
774 workspace_consider_destroy(last_workspace); 772 workspace_consider_destroy(last_workspace);
775 } 773 }
776 774
777 if (last_focus && warp) {
778 if (container && config->mouse_warping == WARP_CONTAINER) {
779 cursor_warp_to_container(seat->cursor, container);
780 cursor_send_pointer_motion(seat->cursor, 0, true);
781 } else if (new_output != last_output &&
782 config->mouse_warping >= WARP_OUTPUT) {
783 if (container) {
784 cursor_warp_to_container(seat->cursor, container);
785 } else {
786 cursor_warp_to_workspace(seat->cursor, new_workspace);
787 }
788 cursor_send_pointer_motion(seat->cursor, 0, true);
789 }
790 }
791
792 seat->has_focus = true; 775 seat->has_focus = true;
793 776
794 if (config->smart_gaps) { 777 if (config->smart_gaps) {
@@ -800,18 +783,14 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
800 update_debug_tree(); 783 update_debug_tree();
801} 784}
802 785
803void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
804 seat_set_focus_warp(seat, node, true);
805}
806
807void seat_set_focus_container(struct sway_seat *seat, 786void seat_set_focus_container(struct sway_seat *seat,
808 struct sway_container *con) { 787 struct sway_container *con) {
809 seat_set_focus_warp(seat, con ? &con->node : NULL, true); 788 seat_set_focus(seat, con ? &con->node : NULL);
810} 789}
811 790
812void seat_set_focus_workspace(struct sway_seat *seat, 791void seat_set_focus_workspace(struct sway_seat *seat,
813 struct sway_workspace *ws) { 792 struct sway_workspace *ws) {
814 seat_set_focus_warp(seat, ws ? &ws->node : NULL, true); 793 seat_set_focus(seat, ws ? &ws->node : NULL);
815} 794}
816 795
817void seat_set_focus_surface(struct sway_seat *seat, 796void seat_set_focus_surface(struct sway_seat *seat,