diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 02:33:21 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-18 03:43:34 -0300 |
| commit | cf5f2d75ba24c02240044027b6de7b151e0ab9df (patch) | |
| tree | d296d5f5956ace420645766fa36b46646a3dd8e3 /src/gui | |
| parent | 7367335a64473d1f5522bdba71db2657b7fb2398 (diff) | |
| download | pardes-cf5f2d75ba24c02240044027b6de7b151e0ab9df.tar.gz pardes-cf5f2d75ba24c02240044027b6de7b151e0ab9df.zip | |
gui: a native Wayland window starts opaque, claimed by the GPU API, and is made again transparent, presenting through SDL_Renderer, at the first WindowOpacity under 100 (syncWindowOpacity: before the first frame when the startup file says it, a blink while running, a --detach session's window kept hidden), not transparent at every start whatever the opacity: at 100 no EGL and GL stack beside Vulkan and no slow first soft present; a real window (the user's Wayland display): the first present 28.7-41.2 ms -> 3.3-3.5 ms, instructions:u to the first frame 551M -> 520M (two runs each), exec to the end of the first frame 288 -> 249 ms best (load 0.9); WindowOpacity 70 in the startup file starts transparent (first present 28.6 ms, the soft path), and typed while running at 100 switches (a 45 ms present after it), no failure said; reference.typ says it
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 92117c19..c83b8209 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -540,6 +540,9 @@ const Gui = struct { /// What a window is opened again with (reopenWindow): the flags (not /// hidden), its size when it was closed (present keeps its present mode). win_flags: c.SDL_WindowFlags = 0, + /// A native Wayland window: transparent at the first WindowOpacity + /// under 100 (syncWindowOpacity). + wayland: bool = false, window_w: c_int = 1120, window_h: c_int = 720, /// The window runNative destroys at the end: the one open then, if any. @@ -819,11 +822,13 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di if (!test_mode) win_flags |= c.SDL_WINDOW_HIGH_PIXEL_DENSITY; // A test run renders to the capture texture; keep it off the desktop. if (test_mode) win_flags |= c.SDL_WINDOW_HIDDEN; + // Background-only opacity needs per-pixel alpha (whole-window compositor + // opacity would dim the text as well), so a transparent window, which + // the GPU API will not claim: it presents through SDL_Renderer, EGL and + // GL beside Vulkan, and its first present is slow. So a window starts + // opaque, and is made again transparent at the first WindowOpacity + // under 100 (syncWindowOpacity): SDL takes the flag only at creation. const native_wayland = !test_mode and std.mem.eql(u8, std.mem.span(c.SDL_GetCurrentVideoDriver()), "wayland"); - // Background-only opacity needs per-pixel alpha; whole-window compositor - // opacity would dim the text as well. SDL requires this flag at creation. - const surface_opacity = native_wayland; - if (surface_opacity) win_flags |= c.SDL_WINDOW_TRANSPARENT; const reopen_flags = win_flags; // `--detach`: a window never shown, closed once the session is up. if (detached) win_flags |= c.SDL_WINDOW_HIDDEN; @@ -851,7 +856,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di defer if (window_slot) |open| c.SDL_DestroyWindow(open); if (want_at) |at| _ = c.SDL_SetWindowPosition(window, at[0], at[1]); updateDisplayScale(window); - if (native_wayland) log.info("Wayland opacity: background-only transparent surface", .{}); // On Linux the desktop's own cursor theme draws them (the compositor's // cursor-shape protocol, else XCURSOR_THEME), at its size and scale: // the arrow is its default, acme's box its move, as the plan9 theme @@ -873,7 +877,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di if (arrow_cursor) |cur| { _ = c.SDL_SetCursor(cur); } else log.err("SDL_CreateCursor: {s}", .{c.SDL_GetError()}); - var presenter = try Present.init(window, test_mode, surface_opacity); + var presenter = try Present.init(window, test_mode, false); defer presenter.deinit(); font_allocator = gpa; @@ -938,6 +942,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di .demo = if (env.get("PARDES_FRAMES_DEMO")) |path| try pardes.FrameStats.readScript(init.arena.allocator(), init.io, path) else &.{}, .demo_next = if (env.get("PARDES_FRAMES_DEMO") != null) 0 else null, .win_flags = reopen_flags, + .wayland = native_wayland, .window_w = want_w, .window_h = want_h, .window_slot = &window_slot, @@ -3167,6 +3172,31 @@ fn finishWindowOpacity(core: *pardes.Pardes, applied: *u8, failure: ?[]const u8) fn syncWindowOpacity(g: *Gui, core: *pardes.Pardes) void { if (!core.settings.window_opacity_pending) return; + // The first opacity under 100 on Wayland: the window made again, + // transparent, presenting through SDL_Renderer from then on (the + // capture's format, the swapchain's, is one it uploads). At a start's + // own WindowOpacity this is before its first frame, so unseen. + const unorm = g.present.swapchain_format == c.SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM or g.present.swapchain_format == c.SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM; + if (g.wayland and !g.present.surface_opacity and core.settings.window_opacity < 100 and unorm) { + // A `--detach` session's window stays hidden. + const hidden = c.SDL_GetWindowFlags(g.window) & c.SDL_WINDOW_HIDDEN; + const mode = g.present.present_mode; + closeWindow(g); + g.present.soft_present = true; + g.present.surface_opacity = true; + g.present.present_mode = c.SDL_GPU_PRESENTMODE_VSYNC; + g.win_flags |= c.SDL_WINDOW_TRANSPARENT | hidden; + log.info("WindowOpacity under 100: the window made again, transparent, presenting through SDL_Renderer", .{}); + if (!reopenWindow(g)) { + // No renderer for it: opaque again, as it was. + g.present.soft_present = false; + g.present.surface_opacity = false; + g.present.present_mode = mode; + g.win_flags &= ~@as(c.SDL_WindowFlags, c.SDL_WINDOW_TRANSPARENT); + if (!reopenWindow(g)) core.quit = true; + } + g.win_flags &= ~hidden; + } // Offscreen captures also support per-pixel alpha. Never approximate this // with SDL_SetWindowOpacity: that would make foreground text translucent. finishWindowOpacity(core, &g.applied_window_opacity, if (g.present.surface_opacity or g.present.capture or core.settings.window_opacity == 100) |
