Native Wayland runtime backend
When built with --enable-wayland, libXm includes an optional XWayland-free
Wayland runtime backend that allows unmodified Xlib/Xt/Motif applications to
connect directly to a Wayland compositor (WAYLAND_DISPLAY) without running an
Xwayland or Xorg server.
Build configuration
Configure discovers the Wayland client stack automatically (--enable-wayland=auto,
the default on platforms providing the Wayland development packages; pass
--enable-wayland=yes to require it or --enable-wayland=no to disable it):
wayland-scanner(build-time protocol code generator)wayland-client >= 1.20andwayland-cursorwayland-protocols >= 1.31(xdg-shell,xdg-decoration-unstable-v1,xdg-toplevel-icon-v1,primary-selection-unstable-v1,text-input-unstable-v3,fractional-scale-v1,viewporter, plus optionallinux-dmabuf-v1,xdg-dialog-v1,tearing-control-v1, andfifo-v1when present in the installedwayland-protocolspackage)pixman-1,xkbcommon,freetype2, andfontconfig
On X11-only hosts (such as macOS with XQuartz), --enable-wayland=auto disables
the Wayland backend cleanly without changing any public headers or the
libXm.so.9 / libXm.9.dylib symbol ABI.
Runtime display selection
At library load time, libXm selects its transport as follows:
CK_MOTIF_BACKEND=x11(or0/off): always use standard X11 / XWayland (DISPLAY), disabling the Wayland backend.CK_MOTIF_BACKEND=wayland(or1): connect directly toWAYLAND_DISPLAYeven ifDISPLAYis also set in the environment.- Default (
CK_MOTIF_BACKENDunset orauto): ifWAYLAND_DISPLAYis set andDISPLAYis unset or empty,libXmactivates the native Wayland backend automatically. IfDISPLAYpoints to a real X11 or XWayland server, standard X11 transport remains active.
When active, each Motif process creates a private 0700 directory beneath
$XDG_RUNTIME_DIR (ck-wlx11-<pid>-XXXXXX/S:0) and serves an in-process X11r11
virtualizer backed directly by wayland-client. If a child Motif process
inherits a parent's ck-wlx11-* DISPLAY string, the child automatically
initializes its own independent Wayland connection and private runtime socket,
and exit cleanup only unlinks the socket owned by the creating PID.
libXm sets CK_MOTIF_WAYLAND_ACTIVE=1 and CK_MOTIF_WAYLAND_DISPLAY in the
process environment when the native Wayland backend is active.
Window management, menus, and rendering
- Top-level shells and modal dialogs:
ApplicationShell,TopLevelShell, andTransientShellwindows map toxdg_surface+xdg_toplevel, negotiating server-side decorations throughzxdg_decoration_manager_v1(honoring_MOTIF_WM_HINTS), transient parent linkage (resolvingWM_TRANSIENT_FORto the enclosing top-levelxdg_toplevel),xdg_wm_dialog_v1modal dialog state (xdg_dialog_v1.set_modal/unset_modaldriven by_MOTIF_WM_HINTSMWM_INPUT_*_MODALonXmDialogShelland_NET_WM_STATE_MODAL, destroyed cleanly beforexdg_toplevel.destroy), per-surface presentation extensions (wp_tearing_control_v1andwp_fifo_v1via<Xm/Wayland.h>or_MOTIF_WAYLAND_TEARING/_MOTIF_WAYLAND_FIFO), size bounds (WM_NORMAL_HINTS), UTF-8 titles (_NET_WM_NAME/WM_NAME),app_id(WM_CLASS), and dynamic ARGB window icons (xdg_toplevel_icon_v1built fromWM_HINTSicon pixmaps and masks). Post-mapxdg_surface.configureresizes coalesce to the latest pending size and synchronizexdg_surface.ack_configure+wl_surface.committhrough a main-threadXtAppAddWorkProc+XSyncbarrier after all childConfigureWindowandExposeredraws finish (withoutO(depth)recursiveExposeduplication across container levels), paired withVendorShellConfigureNotifyqueue compression so interactive drags never commit blank half-laid-out frames or rubber-band. - Menus and popups: Override-redirect menu shells (
XmMenuShellpulldowns, context menus, submenus, option menus, and tooltips—including callback-postedXmMenuPositionpopups andowner_events = Truepassive button grabs) map to constrainedxdg_popupsurfaces withxdg_positionerflip/slide/resize rules, livexdg_popup_repositionupdates when a sharedXmMenuShellmoves between menu-bar cascades or context-menu targets, root-coordinatepopup_stackhit-testing duringButton1press-drag traversal when Wayland's implicit button grab retains pointer focus on the parentxdg_toplevel, monotonic press/release event timestamps for sub-millisecond clicks, and LIFOxdg_popup_graboff-surface dismissal. - Rasterizer and typography: Subwindow clipping, X11-compliant
ChangeWindowAttributesbackground updates (preserving armed menu/button glyphs), classic 3D Motif bevels, pixmap tiles/stipples, andRENDER0.11 operations (Composite,Trapezoids,Triangles,TriStrip,TriFan,LinearGradient,RadialGradient, and glyph sets used bylibXft/HarfBuzz/FreeType, Cairo, and modern themes) composite into256 px-padded backing canvases and persistent quad-bufferedwl_shm_poolslots viapixman-1with tightpixman_region32_tper-slot buffer-age partial-damage copies and multi-rectwl_surface_damage_buffercommits,wl_surface_set_opaque_regionculling, lower-Z sibling uncover repainting acrossConfigureWindow/UnmapWindow, deduplicatedxdg_toplevelmetadata updates,pthread_atforkchild descriptor cleanup, and exact subwindow destination and first-vertexxSrc/ySrcalignment. ShapedA8,A4, andA1GlyphSetmasks pack into refcounted512x512A8shelf-packed glyph-atlas pages shared acrossRenderReferenceGlyphSethandles (with per-IDRenderFreeGlyphseviction and batched per-string damage bounds), while solid/translucentPictOpOver/GXcopyspan fills (used by modern rounded/translucent bevels),A8glyph-atlas blits, and non-overlappingCopyAreabuffered-paint (_XmBufferedPaint) backbuffer transfers accelerate via bit-exact ARM NEON and x86 AVX2/SSE2 SIMD fast paths. Legacy core X11 font requests (OpenFont,QueryFont,ListFonts,ListFontsWithInfo,PolyText8/16,ImageText8/16) expose scalable and multi-size XLFDs across standard Latin-1 and Unicode families and rasterize directly through Fontconfig and FreeType without server-side PCF/BDF font paths.RANDR1.5 output/CRTC/property queries and compositor IPC helper windows (wm_helperandsm_helper) allow desktop control panels and session managers to operate withoutXwayland.
Clipboard, drag-and-drop, input methods, and scaling
- Selections:
CLIPBOARD(wl_data_device) andPRIMARY(zwp_primary_selection_v1) synchronize bidirectionally between Motif widgets and external Wayland clients acrossUTF8_STRING,STRING,TEXT,text/plain;charset=utf-8,text/plain,text/uri-list, andimage/png. - Drag-and-drop: Outgoing
XmDragStartoperations initiate nativewl_data_device_start_dragsessions with persistent cursor-attachedXmDragOverShelldrag-icon surfaces (supporting both 24/32-bit pixmap icons and 1-bitXmDragIconcursor bitmaps withPictStandardA1/PictStandardA8masks, hotspot offsets, and empty pointer input regions so underlying drop targets remain directly hit-testable); incomingwl_data_devicedrags bridge through XDND v5 to registeredXmDropSitewidgets. - Input methods:
XmImbindszwp_text_input_v3forXmTextandXmTextFieldwithout requiring an XIM server, forwarding cursor spot rectangles and applying preedit spans, surrounding-text deletions, and UTF-8 commits on theXtmain loop. - Pointer hover-wheel,
wp-cursor-shape-v1, &wl_touchinput:wl_seatbinds up to v9 (axis_value120high-resolution wheel and touchpad scroll axes),wp_cursor_shape_manager_v1(mapping standardXCreateFontCursor/XC_*glyph cursors to crisp server-sidewp_cursor_shape_device_v1shapes across HiDPI outputs while uploading customCreateCursor/RenderCreateCursorbitmap cursors overwl_pointer.set_cursor), andwl_touch(translating single-finger taps and drags intoButton1widget interaction and two-finger panning into continuous smooth scrolling). Wheel and touch-pan events route directly to the deepest widget under the contact point without movingXmEXPLICITkeyboard focus or firingAnyButtonpopup-menu passive grabs. When smooth scrolling is enabled (*mouseWheelSmooth: True, the default), an ~83 Hz main-thread interpolator drives sub-line / pixel steps acrossXmScrolledWindow,XmScrollBar,XmList,XmText,XmTreeView, andXmDataGrid(including sub-row vertical and horizontal pixel offsets inXmDataGridwith sticky header clipping) with zero speed cap, touchpad finger-flick (WL_POINTER_AXIS_SOURCE_FINGER+wl_pointer.axis_stop) exponential kinetic momentum coasting, instant direction reversal, and clean start/end clamping, scaling dynamically with*mouseWheelSpeed(1..10, default3) and live_DT_WAYLAND_WHEELcompositor IPC updates. On X11, XLibre, and XWayland displays,libXmalso binds XInput2 (2.1+)XIScrollClassInfovertical and horizontal smooth-scroll valuators onXI_Motionwhile suppressing duplicate server-synthesizedXIPointerEmulatedlegacy wheel ticks. - Focus activation and startup tokens (
xdg_activation_v1):libXmcaptures and unsetsXDG_ACTIVATION_TOKEN(orDESKTOP_STARTUP_ID) uponXmDisplayattachment or initial top-level creation—preserving the token for non-GUI launchers that linklibXmbeforeexecwhile ensuring forked GUI helpers never inherit a used one-shot token—then submitsxdg_activation_v1.activateon the application's primaryxdg_toplevelcommit. X11_NET_ACTIVE_WINDOWClientMessagerequests sent to the virtual root window automatically mint and redeem a fresh activation token for the target Motif shell. - Fractional and HiDPI scaling: On compositors that advertise per-output
physical geometry and
DPIover native session IPC (CLIENT_CAP native_dpi),libXmrenders widgets, FreeType/Xft glyphs, 96-DPI catalog XLFD fonts, and scaled icons/masks (XmGetScaledPixmap/XmeGetScaledMask) directly onto1:1integer physicalwl_shmpixels withoutwp_viewportresampling, exposing per-monitor CRTC bounds and"DPI"(XA_INTEGER, format32) properties via virtualRANDR1.5 (_MOTIF_RANDR_OUTPUT_DPI = 1) and tracking authoritative compositor surface coordinates (SURFACE_POS) as well as complete multi-outputwl_surface.enter/wl_surface.leaveoverlap sets so top-level shells reflow smoothly across mixed-DPI outputs without straddle bounce. On other Wayland compositors,wp_fractional_scale_v1, per-surfacewl_output.scaletracking, andwp_viewportersize physicalwl_shmbuffers and embeddedXmWaylandGetWidgetSurfacesubsurface scale factors while preserving 96-DPI Wayland logical coordinates solibXftglyphs are never double-scaled inside logical widget boxes. Explicit toolkit logical zoom (CK_MOTIF_WAYLAND_SCALE) drivesXmSetDisplayScaleOverrideandRANDRscreen-change notifications so realized widgets reflow live across zoom changes.
Subsurface embedding API (<Xm/Wayland.h>)
Applications that embed external Wayland buffers or off-screen renderers (such
as media players or off-screen web views) inside a Motif widget can include
<Xm/Wayland.h>:
XmWaylandIsActive(Display *)reports whetherdisplayis backed bylibXm's native Wayland runtime.XmWaylandLock(Display *)andXmWaylandUnlock(Display *)serialize directlibwayland-clientrequests onlibXm'swl_displayconnection.XmWaylandGetDisplayHandles(...)returns the activewl_display,wl_compositor,wl_subcompositor,wl_shm, andwp_viewporterglobals.XmWaylandGetWidgetSurface(widget, &top_surface, &x, &y, &w, &h, &scale)resolves a realized widget's enclosing top-levelwl_surfacetogether with its logical bounds and scale factor so the caller can attach awl_subsurfacewith an empty input region (wl_surface_set_input_region) while preserving Motif pointer, wheel, focus, popup-menu, andzwp_text_input_v3routing.XmWaylandGetDmabuf(display, &dmabuf, &version),XmWaylandHasDmabufFormat(display, drm_format, modifier), andXmWaylandImportDmabuf(display, planes, plane_count, width, height, drm_format, flags, &wl_buffer)negotiatezwp_linux_dmabuf_v1(including v4default_feedbackformat/modifier tranche tables) and import 1..4DMA-BUFplanes into a zero-copywl_buffer *viazwp_linux_buffer_params_v1.create_immedfor embeddedwl_subsurfacevideo, image, and WebGL presentation without CPUwl_shmreadback.XmWaylandSetSurfaceTearingHint(display, surface, async_tearing),XmWaylandSetSurfaceFifo(display, surface, set_barrier, wait_barrier),XmWaylandSetSurfaceHdrMetadata(display, surface, &hdr_metadata), andXmWaylandReleaseSurfaceExtensions(display, surface)manage deduplicated per-surfacewp_tearing_control_v1,wp_fifo_v1, andwp_color_management_surface_v1(BT.2020 PQ,HLG,Display-P3,sRGB, mastering display primaries/luminance,MaxCLL, andMaxFALL) objects for top-level or embeddedwl_subsurfacesurfaces without protocol object-duplication or teardown ordering errors.- Top-level Motif shells automatically publish
xdg_toplevel_icon_v1multi-scale squarewl_shmARGB8888buffers (1xand2x) from both multi-frame_NET_WM_ICONproperties andWM_HINTS(XmNiconPixmap/XmNiconMask), optional XDG stock icon names (_MOTIF_XDG_ICON_NAME), andNULLresets when icons are cleared, while transient session IPC atoms (_DT_WM_REQUEST,_DT_STYLE_DISPLAY_IPC,*_IPC,*_CMD,PROP_QUEUE) use bounded append-queue semantics so concurrent unbatched IPC writers never overwrite unread payloads. XmWaylandRequestActivationToken(display, source_window, app_id, &token)mints a one-shotxdg_activation_v1token seeded withlibXm's latest button/keypress serial, source top-levelwl_surface, and optional targetapp_idhint (free*tokenwithXtFree()), allowing launchers, file managers, and mail clients to hand focus cleanly to child Wayland processes.- Applications that still prefer X11/XWayland when a real X11
DISPLAYis present may defineconst int ck_motif_prefer_x11 = 1;so library-load auto-selection keeps X11 even whenCK_MOTIF_BACKEND=waylandis set in the environment, while still activating the native Wayland backend in pure XWayland-free (DISPLAYunset) sessions.
On X11, XWayland, macOS, and --disable-wayland builds, these entry points
remain present in libXm and safely return False.
Qualification
Run the automated Wayland backend suite against a built tree or staged prefix:
python3 tests/automated/run-wayland-backend.py \
--prefix /path/to/motif-prefix \
--out /path/to/scratch/wayland-backend-results
For sanitizer-instrumented prefixes (--enable-sanitizers=address,undefined or
--enable-sanitizers=thread), pass --sanitizers address,undefined or
--sanitizers thread so the test client links with the matching sanitizer
runtime. Request parsing in lib/Xm/WaylandX11Server.c and software XRender/core
drawing in lib/Xm/WaylandRender.c are also covered by the standalone
libFuzzer target fuzz-wayland-x11-server (python3 tests/fuzz/run-fuzz.py --target wayland-x11-server).
The runner starts an isolated headless Wayland compositor with DISPLAY unset,
verifies that no Xwayland instance is used for the client, and validates
shell mapping, classic and modern theme rendering, Unicode/CJK text rasterization,
cached core X11 XLFD OpenFont/QueryFont/PolyText8 rendering, XA_STRING
_SUN_TT_SESSION root-property seeding, xdg_popup menus, Wayland clipboard
and drag-and-drop transfers, zwp_text_input_v3 composition, rapid
xdg_toplevel.configure resize-burst coalescing, live scale reflow, and
child-process socket isolation.
CK Core Motif