aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
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
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')
-rw-r--r--sway/tree/container.c62
-rw-r--r--sway/tree/layout.c2
-rw-r--r--sway/tree/workspace.c54
3 files changed, 59 insertions, 59 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index fdbb2922..8ed30b44 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -51,7 +51,7 @@ const char *container_type_to_str(enum sway_container_type type) {
51 } 51 }
52} 52}
53 53
54static void notify_new_container(struct sway_container *container) { 54void container_create_notify(struct sway_container *container) {
55 wl_signal_emit(&root_container.sway_root->events.new_container, container); 55 wl_signal_emit(&root_container.sway_root->events.new_container, container);
56 ipc_event_window(container, "new"); 56 ipc_event_window(container, "new");
57} 57}
@@ -312,7 +312,7 @@ struct sway_container *container_close(struct sway_container *con) {
312 return parent; 312 return parent;
313} 313}
314 314
315struct sway_container *container_output_create( 315struct sway_container *output_create(
316 struct sway_output *sway_output) { 316 struct sway_output *sway_output) {
317 struct wlr_box size; 317 struct wlr_box size;
318 wlr_output_effective_resolution(sway_output->wlr_output, &size.width, 318 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
@@ -363,7 +363,7 @@ struct sway_container *container_output_create(
363 // Create workspace 363 // Create workspace
364 char *ws_name = workspace_next_name(output->name); 364 char *ws_name = workspace_next_name(output->name);
365 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); 365 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name);
366 struct sway_container *ws = container_workspace_create(output, ws_name); 366 struct sway_container *ws = workspace_create(output, ws_name);
367 // Set each seat's focus if not already set 367 // Set each seat's focus if not already set
368 struct sway_seat *seat = NULL; 368 struct sway_seat *seat = NULL;
369 wl_list_for_each(seat, &input_manager->seats, link) { 369 wl_list_for_each(seat, &input_manager->seats, link) {
@@ -373,62 +373,10 @@ struct sway_container *container_output_create(
373 } 373 }
374 374
375 free(ws_name); 375 free(ws_name);
376 notify_new_container(output); 376 container_create_notify(output);
377 return output; 377 return output;
378} 378}
379 379
380static struct sway_container *get_workspace_initial_output(const char *name) {
381 struct sway_container *parent;
382 // Search for workspace<->output pair
383 int e = config->workspace_outputs->length;
384 for (int i = 0; i < config->workspace_outputs->length; ++i) {
385 struct workspace_output *wso = config->workspace_outputs->items[i];
386 if (strcasecmp(wso->workspace, name) == 0) {
387 // Find output to use if it exists
388 e = root_container.children->length;
389 for (i = 0; i < e; ++i) {
390 parent = root_container.children->items[i];
391 if (strcmp(parent->name, wso->output) == 0) {
392 return parent;
393 }
394 }
395 break;
396 }
397 }
398 // Otherwise put it on the focused output
399 struct sway_seat *seat = input_manager_current_seat(input_manager);
400 struct sway_container *focus =
401 seat_get_focus_inactive(seat, &root_container);
402 parent = focus;
403 parent = container_parent(parent, C_OUTPUT);
404 return parent;
405}
406
407struct sway_container *container_workspace_create(struct sway_container *output,
408 const char *name) {
409 if (output == NULL) {
410 output = get_workspace_initial_output(name);
411 }
412
413 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
414 struct sway_container *workspace = container_create(C_WORKSPACE);
415
416 workspace->x = output->x;
417 workspace->y = output->y;
418 workspace->width = output->width;
419 workspace->height = output->height;
420 workspace->name = !name ? NULL : strdup(name);
421 workspace->prev_layout = L_NONE;
422 workspace->layout = container_get_default_layout(output);
423 workspace->workspace_layout = workspace->layout;
424
425 container_add_child(output, workspace);
426 container_sort_workspaces(output);
427 notify_new_container(workspace);
428
429 return workspace;
430}
431
432struct sway_container *container_view_create(struct sway_container *sibling, 380struct sway_container *container_view_create(struct sway_container *sibling,
433 struct sway_view *sway_view) { 381 struct sway_view *sway_view) {
434 if (!sway_assert(sibling, 382 if (!sway_assert(sibling,
@@ -452,7 +400,7 @@ struct sway_container *container_view_create(struct sway_container *sibling,
452 // Regular case, create as sibling of current container 400 // Regular case, create as sibling of current container
453 container_add_sibling(sibling, swayc); 401 container_add_sibling(sibling, swayc);
454 } 402 }
455 notify_new_container(swayc); 403 container_create_notify(swayc);
456 return swayc; 404 return swayc;
457} 405}
458 406
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 3cbbf3b4..a46359bd 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -149,7 +149,7 @@ void container_move_to(struct sway_container *container,
149 if (old_parent->children->length == 0) { 149 if (old_parent->children->length == 0) {
150 char *ws_name = workspace_next_name(old_parent->name); 150 char *ws_name = workspace_next_name(old_parent->name);
151 struct sway_container *ws = 151 struct sway_container *ws =
152 container_workspace_create(old_parent, ws_name); 152 workspace_create(old_parent, ws_name);
153 free(ws_name); 153 free(ws_name);
154 seat_set_focus(seat, ws); 154 seat_set_focus(seat, ws);
155 } 155 }
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)