Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Overview: drop window titles and tighten the grid

oxydizerf818e22705b2
diff --git a/docs/wiki/Using-RediWM.md b/docs/wiki/Using-RediWM.md
index 0bd33b9..0003a91 100644
--- a/docs/wiki/Using-RediWM.md
+++ b/docs/wiki/Using-RediWM.md
@@ -44,8 +44,8 @@ The volume/brightness OSD also shows the desktop zoom percentage.
Press **Super+A** to spread the canvas windows into separate live previews on
the monitor under the pointer. Four windows form a 2×2 grid; five form two
-centred above three. Previews preserve aspect ratios, with gaps and readable
-titles beneath them. Offscreen and minimized windows are included; hidden tabs
+centred above three. Previews preserve aspect ratios and fill the screen with
+only narrow gaps between them. Offscreen and minimized windows are included; hidden tabs
are excluded.
Click a preview, or select one with the arrow keys and press Enter, to visit it.
diff --git a/src/world/overview_cards.zig b/src/world/overview_cards.zig
index d8382a9..954b406 100644
--- a/src/world/overview_cards.zig
+++ b/src/world/overview_cards.zig
@@ -1,23 +1,16 @@
-//! Overview presentation: stable window IDs, balanced grid, live frame transforms
-//! and cached readable captions. No client size or saved window geometry changes.
+//! Overview presentation: stable window IDs, balanced grid and live frame
+//! transforms. No client size or saved window geometry changes.
const std = @import("std");
const World = @import("../World.zig");
const Top = @import("../Toplevel.zig");
const Self = @import("overview.zig");
-const sn = @import("../node.zig");
const layout = @import("overview_layout.zig");
const ui = @import("ui");
const gpa = @import("../main.zig").gpa;
pub const Card = struct {
id: u64,
- label: *sn.Buffer,
- label_hash: u64 = 0,
- label_width: i32 = 0,
- label_height: i32 = 0,
- label_scale: f32 = 0,
target: layout.Rect = .{},
- caption: layout.Rect = .{},
presented: layout.Rect = .{},
};
@@ -30,17 +23,13 @@ pub fn prepare(self: *Self, world: *World) !void {
var i: usize = 0;
while (i < self.cards.items.len) {
if (Self.find(world, self.cards.items[i].id) == null) {
- self.cards.items[i].label.node.destroy();
_ = self.cards.orderedRemove(i);
} else i += 1;
}
var it = world.toplevels.iterator(.forward);
while (it.next()) |top| {
if (!Self.eligible(top) or find(self, top.id) != null) continue;
- try self.cards.ensureUnusedCapacity(gpa, 1);
- const label = try self.tree.?.createSceneBuffer(null);
- label.point_accepts_input = Self.ignoreInput;
- self.cards.appendAssumeCapacity(.{ .id = top.id, .label = label });
+ try self.cards.append(gpa, .{ .id = top.id });
}
// Stable spatial order, including identical overlapping frames. Focusing
// a window changes stacking order but must not shuffle the next overview.
@@ -57,39 +46,10 @@ pub fn prepare(self: *Self, world: *World) !void {
const bounds: layout.Rect = .{ .x = @floatFromInt(area.x), .y = @floatFromInt(area.y), .width = @floatFromInt(area.width), .height = @floatFromInt(area.height) };
for (self.cards.items, 0..) |*card, index| {
const top = Self.find(world, card.id).?;
- const p = layout.place(self.cards.items.len, index, bounds, @floatFromInt(top.chrome_width), @floatFromInt(top.chrome_height), ui.theme.global.switcher_title_size + 12);
- card.target = p.frame;
- card.caption = p.label;
- try paintLabel(self, card, top);
+ card.target = layout.place(self.cards.items.len, index, bounds, @floatFromInt(top.chrome_width), @floatFromInt(top.chrome_height));
}
}
-fn paintLabel(self: *Self, card: *Card, top: *Top) !void {
- const title = top.title();
- const hash = std.hash.Wyhash.hash(@intFromBool(top.minimized), title);
- const width: i32 = @max(1, @as(i32, @intFromFloat(@round(card.caption.width))));
- const height: i32 = @max(1, @as(i32, @intFromFloat(@round(card.caption.height))));
- const scale = self.output.?.wlr_output.scale;
- if (card.label_width == width and card.label_height == height and card.label_hash == hash and card.label_scale == scale) return;
- const image = try @import("../panel_buffer.zig").PanelBuffer.create(width, height, self.output.?.wlr_output.scale);
- defer image.base.drop();
- const t = ui.theme.global;
- var renderer = ui.paint.Renderer.init(image.pixels, image.width, image.height, self.output.?.wlr_output.scale);
- renderer.fillRect(0, 0, @floatFromInt(width), @floatFromInt(height), .{ .color = t.switcher_item_bg, .radius = 5 });
- const font = @min(t.switcher_title_size, @as(f32, @floatFromInt(height)) - 4);
- renderer.drawText(8, 0, @floatFromInt(@max(1, width - 16)), @floatFromInt(height), .{
- .content = if (title.len > 0) title else top.appId(),
- .font_size = @max(1, font),
- .color = if (top.minimized) t.switcher_dim else t.switcher_fg,
- });
- card.label.setBuffer(&image.base);
- card.label.setDestSize(width, height);
- card.label_width = width;
- card.label_height = height;
- card.label_hash = hash;
- card.label_scale = scale;
-}
-
/// Override the source frame's presentation only. The projection still draws
/// the real client buffers, subsurfaces, chrome and shapes and paces their frames.
pub fn apply(self: *Self, top: *Top, x: i32, y: i32, scale: f64, now: i64) bool {
@@ -115,10 +75,6 @@ pub fn apply(self: *Self, top: *Top, x: i32, y: i32, scale: f64, now: i64) bool
pub fn paint(self: *Self, now: i64) void {
const alpha: f32 = @floatCast(self.amount(now));
- for (self.cards.items) |*card| {
- card.label.node.setPosition(@intFromFloat(@round(card.caption.x)), @intFromFloat(@round(card.caption.y)));
- card.label.setOpacity(alpha);
- }
const selected = if (self.selected) |id| find(self, id) else null;
for (self.edges) |edge| edge.node.setEnabled(selected != null and !self.returning);
const card = selected orelse return;
@@ -137,12 +93,6 @@ pub fn paint(self: *Self, now: i64) void {
pub fn picked(self: *Self, world: *World, x: f64, y: f64) ?u64 {
const now = ui.anim.nowMs();
- var i = self.cards.items.len;
- while (i > 0 and self.amount(now) > 0.01) {
- i -= 1;
- const card = self.cards.items[i];
- if (card.caption.contains(x, y)) return card.id;
- }
// While spreading/returning, frames can still overlap. The projection
// knows their actual stacking order, clips and subsurfaces at this instant.
const top = switch (@import("../scene_data.zig").hitTest(world.server, x, y)) {
diff --git a/src/world/overview_layout.zig b/src/world/overview_layout.zig
index 1bd11a5..aeee50b 100644
--- a/src/world/overview_layout.zig
+++ b/src/world/overview_layout.zig
@@ -1,5 +1,6 @@
//! Balanced rows of aspect-preserving previews. Short rows are centred and
-//! extra windows go in the bottom rows: four is 2+2, five is 2+3.
+//! extra windows go in the bottom rows: four is 2+2, five is 2+3. Margins and
+//! gaps are kept small so the previews fill as much of the output as they can.
const std = @import("std");
pub const Rect = struct {
@@ -13,11 +14,9 @@ pub const Rect = struct {
}
};
-pub const Placement = struct { frame: Rect, label: Rect };
-
-pub fn place(count: usize, index: usize, bounds: Rect, width: f64, height: f64, label_height: f64) Placement {
+pub fn place(count: usize, index: usize, bounds: Rect, width: f64, height: f64) Rect {
if (count == 0 or index >= count or bounds.width <= 0 or bounds.height <= 0 or width <= 0 or height <= 0)
- return .{ .frame = .{}, .label = .{} };
+ return .{};
const columns: usize = @intFromFloat(@ceil(@sqrt(@as(f64, @floatFromInt(count)))));
const rows = std.math.divCeil(usize, count, columns) catch unreachable;
const short = count / rows;
@@ -30,26 +29,20 @@ pub fn place(count: usize, index: usize, bounds: Rect, width: f64, height: f64,
column -= items;
}
const items = short + @intFromBool(row >= rows - long_rows);
- const padding = @min(40, @min(bounds.width, bounds.height) * 0.05);
+ const padding = @min(16, @min(bounds.width, bounds.height) * 0.02);
const available_w = bounds.width - padding * 2;
const available_h = bounds.height - padding * 2;
const cols: f64 = @floatFromInt(columns);
const lines: f64 = @floatFromInt(rows);
- const gap = @min(24, @min(available_w / (cols * 4), available_h / (lines * 4)));
+ const gap = @min(12, @min(available_w / (cols * 8), available_h / (lines * 8)));
const cell_w = (available_w - gap * (cols - 1)) / cols;
const cell_h = (available_h - gap * (lines - 1)) / lines;
- const caption = @min(label_height, cell_h / 4);
- const caption_gap = @min(8, cell_h / 10);
- const preview_h = cell_h - caption - caption_gap;
const x = bounds.x + padding + (available_w - (@as(f64, @floatFromInt(items)) * (cell_w + gap) - gap)) / 2 + @as(f64, @floatFromInt(column)) * (cell_w + gap);
const y = bounds.y + padding + @as(f64, @floatFromInt(row)) * (cell_h + gap);
- const scale = @min(1, @min(cell_w / width, preview_h / height));
+ const scale = @min(1, @min(cell_w / width, cell_h / height));
const w = width * scale;
const h = height * scale;
- return .{
- .frame = .{ .x = x + (cell_w - w) / 2, .y = y + (preview_h - h) / 2, .width = w, .height = h },
- .label = .{ .x = x, .y = y + preview_h + caption_gap, .width = cell_w, .height = caption },
- };
+ return .{ .x = x + (cell_w - w) / 2, .y = y + (cell_h - h) / 2, .width = w, .height = h };
}
test {
diff --git a/src/world/overview_layout_tests.zig b/src/world/overview_layout_tests.zig
index 8ee79f9..631eb47 100644
--- a/src/world/overview_layout_tests.zig
+++ b/src/world/overview_layout_tests.zig
@@ -4,39 +4,38 @@ const layout = @import("overview_layout.zig");
test "four windows use two equal rows; five centre two above three" {
const area: layout.Rect = .{ .x = 1280, .y = -100, .width = 1280, .height = 720 };
- const a = layout.place(4, 0, area, 1000, 800, 28).frame;
- const b = layout.place(4, 1, area, 1000, 800, 28).frame;
- const c = layout.place(4, 2, area, 1000, 800, 28).frame;
- const d = layout.place(4, 3, area, 1000, 800, 28).frame;
+ const a = layout.place(4, 0, area, 1000, 800);
+ const b = layout.place(4, 1, area, 1000, 800);
+ const c = layout.place(4, 2, area, 1000, 800);
+ const d = layout.place(4, 3, area, 1000, 800);
try expect(a.y == b.y and c.y == d.y and a.y < c.y);
try expect(a.x == c.x and b.x == d.x);
- const p = layout.place(5, 0, area, 1000, 800, 28).frame;
- const q = layout.place(5, 1, area, 1000, 800, 28).frame;
- const r = layout.place(5, 2, area, 1000, 800, 28).frame;
- const s = layout.place(5, 3, area, 1000, 800, 28).frame;
- const t = layout.place(5, 4, area, 1000, 800, 28).frame;
+ const p = layout.place(5, 0, area, 1000, 800);
+ const q = layout.place(5, 1, area, 1000, 800);
+ const r = layout.place(5, 2, area, 1000, 800);
+ const s = layout.place(5, 3, area, 1000, 800);
+ const t = layout.place(5, 4, area, 1000, 800);
try expect(p.y == q.y and r.y == s.y and s.y == t.y and p.y < r.y);
try std.testing.expectApproxEqAbs(area.x + area.width / 2, (p.x + q.x + q.width) / 2, 0.001);
try expect(p.x > r.x and q.x < t.x);
}
-test "mixed aspect previews and captions fit without intersections on small and large outputs" {
+test "mixed aspect previews fit without intersections on small and large outputs" {
for ([_]f64{ 320, 1280, 2560 }) |width| for (1..65) |count| {
const area: layout.Rect = .{ .x = -320, .y = 20, .width = width, .height = width * 0.6 };
for (0..count) |i| {
const w: f64 = if (i % 2 == 0) 2200 else 240;
const h: f64 = if (i % 2 == 0) 300 else 1500;
- const a = layout.place(count, i, area, w, h, 28);
- try expect(a.frame.width > 0 and a.frame.height > 0);
- try std.testing.expectApproxEqAbs(w / h, a.frame.width / a.frame.height, 0.0001);
- try expect(a.frame.x >= area.x and a.frame.y >= area.y);
- try expect(a.frame.x + a.frame.width <= area.x + area.width);
- try expect(a.label.y >= a.frame.y + a.frame.height);
- try expect(a.label.y + a.label.height <= area.y + area.height + 0.001);
+ const a = layout.place(count, i, area, w, h);
+ try expect(a.width > 0 and a.height > 0);
+ try std.testing.expectApproxEqAbs(w / h, a.width / a.height, 0.0001);
+ try expect(a.x >= area.x and a.y >= area.y);
+ try expect(a.x + a.width <= area.x + area.width);
+ try expect(a.y + a.height <= area.y + area.height + 0.001);
for (0..i) |j| {
- const b = layout.place(count, j, area, if (j % 2 == 0) 2200 else 240, if (j % 2 == 0) 300 else 1500, 28);
- try expect(a.frame.x + a.frame.width <= b.frame.x or b.frame.x + b.frame.width <= a.frame.x or
- a.frame.y + a.frame.height <= b.frame.y or b.frame.y + b.frame.height <= a.frame.y);
+ const b = layout.place(count, j, area, if (j % 2 == 0) 2200 else 240, if (j % 2 == 0) 300 else 1500);
+ try expect(a.x + a.width <= b.x or b.x + b.width <= a.x or
+ a.y + a.height <= b.y or b.y + b.height <= a.y);
}
}
};
diff --git a/tests/overview.py b/tests/overview.py
index 8f5dd9c..500b360 100644
--- a/tests/overview.py
+++ b/tests/overview.py
@@ -126,9 +126,9 @@ def run():
assert [len(row) for row in boxes] == counts, boxes
for row in boxes:
for left, right in zip(row, row[1:]):
- assert right[0] - left[2] >= 20, row
+ assert right[0] - left[2] >= 8, row
for upper, lower in zip(boxes, boxes[1:]):
- assert lower[0][1] - upper[0][3] >= 20, boxes
+ assert lower[0][1] - upper[0][3] >= 8, boxes
rgb = image.tobytes()
assert any(r > 240 and g < 15 and b > 240 for r, g, b in zip(rgb[::3], rgb[1::3], rgb[2::3])), "no selection outline"
return [box for row in boxes for box in row]