RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
added app-launcher
oxydizerf5a9d2a38e32
diff --git a/README.md b/README.mdindex 43b0a69..eccded5 100644--- a/README.md+++ b/README.md@@ -75,7 +75,7 @@ RediWM); it refuses to parse a document if isolation cannot be established.| Keys | Action || --- | --- |-| Super+Space | start menu |+| Super+Space | centered app launcher || Super+T / E / B | terminal / Files / browser || Super+Q, Super+F, Super+M | close, fullscreen, maximize || Super+Shift+arrows | tile halves and quarters |diff --git a/TESTING.md b/TESTING.mdindex 456c744..58a83fe 100644--- a/TESTING.md+++ b/TESTING.md@@ -125,6 +125,7 @@ canvas restore and shortcut overrides; supports `REDIWM_TEST_OUTPUTS=2`,GLES requires a render node; `--persistence-only` runs the restart/control checks), `window_snapping.py`, `initial_window_state.py` (startupmaximize/fullscreen placement, restore, window rules and depth), `taskbar_peek.py`,`taskbar_title_repaint.py`, `window_urgency.py`, `start_menu.py`,+`start_menu.py --launcher-only` (Super+Space in canvas and workspace modes, centered placement on a second output, fractional scale, live theme changes, keyboard/card launches, pin persistence and dismissal),`power_menu.py` (only ever activates Log Out), `control_center.py`,`control_center.py --services-only` (private systemd and polkit fixture: availability, in-table loading, unlock/lock and prompt cancellation, startup settings, Notify service types and isolated drop-in edits, runtime actions, authorization refusal, analysis, in-place state updates and coalesced reloads, signal-flood resistance, nothing read until the page is shown or while it is hidden, no RefUnit or unloaded-unit reads, the IPC lease, and lifetime),`calendar_popup.py`, `bluetooth.py` (private BlueZ service; Settings device search,diff --git a/docs/themes.md b/docs/themes.mdindex c471156..50fb037 100644--- a/docs/themes.md+++ b/docs/themes.md@@ -214,3 +214,26 @@ The small pack in `tests/fixtures/theme-pack/` supplies a glyph, folder icon,wallpaper and logo. `tests/theme_packs.py` adds a real cursor and exercisesinstallation, live switching, restoration, overrides and hostile archives.The greeter never discovers or reads user packs.++## Application launcher++Super+Space opens the application launcher in the centre of the pointer's+display. The taskbar Start button keeps the compact, edge-anchored menu.+The existing `toggle_start_menu` shortcut action opens the centered launcher,+so saved shortcut overrides continue to work.++Type to filter applications, use Up/Down and Enter to launch, and Escape or+Super+Space to dismiss. Tab switches between the list and the quick-launch+cards; Left/Right select a card. Use the + button to pin an application and+the checkmark to unpin it (up to five pins). Pins and recent launches are saved+in `$XDG_STATE_HOME/rediwm/launcher`, falling back to+`~/.local/state/rediwm/launcher`. With no history, Quick Launch offers the+first applications in alphabetical order. On short displays, the cards are+omitted to leave space for search results.++The launcher shares the `start_menu_*` theme colours, corner radius, search+field and selection styling with Start, as well as the shell's shared field+and button tokens, application text sizes and icon theme.+`start_menu_width` and `start_menu_max_height` override its automatic+760×720 logical-pixel size; the panel is always capped to fit its display.+Theme changes apply immediately while it is open.diff --git a/docs/wiki/Using-RediWM.md b/docs/wiki/Using-RediWM.mdindex ede8f00..f6197d2 100644--- a/docs/wiki/Using-RediWM.md+++ b/docs/wiki/Using-RediWM.md@@ -4,7 +4,7 @@| Keys | Action || --- | --- |-| Super+Space | start menu |+| Super+Space | centered app launcher || Super+T / E / B | terminal / Files / browser || Super+Q, Super+F, Super+M | close, fullscreen, maximize || Super+Shift+arrows | tile halves and quarters |diff --git a/src/Output.zig b/src/Output.zigindex 132fd47..728a440 100644--- a/src/Output.zig+++ b/src/Output.zig@@ -795,16 +795,40 @@ pub fn toggleStartMenu(output: *Output) void {/// restoring it is therefore part of opening, and a caller that only called/// `StartMenu.reopen` got a visible menu that no key could reach.pub fn openStartMenu(output: *Output) void {+ output.openMenu(.start);+}++/// The keyboard launcher shares catalogue, focus and lifetime with Start.+pub fn toggleAppLauncher(output: *Output) void {+ if (output.start_menu) |sm| {+ if (sm.mode == .launcher and sm.state != .closing) {+ output.closeStartMenu();+ return;+ }+ }+ output.openMenu(.launcher);+}++fn openMenu(output: *Output, mode: StartMenu.Mode) void {output.server.input.window_menu.close();if (output.server.input.open_wifi) |popup| popup.output.closeWifi();if (output.server.input.open_battery) |popup| popup.output.closeBattery();if (output.server.input.open_calendar) |calendar| calendar.output.closeCalendar();+ if (output.server.input.open_start_menu) |other| {+ if (other.wlr_output != output.wlr_output) {+ if (Output.fromWlr(other.wlr_output)) |owner| owner.closeStartMenu();+ }+ }if (output.start_menu) |sm| {- if (sm.state != .closing) return;+ if (sm.mode != mode) {+ sm.mode = mode;+ sm.buildTree();+ sm.relayout();+ } else if (sm.state != .closing) return;sm.reopen();} else {if (output.power_menu != null) output.closePowerMenu();- output.start_menu = StartMenu.create(output.server, output.wlr_output) catch |err| blk: {+ output.start_menu = StartMenu.createMode(output.server, output.wlr_output, mode) catch |err| blk: {log.err("openStartMenu: could not create panel: {}", .{err});break :blk null;};diff --git a/src/Server.zig b/src/Server.zigindex 3e96be2..7f6df72 100644--- a/src/Server.zig+++ b/src/Server.zig@@ -185,6 +185,7 @@ config_generation: u64 = 1,config_reload_error: ?[]const u8 = null,layout_keyboard: ?*@import("Keyboard.zig") = null,start_menu_catalog: *applications.Catalog,+launcher_history: @import("start_menu/history.zig").History = .{},/// Memoizes `iconNameForAppId`, which is three linear scans over the whole/// desktop-entry catalog (~400 entries here). `syncChrome` calls `iconLookup`/// on every client surface commit, so without this the compositor ran thosediff --git a/src/config/workspace_defaults.zig b/src/config/workspace_defaults.zigindex 3fe3083..9206d63 100644--- a/src/config/workspace_defaults.zig+++ b/src/config/workspace_defaults.zig@@ -5,6 +5,7 @@ pub const source =\\"Super+c" = "close_window"\\"Super+e" = "spawn default-file-manager"\\"Super+r" = "toggle_start_menu"+ \\"Super+space" = "toggle_start_menu"\\"Super+m" = "toggle_power_menu"\\"Super+f" = "toggle_fullscreen"\\"Super+l" = "lock_screen"diff --git a/src/config_runtime/actions.zig b/src/config_runtime/actions.zigindex 4db480e..746577c 100644--- a/src/config_runtime/actions.zig+++ b/src/config_runtime/actions.zig@@ -173,7 +173,7 @@ fn toggleStartMenu(server: *Server) void {var out_it = server.outputs.iterator(.forward);break :blk out_it.next();};- if (output) |out| out.toggleStartMenu();+ if (output) |out| out.toggleAppLauncher();}fn setFocusedDepth(server: *Server, band: u8) void {diff --git a/src/start_menu/history.zig b/src/start_menu/history.zignew file mode 100644index 0000000..e4ac402--- /dev/null+++ b/src/start_menu/history.zig@@ -0,0 +1,157 @@+//! Bounded launcher history: pinned IDs first, then most recently launched.+//! Stored independently of the catalogue so refreshes never retain app pointers.+const std = @import("std");+const Server = @import("../Server.zig");+const gpa = @import("../main.zig").gpa;++pub const History = struct {+ const Entry = struct {+ bytes: [512]u8 = undefined,+ len: usize = 0,+ pinned: bool = false,+ fn id(e: *const Entry) []const u8 {+ return e.bytes[0..e.len];+ }+ };+ entries: [32]Entry = undefined,+ len: usize = 0,+ loaded: bool = false,++ pub fn load(h: *History, server: *Server) void {+ if (h.loaded or server.greeter_mode) return;+ h.loaded = true;+ var arena = std.heap.ArenaAllocator.init(gpa);+ defer arena.deinit();+ const a = arena.allocator();+ const dir = (@import("../window_sizes.zig").resolveStateDir(a, server.environ) catch return) orelse return;+ const path = std.fmt.allocPrint(a, "{s}/launcher", .{dir}) catch return;+ const bytes = std.Io.Dir.cwd().readFileAlloc(server.io, path, a, .limited(32 * 515)) catch return;+ var lines = std.mem.splitScalar(u8, bytes, '\n');+ while (lines.next()) |line| {+ if (line.len < 3 or line[1] != '\t' or (line[0] != 'P' and line[0] != 'R')) continue;+ const app_id = line[2..];+ if (!valid(app_id) or h.index(app_id) != null or h.len == h.entries.len) continue;+ var entry: Entry = .{ .len = app_id.len, .pinned = line[0] == 'P' };+ @memcpy(entry.bytes[0..app_id.len], app_id);+ h.entries[h.len] = entry;+ h.len += 1;+ }+ }++ fn valid(app_id: []const u8) bool {+ return app_id.len > 0 and app_id.len <= 512 and std.mem.indexOfAny(u8, app_id, "\n\r\t\x00") == null;+ }++ fn index(h: *const History, app_id: []const u8) ?usize {+ for (h.entries[0..h.len], 0..) |*entry, i| {+ if (std.mem.eql(u8, entry.id(), app_id)) return i;+ }+ return null;+ }++ pub fn pinned(h: *const History, app_id: []const u8) bool {+ return if (h.index(app_id)) |i| h.entries[i].pinned else false;+ }++ fn remember(h: *History, app_id: []const u8) void {+ if (!valid(app_id)) return;+ const pin = h.pinned(app_id);+ const at = h.index(app_id) orelse blk: {+ if (h.len < h.entries.len) {+ h.len += 1;+ break :blk h.len - 1;+ }+ // Never evict a pin to make room for a launch.+ var i = h.len;+ while (i > 0) {+ i -= 1;+ if (!h.entries[i].pinned) break :blk i;+ }+ return;+ };+ std.mem.copyBackwards(Entry, h.entries[1 .. at + 1], h.entries[0..at]);+ h.entries[0] = .{ .len = app_id.len, .pinned = pin };+ @memcpy(h.entries[0].bytes[0..app_id.len], app_id);+ }++ pub fn launched(h: *History, server: *Server, app_id: []const u8) void {+ if (server.greeter_mode) return;+ h.load(server);+ h.remember(app_id);+ h.save(server);+ }++ pub fn pinCount(h: *const History) usize {+ var count: usize = 0;+ for (h.entries[0..h.len]) |entry| {+ if (entry.pinned) count += 1;+ }+ return count;+ }++ pub fn togglePin(h: *History, server: *Server, app_id: []const u8) void {+ if (server.greeter_mode or !valid(app_id)) return;+ h.load(server);+ if (!h.pinned(app_id) and h.pinCount() >= 5) return;+ if (h.index(app_id) == null) h.remember(app_id);+ const i = h.index(app_id) orelse return;+ h.entries[i].pinned = !h.entries[i].pinned;+ h.save(server);+ }++ /// Resolve against current results; removed/hidden apps are never offered.+ pub fn cards(h: *const History, results: anytype, out: []usize) usize {+ var count: usize = 0;+ for ([_]bool{ true, false }) |pin| {+ for (h.entries[0..h.len]) |*entry| {+ if (entry.pinned != pin) continue;+ for (results, 0..) |result, i| {+ if (result.app_entry != null and std.mem.eql(u8, result.id, entry.id())) {+ if (count == out.len) return count;+ out[count] = i;+ count += 1;+ break;+ }+ }+ }+ }+ return count;+ }++ fn save(h: *const History, server: *Server) void {+ var arena = std.heap.ArenaAllocator.init(gpa);+ defer arena.deinit();+ const a = arena.allocator();+ const dir = (@import("../window_sizes.zig").resolveStateDir(a, server.environ) catch return) orelse return;+ std.Io.Dir.cwd().createDirPath(server.io, dir) catch return;+ const path = std.fmt.allocPrint(a, "{s}/launcher", .{dir}) catch return;+ const tmp = std.fmt.allocPrint(a, "{s}.tmp", .{path}) catch return;+ var bytes: std.ArrayList(u8) = .empty;+ for (h.entries[0..h.len]) |*entry| {+ bytes.appendSlice(a, if (entry.pinned) "P\t" else "R\t") catch return;+ bytes.appendSlice(a, entry.id()) catch return;+ bytes.append(a, '\n') catch return;+ }+ const file = std.Io.Dir.cwd().createFile(server.io, tmp, .{ .truncate = true }) catch return;+ defer std.Io.Dir.cwd().deleteFile(server.io, tmp) catch {};+ file.writeStreamingAll(server.io, bytes.items) catch {+ file.close(server.io);+ return;+ };+ file.close(server.io);+ std.Io.Dir.rename(.cwd(), tmp, .cwd(), path, server.io) catch {};+ }+};++test "launcher history deduplicates launches and preserves pins when full" {+ var history: History = .{};+ history.remember("pinned.desktop");+ history.entries[0].pinned = true;+ var buf: [32]u8 = undefined;+ for (0..40) |i| history.remember(try std.fmt.bufPrint(&buf, "app-{d}.desktop", .{i}));+ try std.testing.expectEqual(@as(usize, 32), history.len);+ try std.testing.expect(history.pinned("pinned.desktop"));+ history.remember("app-39.desktop");+ try std.testing.expectEqual(@as(usize, 32), history.len);+ try std.testing.expectEqualStrings("app-39.desktop", history.entries[0].id());+}diff --git a/src/start_menu/launch.zig b/src/start_menu/launch.zigindex d0c0dbe..898d030 100644--- a/src/start_menu/launch.zig+++ b/src/start_menu/launch.zig@@ -220,7 +220,8 @@ pub fn launch(server: *Server,entry: *const AppEntry,) !void {- return launchUris(allocator, server, entry, &.{});+ try launchUris(allocator, server, entry, &.{});+ server.launcher_history.launched(server, entry.id);}pub fn launchUris(allocator: Allocator, server: *Server, entry: *const AppEntry, uris: []const []const u8) !void {diff --git a/src/start_menu/panel.zig b/src/start_menu/panel.zigindex 0a44c6f..a0a6f58 100644--- a/src/start_menu/panel.zig+++ b/src/start_menu/panel.zig@@ -1,8 +1,6 @@// Compositor-drawn start menu panel.//-// Charcoal panel, red outlined search field, spacious-// two-line application rows, colorful icons, red selection marker, and bottom-// category bar.+// Taskbar menu and centered keyboard launcher, using the same themed widgets.const std = @import("std");const Allocator = std.mem.Allocator;const glass = @import("../glass.zig");@@ -50,6 +48,12 @@ const Highlights = struct { sel: f32 = 0, hover: f32 = 0, hover_alpha: f32 = 0 }const row_pitch: f32 = 60;pub const StartMenu = struct {+ pub const Mode = enum { start, launcher };+ mode: Mode = .start,+ card_indices: [5]usize = undefined,+ card_count: usize = 0,+ card_icons: [5]?u64 = @splat(null),+ card_selection: ?usize = null,server: *Server,wlr_output: *wlr.Output,buffer_node: *wlr.SceneBuffer,@@ -102,6 +106,10 @@ pub const StartMenu = struct {prefetch_initialized: bool = false,pub fn create(server: *Server, wlr_output: *wlr.Output) !*StartMenu {+ return createMode(server, wlr_output, .start);+ }++ pub fn createMode(server: *Server, wlr_output: *wlr.Output, mode: Mode) !*StartMenu {const menu = try gpa.create(StartMenu);errdefer gpa.destroy(menu);@@ -111,6 +119,7 @@ pub const StartMenu = struct {menu.* = .{.server = server,+ .mode = mode,.wlr_output = wlr_output,.buffer_node = buffer_node,.glass_effect = glass.Engine.attach(server.glass_engine, buffer_node, &buffer_node.node, .panel),@@ -124,6 +133,7 @@ pub const StartMenu = struct {defer snap.release();try menu.model.bindSnapshot(snap, false);+ server.launcher_history.load(server);menu.buildTree();menu.slide.retargetTo(anim.nowMs(), 1, anim.curveFor(.panel_slide));menu.relayout();@@ -293,7 +303,7 @@ pub const StartMenu = struct {fn syncHoverRow(menu: *StartMenu) void {const row: ?usize = if (menu.dispatcher.hovered) |w| switch (w.kind) {- .row => |data| if (data.owner == @as(?*anyopaque, menu)) data.id else null,+ .row => |data| if (data.owner == @as(?*anyopaque, menu) and data.on_click == onRowClick) data.id else null,else => null,} else null;menu.setHoverRow(row);@@ -305,6 +315,9 @@ pub const StartMenu = struct {const menu: *StartMenu = @ptrCast(@alignCast(owner orelse return));const t = renderer.palette orelse theme.global;if (scroll.children.len == 0) return;+ if (menu.mode == .launcher) {+ for (scroll.children) |*row| renderer.fillRect(row.computed_x + 8, row.computed_y + row.computed_height + 1, @max(0, row.computed_width - 16), 1, .{ .color = t.border_soft });+ }// Fades out as it reaches the selected row, which draws its own fill.const apart = std.math.clamp(@abs(menu.hl.hover - menu.hl.sel), 0, 1);const hover_alpha = std.math.clamp(menu.hl.hover_alpha, 0, 1) * apart;@@ -317,7 +330,7 @@ pub const StartMenu = struct {.border_color = scaleAlpha(t.border_soft, hover_alpha),});}- if (menu.model.results.len == 0) return;+ if (menu.model.results.len == 0 or menu.card_selection != null) return;const box = rowBox(scroll, menu.hl.sel);renderer.fillRect(box.x, box.y, box.w, box.h, .{.color = t.start_menu_selected_bg,@@ -405,6 +418,7 @@ pub const StartMenu = struct {// ---- Tree building ----pub fn buildTree(menu: *StartMenu) void {+ if (menu.mode == .start) menu.card_selection = null;menu.dispatcher.reset();// Fresh rows carry no pointer state; let the hover fill fade out.menu.setHoverRow(null);@@ -419,7 +433,7 @@ pub const StartMenu = struct {sw_children[0] = .{.name = "search_input",.kind = .{ .text_input = .{- .placeholder = "Type to search…",+ .placeholder = if (menu.mode == .launcher) "Search applications…" else "Type to search…",.field = .{ .leading_icon = .search, .leading_icon_size = 24, .leading_icon_color = t.window_fg },.value = query_val,.cursor_pos = @min(menu.query_cursor, query_val.len),@@ -518,7 +532,7 @@ pub const StartMenu = struct {title_widget.* = .{.kind = .{ .text = .{.content = res.name,- .font_size = 13.5,+ .font_size = if (menu.mode == .launcher) t.app_text_size else 13.5,.weight = 600,.color = t.fg,} },@@ -528,7 +542,7 @@ pub const StartMenu = struct {desc_widget.* = .{.kind = .{ .text = .{.content = res.description,- .font_size = 11.5,+ .font_size = if (menu.mode == .launcher) t.app_status_size else 11.5,.weight = 400,.color = t.dim,} },@@ -549,7 +563,20 @@ pub const StartMenu = struct {// Row children: image, text column, optional enter hintvar row_kids: []Widget = undefined;- if (is_sel) {+ if (menu.mode == .launcher) {+ var output_box: wlr.Box = undefined;+ menu.server.output_layout.getBox(menu.wlr_output, &output_box);+ const show_id = @min(menu.wantedSize().width, @as(f32, @floatFromInt(output_box.width)) - 40) >= 700;+ row_kids = a.alloc(Widget, if (show_id) 5 else 4) catch return;+ row_kids[0] = img_widget.*;+ row_kids[1] = col_widget.*;+ if (show_id) row_kids[2] = .{+ .kind = .{ .text = .{ .content = res.id, .font_size = t.app_status_size, .color = t.dim } },+ .width = .{ .fixed = 170 },+ };+ row_kids[row_kids.len - 2] = menu.pinButton(idx);+ row_kids[row_kids.len - 1] = .{ .kind = .{ .icon = .{ .id = .chevron_right, .color = t.dim } }, .width = .{ .fixed = 14 }, .height = .{ .fixed = 14 } };+ } else if (is_sel) {const hint_widget = a.create(Widget) catch return;hint_widget.* = .{.kind = .{ .text = .{@@ -738,6 +765,23 @@ pub const StartMenu = struct {root_kids[4] = footer_widget.*;}+ var children = root_kids;+ if (menu.mode == .launcher) {+ const recent = menu.buildCards(a) catch return;+ var launcher_kids: std.ArrayList(Widget) = .empty;+ launcher_kids.append(a, search_wrapper.*) catch return;+ if (recent) |cards| launcher_kids.appendSlice(a, &cards) catch return;+ launcher_kids.append(a, heading_wrapper.*) catch return;+ if (error_widget) |err| launcher_kids.append(a, err.*) catch return;+ launcher_kids.append(a, scroll_widget.*) catch return;+ if (row_count == 0) launcher_kids.append(a, .{+ .name = "no_results",+ .kind = .{ .text = .{ .content = "No applications found", .font_size = t.app_text_size, .color = t.dim } },+ .margin = layout.Edges.xy(24, 16),+ }) catch return;+ children = launcher_kids.toOwnedSlice(a) catch return;+ }+menu.root = .{.kind = .{ .rect = .{.color = t.start_menu_bg,@@ -748,7 +792,8 @@ pub const StartMenu = struct {.direction = .column,.width = .{ .fixed = menu.wantedSize().width },.height = .auto,- .children = root_kids,+ .children = children,+ .padding = if (menu.mode == .launcher) .{ .bottom = 16 } else .{},};menu.root.linkParents();// Bind before the opening click release, which otherwise clears search focus.@@ -763,11 +808,136 @@ pub const StartMenu = struct {}}+ fn pinButton(menu: *StartMenu, index: usize) Widget {+ const result = menu.model.results[index];+ const pinned = menu.server.launcher_history.pinned(result.id);+ const full = !pinned and menu.server.launcher_history.pinCount() >= 5;+ return .{+ .name = "pin_app",+ .kind = .{ .button = .{+ .label = if (pinned) "Unpin application" else if (full) "Five applications already pinned" else "Pin application",+ .icon = if (pinned) .checkmark else .plus,+ .variant = if (pinned) .primary else .ghost,+ .size = .sm,+ .owner = menu,+ .id = index,+ .on_click = onPinClick,+ .state = if (result.app_entry == null) .disabled else .idle,+ } },+ .width = .{ .fixed = 28 },+ .height = .{ .fixed = 28 },+ };+ }++ fn buildCards(menu: *StartMenu, a: Allocator) !?[2]Widget {+ menu.card_count = 0;+ menu.card_icons = @splat(null);+ if (menu.model.query.items.len > 0) {+ menu.card_selection = null;+ return null;+ }+ const wanted = menu.wantedSize();+ var box: wlr.Box = undefined;+ menu.server.output_layout.getBox(menu.wlr_output, &box);+ // Leave room for search and results on short/fractionally scaled outputs.+ if (@min(wanted.height, @as(f32, @floatFromInt(box.height)) * 0.85) < 420) {+ menu.card_selection = null;+ return null;+ }+ const width = @min(wanted.width, @as(f32, @floatFromInt(box.width)) - 40);+ const capacity: usize = @intFromFloat(std.math.clamp(@floor((width - 40) / 116), 1, 5));+ menu.card_count = menu.server.launcher_history.cards(menu.model.results, menu.card_indices[0..capacity]);+ const have_history = menu.card_count > 0;+ if (!have_history) {+ for (menu.model.results, 0..) |result, i| {+ if (result.app_entry == null) continue;+ menu.card_indices[menu.card_count] = i;+ menu.card_count += 1;+ if (menu.card_count == capacity) break;+ }+ }+ if (menu.card_count == 0) {+ menu.card_selection = null;+ return null;+ }+ if (menu.card_selection) |selected| {+ if (selected >= menu.card_count) menu.card_selection = null;+ }+ const t = menuPalette();+ const cards = try a.alloc(Widget, menu.card_count);+ for (menu.card_indices[0..menu.card_count], 0..) |index, i| {+ const result = menu.model.results[index];+ const top = try a.dupe(Widget, &.{+ .{ .kind = .container, .width = .{ .flex = 1 } },+ menu.pinButton(index),+ });+ const children = try a.dupe(Widget, &.{+ .{ .kind = .container, .direction = .row, .width = .{ .percent = 1 }, .height = .{ .fixed = 28 }, .children = top },+ .{ .kind = .{ .image = .{ .fallback_icon = .generic, .radius = t.radius } }, .width = .{ .fixed = 48 }, .height = .{ .fixed = 48 } },+ .{ .kind = .{ .text = .{ .content = result.name, .font_size = t.app_text_size, .color = t.fg } }, .width = .{ .percent = 1 }, .height = .{ .fixed = 22 } },+ });+ cards[i] = .{+ .name = "recent_app",+ .kind = .{ .row = .{+ .owner = menu,+ .id = index,+ .on_click = onCardClick,+ .selected = menu.card_selection == i,+ .background = .{ .color = t.start_menu_search_bg, .radius = t.radius, .border_width = 1, .border_color = t.border_soft },+ .hover_background = .{ .color = t.start_menu_selected_bg, .radius = t.radius, .border_width = 1, .border_color = t.start_menu_selected_border },+ } },+ .direction = .column,+ .@"align" = .center,+ .gap = 6,+ .padding = layout.Edges.xy(10, 6),+ .width = .{ .fixed = (width - 40 - @as(f32, @floatFromInt(capacity - 1)) * 10) / @as(f32, @floatFromInt(capacity)) },+ .height = .{ .fixed = 126 },+ .children = children,+ };+ }+ return .{+ .{ .name = "recent_heading", .kind = .container, .direction = .row, .@"align" = .center, .padding = layout.Edges.xy(24, 6), .height = .{ .fixed = 34 }, .children = try a.dupe(Widget, &.{.{ .kind = .{ .text = .{+ .content = if (have_history) "Pinned & Recent" else "Quick Launch",+ .font_size = t.app_heading_size,+ .weight = 600,+ .color = t.dim,+ } } }}) },+ .{ .name = "recent_cards", .kind = .container, .direction = .row, .gap = 10, .padding = .{ .left = 20, .right = 20, .bottom = 16 }, .width = .{ .percent = 1 }, .children = cards },+ };+ }++ fn onCardClick(owner: ?*anyopaque, id: usize) void {+ const menu: *StartMenu = @ptrCast(@alignCast(owner orelse return));+ menu.activateResult(id);+ }++ fn onPinClick(owner: ?*anyopaque, id: usize) void {+ const menu: *StartMenu = @ptrCast(@alignCast(owner orelse return));+ if (id >= menu.model.results.len) return;+ const result = menu.model.results[id];+ if (result.app_entry == null) return;+ const scroll = menu.currentScrollOffset();+ const history = &menu.server.launcher_history;+ if (!history.pinned(result.id) and history.pinCount() >= 5) {+ menu.model.error_msg = "Unpin an application first (five pins maximum).";+ } else {+ menu.model.error_msg = null;+ history.togglePin(menu.server, result.id);+ }+ menu.buildTree();+ menu.restoreScrollOffset(scroll);+ menu.requestRepaint();+ }+/// The size the theme asks for on this menu's output, before the caps in/// `relayout`: its own values, else the automatic ones (`size.zig`).fn wantedSize(menu: *StartMenu) size_mod.Size {var box: wlr.Box = undefined;menu.server.output_layout.getBox(menu.wlr_output, &box);+ if (menu.mode == .launcher) return .{+ .width = if (theme.global.start_menu_width > 0) theme.global.start_menu_width else 760,+ .height = if (theme.global.start_menu_max_height > 0) theme.global.start_menu_max_height else 720,+ };return size_mod.wanted(theme.global, @floatFromInt(box.width), @floatFromInt(box.height));}@@ -781,13 +951,17 @@ pub const StartMenu = struct {const max_allowed_h = @min(wanted.height, @as(f32, @floatFromInt(output_box.height)) * 0.85);const max_allowed_w = @min(wanted.width, @as(f32, @floatFromInt(output_box.width)) - 40);- const target_height = @max(240, max_allowed_h);- const target_width = @max(320, max_allowed_w);+ const target_height = if (menu.mode == .launcher) @max(1, max_allowed_h) else @max(240, max_allowed_h);+ const target_width = if (menu.mode == .launcher) @max(1, max_allowed_w) else @max(320, max_allowed_w);+ const scroll_offset = menu.currentScrollOffset();+ if (menu.mode == .launcher and menu.panel_box.width > 0 and+ (menu.panel_box.width != @as(i32, @intFromFloat(target_width)) or menu.panel_box.height != @as(i32, @intFromFloat(target_height)))) menu.buildTree();menu.root.width = .{ .fixed = target_width };menu.root.height = .{ .fixed = target_height };ui.measure.measure(&menu.root, target_width, target_height);ui.arrange.arrange(&menu.root, 0, 0, target_width, target_height);+ menu.restoreScrollOffset(scroll_offset);const bottom_offset: f32 = @as(f32, @floatFromInt(Taskbar.barHeight())) + theme.global.start_menu_bottom_pad;const start_offset: f32 = if (Output.fromWlr(menu.wlr_output)) |output| if (output.taskbar) |bar| @floatFromInt(bar.startButtonBox().x - output_box.x - Taskbar.startButtonLeft()) else 0 else 0;@@ -799,6 +973,10 @@ pub const StartMenu = struct {.width = @intFromFloat(target_width),.height = @intFromFloat(target_height),};+ if (menu.mode == .launcher) {+ menu.panel_box.x = output_box.x + @divTrunc(output_box.width - menu.panel_box.width, 2);+ menu.panel_box.y = output_box.y + @divTrunc(output_box.height - menu.panel_box.height, 2);+ }menu.dirty = true;menu.paintContent();menu.applyPresentation(anim.nowMs());@@ -842,6 +1020,18 @@ pub const StartMenu = struct {}}+ for (menu.root.children) |*strip| {+ if (!std.mem.eql(u8, strip.name orelse "", "recent_cards")) continue;+ for (strip.children, 0..) |*card, i| {+ const img = &card.children[1];+ const result = menu.model.results[menu.card_indices[i]];+ const lookup = if (result.icon) |name| menu.server.iconLookup(name, geometry.devicePixels(48, menu.wlr_output.scale)) else icon_service.Lookup.missing;+ if (updateIcon(&img.kind.image, &menu.card_icons[i], lookup)) {+ img.markPaintDirty();+ changed = true;+ }+ }+ }if (have_viewport) menu.prefetchAhead(scroll_offset, first_visible, last_visible);return changed;}@@ -854,9 +1044,7 @@ pub const StartMenu = struct {// prefetch for the new one. `results.ptr` changing is a cheap, reliable// "new query/category" signal — `Model.update` always rebuilds// `results` from a fresh arena allocation, even for identical content.- // No favourites prefetch: this codebase has no favourites/launch-history- // source to prefetch from (see plan-performance-4-icon-preparation.md- // step 5), and none is added here just for this optimization.+ // Recent-card icons are visible lookups handled alongside the list above.fn prefetchAhead(menu: *StartMenu, scroll_offset: f32, first_visible: ?usize, last_visible: usize) void {const results_ptr: [*]const SearchResult = menu.model.results.ptr;const results_changed = !menu.prefetch_initialized or results_ptr != menu.prefetch_results_ptr;@@ -933,6 +1121,10 @@ pub const StartMenu = struct {// ---- Interaction & Actions ----pub fn activateSelected(menu: *StartMenu) void {+ if (menu.card_selection) |i| {+ if (i < menu.card_count) menu.activateResult(menu.card_indices[i]);+ return;+ }if (menu.model.selected_index < menu.model.results.len) {menu.activateResult(menu.model.selected_index);}@@ -956,7 +1148,8 @@ pub const StartMenu = struct {menu.model.launching = true;launch.launch(gpa, menu.server, entry) catch |err| {menu.model.launching = false;- menu.model.error_msg = std.fmt.allocPrint(menu.tree_arena.allocator(), "Launch failed: {s}", .{@errorName(err)}) catch "Launch failed";+ log.err("launch failed: {s}", .{@errorName(err)});+ menu.model.error_msg = "Launch failed. The application may have been removed.";menu.buildTree();menu.requestRepaint();return;@@ -979,6 +1172,15 @@ pub const StartMenu = struct {const edit_mods = ui.input.Mods{ .shift = mods.shift };if (state == .released) return true;+ // Left/right navigate the quick-launch strip; typing returns to search.+ if (menu.card_selection) |selected| {+ if (@intFromEnum(keysym) == xkb.Keysym.Left or @intFromEnum(keysym) == xkb.Keysym.Right) {+ menu.card_selection = if (@intFromEnum(keysym) == xkb.Keysym.Left) selected -| 1 else @min(selected + 1, menu.card_count - 1);+ menu.buildTree();+ menu.requestRepaint();+ return true;+ }+ }// Pressed:switch (@intFromEnum(keysym)) {xkb.Keysym.Escape => {@@ -1006,6 +1208,12 @@ pub const StartMenu = struct {return true;},xkb.Keysym.Tab => {+ if (menu.mode == .launcher) {+ menu.card_selection = if (menu.card_selection == null and menu.card_count > 0) 0 else null;+ menu.buildTree();+ menu.requestRepaint();+ return true;+ }// Cycle categoryconst next_cat: Category = if (menu.model.category == .all) .apps else .all;const snap = menu.server.start_menu_catalog.retainSnapshot();@@ -1105,7 +1313,9 @@ pub const StartMenu = struct {}fn navigateResults(menu: *StartMenu, delta: isize) void {- if (menu.model.moveSelection(delta)) {+ const was_card = menu.card_selection != null;+ menu.card_selection = null;+ if (menu.model.moveSelection(delta) or was_card) {menu.sel_pos.retargetTo(anim.nowMs(), @floatFromInt(menu.model.selected_index), anim.curveFor(.start_glide));menu.syncQueryState();menu.buildTree();@@ -1129,6 +1339,7 @@ pub const StartMenu = struct {}fn onQueryEdited(menu: *StartMenu) void {+ menu.card_selection = null;// Read text input value back into modelif (menu.dispatcher.focused) |focused| {if (std.meta.activeTag(focused.kind) == .text_input) {diff --git a/src/ui_tests.zig b/src/ui_tests.zigindex afec3b4..90fbcad 100644--- a/src/ui_tests.zig+++ b/src/ui_tests.zig@@ -53,6 +53,7 @@ test {_ = @import("start_menu/launch.zig");_ = @import("start_menu/search.zig");_ = @import("start_menu/model.zig");+ _ = @import("start_menu/history.zig");_ = @import("start_menu/panel.zig");_ = @import("icon_cache.zig");_ = @import("ui").shell_icons;diff --git a/tests/start_menu.py b/tests/start_menu.pyindex 32a3849..938aa80 100644--- a/tests/start_menu.py+++ b/tests/start_menu.py@@ -219,17 +219,8 @@ def run():client.wait_for("control_center_closed", timeout_ms=5000)assert panel_stats()["paints"] == cc_stats["paints"], "control center close repainted content"- client.action('reset_panel_stats')- client.open_power_menu()- client.wait_for("power_menu_opened", timeout_ms=5000)- pm_stats = panel_stats()- assert pm_stats["paints"] == 1, pm_stats- assert ImageChops.difference(closed, capture_now("power-open")).getbbox(), "power menu did not appear"- key(1)- client.wait_for("power_menu_closed", timeout_ms=5000)- assert panel_stats()["paints"] == 1, "power menu close repainted content"- print(f"Panel reuse: start/control/power open+close without extra paints; "- f"alloc={cc_stats['allocated_bytes']} reuse={pm_stats['reused_bytes']}")+ print(f"Panel reuse: start/control open+close without extra paints; "+ f"alloc={cc_stats['allocated_bytes']} reuse={cc_stats['reused_bytes']}")except Exception:print((tmp / "compositor.log").read_text())raise@@ -531,8 +522,150 @@ def run_highlight_reload():log.close()+def run_launcher():+ """Centered keyboard launcher: placement, shared theme, pin/history and launch."""+ for scale in ("1", "1.5"):+ with tempfile.TemporaryDirectory(prefix="rediwm-launcher-") as directory:+ tmp = Path(directory)+ apps = tmp / "data" / "applications"+ apps.mkdir(parents=True)+ for number in range(8):+ (apps / f"launcher-{number}.desktop").write_text(+ "[Desktop Entry]\nType=Application\n"+ f"Name=Launcher App {number}\nComment=Launcher fixture {number}\n"+ f"Exec=/usr/bin/touch {tmp}/launched-{number}\nIcon=system-file-manager\n")+ env = {"XDG_DATA_HOME": str(tmp / "data"), "XDG_DATA_DIRS": str(tmp / "empty"), "XDG_CACHE_HOME": str(tmp / "cache"),+ "DBUS_SESSION_BUS_ADDRESS": "", "REDIWM_FILES_DEVICES": "0"}+ config = ('[compositor]\ndesktop_mode = "workspaces"\n' if scale == '1.5' else '') + '[animations]\nenabled = false\n[theme]\nstart_menu_bg = "#102030"\n'+ process, log = spawn_compositor(tmp, scale=scale, outputs="2", config_content=config, env_extra=env)+ try:+ with IPCClient(tmp) as client:+ client.wait_for("catalog_published", timeout_ms=10000)+ outputs = client.get_outputs()+ out = outputs[-1]+ client.move_cursor(50, 50, output=out["name"])++ def toggle():+ client.key(125, True)+ client.key_down_up(57)+ client.key(125, False)++ def menu():+ return client.get_shell_state(output=out["name"])["start_menu"]++ def widgets():+ return client.get_widget_tree("start_menu")["widgets"]++ def click(widget):+ box = widget["global_box"]+ client.move_cursor(box["x"] + box["width"] // 2 - out["x"], box["y"] + box["height"] // 2 - out["y"], output=out["name"])+ client.pointer_button(272, True)+ client.pointer_button(272, False)++ toggle()+ client.wait_for("menu_opened", timeout_ms=5000)+ panel = menu()["box"]+ assert abs(2 * panel["x"] + panel["width"] - (2 * out["x"] + out["logical_width"])) <= 1, (panel, out)+ assert abs(2 * panel["y"] + panel["height"] - (2 * out["y"] + out["logical_height"])) <= 1, (panel, out)+ assert panel["width"] <= out["logical_width"] and panel["height"] <= out["logical_height"], (panel, out)+ if scale == "1":+ assert any(w.get("name") == "recent_cards" for w in widgets()), widgets()+ client.key_down_up(15) # Tab: cards; Right then Enter launches app 1.+ client.key_down_up(106)+ client.key_down_up(28)+ client.wait_for("menu_closed", timeout_ms=5000)+ wait_for(lambda: (tmp / "launched-1").exists(), "card keyboard launch failed")+ toggle()+ client.wait_for("menu_opened", timeout_ms=5000)+ assert any(w.get("label") == "Pinned & Recent" for w in widgets())++ client.type_text("Launcher App 3")+ assert menu()["search_text"] == "Launcher App 3"+ assert not any(w.get("name") == "recent_cards" for w in widgets())+ pin = next(w for w in widgets() if w.get("label") == "Pin application")+ click(pin)+ state = tmp / "state" / "rediwm" / "launcher"+ assert "P\tlauncher-3.desktop" in state.read_text()+ assert menu()["search_text"] == "Launcher App 3", "pinning lost search"+ client.key_down_up(28)+ client.wait_for("menu_closed", timeout_ms=5000)+ wait_for(lambda: (tmp / "launched-3").exists(), "selected app did not launch")+ toggle()+ client.wait_for("menu_opened", timeout_ms=5000)+ # Reload colours and dimensions while open; geometry stays centred.+ (tmp / "rediwm-config.toml").write_text(config.replace('#102030', '#304050') + 'start_menu_width = 600\n')+ client.reload_config()+ client.wait_for_frame()+ panel = menu()["box"]+ assert panel["width"] == min(600, out["logical_width"] - 40), panel+ assert abs(2 * panel["x"] + panel["width"] - (2 * out["x"] + out["logical_width"])) <= 1+ client.wait_for_frame(output=out["name"])+ sampled = client.action("sample_pixels", {"x": round((panel["x"] + panel["width"] // 2 - out["x"]) * float(scale)),+ "y": round((panel["y"] + 10 - out["y"]) * float(scale)), "width": 1, "height": 1, "output": out["name"]})+ assert sampled.get("SamplePixels", sampled)["pixels"][0] & 0xFFFFFF == 0x304050, (sampled, panel, out)+ if os.environ.get("REDIWM_LAUNCHER_PREVIEW") and scale == "1":+ Path(os.environ["REDIWM_LAUNCHER_PREVIEW"]).unlink(missing_ok=True)+ client.screenshot(path=os.environ["REDIWM_LAUNCHER_PREVIEW"], output=out["name"])+ toggle()+ client.wait_for("menu_closed", timeout_ms=5000)+ toggle()+ client.wait_for("menu_opened", timeout_ms=5000)+ client.move_cursor(8, 8, output=out["name"])+ client.pointer_button(272, True)+ client.pointer_button(272, False)+ client.wait_for("menu_closed", timeout_ms=5000)+ toggle()+ client.wait_for("menu_opened", timeout_ms=5000)+ client.type_text("no-such-application")+ assert any(w.get("label") == "No applications found" for w in widgets())+ client.key_down_up(1)+ client.wait_for("menu_closed", timeout_ms=5000)+ print(f"Launcher at scale {scale}: centered on second output, search, pins, launch, theme reload and dismissal")+ except Exception:+ print((tmp / "compositor.log").read_text())+ raise+ finally:+ stop_process(process)+ log.close()+ # Pins and recents survive a completely new compositor/catalogue.+ process, log = spawn_compositor(tmp, scale=scale, config_content=config, env_extra=env)+ try:+ with IPCClient(tmp) as client:+ client.wait_for("catalog_published", timeout_ms=10000)+ client.key(125, True)+ client.key_down_up(57)+ client.key(125, False)+ client.wait_for("menu_opened", timeout_ms=5000)+ if scale == "1":+ (tmp / "launched-3").unlink()+ card = next(w for w in client.get_widget_tree("start_menu")["widgets"] if w.get("name") == "recent_app")+ box = card["global_box"]+ client.move_cursor(box["x"] + box["width"] // 2, box["y"] + box["height"] // 2)+ client.pointer_button(272, True)+ client.pointer_button(272, False)+ client.wait_for("menu_closed", timeout_ms=5000)+ wait_for(lambda: (tmp / "launched-3").exists(), "saved pin did not remain first or card click failed")+ client.key(125, True)+ client.key_down_up(57)+ client.key(125, False)+ client.wait_for("menu_opened", timeout_ms=5000)+ client.type_text("Launcher App 3")+ pin = next(w for w in client.get_widget_tree("start_menu")["widgets"] if w.get("label") == "Unpin application")+ box = pin["global_box"]+ client.move_cursor(box["x"] + 10, box["y"] + 10)+ client.pointer_button(272, True)+ client.pointer_button(272, False)+ assert "P\tlauncher-3.desktop" not in (tmp / "state" / "rediwm" / "launcher").read_text()+ finally:+ stop_process(process)+ log.close()++if __name__ == "__main__":- run()- run_reopen()- run_selection()- run_highlight_reload()+ import sys+ if "--launcher-only" not in sys.argv:+ run()+ run_reopen()+ run_selection()+ run_highlight_reload()+ run_launcher()