aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/output.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/config/output.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/config/output.c')
-rw-r--r--sway/config/output.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 65f09258..aa53fc46 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -174,21 +174,16 @@ void terminate_swaybg(pid_t pid) {
174 } 174 }
175} 175}
176 176
177void apply_output_config(struct output_config *oc, struct sway_container *output) { 177void apply_output_config(struct output_config *oc, struct sway_output *output) {
178 assert(output->type == C_OUTPUT); 178 struct wlr_output *wlr_output = output->wlr_output;
179
180 struct wlr_output_layout *output_layout =
181 root_container.sway_root->output_layout;
182 struct wlr_output *wlr_output = output->sway_output->wlr_output;
183 179
184 if (oc && oc->enabled == 0) { 180 if (oc && oc->enabled == 0) {
185 if (output->sway_output->bg_pid != 0) { 181 if (output->bg_pid != 0) {
186 terminate_swaybg(output->sway_output->bg_pid); 182 terminate_swaybg(output->bg_pid);
187 output->sway_output->bg_pid = 0; 183 output->bg_pid = 0;
188 } 184 }
189 output_begin_destroy(output); 185 output_disable(output);
190 wlr_output_layout_remove(root_container.sway_root->output_layout, 186 wlr_output_layout_remove(root->output_layout, wlr_output);
191 wlr_output);
192 return; 187 return;
193 } 188 }
194 189
@@ -213,21 +208,21 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
213 // Find position for it 208 // Find position for it
214 if (oc && (oc->x != -1 || oc->y != -1)) { 209 if (oc && (oc->x != -1 || oc->y != -1)) {
215 wlr_log(WLR_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); 210 wlr_log(WLR_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
216 wlr_output_layout_add(output_layout, wlr_output, oc->x, oc->y); 211 wlr_output_layout_add(root->output_layout, wlr_output, oc->x, oc->y);
217 } else { 212 } else {
218 wlr_output_layout_add_auto(output_layout, wlr_output); 213 wlr_output_layout_add_auto(root->output_layout, wlr_output);
219 } 214 }
220 215
221 int output_i; 216 int output_i;
222 for (output_i = 0; output_i < root_container.children->length; ++output_i) { 217 for (output_i = 0; output_i < root->outputs->length; ++output_i) {
223 if (root_container.children->items[output_i] == output) { 218 if (root->outputs->items[output_i] == output) {
224 break; 219 break;
225 } 220 }
226 } 221 }
227 222
228 if (oc && oc->background) { 223 if (oc && oc->background) {
229 if (output->sway_output->bg_pid != 0) { 224 if (output->bg_pid != 0) {
230 terminate_swaybg(output->sway_output->bg_pid); 225 terminate_swaybg(output->bg_pid);
231 } 226 }
232 227
233 wlr_log(WLR_DEBUG, "Setting background for output %d to %s", 228 wlr_log(WLR_DEBUG, "Setting background for output %d to %s",
@@ -249,8 +244,8 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
249 wlr_log(WLR_DEBUG, "-> %s", command); 244 wlr_log(WLR_DEBUG, "-> %s", command);
250 245
251 char *const cmd[] = { "sh", "-c", command, NULL }; 246 char *const cmd[] = { "sh", "-c", command, NULL };
252 output->sway_output->bg_pid = fork(); 247 output->bg_pid = fork();
253 if (output->sway_output->bg_pid == 0) { 248 if (output->bg_pid == 0) {
254 execvp(cmd[0], cmd); 249 execvp(cmd[0], cmd);
255 } else { 250 } else {
256 free(command); 251 free(command);
@@ -293,12 +288,11 @@ void apply_output_config_to_outputs(struct output_config *oc) {
293 bool wildcard = strcmp(oc->name, "*") == 0; 288 bool wildcard = strcmp(oc->name, "*") == 0;
294 char id[128]; 289 char id[128];
295 struct sway_output *sway_output; 290 struct sway_output *sway_output;
296 wl_list_for_each(sway_output, 291 wl_list_for_each(sway_output, &root->all_outputs, link) {
297 &root_container.sway_root->all_outputs, link) {
298 char *name = sway_output->wlr_output->name; 292 char *name = sway_output->wlr_output->name;
299 output_get_identifier(id, sizeof(id), sway_output); 293 output_get_identifier(id, sizeof(id), sway_output);
300 if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { 294 if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
301 if (!sway_output->swayc) { 295 if (!sway_output->enabled) {
302 if (!oc->enabled) { 296 if (!oc->enabled) {
303 if (!wildcard) { 297 if (!wildcard) {
304 break; 298 break;
@@ -306,7 +300,7 @@ void apply_output_config_to_outputs(struct output_config *oc) {
306 continue; 300 continue;
307 } 301 }
308 302
309 output_enable(sway_output); 303 output_enable(sway_output, oc);
310 } 304 }
311 305
312 struct output_config *current = oc; 306 struct output_config *current = oc;
@@ -316,7 +310,7 @@ void apply_output_config_to_outputs(struct output_config *oc) {
316 current = tmp; 310 current = tmp;
317 } 311 }
318 } 312 }
319 apply_output_config(current, sway_output->swayc); 313 apply_output_config(current, sway_output);
320 314
321 if (!wildcard) { 315 if (!wildcard) {
322 // Stop looking if the output config isn't applicable to all 316 // Stop looking if the output config isn't applicable to all
@@ -354,8 +348,7 @@ static void default_output_config(struct output_config *oc,
354 348
355void create_default_output_configs(void) { 349void create_default_output_configs(void) {
356 struct sway_output *sway_output; 350 struct sway_output *sway_output;
357 wl_list_for_each(sway_output, 351 wl_list_for_each(sway_output, &root->all_outputs, link) {
358 &root_container.sway_root->all_outputs, link) {
359 char *name = sway_output->wlr_output->name; 352 char *name = sway_output->wlr_output->name;
360 struct output_config *oc = new_output_config(name); 353 struct output_config *oc = new_output_config(name);
361 default_output_config(oc, sway_output->wlr_output); 354 default_output_config(oc, sway_output->wlr_output);