Skip to content

libaudqt: Use unique window role for core & plugin windows, fix crash with QT 6.12, follow x11 rule - #1889

Closed
afunyun wants to merge 1 commit into
audacious-media-player:masterfrom
afunyun:fix-libaudqt-wayland-restore-wm-window-role
Closed

afunyun wants to merge 1 commit into
audacious-media-player:masterfrom
afunyun:fix-libaudqt-wayland-restore-wm-window-role

Conversation

@afunyun

@afunyun afunyun commented Oct 12, 2026 •

Copy link
Copy Markdown

Related to audacious-media-player/audacious-plugins#215, these changes complement the fix addressing #1887. This remedies a crash new to QT 6.12 & related to the new session restore protocol.

This also, as I discovered while fixing the crash, incidentally makes both occurrences of setWindowRole (in core repo, and in the plugins repo) comply with ICCCM §5.1. This historically was not a problem as it seems X11 was not strictly enforcing compliance with 5.1, but wayland compositors/qt are now doing so in support of the new session restore functionality, introducing a crash instead of a quiet error.

We provide a helper declared in libaudqt-internal.h with a little explainer comment in that file since it'd be unique among these QT setX methods where it is used, leaving the public API unchanged and being fully independent from the changes made under the audacious-plugins repo due to the way their concerns are separated.

Opted for a helper instead of the per-window handler change like the plugins repo due to setWindowRole appearing in a multitude of areas under src/libaudqt/. All 16 audacious core setWindowRole calls now go through it: audqt::set_window_role(window, role), next to window_bring_to_front in audqt.cc. That includes the windows that can only ever have one copy open, so every role works the same way to avoid confusion as to why some window roles are set through this and why some don't.

Functionally, it simply appends a per-process serial number to the role. Each window gets a unique role (settings-1, file-dialog-4, etc).

For those users that use window rules that rely on the window's role, prefix rules like ^settings keep matching. This DOES break exact-match rules, necessarily, but prefix rules will continue working:
KWin (my environment): Substring rule matching settings-, or regex matching ^settings-[0-9]+$
sway/i3 type: window_role="^settings-"

/* the window role must be unique among the windows of a client (ICCCM 5.1);
 * Qt also uses it as the Wayland session restore ID, where a duplicate is a
 * fatal protocol error, so append a serial number to the base role */
void set_window_role(QWidget * window, const char * role)
{
    static int serial = 0;
    window->setWindowRole(QString(role) + '-' + QString::number(++serial));
}

Most changed files follow as shown in src/libaudqt/colorbutton.cc as an example:

#include "colorbutton.h"
#include "libaudqt-internal.h"
#include "libaudqt.h"

#include <QColorDialog>

[...]

EXPORT void simple_message(const char * title, const char * text)
{
    simple_message(title, text, QMessageBox::NoIcon);
	@@ -330,7 +339,7 @@ EXPORT void simple_message(const char * title, const char * text,
    msgbox->button(QMessageBox::Close)->setText(translate_str(N_("_Close")));
    msgbox->setAttribute(Qt::WA_DeleteOnClose);
    msgbox->setTextInteractionFlags(Qt::TextSelectableByMouse);
    set_window_role(msgbox, "message");
    msgbox->show();
}

Uniquely, about-qt.cc calls it as audqt::set_window_role because it's in a separate namespace. Eight files gained an include of libaudqt-internal.h in order to call this helper.

#include <libaudcore/runtime.h>
#include <libaudcore/vfs.h>

#include "libaudqt-internal.h"
#include "libaudqt.h"

[...]

static QTabWidget * buildCreditsNotebook(QWidget * parent)
	@@ -62,7 +63,7 @@ static QDialog * buildAboutWindow()

    auto window = new QDialog;
    window->setWindowTitle(_("About Audacious"));
    audqt::set_window_role(window, "about");

    auto logo = new QLabel(window);
    int logo_size = audqt::to_native_dpi(400);

Testing: built a patched 4.6.1 with patched libaudqt as well as the fixes for the plugins repo applied. Ran with the generic QT platform theme, as this had more crash cases than my normal KWin environment - file dialogs and message boxes use native helpers in platform themes that provide them, but generic QT would previously crash on two of those being opened with this enforced, due to not handing it off to a native helper that doesn't exist in that setting.

The new roles appear in the Wayland trace next to plugin- and mainwindow, with no errors.

Every case that would have crashed with the old fixed roles survived: two+ plugin settings dialogs, two+ file dialogs, combinations of those along with windows having their role set by the fixes on the plugins side. On stock 4.6.1 each of these is a duplicate "plugin-settings" or "file-dialog" ID, and a crash. The fixes for plugins and the core audacious repo coexist without issues; I had settings-9, plugin-settings-10, plugin-settings-11, plugin-blur_scope-qt, plugin-qt-spectrum, file-dialog-5, file-dialog-6 all open at once with no issues. Closing one of the core windows affected by this PR, and indeed just opening a new copy of any core window without regard for whether or not it was previously closed, properly increments the window's role ID, preventing any possible collisions.

image

Two plugins with their settings windows opened simultaneously, with generic QT enforced on the patches. No wayland errors.

image Same but with both Add File and Open Files opened simultaneously. image Multiple visualizers, multiple plugin settings, etc.

…ger_v1 under qt 3.12, complies with icccm sect. 5.1 as well for xwindowsystem
Copilot AI balanced review requested due to automatic review settings October 12, 2026 18:46
@afunyun afunyun changed the title Use unique window role for plugin windows, fix crash with QT 6.12, follow x11 rule libaudqt: Use unique window role for core & plugin windows, fix crash with QT 6.12, follow x11 rule Oct 12, 2026

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.

🟡 Changes recommended

The global serial makes persistent Wayland window identities depend on unrelated window creation order.

1 open finding
What changed in this PR

Introduces unique Qt window roles to prevent Qt 6.12 Wayland session-ID collisions.

Changes:

  • Adds an internal window-role helper with serialized identifiers.
  • Migrates all core Qt windows and dialogs to the helper.
  • Preserves role prefixes for existing window rules.
File Description
src/​libaudqt/​about-qt.cc Migrates the About dialog role.
src/​libaudqt/​audqt.cc Implements role serialization and migrates messages.
src/​libaudqt/​colorbutton.cc Migrates color-dialog roles.
src/​libaudqt/​eq-preset-qt.cc Migrates preset file-dialog roles.
src/​libaudqt/​file-entry.cc Migrates file-entry dialog roles.
src/​libaudqt/​fileopener.cc Migrates file-opener dialog roles.
src/​libaudqt/​infowin-qt.cc Migrates song-information roles.
src/​libaudqt/​libaudqt-internal.h Declares the internal helper.
src/​libaudqt/​log-inspector.cc Migrates log-inspector roles.
src/​libaudqt/​playlist-management.cc Migrates playlist-dialog roles.
src/​libaudqt/​prefs-plugin.cc Migrates plugin-settings roles.
src/​libaudqt/​prefs-window-qt.cc Migrates application-settings roles.
src/​libaudqt/​queue-manager-qt.cc Migrates queue-manager roles.
src/​libaudqt/​song-window-qt.cc Migrates jump-to-song roles.
src/​libaudqt/​url-opener-qt.cc Migrates URL-dialog roles.

🧠 Review effort: Balanced


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

Comment thread src/libaudqt/audqt.cc Resolved
@afunyun

afunyun commented Oct 12, 2026

Copy link
Copy Markdown
Author

🟡 Changes recommended

The global serial makes persistent Wayland window identities depend on unrelated window creation order.

1 open finding

Addressing since marking not-changed collapsed it,

This isn't a concern for this change. Audacious doesn't participate in session restore. It only ran into the protocol because Qt 6.12 now registers window roles as xdg_session_v1 toplevel IDs, and the compositor enforces their uniqueness. src/libaudqt/audqt.cc constructs its QApplication with a dummy argv, so Qt never sees -session and always calls get_session(reason_launch, nil). Every launch is a fresh compositor session, so IDs are never matched across restarts. The fixed roles used before this PR weren't restored across restarts either. The global serial is scoped to a single run and exists only to guarantee uniqueness within that run, which is the requirement this PR addresses.
If Audacious ever adds explicit session restore, stable IDs would need to be designed deliberately at that point, though it's unclear what restoring transient dialogs like these would gain. Windows with a natural identifier wouldn't need a counter because of the way that they are: the plugin dock windows already use stable plugin- roles (this can be found in #1887), and plugin settings dialogs could likewise use the plugin's basename, since only one can be open per plugin. The counter is only needed for windows with no inherent differentiator, such as multiple file dialogs or message boxes.

@radioactiveman

Copy link
Copy Markdown
Member

Obsolete now with 612bd8b.

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