aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 19:52:17 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 19:52:17 -0400
commita001890fb8a9fc8c7f0b8eac03ca5912be2de479 (patch)
tree2127025dfa5c7cfed6e75188d38ffdda448f9163 /sway/tree/workspace.c
parentmove output damage to workspace destructor (diff)
downloadsway-a001890fb8a9fc8c7f0b8eac03ca5912be2de479.tar.gz
sway-a001890fb8a9fc8c7f0b8eac03ca5912be2de479.tar.zst
sway-a001890fb8a9fc8c7f0b8eac03ca5912be2de479.zip
move workspace create to workspace.c
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index d5a16410..6ba3d973 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -14,6 +14,58 @@
14#include "log.h" 14#include "log.h"
15#include "util.h" 15#include "util.h"
16 16
17static struct sway_container *get_workspace_initial_output(const char *name) {
18 struct sway_container *parent;
19 // Search for workspace<->output pair
20 int e = config->workspace_outputs->length;
21 for (int i = 0; i < config->workspace_outputs->length; ++i) {
22 struct workspace_output *wso = config->workspace_outputs->items[i];
23 if (strcasecmp(wso->workspace, name) == 0) {
24 // Find output to use if it exists
25 e = root_container.children->length;
26 for (i = 0; i < e; ++i) {
27 parent = root_container.children->items[i];
28 if (strcmp(parent->name, wso->output) == 0) {
29 return parent;
30 }
31 }
32 break;
33 }
34 }
35 // Otherwise put it on the focused output
36 struct sway_seat *seat = input_manager_current_seat(input_manager);
37 struct sway_container *focus =
38 seat_get_focus_inactive(seat, &root_container);
39 parent = focus;
40 parent = container_parent(parent, C_OUTPUT);
41 return parent;
42}
43
44struct sway_container *workspace_create(struct sway_container *output,
45 const char *name) {
46 if (output == NULL) {
47 output = get_workspace_initial_output(name);
48 }
49
50 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
51 struct sway_container *workspace = container_create(C_WORKSPACE);
52
53 workspace->x = output->x;
54 workspace->y = output->y;
55 workspace->width = output->width;
56 workspace->height = output->height;
57 workspace->name = !name ? NULL : strdup(name);
58 workspace->prev_layout = L_NONE;
59 workspace->layout = container_get_default_layout(output);
60 workspace->workspace_layout = workspace->layout;
61
62 container_add_child(output, workspace);
63 container_sort_workspaces(output);
64 container_create_notify(workspace);
65
66 return workspace;
67}
68
17char *prev_workspace_name = NULL; 69char *prev_workspace_name = NULL;
18struct workspace_by_number_data { 70struct workspace_by_number_data {
19 int len; 71 int len;
@@ -292,7 +344,7 @@ bool workspace_switch(struct sway_container *workspace) {
292 struct sway_container *new_ws = workspace_by_name(prev_workspace_name); 344 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
293 workspace = new_ws ? 345 workspace = new_ws ?
294 new_ws : 346 new_ws :
295 container_workspace_create(NULL, prev_workspace_name); 347 workspace_create(NULL, prev_workspace_name);
296 } 348 }
297 349
298 if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name) 350 if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name)