Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add system tray module #87

Merged
merged 8 commits into from Jan 31, 2022

Conversation

christian-schulze
Copy link
Contributor

@christian-schulze christian-schulze commented Jan 29, 2022

This is an attempt to create an SNI based system tray module for nwg-panel.

Progress:

  • dbus watcher
  • dbus host
  • item
  • tray module (showing real app icons)
  • wire in DbusmenuGtk3
  • cleanup and action any feedback

I think the menu's can be implemented by leveraging the libdbusmenu library. There is example python code in the following two tests:

I'm a front-end developer by day so I apologise in advance for butchering the python language 馃槈 All feedback welcome!

This addresses #41

@christian-schulze christian-schulze force-pushed the add-system-tray-module branch 3 times, most recently from d05c0b7 to ada8ee7 Compare January 29, 2022 12:53
@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 29, 2022

Great! I'll give it a try as soon as I settle down behind my desk (tonight).

@nwg-piotr
Copy link
Owner

I managed to launch your add-system-tray-module branch and see a tray icon.

image

Dependencies check: {'light': True, 'brightnessctl': False, 'pamixer': True, 'pactl': True, 'playerctl': True, 'netifaces': True, 'btmgmt': True, 'wlr-randr': True, 'upower': True, 'swaync': True}
Running on sway
Output: eDP-1, position: top, layer: bottom, width: 1920, height: 30
Output: eDP-1, position: bottom, layer: bottom, width: 1920, height: 30
Output: DP-1, position: bottom, layer: bottom, width: 1200, height: 30
Output: HDMI-A-1, position: bottom, layer: bottom, width: 1920, height: 30
host.init(): running dasbus.EventLoop
StatusNotifierHostInterface -> watcher_available_handler
watcher.init(): published org.kde.StatusNotifierWatcher/StatusNotifierWatcher on dbus.
watcher.init(): running dasbus.EventLoop
StatusNotifierWatcher -> RegisteredStatusNotifierItems
StatusNotifierWatcher -> IsStatusNotifierHostRegistered: False
StatusNotifierWatcher -> ProtocolVersion: 
StatusNotifierWatcher -> RegisterStatusNotifierHost: /StatusNotifierHost/0
StatusNotifierWatcher -> RegisterStatusNotifierItem
  service: /org/ayatana/NotificationItem/azote_status_icon
  sender: :1.3410
StatusNotifierWatcher -> item_available_handler
  full_service_name: :1.3410/org/ayatana/NotificationItem/azote_status_icon
StatusNotifierHostInterface -> item_registered_handler
  full_service_name: :1.3410/org/ayatana/NotificationItem/azote_status_icon
Tray -> add_item: {'ItemIsMenu': True, 'Id': 'azote_status_icon', 'Category': 'ApplicationStatus', 'Title': 'azote', 'Status': 'NeedsAttention', 'IconName': '/usr/share/azote/indicator_attention.png', 'AttentionIconName': '/usr/share/azote/indicator_attention.png', 'IconThemePath': '', 'Menu': '/org/ayatana/NotificationItem/azote_status_icon/Menu'}
StatusNotifierWatcher -> RegisterStatusNotifierItem
  service: /org/ayatana/NotificationItem/azote_status_icon
  sender: :1.3410
StatusNotifierWatcher -> RegisterStatusNotifierItem: item already registered
  full_service_name: :1.3410/org/ayatana/NotificationItem/azote_status_icon
tray.update_icon -> icon not found
  icon_name: /usr/share/azote/indicator_attention.png
  search_path: ['/home/piotr/.local/share/icons', '/home/piotr/.icons', '/usr/local/share/icons', '/usr/share/icons', '/usr/local/share/pixmaps', '/usr/share/pixmaps']

@christian-schulze
Copy link
Contributor Author

@nwg-piotr Excellent 馃憤

I see the azote icon was not found so it rendered the fallback icon:

tray.update_icon -> icon not found
icon_name: /usr/share/azote/indicator_attention.png

I'll look into that now.

@nwg-piotr
Copy link
Owner

Great! Will check the progress in the morning. It's 4 am here. :)

@christian-schulze
Copy link
Contributor Author

yikes, sorry if I woke you. FYI missing icon fixed.

@christian-schulze
Copy link
Contributor Author

@nwg-piotr I've managed to get the menu's working! This makes use of the libdbusmenu library mentioned in the description.

I struggled to get python to recognise the gi.repository.DbusmenuGtk3 class. In the end I needed to install the gobject-introspection system library and nuke my python virtual environment, after that magic 馃獎

@christian-schulze christian-schulze changed the title WIP - add system tray module - request for feedback WIP - add system tray module Jan 30, 2022
@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 30, 2022

It looks excellent!

If it comes to virtual environments: they are great, but cause issues, too, at least in PyCharm. Lately I use my system python.

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 30, 2022

flameshot ends up in positional arguments missing:

host.init(): running dasbus.EventLoop
watcher.init(): published org.kde.StatusNotifierWatcher/StatusNotifierWatcher on dbus.
watcher.init(): running dasbus.EventLoop
StatusNotifierHostInterface -> watcher_available_handler
StatusNotifierWatcher -> RegisterStatusNotifierHost: /StatusNotifierHost/0
StatusNotifierWatcher -> IsStatusNotifierHostRegistered: True
StatusNotifierWatcher -> IsStatusNotifierHostRegistered: True
StatusNotifierWatcher -> RegisterStatusNotifierItem
  service: :1.1883
  sender: :1.1883
StatusNotifierWatcher -> item_available_handler
  full_service_name: :1.1883/StatusNotifierItem
StatusNotifierHostInterface -> item_registered_handler
  full_service_name: :1.1883/StatusNotifierItem
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/dasbus/client/observer.py", line 88, in _name_appeared_callback
    callback(name_owner, *callback_args)
  File "/usr/lib/python3.10/site-packages/dasbus/client/observer.py", line 230, in _service_name_appeared_callback
    self._enable_service()
  File "/usr/lib/python3.10/site-packages/dasbus/client/observer.py", line 220, in _enable_service
    self._service_available.emit(self)
  File "/usr/lib/python3.10/site-packages/dasbus/signal.py", line 53, in emit
    callback(*args, **kwargs)
  File "/home/piotr/PycharmProjects/nwg-panel-shulze/nwg_panel/modules/sni_system_tray/item.py", line 69, in item_available_handler
    self.item_proxy.NewIconThemePath.connect(
  File "/usr/lib/python3.10/site-packages/dasbus/client/proxy.py", line 161, in __getattr__
    member = self._get_member(self._get_interface(name), name)
  File "/usr/lib/python3.10/site-packages/dasbus/client/proxy.py", line 223, in _get_interface
    raise AttributeError(
AttributeError: DBus object has no attribute 'NewIconThemePath'.
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/dasbus/client/handler.py", line 133, in _signal_callback
    callback(parameters, *callback_args)
  File "/usr/lib/python3.10/site-packages/dasbus/client/handler.py", line 359, in _signal_callback
    callback(*unwrap_variant(parameters))
  File "/usr/lib/python3.10/site-packages/dasbus/signal.py", line 53, in emit
    callback(*args, **kwargs)
TypeError: StatusNotifierItem.item_available_handler.<locals>.<lambda>() missing 2 required positional arguments: '_icon_name' and '_icon_pixmap'
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/dasbus/client/handler.py", line 133, in _signal_callback
    callback(parameters, *callback_args)
  File "/usr/lib/python3.10/site-packages/dasbus/client/handler.py", line 359, in _signal_callback
    callback(*unwrap_variant(parameters))
  File "/usr/lib/python3.10/site-packages/dasbus/signal.py", line 53, in emit
    callback(*args, **kwargs)
TypeError: StatusNotifierItem.item_available_handler.<locals>.<lambda>() missing 1 required positional argument: '_title'

@christian-schulze
Copy link
Contributor Author

oh cool, so flameshot is doing a bunch of things differently which I need to complete implementing:

  1. Sends the icon as a pixbuf instead of an icon name/path
  2. Does not implement the WindowId property (causing the error you see)
  3. Implements the Tooltip property

These are basically differences in libappindicator and full SNI implementations. I'll get stuck in and fill in the missing pieces 馃憤

@nwg-piotr
Copy link
Owner

Yes, I heard it's a mess. That's why gnome guys gave up on the tray. But people are strangely attached to it, for some mysterious reason.

@christian-schulze
Copy link
Contributor Author

@nwg-piotr yeah its fragmented.

Fixes pushed 馃帀

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 30, 2022

It must be 2:30 am in your place! 馃ぃ

No more problem with the flameshot icon. Good job!

I wonder why I see no Chromium icon. I remember seeing it previously. Same applies to nm-applet.

@christian-schulze
Copy link
Contributor Author

It is 12:45AM so yeah just about time to log off.

I don't use Chromium so can't check yet, but if you're not seeing anything chromium related in the logs then that means its using another protocol other than SNI over dbus. It may well be using the xembed protocol, which this solution definitely does not support.

@christian-schulze
Copy link
Contributor Author

For what its worth, this solution is now very close to feature parity with Waybars tray implementation.

@nwg-piotr
Copy link
Owner

I don't care about the Chomium icon. I never use it residently. But the nm-applet icon does appear in Waybar, if I remember well.

@christian-schulze
Copy link
Contributor Author

christian-schulze commented Jan 30, 2022

Also last before i go to bed...i just tested nm-applet and I see the icon/menu, I ran it like this:

nm-applet --indicator

This instructs it to use the libappindicator lib which is a partial SNI implementation.

@nwg-piotr
Copy link
Owner

Maybe I'm doing something wrong....

@christian-schulze
Copy link
Contributor Author

2022-01-31_00-49

I'll need some info about your environment to help troubleshoot, I'm on arch.

@nwg-piotr
Copy link
Owner

So am I. Just added nm-applet --indicator to autostart. Haven't used it for quite a long time, possibly I'm missing something.

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 30, 2022

It works after restarting sway.

Many thanks for your contribution!

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 30, 2022

Let me know when it's ready to merge. It seems to have no config yet (?).

@christian-schulze
Copy link
Contributor Author

No worries at all, this has been really interesting to work on.

I've got some errors showing after opening/closing the nm-applet menu, so I will fix that tomorrow evening. Will ping you when its ready 馃憤

@christian-schulze
Copy link
Contributor Author

@nwg-piotr unless you have any feedback, I think this is ready to go.

@christian-schulze
Copy link
Contributor Author

Also some interesting reading on the effort to create a new app indicator protocol:
https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/84

@christian-schulze christian-schulze changed the title WIP - add system tray module add system tray module Jan 31, 2022
@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 31, 2022

effort to create a new app indicator protocol

Yes, I saw this last night somewhere on reddit.

Your PR seems not to contain any config GUI. No problem, but please check if these are all keys:

settings["root-css-name"]
settings["inner-css-name"]
settings["icon-size"]
settings["inner-css-name"]
settings["smooth-scrolling-threshold"]

@christian-schulze
Copy link
Contributor Author

Yes those are the ones used, though it works fine without any settings at all.

I'm more than happy to add settings into nwg_panel/config.py, either as part of this PR or I can create another one in the next few days. What do you think?

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 31, 2022

This would take me half an hour... :)

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 31, 2022

The minimum requirement is to add "taskbar" to the known_modules list. I do not want users to edit json manually. But the icon size should be adjustable, too.

@christian-schulze
Copy link
Contributor Author

no worries, config added.

@nwg-piotr nwg-piotr merged commit 4018dd8 into nwg-piotr:master Jan 31, 2022
@christian-schulze
Copy link
Contributor Author

Cheers for merging 馃帀

Happy to address any bugs and improvements anyone has.

@nwg-piotr
Copy link
Owner

nwg-piotr commented Jan 31, 2022

Thanks again for the great module!

I'll need to add the dependency check. As the python-dasbus package comes from AUR, it should be an optional dependency. I'll add some lines to prevent the program from crashing when it's absent.

For use in my flagship, the full shell implementation in ArchLabs Linux, I'll have python-dasbus packaged in the distro-specific repo.

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.

None yet

2 participants