aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-06 19:26:56 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-06 19:26:56 +1000
commit908095ef9a479cafaf7d815824f243b4576ff1bb (patch)
tree812b58eae73d0816610e93c6595facb42b141536 /sway/commands
parentMerge pull request #2578 from RyanDwyer/fix-binding-reload (diff)
downloadsway-908095ef9a479cafaf7d815824f243b4576ff1bb.tar.gz
sway-908095ef9a479cafaf7d815824f243b4576ff1bb.tar.zst
sway-908095ef9a479cafaf7d815824f243b4576ff1bb.zip
Introduce seat_set_focus_container and seat_set_focus_workspace
These are the same as seat_set_focus, but accept a specific type rather than using nodes. Doing this adds more typesafety and lets us avoid using &con->node which looks a little ugly. This fixes a crash that pretty much nobody would ever come across. If you have a bindsym for "focus" with no arguments and run it from an empty workspace, sway would crash because it assumes `container` is not NULL.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/floating.c2
-rw-r--r--sway/commands/focus.c6
-rw-r--r--sway/commands/fullscreen.c2
-rw-r--r--sway/commands/move.c7
-rw-r--r--sway/commands/swap.c10
5 files changed, 14 insertions, 13 deletions
diff --git a/sway/commands/floating.c b/sway/commands/floating.c
index d8729094..97662a18 100644
--- a/sway/commands/floating.c
+++ b/sway/commands/floating.c
@@ -25,7 +25,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
25 // Wrap the workspace's children in a container so we can float it 25 // Wrap the workspace's children in a container so we can float it
26 container = workspace_wrap_children(workspace); 26 container = workspace_wrap_children(workspace);
27 workspace->layout = L_HORIZ; 27 workspace->layout = L_HORIZ;
28 seat_set_focus(config->handler_context.seat, &container->node); 28 seat_set_focus_container(config->handler_context.seat, container);
29 } 29 }
30 30
31 // If the container is in a floating split container, 31 // If the container is in a floating split container,
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 58721b7e..668a0c7b 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -179,7 +179,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
179 new_focus = seat_get_focus_inactive_tiling(seat, ws); 179 new_focus = seat_get_focus_inactive_tiling(seat, ws);
180 } 180 }
181 if (new_focus) { 181 if (new_focus) {
182 seat_set_focus(seat, &new_focus->node); 182 seat_set_focus_container(seat, new_focus);
183 } else { 183 } else {
184 return cmd_results_new(CMD_FAILURE, "focus", 184 return cmd_results_new(CMD_FAILURE, "focus",
185 "Failed to find a %s container in workspace", 185 "Failed to find a %s container in workspace",
@@ -230,8 +230,8 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
230 "Command 'focus' cannot be used above the workspace level"); 230 "Command 'focus' cannot be used above the workspace level");
231 } 231 }
232 232
233 if (argc == 0) { 233 if (argc == 0 && container) {
234 seat_set_focus(seat, node); 234 seat_set_focus_container(seat, container);
235 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 235 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
236 } 236 }
237 237
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c
index 3bbe00c5..22d747b9 100644
--- a/sway/commands/fullscreen.c
+++ b/sway/commands/fullscreen.c
@@ -23,7 +23,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
23 // Wrap the workspace's children in a container so we can fullscreen it 23 // Wrap the workspace's children in a container so we can fullscreen it
24 container = workspace_wrap_children(workspace); 24 container = workspace_wrap_children(workspace);
25 workspace->layout = L_HORIZ; 25 workspace->layout = L_HORIZ;
26 seat_set_focus(config->handler_context.seat, &container->node); 26 seat_set_focus_container(config->handler_context.seat, container);
27 } 27 }
28 bool enable = !container->is_fullscreen; 28 bool enable = !container->is_fullscreen;
29 29
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 59f1cf78..2e9c00f8 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -624,7 +624,7 @@ static void workspace_move_to_output(struct sway_workspace *workspace,
624 char *ws_name = workspace_next_name(old_output->wlr_output->name); 624 char *ws_name = workspace_next_name(old_output->wlr_output->name);
625 struct sway_workspace *ws = workspace_create(old_output, ws_name); 625 struct sway_workspace *ws = workspace_create(old_output, ws_name);
626 free(ws_name); 626 free(ws_name);
627 seat_set_focus(seat, &ws->node); 627 seat_set_focus_workspace(seat, ws);
628 } 628 }
629 629
630 workspace_consider_destroy(new_output_old_ws); 630 workspace_consider_destroy(new_output_old_ws);
@@ -734,8 +734,9 @@ static struct cmd_results *cmd_move_in_direction(
734 ipc_event_window(container, "move"); 734 ipc_event_window(container, "move");
735 } 735 }
736 736
737 seat_set_focus(config->handler_context.seat, &new_ws->node); 737 // Hack to re-focus container
738 seat_set_focus(config->handler_context.seat, &container->node); 738 seat_set_focus_workspace(config->handler_context.seat, new_ws);
739 seat_set_focus_container(config->handler_context.seat, container);
739 740
740 if (old_ws != new_ws) { 741 if (old_ws != new_ws) {
741 ipc_event_workspace(old_ws, new_ws, "focus"); 742 ipc_event_workspace(old_ws, new_ws, "focus");
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index a0ffbda8..e7f9cbea 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -52,20 +52,20 @@ static void swap_focus(struct sway_container *con1,
52 if (workspace_is_visible(ws2)) { 52 if (workspace_is_visible(ws2)) {
53 seat_set_focus_warp(seat, &con2->node, false, true); 53 seat_set_focus_warp(seat, &con2->node, false, true);
54 } 54 }
55 seat_set_focus(seat, ws1 != ws2 ? &con2->node : &con1->node); 55 seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1);
56 } else if (focus == con2 && (layout1 == L_TABBED 56 } else if (focus == con2 && (layout1 == L_TABBED
57 || layout1 == L_STACKED)) { 57 || layout1 == L_STACKED)) {
58 if (workspace_is_visible(ws1)) { 58 if (workspace_is_visible(ws1)) {
59 seat_set_focus_warp(seat, &con1->node, false, true); 59 seat_set_focus_warp(seat, &con1->node, false, true);
60 } 60 }
61 seat_set_focus(seat, ws1 != ws2 ? &con1->node : &con2->node); 61 seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2);
62 } else if (ws1 != ws2) { 62 } else if (ws1 != ws2) {
63 seat_set_focus(seat, focus == con1 ? &con2->node : &con1->node); 63 seat_set_focus_container(seat, focus == con1 ? con2 : con1);
64 } else { 64 } else {
65 seat_set_focus(seat, &focus->node); 65 seat_set_focus_container(seat, focus);
66 } 66 }
67 } else { 67 } else {
68 seat_set_focus(seat, &focus->node); 68 seat_set_focus_container(seat, focus);
69 } 69 }
70} 70}
71 71