aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2017-12-06 12:36:06 +0100
committerLibravatar emersion <contact@emersion.fr>2017-12-06 12:36:06 +0100
commitaaae59026ff3751190b93277ac6d7566e373c892 (patch)
tree2dc365f9ceeb6a08a98e08d2f79fcc940624b199 /sway/tree/container.c
parentMerge pull request #1498 from emersion/config (diff)
downloadsway-aaae59026ff3751190b93277ac6d7566e373c892.tar.gz
sway-aaae59026ff3751190b93277ac6d7566e373c892.tar.zst
sway-aaae59026ff3751190b93277ac6d7566e373c892.zip
Add output config
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c83
1 files changed, 81 insertions, 2 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index e205fbcf..7720718f 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -2,7 +2,9 @@
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"
@@ -23,6 +25,30 @@ void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
23 } 25 }
24} 26}
25 27
28static void update_root_geometry() {
29 int width = 0;
30 int height = 0;
31 swayc_t *child;
32 int child_width;
33 int child_height;
34
35 for (int i = 0; i < root_container.children->length; ++i) {
36 child = root_container.children->items[i];
37 child_width = child->width + child->x;
38 child_height = child->height + child->y;
39 if (child_width > width) {
40 width = child_width;
41 }
42
43 if (child_height > height) {
44 height = child_height;
45 }
46 }
47
48 root_container.width = width;
49 root_container.height = height;
50}
51
26static swayc_t *new_swayc(enum swayc_types type) { 52static swayc_t *new_swayc(enum swayc_types type) {
27 // next id starts at 1 because 0 is assigned to root_container in layout.c 53 // next id starts at 1 because 0 is assigned to root_container in layout.c
28 static size_t next_id = 1; 54 static size_t next_id = 1;
@@ -44,10 +70,33 @@ static swayc_t *new_swayc(enum swayc_types type) {
44 70
45swayc_t *new_output(struct sway_output *sway_output) { 71swayc_t *new_output(struct sway_output *sway_output) {
46 struct wlr_box size; 72 struct wlr_box size;
47 wlr_output_effective_resolution( 73 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
48 sway_output->wlr_output, &size.width, &size.height); 74 &size.height);
49 const char *name = sway_output->wlr_output->name; 75 const char *name = sway_output->wlr_output->name;
50 76
77 struct output_config *oc = NULL, *all = NULL;
78 for (int i = 0; i < config->output_configs->length; ++i) {
79 struct output_config *cur = config->output_configs->items[i];
80 if (strcasecmp(name, cur->name) == 0) {
81 sway_log(L_DEBUG, "Matched output config for %s", name);
82 oc = cur;
83 }
84 if (strcasecmp("*", cur->name) == 0) {
85 sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
86 all = cur;
87 }
88
89 if (oc && all) {
90 break;
91 }
92 }
93 if (!oc) {
94 oc = all;
95 }
96 if (oc && !oc->enabled) {
97 return NULL;
98 }
99
51 swayc_t *output = new_swayc(C_OUTPUT); 100 swayc_t *output = new_swayc(C_OUTPUT);
52 output->sway_output = sway_output; 101 output->sway_output = sway_output;
53 output->name = name ? strdup(name) : NULL; 102 output->name = name ? strdup(name) : NULL;
@@ -58,6 +107,8 @@ swayc_t *new_output(struct sway_output *sway_output) {
58 wlr_output_layout_add_auto(root_container.output_layout, 107 wlr_output_layout_add_auto(root_container.output_layout,
59 sway_output->wlr_output); 108 sway_output->wlr_output);
60 109
110 apply_output_config(oc, output);
111
61 add_child(&root_container, output); 112 add_child(&root_container, output);
62 113
63 // Create workspace 114 // Create workspace
@@ -139,6 +190,34 @@ static void free_swayc(swayc_t *cont) {
139 free(cont); 190 free(cont);
140} 191}
141 192
193swayc_t *destroy_output(swayc_t *output) {
194 if (!sway_assert(output, "null output passed to destroy_output")) {
195 return NULL;
196 }
197 if (output->children->length > 0) {
198 // TODO save workspaces when there are no outputs.
199 // TODO also check if there will ever be no outputs except for exiting
200 // program
201 if (root_container.children->length > 1) {
202 int p = root_container.children->items[0] == output;
203 // Move workspace from this output to another output
204 while (output->children->length) {
205 swayc_t *child = output->children->items[0];
206 remove_child(child);
207 add_child(root_container.children->items[p], child);
208 }
209 sort_workspaces(root_container.children->items[p]);
210 // TODO WLR: is this needed anymore?
211 //update_visibility(root_container.children->items[p]);
212 arrange_windows(root_container.children->items[p], -1, -1);
213 }
214 }
215 sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
216 free_swayc(output);
217 update_root_geometry();
218 return &root_container;
219}
220
142swayc_t *destroy_view(swayc_t *view) { 221swayc_t *destroy_view(swayc_t *view) {
143 if (!sway_assert(view, "null view passed to destroy_view")) { 222 if (!sway_assert(view, "null view passed to destroy_view")) {
144 return NULL; 223 return NULL;