aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 13:08:45 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 13:08:45 -0400
commit5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc (patch)
tree75f4da71db52745ffd833e0bb7b110ff0044c084
parentmove output code out of the tree (diff)
downloadsway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.tar.gz
sway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.tar.zst
sway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.zip
unify workspace create functions
-rw-r--r--include/sway/tree/workspace.h2
-rw-r--r--sway/commands/move.c2
-rw-r--r--sway/commands/workspace.c6
-rw-r--r--sway/tree/container.c47
-rw-r--r--sway/tree/workspace.c33
5 files changed, 46 insertions, 44 deletions
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
index 4e4c3450..8d49fefb 100644
--- a/include/sway/tree/workspace.h
+++ b/include/sway/tree/workspace.h
@@ -7,8 +7,6 @@ extern char *prev_workspace_name;
7 7
8char *workspace_next_name(const char *output_name); 8char *workspace_next_name(const char *output_name);
9 9
10struct sway_container *workspace_create(const char *name);
11
12bool workspace_switch(struct sway_container *workspace); 10bool workspace_switch(struct sway_container *workspace);
13 11
14struct sway_container *workspace_by_number(const char* name); 12struct sway_container *workspace_by_number(const char* name);
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 644c622b..7ac5f009 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -74,7 +74,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
74 ws = workspace_by_name(ws_name); 74 ws = workspace_by_name(ws_name);
75 } 75 }
76 if (!ws) { 76 if (!ws) {
77 ws = workspace_create(ws_name ? ws_name : num_name); 77 ws = container_workspace_create(NULL, ws_name ? ws_name : num_name);
78 } 78 }
79 free(ws_name); 79 free(ws_name);
80 struct sway_container *old_parent = current->parent; 80 struct sway_container *old_parent = current->parent;
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index aa4096f7..a3702803 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -61,7 +61,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
61 if (strcasecmp(argv[0], "number") == 0) { 61 if (strcasecmp(argv[0], "number") == 0) {
62 if (!(ws = workspace_by_number(argv[1]))) { 62 if (!(ws = workspace_by_number(argv[1]))) {
63 char *name = join_args(argv + 1, argc - 1); 63 char *name = join_args(argv + 1, argc - 1);
64 ws = workspace_create(name); 64 ws = container_workspace_create(NULL, name);
65 free(name); 65 free(name);
66 } 66 }
67 } else if (strcasecmp(argv[0], "next") == 0) { 67 } else if (strcasecmp(argv[0], "next") == 0) {
@@ -80,12 +80,12 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
80 ws = old_workspace; 80 ws = old_workspace;
81 } else if (prev_workspace_name 81 } else if (prev_workspace_name
82 && !(ws = workspace_by_name(prev_workspace_name))) { 82 && !(ws = workspace_by_name(prev_workspace_name))) {
83 ws = workspace_create(prev_workspace_name); 83 ws = container_workspace_create(NULL, prev_workspace_name);
84 } 84 }
85 } else { 85 } else {
86 char *name = join_args(argv, argc); 86 char *name = join_args(argv, argc);
87 if (!(ws = workspace_by_name(name))) { 87 if (!(ws = workspace_by_name(name))) {
88 ws = workspace_create(name); 88 ws = container_workspace_create(NULL, name);
89 } 89 }
90 free(name); 90 free(name);
91 } 91 }
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 1c41bf5d..7ccd43ea 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -110,7 +110,8 @@ struct sway_container *container_finish(struct sway_container *cont) {
110 return parent; 110 return parent;
111} 111}
112 112
113static struct sway_container *container_output_destroy(struct sway_container *output) { 113static struct sway_container *container_output_destroy(
114 struct sway_container *output) {
114 if (!sway_assert(output, "cannot destroy null output")) { 115 if (!sway_assert(output, "cannot destroy null output")) {
115 return NULL; 116 return NULL;
116 } 117 }
@@ -245,7 +246,8 @@ struct sway_container *container_destroy(struct sway_container *con) {
245 break; 246 break;
246 case C_CONTAINER: 247 case C_CONTAINER:
247 if (con->children != NULL && con->children->length) { 248 if (con->children != NULL && con->children->length) {
248 assert(false && "dont destroy container containers with children"); 249 assert(false &&
250 "dont destroy container containers with children");
249 } 251 }
250 container_finish(con); 252 container_finish(con);
251 // TODO return parent to arrange maybe? 253 // TODO return parent to arrange maybe?
@@ -271,7 +273,8 @@ static void container_close_func(struct sway_container *container, void *data) {
271} 273}
272 274
273struct sway_container *container_close(struct sway_container *con) { 275struct sway_container *container_close(struct sway_container *con) {
274 if (!sway_assert(con != NULL, "container_close called with a NULL container")) { 276 if (!sway_assert(con != NULL,
277 "container_close called with a NULL container")) {
275 return NULL; 278 return NULL;
276 } 279 }
277 280
@@ -359,12 +362,39 @@ struct sway_container *container_output_create(
359 return output; 362 return output;
360} 363}
361 364
362struct sway_container *container_workspace_create( 365static struct sway_container *workspace_get_initial_output(const char *name) {
363 struct sway_container *output, const char *name) { 366 struct sway_container *parent;
364 if (!sway_assert(output, 367 // Search for workspace<->output pair
365 "container_workspace_create called with null output")) { 368 int i, e = config->workspace_outputs->length;
366 return NULL; 369 for (i = 0; i < e; ++i) {
370 struct workspace_output *wso = config->workspace_outputs->items[i];
371 if (strcasecmp(wso->workspace, name) == 0) {
372 // Find output to use if it exists
373 e = root_container.children->length;
374 for (i = 0; i < e; ++i) {
375 parent = root_container.children->items[i];
376 if (strcmp(parent->name, wso->output) == 0) {
377 return parent;
378 }
379 }
380 break;
381 }
367 } 382 }
383 // Otherwise put it on the focused output
384 struct sway_seat *seat = input_manager_current_seat(input_manager);
385 struct sway_container *focus =
386 seat_get_focus_inactive(seat, &root_container);
387 parent = focus;
388 parent = container_parent(parent, C_OUTPUT);
389 return parent;
390}
391
392struct sway_container *container_workspace_create(struct sway_container *output,
393 const char *name) {
394 if (output == NULL) {
395 output = workspace_get_initial_output(name);
396 }
397
368 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 398 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
369 struct sway_container *workspace = container_create(C_WORKSPACE); 399 struct sway_container *workspace = container_create(C_WORKSPACE);
370 400
@@ -380,6 +410,7 @@ struct sway_container *container_workspace_create(
380 container_add_child(output, workspace); 410 container_add_child(output, workspace);
381 container_sort_workspaces(output); 411 container_sort_workspaces(output);
382 notify_new_container(workspace); 412 notify_new_container(workspace);
413
383 return workspace; 414 return workspace;
384} 415}
385 416
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 7d180009..d5a16410 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -179,35 +179,6 @@ struct sway_container *workspace_by_name(const char *name) {
179 } 179 }
180} 180}
181 181
182struct sway_container *workspace_create(const char *name) {
183 struct sway_container *parent;
184 // Search for workspace<->output pair
185 int i, e = config->workspace_outputs->length;
186 for (i = 0; i < e; ++i) {
187 struct workspace_output *wso = config->workspace_outputs->items[i];
188 if (strcasecmp(wso->workspace, name) == 0) {
189 // Find output to use if it exists
190 e = root_container.children->length;
191 for (i = 0; i < e; ++i) {
192 parent = root_container.children->items[i];
193 if (strcmp(parent->name, wso->output) == 0) {
194 return container_workspace_create(parent, name);
195 }
196 }
197 break;
198 }
199 }
200 // Otherwise create a new one
201 struct sway_seat *seat = input_manager_current_seat(input_manager);
202 struct sway_container *focus =
203 seat_get_focus_inactive(seat, &root_container);
204 parent = focus;
205 parent = container_parent(parent, C_OUTPUT);
206 struct sway_container *new_ws = container_workspace_create(parent, name);
207 ipc_event_workspace(NULL, new_ws, "init");
208 return new_ws;
209}
210
211/** 182/**
212 * Get the previous or next workspace on the specified output. Wraps around at 183 * Get the previous or next workspace on the specified output. Wraps around at
213 * the end and beginning. If next is false, the previous workspace is returned, 184 * the end and beginning. If next is false, the previous workspace is returned,
@@ -319,7 +290,9 @@ bool workspace_switch(struct sway_container *workspace) {
319 && active_ws == workspace 290 && active_ws == workspace
320 && prev_workspace_name) { 291 && prev_workspace_name) {
321 struct sway_container *new_ws = workspace_by_name(prev_workspace_name); 292 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
322 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); 293 workspace = new_ws ?
294 new_ws :
295 container_workspace_create(NULL, prev_workspace_name);
323 } 296 }
324 297
325 if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name) 298 if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name)