aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-16 07:33:23 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-16 07:33:23 -0500
commit9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7 (patch)
tree823cce0da3f7e0dc21c26bef7e639e8370e29b3d /sway/tree
parentkeyboard cleanup (diff)
parentMerge pull request #1503 from emersion/output-config (diff)
downloadsway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.tar.gz
sway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.tar.zst
sway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.zip
Merge branch 'wlroots' into feature/input
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c67
-rw-r--r--sway/tree/layout.c37
2 files changed, 95 insertions, 9 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 78c8625f..6f2a3abf 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -2,11 +2,14 @@
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>
6#include <wlr/types/wlr_wl_shell.h> 7#include <wlr/types/wlr_wl_shell.h>
8#include "sway/config.h"
7#include "sway/container.h" 9#include "sway/container.h"
8#include "sway/layout.h" 10#include "sway/layout.h"
9#include "sway/output.h" 11#include "sway/output.h"
12#include "sway/server.h"
10#include "sway/view.h" 13#include "sway/view.h"
11#include "sway/workspace.h" 14#include "sway/workspace.h"
12#include "log.h" 15#include "log.h"
@@ -48,19 +51,38 @@ static swayc_t *new_swayc(enum swayc_types type) {
48 51
49swayc_t *new_output(struct sway_output *sway_output) { 52swayc_t *new_output(struct sway_output *sway_output) {
50 struct wlr_box size; 53 struct wlr_box size;
51 wlr_output_effective_resolution( 54 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
52 sway_output->wlr_output, &size.width, &size.height); 55 &size.height);
53 const char *name = sway_output->wlr_output->name; 56 const char *name = sway_output->wlr_output->name;
54 57
58 struct output_config *oc = NULL, *all = NULL;
59 for (int i = 0; i < config->output_configs->length; ++i) {
60 struct output_config *cur = config->output_configs->items[i];
61 if (strcasecmp(name, cur->name) == 0) {
62 sway_log(L_DEBUG, "Matched output config for %s", name);
63 oc = cur;
64 }
65 if (strcasecmp("*", cur->name) == 0) {
66 sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
67 all = cur;
68 }
69
70 if (oc && all) {
71 break;
72 }
73 }
74 if (!oc) {
75 oc = all;
76 }
77 if (oc && !oc->enabled) {
78 return NULL;
79 }
80
55 swayc_t *output = new_swayc(C_OUTPUT); 81 swayc_t *output = new_swayc(C_OUTPUT);
56 output->sway_output = sway_output; 82 output->sway_output = sway_output;
57 output->name = name ? strdup(name) : NULL; 83 output->name = name ? strdup(name) : NULL;
58 output->width = size.width;
59 output->height = size.width;
60 84
61 // TODO configure output layout position 85 apply_output_config(oc, output);
62 wlr_output_layout_add_auto(root_container.output_layout,
63 sway_output->wlr_output);
64 86
65 add_child(&root_container, output); 87 add_child(&root_container, output);
66 88
@@ -146,6 +168,34 @@ static void free_swayc(swayc_t *cont) {
146 free(cont); 168 free(cont);
147} 169}
148 170
171swayc_t *destroy_output(swayc_t *output) {
172 if (!sway_assert(output, "null output passed to destroy_output")) {
173 return NULL;
174 }
175
176 if (output->children->length > 0) {
177 // TODO save workspaces when there are no outputs.
178 // TODO also check if there will ever be no outputs except for exiting
179 // program
180 if (root_container.children->length > 1) {
181 int p = root_container.children->items[0] == output;
182 // Move workspace from this output to another output
183 while (output->children->length) {
184 swayc_t *child = output->children->items[0];
185 remove_child(child);
186 add_child(root_container.children->items[p], child);
187 }
188 sort_workspaces(root_container.children->items[p]);
189 arrange_windows(root_container.children->items[p], -1, -1);
190 }
191 }
192
193 sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
194 free_swayc(output);
195
196 return &root_container;
197}
198
149swayc_t *destroy_view(swayc_t *view) { 199swayc_t *destroy_view(swayc_t *view) {
150 if (!sway_assert(view, "null view passed to destroy_view")) { 200 if (!sway_assert(view, "null view passed to destroy_view")) {
151 return NULL; 201 return NULL;
@@ -189,7 +239,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
189 struct sway_view *sview = swayc->sway_view; 239 struct sway_view *sview = swayc->sway_view;
190 swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); 240 swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT);
191 struct wlr_box *output_box = 241 struct wlr_box *output_box =
192 wlr_output_layout_get_box(root_container.output_layout, 242 wlr_output_layout_get_box(
243 root_container.sway_root->output_layout,
193 soutput->sway_output->wlr_output); 244 soutput->sway_output->wlr_output);
194 double ox = lx - output_box->x; 245 double ox = lx - output_box->x;
195 double oy = ly - output_box->y; 246 double oy = ly - output_box->y;
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index cb39a361..4bcf0e2f 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -7,6 +7,7 @@
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include <wlr/types/wlr_output_layout.h> 8#include <wlr/types/wlr_output_layout.h>
9#include "sway/container.h" 9#include "sway/container.h"
10#include "sway/layout.h"
10#include "sway/output.h" 11#include "sway/output.h"
11#include "sway/view.h" 12#include "sway/view.h"
12#include "list.h" 13#include "list.h"
@@ -14,13 +15,47 @@
14 15
15swayc_t root_container; 16swayc_t root_container;
16 17
18static void output_layout_change_notify(struct wl_listener *listener, void *data) {
19 struct wlr_box *layout_box = wlr_output_layout_get_box(
20 root_container.sway_root->output_layout, NULL);
21 root_container.width = layout_box->width;
22 root_container.height = layout_box->height;
23
24 for (int i = 0 ; i < root_container.children->length; ++i) {
25 swayc_t *output_container = root_container.children->items[i];
26 if (output_container->type != C_OUTPUT) {
27 continue;
28 }
29 struct sway_output *output = output_container->sway_output;
30
31 struct wlr_box *output_box = wlr_output_layout_get_box(
32 root_container.sway_root->output_layout, output->wlr_output);
33 if (!output_box) {
34 continue;
35 }
36 output_container->x = output_box->x;
37 output_container->y = output_box->y;
38 output_container->width = output_box->width;
39 output_container->height = output_box->height;
40 }
41
42 arrange_windows(&root_container, -1, -1);
43}
44
17void init_layout(void) { 45void init_layout(void) {
18 root_container.id = 0; // normally assigned in new_swayc() 46 root_container.id = 0; // normally assigned in new_swayc()
19 root_container.type = C_ROOT; 47 root_container.type = C_ROOT;
20 root_container.layout = L_NONE; 48 root_container.layout = L_NONE;
21 root_container.name = strdup("root"); 49 root_container.name = strdup("root");
22 root_container.children = create_list(); 50 root_container.children = create_list();
23 root_container.output_layout = wlr_output_layout_create(); 51
52 root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
53 root_container.sway_root->output_layout = wlr_output_layout_create();
54
55 root_container.sway_root->output_layout_change.notify =
56 output_layout_change_notify;
57 wl_signal_add(&root_container.sway_root->output_layout->events.change,
58 &root_container.sway_root->output_layout_change);
24} 59}
25 60
26void add_child(swayc_t *parent, swayc_t *child) { 61void add_child(swayc_t *parent, swayc_t *child) {