Repository: pwr-Solaar/Solaar

Issue:
Tray Icons don't appear under Wayland when using libappindicator-gtk3 
**Information**
<!-- Make sure that your issue is not one of the known issues in the Solaar documentation at https://pwr-solaar.github.io/Solaar/ -->
<!-- Do not bother opening an issue for a version older than 1.1.0.  Upgrade to the latest version and see if your issue persists. -->
<!-- If you not running the current version of Solaar, strongly consider upgrading to the newest version. -->
- Solaar version (`solaar --version` or `git describe --tags` if cloned from this repository): solaar 1.1.4rc1
- Distribution: Arch Linux
- Kernel version (ex. `uname -srmo`): `5.18.6-arch1-1`

- Output of `solaar show`:

<details>

```
Solaar version 1.1.4rc1

Lightspeed Receiver
  Device path  : /dev/hidraw5
  USB id       : 046d:C539
  Serial       : F4E89C04
    Firmware   : 39.06.B0040
    Bootloader : 02.09
    Other      : AA.BE
  Has 1 paired device(s) out of a maximum of 1.
  Notifications: wireless, software present (0x000900)
  Device activity counters: (empty)

  1: G Pro Wireless Gaming Mouse
     Device path  : /dev/hidraw10
     WPID         : 4079
     Codename     : G Pro
     Kind         : mouse
     Protocol     : HID++ 4.2
     Polling rate : 2 ms (500Hz)
     Serial number: 40B217C0
     Model ID:      4079C0880000
     Unit ID:       40B217C0
        Bootloader: BOT 74.02.B0026
          Firmware: MPM 15.02.B0026
             Other: 
     The power switch is located on the base.
     Supports 28 HID++ 2.0 features:
         0: ROOT                   {0000}   
         1: FEATURE SET            {0001}   
         2: DEVICE FW VERSION      {0003}   
            Firmware: Bootloader BOT 74.02.B0026 AADF85EE714A
            Firmware: Firmware MPM 15.02.B0026 407985EE714A
            Firmware: Other   
            Unit ID: 40B217C0  Model ID: 4079C0880000  Transport IDs: {'wpid': '4079', 'usbid': 'C088'}
         3: DEVICE NAME            {0005}   
            Name: G Pro Wireless Gaming Mouse
            Kind: mouse
         4: WIRELESS DEVICE STATUS {1D4B}   
         5: RESET                  {0020}   
         6: BATTERY VOLTAGE        {1001}   
            Battery: 3926mV, discharging, 70.
         7: COLOR LED EFFECTS      {8070}   
         8: LED CONTROL            {1300}   
         9: ONBOARD PROFILES       {8100}   
            Device Mode: On-Board
            Onboard Profiles (saved): Enable
            Onboard Profiles        : Enable
        10: MOUSE BUTTON SPY       {8110}   
        11: REPORT RATE            {8060}   
            Polling Rate (ms): 2
            Polling Rate (ms) (saved): 2
            Polling Rate (ms)        : 2
        12: ADJUSTABLE DPI         {2201}   
            Sensitivity (DPI) (saved): 1600
            Sensitivity (DPI)        : 1600
        13: DEVICE RESET           {1802}   internal, hidden
        14: unknown:1803           {1803}   internal, hidden
        15: OOBSTATE               {1805}   internal, hidden
        16: CONFIG DEVICE PROPS    {1806}   internal, hidden
        17: unknown:1811           {1811}   internal, hidden
        18: unknown:1830           {1830}   internal, hidden
        19: unknown:1890           {1890}   internal, hidden
        20: unknown:1891           {1891}   internal, hidden
        21: unknown:18A1           {18A1}   internal, hidden
        22: unknown:1801           {1801}   internal, hidden
        23: unknown:18B1           {18B1}   internal, hidden
        24: unknown:1DF3           {1DF3}   internal, hidden
        25: unknown:1E00           {1E00}   hidden
        26: unknown:1EB0           {1EB0}   internal, hidden
        27: unknown:1863           {1863}   internal, hidden
     Battery: 3926mV, discharging, 70.

```
</details>

- Contents of `~/.config/solaar/config.yaml` (or `~/.config/solaar/config.json` if `~/.config/solaar/config.yaml` not present):

<details>

```
Jun 23 18:54:54 arch dbus-daemon[770]: [session uid=1000 pid=770] Activating via systemd: service name='org.a11y.Bus' unit='at-spi-dbus-bus.service' requested by ':1.29' (uid=1000 pid=986 comm="/usr/bin/python /usr/bin/solaar --window=hide")
Jun 23 18:54:54 arch at-spi-bus-launcher[1036]: dbus-daemon[1036]: Activating service name='org.a11y.atspi.Registry' requested by ':1.0' (uid=1000 pid=986 comm="/usr/bin/python /usr/bin/solaar --window=hide")
Jun 23 18:54:54 arch solaar[986]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:54:57 arch solaar[986]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:54:57 arch solaar[986]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:55:01 arch solaar[986]: Lost connection to Wayland compositor.
Jun 23 18:55:01 arch systemd[746]: app-solaar@autostart.service: Main process exited, code=exited, status=1/FAILURE
Jun 23 18:55:01 arch systemd[746]: app-solaar@autostart.service: Failed with result 'exit-code'.
Jun 23 18:55:13 arch dbus-daemon[1215]: [session uid=1000 pid=1215] Activating via systemd: service name='org.a11y.Bus' unit='at-spi-dbus-bus.service' requested by ':1.28' (uid=1000 pid=1407 comm="/usr/bin/python /usr/bin/solaar --window=hide")
Jun 23 18:55:13 arch at-spi-bus-launcher[1450]: dbus-daemon[1450]: Activating service name='org.a11y.atspi.Registry' requested by ':1.0' (uid=1000 pid=1407 comm="/usr/bin/python /usr/bin/solaar --window=hide")
[lee@arch ~]$ journalctl -b -3 | grep solaar
Jun 23 18:39:56 arch dbus-daemon[761]: [session uid=1000 pid=761] Activating via systemd: service name='org.a11y.Bus' unit='at-spi-dbus-bus.service' requested by ':1.29' (uid=1000 pid=980 comm="/usr/bin/python /usr/bin/solaar --window=hide")
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:39:56 arch at-spi-bus-launcher[1027]: dbus-daemon[1027]: Activating service name='org.a11y.atspi.Registry' requested by ':1.0' (uid=1000 pid=980 comm="/usr/bin/python /usr/bin/solaar --window=hide")
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:39:56 arch solaar[980]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed
Jun 23 18:41:36 arch solaar[980]: Lost connection to Wayland compositor.
Jun 23 18:41:37 arch systemd[744]: app-solaar@autostart.service: Main process exited, code=exited, status=1/FAILURE
Jun 23 18:41:37 arch systemd[744]: app-solaar@autostart.service: Failed with result 'exit-code'.

```
</details>


- Errors or warrnings from Solaar:
<!-- Run Solaar as `solaar -dd`, after killing any running Solaar processes.  If any warnings or errors show up, include the output here. -->



**Describe the bug**
When using  the libappindicator-gtk3 library for tray icons, the icons don't appear when auto starting solaar with the ```window=hide flag``` in Wayland. I have removed the package and installed ```libayatana-appindicator``` instead which works, but the question remains as to why it's only seemingly affecting Arch Linux on the distributions tested. It fails to execute the program when logged into a new session in the DE. I note that some distros have deprivcated the libappindicator-gtk3 package in favour of `libayatana-appindicator`, so perhaps this is the way forward regarding what dependencies are shipped and used in the repos for Solaar?

**To Reproduce**
Steps to reproduce the behavior:
1. Install ```libappindicator-gtk3```
2. Reboot/restart DE and check ```journalctl -b | grep solaar```
3. Scroll down to ```arch solaar[986]: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed```

4. See error

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**

KDE Plasma 5.25.1



Discussion:
Does Solaar complain when running with libappindicator-gtk3?  Please run `solaar -dd` in this setup and post the output.
> Does Solaar complain when running with libappindicator-gtk3? Please run `solaar -dd` in this setup and post the output.

The tray icon seems to show up when running it manually either via terminal or application menu. Those GTK errors mentioned above appear on boot/login.

Nothing seems to pop out, here's the output of ```solaar -dd```:

```
19:48:52,142     INFO [MainThread] root: language en_GB (UTF-8), translations path /usr/share/locale
19:48:52,255     INFO [MainThread] logitech_receiver.diversion: GDK Keymap set up
19:48:52,255  WARNING [MainThread] logitech_receiver.diversion: rules cannot access active process or modifier keys in Wayland
19:48:52,255  WARNING [MainThread] logitech_receiver.diversion: cannot create uinput device: "/dev/uinput" cannot be opened for writing
19:48:52,266     INFO [MainThread] solaar.upower: connected to system dbus, watching for suspend/resume events
19:48:52,283     INFO [MainThread] solaar.ui.notify: starting desktop notifications
19:48:52,314     INFO [MainThread] solaar.listener: starting receiver listening threads
19:48:52,319     INFO [MainThread] solaar.listener: receiver event add DeviceInfo(path='/dev/hidraw5', vendor_id='046D', product_id='C539', serial='', release=None, manufacturer=None, product=None, interface=2, driver='logitech-djreceiver', bus_id=3, isDevice=None)
19:48:52,319     INFO [MainThread] logitech_receiver.base: New lock 15
19:48:52,326     INFO [ReceiverListener:hidraw5] logitech_receiver.listener: started with <LightspeedReceiver(/dev/hidraw5,15)> (15)
19:48:52,326     INFO [ReceiverListener:hidraw5] solaar.listener: <LightspeedReceiver(/dev/hidraw5,15)>: notifications listener has started (15)
19:48:52,326     INFO [ReceiverListener:hidraw5] logitech_receiver.base: New lock <_ThreadedHandle(/dev/hidraw5)>
19:48:52,335     INFO [ReceiverListener:hidraw5] logitech_receiver.receiver: <LightspeedReceiver(/dev/hidraw5,15)>: receiver notifications enabled => ('wireless', 'software present')
19:48:52,339     INFO [ReceiverListener:hidraw5] solaar.listener: status_changed <LightspeedReceiver(/dev/hidraw5,15)>: present, No paired devices. (0) 
19:48:52,345     INFO [ReceiverListener:hidraw5] logitech_receiver.receiver: <LightspeedReceiver(/dev/hidraw5,15)>: found new device 1 (4079)
19:48:52,345     INFO [ReceiverListener:hidraw5] logitech_receiver.base: New lock 18
19:48:52,345     INFO [ReceiverListener:hidraw5] solaar.listener: connection Notification(10,1,41,0C,327940) for <Device(1,4079,G Pro Wireless Gaming Mouse,40B217C0)> (mouse)
19:48:52,435     INFO [ReceiverListener:hidraw5] solaar.listener: status_changed <LightspeedReceiver(/dev/hidraw5,15)>: present, 1 paired device. (0) 
19:48:52,481     INFO [ReceiverListener:hidraw5] solaar.listener: status_changed <Device(1,4079,G Pro Wireless Gaming Mouse,40B217C0)>: paired online, {'LINK ENCRYPTED': True, 'BATTERY LEVEL': 60, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY NEXT LEVEL': None, 'BATTERY VOLTAGE': 3920, 'BATTERY CHARGING': False, 'ERROR': None} (0) 
19:48:52,566     INFO [ReceiverListener:hidraw5] logitech_receiver.status: <Device(1,4079,G Pro Wireless Gaming Mouse,40B217C0)> pushing device settings [<Setting([feature:choice] G Pro:onboard_profiles=None)>, <Setting([feature:choice] G Pro:report_rate=None)>, <Setting([feature:choice] G Pro:dpi=None)>]
19:48:52,589    ERROR [ReceiverListener:hidraw5] logitech_receiver.base: (18) device 1 error on feature request {0B2B}: 2 = invalid argument
19:48:52,589  WARNING [ReceiverListener:hidraw5] logitech_receiver.settings: report_rate: error applying value 2 so ignore it (<Device(1,4079,G Pro Wireless Gaming Mouse,40B217C0)>)
19:48:52,601     INFO [ReceiverListener:hidraw5] solaar.listener: status_changed <Device(1,4079,G Pro Wireless Gaming Mouse,40B217C0)>: paired online, {'LINK ENCRYPTED': True, 'BATTERY LEVEL': 60, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY NEXT LEVEL': None, 'BATTERY VOLTAGE': 3920, 'BATTERY CHARGING': False, 'ERROR': None} (0) 
```
In docs/installation.md there is the comment that Solaar installation in KDE you need to have ayatanaappindicator3 installed.  The wording there is confusing so improving it would be useful.  What exactly did you install or remove?  Do you have any suggestions on what this should read?

It may be that running Solaar at startup needs to be done carefully so that required resources are available when Solaar starts.   How do you arrange for Solaar to be run at startup?
The flag `--window=hide` just turns of showing the main window at startup.  Running Solaar with no flags at startup should work the same, except that the Solaar main window should show up.
> In docs/installation.md there is the comment that Solaar installation in KDE you need to have ayatanaappindicator3 installed. The wording there is confusing so improving it would be useful. What exactly did you install or remove? Do you have any suggestions on what this should read?

I removed ```libappindicator-gtk3``` and installed ```libayatana-appindicator``` prior to the discussion and the tray icons appeared on autostart. As per your instructions, I reinstalled ```libappindicator-gtk3``` and removed the other package for debug purposes.

I have a .desktop file at ```/etc/xdg/autostart/solaar.desktop```. It runs fine under Ayatana AppIndicators, it fails with a GTK warning on the default libappindicator-gtk library.
I'm updating the installation documentation to say:

Solaar needs a library to interact with the system tray.  The library that provides this interaction depends on the distribution and window system.  If ayatana appindicator is available then it is best to have this library installed,  e.g., by installing `libayatana-appindicator` or `gir1.2-ayatanaappindicator3-0.1` or similar,  depending on distribution.  Otherwise appindicator can sometimes be used,  e.g., by installing `libappindicator-gtk3` or `gir1.2-appindicator3-0.1` or similar,  depending on distribution.

Does this match your understanding of what is required?
 



> I'm updating the installation documentation to say:
> 
> Solaar needs a library to interact with the system tray. The library that provides this interaction depends on the distribution and window system. If ayatana appindicator is available then it is best to have this library installed, e.g., by installing `libayatana-appindicator` or `gir1.2-ayatanaappindicator3-0.1` or similar, depending on distribution. Otherwise appindicator can sometimes be used, e.g., by installing `libappindicator-gtk3` or `gir1.2-appindicator3-0.1` or similar, depending on distribution.
> 
> Does this match your understanding of what is required?

Looks clear and concise to me. It will save everyone the hassle trying to troubleshoot the tray icons not appearing without the additional libraries installed when using Wayland. 







Resolving patch:
diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py
--- a/lib/solaar/ui/tray.py
+++ b/lib/solaar/ui/tray.py
@@ -326,7 +326,6 @@ def _generate_description_lines():
                 yield '<b>%s</b> <small>(' % name + _('no status') + ')</small>'
             else:
                 yield '<b>%s</b> <small>(' % name + _('offline') + ')</small>'
-        yield ''
 
 
 def _pick_device_with_lowest_battery():


Test patch: