mirror of
https://github.com/swaywm/sway.git
synced 2025-11-25 06:59:48 -05:00
Use noop output when there's no outputs connected
Instead of having NULL workspace->output pointers, use a noop output. This should be safer.
This commit is contained in:
parent
ab0248a545
commit
2301349ad5
8 changed files with 29 additions and 28 deletions
|
|
@ -57,12 +57,12 @@ static void restore_workspaces(struct sway_output *output) {
|
|||
}
|
||||
|
||||
// Saved workspaces
|
||||
for (int i = 0; i < root->saved_workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->saved_workspaces->items[i];
|
||||
while (root->noop_output->workspaces->length) {
|
||||
struct sway_workspace *ws = root->noop_output->workspaces->items[0];
|
||||
workspace_detach(ws);
|
||||
output_add_workspace(output, ws);
|
||||
ipc_event_workspace(NULL, ws, "move");
|
||||
}
|
||||
root->saved_workspaces->length = 0;
|
||||
|
||||
output_sort_workspaces(output);
|
||||
}
|
||||
|
|
@ -177,6 +177,9 @@ static void output_evacuate(struct sway_output *output) {
|
|||
if (!new_output) {
|
||||
new_output = fallback_output;
|
||||
}
|
||||
if (!new_output) {
|
||||
new_output = root->noop_output;
|
||||
}
|
||||
|
||||
if (workspace_is_empty(workspace)) {
|
||||
// If floating is not empty, there are sticky containers to move
|
||||
|
|
@ -187,14 +190,10 @@ static void output_evacuate(struct sway_output *output) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (new_output) {
|
||||
workspace_output_add_priority(workspace, new_output);
|
||||
output_add_workspace(new_output, workspace);
|
||||
output_sort_workspaces(new_output);
|
||||
ipc_event_workspace(NULL, workspace, "move");
|
||||
} else {
|
||||
list_add(root->saved_workspaces, workspace);
|
||||
}
|
||||
workspace_output_add_priority(workspace, new_output);
|
||||
output_add_workspace(new_output, workspace);
|
||||
output_sort_workspaces(new_output);
|
||||
ipc_event_workspace(NULL, workspace, "move");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ struct sway_root *root_create(void) {
|
|||
wl_signal_init(&root->events.new_node);
|
||||
root->outputs = create_list();
|
||||
root->scratchpad = create_list();
|
||||
root->saved_workspaces = create_list();
|
||||
|
||||
root->output_layout_change.notify = output_layout_handle_change;
|
||||
wl_signal_add(&root->output_layout->events.change,
|
||||
|
|
@ -50,7 +49,6 @@ struct sway_root *root_create(void) {
|
|||
void root_destroy(struct sway_root *root) {
|
||||
wl_list_remove(&root->output_layout_change.link);
|
||||
list_free(root->scratchpad);
|
||||
list_free(root->saved_workspaces);
|
||||
list_free(root->outputs);
|
||||
wlr_output_layout_destroy(root->output_layout);
|
||||
free(root);
|
||||
|
|
@ -327,8 +325,8 @@ void root_for_each_container(void (*f)(struct sway_container *con, void *data),
|
|||
}
|
||||
|
||||
// Saved workspaces
|
||||
for (int i = 0; i < root->saved_workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->saved_workspaces->items[i];
|
||||
for (int i = 0; i < root->noop_output->workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->noop_output->workspaces->items[i];
|
||||
workspace_for_each_container(ws, f, data);
|
||||
}
|
||||
}
|
||||
|
|
@ -380,8 +378,8 @@ struct sway_container *root_find_container(
|
|||
}
|
||||
|
||||
// Saved workspaces
|
||||
for (int i = 0; i < root->saved_workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->saved_workspaces->items[i];
|
||||
for (int i = 0; i < root->noop_output->workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->noop_output->workspaces->items[i];
|
||||
if ((result = workspace_find_container(ws, test, data))) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -518,9 +518,10 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
|
|||
return node->sway_container->workspace;
|
||||
}
|
||||
|
||||
// If there's no focus_inactive workspace then we must be running without
|
||||
// any outputs connected
|
||||
return root->saved_workspaces->items[0];
|
||||
// When there's no outputs connected, the above should match a workspace on
|
||||
// the noop output.
|
||||
sway_assert(false, "Expected to find a workspace");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool should_focus(struct sway_view *view) {
|
||||
|
|
|
|||
|
|
@ -158,13 +158,7 @@ void workspace_begin_destroy(struct sway_workspace *workspace) {
|
|||
|
||||
if (workspace->output) {
|
||||
workspace_detach(workspace);
|
||||
} else {
|
||||
int index = list_find(root->saved_workspaces, workspace);
|
||||
if (index != -1) {
|
||||
list_del(root->saved_workspaces, index);
|
||||
}
|
||||
}
|
||||
|
||||
workspace->node.destroying = true;
|
||||
node_set_dirty(&workspace->node);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue