aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar Kenny Levinsen <kl@kl.wtf>2021-02-12 23:22:51 +0100
committerLibravatar Tudor Brindus <me@tbrindus.ca>2021-02-16 22:05:00 -0500
commita047b5ee4a2a67d30d93641ff86531d54b8e0879 (patch)
tree271666c6254e4fabf943c1153224059411a5ce56 /sway/tree/view.c
parentAdd missing transaction commits to seatop_default (diff)
downloadsway-a047b5ee4a2a67d30d93641ff86531d54b8e0879.tar.gz
sway-a047b5ee4a2a67d30d93641ff86531d54b8e0879.tar.zst
sway-a047b5ee4a2a67d30d93641ff86531d54b8e0879.zip
container: Move pending state to state struct
Pending state is currently inlined directly in the container struct, while the current state is in a state struct. A side-effect of this is that it is not immediately obvious that pending double-buffered state is accessed, nor is it obvious what state is double-buffered. Instead, use the state struct for both current and pending.
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c208
1 files changed, 104 insertions, 104 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index e62fd018..ad79b229 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -206,7 +206,7 @@ bool view_ancestor_is_only_visible(struct sway_view *view) {
206 } else { 206 } else {
207 only_visible = true; 207 only_visible = true;
208 } 208 }
209 con = con->parent; 209 con = con->pending.parent;
210 } 210 }
211 return only_visible; 211 return only_visible;
212} 212}
@@ -222,58 +222,58 @@ static bool view_is_only_visible(struct sway_view *view) {
222 } 222 }
223 } 223 }
224 224
225 con = con->parent; 225 con = con->pending.parent;
226 } 226 }
227 227
228 return true; 228 return true;
229} 229}
230 230
231static bool gaps_to_edge(struct sway_view *view) { 231static bool gaps_to_edge(struct sway_view *view) {
232 struct side_gaps gaps = view->container->workspace->current_gaps; 232 struct side_gaps gaps = view->container->pending.workspace->current_gaps;
233 return gaps.top > 0 || gaps.right > 0 || gaps.bottom > 0 || gaps.left > 0; 233 return gaps.top > 0 || gaps.right > 0 || gaps.bottom > 0 || gaps.left > 0;
234} 234}
235 235
236void view_autoconfigure(struct sway_view *view) { 236void view_autoconfigure(struct sway_view *view) {
237 struct sway_container *con = view->container; 237 struct sway_container *con = view->container;
238 struct sway_workspace *ws = con->workspace; 238 struct sway_workspace *ws = con->pending.workspace;
239 239
240 if (container_is_scratchpad_hidden(con) && 240 if (container_is_scratchpad_hidden(con) &&
241 con->fullscreen_mode != FULLSCREEN_GLOBAL) { 241 con->pending.fullscreen_mode != FULLSCREEN_GLOBAL) {
242 return; 242 return;
243 } 243 }
244 struct sway_output *output = ws ? ws->output : NULL; 244 struct sway_output *output = ws ? ws->output : NULL;
245 245
246 if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { 246 if (con->pending.fullscreen_mode == FULLSCREEN_WORKSPACE) {
247 con->content_x = output->lx; 247 con->pending.content_x = output->lx;
248 con->content_y = output->ly; 248 con->pending.content_y = output->ly;
249 con->content_width = output->width; 249 con->pending.content_width = output->width;
250 con->content_height = output->height; 250 con->pending.content_height = output->height;
251 return; 251 return;
252 } else if (con->fullscreen_mode == FULLSCREEN_GLOBAL) { 252 } else if (con->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
253 con->content_x = root->x; 253 con->pending.content_x = root->x;
254 con->content_y = root->y; 254 con->pending.content_y = root->y;
255 con->content_width = root->width; 255 con->pending.content_width = root->width;
256 con->content_height = root->height; 256 con->pending.content_height = root->height;
257 return; 257 return;
258 } 258 }
259 259
260 con->border_top = con->border_bottom = true; 260 con->pending.border_top = con->pending.border_bottom = true;
261 con->border_left = con->border_right = true; 261 con->pending.border_left = con->pending.border_right = true;
262 double y_offset = 0; 262 double y_offset = 0;
263 263
264 if (!container_is_floating(con) && ws) { 264 if (!container_is_floating(con) && ws) {
265 if (config->hide_edge_borders == E_BOTH 265 if (config->hide_edge_borders == E_BOTH
266 || config->hide_edge_borders == E_VERTICAL) { 266 || config->hide_edge_borders == E_VERTICAL) {
267 con->border_left = con->x != ws->x; 267 con->pending.border_left = con->pending.x != ws->x;
268 int right_x = con->x + con->width; 268 int right_x = con->pending.x + con->pending.width;
269 con->border_right = right_x != ws->x + ws->width; 269 con->pending.border_right = right_x != ws->x + ws->width;
270 } 270 }
271 271
272 if (config->hide_edge_borders == E_BOTH 272 if (config->hide_edge_borders == E_BOTH
273 || config->hide_edge_borders == E_HORIZONTAL) { 273 || config->hide_edge_borders == E_HORIZONTAL) {
274 con->border_top = con->y != ws->y; 274 con->pending.border_top = con->pending.y != ws->y;
275 int bottom_y = con->y + con->height; 275 int bottom_y = con->pending.y + con->pending.height;
276 con->border_bottom = bottom_y != ws->y + ws->height; 276 con->pending.border_bottom = bottom_y != ws->y + ws->height;
277 } 277 }
278 278
279 bool smart = config->hide_edge_borders_smart == ESMART_ON || 279 bool smart = config->hide_edge_borders_smart == ESMART_ON ||
@@ -282,10 +282,10 @@ void view_autoconfigure(struct sway_view *view) {
282 if (smart) { 282 if (smart) {
283 bool show_border = container_is_floating_or_child(con) || 283 bool show_border = container_is_floating_or_child(con) ||
284 !view_is_only_visible(view); 284 !view_is_only_visible(view);
285 con->border_left &= show_border; 285 con->pending.border_left &= show_border;
286 con->border_right &= show_border; 286 con->pending.border_right &= show_border;
287 con->border_top &= show_border; 287 con->pending.border_top &= show_border;
288 con->border_bottom &= show_border; 288 con->pending.border_bottom &= show_border;
289 } 289 }
290 290
291 // In a tabbed or stacked container, the container's y is the top of the 291 // In a tabbed or stacked container, the container's y is the top of the
@@ -298,56 +298,56 @@ void view_autoconfigure(struct sway_view *view) {
298 enum sway_container_layout layout = container_parent_layout(con); 298 enum sway_container_layout layout = container_parent_layout(con);
299 if (layout == L_TABBED) { 299 if (layout == L_TABBED) {
300 y_offset = container_titlebar_height(); 300 y_offset = container_titlebar_height();
301 con->border_top = false; 301 con->pending.border_top = false;
302 } else if (layout == L_STACKED) { 302 } else if (layout == L_STACKED) {
303 y_offset = container_titlebar_height() * siblings->length; 303 y_offset = container_titlebar_height() * siblings->length;
304 con->border_top = false; 304 con->pending.border_top = false;
305 } 305 }
306 } 306 }
307 } 307 }
308 308
309 double x, y, width, height; 309 double x, y, width, height;
310 switch (con->border) { 310 switch (con->pending.border) {
311 default: 311 default:
312 case B_CSD: 312 case B_CSD:
313 case B_NONE: 313 case B_NONE:
314 x = con->x; 314 x = con->pending.x;
315 y = con->y + y_offset; 315 y = con->pending.y + y_offset;
316 width = con->width; 316 width = con->pending.width;
317 height = con->height - y_offset; 317 height = con->pending.height - y_offset;
318 break; 318 break;
319 case B_PIXEL: 319 case B_PIXEL:
320 x = con->x + con->border_thickness * con->border_left; 320 x = con->pending.x + con->pending.border_thickness * con->pending.border_left;
321 y = con->y + con->border_thickness * con->border_top + y_offset; 321 y = con->pending.y + con->pending.border_thickness * con->pending.border_top + y_offset;
322 width = con->width 322 width = con->pending.width
323 - con->border_thickness * con->border_left 323 - con->pending.border_thickness * con->pending.border_left
324 - con->border_thickness * con->border_right; 324 - con->pending.border_thickness * con->pending.border_right;
325 height = con->height - y_offset 325 height = con->pending.height - y_offset
326 - con->border_thickness * con->border_top 326 - con->pending.border_thickness * con->pending.border_top
327 - con->border_thickness * con->border_bottom; 327 - con->pending.border_thickness * con->pending.border_bottom;
328 break; 328 break;
329 case B_NORMAL: 329 case B_NORMAL:
330 // Height is: 1px border + 3px pad + title height + 3px pad + 1px border 330 // Height is: 1px border + 3px pad + title height + 3px pad + 1px border
331 x = con->x + con->border_thickness * con->border_left; 331 x = con->pending.x + con->pending.border_thickness * con->pending.border_left;
332 width = con->width 332 width = con->pending.width
333 - con->border_thickness * con->border_left 333 - con->pending.border_thickness * con->pending.border_left
334 - con->border_thickness * con->border_right; 334 - con->pending.border_thickness * con->pending.border_right;
335 if (y_offset) { 335 if (y_offset) {
336 y = con->y + y_offset; 336 y = con->pending.y + y_offset;
337 height = con->height - y_offset 337 height = con->pending.height - y_offset
338 - con->border_thickness * con->border_bottom; 338 - con->pending.border_thickness * con->pending.border_bottom;
339 } else { 339 } else {
340 y = con->y + container_titlebar_height(); 340 y = con->pending.y + container_titlebar_height();
341 height = con->height - container_titlebar_height() 341 height = con->pending.height - container_titlebar_height()
342 - con->border_thickness * con->border_bottom; 342 - con->pending.border_thickness * con->pending.border_bottom;
343 } 343 }
344 break; 344 break;
345 } 345 }
346 346
347 con->content_x = x; 347 con->pending.content_x = x;
348 con->content_y = y; 348 con->pending.content_y = y;
349 con->content_width = width; 349 con->pending.content_width = width;
350 con->content_height = height; 350 con->pending.content_height = height;
351} 351}
352 352
353void view_set_activated(struct sway_view *view, bool activated) { 353void view_set_activated(struct sway_view *view, bool activated) {
@@ -361,7 +361,7 @@ void view_set_activated(struct sway_view *view, bool activated) {
361} 361}
362 362
363void view_request_activate(struct sway_view *view) { 363void view_request_activate(struct sway_view *view) {
364 struct sway_workspace *ws = view->container->workspace; 364 struct sway_workspace *ws = view->container->pending.workspace;
365 if (!ws) { // hidden scratchpad container 365 if (!ws) { // hidden scratchpad container
366 return; 366 return;
367 } 367 }
@@ -401,13 +401,13 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
401void view_update_csd_from_client(struct sway_view *view, bool enabled) { 401void view_update_csd_from_client(struct sway_view *view, bool enabled) {
402 sway_log(SWAY_DEBUG, "View %p updated CSD to %i", view, enabled); 402 sway_log(SWAY_DEBUG, "View %p updated CSD to %i", view, enabled);
403 struct sway_container *con = view->container; 403 struct sway_container *con = view->container;
404 if (enabled && con && con->border != B_CSD) { 404 if (enabled && con && con->pending.border != B_CSD) {
405 con->saved_border = con->border; 405 con->saved_border = con->pending.border;
406 if (container_is_floating(con)) { 406 if (container_is_floating(con)) {
407 con->border = B_CSD; 407 con->pending.border = B_CSD;
408 } 408 }
409 } else if (!enabled && con && con->border == B_CSD) { 409 } else if (!enabled && con && con->pending.border == B_CSD) {
410 con->border = con->saved_border; 410 con->pending.border = con->saved_border;
411 } 411 }
412 view->using_csd = enabled; 412 view->using_csd = enabled;
413} 413}
@@ -577,7 +577,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
577 if (node && node->type == N_WORKSPACE) { 577 if (node && node->type == N_WORKSPACE) {
578 return node->sway_workspace; 578 return node->sway_workspace;
579 } else if (node && node->type == N_CONTAINER) { 579 } else if (node && node->type == N_CONTAINER) {
580 return node->sway_container->workspace; 580 return node->sway_container->pending.workspace;
581 } 581 }
582 582
583 // When there's no outputs connected, the above should match a workspace on 583 // When there's no outputs connected, the above should match a workspace on
@@ -590,9 +590,9 @@ static bool should_focus(struct sway_view *view) {
590 struct sway_seat *seat = input_manager_current_seat(); 590 struct sway_seat *seat = input_manager_current_seat();
591 struct sway_container *prev_con = seat_get_focused_container(seat); 591 struct sway_container *prev_con = seat_get_focused_container(seat);
592 struct sway_workspace *prev_ws = seat_get_focused_workspace(seat); 592 struct sway_workspace *prev_ws = seat_get_focused_workspace(seat);
593 struct sway_workspace *map_ws = view->container->workspace; 593 struct sway_workspace *map_ws = view->container->pending.workspace;
594 594
595 if (view->container->fullscreen_mode == FULLSCREEN_GLOBAL) { 595 if (view->container->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
596 return true; 596 return true;
597 } 597 }
598 598
@@ -603,9 +603,9 @@ static bool should_focus(struct sway_view *view) {
603 603
604 // If the view is the only one in the focused workspace, it'll get focus 604 // If the view is the only one in the focused workspace, it'll get focus
605 // regardless of any no_focus criteria. 605 // regardless of any no_focus criteria.
606 if (!view->container->parent && !prev_con) { 606 if (!view->container->pending.parent && !prev_con) {
607 size_t num_children = view->container->workspace->tiling->length + 607 size_t num_children = view->container->pending.workspace->tiling->length +
608 view->container->workspace->floating->length; 608 view->container->pending.workspace->floating->length;
609 if (num_children == 1) { 609 if (num_children == 1) {
610 return true; 610 return true;
611 } 611 }
@@ -645,9 +645,9 @@ static void handle_foreign_fullscreen_request(
645 645
646 // Match fullscreen command behavior for scratchpad hidden views 646 // Match fullscreen command behavior for scratchpad hidden views
647 struct sway_container *container = view->container; 647 struct sway_container *container = view->container;
648 if (!container->workspace) { 648 if (!container->pending.workspace) {
649 while (container->parent) { 649 while (container->pending.parent) {
650 container = container->parent; 650 container = container->pending.parent;
651 } 651 }
652 } 652 }
653 653
@@ -668,10 +668,10 @@ static void handle_foreign_fullscreen_request(
668 if (event->fullscreen) { 668 if (event->fullscreen) {
669 arrange_root(); 669 arrange_root();
670 } else { 670 } else {
671 if (container->parent) { 671 if (container->pending.parent) {
672 arrange_container(container->parent); 672 arrange_container(container->pending.parent);
673 } else if (container->workspace) { 673 } else if (container->pending.workspace) {
674 arrange_workspace(container->workspace); 674 arrange_workspace(container->pending.workspace);
675 } 675 }
676 } 676 }
677} 677}
@@ -762,20 +762,20 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
762 } 762 }
763 763
764 if (view->impl->wants_floating && view->impl->wants_floating(view)) { 764 if (view->impl->wants_floating && view->impl->wants_floating(view)) {
765 view->container->border = config->floating_border; 765 view->container->pending.border = config->floating_border;
766 view->container->border_thickness = config->floating_border_thickness; 766 view->container->pending.border_thickness = config->floating_border_thickness;
767 container_set_floating(view->container, true); 767 container_set_floating(view->container, true);
768 } else { 768 } else {
769 view->container->border = config->border; 769 view->container->pending.border = config->border;
770 view->container->border_thickness = config->border_thickness; 770 view->container->pending.border_thickness = config->border_thickness;
771 view_set_tiled(view, true); 771 view_set_tiled(view, true);
772 } 772 }
773 773
774 if (config->popup_during_fullscreen == POPUP_LEAVE && 774 if (config->popup_during_fullscreen == POPUP_LEAVE &&
775 container->workspace && 775 container->pending.workspace &&
776 container->workspace->fullscreen && 776 container->pending.workspace->fullscreen &&
777 container->workspace->fullscreen->view) { 777 container->pending.workspace->fullscreen->view) {
778 struct sway_container *fs = container->workspace->fullscreen; 778 struct sway_container *fs = container->pending.workspace->fullscreen;
779 if (view_is_transient_for(view, fs->view)) { 779 if (view_is_transient_for(view, fs->view)) {
780 container_set_fullscreen(fs, false); 780 container_set_fullscreen(fs, false);
781 } 781 }
@@ -786,12 +786,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
786 786
787 if (fullscreen) { 787 if (fullscreen) {
788 container_set_fullscreen(view->container, true); 788 container_set_fullscreen(view->container, true);
789 arrange_workspace(view->container->workspace); 789 arrange_workspace(view->container->pending.workspace);
790 } else { 790 } else {
791 if (container->parent) { 791 if (container->pending.parent) {
792 arrange_container(container->parent); 792 arrange_container(container->pending.parent);
793 } else if (container->workspace) { 793 } else if (container->pending.workspace) {
794 arrange_workspace(container->workspace); 794 arrange_workspace(container->pending.workspace);
795 } 795 }
796 } 796 }
797 797
@@ -838,8 +838,8 @@ void view_unmap(struct sway_view *view) {
838 view->foreign_toplevel = NULL; 838 view->foreign_toplevel = NULL;
839 } 839 }
840 840
841 struct sway_container *parent = view->container->parent; 841 struct sway_container *parent = view->container->pending.parent;
842 struct sway_workspace *ws = view->container->workspace; 842 struct sway_workspace *ws = view->container->pending.workspace;
843 container_begin_destroy(view->container); 843 container_begin_destroy(view->container);
844 if (parent) { 844 if (parent) {
845 container_reap_empty(parent); 845 container_reap_empty(parent);
@@ -874,8 +874,8 @@ void view_unmap(struct sway_view *view) {
874 874
875void view_update_size(struct sway_view *view) { 875void view_update_size(struct sway_view *view) {
876 struct sway_container *con = view->container; 876 struct sway_container *con = view->container;
877 con->content_width = view->geometry.width; 877 con->pending.content_width = view->geometry.width;
878 con->content_height = view->geometry.height; 878 con->pending.content_height = view->geometry.height;
879 container_set_geometry_from_content(con); 879 container_set_geometry_from_content(con);
880} 880}
881 881
@@ -989,8 +989,8 @@ static void view_child_damage(struct sway_view_child *child, bool whole) {
989 int sx, sy; 989 int sx, sy;
990 child->impl->get_root_coords(child, &sx, &sy); 990 child->impl->get_root_coords(child, &sx, &sy);
991 desktop_damage_surface(child->surface, 991 desktop_damage_surface(child->surface,
992 child->view->container->content_x + sx, 992 child->view->container->pending.content_x + sx,
993 child->view->container->content_y + sy, whole); 993 child->view->container->pending.content_y + sy, whole);
994} 994}
995 995
996static void view_child_handle_surface_commit(struct wl_listener *listener, 996static void view_child_handle_surface_commit(struct wl_listener *listener,
@@ -1073,7 +1073,7 @@ void view_child_init(struct sway_view_child *child,
1073 wl_signal_add(&view->events.unmap, &child->view_unmap); 1073 wl_signal_add(&view->events.unmap, &child->view_unmap);
1074 child->view_unmap.notify = view_child_handle_view_unmap; 1074 child->view_unmap.notify = view_child_handle_view_unmap;
1075 1075
1076 struct sway_workspace *workspace = child->view->container->workspace; 1076 struct sway_workspace *workspace = child->view->container->pending.workspace;
1077 if (workspace) { 1077 if (workspace) {
1078 wlr_surface_send_enter(child->surface, workspace->output->wlr_output); 1078 wlr_surface_send_enter(child->surface, workspace->output->wlr_output);
1079 } 1079 }
@@ -1256,15 +1256,15 @@ bool view_is_visible(struct sway_view *view) {
1256 if (view->container->node.destroying) { 1256 if (view->container->node.destroying) {
1257 return false; 1257 return false;
1258 } 1258 }
1259 struct sway_workspace *workspace = view->container->workspace; 1259 struct sway_workspace *workspace = view->container->pending.workspace;
1260 if (!workspace && view->container->fullscreen_mode != FULLSCREEN_GLOBAL) { 1260 if (!workspace && view->container->pending.fullscreen_mode != FULLSCREEN_GLOBAL) {
1261 bool fs_global_descendant = false; 1261 bool fs_global_descendant = false;
1262 struct sway_container *parent = view->container->parent; 1262 struct sway_container *parent = view->container->pending.parent;
1263 while (parent) { 1263 while (parent) {
1264 if (parent->fullscreen_mode == FULLSCREEN_GLOBAL) { 1264 if (parent->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
1265 fs_global_descendant = true; 1265 fs_global_descendant = true;
1266 } 1266 }
1267 parent = parent->parent; 1267 parent = parent->pending.parent;
1268 } 1268 }
1269 if (!fs_global_descendant) { 1269 if (!fs_global_descendant) {
1270 return false; 1270 return false;
@@ -1282,13 +1282,13 @@ bool view_is_visible(struct sway_view *view) {
1282 enum sway_container_layout layout = container_parent_layout(con); 1282 enum sway_container_layout layout = container_parent_layout(con);
1283 if ((layout == L_TABBED || layout == L_STACKED) 1283 if ((layout == L_TABBED || layout == L_STACKED)
1284 && !container_is_floating(con)) { 1284 && !container_is_floating(con)) {
1285 struct sway_node *parent = con->parent ? 1285 struct sway_node *parent = con->pending.parent ?
1286 &con->parent->node : &con->workspace->node; 1286 &con->pending.parent->node : &con->pending.workspace->node;
1287 if (seat_get_active_tiling_child(seat, parent) != &con->node) { 1287 if (seat_get_active_tiling_child(seat, parent) != &con->node) {
1288 return false; 1288 return false;
1289 } 1289 }
1290 } 1290 }
1291 con = con->parent; 1291 con = con->pending.parent;
1292 } 1292 }
1293 // Check view isn't hidden by another fullscreen view 1293 // Check view isn't hidden by another fullscreen view
1294 struct sway_container *fs = root->fullscreen_global ? 1294 struct sway_container *fs = root->fullscreen_global ?
@@ -1322,7 +1322,7 @@ void view_set_urgent(struct sway_view *view, bool enable) {
1322 ipc_event_window(view->container, "urgent"); 1322 ipc_event_window(view->container, "urgent");
1323 1323
1324 if (!container_is_scratchpad_hidden(view->container)) { 1324 if (!container_is_scratchpad_hidden(view->container)) {
1325 workspace_detect_urgent(view->container->workspace); 1325 workspace_detect_urgent(view->container->pending.workspace);
1326 } 1326 }
1327} 1327}
1328 1328