Repository navigation
Description
Problem
On Linux, Rune's GUI only speaks X11. Our ebiten fork
(github.com/unstablebuild/ebiten/v2, currently v2.7.5-ub.32) vendors GLFW
3.3.8 and compiles only its X11 platform (internal/glfw/build_linux.go
defines _GLFW_X11). On a Wayland session Rune always runs as an XWayland
client, and inherits XWayland's limits:
- Scaling. X11 has no per-window scale; GLFW reads one global
Xft.dpi.
On fractional-scale monitors the compositor stretches Rune's 1x buffer,
which blurs text (Blurry text rendering with non-integer monitor scaling under hyprland #55). A move to a monitor with a different scale can't be
detected. - Input goes through the X server: layouts through XKB groups, text
through XIM, and the scroll wheel as discrete button clicks. - Dependency. The GUI doesn't start without XWayland installed.
Blurry fractional scaling is the most visible symptom, but fixing it means
adding a Wayland platform to the fork and making Rune's GUI layer work with
it. This issue scopes that work.
Upstream context. ebiten had an opt-in -tags=wayland build on GLFW 3.3
and removed it in v2.6 because GLFW 3.3's Wayland port was incomplete
(hajimehoshi/ebiten#2759). Bringing it back is tracked in
hajimehoshi/ebiten#2762, blocked on rewriting GLFW in Go. GLFW 3.4 fills most
of the 3.3 gaps: runtime platform selection (one binary for X11 and Wayland),
dynamic loading of all Wayland libraries, fractional scaling, libdecor
decorations, xkbcommon key names, file drop, glfwFocusWindow, and an
app_id hint.
Proposed behavior
- One Linux binary. When
WAYLAND_DISPLAYis set, the GUI runs as a native
Wayland client; otherwise it uses X11 as today. - An override (e.g.
RUNE_GUI_BACKEND=x11|wayland) forces either platform,
for compositors with incomplete protocol support. --tuiand--headlesskeep starting on machines with no graphics
libraries: no new load-time (DT_NEEDED) dependencies.- Feature parity with X11, except where Wayland forbids it (window position).
Those features are disabled cleanly instead of failing or hanging.
Scope
1. Platform layer (ebiten fork)
-
Upgrade the vendored GLFW from 3.3.8 to 3.4 and build X11 and Wayland
together with runtime selection (GLFW_PLATFORM). Rebase the fork's
GLFW patches: keyboard-layout translation, input source attribution,
backported cursor shapes, dlopened Xlib. -
Commit the
wayland-scanneroutput for the protocols GLFW uses; cgo
can't run the scanner. -
Keep every Wayland library dlopened (
libwayland-client,-cursor,
-egl,libxkbcommon,libdecor), as Xlib is today
(x11_dynamic_linbsd.c). CI asserts the binary needs only glibc at load
time (.github/workflows/test-linux.yml). -
Add a symbol-table test for the Wayland libraries next to the X11 one
CI already runs. -
Startup blocker: guard every window-position call. On Wayland,
GLFW 3.4 answersglfwGetWindowPos/glfwSetWindowPoswith
GLFW_FEATURE_UNAVAILABLE, but the fork'sGetPos/SetPoswrappers
only ignorePlatformError(internal/glfw/window_unix.go,
error_unix.go), so the error propagates:
-createWindowcallsSetPosviasetWindowPositionInDIP
(internal/ui/ui_glfw.go), so the window never opens. Initial
centering callsSetPostoo.
-currentMonitorfalls back toGetPosbecause
monitorFromWindowByOSis a stub on Linux. It runs every frame via
outsideSizeand cursor input (input_glfw.go).
- Fullscreen save/restore andWindowPosition()also call it.Skip these calls when `glfwGetPlatform()` is Wayland, and have `WindowPosition()` return 0,0 without calling GLFW. Use explicit platform checks rather than swallowing the error, so real errors still surface. Add GLFW 3.4's new error codes to `internal/glfw/const.go`. -
Monitor detection. Gate the X11-only code in
internal/ui/ui_linbsd.goon the active platform.
glfwMonitorSizeInGLFWPixels(RandR) andinitialMonitorByOS
(QueryPointer) open their own X connection, so in a Wayland session
they succeed through XWayland and return wrong answers: a stale pointer
position, and RandR outputs matched by a monitor position that wlroots
reports as 0,0 for every output. Instead:
-initialMonitorByOSreturns nil on Wayland (the compositor places the
window; use the primary monitor until it lands).
- ImplementmonitorFromWindowByOSwith a small C accessor for the
output the surface last entered. GLFW already tracks this
(window->wl.outputScales, filled insurfaceHandleEnter), so
currentMonitornever needs a position.
- The monitor-changed callback is driven by window moves
(registerWindowPosCallback), which Wayland never reports. Drive it
from surface enter instead. -
Coordinates and monitor size. On Linux,
dipFromGLFWPixel/
dipToGLFWPixelscale by the device scale because X11 window
coordinates are physical pixels. On Wayland they are logical, so make
them identity there, as on macOS. GLFW 3.4 only knows a monitor's video
mode (physical) and integerwl_output.scale, soMonitor.Size()is
wrong at fractional scales. Addzxdg_output_manager_v1to get each
output's logical size. -
Revisit the
WAYLAND_DISPLAYcheck ininternal/ui/ui_glfw.gothat
forces the window visible; today it also fires under XWayland.
2. Rendering, frame pacing and scaling
- Load GL functions through GLFW. On Wayland, GLFW creates the context
with EGL, butinternal/graphicsdriver/opengl/gl/procaddr_linbsd.go
resolves every function throughglXGetProcAddress. That probably
works with libglvnd's shared dispatch, but neither spec guarantees it,
and loadinglibGL.so.1pulls in libGLX and libX11.
- Passglfw.GetProcAddress(internal/glfw/context_unix.go) into the
glpackage fromgraphics_glfw.go.glcan't importglfw
becauseprocaddr_linbsd.goalso builds for Android. GLFW then
resolves through GLX or EGL, whichever made the context.
- TrylibOpenGL.so.0(no X11 dependency) beforelibGL.so.1, then
GLES.
-EBITENGINE_OPENGL=esalready forces the EGL + GLES path for
testing. - Pick an EGL config with alpha for transparent windows
(gui.enable_transparent_window). - Verify event-driven frames. Rune runs
FPSModeVsyncOffMinimum, which
blocks inglfw.WaitEvents()and wakes onglfw.PostEmptyEvent()from
ScheduleFrame(internal/ui/ui_glfw.go). On Wayland the wait must also
wake for client-side key repeat, andeglSwapBuffersmust not block on
frame callbacks while the window is hidden. - Render at the exact output scale, including fractional scales
(wp_fractional_scale_v1+wp_viewporter, in GLFW 3.4). - Take the device scale from the window, not the monitor. ebiten caches
one scale per monitor (internal/ui/monitor_glfw.go, TODO for
Detect dynamic device scale factor changes hajimehoshi/ebiten#2343), but on Wayland the monitor only reports the integer
wl_output.scale; the fractional scale is per window. On Wayland, read
glfwGetWindowContentScale, and wireSetContentScaleCallback
(internal/glfw/window_unix.go, currently unused) to the
monitor-changed callback so Rune reloads its font when the surface
enters an output with a different scale. - Rune: implement
ebiten.LayoutFerinGUI
(internal/term/gui/gui.go).Layoutreceives the logical size
truncated to an int, so at non-integer scales the frame is up to 1px
smaller than the screen and ebiten stretches it with a linear filter
(about 64% of window sizes at scale 1.25). This already affects X11 with
Xft.dpiand Windows at 125%/150%, so it can land first.
3. Input
- Port the fork's keyboard-layout translation
(_glfwPlatformGetScancodeCodepoint, XKB group tracking) to
xkbcommon. Without itInputEvent.Charis 0 and Rune falls back to US
key positions (internal/term/gui/input.go), so Ctrl/Alt/Super chords
are wrong on non-US layouts. - Attribute text commits to their key action (
InputEvent.Source) and
classifyNormalTextas the X11 path does (text typed with Ctrl or Alt
held isn't normal text). Rune dedupes chord text by source, so commits
with no source insert chord text twice.input_test.goencodes the X11
cases. - Key repeat is synthesized by the client on Wayland. Repeats must reach
Rune asKeyActionRepeatwith fresh sources and repeated text. - Dead keys and compose through xkbcommon-compose.
- Scrolling: Wayland sends continuous axis values (and
axis_value120
for wheels) instead of discrete clicks. Check direction and per-notch
magnitude against X11, and tune the wheel accumulator
(internal/term/gui/mouse.go) for trackpads. - Cursor shapes:
initializeGLFWfails if any standard cursor can't be
created (internal/ui/ui_glfw.go), including the fork's backported
resize, move and not-allowed shapes. Make sure they all resolve from the
cursor theme, or degrade. - File drop and drag position via
wl_data_device. Rune's drop
targeting uses bothebiten.DroppedFilePathsand
ebiten.DraggingPosition(internal/term/gui/drag.go).
4. Windowing
- Rune: window position doesn't exist on Wayland (see the fork-side
guards in section 1, and Console spam under Wayland hajimehoshi/ebiten#1873 for the GLFW 3.3
equivalent). SkipSetWindowPositionat startup (gui.go), don't save
a position on exit (gui.go,cmd/rune/storage.go), and make
guiposition(cmd/rune/commands.go) return an error. - Minimize must not hang.
iconifyWindowpolls untilGLFW_ICONIFIEDis
true (internal/ui/ui_glfw.go), but xdg-shell can't report the
minimized state, soguiminimizewould spin forever.maximizeWindow
polls the same way, and a tiling compositor may never maximize. Disabling this
command is an option, thus delegating minimizing to the OS wm. - Initial size: on first launch Rune sizes the window from
ebiten.Monitor().Size()(gui.go). Before its first configure, a
Wayland client doesn't know its output; pick a sane default. - Decorations: Rune sets
DecorationsButtonsOnly. Use server-side
decorations via xdg-decoration where offered, and libdecor otherwise
(GNOME has no server-side decorations). - Set
app_idtoruneso the window groups withrune.desktopand
gets its icon. Today only WM_CLASS is set (x11WMClassingui.go);
StartupWMClasshas no effect on Wayland. - Activation via
xdg_activation_v1. Check whether the window should
consumeXDG_ACTIVATION_TOKEN, whichsetEnvForGUI(cmd/rune/env.go)
currently unsets.
5. Packaging and CI
- Release tarball: built on
debian:buster-slimwith X11/GL headers only
(deploy/rune-linux/Dockerfile). Add the Wayland and xkbcommon headers
(or vendor them in the fork). Add the Wayland libraries to the bundling
skip lists there and inmake-release-linux(cmd/rune/Makefile) so
they're never shipped. - Debian: add the Wayland runtime libraries to Recommends. Update the
"X11 and OpenGL support is required" description and the man page
(dist/debian). - Arch: add the runtime libraries to
optdependsand regenerate
.SRCINFO(dist/arch). - CI: unit and e2e tests run under
xvfb-run, whereWAYLAND_DISPLAYis
unset, so they keep covering X11. Add a headless Wayland job (e.g.
weston --backend=headlessor headless sway) that opens a window, types
on a non-US layout, and checks rendering at scale 1.25. - Port the fork's keyboard-layout e2e test
(internal/glfw/layout_linbsd_e2e_test.go, Xvfb +setxkbmap) to
Wayland. - Make
extra/diag/rune-glx-diag.shreport the active platform and EGL.
6. Docs
-
intro.md("Wayland via XWayland"),develop/building.md(the
XWayland requirement and "The window fails to open on a Wayland
session"), andtroubleshoot.md. - Document HiDPI and fractional scaling, including
gui.dpi, which is
undocumented today.
Suggested phasing
- Layout rounding fix in Rune. Independent, and fixes X11 with
Xft.dpi
and Windows today. - GLFW 3.4 upgrade in the fork, X11 only. No behavior change; rebases the
fork patches with X11 CI still green. - Wayland behind the override: platform layer, rendering, windowing
hazards. - Input parity: layout translation, sources, repeat, scrolling, file
drop. - Packaging, CI and docs, then make Wayland the default when
WAYLAND_DISPLAYis set.
Out of scope (follow-ups)
- IME preedit and candidate positioning via
zwp_text_input_v3. GLFW doesn't
support it, and Rune has no IME caret API today. - Background blur. It's a no-op on Linux today, and
guibluralready errors
outside macOS. - In-process clipboard. Rune shells out to
wl-copy/wl-pasteon Wayland
(internal/text/system_clipboard.go), which keeps working. - A file chooser through xdg-desktop-portal (
openpanelis a no-op on Linux).
Area
GUI and rendering
Alternatives considered
- Stay on XWayland and document compositor settings
(xwayland:force_zero_scalingplusgui.dpi). This works around Blurry text rendering with non-integer monitor scaling under hyprland #55
today, but the setting is compositor-wide and manual, and it doesn't handle
per-monitor scale or input. - Wait for upstream ebiten (support native Wayland again hajimehoshi/ebiten#2762). It depends on a Go
rewrite of GLFW with no timeline, and our fork carries input and frame
pacing changes Rune depends on. - Integer scale only (render at 2x, compositor downsamples to 1.25x).
Softer than native and costs more memory and fill, while GLFW 3.4 already
supports fractional scaling.
Additional context
- Blurry text rendering with non-integer monitor scaling under hyprland #55: blurry text at scale 1.25 on Hyprland.
- internal/cglfw: remove native Wayland support temporarily hajimehoshi/ebiten#2759 (Wayland removed), support native Wayland again hajimehoshi/ebiten#2762 (bring
it back), Console spam under Wayland hajimehoshi/ebiten#1873 (window-position error spam on Wayland). - GLFW 3.4 changelog, Wayland entries:
https://github.com/glfw/glfw/blob/3.4/README.md
Activity
Spandan-Mishra commentedon Sep 26, 2026
i'd like to work on this issue. should i create one PR per scope or one per checklist item?
i think one monolith PR would take a lot of time & effort to review @ernestrc