Skip to content

fix(linux): migrate to qt tray#104

Open
ReenigneArcher wants to merge 9 commits intomasterfrom
fix/linux/migrate-to-qt-tray
Open

fix(linux): migrate to qt tray#104
ReenigneArcher wants to merge 9 commits intomasterfrom
fix/linux/migrate-to-qt-tray

Conversation

@ReenigneArcher
Copy link
Member

Description

Migrate to qt5/6 for Linux tray.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 56.50407% with 107 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.29%. Comparing base (f04a48b) to head (bd83ea9).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/tray_linux.cpp 57.67% 65 Missing and 37 partials ⚠️
src/tray_darwin.m 0.00% 3 Missing ⚠️
src/tray_windows.c 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (f04a48b) and HEAD (bd83ea9). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (f04a48b) HEAD (bd83ea9)
libappindicator3-dev 1 0
Linux 2 1
libayatana-appindicator3-dev 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #104      +/-   ##
==========================================
- Coverage   73.06%   66.29%   -6.78%     
==========================================
  Files           4        4              
  Lines         427      531     +104     
  Branches       83      157      +74     
==========================================
+ Hits          312      352      +40     
- Misses         72      120      +48     
- Partials       43       59      +16     
Flag Coverage Δ
Linux 52.65% <57.67%> (-7.35%) ⬇️
Windows 70.87% <0.00%> (-0.70%) ⬇️
libappindicator3-dev ?
libayatana-appindicator3-dev ?
macOS 62.61% <0.00%> (-1.81%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/example.c 0.00% <ø> (ø)
src/tray_windows.c 79.78% <0.00%> (-0.89%) ⬇️
src/tray_darwin.m 83.75% <0.00%> (-3.27%) ⬇️
src/tray_linux.cpp 57.67% <57.67%> (ø)

@github-actions
Copy link

Screenshot Comparison

PR #104 screenshots vs screenshots baseline.

Matrix: Linux

Image Baseline PR
tray_icon_initial.png
tray_icon_themed.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_left_click.png
tray_menu_shown.png
tray_notification_displayed.png
tray_notification_themed_icon.png

Matrix: Linux-libappindicator3-dev

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

Matrix: Linux-libayatana-appindicator3-dev

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

Matrix: Windows

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

Matrix: macOS

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

Add support for simulating notification clicks and routing D-Bus notification actions to callbacks.

- Export tray_simulate_notification_click() in tray.h and provide platform implementations: no-op stubs for macOS and Windows, and a working simulator for Linux.
- Introduce TrayNotificationHandler (src/tray_notification_handler.h) to handle org.freedesktop.Notifications ActionInvoked signals and invoke the stored callback when the "default" action is triggered.
- Integrate the handler into the Linux tray: create/connect a single handler per QApplication, store callback and notification ID before calling Notify, set up a fallback that connects QSystemTrayIcon::messageClicked when D-Bus is unavailable, and clean up/disconnect the handler on app destroy.
- Also connect QSystemTrayIcon::activated to popup the context menu on left/middle clicks (fixes missing menu on left-click).
- Add unit tests verifying left-click menu popup and that notification callbacks fire when simulated (tests call tray_simulate_notification_click()).

These changes ensure notification clicks are handled consistently for D-Bus-dispatched notifications and add a test hook for exercising the click behavior.
Expose tray_set_log_callback in the public API and implement it on Linux to forward Qt diagnostic messages to a user-provided callback (NULL restores default behavior). Add a Qt message handler and global callback state, and route qInstallMessageHandler accordingly; provide no-op stubs on macOS and Windows since Qt logging is not used there. Improve context-menu positioning by calculating a sensible popup point from the tray icon geometry (falling back to cursor position) and use it when showing menus. Defer D-Bus ActionInvoked connection via QTimer::singleShot to avoid QSocketNotifier warnings when the tray runs in a std::thread, and add a few related include adjustments and minor activation handling cleanup.
Detect Wayland sessions and improve context-menu placement by prioritizing tray icon geometry, then using QCursor on Xorg, and falling back to a screen-geometry heuristic on Wayland (inferring panel edge from full vs available geometry). Defer showing the menu with QTimer::singleShot(0) and call QApplication::setActiveWindow before popup() so pointer grabs and XGrabPointer behavior work reliably; avoid showing the menu if it's already visible. Also avoid clearing the tray icon by only setting it when the resolved QIcon is valid, preventing spurious "No Icon set" warnings.
Replace QApplication::setActiveWindow with menu->activateWindow() to give the menu X11 focus before popup() and clarify the comment. Include QPixmap and change icon resolution logic: when the icon string refers to an existing file, load a QPixmap and add it to a QIcon immediately (avoiding QIcon's lazy loading that leaves availableSizes() empty and can produce a blank tray icon with Qt6 SNI). Fall back to QIcon::fromTheme() when the file doesn't exist. Keep guarding against setting null icons.
@ReenigneArcher ReenigneArcher force-pushed the fix/linux/migrate-to-qt-tray branch from acf7230 to bd83ea9 Compare March 26, 2026 14:11
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
9 New issues
9 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

1 participant