Bug 511981

Summary: Fix System Tray widget global shortcuts not working
Product: [Plasma] plasmashell Reporter: Mikhail Pavlovich Sidorenko (Михаил Павлович Сидоренко) <motherlode.muwa>
Component: System Tray widgetAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED DOWNSTREAM    
Severity: minor CC: materka
Priority: NOR    
Version First Reported In: 6.0.0   
Target Milestone: 1.0   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Patch for system tray

Description Mikhail Pavlovich Sidorenko (Михаил Павлович Сидоренко) 2025-11-12 07:17:37 UTC
Created attachment 186718 [details]
Patch for system tray

# Fix System Tray widget global shortcuts not working

## Summary

This patch fixes a bug where global keyboard shortcuts assigned to the System Tray widget are registered in kglobalaccel but do not activate the widget. The root cause is that System Tray disconnects the default `activated` signal handler but never connects its own.

**This is a regression introduced in Plasma 6.0 during the nested containment refactoring and remains unfixed in master as of November 2025.**

## Bug Description

**Affected versions:** Plasma 6.0 - 6.5.2, master  
**Regression from:** Plasma 5.21+ (where it worked correctly)  
**Severity:** Medium - Feature regression from Plasma 5  
**Git history verified:** Bug NOT fixed in any version 6.0+

When users assign a global shortcut to the System Tray widget through the GUI (Configure System Tray → Keyboard Shortcuts):
1. The shortcut is saved in configuration
2. The shortcut is registered in kglobalaccel
3. Pressing the shortcut sends the `activated` signal
4. **Nothing happens** - the System Tray does not expand

This works correctly for other widgets like Analog Clock, which use the default `PlasmoidItem` handler.

## Root Cause

In `plasma-workspace/applets/systemtray/systemtray.cpp` lines 63-67, the System Tray explicitly disconnects the `activated` signal from child applets:

```cpp
// we don't want to automatically propagate the activated signal from the Applet to the Containment
// even if SystemTray is of type Containment, it is de facto Applet and should act like one
connect(this, &Containment::appletAdded, this, [this](Plasma::Applet *applet) {
    disconnect(applet, &Applet::activated, this, &Applet::activated);
});
```

However, **no handler is connected for the System Tray's own `activated` signal**, unlike other widgets which inherit the default behavior from `PlasmoidItem` (plasma-framework/src/plasmaquick/plasmoid/plasmoiditem.cpp:99-105).

## Verification

```bash
# Shortcut IS registered in kglobalaccel
$ qdbus6 org.kde.kglobalaccel /component/plasmashell \
  org.kde.kglobalaccel.Component.allShortcutInfos | grep "activate widget"
# Shows: [Argument: ai {234881108}] ✓

# Signal IS sent when shortcut is pressed
$ qdbus6 org.kde.kglobalaccel /component/plasmashell \
  org.kde.kglobalaccel.Component.invokeShortcut "activate widget 8"
# Executes without error ✓

# But System Tray does NOT respond ✗
```

## Solution

Add a QML handler for the `activated` signal in the System Tray's main.qml to toggle the expanded state.

## Changes

**File:** `applets/systemtray/package/contents/ui/main.qml`

After the `Component.onCompleted` block (line 46), add:

```qml
// BUGFIX: Handle activated signal to toggle expansion (for global shortcuts)
Connections {
    target: Plasmoid
    function onActivated() { systemTrayState.expanded = !systemTrayState.expanded; }
}
```

## Testing

1. Right-click System Tray → Configure System Tray
2. Go to Keyboard Shortcuts tab
3. Assign a shortcut (e.g., Ctrl+Alt+Shift+T)
4. Click Apply
5. Press the assigned shortcut
6. **Expected:** System Tray popup appears/disappears
7. **Before patch:** Nothing happens
8. **After patch:** System Tray toggles correctly ✓

## Related Code

- **plasma-framework/src/plasmaquick/plasmoid/plasmoiditem.cpp:99-105** - Default activated handler that works for other widgets
- **plasma-workspace/shell/kconf_update/plasma6.0-remove-old-shortcuts.cpp** - Migration script that mentions widget shortcuts should be handled explicitly in Plasma 6

## Related Commits

- **0411253613** (Oct 2020, Plasma 5.21) - Original fix that worked in Plasma 5 by adding `setGlobalShortcut()` in `restoreContents()` and the `disconnect()` line
- **46ada24fd8** (Mar 2024, Plasma 6.0) - Refactored to nested containment, regression likely introduced here
- **9c872a5428** (Jun 2024, Plasma 6.2) - Fixed shortcuts for child applets **inside** System Tray, but not for System Tray itself
- **cb73a963c0** (Feb 2025, master) - Focus improvements, unrelated to shortcuts

**Analysis:** The bug has been present since Plasma 6.0 and remains unfixed in master (verified Nov 2025).

## Notes

- This regression was introduced in Plasma 6.0 when the automatic signal propagation was removed
- The comment in systemtray.cpp indicates this was intentional, but no replacement handler was added
- Other containment-based widgets may have the same issue and need similar fixes
- This does not affect widgets that use the standard `PlasmoidItem` behavior
- This bug can also occur in other widgets, such as Media Frame.

## Checklist

- [x] Patch applies cleanly to v6.4.5
- [x] Tested on Kubuntu 25.10 with Plasma 6.4.5
- [x] No compilation warnings introduced
- [x] Feature works as expected after patch
- [x] Does not affect other System Tray functionality
- [x] Follows existing code style (QML Connections pattern)

---

**Patch file:** `systemtray-activation-fix.patch`  
**Reported by:** Mikhail Pavlovich Sidorenko via Cursor
**Tested on:** KDE Plasma 6.4.5, KDE Frameworks 6.17.0, Qt 6.9.2  
**Date:** 2025-11-12
Comment 1 Bug Janitor Service 2025-11-12 07:33:42 UTC
Thank you for the bug report!

However Plasma 6.0.0 no longer receives updates or maintenance from KDE; active versions are 6.4 or newer. Please upgrade to an active version as soon as your distribution makes it available to you. Plasma is a fast-moving project, and bugs in one version are often fixed in the next one.

If you need help with Plasma 6.0.0, please contact your distribution, who bears the responsibility of providing help for older releases that are no longer receiving updates from KDE.

If you can reproduce the issue after upgrading to an active version, feel free to re-open this bug report.
Comment 2 Mikhail Pavlovich Sidorenko (Михаил Павлович Сидоренко) 2025-11-12 08:10:50 UTC
This is duplicate of 483688