fix(linux): implement setAlwaysOnTop + fix SoupMessageHeaders leak (GTK4 + GTK3)#5488
Conversation
… GTK4/GTK3 paths - Implement setAlwaysOnTop via _NET_WM_STATE_ABOVE on X11 (no-op on Wayland, which has no standard compositor-neutral protocol for this) - Fix SoupMessageHeaders reference leak: soup_message_headers_new transfers a floating ref to the caller; add soup_message_headers_unref after passing to webkit_uri_scheme_response_set_http_headers in both GTK4 and GTK3 paths - Remove dead GBytes allocation in linuxApp.setIcon (allocated and unref'd without use); clarify GTK4 limitation in both app-level and window-level setIcon — GTK4 removed per-window icon APIs, icon is set via .desktop file
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds WebKit header unrefs to avoid C leaks, documents GTK4 per-window icon removal, and implements X11 always-on-top behavior with runtime symbol loading and Go bindings to apply/reapply the state. ChangesLinux Platform Improvements
🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR improves the Linux frontend (GTK4 + GTK3) by implementing X11 always-on-top behavior, fixing a libsoup header reference leak in the asset server, and removing a dead GTK4 icon-setting allocation while clarifying the GTK4 icon limitation.
Changes:
- Implement
SetAlwaysOnTopon X11 (GTK4) via_NET_WM_STATE_ABOVE, using the existing dlsym-based X11 symbol resolution approach. - Fix a
SoupMessageHeadersreference leak in the WebKit URI-scheme response path (GTK4 + GTK3). - Remove an unused
GBytesallocation in GTK4 icon-setting and replace it with accurate limitation comments.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| v3/pkg/application/linux_cgo.h | Adds the C API declaration for window_set_always_on_top. |
| v3/pkg/application/linux_cgo.go | Removes dead GTK4 icon code; wires setAlwaysOnTop to the new C helper and updates icon comments. |
| v3/pkg/application/linux_cgo.c | Adds X11 _NET_WM_STATE_ABOVE ClientMessage implementation with dlsym-loaded Xlib calls. |
| v3/internal/assetserver/webview/webkit_linux.go | Unrefs SoupMessageHeaders to prevent a per-request leak (GTK4). |
| v3/internal/assetserver/webview/webkit_linux_gtk3.go | Unrefs SoupMessageHeaders to prevent a per-request leak (GTK3). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@v3/pkg/application/linux_cgo.c`:
- Around line 964-966: window_set_always_on_top currently returns early when
gtk_native_get_surface(native) is NULL, so the X11 _NET_WM_STATE_ABOVE message
never gets sent if setAlwaysOnTop is called before the surface exists; modify
the logic to cache the desired AlwaysOnTop state (e.g., a field on the window
struct) when gtk_native_get_surface(native) is NULL and schedule a retry after
the window is realized/presented, then in windowShow/present (linux_cgo.go) call
the retry path to apply the cached value; ensure updates happen from the same
symbol paths: window_set_always_on_top, the cached AlwaysOnTop flag on the
window object, and the present/windowShow flow used by webview_window_linux.go
-> w.setAlwaysOnTop so the flag is applied once the GTK surface exists.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: dc701e8a-87e4-4b9e-9079-c45946d417f5
📒 Files selected for processing (5)
v3/internal/assetserver/webview/webkit_linux.gov3/internal/assetserver/webview/webkit_linux_gtk3.gov3/pkg/application/linux_cgo.cv3/pkg/application/linux_cgo.gov3/pkg/application/linux_cgo.h
pkg.InstallCommand is a string, not map[string]string. Indexing it with a string key doesn't compile. Use the field directly, matching every other package manager implementation.
If setAlwaysOnTop is called before the window is shown (GTK surface doesn't exist yet), the X11 ClientMessage had nowhere to go and the call was silently lost. Store the desired state in g_object_data (1=true, 2=false; NULL=never set) so we can distinguish "set to false" from "never called". Add window_apply_pending_always_on_top() and call it from windowShow() after gtk_window_present, so the state is applied as soon as the surface exists.
XClientMessageEvent.display must be initialized to the X11 display connection. Leaving it zeroed can cause window managers to ignore the message or trigger undefined behaviour in Xlib.
|
Addressed both outstanding Copilot inline comments: Line 965 (surface NULL): Fixed in commit Line 981 ( |
Summary
Fixes three issues identified during review of PR #4570 (webkit_6 for v2) that were present or partially addressed in the v3 GTK4 codebase:
setAlwaysOnTopimplemented via_NET_WM_STATE_ABOVEon X11, following the same dlsym-based function loading pattern already used forXMoveWindow/XTranslateCoordinates. No-op on Wayland — there is no compositor-neutral standard protocol for this in GTK4.SoupMessageHeadersreference leak fixed in both GTK4 (webkit_linux.go) and GTK3 (webkit_linux_gtk3.go) asset-serving paths.soup_message_headers_newallocates a struct the caller owns; passing it towebkit_uri_scheme_response_set_http_headersdoes not transfer ownership, so the caller's ref was leaking one count per asset request served. Addeddefer soup_message_headers_unrefimmediately after allocation.GBytesallocation removed fromlinuxApp.setIcon: the previous code allocated aGBytesfrom the icon slice and immediately unref'd it without doing anything — effectively a no-op with a transient alloc. BothlinuxApp.setIconandlinuxWebviewWindow.setIconnow have accurate comments explaining the GTK4 limitation: per-window icon APIs were removed in GTK4; the application icon is set via the.desktopfile'sIcon=field.What's still a known limitation
setAlwaysOnTopis X11-only. Wayland does not expose a standard client-side API for this; it would require compositor-specific protocols (e.g.wlr-layer-shell,xdg-activation).setIconfrom bytes has no equivalent in GTK4. This is a GTK4 platform limitation, not a Wails gap.Relation to PR #4570
These issues were surfaced while reviewing #4570 (webkit_6 opt-in for v2 Linux). The v2 PR has additional blockers that are tracked separately in a comment on that PR.
Test plan
!gtk3), verifySetAlwaysOnTop(true/false)toggles window stacking orderSetAlwaysOnTopis a silent no-op (no crash)-tags gtk3, verify asset serving worksSummary by CodeRabbit
New Features
Bug Fixes