aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/scratchpad.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/commands/scratchpad.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/commands/scratchpad.c')
-rw-r--r--sway/commands/scratchpad.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
index 7da20015..d8bae615 100644
--- a/sway/commands/scratchpad.c
+++ b/sway/commands/scratchpad.c
@@ -9,36 +9,34 @@
9 9
10static void scratchpad_toggle_auto(void) { 10static void scratchpad_toggle_auto(void) {
11 struct sway_seat *seat = input_manager_current_seat(input_manager); 11 struct sway_seat *seat = input_manager_current_seat(input_manager);
12 struct sway_container *focus = seat_get_focus(seat); 12 struct sway_container *focus = seat_get_focused_container(seat);
13 struct sway_container *ws = focus->type == C_WORKSPACE ? 13 struct sway_workspace *ws = seat_get_focused_workspace(seat);
14 focus : container_parent(focus, C_WORKSPACE);
15 14
16 // If the focus is in a floating split container, 15 // If the focus is in a floating split container,
17 // operate on the split container instead of the child. 16 // operate on the split container instead of the child.
18 if (container_is_floating_or_child(focus)) { 17 if (focus && container_is_floating_or_child(focus)) {
19 while (focus->parent->type != C_WORKSPACE) { 18 while (focus->parent) {
20 focus = focus->parent; 19 focus = focus->parent;
21 } 20 }
22 } 21 }
23 22
24
25 // Check if the currently focused window is a scratchpad window and should 23 // Check if the currently focused window is a scratchpad window and should
26 // be hidden again. 24 // be hidden again.
27 if (focus->scratchpad) { 25 if (focus && focus->scratchpad) {
28 wlr_log(WLR_DEBUG, "Focus is a scratchpad window - hiding %s", 26 wlr_log(WLR_DEBUG, "Focus is a scratchpad window - hiding %s",
29 focus->name); 27 focus->title);
30 root_scratchpad_hide(focus); 28 root_scratchpad_hide(focus);
31 return; 29 return;
32 } 30 }
33 31
34 // Check if there is an unfocused scratchpad window on the current workspace 32 // Check if there is an unfocused scratchpad window on the current workspace
35 // and focus it. 33 // and focus it.
36 for (int i = 0; i < ws->sway_workspace->floating->length; ++i) { 34 for (int i = 0; i < ws->floating->length; ++i) {
37 struct sway_container *floater = ws->sway_workspace->floating->items[i]; 35 struct sway_container *floater = ws->floating->items[i];
38 if (floater->scratchpad && focus != floater) { 36 if (floater->scratchpad && focus != floater) {
39 wlr_log(WLR_DEBUG, 37 wlr_log(WLR_DEBUG,
40 "Focusing other scratchpad window (%s) in this workspace", 38 "Focusing other scratchpad window (%s) in this workspace",
41 floater->name); 39 floater->title);
42 root_scratchpad_show(floater); 40 root_scratchpad_show(floater);
43 return; 41 return;
44 } 42 }
@@ -46,25 +44,23 @@ static void scratchpad_toggle_auto(void) {
46 44
47 // Check if there is a visible scratchpad window on another workspace. 45 // Check if there is a visible scratchpad window on another workspace.
48 // In this case we move it to the current workspace. 46 // In this case we move it to the current workspace.
49 for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) { 47 for (int i = 0; i < root->scratchpad->length; ++i) {
50 struct sway_container *con = 48 struct sway_container *con = root->scratchpad->items[i];
51 root_container.sway_root->scratchpad->items[i];
52 if (con->parent) { 49 if (con->parent) {
53 wlr_log(WLR_DEBUG, 50 wlr_log(WLR_DEBUG,
54 "Moving a visible scratchpad window (%s) to this workspace", 51 "Moving a visible scratchpad window (%s) to this workspace",
55 con->name); 52 con->title);
56 root_scratchpad_show(con); 53 root_scratchpad_show(con);
57 return; 54 return;
58 } 55 }
59 } 56 }
60 57
61 // Take the container at the bottom of the scratchpad list 58 // Take the container at the bottom of the scratchpad list
62 if (!sway_assert(root_container.sway_root->scratchpad->length, 59 if (!sway_assert(root->scratchpad->length, "Scratchpad is empty")) {
63 "Scratchpad is empty")) {
64 return; 60 return;
65 } 61 }
66 struct sway_container *con = root_container.sway_root->scratchpad->items[0]; 62 struct sway_container *con = root->scratchpad->items[0];
67 wlr_log(WLR_DEBUG, "Showing %s from list", con->name); 63 wlr_log(WLR_DEBUG, "Showing %s from list", con->title);
68 root_scratchpad_show(con); 64 root_scratchpad_show(con);
69} 65}
70 66
@@ -74,7 +70,7 @@ static void scratchpad_toggle_container(struct sway_container *con) {
74 } 70 }
75 71
76 // Check if it matches a currently visible scratchpad window and hide it. 72 // Check if it matches a currently visible scratchpad window and hide it.
77 if (con->parent) { 73 if (con->workspace) {
78 root_scratchpad_hide(con); 74 root_scratchpad_hide(con);
79 return; 75 return;
80 } 76 }
@@ -91,18 +87,18 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) {
91 return cmd_results_new(CMD_INVALID, "scratchpad", 87 return cmd_results_new(CMD_INVALID, "scratchpad",
92 "Expected 'scratchpad show'"); 88 "Expected 'scratchpad show'");
93 } 89 }
94 if (!root_container.sway_root->scratchpad->length) { 90 if (!root->scratchpad->length) {
95 return cmd_results_new(CMD_INVALID, "scratchpad", 91 return cmd_results_new(CMD_INVALID, "scratchpad",
96 "Scratchpad is empty"); 92 "Scratchpad is empty");
97 } 93 }
98 94
99 if (config->handler_context.using_criteria) { 95 if (config->handler_context.using_criteria) {
100 struct sway_container *con = config->handler_context.current_container; 96 struct sway_container *con = config->handler_context.container;
101 97
102 // If the container is in a floating split container, 98 // If the container is in a floating split container,
103 // operate on the split container instead of the child. 99 // operate on the split container instead of the child.
104 if (container_is_floating_or_child(con)) { 100 if (container_is_floating_or_child(con)) {
105 while (con->parent->type != C_WORKSPACE) { 101 while (con->parent) {
106 con = con->parent; 102 con = con->parent;
107 } 103 }
108 } 104 }