aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree/workspace.h
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 /include/sway/tree/workspace.h
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 'include/sway/tree/workspace.h')
-rw-r--r--include/sway/tree/workspace.h105
1 files changed, 76 insertions, 29 deletions
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
index 04325919..af9a071a 100644
--- a/include/sway/tree/workspace.h
+++ b/include/sway/tree/workspace.h
@@ -3,66 +3,98 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "sway/tree/container.h" 5#include "sway/tree/container.h"
6#include "sway/tree/node.h"
6 7
7struct sway_view; 8struct sway_view;
8 9
10struct sway_workspace_state {
11 struct sway_container *fullscreen;
12 double x, y;
13 int width, height;
14 enum sway_container_layout layout;
15 struct sway_output *output;
16 list_t *floating;
17 list_t *tiling;
18
19 struct sway_container *focused_inactive_child;
20 bool focused;
21};
22
9struct sway_workspace { 23struct sway_workspace {
10 struct sway_container *swayc; 24 struct sway_node node;
11 struct sway_container *fullscreen; 25 struct sway_container *fullscreen;
12 list_t *floating; // struct sway_container 26
27 char *name;
28 char *representation;
29
30 double x, y;
31 int width, height;
32 enum sway_container_layout layout;
33 enum sway_container_layout prev_split_layout;
34
35 double current_gaps;
36 bool has_gaps;
37 double gaps_inner;
38 double gaps_outer;
39
40 struct sway_output *output; // NULL if no outputs are connected
41 list_t *floating; // struct sway_container
42 list_t *tiling; // struct sway_container
13 list_t *output_priority; 43 list_t *output_priority;
14 bool urgent; 44 bool urgent;
45
46 struct sway_workspace_state current;
15}; 47};
16 48
17extern char *prev_workspace_name; 49extern char *prev_workspace_name;
18 50
19struct sway_container *workspace_get_initial_output(const char *name); 51struct sway_output *workspace_get_initial_output(const char *name);
20 52
21struct sway_container *workspace_create(struct sway_container *output, 53struct sway_workspace *workspace_create(struct sway_output *output,
22 const char *name); 54 const char *name);
23 55
24void workspace_destroy(struct sway_container *workspace); 56void workspace_destroy(struct sway_workspace *workspace);
25 57
26void workspace_begin_destroy(struct sway_container *workspace); 58void workspace_begin_destroy(struct sway_workspace *workspace);
27 59
28void workspace_consider_destroy(struct sway_container *ws); 60void workspace_consider_destroy(struct sway_workspace *ws);
29 61
30char *workspace_next_name(const char *output_name); 62char *workspace_next_name(const char *output_name);
31 63
32bool workspace_switch(struct sway_container *workspace, 64bool workspace_switch(struct sway_workspace *workspace,
33 bool no_auto_back_and_forth); 65 bool no_auto_back_and_forth);
34 66
35struct sway_container *workspace_by_number(const char* name); 67struct sway_workspace *workspace_by_number(const char* name);
36 68
37struct sway_container *workspace_by_name(const char*); 69struct sway_workspace *workspace_by_name(const char*);
38 70
39struct sway_container *workspace_output_next(struct sway_container *current); 71struct sway_workspace *workspace_output_next(struct sway_workspace *current);
40 72
41struct sway_container *workspace_next(struct sway_container *current); 73struct sway_workspace *workspace_next(struct sway_workspace *current);
42 74
43struct sway_container *workspace_output_prev(struct sway_container *current); 75struct sway_workspace *workspace_output_prev(struct sway_workspace *current);
44 76
45struct sway_container *workspace_prev(struct sway_container *current); 77struct sway_workspace *workspace_prev(struct sway_workspace *current);
46 78
47bool workspace_is_visible(struct sway_container *ws); 79bool workspace_is_visible(struct sway_workspace *ws);
48 80
49bool workspace_is_empty(struct sway_container *ws); 81bool workspace_is_empty(struct sway_workspace *ws);
50 82
51void workspace_output_raise_priority(struct sway_container *workspace, 83void workspace_output_raise_priority(struct sway_workspace *workspace,
52 struct sway_container *old_output, struct sway_container *new_output); 84 struct sway_output *old_output, struct sway_output *new_output);
53 85
54void workspace_output_add_priority(struct sway_container *workspace, 86void workspace_output_add_priority(struct sway_workspace *workspace,
55 struct sway_container *output); 87 struct sway_output *output);
56 88
57struct sway_container *workspace_output_get_highest_available( 89struct sway_output *workspace_output_get_highest_available(
58 struct sway_container *ws, struct sway_container *exclude); 90 struct sway_workspace *ws, struct sway_output *exclude);
59 91
60void workspace_detect_urgent(struct sway_container *workspace); 92void workspace_detect_urgent(struct sway_workspace *workspace);
61 93
62void workspace_for_each_container(struct sway_container *ws, 94void workspace_for_each_container(struct sway_workspace *ws,
63 void (*f)(struct sway_container *con, void *data), void *data); 95 void (*f)(struct sway_container *con, void *data), void *data);
64 96
65struct sway_container *workspace_find_container(struct sway_container *ws, 97struct sway_container *workspace_find_container(struct sway_workspace *ws,
66 bool (*test)(struct sway_container *con, void *data), void *data); 98 bool (*test)(struct sway_container *con, void *data), void *data);
67 99
68/** 100/**
@@ -70,13 +102,28 @@ struct sway_container *workspace_find_container(struct sway_container *ws,
70 * The new container will be the only direct tiling child of the workspace. 102 * The new container will be the only direct tiling child of the workspace.
71 * The new container is returned. 103 * The new container is returned.
72 */ 104 */
73struct sway_container *workspace_wrap_children(struct sway_container *ws); 105struct sway_container *workspace_wrap_children(struct sway_workspace *ws);
74 106
75void workspace_add_floating(struct sway_container *workspace, 107void workspace_detach(struct sway_workspace *workspace);
108
109void workspace_add_tiling(struct sway_workspace *workspace,
110 struct sway_container *con);
111
112void workspace_add_floating(struct sway_workspace *workspace,
76 struct sway_container *con); 113 struct sway_container *con);
77 114
78void workspace_remove_gaps(struct sway_container *ws); 115void workspace_insert_tiling(struct sway_workspace *workspace,
116 struct sway_container *con, int index);
117
118void workspace_remove_gaps(struct sway_workspace *ws);
119
120void workspace_add_gaps(struct sway_workspace *ws);
121
122struct sway_container *workspace_split(struct sway_workspace *workspace,
123 enum sway_container_layout layout);
124
125void workspace_update_representation(struct sway_workspace *ws);
79 126
80void workspace_add_gaps(struct sway_container *ws); 127void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box);
81 128
82#endif 129#endif