Skip to content

Add native Wayland backend #144

Open

Description

@ernestrc

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_DISPLAY is 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.
  • --tui and --headless keep 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-scanner output 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 answers glfwGetWindowPos / glfwSetWindowPos with
    GLFW_FEATURE_UNAVAILABLE, but the fork's GetPos/SetPos wrappers
    only ignore PlatformError (internal/glfw/window_unix.go,
    error_unix.go), so the error propagates:
    - createWindow calls SetPos via setWindowPositionInDIP
    (internal/ui/ui_glfw.go), so the window never opens. Initial
    centering calls SetPos too.
    - currentMonitor falls back to GetPos because
    monitorFromWindowByOS is a stub on Linux. It runs every frame via
    outsideSize and cursor input (input_glfw.go).
    - Fullscreen save/restore and WindowPosition() 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.go on the active platform.
    glfwMonitorSizeInGLFWPixels (RandR) and initialMonitorByOS
    (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:
    - initialMonitorByOS returns nil on Wayland (the compositor places the
    window; use the primary monitor until it lands).
    - Implement monitorFromWindowByOS with a small C accessor for the
    output the surface last entered. GLFW already tracks this
    (window->wl.outputScales, filled in surfaceHandleEnter), so
    currentMonitor never 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 /
    dipToGLFWPixel scale 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 integer wl_output.scale, so Monitor.Size() is
    wrong at fractional scales. Add zxdg_output_manager_v1 to get each
    output's logical size.

  • Revisit the WAYLAND_DISPLAY check in internal/ui/ui_glfw.go that
    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, but internal/graphicsdriver/opengl/gl/procaddr_linbsd.go
    resolves every function through glXGetProcAddress. That probably
    works with libglvnd's shared dispatch, but neither spec guarantees it,
    and loading libGL.so.1 pulls in libGLX and libX11.
    - Pass glfw.GetProcAddress (internal/glfw/context_unix.go) into the
    gl package from graphics_glfw.go. gl can't import glfw
    because procaddr_linbsd.go also builds for Android. GLFW then
    resolves through GLX or EGL, whichever made the context.
    - Try libOpenGL.so.0 (no X11 dependency) before libGL.so.1, then
    GLES.
    - EBITENGINE_OPENGL=es already 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 in glfw.WaitEvents() and wakes on glfw.PostEmptyEvent() from
    ScheduleFrame (internal/ui/ui_glfw.go). On Wayland the wait must also
    wake for client-side key repeat, and eglSwapBuffers must 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 wire SetContentScaleCallback
    (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.LayoutFer in GUI
    (internal/term/gui/gui.go). Layout receives 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.dpi and 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 it InputEvent.Char is 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
    classify NormalText as 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.go encodes the X11
    cases.
  • Key repeat is synthesized by the client on Wayland. Repeats must reach
    Rune as KeyActionRepeat with 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: initializeGLFW fails 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 both ebiten.DroppedFilePaths and
    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). Skip SetWindowPosition at 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. iconifyWindow polls until GLFW_ICONIFIED is
    true (internal/ui/ui_glfw.go), but xdg-shell can't report the
    minimized state, so guiminimize would 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_id to rune so the window groups with rune.desktop and
    gets its icon. Today only WM_CLASS is set (x11WMClass in gui.go);
    StartupWMClass has no effect on Wayland.
  • Activation via xdg_activation_v1. Check whether the window should
    consume XDG_ACTIVATION_TOKEN, which setEnvForGUI (cmd/rune/env.go)
    currently unsets.

5. Packaging and CI

  • Release tarball: built on debian:buster-slim with 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 in make-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 optdepends and regenerate
    .SRCINFO (dist/arch).
  • CI: unit and e2e tests run under xvfb-run, where WAYLAND_DISPLAY is
    unset, so they keep covering X11. Add a headless Wayland job (e.g.
    weston --backend=headless or 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.sh report 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"), and troubleshoot.md.
  • Document HiDPI and fractional scaling, including gui.dpi, which is
    undocumented today.

Suggested phasing

  1. Layout rounding fix in Rune. Independent, and fixes X11 with Xft.dpi
    and Windows today.
  2. GLFW 3.4 upgrade in the fork, X11 only. No behavior change; rebases the
    fork patches with X11 CI still green.
  3. Wayland behind the override: platform layer, rendering, windowing
    hazards.
  4. Input parity: layout translation, sources, repeat, scrolling, file
    drop.
  5. Packaging, CI and docs, then make Wayland the default when
    WAYLAND_DISPLAY is 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 guiblur already errors
    outside macOS.
  • In-process clipboard. Rune shells out to wl-copy/wl-paste on Wayland
    (internal/text/system_clipboard.go), which keeps working.
  • A file chooser through xdg-desktop-portal (openpanel is a no-op on Linux).

Area

GUI and rendering

Alternatives considered

  • Stay on XWayland and document compositor settings
    (xwayland:force_zero_scaling plus gui.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

Activity

  1. added
    enhancement
    on Sep 25, 2026
  2. added
    help wanted
    on Sep 25, 2026
  3. Spandan-Mishra commented on Sep 26, 2026

    @Spandan-Mishra
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions