aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c64
-rw-r--r--sway/tree/layout.c37
2 files changed, 93 insertions, 8 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 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <wlr/types/wlr_output_layout.h>
+#include "sway/config.h"
#include "sway/container.h"
#include "sway/layout.h"
#include "sway/output.h"
+#include "sway/server.h"
#include "sway/view.h"
#include "sway/workspace.h"
#include "log.h"
@@ -44,19 +47,38 @@ static swayc_t *new_swayc(enum swayc_types type) {
swayc_t *new_output(struct sway_output *sway_output) {
struct wlr_box size;
- wlr_output_effective_resolution(
- sway_output->wlr_output, &size.width, &size.height);
+ wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
+ &size.height);
const char *name = sway_output->wlr_output->name;
+ struct output_config *oc = NULL, *all = NULL;
+ for (int i = 0; i < config->output_configs->length; ++i) {
+ struct output_config *cur = config->output_configs->items[i];
+ if (strcasecmp(name, cur->name) == 0) {
+ sway_log(L_DEBUG, "Matched output config for %s", name);
+ oc = cur;
+ }
+ if (strcasecmp("*", cur->name) == 0) {
+ sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
+ all = cur;
+ }
+
+ if (oc && all) {
+ break;
+ }
+ }
+ if (!oc) {
+ oc = all;
+ }
+ if (oc && !oc->enabled) {
+ return NULL;
+ }
+
swayc_t *output = new_swayc(C_OUTPUT);
output->sway_output = sway_output;
output->name = name ? strdup(name) : NULL;
- output->width = size.width;
- output->height = size.width;
- // TODO configure output layout position
- wlr_output_layout_add_auto(root_container.output_layout,
- sway_output->wlr_output);
+ apply_output_config(oc, output);
add_child(&root_container, output);
@@ -139,6 +161,34 @@ static void free_swayc(swayc_t *cont) {
free(cont);
}
+swayc_t *destroy_output(swayc_t *output) {
+ if (!sway_assert(output, "null output passed to destroy_output")) {
+ return NULL;
+ }
+
+ if (output->children->length > 0) {
+ // TODO save workspaces when there are no outputs.
+ // TODO also check if there will ever be no outputs except for exiting
+ // program
+ if (root_container.children->length > 1) {
+ int p = root_container.children->items[0] == output;
+ // Move workspace from this output to another output
+ while (output->children->length) {
+ swayc_t *child = output->children->items[0];
+ remove_child(child);
+ add_child(root_container.children->items[p], child);
+ }
+ sort_workspaces(root_container.children->items[p]);
+ arrange_windows(root_container.children->items[p], -1, -1);
+ }
+ }
+
+ sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
+ free_swayc(output);
+
+ return &root_container;
+}
+
swayc_t *destroy_view(swayc_t *view) {
if (!sway_assert(view, "null view passed to destroy_view")) {
return NULL;
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 @@
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include "sway/container.h"
+#include "sway/layout.h"
#include "sway/output.h"
#include "sway/view.h"
#include "list.h"
@@ -14,13 +15,47 @@
swayc_t root_container;
+static void output_layout_change_notify(struct wl_listener *listener, void *data) {
+ struct wlr_box *layout_box = wlr_output_layout_get_box(
+ root_container.sway_root->output_layout, NULL);
+ root_container.width = layout_box->width;
+ root_container.height = layout_box->height;
+
+ for (int i = 0 ; i < root_container.children->length; ++i) {
+ swayc_t *output_container = root_container.children->items[i];
+ if (output_container->type != C_OUTPUT) {
+ continue;
+ }
+ struct sway_output *output = output_container->sway_output;
+
+ struct wlr_box *output_box = wlr_output_layout_get_box(
+ root_container.sway_root->output_layout, output->wlr_output);
+ if (!output_box) {
+ continue;
+ }
+ output_container->x = output_box->x;
+ output_container->y = output_box->y;
+ output_container->width = output_box->width;
+ output_container->height = output_box->height;
+ }
+
+ arrange_windows(&root_container, -1, -1);
+}
+
void init_layout(void) {
root_container.id = 0; // normally assigned in new_swayc()
root_container.type = C_ROOT;
root_container.layout = L_NONE;
root_container.name = strdup("root");
root_container.children = create_list();
- root_container.output_layout = wlr_output_layout_create();
+
+ root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
+ root_container.sway_root->output_layout = wlr_output_layout_create();
+
+ root_container.sway_root->output_layout_change.notify =
+ output_layout_change_notify;
+ wl_signal_add(&root_container.sway_root->output_layout->events.change,
+ &root_container.sway_root->output_layout_change);
}
void add_child(swayc_t *parent, swayc_t *child) {