https://bugs.kde.org/show_bug.cgi?id=528567

--- Comment #4 from GreenStar <[email protected]> ---
Plain-text version of the report. Bugzilla does not render Markdown, and the
description above was submitted with it; the content below is the same,
formatted for Bugzilla.

AI disclosure: this report and the example patch were produced by an AI agent
(OpenCode, DeepSeek V4.1 Flash) from a live debugging session. They are
provided
as an example for a contributor who can own the change. The patch is not a
merge
request and has not been reviewed by a KDE contributor.


SUMMARY

After a second kwin_wayland runs on the same session bus (headless test
harness,
recording setup, or kwin_wayland --replace), the first compositor's global
shortcuts stop firing. Alt+Tab and Meta+Tab do nothing, although the keys reach
KWin (visible in the Debug Console's Input Events tab) and kglobalshortcutsrc
still contains the bindings.

The whole kwin shortcut component is inactive:

    qdbus6 org.kde.kglobalaccel /component/kwin
org.kde.kglobalaccel.Component.isActive
    false

GlobalShortcut::setActive() refuses to grab any keys when _isPresent is false,
so
every KWin shortcut is dead at once.


ROOT CAUSE

Presence is a single boolean per component/action, shared by all clients
(kglobalacceld src/globalshortcut.h):

    bool _isPresent : 1;

On QAction destruction the client library calls the D-Bus method setInactive
(kglobalaccel src/kglobalaccel.cpp:269-275), and the daemon clears that shared
flag for everybody (kglobalacceld src/kglobalacceld.cpp:438-446):

    void KGlobalAccelD::setInactive(const QStringList &actionId)
    {
        GlobalShortcut *shortcut = d->findAction(actionId);
        if (shortcut) {
            shortcut->setIsPresent(false);   // all clients lose it
        }
    }

A second process that registers the same kwin actions (a nested compositor, or
two instances of an app sharing a component/action) therefore kills the first
process's shortcuts simply by exiting.

--no-global-shortcuts is not enough: it only gates the input filter
(src/main_wayland.cpp:631, src/input.cpp:3194), not the
KGlobalAccel::setGlobalShortcut() calls, so the nested instance still registers
and still clears presence when it exits.


STEPS TO REPRODUCE (private bus)

Everything below uses a private dbus-daemon. Do not point a nested kwin_wayland
at a real session bus; that breaks the developer's shortcuts.

1. Start kwin_wayland --virtual on a private bus (compositor A). Open two
   windows. Alt+Tab opens the switcher (attachment 198253).
2. Start a second kwin_wayland --virtual on the same private bus (compositor B,
   optionally with --no-global-shortcuts), then let it exit.
3. Press Alt+Tab in compositor A: the switcher no longer appears (attachment
   198254), and Component.isActive for the kwin component is false.

Minimal form without a compositor: two D-Bus clients call
setShortcutKeys(..., SetPresent) for the same action and one calls setInactive.
With the unpatched library the action becomes inactive when the second client
leaves; with the example patch it stays active.


EXPECTED

A client going away must not clear a shortcut another client still presents.
Presence should be per client, or the second compositor must not register at
all.


WORKAROUND

Re-mark the actions present in the running daemon (no compositor restart, no
key
changes). Script:
https://gist.github.com/VIGO-VI/bfab9dcd2ea958c40dbf0feb0845e672

    python3 repair-running-session.py
    present again: 46 kwin shortcuts
    isActive: (true,)

First aid only: the next foreign compositor exit can clear them again.


EXAMPLE FIX

kglobalacceld-per-client-present.patch (attachment 198252, targets
invent.kde.org/plasma/kglobalacceld) tracks a set of present D-Bus senders per
shortcut: setShortcut(..., SetPresent) adds message().service(); setInactive()
removes only that sender; the shortcut goes inactive only when the last owner
leaves.

Validated here by building kglobalacceld 6.8.2 with the patch and running the
two-client test:

    [system]  active after first client: (true,) | after second client left:
(false,)
    [patched] active after first client: (true,) | after second client left:
(true,)

Known gap: owners are not reaped when a client disconnects without calling
setInactive (crash); a NameOwnerChanged watcher should drop vanished senders. A
proper patch should also add an autotest.


ATTACHMENTS / LINKS

Report, patch, reproducers and repair script:
https://gist.github.com/VIGO-VI/bfab9dcd2ea958c40dbf0feb0845e672

Screenshots attached to this bug:
Before, switcher works:
https://bugs.kde.org/attachment.cgi?id=198253
After, second compositor exited:
https://bugs.kde.org/attachment.cgi?id=198254

Environment: CachyOS (glibc), Plasma 6.8.2, kwin 6.8.2-2.1, kglobalacceld
6.8.2,
Qt 6.12.0, Wayland, one output. The switcher layout was the stock big_icons; a
QML binding-loop warning exists but is unrelated.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to