aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c64
1 files changed, 57 insertions, 7 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index e205fbcf..5df10bcb 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -2,10 +2,13 @@
2#include <stdint.h> 2#include <stdint.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
5#include <strings.h>
5#include <wlr/types/wlr_output_layout.h> 6#include <wlr/types/wlr_output_layout.h>
7#include "sway/config.h"
6#include "sway/container.h" 8#include "sway/container.h"
7#include "sway/layout.h" 9#include "sway/layout.h"
8#include "sway/output.h" 10#include "sway/output.h"
11#include "sway/server.h"
9#include "sway/view.h" 12#include "sway/view.h"
10#include "sway/workspace.h" 13#include "sway/workspace.h"
11#include "log.h" 14#include "log.h"
@@ -44,19 +47,38 @@ static swayc_t *new_swayc(enum swayc_types type) {
44 47
45swayc_t *new_output(struct sway_output *sway_output) { 48swayc_t *new_output(struct sway_output *sway_output) {
46 struct wlr_box size; 49 struct wlr_box size;
47 wlr_output_effective_resolution( 50 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
48 sway_output->wlr_output, &size.width, &size.height); 51 &size.height);
49 const char *name = sway_output->wlr_output->name; 52 const char *name = sway_output->wlr_output->name;
50 53
54 struct output_config *oc = NULL, *all = NULL;
55 for (int i = 0; i < config->output_configs->length; ++i) {
56 struct output_config *cur = config->output_configs->items[i];
57 if (strcasecmp(name, cur->name) == 0) {
58 sway_log(L_DEBUG, "Matched output config for %s", name);
59 oc = cur;
60 }
61 if (strcasecmp("*", cur->name) == 0) {
62 sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
63 all = cur;
64 }
65
66 if (oc && all) {
67 break;
68 }
69 }
70 if (!oc) {
71 oc = all;
72 }
73 if (oc && !oc->enabled) {
74 return NULL;
75 }
76
51 swayc_t *output = new_swayc(C_OUTPUT); 77 swayc_t *output = new_swayc(C_OUTPUT);
52 output->sway_output = sway_output; 78 output->sway_output = sway_output;
53 output->name = name ? strdup(name) : NULL; 79 output->name = name ? strdup(name) : NULL;
54 output->width = size.width;
55 output->height = size.width;
56 80
57 // TODO configure output layout position 81 apply_output_config(oc, output);
58 wlr_output_layout_add_auto(root_container.output_layout,
59 sway_output->wlr_output);
60 82
61 add_child(&root_container, output); 83 add_child(&root_container, output);
62 84
@@ -139,6 +161,34 @@ static void free_swayc(swayc_t *cont) {
139 free(cont); 161 free(cont);
140} 162}
141 163
164swayc_t *destroy_output(swayc_t *output) {
165 if (!sway_assert(output, "null output passed to destroy_output")) {
166 return NULL;
167 }
168
169 if (output->children->length > 0) {
170 // TODO save workspaces when there are no outputs.
171 // TODO also check if there will ever be no outputs except for exiting
172 // program
173 if (root_container.children->length > 1) {
174 int p = root_container.children->items[0] == output;
175 // Move workspace from this output to another output
176 while (output->children->length) {
177 swayc_t *child = output->children->items[0];
178 remove_child(child);
179 add_child(root_container.children->items[p], child);
180 }
181 sort_workspaces(root_container.children->items[p]);
182 arrange_windows(root_container.children->items[p], -1, -1);
183 }
184 }
185
186 sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
187 free_swayc(output);
188
189 return &root_container;
190}
191
142swayc_t *destroy_view(swayc_t *view) { 192swayc_t *destroy_view(swayc_t *view) {
143 if (!sway_assert(view, "null view passed to destroy_view")) { 193 if (!sway_assert(view, "null view passed to destroy_view")) {
144 return NULL; 194 return NULL;