Skip to content

qtui, skins-qt: Use unique window role for plugin windows, fix crash with QT 6.12, follow x11 rule - #215

Merged
radioactiveman merged 2 commits into
audacious-media-player:masterfrom
afunyun:fix-wayland-session-window-role
Oct 18, 2026
Merged

radioactiveman merged 2 commits into
audacious-media-player:masterfrom
afunyun:fix-wayland-session-window-role

Conversation

@afunyun

@afunyun afunyun commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Full writeup is in audacious-media-player/audacious#1887 but restating some info (not that this is complex in any way, i just ramble):

This fixes a crash with qt 6.12.0 on kwin 6.7.5 due to WM_WINDOW_ROLE collisions.

Plugin windows all shared the window role plugin. Qt 6.12.0 now passes the role to xdg_session_v1 as the toplevel ID. WM_WINDOW_ROLE is expected to be unique rather than shared among all nontransient child windows. kwin enforces this uniqueness and terminates the client on duplicates.

My change makes the role plugin-<id> on all platforms which follows existing X11 convention (source) while fixing the new crash. It appears the ICCCM convention was not strictly enforced (hence no prior issues with this), but according to ICCCM 5.1, technically the plugin shared role is unexpected behavior, and this fixes that.

user created window rules that exactly match plugin will need to be updated to use the prefix.

This is quite simple, we just make the role unique per plugin, which can be done via the dock item ID as is already done for setObjectName() in DockWidget:

[...]
class DockWidget : public QDockWidget
{
public:
    DockWidget(QWidget * parent, audqt::DockItem * item)
        : QDockWidget(parent), m_item(item)
    {
        setObjectName(item->id());
        setWindowTitle(item->name());
        setWindowRole("plugin");
        setWidget(item->widget());
        setContextMenuPolicy(Qt::PreventContextMenu);

        item->set_host_data(this);
    }

[...]

I've simply updated to mimic that within src/qtui/main_window.cc and src/skins-qt/plugin-window.cc:

setWindowRole ("plugin");

becomes

setWindowRole (QString ("plugin-") + item->id ());

For whatever reasons, src/qtui/main_window.cc and src/skins-qt/plugin-window.cc use different spacing conventions so that's why they differ in that, but otherwise it's the same change on each.

…d crash with qt 6.12.0 & complies with ICCCM 5.1
Copilot AI balanced review requested due to automatic review settings October 9, 2026 05:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Both plugin-window hosts consistently use stable dock-item IDs to eliminate role collisions.

0 open findings

What changed in this PR

Prevents Qt 6.12/KWin crashes by assigning each plugin window a unique role based on its dock-item ID.

Changes:

  • Uses plugin-<id> roles in both Qt interfaces.
  • Preserves distinct window roles across plugin windows.
File Description
src/​qtui/​main_window.cc Assigns unique roles to dock widgets.
src/​skins-qt/​plugin-window.cc Assigns unique roles to skin plugin windows.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@afunyun afunyun changed the title qtui, skins-qt: Use unique window role for plugin windows, fix waylan… qtui, skins-qt: Use unique window role for plugin windows, fix kwin/wayland crash with QT 6.12.0 Oct 9, 2026
@afunyun afunyun changed the title qtui, skins-qt: Use unique window role for plugin windows, fix kwin/wayland crash with QT 6.12.0 qtui, skins-qt: Use unique window role for plugin windows, fix crash with QT 6.12, follow x11 rule Oct 9, 2026
@radioactiveman

radioactiveman commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Thanks for the report and pull request. 👍

Could you also please check libaudqt from the Audacious core project? "file-dialog" and "message" are used multiple times.

What happens for example when you add/open files (via the File menu, keeping the dialog open) and then import/export an equalizer preset?

src/libaudqt/url-opener-qt.cc:    dialog->setWindowRole("url-dialog");
src/libaudqt/audqt.cc:    msgbox->setWindowRole("message");
src/libaudqt/colorbutton.cc:            dialog->setWindowRole("color-dialog");
src/libaudqt/about-qt.cc:    window->setWindowRole("about");
src/libaudqt/infowin-qt.cc:    setWindowRole("song-info");
src/libaudqt/prefs-window-qt.cc:    setWindowRole("settings");
src/libaudqt/song-window-qt.cc:    setWindowRole("jump-to-song");
src/libaudqt/file-entry.cc:    dialog->setWindowRole("file-dialog");
src/libaudqt/log-inspector.cc:    setWindowRole("log-inspector");
src/libaudqt/queue-manager-qt.cc:    setWindowRole("queue-manager");
src/libaudqt/eq-preset-qt.cc:    dialog->setWindowRole("file-dialog");
src/libaudqt/eq-preset-qt.cc:    dialog->setWindowRole("file-dialog");
src/libaudqt/prefs-plugin.cc:    cw->root->setWindowRole("plugin-settings");
src/libaudqt/fileopener.cc:        dialog->setWindowRole("file-dialog");
src/libaudqt/playlist-management.cc:    dialog->setWindowRole("rename-playlist");
src/libaudqt/playlist-management.cc:    dialog->setWindowRole("remove-playlist");

src/ui-common/dialogs-qt.cc:        m_progress->setWindowRole ("progress");
src/skins-qt/equalizer.cc:    equalizerwin->setWindowRole ("equalizer");
src/skins-qt/plugin-window.cc:        setWindowRole ("plugin");
src/skins-qt/main.cc:    mainwin->setWindowRole("mainwindow");
src/skins-qt/playlistwin.cc:    playlistwin->setWindowRole ("playlist");
src/skins-qt/search-select.cc:    setWindowRole ("search");
src/qtui/main_window.cc:        setWindowRole("plugin");
src/qtui/main_window.cc:    setWindowRole("mainwindow");
src/delete-files/delete-files.cc:        qdialog->setWindowRole ("message");

@afunyun

afunyun commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Great question, it appears this bug exists in core libaudqt as well. The split repos left my search for further uses too narrow.

Your specific example actually does NOT crash on my particular environment as explained below, since file-dialog is protected by my platform theme providing a helper.

native    widget  concurrent  restore_toplevel(dup-role)=2  error 1: the specified toplevel id is already used
native    widget  sequential  restore_toplevel(dup-role)=2  ok
native    widget  reshow      restore_toplevel(dup-role)=2  ok
native    file    concurrent  restore_toplevel(dup-role)=0  ok
native    file    sequential  restore_toplevel(dup-role)=0  ok
native    file    reshow      restore_toplevel(dup-role)=0  ok
native    msg     concurrent  restore_toplevel(dup-role)=0  ok
native    msg     sequential  restore_toplevel(dup-role)=0  ok
native    msg     reshow      restore_toplevel(dup-role)=0  ok
nonative  widget  concurrent  restore_toplevel(dup-role)=2  error 1: the specified toplevel id is already used
nonative  widget  sequential  restore_toplevel(dup-role)=2  ok
nonative  widget  reshow      restore_toplevel(dup-role)=2  ok
nonative  file    concurrent  restore_toplevel(dup-role)=2  error 1: the specified toplevel id is already used
nonative  file    sequential  restore_toplevel(dup-role)=2  ok
nonative  file    reshow      restore_toplevel(dup-role)=2  ok
nonative  msg     concurrent  restore_toplevel(dup-role)=2  error 1: the specified toplevel id is already used
nonative  msg     sequential  restore_toplevel(dup-role)=2  ok
nonative  msg     reshow      restore_toplevel(dup-role)=2  ok

For cases it appears roles file-dialog, message, plugin-settings, rename-playlist & remove-playlist, and color-dialog can all have 2 open, KWin with a theme accidentally avoids the crash via handoff to a native helper in the cases of file-dialog and message and likely color-dialog in any theme that has a native dialog for it. url-dialog, about, song-info, jump-to-song, log-inspector, settings, queue manager are single instance only via a static QPointer.

KWin will free the toplevel ID if it was already used, if it's being opened after the window that had the role is already destroyed. Hiding a window and bringing it back doesn't cause a problem. For my setup, for QFileDialogue and QMessageBox since the helper that handles them doesn't have Audacious's role in the first place, no conflict. QT doesn't send send the ID at all in that case because it isn't concerned with the native windows role at that point.

If I set QT_QPA_PLATFORMTHEME=generic, or Qt::AA_DontUseNativeDialog, QFileDialogue and QMessageBox do crash with 2 same-ID windows open simultaneously.

I will also draft fixes under the core repo for plugin-settings for sure, that should be handled by appending the plugin's basename to the role as worked in the 2 changes in this PR.

@radioactiveman would like your input for the shorter lived dialogs, file-dialog, message, rename-playlist/remove-playlist, color-dialog roles since for these windows, I do not think there are any cases where restoring a session would apply. So, we can either append something unique, like the FileMode for fileopener, or simply stop setting a role for those in the first place. Not setting a role would prevent X11 window rules from working, but that's the only thing it affects besides Wayland session restore which as stated shouldn't ever be restoring these roles in normal use.

Also, the fixes in this PR itself as it stands do not cause additional issues with any of the above, ie this change does not conflict with the core repo's libaudqt whether it itself is fixed, or not. I could be missing something, but I verified:

dock.cc only manages DockItem objects, never touches setWindowRole or handle their creation in general, that's exclusively DockWidget nd PluginWindow both in the plugins repo. No setWindowRole calls ever touch dialogs outside of core. It does set the IDs that the item->id() call reads, but it is only ever a read and the possible values are all unique already.

They do share the same wayland session namespace but I did not find anything in core that would collide with anything from plugins. If someone made a plugin called settings it would collide with the plugin-settings role itself but this is obviously highly improbable. If we wanted to close that possibility, renaming core's role for this to settings-plugin-X would do it, but I doubt that a settings plugin is likely to appear to be honest. That'd be a matter of preference for the core repo and still doesn't affect this repo's fixes.

PR open for the core repo addressing it: audacious-media-player/audacious#1889

Rather than the smaller changes for plugins due to only needing changes in 2 locations for https://github.com/audacious-media-player/audacious-plugins/, and in the interest of avoiding inconsistency/confusion as to why some are using a similar but different method of setting the role, all 16 instances of setWindowRole under the core repo are now run through a helper in libaudqt-internal.h that is then included throughout the various cases that use it, if necessary.

dialog->setWindowRole("foo");

becomes

set_window_role(dialog, "foo");

throughout.

- Make roles more unique
- Remove generic role names
- Adapt GTK code as well
- Set missing role names
@radioactiveman
radioactiveman merged commit 6993dd5 into audacious-media-player:master Oct 18, 2026
7 checks passed
@radioactiveman

Copy link
Copy Markdown
Member

I would like your input for the shorter lived dialogs, file-dialog, message, rename-playlist/remove-playlist, color-dialog roles since for these windows, I do not think there are any cases where restoring a session would apply. So, we can either append something unique, like the FileMode for fileopener, or simply stop setting a role for those in the first place. Not setting a role would prevent X11 window rules from working, but that's the only thing it affects besides Wayland session restore which as stated shouldn't ever be restoring these roles in normal use.

Thinking about that I decided to just drop the roles for such windows. The benefit for those short-lived dialogs is from my point of view indeed very limited.

@afunyun

afunyun commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

I would like your input for the shorter lived dialogs, file-dialog, message, rename-playlist/remove-playlist, color-dialog roles since for these windows, I do not think there are any cases where restoring a session would apply. So, we can either append something unique, like the FileMode for fileopener, or simply stop setting a role for those in the first place. Not setting a role would prevent X11 window rules from working, but that's the only thing it affects besides Wayland session restore which as stated shouldn't ever be restoring these roles in normal use.

Thinking about that I decided to just drop the roles for such windows. The benefit for those short-lived dialogs is from my point of view indeed very limited.

Completely valid conclusion. Glad to have helped! Been using audacious as my preferred foobar2000 analogue on linux after leaving windows, and working on this was a bit of a crash course in wayland/X11/Qt interaction for me, so thanks! Will report back if I find any issues, but I've been using a build with this fix for a bit and haven't had issues to date so I'm sure it'll be all good to go.

@afunyun
afunyun deleted the fix-wayland-session-window-role branch October 19, 2026 05:29
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.

3 participants