coldfix / udiskie

Automounter for removable media
MIT License
884 stars 54 forks source link

Tray icon on Wayland #199

Closed Weishaupt closed 3 years ago

Weishaupt commented 4 years ago

I'm trying to run udiskie with a tray icon on wayland, but this fails with the following error

$ udiskie -t

(udiskie:19307): Gtk-CRITICAL **: 15:13:21.132: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed

My setup

coldfix commented 4 years ago

Hi,

I have little experience with wayland, but I will try to check up whether I can reproduce this during the weekend.

Do you have any issues with other applications displaying tray icons?

Is this an actual crash (program terminates) or is it just some message appearing as output?

Best, Thomas

Weishaupt commented 4 years ago

I don't have issues with other tray icons (udiskie is the only GTK-based one though). Apart from the tray udiskie seems to work. At least it isn't crashing, only the warning is produced and no tray icon is displayed.

coldfix commented 4 years ago

I have now tried running sway+waybar, and I could reproduce your problem, but I also had a bad experience apart from that:

 `(kalu:61876): Gtk-CRITICAL **: 11:41:15.254: gtk_status_icon_set_from_icon_name: assertion 'GTK_IS_STATUS_ICON (status_icon)' failed`

It could be related to this comment from the swaywm wiki:

There are two standards for status icons: XEmbed and StatusNotifierItem (SNI). XEmbed is legacy and unimplemented in Sway. SNI is supported by swaybar. If your app uses XEmbed, the status icon won't show up. You should ask them to upgrade to SNI.

udiskie implements tray using GtkStatusIcon as well as AppIndicator3 (using the --appindicator option). Neither shows up. I don't know for either option whether they are based on xembed or sni, or if they can adapt to what's available.

Therefore, I'm sorry that this is a wontfix from my side so far, but if you happen to figure out the problem, I'm happy to accept a pull-request or hints for patching.

Best, Thomas

robertjk commented 4 years ago

I came for the same issue, as I'm getting the same error on sway:

$ udiskie --tray

(udiskie:115048): Gtk-CRITICAL **: 00:04:54.083: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed

It could be related to this comment from the swaywm wiki:

There are two standards for status icons: XEmbed and StatusNotifierItem (SNI). XEmbed is legacy and unimplemented in Sway. SNI is supported by swaybar. If your app uses XEmbed, the status icon won't show up. You should ask them to upgrade to SNI.

udiskie implements tray using GtkStatusIcon as well as AppIndicator3 (using the --appindicator option). Neither shows up. I don't know for either option whether they are based on xembed or sni, or if they can adapt to what's available.

libappindicator says it uses KSNI. What is that and how is that different from SNI that swaywm supposedly supports, I don't know.

soyuka commented 4 years ago

Hi, same issue brought me here

udiskie -v  -t --appindicator

Works! Just make sure you have libappindicator-gtk3 installed.

coldfix commented 4 years ago

thanks @soyuka!

After your comment, I realized the --appindicator flag is effective only if also providing --tray. With this the udiskie appindicator icon shows for me too. I will change the behaviour so --appindicator is sufficient.

@Weishaupt @robertjk Can you confirm that this works for you as well?

Best, Thomas

robertjk commented 4 years ago

It doesn't fully work for me. Yes, the icon is displayed:

20200313_10h42m06s_grim

But when I open the context menu it's totally unreadable:

20200313_10h42m22s_grim

I installed libappindicator-gtk3 package (Arch) and ran by udiskie --automount --tray --notify --appindicator &. I'm running Sway and Waybar.

coldfix commented 4 years ago

Thanks for the update. I have seen similar issues with the udiskie menu not displaying correctly when using the appindicator within my usual environment. For some reason, it seems to work under sway (but only after clicking two or three times), while another application (kalu) shows the same erroneous behaviour there.

I will leave this open for now and investigate a bit, but I can't promise that I will figure something out.

robertjk commented 4 years ago

I'm running Sway and the above screenshot is from Waybar ran in Sway. Cool, let's leave it open and maybe at some point it'll get fixed. Thanks for help!

coldfix commented 4 years ago

One part of the issue seems to be that a call to menu.show_all() is missing. With the call it shows properly on my machine.

However the situation is still not resolved, because I noticed that the handler which is supposed be called after the user clicks the icon, before the menu is shown, never gets called, and therefore doesn't update the menu.

I also noticed that the following message appears when using appindicator:

Gdk-CRITICAL **: 18:42:33.305: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed

Can't trace this so far.

coldfix commented 4 years ago

Update on my interim findings, mostly for future-me:

For lack of a proper mechanism in the AppIndicator3 AP itself, udiskie.appindicator currently uses the following hack (which I adapted from comment 15 of this bug report back in the day when I added this module) to subscribe to an about-to-show signal:

        dbusmenuserver = self._indicator.get_property('dbus-menu-server')
        self._dbusmenuitem = dbusmenuserver.get_property('root-node')
        self._conn = self._dbusmenuitem.connect('about-to-show', self._on_show)

Today, this signal:

Furthermore, via this signal and Indicator.get_property we unfortunately have access only to very restricted versions of Dbusmenuitem objects, which unfortunately do not provide the full API of Dbusmenu.Menuitem (in fact basically only connecting signals) (with the full API one might at least hope to achieve our goals).

IMO, AppIndicator is utterly broken because

So, I searched a bit for alternatives, and found the following:

Long term solution may be to migrate udiskie to Qt where more reliable alternatives are available (QSystemTrayIcon/KStatusNotifierItem) that should work with waybar while supporting all features that are needed. Also, I have some quarrels with gtk3+ regarding menus, ease-of-use, and their history of deprecating useful features

It's not just me, others seem to despise appindicator as well, some references:

robertjk commented 4 years ago

Wow, it seems you did quite a research. Respect :bowing_man: .

mox-mox commented 4 years ago

Hi, I just started using udiskie under wayland. Cool project! If you need testing I'd be glad to help :)

somini commented 4 years ago

You can add appindicator: true on the configuration program_options YML to default. The defaults are not updated and the "flat" menu option is ignored, but it's usable at least.

nicewarmcoffee commented 4 years ago

I am having an issue with the tray as well on sway

$ udiskie -t
Not run within X session. 
Starting udiskie without tray icon.

$ cat ~/.config/udiskie/config.yml 
program_options:
    tray: true
    appindicator: true
    file_manager: ranger
    terminal: 'kitty -d'

$ emerge -avp udiskie

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ~] sys-fs/udiskie-2.2.0::gentoo  PYTHON_TARGETS="python3_7 -python3_8" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Tested with both appindicator on and off, same behaviour on both 2.2 and 2.1. Automount/notifications are working perfectly so I have no complaints.

ghost commented 3 years ago

Hello coldfix, I am having the same issue as ultratensai, i.e. I get the Not run within X session. Starting udiskie without tray icon. warning/error when running udiskie --appindicator. I was able to get around it by setting the DISPLAY environment variable, but I don’t know if there’s other code that this workaround could break.

Would you please adjust it to work without $DISPLAY? Possibly check for $WAYLAND_DISPLAY as well, or less, or more (e.g. use appindicator by default when under wayland, I don’t know if it’s a good idea).

This line should definitely be changed: https://github.com/coldfix/udiskie/blob/d7b95ae94cdce5d175e8a49fab1c94f7c8d75961/udiskie/cli.py#L380

coldfix commented 3 years ago

Hi @tiosgz,

ok. I agree that something definitely has to change about wayland support. I currently don't have much time. Might have some time next weekend. Otherwise feel free to submit PRs.

Best, Thomas

coldfix commented 3 years ago

FYI, I have added a workaround that should hopefully display the tray menu correctly from now on, at the (minor) cost of moving the device list into a submenu.

kberkut commented 1 year ago

I'm have error message and icon udiskie not present in tray.

`udiskie -t

(udiskie:4248): Gtk-CRITICAL **: 09:26:44.847: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed`

`community/udiskie 2.4.2-1 [установлен]

Removable disk automounter using udisks`


OS: Arch Linux x86_64 Host: 81NC Lenovo IdeaPad S340-15API Kernel: 6.2.7-arch1-1 Uptime: 14 mins Packages: 1858 (pacman), 14 (flatpak) Shell: zsh 5.9 Resolution: 1920x1080 DE: GNOME 43.3 WM: Mutter WM Theme: Adwaita Theme: Adwaita [GTK2/3] Icons: Faenza [GTK2/3] Terminal: qterminal Terminal Font: DejaVu Sans Mono 12 CPU: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx (8) @ 2.100GHz GPU: AMD ATI Radeon Vega Series / Radeon Vega Mobile Series Memory: 2879MiB / 9886MiB