From d7d3b9f8459257041a698eb33c31cab249e4997f Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Mon, 15 Jan 2024 09:42:00 -0500 Subject: [PATCH] squash! [wip] Add ToggleShade Expand ToggleShade into Shade and Unshade --- include/view.h | 3 ++- src/action.c | 16 +++++++++++++++- src/placement.c | 11 ++++++----- src/snap.c | 19 ++++++++++--------- src/view.c | 39 +++++++++++++++++---------------------- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/include/view.h b/include/view.h index 99cb7bd7..f18904fc 100644 --- a/include/view.h +++ b/include/view.h @@ -470,7 +470,8 @@ const char *view_get_string_prop(struct view *view, const char *prop); void view_update_title(struct view *view); void view_update_app_id(struct view *view); void view_reload_ssd(struct view *view); -void view_toggle_shade(struct view *view); + +void view_set_shade(struct view *view, bool shaded); struct view_size_hints view_get_size_hints(struct view *view); void view_adjust_size(struct view *view, int *w, int *h); diff --git a/src/action.c b/src/action.c index 9ff478bf..ef01310e 100644 --- a/src/action.c +++ b/src/action.c @@ -103,6 +103,8 @@ enum action_type { ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE, ACTION_TYPE_AUTO_PLACE, ACTION_TYPE_TOGGLE_TEARING, + ACTION_TYPE_SHADE, + ACTION_TYPE_UNSHADE, ACTION_TYPE_TOGGLE_SHADE, }; @@ -152,6 +154,8 @@ const char *action_names[] = { "VirtualOutputRemove", "AutoPlace", "ToggleTearing", + "Shade", + "Unshade", "ToggleShade", NULL }; @@ -964,7 +968,17 @@ actions_run(struct view *activator, struct server *server, break; case ACTION_TYPE_TOGGLE_SHADE: if (view) { - view_toggle_shade(view); + view_set_shade(view, !view->shaded); + } + break; + case ACTION_TYPE_SHADE: + if (view) { + view_set_shade(view, true); + } + break; + case ACTION_TYPE_UNSHADE: + if (view) { + view_set_shade(view, false); } break; case ACTION_TYPE_INVALID: diff --git a/src/placement.c b/src/placement.c index c64b7570..560b5e54 100644 --- a/src/placement.c +++ b/src/placement.c @@ -168,8 +168,9 @@ build_grid(struct overlap_bitmap *bmp, struct view *view) bmp->rows[nr_rows++] = y; } - x = v->pending.x + v->pending.width + margin.right; - y = v->pending.y + view_effective_height(v, true) + margin.bottom; + x = v->pending.x + margin.right + v->pending.width; + y = v->pending.y + margin.bottom + + view_effective_height(v, /* use_pending */ true); /* Add a column if the right view edge is in the usable region */ if (x > usable.x && x < usable_right) { @@ -259,9 +260,9 @@ build_overlap(struct overlap_bitmap *bmp, struct view *view) struct border margin = ssd_get_margin(v->ssd); int lx = v->pending.x - margin.left; int ly = v->pending.y - margin.top; - int hx = v->pending.x + v->pending.width + margin.right; - int hy = v->pending.y - + view_effective_height(v, true) + margin.bottom; + int hx = v->pending.x + margin.right + v->pending.width; + int hy = v->pending.y + margin.bottom + + view_effective_height(v, /* use_pending */ true); /* * Find the first and last row and column intervals spanned by diff --git a/src/snap.c b/src/snap.c index d8dc32dd..fd60cad0 100644 --- a/src/snap.c +++ b/src/snap.c @@ -37,9 +37,9 @@ snap_get_view_edge(struct view *view) struct border edge = { .left = view->pending.x - margin.left, .top = view->pending.y - margin.top, - .right = view->pending.x + view->pending.width + margin.right, - .bottom = view->pending.y - + view_effective_height(view, true) + margin.bottom + .right = view->pending.x + margin.right + view->pending.width, + .bottom = view->pending.y + margin.bottom + + view_effective_height(view, /* use_pending */ true) }; return edge; } @@ -53,11 +53,10 @@ snap_get_max_distance(struct view *view) struct border distance = { .left = usable.x + margin.left + rc.gap - view->pending.x, .top = usable.y + margin.top + rc.gap - view->pending.y, - .right = usable.x + usable.width - - view->pending.width + .right = usable.x + usable.width - view->pending.width - margin.right - rc.gap - view->pending.x, .bottom = usable.y + usable.height - - view_effective_height(view, true) + - view_effective_height(view, /* use_pending */ true) - margin.bottom - rc.gap - view->pending.y }; return distance; @@ -118,7 +117,8 @@ _snap_next_edge(struct view *view, int start_pos, const struct snap_search def, vp += def.add_view_x * v->pending.x; vp += def.add_view_y * v->pending.y; vp += def.add_view_width * v->pending.width; - vp += def.add_view_height * view_effective_height(v, true); + vp += def.add_view_height + * view_effective_height(v, /* use_pending */ true); vp += gap; if (def.search_dir * vp > 0 && def.search_dir * (vp - p) < 0) { @@ -137,8 +137,9 @@ _snap_move_resize_to_edge(struct view *view, enum view_edge direction, enum snap if (mode == SNAP_MODE_SHRINK) { /* limit to half of current size */ - int eff_height = view_effective_height(view, true); - int width_max_dx = max(view->pending.width - LAB_MIN_VIEW_WIDTH, 0); + int eff_height = + view_effective_height(view, /* use_pending */ true); + int width_max_dx = max(view->pending.width - LAB_MIN_VIEW_WIDTH, 0); int height_max_dy = max(eff_height - LAB_MIN_VIEW_HEIGHT, 0); dmax.right = min(width_max_dx, view->pending.width / 2); dmax.bottom = min(height_max_dy, eff_height / 2); diff --git a/src/view.c b/src/view.c index 3b5fc523..f50a5f0f 100644 --- a/src/view.c +++ b/src/view.c @@ -26,8 +26,6 @@ #define LAB_FALLBACK_WIDTH 640 #define LAB_FALLBACK_HEIGHT 480 -static void ensure_shade_state(struct view *view, bool shaded); - struct view * view_from_wlr_surface(struct wlr_surface *surface) { @@ -386,7 +384,7 @@ view_resize_relative(struct view *view, int left, int right, int top, int bottom if (view->fullscreen || view->maximized != VIEW_AXIS_NONE) { return; } - ensure_shade_state(view, false); + view_set_shade(view, false); struct wlr_box newgeo = view->pending; newgeo.x -= left; newgeo.width += left + right; @@ -1056,7 +1054,7 @@ view_maximize(struct view *view, enum view_axis axis, return; } - ensure_shade_state(view, false); + view_set_shade(view, false); if (axis != VIEW_AXIS_NONE) { /* @@ -1587,7 +1585,8 @@ view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_wind destination_y = top; break; case VIEW_EDGE_DOWN: - destination_y = bottom - view_effective_height(view, true); + destination_y = bottom + - view_effective_height(view, /* use_pending */ true); break; default: return; @@ -1604,9 +1603,11 @@ view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_wind destination_x = MAX(destination_x, left); /* If more than half the view is below usable region, align to bottom */ - midpoint = destination_y + view_effective_height(view, true) / 2; + midpoint = destination_y + + view_effective_height(view, /* use_pending */ true) / 2; if (destination_y >= top && midpoint > usable.y + usable.height) { - destination_y = bottom - view_effective_height(view, true); + destination_y = bottom + - view_effective_height(view, /* use_pending */ true); } /* Never allow the window to start above the usable edge */ @@ -1631,7 +1632,7 @@ view_grow_to_edge(struct view *view, enum view_edge direction) return; } - ensure_shade_state(view, false); + view_set_shade(view, false); struct wlr_box geo = view->pending; snap_grow_to_next_edge(view, direction, &geo); @@ -1717,7 +1718,7 @@ view_snap_to_edge(struct view *view, enum view_edge edge, return; } - ensure_shade_state(view, false); + view_set_shade(view, false); if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) { /* We are already tiled for this edge; try to switch outputs */ @@ -1772,7 +1773,7 @@ view_snap_to_region(struct view *view, struct region *region, return; } - ensure_shade_state(view, false); + view_set_shade(view, false); if (view->maximized != VIEW_AXIS_NONE) { /* Unmaximize + keep using existing natural_geometry */ @@ -2018,32 +2019,26 @@ view_connect_map(struct view *view, struct wlr_surface *surface) mappable_connect(&view->mappable, surface, handle_map, handle_unmap); } -static void -ensure_shade_state(struct view *view, bool shaded) +void +view_set_shade(struct view *view, bool shaded) { assert(view); + if (view->shaded == shaded) { return; } - view_toggle_shade(view); -} - -void -view_toggle_shade(struct view *view) -{ - assert(view); /* Views without a title-bar or SSD cannot be shaded */ - if (!view->ssd || view->ssd_titlebar_hidden) { + if (shaded && (!view->ssd || view->ssd_titlebar_hidden)) { return; } /* Restore fullscreen views to natural size before shading */ - if (!view->shaded && view->fullscreen) { + if (shaded && view->fullscreen) { view_toggle_fullscreen(view); } - view->shaded = !view->shaded; + view->shaded = shaded; ssd_enable_shade(view->ssd, view->shaded); wlr_scene_node_set_enabled(view->scene_node, !view->shaded); }