GSoC Idea: Tk Backend for the Wayland Display Protocol

Wayland Backend for Tk

Areas Tk
Good if student knows C, X11
Priority Low
Difficulty Hard
Benefits to the student Learning to read a large code base, and tease it apart
Benefits to Tcl ???
Mentor Mentor's name/link

Project Description

Initial Ideas

   I. Create a proof-of-concept for Tk running directly on the Wayland display protocol

   http://wayland.freedesktop.org/

References

  • See TkGS for an older attempt at reworking the underpinnings of Tk.
  • See this source code for how to actually get a working drawing surface with Wayland. Pay particular attention to the snippet including wl_egl_window_create and eglCreateWindowSurface…

Comments & Discussion

PYK 2014-09-11: Would Tk perhaps get more mileage out of targeting SDL?

DKF 2014-09-11: Only if SDL has been ported to run on top of Wayland. (Googling indicates that experimental support is in SDL 2.0.2, but I don't know what that implies…)

chw 2017-01-11: The trunk of the fossil repository of http://www.androwish.org now provides Wayland support in undroidwish based on a modified version of SDL 2.0.5, which was tested successfully on the GNOME based Fedora 25 workstation. A self contained experimental undroidwish for x86_64 Linux with the Wayland and X11 drivers can be downloaded from http://www.ch-werner.de/AndroWish/undroidwish-wayland-linux64


dther - 2025-09-12 01:46:47

A missing Wayland back-end for Tk is the only real reason I don't want to leave X11. Xwayland is a fine solution, but has weird implementation greebles like the clipboard ceasing to exist once the last X application exits (see Clipboard on Wayland).

The issue preventing one from existing is that the Wayland protocol is just that, merely a protocol. Where X11 standardises much of what should be considered "basic desktop functions" like keyboard/mouse events, window decorations or sizing hints, Wayland leaves all of that to the discretion of the "compositor". In the context of Wayland fills the role of display compositor, window manager, IPC coordinator and default widget system plus styling hint database, all in one. Wayland promises a drawable surface and little more. I don't think it even promises that the surface maps linearly to 2D space, which affords creative uses like Simula's VR window manager.

Given that it's well proven that Tk on Wayland is at least possible thanks to Androwish and SDL, I wonder if the ideal "Tk backend" is something resembling a specialised xwayland server: a long-running process that provides Tk as a first-class widget system to more minimal compositors, much like how GTK could be considered a component of the GNOME desktop.


kevin_walzer - 2026-07-13 01:39:44

A full port of Tk to Wayland is under way in 2026 in the wayland branch. The port makes use of GLFW for windowing operations (GLFW has a mature Wayland back end) and NanoVG for 2-D drawing operations and font management. Clipboard integration is managed through the wl-clipboard toolset. Accessibility, system tray, and input methods are managed over D-Bus via the sd-bus library. As of July 2026 the port is in a pre-alpha stage and is not yet ready for testing, but steady progress is being made. The Tcl Core Team is targeting 9.2 for release of the Wayland port and will send out an invitation for testing and feedback when things are stable enough.


pounceandmiss - 2026-10-19 17:39:42

I had Claude generate Wayland and Android ports of Tk almost autonomously in a few hours. The demo seems to run with no significant issues on both platforms. I had Claude look at kevin_walzer's work and it judged against the approach. The ports don't use GLFW or SDL - they utilizes an approach more similar to the macOS port - emulating x11 to a limited but larger extent, with the emulation being done through a common layer. The Wayland port also supports client side decorations for good measure, even with rounded corners. There's also generic on-screen keyboard and gestures support in the same tree, so it's usable on a touchscreen.

Video of android: https://imgur.com/a/5ry1nZz Fossil bundle: https://x0.at/tk-ports_hAZq.bundle Full fossil repo: https://x0.at/tk-ports_Pht0.fossil https://i.imgur.com/3uRJIhn.png


pounceandmiss - 2026-10-30 19:25:12

The port is now good enough to run Tkabber on Wayland natively. Even threw in a small patch to show off CSD - but that's optional, it doesn't need a patch. Github repo: https://github.com/pounceandmiss/tk-wayland/ https://i.postimg.cc/WsSLjDPS/Screenshot-2026-10-30-10-34-15.png


pounceandmiss - 2026-11-06 20:26:33

Benchmark of Claude's port (Cairo, [L1 ], android 22cce92aba) vs. the human port (GPU, wayland a51d3cd70c), 2026-11-06, headless weston on a ThinkPad, both at 96 dpi. Mixed results: Claude's port wins on most things and uses a third of the memory, but loses on images, large shapes and plain-text scrolling.

TestClaude msHuman msFaster
label (text of a label changes)0.0370.142Claude 3.8x
typing (one char into a text)2.472.54same
text_scroll (5000 lines)0.950.56Human 1.7x
complex_scroll (Arabic, Devanagari)0.852.39Claude 2.8x
canvas_move (10000 rectangles)28.5352.2Claude 12.4x
canvas_text (2000 text items)20.338.8Claude 1.9x
canvas_shapes (40 large ovals, lines)4.112.78Human 1.5x
photo (800x600, partly redrawn)3.491.55Human 2.2x
photo_full (zoomed 1000x700 photo)10.874.41Human 2.5x
resize (300 ttk widgets)32.0181.7Claude 5.7x
Memory (RSS)97 MB281 MBClaude 2.9x
Startup347-362 ms518-546 msClaude 1.5x

Benchmark script: [L2 ]


pounceandmiss - 2026-11-19 07:52:38

And here's Tk running natively on Haiku using the same xemu core as Wayland and Android, no xlibe or sdl involved. https://i.ibb.co/DD0sm139/tkabber1.png


kevin_walzer - 2026-11-19 17:12:20

It's an interesting project, and if it had been around a year ago, I would have wanted to use this as the basis of the Tk Wayland port (minus the Android part). We started from scratch because there was a need and there was nothing, at all, in the pipeline. The Wayland-all-the-way-down design is the most impressive part - we chose GLFW as the primary interface to Wayland because writing a full Wayland back end seemed too large a task. However, Cairo is a very heavy external dependency that appears to have been chosen by Claude because it's the most widely used 2D library on Linux, not because it is the optimal one. Also, the strong dependency not just on X11's API but its actual code seems to me to be misguided. The official Wayland port will continue to evolve even if the X11 port becomes unmaintained or even removed from Tk if no distributions support X11 in the future. Finally, the official Wayland port has had hundreds of hours of actual user testing in the widget demo, complex Tk apps, and other tasks to help refine the implementation and the user experience, and also, to iterate on the design - we chose to implement menus and popups as wl_subsurfaces, and they work better than xdg_popup in our view. So while the Claude port has impressive benchmarks, it's a bit rough around the edges - not surprising, given that it hasn't had those months and months of actual human users poking around with the running Tk widgets. I will say this port has inspired us to improve the clipboard implementation (now fully native, not shelling out to wl-clipboard) and the IME implementation. So we've definitely learned a bit from this port and are using some of its ideas to make the official Wayland port better.


pounceandmiss - 2026-11-20 08:09:56

> Also, the strong dependency not just on X11's API but its actual code seems to me to be misguided. The official Wayland port will continue to evolve even if the X11 port becomes unmaintained or even removed from Tk if no distributions support X11 in the future.

The dependency is there either way, tkWaylandXlib.c talks Xlib to Tk core, and its wm, scale etc are adapted copies of unix/. If anything, Claude's approach appears to be more loosely coupled and certainly DRYer, not copying but bridging, and bridging mostly in one place (xemu/). That's textbook good software engineering, and Android and Haiku ports, being so short and built on top of it, demonstrate why it's a good practice, in practice.

On Cairo its reasoning looks pretty solid and not based on popularity, quoting:

> Cairo's image back end matches Tk's drawing model: exact, on the CPU, anywhere. It draws through pixman into ordinary memory that is handed straight to the compositor. NanoVG needs a GPU context in every application, so it depends on the GPU drivers, and falls back to Mesa's software rendering where there is no GPU.

> Proper text. FreeType with hinting, fontconfig matching and HarfBuzz shaping: the same stack Tk's Xft build already uses. - Light at run time. Cairo and pixman are 2 MB together. An OpenGL renderer such as NanoVG with GLFW also loads Mesa's driver when a window opens (54 MB, linking LLVM at 165 MB). On Linux desktops Cairo is usually loaded anyway, by libdecor's decoration plugins.

> Not chosen just for Linux desktops. Cairo builds and runs the same on Android, the BSDs, Windows and macOS, so the drawing of the X emulation is identical wherever it runs. That libdecor already loads it on Linux is a bonus, not the reason.

What Cairo does cost is a library to build, especially for Android, but that isn't even targeted by upstream anyway.