From 7586f150c058997d9dde387ea7c091ffa7a3c3c7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 30 Aug 2018 21:00:10 +1000 Subject: Implement type safe arguments and demote sway_container This commit changes the meaning of sway_container so that it only refers to layout containers and view containers. Workspaces, outputs and the root are no longer known as containers. Instead, root, outputs, workspaces and containers are all a type of node, and containers come in two types: layout containers and view containers. In addition to the above, this implements type safe variables. This means we use specific types such as sway_output and sway_workspace instead of generic containers or nodes. However, it's worth noting that in a few places places (eg. seat focus and transactions) referring to them in a generic way is unavoidable which is why we still use nodes in some places. If you want a TL;DR, look at node.h, as well as the struct definitions for root, output, workspace and container. Note that sway_output now contains a workspaces list, and workspaces now contain a tiling and floating list, and containers now contain a pointer back to the workspace. There are now functions for seat_get_focused_workspace and seat_get_focused_container. The latter will return NULL if a workspace itself is focused. Most other seat functions like seat_get_focus and seat_set_focus now accept and return nodes. In the config->handler_context struct, current_container has been replaced with three pointers: node, container and workspace. node is the same as what current_container was, while workspace is the workspace that the node resides on and container is the actual container, which may be NULL if a workspace itself is focused. The global root_container variable has been replaced with one simply called root, which is a pointer to the sway_root instance. The way outputs are created, enabled, disabled and destroyed has changed. Previously we'd wrap the sway_output in a container when it is enabled, but as we don't have containers any more it needs a different approach. The output_create and output_destroy functions previously created/destroyed the container, but now they create/destroy the sway_output. There is a new function output_disable to disable an output without destroying it. Containers have a new view property. If this is populated then the container is a view container, otherwise it's a layout container. Like before, this property is immutable for the life of the container. Containers have both a `sway_container *parent` and `sway_workspace *workspace`. As we use specific types now, parent cannot point to a workspace so it'll be NULL for containers which are direct children of the workspace. The workspace property is set for all containers, except those which are hidden in the scratchpad as they have no workspace. In some cases we need to refer to workspaces in a container-like way. For example, workspaces have layout and children, but when using specific types this makes it difficult. Likewise, it's difficult for a container to get its parent's layout when the parent could be another container or a workspace. To make it easier, some helper functions have been created: container_parent_layout and container_get_siblings. container_remove_child has been renamed to container_detach and container_replace_child has been renamed to container_replace. `container_handle_fullscreen_reparent(con, old_parent)` has had the old_parent removed. We now unfullscreen the workspace when detaching the container, so this function is simplified and only needs one argument now. container_notify_subtree_changed has been renamed to container_update_representation. This is more descriptive of its purpose. I also wanted to be able to call it with whatever container was changed rather than the container's parent, which makes bubbling up to the workspace easier. There are now state structs per node thing. ie. sway_output_state, sway_workspace_state and sway_container_state. The focus, move and layout commands have been completely refactored to work with the specific types. I considered making these a separate PR, but I'd be backporting my changes only to replace them again, and it's easier just to test everything at once. --- sway/tree/output.c | 348 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 208 insertions(+), 140 deletions(-) (limited to 'sway/tree/output.c') diff --git a/sway/tree/output.c b/sway/tree/output.c index 6601220b..d72eb1a1 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -2,28 +2,31 @@ #include #include #include +#include #include "sway/ipc-server.h" +#include "sway/layers.h" #include "sway/output.h" #include "sway/tree/arrange.h" #include "sway/tree/output.h" #include "sway/tree/workspace.h" #include "log.h" +#include "util.h" -static void restore_workspaces(struct sway_container *output) { +static void restore_workspaces(struct sway_output *output) { // Workspace output priority - for (int i = 0; i < root_container.children->length; i++) { - struct sway_container *other = root_container.children->items[i]; + for (int i = 0; i < root->outputs->length; i++) { + struct sway_output *other = root->outputs->items[i]; if (other == output) { continue; } - for (int j = 0; j < other->children->length; j++) { - struct sway_container *ws = other->children->items[j]; - struct sway_container *highest = + for (int j = 0; j < other->workspaces->length; j++) { + struct sway_workspace *ws = other->workspaces->items[j]; + struct sway_output *highest = workspace_output_get_highest_available(ws, NULL); if (highest == output) { - container_remove_child(ws); - container_add_child(output, ws); + workspace_detach(ws); + output_add_workspace(output, ws); ipc_event_workspace(NULL, ws, "move"); j--; } @@ -31,111 +34,111 @@ static void restore_workspaces(struct sway_container *output) { } // Saved workspaces - list_t *saved = root_container.sway_root->saved_workspaces; - for (int i = 0; i < saved->length; ++i) { - struct sway_container *ws = saved->items[i]; - container_add_child(output, ws); + for (int i = 0; i < root->saved_workspaces->length; ++i) { + struct sway_workspace *ws = root->saved_workspaces->items[i]; + output_add_workspace(output, ws); ipc_event_workspace(NULL, ws, "move"); } - saved->length = 0; + root->saved_workspaces->length = 0; output_sort_workspaces(output); } -struct sway_container *output_create( - struct sway_output *sway_output) { - const char *name = sway_output->wlr_output->name; - char identifier[128]; - output_get_identifier(identifier, sizeof(identifier), sway_output); +struct sway_output *output_create(struct wlr_output *wlr_output) { + struct sway_output *output = calloc(1, sizeof(struct sway_output)); + node_init(&output->node, N_OUTPUT, output); + output->wlr_output = wlr_output; + wlr_output->data = output; - 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]; + wl_signal_add(&wlr_output->events.destroy, &output->destroy); - if (strcasecmp(name, cur->name) == 0 || - strcasecmp(identifier, cur->name) == 0) { - wlr_log(WLR_DEBUG, "Matched output config for %s", name); - oc = cur; - } - if (strcasecmp("*", cur->name) == 0) { - wlr_log(WLR_DEBUG, "Matched wildcard output config for %s", name); - all = cur; - } + wl_list_insert(&root->all_outputs, &output->link); - if (oc && all) { - break; - } - } - if (!oc) { - oc = all; + 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); } - if (oc && !oc->enabled) { - return NULL; - } + output->workspaces = create_list(); + output->current.workspaces = create_list(); - struct sway_container *output = container_create(C_OUTPUT); - output->sway_output = sway_output; - output->name = strdup(name); - if (output->name == NULL) { - output_begin_destroy(output); - return NULL; - } + return output; +} +void output_enable(struct sway_output *output, struct output_config *oc) { + if (!sway_assert(!output->enabled, "output is already enabled")) { + return; + } + struct wlr_output *wlr_output = output->wlr_output; + output->enabled = true; apply_output_config(oc, output); - container_add_child(&root_container, output); - load_swaybars(); - - struct wlr_box size; - wlr_output_effective_resolution(sway_output->wlr_output, &size.width, - &size.height); - output->width = size.width; - output->height = size.height; + list_add(root->outputs, output); restore_workspaces(output); - if (!output->children->length) { + if (!output->workspaces->length) { // Create workspace - char *ws_name = workspace_next_name(output->name); + char *ws_name = workspace_next_name(wlr_output->name); wlr_log(WLR_DEBUG, "Creating default workspace %s", ws_name); - struct sway_container *ws = workspace_create(output, ws_name); + struct sway_workspace *ws = workspace_create(output, ws_name); // Set each seat's focus if not already set struct sway_seat *seat = NULL; wl_list_for_each(seat, &input_manager->seats, link) { if (!seat->has_focus) { - seat_set_focus(seat, ws); + seat_set_focus(seat, &ws->node); } } free(ws_name); } - container_create_notify(output); - return output; + size_t len = sizeof(output->layers) / sizeof(output->layers[0]); + for (size_t i = 0; i < len; ++i) { + wl_list_init(&output->layers[i]); + } + wl_signal_init(&output->events.destroy); + + input_manager_configure_xcursor(input_manager); + + wl_signal_add(&wlr_output->events.mode, &output->mode); + wl_signal_add(&wlr_output->events.transform, &output->transform); + wl_signal_add(&wlr_output->events.scale, &output->scale); + wl_signal_add(&output->damage->events.frame, &output->damage_frame); + wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); + + output_add_listeners(output); + + wl_signal_emit(&root->events.new_node, &output->node); + + load_swaybars(); + + arrange_layers(output); + arrange_root(); } -static void output_evacuate(struct sway_container *output) { - if (!output->children->length) { +static void output_evacuate(struct sway_output *output) { + if (!output->workspaces->length) { return; } - struct sway_container *fallback_output = NULL; - if (root_container.children->length > 1) { - fallback_output = root_container.children->items[0]; + struct sway_output *fallback_output = NULL; + if (root->outputs->length > 1) { + fallback_output = root->outputs->items[0]; if (fallback_output == output) { - fallback_output = root_container.children->items[1]; + fallback_output = root->outputs->items[1]; } } - while (output->children->length) { - struct sway_container *workspace = output->children->items[0]; + while (output->workspaces->length) { + struct sway_workspace *workspace = output->workspaces->items[0]; - container_remove_child(workspace); + workspace_detach(workspace); if (workspace_is_empty(workspace)) { workspace_begin_destroy(workspace); continue; } - struct sway_container *new_output = + struct sway_output *new_output = workspace_output_get_highest_available(workspace, output); if (!new_output) { new_output = fallback_output; @@ -143,39 +146,31 @@ static void output_evacuate(struct sway_container *output) { if (new_output) { workspace_output_add_priority(workspace, new_output); - container_add_child(new_output, workspace); + output_add_workspace(new_output, workspace); output_sort_workspaces(new_output); ipc_event_workspace(NULL, workspace, "move"); } else { - list_add(root_container.sway_root->saved_workspaces, workspace); + list_add(root->saved_workspaces, workspace); } } } -void output_destroy(struct sway_container *output) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { +void output_destroy(struct sway_output *output) { + if (!sway_assert(output->node.destroying, + "Tried to free output which wasn't marked as destroying")) { return; } - if (!sway_assert(output->destroying, - "Tried to free output which wasn't marked as destroying")) { + if (!sway_assert(output->wlr_output == NULL, + "Tried to free output which still had a wlr_output")) { return; } - if (!sway_assert(output->ntxnrefs == 0, "Tried to free output " + if (!sway_assert(output->node.ntxnrefs == 0, "Tried to free output " "which is still referenced by transactions")) { return; } - free(output->name); - free(output->formatted_title); - wlr_texture_destroy(output->title_focused); - wlr_texture_destroy(output->title_focused_inactive); - wlr_texture_destroy(output->title_unfocused); - wlr_texture_destroy(output->title_urgent); - list_free(output->children); - list_free(output->current.children); - list_free(output->outputs); + list_free(output->workspaces); + list_free(output->current.workspaces); free(output); - - // NOTE: We don't actually destroy the sway_output here } static void untrack_output(struct sway_container *con, void *data) { @@ -186,76 +181,131 @@ static void untrack_output(struct sway_container *con, void *data) { } } -void output_begin_destroy(struct sway_container *output) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { +void output_disable(struct sway_output *output) { + if (!sway_assert(output->enabled, "Expected an enabled output")) { return; } - wlr_log(WLR_DEBUG, "OUTPUT: Destroying output '%s'", output->name); + wlr_log(WLR_DEBUG, "Disabling output '%s'", output->wlr_output->name); wl_signal_emit(&output->events.destroy, output); output_evacuate(output); - output->destroying = true; - container_set_dirty(output); + root_for_each_container(untrack_output, output); + + int index = list_find(root->outputs, output); + list_del(root->outputs, index); - root_for_each_container(untrack_output, output->sway_output); + wl_list_remove(&output->mode.link); + wl_list_remove(&output->transform.link); + wl_list_remove(&output->scale.link); + wl_list_remove(&output->damage_destroy.link); + wl_list_remove(&output->damage_frame.link); - wl_list_remove(&output->sway_output->mode.link); - wl_list_remove(&output->sway_output->transform.link); - wl_list_remove(&output->sway_output->scale.link); - wl_list_remove(&output->sway_output->damage_destroy.link); - wl_list_remove(&output->sway_output->damage_frame.link); + output->enabled = false; - output->sway_output->swayc = NULL; - output->sway_output = NULL; + arrange_root(); +} - if (output->parent) { - container_remove_child(output); +void output_begin_destroy(struct sway_output *output) { + if (!sway_assert(!output->enabled, "Expected a disabled output")) { + return; } + wlr_log(WLR_DEBUG, "Destroying output '%s'", output->wlr_output->name); + + output->node.destroying = true; + node_set_dirty(&output->node); + + wl_list_remove(&output->link); + wl_list_remove(&output->destroy.link); + output->wlr_output->data = NULL; + output->wlr_output = NULL; } -struct sway_container *output_from_wlr_output(struct wlr_output *output) { - if (output == NULL) { +struct output_config *output_find_config(struct sway_output *output) { + const char *name = output->wlr_output->name; + char identifier[128]; + output_get_identifier(identifier, sizeof(identifier), output); + + 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 || + strcasecmp(identifier, cur->name) == 0) { + wlr_log(WLR_DEBUG, "Matched output config for %s", name); + oc = cur; + } + if (strcasecmp("*", cur->name) == 0) { + wlr_log(WLR_DEBUG, "Matched wildcard output config for %s", name); + all = cur; + } + + if (oc && all) { + break; + } + } + if (!oc) { + oc = all; + } + + if (oc && !oc->enabled) { return NULL; } - for (int i = 0; i < root_container.children->length; ++i) { - struct sway_container *o = root_container.children->items[i]; - if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { - return o; - } + return oc; +} + +struct sway_output *output_from_wlr_output(struct wlr_output *output) { + return output->data; +} + +struct sway_output *output_get_in_direction(struct sway_output *reference, + enum movement_direction direction) { + enum wlr_direction wlr_dir = 0; + if (!sway_assert(sway_dir_to_wlr(direction, &wlr_dir), + "got invalid direction: %d", direction)) { + return NULL; } - return NULL; + int lx = reference->wlr_output->lx + reference->wlr_output->width / 2; + int ly = reference->wlr_output->ly + reference->wlr_output->height / 2; + struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output( + root->output_layout, wlr_dir, reference->wlr_output, lx, ly); + if (!wlr_adjacent) { + return NULL; + } + return output_from_wlr_output(wlr_adjacent); } -void output_for_each_workspace(struct sway_container *output, - void (*f)(struct sway_container *con, void *data), void *data) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { - return; +void output_add_workspace(struct sway_output *output, + struct sway_workspace *workspace) { + if (workspace->output) { + workspace_detach(workspace); } - for (int i = 0; i < output->children->length; ++i) { - struct sway_container *workspace = output->children->items[i]; + list_add(output->workspaces, workspace); + workspace->output = output; + node_set_dirty(&output->node); + node_set_dirty(&workspace->node); +} + +void output_for_each_workspace(struct sway_output *output, + void (*f)(struct sway_workspace *ws, void *data), void *data) { + for (int i = 0; i < output->workspaces->length; ++i) { + struct sway_workspace *workspace = output->workspaces->items[i]; f(workspace, data); } } -void output_for_each_container(struct sway_container *output, +void output_for_each_container(struct sway_output *output, void (*f)(struct sway_container *con, void *data), void *data) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { - return; - } - for (int i = 0; i < output->children->length; ++i) { - struct sway_container *workspace = output->children->items[i]; + for (int i = 0; i < output->workspaces->length; ++i) { + struct sway_workspace *workspace = output->workspaces->items[i]; workspace_for_each_container(workspace, f, data); } } -struct sway_container *output_find_workspace(struct sway_container *output, - bool (*test)(struct sway_container *con, void *data), void *data) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { - return NULL; - } - for (int i = 0; i < output->children->length; ++i) { - struct sway_container *workspace = output->children->items[i]; +struct sway_workspace *output_find_workspace(struct sway_output *output, + bool (*test)(struct sway_workspace *ws, void *data), void *data) { + for (int i = 0; i < output->workspaces->length; ++i) { + struct sway_workspace *workspace = output->workspaces->items[i]; if (test(workspace, data)) { return workspace; } @@ -263,14 +313,11 @@ struct sway_container *output_find_workspace(struct sway_container *output, return NULL; } -struct sway_container *output_find_container(struct sway_container *output, +struct sway_container *output_find_container(struct sway_output *output, bool (*test)(struct sway_container *con, void *data), void *data) { - if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { - return NULL; - } struct sway_container *result = NULL; - for (int i = 0; i < output->children->length; ++i) { - struct sway_container *workspace = output->children->items[i]; + for (int i = 0; i < output->workspaces->length; ++i) { + struct sway_workspace *workspace = output->workspaces->items[i]; if ((result = workspace_find_container(workspace, test, data))) { return result; } @@ -279,8 +326,8 @@ struct sway_container *output_find_container(struct sway_container *output, } static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { - struct sway_container *a = *(void **)_a; - struct sway_container *b = *(void **)_b; + struct sway_workspace *a = *(void **)_a; + struct sway_workspace *b = *(void **)_b; if (isdigit(a->name[0]) && isdigit(b->name[0])) { int a_num = strtol(a->name, NULL, 10); @@ -294,6 +341,27 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { return 0; } -void output_sort_workspaces(struct sway_container *output) { - list_stable_sort(output->children, sort_workspace_cmp_qsort); +void output_sort_workspaces(struct sway_output *output) { + list_stable_sort(output->workspaces, sort_workspace_cmp_qsort); +} + +void output_get_box(struct sway_output *output, struct wlr_box *box) { + box->x = output->wlr_output->lx; + box->y = output->wlr_output->ly; + box->width = output->wlr_output->width; + box->height = output->wlr_output->height; +} + +enum sway_container_layout output_get_default_layout( + struct sway_output *output) { + if (config->default_layout != L_NONE) { + return config->default_layout; + } + if (config->default_orientation != L_NONE) { + return config->default_orientation; + } + if (output->wlr_output->height > output->wlr_output->width) { + return L_VERT; + } + return L_HORIZ; } -- cgit v1.2.3-54-g00ecf From acc2628c799170dea98380cda2237137137f182f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 30 Aug 2018 21:20:31 +1000 Subject: Don't use wlr_output properties These properties are before rotation. --- include/sway/output.h | 3 +++ sway/debug-tree.c | 16 ++++++++-------- sway/desktop/output.c | 8 ++++---- sway/desktop/render.c | 4 ++-- sway/desktop/xdg_shell.c | 8 ++++---- sway/desktop/xdg_shell_v6.c | 8 ++++---- sway/tree/arrange.c | 4 ++-- sway/tree/output.c | 19 ++++++++++++------- sway/tree/view.c | 8 ++++---- sway/tree/workspace.c | 8 ++++---- 10 files changed, 47 insertions(+), 39 deletions(-) (limited to 'sway/tree/output.c') diff --git a/include/sway/output.h b/include/sway/output.h index 540ed8a0..19a61175 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -28,6 +28,9 @@ struct sway_output { struct timespec last_frame; struct wlr_output_damage *damage; + int lx, ly; + int width, height; + bool enabled; list_t *workspaces; diff --git a/sway/debug-tree.c b/sway/debug-tree.c index 2ed3c087..973c6d88 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -43,10 +43,10 @@ static char *get_string(struct sway_node *node) { case N_OUTPUT: snprintf(buffer, 512, "N_OUTPUT id:%zd '%s' %dx%d@%d,%d", node->id, node->sway_output->wlr_output->name, - node->sway_output->wlr_output->width, - node->sway_output->wlr_output->height, - node->sway_output->wlr_output->lx, - node->sway_output->wlr_output->ly); + node->sway_output->width, + node->sway_output->height, + node->sway_output->lx, + node->sway_output->ly); break; case N_WORKSPACE: snprintf(buffer, 512, "N_WORKSPACE id:%zd '%s' %s %dx%d@%.f,%.f", @@ -128,11 +128,11 @@ void update_debug_tree() { int width = 640, height = 480; for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; - if (output->wlr_output->width > width) { - width = output->wlr_output->width; + if (output->width > width) { + width = output->width; } - if (output->wlr_output->height > height) { - height = output->wlr_output->height; + if (output->height > height) { + height = output->height; } } cairo_surface_t *surface = diff --git a/sway/desktop/output.c b/sway/desktop/output.c index c182bad6..792a7231 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -98,8 +98,8 @@ static bool get_surface_box(struct surface_iterator_data *data, wlr_box_rotated_bounds(&box, data->rotation, &rotated_box); struct wlr_box output_box = { - .width = output->wlr_output->width, - .height = output->wlr_output->height, + .width = output->width, + .height = output->height, }; struct wlr_box intersection; @@ -249,8 +249,8 @@ bool output_has_opaque_overlay_layer_surface(struct sway_output *output) { struct sway_layer_surface *sway_layer_surface = layer_from_wlr_layer_surface(wlr_layer_surface); pixman_box32_t output_box = { - .x2 = output->wlr_output->width, - .y2 = output->wlr_output->height, + .x2 = output->width, + .y2 = output->height, }; pixman_region32_t surface_opaque_box; pixman_region32_init(&surface_opaque_box); diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 99b2cf3d..9d80f3c7 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -238,8 +238,8 @@ static void render_saved_view(struct sway_view *view, }; struct wlr_box output_box = { - .width = output->wlr_output->width, - .height = output->wlr_output->height, + .width = output->width, + .height = output->height, }; struct wlr_box intersection; diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index e19d8e18..575f229d 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -59,10 +59,10 @@ static void popup_unconstrain(struct sway_xdg_popup *popup) { // the output box expressed in the coordinate system of the toplevel parent // of the popup struct wlr_box output_toplevel_sx_box = { - .x = output->wlr_output->lx - view->x, - .y = output->wlr_output->ly - view->y, - .width = output->wlr_output->width, - .height = output->wlr_output->height, + .x = output->lx - view->x, + .y = output->ly - view->y, + .width = output->width, + .height = output->height, }; wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index b23d4577..58fbd631 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -58,10 +58,10 @@ static void popup_unconstrain(struct sway_xdg_popup_v6 *popup) { // the output box expressed in the coordinate system of the toplevel parent // of the popup struct wlr_box output_toplevel_sx_box = { - .x = output->wlr_output->lx - view->x, - .y = output->wlr_output->ly - view->y, - .width = output->wlr_output->width, - .height = output->wlr_output->height, + .x = output->lx - view->x, + .y = output->ly - view->y, + .width = output->width, + .height = output->height, }; wlr_xdg_popup_v6_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box); diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index f86d4a74..2cccf65a 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -219,8 +219,8 @@ void arrange_workspace(struct sway_workspace *workspace) { struct sway_container *fs = workspace->fullscreen; fs->x = output->wlr_output->lx; fs->y = output->wlr_output->ly; - fs->width = output->wlr_output->width; - fs->height = output->wlr_output->height; + fs->width = output->width; + fs->height = output->height; arrange_container(fs); } else { struct wlr_box box; diff --git a/sway/tree/output.c b/sway/tree/output.c index d72eb1a1..afc336f8 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -75,6 +75,11 @@ void output_enable(struct sway_output *output, struct output_config *oc) { apply_output_config(oc, output); list_add(root->outputs, output); + output->lx = wlr_output->lx; + output->ly = wlr_output->ly; + wlr_output_transformed_resolution(wlr_output, + &output->width, &output->height); + restore_workspaces(output); if (!output->workspaces->length) { @@ -265,8 +270,8 @@ struct sway_output *output_get_in_direction(struct sway_output *reference, "got invalid direction: %d", direction)) { return NULL; } - int lx = reference->wlr_output->lx + reference->wlr_output->width / 2; - int ly = reference->wlr_output->ly + reference->wlr_output->height / 2; + int lx = reference->wlr_output->lx + reference->width / 2; + int ly = reference->wlr_output->ly + reference->height / 2; struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output( root->output_layout, wlr_dir, reference->wlr_output, lx, ly); if (!wlr_adjacent) { @@ -346,10 +351,10 @@ void output_sort_workspaces(struct sway_output *output) { } void output_get_box(struct sway_output *output, struct wlr_box *box) { - box->x = output->wlr_output->lx; - box->y = output->wlr_output->ly; - box->width = output->wlr_output->width; - box->height = output->wlr_output->height; + box->x = output->lx; + box->y = output->ly; + box->width = output->width; + box->height = output->height; } enum sway_container_layout output_get_default_layout( @@ -360,7 +365,7 @@ enum sway_container_layout output_get_default_layout( if (config->default_orientation != L_NONE) { return config->default_orientation; } - if (output->wlr_output->height > output->wlr_output->width) { + if (output->height > output->width) { return L_VERT; } return L_HORIZ; diff --git a/sway/tree/view.c b/sway/tree/view.c index 452c2bd1..ff63df2d 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -167,10 +167,10 @@ void view_autoconfigure(struct sway_view *view) { struct sway_output *output = view->container->workspace->output; if (view->container->is_fullscreen) { - view->x = output->wlr_output->lx; - view->y = output->wlr_output->ly; - view->width = output->wlr_output->width; - view->height = output->wlr_output->height; + view->x = output->lx; + view->y = output->ly; + view->width = output->width; + view->height = output->height; return; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 38ee478e..bb1ded22 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -53,10 +53,10 @@ struct sway_workspace *workspace_create(struct sway_output *output, return NULL; } node_init(&ws->node, N_WORKSPACE, ws); - ws->x = output->wlr_output->lx; - ws->y = output->wlr_output->ly; - ws->width = output->wlr_output->width; - ws->height = output->wlr_output->height; + ws->x = output->lx; + ws->y = output->ly; + ws->width = output->width; + ws->height = output->height; ws->name = name ? strdup(name) : NULL; ws->prev_split_layout = L_NONE; ws->layout = output_get_default_layout(output); -- cgit v1.2.3-54-g00ecf From 26204441b40591415855d971f87f2bed511ccd7d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 30 Aug 2018 23:58:53 +1000 Subject: Apply default config to output When starting without any output config, the default config was not applying. --- sway/desktop/output.c | 2 +- sway/tree/output.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'sway/tree/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 792a7231..7e9f7b7e 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -547,7 +547,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { struct output_config *oc = output_find_config(output); - if (oc && oc->enabled) { + if (!oc || oc->enabled) { output_enable(output, oc); } diff --git a/sway/tree/output.c b/sway/tree/output.c index afc336f8..35589032 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -253,9 +253,6 @@ struct output_config *output_find_config(struct sway_output *output) { oc = all; } - if (oc && !oc->enabled) { - return NULL; - } return oc; } -- cgit v1.2.3-54-g00ecf