summaryrefslogtreecommitdiffstats
path: root/sway/desktop/xdg_shell_v6.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_v6.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_v6.c')
-rw-r--r--sway/desktop/xdg_shell_v6.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 175416f3..b23d4577 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -10,10 +10,12 @@
10#include "sway/desktop/transaction.h" 10#include "sway/desktop/transaction.h"
11#include "sway/input/input-manager.h" 11#include "sway/input/input-manager.h"
12#include "sway/input/seat.h" 12#include "sway/input/seat.h"
13#include "sway/output.h"
13#include "sway/server.h" 14#include "sway/server.h"
14#include "sway/tree/arrange.h" 15#include "sway/tree/arrange.h"
15#include "sway/tree/container.h" 16#include "sway/tree/container.h"
16#include "sway/tree/view.h" 17#include "sway/tree/view.h"
18#include "sway/tree/workspace.h"
17 19
18static const struct sway_view_child_impl popup_impl; 20static const struct sway_view_child_impl popup_impl;
19 21
@@ -51,15 +53,15 @@ static void popup_unconstrain(struct sway_xdg_popup_v6 *popup) {
51 struct sway_view *view = popup->child.view; 53 struct sway_view *view = popup->child.view;
52 struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_xdg_surface_v6->popup; 54 struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_xdg_surface_v6->popup;
53 55
54 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 56 struct sway_output *output = view->container->workspace->output;
55 57
56 // the output box expressed in the coordinate system of the toplevel parent 58 // the output box expressed in the coordinate system of the toplevel parent
57 // of the popup 59 // of the popup
58 struct wlr_box output_toplevel_sx_box = { 60 struct wlr_box output_toplevel_sx_box = {
59 .x = output->x - view->x, 61 .x = output->wlr_output->lx - view->x,
60 .y = output->y - view->y, 62 .y = output->wlr_output->ly - view->y,
61 .width = output->width, 63 .width = output->wlr_output->width,
62 .height = output->height, 64 .height = output->wlr_output->height,
63 }; 65 };
64 66
65 wlr_xdg_popup_v6_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box); 67 wlr_xdg_popup_v6_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
@@ -249,11 +251,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
249 struct sway_view *view = &xdg_shell_v6_view->view; 251 struct sway_view *view = &xdg_shell_v6_view->view;
250 struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6; 252 struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6;
251 253
252 if (!view->swayc) { 254 if (view->container->node.instruction) {
253 return;
254 }
255
256 if (view->swayc->instruction) {
257 wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &view->geometry); 255 wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &view->geometry);
258 transaction_notify_view_ready_by_serial(view, 256 transaction_notify_view_ready_by_serial(view,
259 xdg_surface_v6->configure_serial); 257 xdg_surface_v6->configure_serial);
@@ -262,7 +260,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
262 wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo); 260 wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo);
263 261
264 if ((new_geo.width != view->width || new_geo.height != view->height) && 262 if ((new_geo.width != view->width || new_geo.height != view->height) &&
265 container_is_floating(view->swayc)) { 263 container_is_floating(view->container)) {
266 // A floating view has unexpectedly sent a new size 264 // A floating view has unexpectedly sent a new size
267 desktop_damage_view(view); 265 desktop_damage_view(view);
268 view_update_size(view, new_geo.width, new_geo.height); 266 view_update_size(view, new_geo.width, new_geo.height);
@@ -316,10 +314,9 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
316 return; 314 return;
317 } 315 }
318 316
319 container_set_fullscreen(view->swayc, e->fullscreen); 317 container_set_fullscreen(view->container, e->fullscreen);
320 318
321 struct sway_container *output = container_parent(view->swayc, C_OUTPUT); 319 arrange_workspace(view->container->workspace);
322 arrange_windows(output);
323 transaction_commit_dirty(); 320 transaction_commit_dirty();
324} 321}
325 322
@@ -327,13 +324,13 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
327 struct sway_xdg_shell_v6_view *xdg_shell_v6_view = 324 struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
328 wl_container_of(listener, xdg_shell_v6_view, request_move); 325 wl_container_of(listener, xdg_shell_v6_view, request_move);
329 struct sway_view *view = &xdg_shell_v6_view->view; 326 struct sway_view *view = &xdg_shell_v6_view->view;
330 if (!container_is_floating(view->swayc)) { 327 if (!container_is_floating(view->container)) {
331 return; 328 return;
332 } 329 }
333 struct wlr_xdg_toplevel_v6_move_event *e = data; 330 struct wlr_xdg_toplevel_v6_move_event *e = data;
334 struct sway_seat *seat = e->seat->seat->data; 331 struct sway_seat *seat = e->seat->seat->data;
335 if (e->serial == seat->last_button_serial) { 332 if (e->serial == seat->last_button_serial) {
336 seat_begin_move(seat, view->swayc, seat->last_button); 333 seat_begin_move(seat, view->container, seat->last_button);
337 } 334 }
338} 335}
339 336
@@ -341,13 +338,13 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
341 struct sway_xdg_shell_v6_view *xdg_shell_v6_view = 338 struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
342 wl_container_of(listener, xdg_shell_v6_view, request_resize); 339 wl_container_of(listener, xdg_shell_v6_view, request_resize);
343 struct sway_view *view = &xdg_shell_v6_view->view; 340 struct sway_view *view = &xdg_shell_v6_view->view;
344 if (!container_is_floating(view->swayc)) { 341 if (!container_is_floating(view->container)) {
345 return; 342 return;
346 } 343 }
347 struct wlr_xdg_toplevel_v6_resize_event *e = data; 344 struct wlr_xdg_toplevel_v6_resize_event *e = data;
348 struct sway_seat *seat = e->seat->seat->data; 345 struct sway_seat *seat = e->seat->seat->data;
349 if (e->serial == seat->last_button_serial) { 346 if (e->serial == seat->last_button_serial) {
350 seat_begin_resize_floating(seat, view->swayc, 347 seat_begin_resize_floating(seat, view->container,
351 seat->last_button, e->edges); 348 seat->last_button, e->edges);
352 } 349 }
353} 350}
@@ -396,11 +393,14 @@ static void handle_map(struct wl_listener *listener, void *data) {
396 view_map(view, view->wlr_xdg_surface_v6->surface); 393 view_map(view, view->wlr_xdg_surface_v6->surface);
397 394
398 if (xdg_surface->toplevel->client_pending.fullscreen) { 395 if (xdg_surface->toplevel->client_pending.fullscreen) {
399 container_set_fullscreen(view->swayc, true); 396 container_set_fullscreen(view->container, true);
400 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 397 arrange_workspace(view->container->workspace);
401 arrange_windows(ws);
402 } else { 398 } else {
403 arrange_windows(view->swayc->parent); 399 if (view->container->parent) {
400 arrange_container(view->container->parent);
401 } else {
402 arrange_workspace(view->container->workspace);
403 }
404 } 404 }
405 transaction_commit_dirty(); 405 transaction_commit_dirty();
406 406