Skip to content

feat(gtk): port the backend to gtk4#369

Open
johncarmack1984 wants to merge 3 commits into
tauri-apps:feat/gtk4from
johncarmack1984:gtk4
Open

feat(gtk): port the backend to gtk4#369
johncarmack1984 wants to merge 3 commits into
tauri-apps:feat/gtk4from
johncarmack1984:gtk4

Conversation

@johncarmack1984

@johncarmack1984 johncarmack1984 commented Jul 3, 2026

Copy link
Copy Markdown

Toward #270: the gtk4 port, targeting feat/gtk4 (#272) so the diff is what sits on top of that branch, in three commits: the port (@rmakestrash-jpg's continuation from #341 adapted to current dev), the icon rendering fix, and CI. Part of the delta is re-syncing shared modules with dev's current API (the KeyAccelerator line), which moved after the branch split.

The API: GTK4 deleted gtk::Menu, gtk::MenuBar, and gtk::Container, so those types can't survive. Every method keeps its name and shape. gtk_context_menu() returns gtk::PopoverMenu, gtk_menubar_for_gtk_window returns Option<gtk::PopoverMenuBar>, Container bounds widen to Widget. gtk3 call sites compile unchanged -- checked against tauri and tauri-apps/tao#1258 -- and no gtk3 process can link a gtk4 muda anyway.

Icons: PopoverMenu ignores icons set on model items, so icon items get a custom slot with a real icon+label widget bound via add_child. Here it is in a running Tauri app on the full gtk4 stack (tao#1258 + wry gtk4 + this); label, icon, and checked changes show up live:

menu icon rendering in a Tauri app on the gtk4 stack

Also fixes the macOS break from #341 (KeyAccelerator throughout) and drops the ksni and sync-workflow changes per the feedback there. check, clippy, and tests green on Linux (GTK 4.18) and macOS. MSRV 1.92; CI needs libgtk-4-dev. The two changed return types are the main review question.

@socket-security

socket-security Bot commented Jul 3, 2026

Copy link
Copy Markdown

@johncarmack1984

Copy link
Copy Markdown
Author

CI should be in better shape now. Three things were failing: the test jobs pin a 1.73 toolchain that can't parse a v4 lockfile (MSRV is 1.92 with this port, so the pin moves with it), the runners were missing libgtk-4-dev, and the clippy gate caught one lint plus examples still calling the gtk API with gtk3-era tao types; those calls are commented until a tao release on gtk4 exists. Everything green locally on the exact CI commands for Linux and macOS.

The audit failure is pre-existing rather than from this PR: quick-xml < 0.41 arrives through winit -> wayland-scanner in the dev-dependencies, the advisory is dated June 29, and dev's lockfile carries the same version, so a fresh audit fails identically on dev. Nothing here can reach the patched version until wayland-scanner bumps.

@amrbashir

Copy link
Copy Markdown
Member

can you target my feat/gtk4 branch? This way I can review and discuss what you added on top of my work without the noise of previous work.

@johncarmack1984 johncarmack1984 changed the base branch from dev to feat/gtk4 July 7, 2026 20:12
@johncarmack1984

Copy link
Copy Markdown
Author

Done. The PR now targets feat/gtk4, with the delta in three commits on top of your branch: the port (rmakestrash-jpg's continuation adapted to current dev), the icon rendering fix, and CI. One note on the diff: dev's shared modules moved to the KeyAccelerator API after the branch split, so part of the delta is re-syncing those files with current dev.

johncarmack1984 and others added 3 commits July 7, 2026 13:26
Builds on the feat/gtk4 backend: brings in the extension work from
rmakestrash's fork and adapts everything to dev's current API, so the
public surface stays what dev ships today and call sites compile
unchanged.

- gtk4 0.11 and png 0.18, MSRV 1.92 to match gtk4's floor
- the gtk dependency is optional behind a `gtk` feature (part of
  default) with dev's BSD-wide target cfg; `libxdo` stays as a no-op
  feature name for compatibility
- shared modules follow dev's current API (the KeyAccelerator line);
  the only changes there are the feature and target cfg gates
- backend methods keep their gtk3 names and shapes; only widget types
  move with the toolkit (Menu to PopoverMenu, MenuBar to
  PopoverMenuBar, Container bounds to Widget)
- predefined item accelerators are wired on gtk, matching macOS
- KeyAccelerator::to_gtk covers the Key-based accelerator path

Co-authored-by: amrbashir <github@amrbashir.me>
Co-authored-by: rmakestrash-jpg <rmakestrash-jpg@users.noreply.github.com>
GTK4's PopoverMenu does not render icons set on a gio::MenuItem, which is
why menu icons were blank on the gtk4 backend. Mark icon items with a
`custom` attribute and bind an icon+label widget (a flat button carrying
the item's action) via PopoverMenu/PopoverMenuBar add_child; the binding
reaches nested submenu slots too. Context menus rebuild on show so label,
icon, and checked-state changes are reflected instead of showing a stale
first build.

Verified headless (xvfb) with a menu whose icon and label are mutated
live: the icon renders and updates, addressing the icon issue tracked in
tauri-apps#270.
The runners need libgtk-4-dev next to the existing gtk3 packages,
which stay for the tao and wry dev-dependencies. The test job's
pinned toolchain moves to 1.92 to match the crate's MSRV, set via the
action's toolchain input because dtolnay/rust-toolchain has no 1.92
tag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants