mirror of
https://github.com/labwc/labwc.git
synced 2026-04-13 08:21:15 -04:00
squash! [wip] Add ToggleShade
Expand ToggleShade into Shade and Unshade
This commit is contained in:
parent
0377772c5d
commit
d7d3b9f845
5 changed files with 50 additions and 38 deletions
16
src/action.c
16
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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
19
src/snap.c
19
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);
|
||||
|
|
|
|||
39
src/view.c
39
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue