aboutsummaryrefslogtreecommitdiffstats
path: root/sway/criteria.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/criteria.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/criteria.c')
-rw-r--r--sway/criteria.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/sway/criteria.c b/sway/criteria.c
index feca904a..e5b308e0 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -9,6 +9,7 @@
9#include "sway/config.h" 9#include "sway/config.h"
10#include "sway/tree/root.h" 10#include "sway/tree/root.h"
11#include "sway/tree/view.h" 11#include "sway/tree/view.h"
12#include "sway/tree/workspace.h"
12#include "stringop.h" 13#include "stringop.h"
13#include "list.h" 14#include "list.h"
14#include "log.h" 15#include "log.h"
@@ -87,12 +88,12 @@ static int cmp_urgent(const void *_a, const void *_b) {
87 return 0; 88 return 0;
88} 89}
89 90
90static void find_urgent_iterator(struct sway_container *swayc, void *data) { 91static void find_urgent_iterator(struct sway_container *con, void *data) {
91 if (swayc->type != C_VIEW || !view_is_urgent(swayc->sway_view)) { 92 if (!con->view || !view_is_urgent(con->view)) {
92 return; 93 return;
93 } 94 }
94 list_t *urgent_views = data; 95 list_t *urgent_views = data;
95 list_add(urgent_views, swayc->sway_view); 96 list_add(urgent_views, con->view);
96} 97}
97 98
98static bool criteria_matches_view(struct criteria *criteria, 99static bool criteria_matches_view(struct criteria *criteria,
@@ -132,7 +133,7 @@ static bool criteria_matches_view(struct criteria *criteria,
132 } 133 }
133 134
134 if (criteria->con_id) { // Internal ID 135 if (criteria->con_id) { // Internal ID
135 if (!view->swayc || view->swayc->id != criteria->con_id) { 136 if (!view->container || view->container->node.id != criteria->con_id) {
136 return false; 137 return false;
137 } 138 }
138 } 139 }
@@ -174,13 +175,13 @@ static bool criteria_matches_view(struct criteria *criteria,
174#endif 175#endif
175 176
176 if (criteria->floating) { 177 if (criteria->floating) {
177 if (!container_is_floating(view->swayc)) { 178 if (!container_is_floating(view->container)) {
178 return false; 179 return false;
179 } 180 }
180 } 181 }
181 182
182 if (criteria->tiling) { 183 if (criteria->tiling) {
183 if (container_is_floating(view->swayc)) { 184 if (container_is_floating(view->container)) {
184 return false; 185 return false;
185 } 186 }
186 } 187 }
@@ -205,10 +206,7 @@ static bool criteria_matches_view(struct criteria *criteria,
205 } 206 }
206 207
207 if (criteria->workspace) { 208 if (criteria->workspace) {
208 if (!view->swayc) { 209 struct sway_workspace *ws = view->container->workspace;
209 return false;
210 }
211 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
212 if (!ws || strcmp(ws->name, criteria->workspace) != 0) { 210 if (!ws || strcmp(ws->name, criteria->workspace) != 0) {
213 return false; 211 return false;
214 } 212 }
@@ -237,9 +235,9 @@ struct match_data {
237static void criteria_get_views_iterator(struct sway_container *container, 235static void criteria_get_views_iterator(struct sway_container *container,
238 void *data) { 236 void *data) {
239 struct match_data *match_data = data; 237 struct match_data *match_data = data;
240 if (container->type == C_VIEW) { 238 if (!container->view) {
241 if (criteria_matches_view(match_data->criteria, container->sway_view)) { 239 if (criteria_matches_view(match_data->criteria, container->view)) {
242 list_add(match_data->matches, container->sway_view); 240 list_add(match_data->matches, container->view);
243 } 241 }
244 } 242 }
245} 243}
@@ -355,12 +353,12 @@ static enum criteria_token token_from_name(char *name) {
355 */ 353 */
356static char *get_focused_prop(enum criteria_token token) { 354static char *get_focused_prop(enum criteria_token token) {
357 struct sway_seat *seat = input_manager_current_seat(input_manager); 355 struct sway_seat *seat = input_manager_current_seat(input_manager);
358 struct sway_container *focus = seat_get_focus(seat); 356 struct sway_container *focus = seat_get_focused_container(seat);
359 357
360 if (!focus || focus->type != C_VIEW) { 358 if (!focus || !focus->view) {
361 return NULL; 359 return NULL;
362 } 360 }
363 struct sway_view *view = focus->sway_view; 361 struct sway_view *view = focus->view;
364 const char *value = NULL; 362 const char *value = NULL;
365 363
366 switch (token) { 364 switch (token) {
@@ -374,18 +372,15 @@ static char *get_focused_prop(enum criteria_token token) {
374 value = view_get_title(view); 372 value = view_get_title(view);
375 break; 373 break;
376 case T_WORKSPACE: 374 case T_WORKSPACE:
377 { 375 if (focus->workspace) {
378 struct sway_container *ws = container_parent(focus, C_WORKSPACE); 376 value = focus->workspace->name;
379 if (ws) {
380 value = ws->name;
381 }
382 } 377 }
383 break; 378 break;
384 case T_CON_ID: 379 case T_CON_ID:
385 if (view->swayc == NULL) { 380 if (view->container == NULL) {
386 return NULL; 381 return NULL;
387 } 382 }
388 size_t id = view->swayc->id; 383 size_t id = view->container->node.id;
389 size_t id_size = snprintf(NULL, 0, "%zu", id) + 1; 384 size_t id_size = snprintf(NULL, 0, "%zu", id) + 1;
390 char *id_str = malloc(id_size); 385 char *id_str = malloc(id_size);
391 snprintf(id_str, id_size, "%zu", id); 386 snprintf(id_str, id_size, "%zu", id);