squash! [wip] Add ToggleShade

Expand ToggleShade into Shade and Unshade
This commit is contained in:
Andrew J. Hesford 2024-01-15 09:42:00 -05:00
parent 0377772c5d
commit d7d3b9f845
5 changed files with 50 additions and 38 deletions

View file

@ -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_title(struct view *view);
void view_update_app_id(struct view *view); void view_update_app_id(struct view *view);
void view_reload_ssd(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); struct view_size_hints view_get_size_hints(struct view *view);
void view_adjust_size(struct view *view, int *w, int *h); void view_adjust_size(struct view *view, int *w, int *h);

View file

@ -103,6 +103,8 @@ enum action_type {
ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE, ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE,
ACTION_TYPE_AUTO_PLACE, ACTION_TYPE_AUTO_PLACE,
ACTION_TYPE_TOGGLE_TEARING, ACTION_TYPE_TOGGLE_TEARING,
ACTION_TYPE_SHADE,
ACTION_TYPE_UNSHADE,
ACTION_TYPE_TOGGLE_SHADE, ACTION_TYPE_TOGGLE_SHADE,
}; };
@ -152,6 +154,8 @@ const char *action_names[] = {
"VirtualOutputRemove", "VirtualOutputRemove",
"AutoPlace", "AutoPlace",
"ToggleTearing", "ToggleTearing",
"Shade",
"Unshade",
"ToggleShade", "ToggleShade",
NULL NULL
}; };
@ -964,7 +968,17 @@ actions_run(struct view *activator, struct server *server,
break; break;
case ACTION_TYPE_TOGGLE_SHADE: case ACTION_TYPE_TOGGLE_SHADE:
if (view) { 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; break;
case ACTION_TYPE_INVALID: case ACTION_TYPE_INVALID:

View file

@ -168,8 +168,9 @@ build_grid(struct overlap_bitmap *bmp, struct view *view)
bmp->rows[nr_rows++] = y; bmp->rows[nr_rows++] = y;
} }
x = v->pending.x + v->pending.width + margin.right; x = v->pending.x + margin.right + v->pending.width;
y = v->pending.y + view_effective_height(v, true) + margin.bottom; 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 */ /* Add a column if the right view edge is in the usable region */
if (x > usable.x && x < usable_right) { 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); struct border margin = ssd_get_margin(v->ssd);
int lx = v->pending.x - margin.left; int lx = v->pending.x - margin.left;
int ly = v->pending.y - margin.top; int ly = v->pending.y - margin.top;
int hx = v->pending.x + v->pending.width + margin.right; int hx = v->pending.x + margin.right + v->pending.width;
int hy = v->pending.y int hy = v->pending.y + margin.bottom
+ view_effective_height(v, true) + margin.bottom; + view_effective_height(v, /* use_pending */ true);
/* /*
* Find the first and last row and column intervals spanned by * Find the first and last row and column intervals spanned by

View file

@ -37,9 +37,9 @@ snap_get_view_edge(struct view *view)
struct border edge = { struct border edge = {
.left = view->pending.x - margin.left, .left = view->pending.x - margin.left,
.top = view->pending.y - margin.top, .top = view->pending.y - margin.top,
.right = view->pending.x + view->pending.width + margin.right, .right = view->pending.x + margin.right + view->pending.width,
.bottom = view->pending.y .bottom = view->pending.y + margin.bottom
+ view_effective_height(view, true) + margin.bottom + view_effective_height(view, /* use_pending */ true)
}; };
return edge; return edge;
} }
@ -53,11 +53,10 @@ snap_get_max_distance(struct view *view)
struct border distance = { struct border distance = {
.left = usable.x + margin.left + rc.gap - view->pending.x, .left = usable.x + margin.left + rc.gap - view->pending.x,
.top = usable.y + margin.top + rc.gap - view->pending.y, .top = usable.y + margin.top + rc.gap - view->pending.y,
.right = usable.x + usable.width .right = usable.x + usable.width - view->pending.width
- view->pending.width
- margin.right - rc.gap - view->pending.x, - margin.right - rc.gap - view->pending.x,
.bottom = usable.y + usable.height .bottom = usable.y + usable.height
- view_effective_height(view, true) - view_effective_height(view, /* use_pending */ true)
- margin.bottom - rc.gap - view->pending.y - margin.bottom - rc.gap - view->pending.y
}; };
return distance; 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_x * v->pending.x;
vp += def.add_view_y * v->pending.y; vp += def.add_view_y * v->pending.y;
vp += def.add_view_width * v->pending.width; 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; vp += gap;
if (def.search_dir * vp > 0 && def.search_dir * (vp - p) < 0) { 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) { if (mode == SNAP_MODE_SHRINK) {
/* limit to half of current size */ /* limit to half of current size */
int eff_height = view_effective_height(view, true); int eff_height =
int width_max_dx = max(view->pending.width - LAB_MIN_VIEW_WIDTH, 0); 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); int height_max_dy = max(eff_height - LAB_MIN_VIEW_HEIGHT, 0);
dmax.right = min(width_max_dx, view->pending.width / 2); dmax.right = min(width_max_dx, view->pending.width / 2);
dmax.bottom = min(height_max_dy, eff_height / 2); dmax.bottom = min(height_max_dy, eff_height / 2);

View file

@ -26,8 +26,6 @@
#define LAB_FALLBACK_WIDTH 640 #define LAB_FALLBACK_WIDTH 640
#define LAB_FALLBACK_HEIGHT 480 #define LAB_FALLBACK_HEIGHT 480
static void ensure_shade_state(struct view *view, bool shaded);
struct view * struct view *
view_from_wlr_surface(struct wlr_surface *surface) 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) { if (view->fullscreen || view->maximized != VIEW_AXIS_NONE) {
return; return;
} }
ensure_shade_state(view, false); view_set_shade(view, false);
struct wlr_box newgeo = view->pending; struct wlr_box newgeo = view->pending;
newgeo.x -= left; newgeo.x -= left;
newgeo.width += left + right; newgeo.width += left + right;
@ -1056,7 +1054,7 @@ view_maximize(struct view *view, enum view_axis axis,
return; return;
} }
ensure_shade_state(view, false); view_set_shade(view, false);
if (axis != VIEW_AXIS_NONE) { 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; destination_y = top;
break; break;
case VIEW_EDGE_DOWN: case VIEW_EDGE_DOWN:
destination_y = bottom - view_effective_height(view, true); destination_y = bottom
- view_effective_height(view, /* use_pending */ true);
break; break;
default: default:
return; 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); destination_x = MAX(destination_x, left);
/* If more than half the view is below usable region, align to bottom */ /* 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) { 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 */ /* 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; return;
} }
ensure_shade_state(view, false); view_set_shade(view, false);
struct wlr_box geo = view->pending; struct wlr_box geo = view->pending;
snap_grow_to_next_edge(view, direction, &geo); snap_grow_to_next_edge(view, direction, &geo);
@ -1717,7 +1718,7 @@ view_snap_to_edge(struct view *view, enum view_edge edge,
return; return;
} }
ensure_shade_state(view, false); view_set_shade(view, false);
if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) { if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) {
/* We are already tiled for this edge; try to switch outputs */ /* 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; return;
} }
ensure_shade_state(view, false); view_set_shade(view, false);
if (view->maximized != VIEW_AXIS_NONE) { if (view->maximized != VIEW_AXIS_NONE) {
/* Unmaximize + keep using existing natural_geometry */ /* 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); mappable_connect(&view->mappable, surface, handle_map, handle_unmap);
} }
static void void
ensure_shade_state(struct view *view, bool shaded) view_set_shade(struct view *view, bool shaded)
{ {
assert(view); assert(view);
if (view->shaded == shaded) { if (view->shaded == shaded) {
return; return;
} }
view_toggle_shade(view);
}
void
view_toggle_shade(struct view *view)
{
assert(view);
/* Views without a title-bar or SSD cannot be shaded */ /* 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; return;
} }
/* Restore fullscreen views to natural size before shading */ /* Restore fullscreen views to natural size before shading */
if (!view->shaded && view->fullscreen) { if (shaded && view->fullscreen) {
view_toggle_fullscreen(view); view_toggle_fullscreen(view);
} }
view->shaded = !view->shaded; view->shaded = shaded;
ssd_enable_shade(view->ssd, view->shaded); ssd_enable_shade(view->ssd, view->shaded);
wlr_scene_node_set_enabled(view->scene_node, !view->shaded); wlr_scene_node_set_enabled(view->scene_node, !view->shaded);
} }