aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/xdg_shell.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-30 21:00:10 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-05 18:01:43 +1000
commit7586f150c058997d9dde387ea7c091ffa7a3c3c7 (patch)
tree63d19027974c1db62ce3a74ca1d2314eb6d5049b /sway/desktop/xdg_shell.c
parentMerge pull request #2569 from RyanDwyer/deny-reload-repeat (diff)
downloadsway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.tar.gz
sway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.tar.zst
sway-7586f150c058997d9dde387ea7c091ffa7a3c3c7.zip
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.
Diffstat (limited to 'sway/desktop/xdg_shell.c')
-rw-r--r--sway/desktop/xdg_shell.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 587deb0f..e19d8e18 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -11,10 +11,12 @@
11#include "sway/desktop/transaction.h" 11#include "sway/desktop/transaction.h"
12#include "sway/input/input-manager.h" 12#include "sway/input/input-manager.h"
13#include "sway/input/seat.h" 13#include "sway/input/seat.h"
14#include "sway/output.h"
14#include "sway/server.h" 15#include "sway/server.h"
15#include "sway/tree/arrange.h" 16#include "sway/tree/arrange.h"
16#include "sway/tree/container.h" 17#include "sway/tree/container.h"
17#include "sway/tree/view.h" 18#include "sway/tree/view.h"
19#include "sway/tree/workspace.h"
18 20
19static const struct sway_view_child_impl popup_impl; 21static const struct sway_view_child_impl popup_impl;
20 22
@@ -52,15 +54,15 @@ static void popup_unconstrain(struct sway_xdg_popup *popup) {
52 struct sway_view *view = popup->child.view; 54 struct sway_view *view = popup->child.view;
53 struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup; 55 struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup;
54 56
55 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 57 struct sway_output *output = view->container->workspace->output;
56 58
57 // the output box expressed in the coordinate system of the toplevel parent 59 // the output box expressed in the coordinate system of the toplevel parent
58 // of the popup 60 // of the popup
59 struct wlr_box output_toplevel_sx_box = { 61 struct wlr_box output_toplevel_sx_box = {
60 .x = output->x - view->x, 62 .x = output->wlr_output->lx - view->x,
61 .y = output->y - view->y, 63 .y = output->wlr_output->ly - view->y,
62 .width = output->width, 64 .width = output->wlr_output->width,
63 .height = output->height, 65 .height = output->wlr_output->height,
64 }; 66 };
65 67
66 wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box); 68 wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
@@ -252,11 +254,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
252 struct sway_view *view = &xdg_shell_view->view; 254 struct sway_view *view = &xdg_shell_view->view;
253 struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface; 255 struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
254 256
255 if (!view->swayc) { 257 if (view->container->node.instruction) {
256 return;
257 }
258
259 if (view->swayc->instruction) {
260 wlr_xdg_surface_get_geometry(xdg_surface, &view->geometry); 258 wlr_xdg_surface_get_geometry(xdg_surface, &view->geometry);
261 transaction_notify_view_ready_by_serial(view, 259 transaction_notify_view_ready_by_serial(view,
262 xdg_surface->configure_serial); 260 xdg_surface->configure_serial);
@@ -265,7 +263,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
265 wlr_xdg_surface_get_geometry(xdg_surface, &new_geo); 263 wlr_xdg_surface_get_geometry(xdg_surface, &new_geo);
266 264
267 if ((new_geo.width != view->width || new_geo.height != view->height) && 265 if ((new_geo.width != view->width || new_geo.height != view->height) &&
268 container_is_floating(view->swayc)) { 266 container_is_floating(view->container)) {
269 // A floating view has unexpectedly sent a new size 267 // A floating view has unexpectedly sent a new size
270 desktop_damage_view(view); 268 desktop_damage_view(view);
271 view_update_size(view, new_geo.width, new_geo.height); 269 view_update_size(view, new_geo.width, new_geo.height);
@@ -319,10 +317,9 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
319 return; 317 return;
320 } 318 }
321 319
322 container_set_fullscreen(view->swayc, e->fullscreen); 320 container_set_fullscreen(view->container, e->fullscreen);
323 321
324 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 322 arrange_workspace(view->container->workspace);
325 arrange_windows(output);
326 transaction_commit_dirty(); 323 transaction_commit_dirty();
327} 324}
328 325
@@ -330,13 +327,13 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
330 struct sway_xdg_shell_view *xdg_shell_view = 327 struct sway_xdg_shell_view *xdg_shell_view =
331 wl_container_of(listener, xdg_shell_view, request_move); 328 wl_container_of(listener, xdg_shell_view, request_move);
332 struct sway_view *view = &xdg_shell_view->view; 329 struct sway_view *view = &xdg_shell_view->view;
333 if (!container_is_floating(view->swayc)) { 330 if (!container_is_floating(view->container)) {
334 return; 331 return;
335 } 332 }
336 struct wlr_xdg_toplevel_move_event *e = data; 333 struct wlr_xdg_toplevel_move_event *e = data;
337 struct sway_seat *seat = e->seat->seat->data; 334 struct sway_seat *seat = e->seat->seat->data;
338 if (e->serial == seat->last_button_serial) { 335 if (e->serial == seat->last_button_serial) {
339 seat_begin_move(seat, view->swayc, seat->last_button); 336 seat_begin_move(seat, view->container, seat->last_button);
340 } 337 }
341} 338}
342 339
@@ -344,13 +341,13 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
344 struct sway_xdg_shell_view *xdg_shell_view = 341 struct sway_xdg_shell_view *xdg_shell_view =
345 wl_container_of(listener, xdg_shell_view, request_resize); 342 wl_container_of(listener, xdg_shell_view, request_resize);
346 struct sway_view *view = &xdg_shell_view->view; 343 struct sway_view *view = &xdg_shell_view->view;
347 if (!container_is_floating(view->swayc)) { 344 if (!container_is_floating(view->container)) {
348 return; 345 return;
349 } 346 }
350 struct wlr_xdg_toplevel_resize_event *e = data; 347 struct wlr_xdg_toplevel_resize_event *e = data;
351 struct sway_seat *seat = e->seat->seat->data; 348 struct sway_seat *seat = e->seat->seat->data;
352 if (e->serial == seat->last_button_serial) { 349 if (e->serial == seat->last_button_serial) {
353 seat_begin_resize_floating(seat, view->swayc, 350 seat_begin_resize_floating(seat, view->container,
354 seat->last_button, e->edges); 351 seat->last_button, e->edges);
355 } 352 }
356} 353}
@@ -399,11 +396,14 @@ static void handle_map(struct wl_listener *listener, void *data) {
399 view_map(view, view->wlr_xdg_surface->surface); 396 view_map(view, view->wlr_xdg_surface->surface);
400 397
401 if (xdg_surface->toplevel->client_pending.fullscreen) { 398 if (xdg_surface->toplevel->client_pending.fullscreen) {
402 container_set_fullscreen(view->swayc, true); 399 container_set_fullscreen(view->container, true);
403 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 400 arrange_workspace(view->container->workspace);
404 arrange_windows(ws);
405 } else { 401 } else {
406 arrange_windows(view->swayc->parent); 402 if (view->container->parent) {
403 arrange_container(view->container->parent);
404 } else {
405 arrange_workspace(view->container->workspace);
406 }
407 } 407 }
408 transaction_commit_dirty(); 408 transaction_commit_dirty();
409 409
@@ -440,8 +440,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
440 struct sway_xdg_shell_view *xdg_shell_view = 440 struct sway_xdg_shell_view *xdg_shell_view =
441 wl_container_of(listener, xdg_shell_view, destroy); 441 wl_container_of(listener, xdg_shell_view, destroy);
442 struct sway_view *view = &xdg_shell_view->view; 442 struct sway_view *view = &xdg_shell_view->view;
443 if (!sway_assert(view->swayc == NULL || view->swayc->destroying, 443 if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
444 "Tried to destroy a mapped view")) {
445 return; 444 return;
446 } 445 }
447 wl_list_remove(&xdg_shell_view->destroy.link); 446 wl_list_remove(&xdg_shell_view->destroy.link);