From f3d880b0ec9eae246ef0d70dd67bed6d7488ab33 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 12 Dec 2017 19:40:17 +0100 Subject: Add scale and transform events to sway_output --- sway/desktop/output.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 7eb48bdf..f44cda1a 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -98,17 +98,40 @@ static void output_resolution_notify(struct wl_listener *listener, void *data) { arrange_windows(soutput->swayc, -1, -1); } +static void output_scale_notify(struct wl_listener *listener, void *data) { + struct sway_output *soutput = wl_container_of( + listener, soutput, scale); + arrange_windows(soutput->swayc, -1, -1); +} + +static void output_transform_notify(struct wl_listener *listener, void *data) { + struct sway_output *soutput = wl_container_of( + listener, soutput, transform); + arrange_windows(soutput->swayc, -1, -1); +} + void output_add_notify(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, output_add); struct wlr_output *wlr_output = data; sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); struct sway_output *output = calloc(1, sizeof(struct sway_output)); + if (!output) { + return; + } output->wlr_output = wlr_output; output->server = server; + + wl_signal_init(&output->events.scale); + wl_signal_init(&output->events.transform); + output->swayc = new_output(output); + if (!output->swayc) { + free(output); + return; + } - if (wl_list_length(&wlr_output->modes) > 0) { + if (!wl_list_empty(&wlr_output->modes)) { struct wlr_output_mode *mode = NULL; mode = wl_container_of((&wlr_output->modes)->prev, mode, link); wlr_output_set_mode(wlr_output, mode); @@ -116,9 +139,12 @@ void output_add_notify(struct wl_listener *listener, void *data) { output->frame.notify = output_frame_notify; wl_signal_add(&wlr_output->events.frame, &output->frame); - output->resolution.notify = output_resolution_notify; wl_signal_add(&wlr_output->events.resolution, &output->resolution); + output->scale.notify = output_scale_notify; + wl_signal_add(&output->events.scale, &output->scale); + output->transform.notify = output_transform_notify; + wl_signal_add(&output->events.transform, &output->transform); arrange_windows(output->swayc, -1, -1); } -- cgit v1.2.3 From c7abb77f2217cc4d5642ef1650f7fc75e1c1a9a4 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 12 Dec 2017 20:02:01 +0100 Subject: Listen to output layout change --- include/sway/container.h | 4 ++-- include/sway/layout.h | 8 ++++++++ sway/config/output.c | 17 ++++++++++------- sway/desktop/output.c | 12 ++++-------- sway/desktop/xwayland.c | 6 +++--- sway/tree/container.c | 9 --------- sway/tree/layout.c | 17 ++++++++++++++++- 7 files changed, 43 insertions(+), 30 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/include/sway/container.h b/include/sway/container.h index e3f84fc6..b15e0428 100644 --- a/include/sway/container.h +++ b/include/sway/container.h @@ -57,9 +57,9 @@ enum swayc_border_types { B_NORMAL, /**< Normal border with title bar */ }; +struct sway_root; struct sway_output; struct sway_view; -struct wlr_output_layout; /** * Stores information about a container. @@ -69,7 +69,7 @@ struct wlr_output_layout; struct sway_container { union { // TODO: Encapsulate state for other node types as well like C_CONTAINER - struct wlr_output_layout *output_layout; // C_ROOT + struct sway_root *sway_root; // C_ROOT struct sway_output *sway_output; // C_OUTPUT struct sway_view *sway_view; // C_VIEW }; diff --git a/include/sway/layout.h b/include/sway/layout.h index f3b62b05..bfd96a02 100644 --- a/include/sway/layout.h +++ b/include/sway/layout.h @@ -1,8 +1,16 @@ #ifndef _SWAY_LAYOUT_H #define _SWAY_LAYOUT_H +#include + struct sway_container; +struct sway_root { + struct wlr_output_layout *output_layout; + + struct wl_listener output_layout_change; +}; + void init_layout(void); void add_child(struct sway_container *parent, struct sway_container *child); struct sway_container *remove_child(struct sway_container *child); diff --git a/sway/config/output.c b/sway/config/output.c index b06c7c0e..ed47a617 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -99,7 +99,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { struct wlr_output *wlr_output = output->sway_output->wlr_output; if (oc && oc->enabled == 0) { - wlr_output_layout_remove(root_container.output_layout, wlr_output); + wlr_output_layout_remove(root_container.sway_root->output_layout, + wlr_output); destroy_output(output); return; } @@ -117,19 +118,21 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { if (oc && oc->transform >= 0) { sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); wlr_output_transform(wlr_output, oc->transform); - wl_signal_emit(&output->sway_output->events.transform, output->sway_output); + wl_signal_emit(&output->sway_output->events.transform, + output->sway_output); } // Find position for it if (oc && (oc->x != -1 || oc->y != -1)) { sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); - wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x, - oc->y); + wlr_output_layout_add(root_container.sway_root->output_layout, + wlr_output, oc->x, oc->y); } else { - wlr_output_layout_add_auto(root_container.output_layout, wlr_output); + wlr_output_layout_add_auto(root_container.sway_root->output_layout, + wlr_output); } - struct wlr_box *output_layout_box = - wlr_output_layout_get_box(root_container.output_layout, wlr_output); + struct wlr_box *output_layout_box = wlr_output_layout_get_box( + root_container.sway_root->output_layout, wlr_output); output->x = output_layout_box->x; output->y = output_layout_box->y; output->width = output_layout_box->width; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index f44cda1a..bcdaa7d2 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -72,8 +72,7 @@ static void output_frame_view(swayc_t *view, void *data) { } static void output_frame_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of( - listener, soutput, frame); + struct sway_output *soutput = wl_container_of(listener, soutput, frame); struct wlr_output *wlr_output = data; struct sway_server *server = soutput->server; @@ -93,20 +92,17 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { } static void output_resolution_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of( - listener, soutput, resolution); + struct sway_output *soutput = wl_container_of(listener, soutput, resolution); arrange_windows(soutput->swayc, -1, -1); } static void output_scale_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of( - listener, soutput, scale); + struct sway_output *soutput = wl_container_of(listener, soutput, scale); arrange_windows(soutput->swayc, -1, -1); } static void output_transform_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of( - listener, soutput, transform); + struct sway_output *soutput = wl_container_of(listener, soutput, transform); arrange_windows(soutput->swayc, -1, -1); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 65c7e1ec..e3799d2d 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -55,7 +55,7 @@ static void set_position(struct sway_view *view, double ox, double oy) { if (!sway_assert(root, "output must be within tree to set position")) { return; } - struct wlr_output_layout *layout = root->output_layout; + struct wlr_output_layout *layout = root->sway_root->output_layout; struct wlr_output_layout_output *loutput = wlr_output_layout_get(layout, output->sway_output->wlr_output); if (!sway_assert(loutput, "output must be within layout to set position")) { @@ -147,14 +147,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { // TODO remove from the tree when the surface goes away (unmapped) sway_view->surface = xsurface->surface; sway_surface->view = sway_view; - + // TODO: // - Wire up listeners // - Handle popups // - Look up pid and open on appropriate workspace // - Set new view to maximized so it behaves nicely // - Criteria - + sway_surface->commit.notify = handle_commit; wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); sway_surface->destroy.notify = handle_destroy; diff --git a/sway/tree/container.c b/sway/tree/container.c index e4c27d61..f70bccdc 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -26,13 +26,6 @@ void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, } } -static void update_root_geometry() { - struct wlr_box *box = - wlr_output_layout_get_box(root_container.output_layout, NULL); - root_container.width = box->width; - root_container.height = box->height; -} - static swayc_t *new_swayc(enum swayc_types type) { // next id starts at 1 because 0 is assigned to root_container in layout.c static size_t next_id = 1; @@ -94,7 +87,6 @@ swayc_t *new_output(struct sway_output *sway_output) { sway_log(L_DEBUG, "Creating default workspace %s", ws_name); new_workspace(output, ws_name); free(ws_name); - update_root_geometry(); return output; } @@ -195,7 +187,6 @@ swayc_t *destroy_output(swayc_t *output) { sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); free_swayc(output); - update_root_geometry(); return &root_container; } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index cb39a361..fd17f8a5 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -7,6 +7,7 @@ #include #include #include "sway/container.h" +#include "sway/layout.h" #include "sway/output.h" #include "sway/view.h" #include "list.h" @@ -14,13 +15,27 @@ swayc_t root_container; +static void output_layout_change_notify(struct wl_listener *listener, void *data) { + struct wlr_box *box = wlr_output_layout_get_box( + root_container.sway_root->output_layout, NULL); + root_container.width = box->width; + root_container.height = box->height; +} + 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) { -- cgit v1.2.3 From d293c429424a9f96c3fc8143af457645326e7a0e Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 12 Dec 2017 21:09:51 +0100 Subject: Update output container box in event handler --- include/sway/config.h | 1 - sway/commands/output.c | 3 ++- sway/config/output.c | 6 ------ sway/desktop/output.c | 23 +++++++++++++++++------ 4 files changed, 19 insertions(+), 14 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/include/sway/config.h b/include/sway/config.h index 4dd8e94c..139d7800 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/sway/commands/output.c b/sway/commands/output.c index be78358a..23792855 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -29,7 +29,8 @@ struct cmd_results *cmd_output(int argc, char **argv) { struct output_config *output = new_output_config(); if (!output) { - return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); + sway_log(L_ERROR, "Failed to allocate output config"); + return NULL; } output->name = strdup(name); diff --git a/sway/config/output.c b/sway/config/output.c index ed47a617..6371763f 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -131,12 +131,6 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { wlr_output_layout_add_auto(root_container.sway_root->output_layout, wlr_output); } - struct wlr_box *output_layout_box = wlr_output_layout_get_box( - root_container.sway_root->output_layout, wlr_output); - output->x = output_layout_box->x; - output->y = output_layout_box->y; - output->width = output_layout_box->width; - output->height = output_layout_box->height; if (!oc || !oc->background) { // Look for a * config for background diff --git a/sway/desktop/output.c b/sway/desktop/output.c index bcdaa7d2..3fd49846 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -91,19 +91,30 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { soutput->last_frame = now; } +static void output_update_size(struct sway_output *output) { + struct wlr_box *output_layout_box = wlr_output_layout_get_box( + root_container.sway_root->output_layout, output->wlr_output); + output->swayc->x = output_layout_box->x; + output->swayc->y = output_layout_box->y; + output->swayc->width = output_layout_box->width; + output->swayc->height = output_layout_box->height; + + arrange_windows(output->swayc, -1, -1); +} + static void output_resolution_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of(listener, soutput, resolution); - arrange_windows(soutput->swayc, -1, -1); + struct sway_output *output = wl_container_of(listener, output, resolution); + output_update_size(output); } static void output_scale_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of(listener, soutput, scale); - arrange_windows(soutput->swayc, -1, -1); + struct sway_output *output = wl_container_of(listener, output, scale); + output_update_size(output); } static void output_transform_notify(struct wl_listener *listener, void *data) { - struct sway_output *soutput = wl_container_of(listener, soutput, transform); - arrange_windows(soutput->swayc, -1, -1); + struct sway_output *output = wl_container_of(listener, output, transform); + output_update_size(output); } void output_add_notify(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From a4619e98c462690f14baf5c0c72c25553e3c6d51 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 13 Dec 2017 15:52:18 +0100 Subject: Update output containers on output layout change --- include/sway/output.h | 8 -------- sway/config/output.c | 5 +---- sway/desktop/output.c | 47 +++++------------------------------------------ sway/tree/layout.c | 20 +++++++++++++++++--- 4 files changed, 23 insertions(+), 57 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/include/sway/output.h b/include/sway/output.h index 11869398..7ca02d7b 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -13,15 +13,7 @@ struct sway_output { struct sway_server *server; struct timespec last_frame; - struct { - struct wl_signal scale; - struct wl_signal transform; - } events; - struct wl_listener frame; - struct wl_listener resolution; - struct wl_listener scale; - struct wl_listener transform; }; #endif diff --git a/sway/config/output.c b/sway/config/output.c index 6371763f..8d946386 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -113,13 +113,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { if (oc && oc->scale > 0) { sway_log(L_DEBUG, "Set %s scale to %d", oc->name, oc->scale); wlr_output_set_scale(wlr_output, oc->scale); - wl_signal_emit(&output->sway_output->events.scale, output->sway_output); } if (oc && oc->transform >= 0) { sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); - wlr_output_transform(wlr_output, oc->transform); - wl_signal_emit(&output->sway_output->events.transform, - output->sway_output); + wlr_output_set_transform(wlr_output, oc->transform); } // Find position for it diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 3fd49846..2177ad74 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -91,32 +91,6 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { soutput->last_frame = now; } -static void output_update_size(struct sway_output *output) { - struct wlr_box *output_layout_box = wlr_output_layout_get_box( - root_container.sway_root->output_layout, output->wlr_output); - output->swayc->x = output_layout_box->x; - output->swayc->y = output_layout_box->y; - output->swayc->width = output_layout_box->width; - output->swayc->height = output_layout_box->height; - - arrange_windows(output->swayc, -1, -1); -} - -static void output_resolution_notify(struct wl_listener *listener, void *data) { - struct sway_output *output = wl_container_of(listener, output, resolution); - output_update_size(output); -} - -static void output_scale_notify(struct wl_listener *listener, void *data) { - struct sway_output *output = wl_container_of(listener, output, scale); - output_update_size(output); -} - -static void output_transform_notify(struct wl_listener *listener, void *data) { - struct sway_output *output = wl_container_of(listener, output, transform); - output_update_size(output); -} - void output_add_notify(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, output_add); struct wlr_output *wlr_output = data; @@ -129,8 +103,11 @@ void output_add_notify(struct wl_listener *listener, void *data) { output->wlr_output = wlr_output; output->server = server; - wl_signal_init(&output->events.scale); - wl_signal_init(&output->events.transform); + if (!wl_list_empty(&wlr_output->modes)) { + struct wlr_output_mode *mode = + wl_container_of(wlr_output->modes.prev, mode, link); + wlr_output_set_mode(wlr_output, mode); + } output->swayc = new_output(output); if (!output->swayc) { @@ -138,22 +115,8 @@ void output_add_notify(struct wl_listener *listener, void *data) { return; } - if (!wl_list_empty(&wlr_output->modes)) { - struct wlr_output_mode *mode = NULL; - mode = wl_container_of((&wlr_output->modes)->prev, mode, link); - wlr_output_set_mode(wlr_output, mode); - } - output->frame.notify = output_frame_notify; wl_signal_add(&wlr_output->events.frame, &output->frame); - output->resolution.notify = output_resolution_notify; - wl_signal_add(&wlr_output->events.resolution, &output->resolution); - output->scale.notify = output_scale_notify; - wl_signal_add(&output->events.scale, &output->scale); - output->transform.notify = output_transform_notify; - wl_signal_add(&output->events.transform, &output->transform); - - arrange_windows(output->swayc, -1, -1); } void output_remove_notify(struct wl_listener *listener, void *data) { diff --git a/sway/tree/layout.c b/sway/tree/layout.c index fd17f8a5..65382231 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -16,10 +16,24 @@ swayc_t root_container; static void output_layout_change_notify(struct wl_listener *listener, void *data) { - struct wlr_box *box = wlr_output_layout_get_box( + struct wlr_box *layout_box = wlr_output_layout_get_box( root_container.sway_root->output_layout, NULL); - root_container.width = box->width; - root_container.height = box->height; + 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]; + 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); + 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) { -- cgit v1.2.3 From ec2fd6e5c0217ae58a03eca1e83d85f02c739643 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 13 Dec 2017 21:47:37 +0100 Subject: Handle output remove --- sway/desktop/output.c | 16 +++++++++++++++- sway/tree/layout.c | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'sway/desktop/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 2177ad74..ad843b31 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -123,5 +123,19 @@ void output_remove_notify(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, output_remove); struct wlr_output *wlr_output = data; sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); - // TODO + + swayc_t *output_container = NULL; + for (int i = 0 ; i < root_container.children->length; ++i) { + swayc_t *child = root_container.children->items[i]; + if (child->type == C_OUTPUT && + child->sway_output->wlr_output == wlr_output) { + output_container = child; + break; + } + } + if (!output_container) { + return; + } + + destroy_output(output_container); } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 65382231..4bcf0e2f 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -23,10 +23,16 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data 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; -- cgit v1.2.3