aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-01-17 20:16:23 +1000
committerLibravatar emersion <contact@emersion.fr>2019-01-22 09:55:13 +0100
commit2301349ad59751640ed9e59dd22edeafaf09da39 (patch)
tree1726c2f8ec1cd9baaf27fbed62aa6a337bc85ce7 /sway/tree
parentseat_create: set initial focus for added seats (diff)
downloadsway-2301349ad59751640ed9e59dd22edeafaf09da39.tar.gz
sway-2301349ad59751640ed9e59dd22edeafaf09da39.tar.zst
sway-2301349ad59751640ed9e59dd22edeafaf09da39.zip
Use noop output when there's no outputs connected
Instead of having NULL workspace->output pointers, use a noop output. This should be safer.
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/output.c21
-rw-r--r--sway/tree/root.c10
-rw-r--r--sway/tree/view.c7
-rw-r--r--sway/tree/workspace.c6
4 files changed, 18 insertions, 26 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 50a2c535..5a992f2d 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -57,12 +57,12 @@ static void restore_workspaces(struct sway_output *output) {
57 } 57 }
58 58
59 // Saved workspaces 59 // Saved workspaces
60 for (int i = 0; i < root->saved_workspaces->length; ++i) { 60 while (root->noop_output->workspaces->length) {
61 struct sway_workspace *ws = root->saved_workspaces->items[i]; 61 struct sway_workspace *ws = root->noop_output->workspaces->items[0];
62 workspace_detach(ws);
62 output_add_workspace(output, ws); 63 output_add_workspace(output, ws);
63 ipc_event_workspace(NULL, ws, "move"); 64 ipc_event_workspace(NULL, ws, "move");
64 } 65 }
65 root->saved_workspaces->length = 0;
66 66
67 output_sort_workspaces(output); 67 output_sort_workspaces(output);
68} 68}
@@ -177,6 +177,9 @@ static void output_evacuate(struct sway_output *output) {
177 if (!new_output) { 177 if (!new_output) {
178 new_output = fallback_output; 178 new_output = fallback_output;
179 } 179 }
180 if (!new_output) {
181 new_output = root->noop_output;
182 }
180 183
181 if (workspace_is_empty(workspace)) { 184 if (workspace_is_empty(workspace)) {
182 // If floating is not empty, there are sticky containers to move 185 // If floating is not empty, there are sticky containers to move
@@ -187,14 +190,10 @@ static void output_evacuate(struct sway_output *output) {
187 continue; 190 continue;
188 } 191 }
189 192
190 if (new_output) { 193 workspace_output_add_priority(workspace, new_output);
191 workspace_output_add_priority(workspace, new_output); 194 output_add_workspace(new_output, workspace);
192 output_add_workspace(new_output, workspace); 195 output_sort_workspaces(new_output);
193 output_sort_workspaces(new_output); 196 ipc_event_workspace(NULL, workspace, "move");
194 ipc_event_workspace(NULL, workspace, "move");
195 } else {
196 list_add(root->saved_workspaces, workspace);
197 }
198 } 197 }
199} 198}
200 199
diff --git a/sway/tree/root.c b/sway/tree/root.c
index d4b97be3..ec6bccf6 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -39,7 +39,6 @@ struct sway_root *root_create(void) {
39 wl_signal_init(&root->events.new_node); 39 wl_signal_init(&root->events.new_node);
40 root->outputs = create_list(); 40 root->outputs = create_list();
41 root->scratchpad = create_list(); 41 root->scratchpad = create_list();
42 root->saved_workspaces = create_list();
43 42
44 root->output_layout_change.notify = output_layout_handle_change; 43 root->output_layout_change.notify = output_layout_handle_change;
45 wl_signal_add(&root->output_layout->events.change, 44 wl_signal_add(&root->output_layout->events.change,
@@ -50,7 +49,6 @@ struct sway_root *root_create(void) {
50void root_destroy(struct sway_root *root) { 49void root_destroy(struct sway_root *root) {
51 wl_list_remove(&root->output_layout_change.link); 50 wl_list_remove(&root->output_layout_change.link);
52 list_free(root->scratchpad); 51 list_free(root->scratchpad);
53 list_free(root->saved_workspaces);
54 list_free(root->outputs); 52 list_free(root->outputs);
55 wlr_output_layout_destroy(root->output_layout); 53 wlr_output_layout_destroy(root->output_layout);
56 free(root); 54 free(root);
@@ -327,8 +325,8 @@ void root_for_each_container(void (*f)(struct sway_container *con, void *data),
327 } 325 }
328 326
329 // Saved workspaces 327 // Saved workspaces
330 for (int i = 0; i < root->saved_workspaces->length; ++i) { 328 for (int i = 0; i < root->noop_output->workspaces->length; ++i) {
331 struct sway_workspace *ws = root->saved_workspaces->items[i]; 329 struct sway_workspace *ws = root->noop_output->workspaces->items[i];
332 workspace_for_each_container(ws, f, data); 330 workspace_for_each_container(ws, f, data);
333 } 331 }
334} 332}
@@ -380,8 +378,8 @@ struct sway_container *root_find_container(
380 } 378 }
381 379
382 // Saved workspaces 380 // Saved workspaces
383 for (int i = 0; i < root->saved_workspaces->length; ++i) { 381 for (int i = 0; i < root->noop_output->workspaces->length; ++i) {
384 struct sway_workspace *ws = root->saved_workspaces->items[i]; 382 struct sway_workspace *ws = root->noop_output->workspaces->items[i];
385 if ((result = workspace_find_container(ws, test, data))) { 383 if ((result = workspace_find_container(ws, test, data))) {
386 return result; 384 return result;
387 } 385 }
diff --git a/sway/tree/view.c b/sway/tree/view.c
index bc252521..edbfca97 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -518,9 +518,10 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
518 return node->sway_container->workspace; 518 return node->sway_container->workspace;
519 } 519 }
520 520
521 // If there's no focus_inactive workspace then we must be running without 521 // When there's no outputs connected, the above should match a workspace on
522 // any outputs connected 522 // the noop output.
523 return root->saved_workspaces->items[0]; 523 sway_assert(false, "Expected to find a workspace");
524 return NULL;
524} 525}
525 526
526static bool should_focus(struct sway_view *view) { 527static bool should_focus(struct sway_view *view) {
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index e89c0849..8b3eb2ad 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -158,13 +158,7 @@ void workspace_begin_destroy(struct sway_workspace *workspace) {
158 158
159 if (workspace->output) { 159 if (workspace->output) {
160 workspace_detach(workspace); 160 workspace_detach(workspace);
161 } else {
162 int index = list_find(root->saved_workspaces, workspace);
163 if (index != -1) {
164 list_del(root->saved_workspaces, index);
165 }
166 } 161 }
167
168 workspace->node.destroying = true; 162 workspace->node.destroying = true;
169 node_set_dirty(&workspace->node); 163 node_set_dirty(&workspace->node);
170} 164}