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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systray linux support #20

Closed
hockeymikey opened this issue Dec 23, 2021 · 113 comments
Closed

Systray linux support #20

hockeymikey opened this issue Dec 23, 2021 · 113 comments

Comments

@hockeymikey
Copy link

I'm using KDE on Arch, but not seeing the systray or anything. Would be a slick feature. I figure the current one is Windows only?

@Betterbird
Copy link
Owner

Betterbird commented Dec 23, 2021

Yes, it's a nice feature, makes my life much easier to see into which folders all the new e-mails were moved via a filter.
Betterbird basically enhances Thunderbirds systray display with a correct count and a tooltip showing the individual folder counts.

Looking at our code

@@ -442,16 +444,19 @@ class MailNotificationManager {
     if (AppConstants.platform == "win") {
       if (!Services.prefs.getBoolPref("mail.biff.show_badge", true)) {
         count = 0;
       }
       if (count > 0) {
         tooltip = await l10n.formatValue("unread-messages-os-tooltip", {
           count,
         });
+        if (this._unreadMailExtra) {
+          tooltip += this._unreadMailExtra;
+        }
       }
       await WinUnreadBadge.updateUnreadCount(count, tooltip);
     }
     this._osIntegration?.updateUnreadCount(count, tooltip);

we only add this._unreadMailExtra to the tooltip in the case of AppConstants.platform == "win", which seem to be incorrect. It could also be added for the general case.

Do you get any unread counts anywhere in KDE? I guess they have a thing that looks like the Windows systray. Could you supply a screenshot? If there is an unread count, I could add the tooltip there as well. Would you be willing to try out a corrected version?

@Betterbird
Copy link
Owner

@hockeymikey
Copy link
Author

There isn't any systray on Linux, on Thunderbird too. Gotta use something like BirdTray or Systray-x but both kinda suck.

@Betterbird
Copy link
Owner

Well, I guess the problem is, that there isn't one Linux, but there are many, and they use many desktops. On Mint, there is a systray:
image
But who knows what the API is to drive it. There is also no "minimise to tray"
image
for Linux, although the old add-on did do something for some Linuxes.

@Betterbird
Copy link
Owner

Actually, if I don't work on Betterbird, I work for a company that has a product that puts something into the Linux systray. Let me find out how they do it. No promised made, this doesn't look so good: https://islinuxabout.xyz/systray/

@Betterbird Betterbird reopened this Dec 24, 2021
@Betterbird
Copy link
Owner

OK, I found it. Our product uses libappindicator with calls like app_indicator_new(), app_indicator_set_status/label/title() and also Gtk calls like gtk_menu_new(), etc. There's even some sample code on how to drive this:
https://github.com/linuxmint/libappindicator/blob/master/example/simple-client.c
Looks like this could be made to work with medium effort. It's handy that those "app indicators" can also have tooltips, so the whole solution could look a lot like on Windows.

@hockeymikey
Copy link
Author

OK, I found it. Our product uses libappindicator with calls like app_indicator_new(), app_indicator_set_status/label/title() and also Gtk calls like gtk_menu_new(), etc. There's even some sample code on how to drive this: https://github.com/linuxmint/libappindicator/blob/master/example/simple-client.c Looks like this could be made to work with medium effort. It's handy that those "app indicators" can also have tooltips, so the whole solution could look a lot like on Windows.

Amazing! Seems promising! I'll maybe research alittle later too. I know Gnome dropped their systray I think but they have addons to bring it back. Think kde and gnome would be the big ones to test on. Maybe xfce too (and any others people can chime in). I can help test and debug any code, littlw code review too even though the code is more unfamiliar territory for me.

@Betterbird
Copy link
Owner

I managed to compile the sample code and yes, it displays an icon in the "systray" (seems to be called application indicator area(?)). I'll tweak it a bit later today and give you a test program to see whether you get the icon. If that works, it can be integrated into Betterbird.

@Betterbird
Copy link
Owner

Betterbird commented Dec 25, 2021

Putting up an icon was easy enough
image
but none of the examples I have show how to do a tooltip. Seems like others have asked the same question:
https://stackoverflow.com/questions/24000840/setting-an-appindicators-tooltip-in-pygtk
They give the impression that it's not supported, however, all the other applications (likely not using app indicators) do show tooltips (as you can see in the image). Sigh.

@Betterbird
Copy link
Owner

Betterbird commented Dec 25, 2021

This stuff is really painful 👎.
I've looked at it for hours and here are the findings:

  1. libappindicator doesn't support tooltips, it's mostly geared around displaying an icon with popup menu.
  2. I haven't see a way to get the Gtk widget from that icon to call gtk_widget_set_tooltip_text()
  3. libappindicator itself uses dbus calls, for example here: https://github.com/linuxmint/libappindicator/blob/a510ab75ba8e0a2f10b5facae430b1ddee2e7b4d/src/app-indicator.c#L2037
  4. Looks like you need to do all the dbus/Gtk programming yourself if you want a tooltip. I haven't yet found the code for the Mint Notification, Update, Network, Volume Control and Clock widgets, all of which display a tooltip. It looks like they do the Gtk programming themselves, like here: https://github.com/linuxmint/cinnamon/blob/990ceea96aef4b70d26586bf3719a91bf1ed4ccc/files/usr/share/cinnamon/cinnamon-settings/bin/ExtensionCore.py#L1017
  5. (That notification/indicator area also seems to be called the "panel".)

@hockeymikey
Copy link
Author

@Betterbird Excellent work. Painful, hopefully there is a way. KDE's implementation is more straight forward: https://api.kde.org/frameworks/knotifications/html/classKStatusNotifierItem.html
https://github.com/ubuntu/gnome-shell-extension-appindicator#missing-features
Yeah, see what you're saying with the tooltip. I looked at it for a few hours, but nothing new that would help you beyond what you found for appindicators.

@Betterbird
Copy link
Owner

Betterbird commented Dec 26, 2021

"Excellent work", no result 😢

I think this needs to be written in terms of dbus/Gtk, like Mozilla code does already a bit:
https://searchfox.org/mozilla-central/rev/42c90d1426f244db74a164a3121e164f601ad439/widget/gtk/MPRISServiceHandler.cpp#834 - using g_dbus_connection_emit_signal(). You can search there for "dbus" and you will find more dbus stuff in the Mozilla code base. Dbus is also a requirement.

BTW, when I said "Mint", I was talking about my XFCE desktop on Mint. It would be good if we could locate the source code of the Notification, Update, Network, Volume Control and Clock widgets, all of which display a tooltip. The other option would be to drill this open: https://sources.debian.org/src/libayatana-appindicator/.
Update: I'm looking into getting and compiling the Debian source. It should just be a matter of sending a "NewToolTip" signal along with the "NewIcon" signal.
Update 2: Following https://www.linuxfordevices.com/tutorials/debian/build-packages-from-source in the
sudo apt build-dep libayatana-appindicator
I run into
The following packages have unmet dependencies: builddeps:libayatana-appindicator : Depends: debhelper-compat (= 13) E: Unable to correct problems, you have held broken packages. (or with aptitude I get this: Unable to satisfy the build-depends: Build-Depends: debhelper-compat (= 13)).
No idea how to solve this. Strangely enough we have people familiar with the Thunderbird/Mozilla code base, no Linux system hackers 😉

The whole thing is so sad, since this (real screenshot, no mock-up) can be done with little code, cutting out the menu and putting the tooltip directly on the icon requires days of development:
image

@Betterbird
Copy link
Owner

Betterbird commented Dec 26, 2021

@hockeymikey: Try this on KDE, does it work? You need to extract the PNG next to the executable.
betterbird-systray-icom.zip

@Betterbird
Copy link
Owner

Through a contact with @sunweaver finally found https://github.com/AyatanaIndicators/libayatana-appindicator and AyatanaIndicators/libayatana-appindicator#17 where tooltips have been added; what a coincidence. I'll check it out.

@hockeymikey
Copy link
Author

@Betterbird What am I supposed to do with the zip? Build it and then what?

@Betterbird
Copy link
Owner

@hockeymikey : Run the executable betterbird-systray-icon. If you don't trust it, you can compile it yourself, source code and Makefile supplied. You need to unzip the PNG into the same directory. From what I've read, you should see the app icon in the systray/panel. I'm working on getting a version with the tooltip in the right spot, and then integrating that in to Betterbird.

@hockeymikey
Copy link
Author

Screenshot_20211227_134825

@Betterbird
Copy link
Owner

OK, so KDE does show the title from app_indicator_set_title (ci, "Test Inidcator") (yes, there's a typo) as "sort of" tooltip. I don't see that on my desktop. Click on the icon, then hover the menu item, how does the tooltip look then? And does that tooltip look different to other tooltips? I managed to build https://github.com/AyatanaIndicators/libayatana-appindicator with the help of the maintainer, now I'll add the new tooltip code from the PR.

@hockeymikey
Copy link
Author

Screenshot_20211227_142117

@Betterbird
Copy link
Owner

Sorry, hover the menu item. How does the tooltip look like? See #20 (comment) for how it looks for me.

@Betterbird
Copy link
Owner

@hockeymikey: Here's the next one to try. No menu, just the desired tooltip. Works (badly) on Mint XFCE: AyatanaIndicators/libayatana-appindicator#17 (comment)

Here's the archive, executable plus source/makefile:
betterbird-systray-icon-2.zip

@hockeymikey
Copy link
Author

@Betterbird That second one does nothing for me.

@Betterbird
Copy link
Owner

Well, the second one is the one that should display the tooltip. Apparently on Kubuntu it works half-way if you run it as sudo:
https://www.thunderbird-mail.de/forum/thread/88737-hilfe-beim-testen-des-systray-panel-indicators-auf-linux/?postID=489690#post489690

So far I haven't see a stable solution, so let's see how AyatanaIndicators/libayatana-appindicator#17 works out. The whole thing goes onto the back burner.

@felixoi
Copy link

felixoi commented Jan 3, 2022

The only stable solution I've found so far for Linux is https://github.com/gyunaev/birdtray. You can configure it to use Betterbird.
It only supports new message count and not a folder list but that's still a lot better than noting.

Manjaro 21.2.1
GNOME Shell 41.2
GTK 3.24.31

@Betterbird
Copy link
Owner

Thanks for the comment, but that's a lot of code and - dare a say - quite some over-engineering (quote: Birdtray checks the unread e-mail status directly by reading the Thunderbird email mork database). The information is there in TB/BB, we just need to display it in the systray which should essentially be <10 lines of code, see AyatanaIndicators/libayatana-appindicator#17 (comment).

@felixoi
Copy link

felixoi commented Jan 3, 2022

Which is absolutely correct I guess! I'd love having it in Betterbird natively and kick that one out! Just wanted to share it with everyone who's searching for a solution which is working out at the time being.

@Betterbird
Copy link
Owner

Here's another test program which simulates the full Betterbird function. It updates icons, title and tooltip.
appindicator-dynamic-test-with-tooltip.zip

I guess it makes no difference on GNOME which doesn't show any text, and it won't make a difference on KDE which displays the title. It does make a difference on one of our Minx/Xfce systems since this now shows a text to go with the icon when hovered.

@Betterbird
Copy link
Owner

Betterbird commented Jan 14, 2023

@hockeymikey @Zahrun @Posi81 @mfschumann : Could you try the test programs from the previous comment and this comment #20 (comment) again on KDE. With and without root. Hover the icon after each change to see whether the text updates.

@mfschumann
Copy link
Contributor

I don't have KDE available, so I have only tested the demos under Gnome and Xfce. The behavior is pretty consistent, the only exception being that Gnome does not show tooltips (this is to be expected as per this comment on the gnome-shell-extension-appindicator repo). The tooltips shown on Xfce do update as intended.

Here are my full results:

demo variant OS DE Run as root? Icon shown? Icon changes as intended? Tooltip shown?
dynamic-test Fedora 37 Gnome 43.2 no no - -
dynamic-test Fedora 37 Gnome 43.2 yes yes yes no
dynamic-test-with-tooltip Fedora 37 Gnome 43.2 no no - -
dynamic-test-with-tooltip Fedora 37 Gnome 43.2 yes yes yes no
dynamic-test Xubuntu 22.04.1 Xfce 4.16 no no - -
dynamic-test Xubuntu 22.04.1 Xfce 4.16 yes yes yes no
dynamic-test-with-tooltip Xubuntu 22.04.1 Xfce 4.16 no no - -
dynamic-test-with-tooltip Xubuntu 22.04.1 Xfce 4.16 yes yes yes yes

@Betterbird
Copy link
Owner

Wow. Thanks! I'd love to see a table like this for KDE. So BB (https://www.betterbird.eu/downloads/LinuxArchive/betterbird-102.7.0-preview.en-US.linux-x86_64.tar.bz2) run as root on Xubuntu/Xfce behaves the same as the last line in the table, right?

@mfschumann
Copy link
Contributor

Wow. Thanks! I'd love to see a table like this for KDE. So BB (https://www.betterbird.eu/downloads/LinuxArchive/betterbird-102.7.0-preview.en-US.linux-x86_64.tar.bz2) run as root on Xubuntu/Xfce behaves the same as the last line in the table, right?

Yes, this BB version run as root on Xfce shows the icon when new mail arrives and updates the tooltip when more mail arrives.

Is there any idea on how to get rid of the run-as-root requirement? I don't think it is a good idea to recommend running BB (or any GUI app) as root.

@Betterbird
Copy link
Owner

Here's our table:

demo variant OS DE Run as root? Icon shown? Icon changes as intended? Tooltip shown?
dynamic-test Mint 20 (VM) Xfce 4.14 no yes yes no
dynamic-test-with-tooltip Mint 20 (VM) Xfce 4.14 no yes yes yes (tooltip: "New Mail x")
dynamic-test Mint 20.2 Xfce 4.16 no no - -
dynamic-test Mint 20.2 Xfce 4.16 yes yes yes no
dynamic-test-with-tooltip Mint 20.2 Xfce 4.16 no no - -
dynamic-test-with-tooltip Mint 20.2 Xfce 4.16 yes yes yes yes (tooltip: "New Mail x")

I expect that KDE users will report that the tooltip is actually the title "Test Icon Title x". BB sets title and tooptip to the same string.

Is there any idea on how to get rid of the run-as-root requirement? I don't think it is a good idea to recommend running BB (or any GUI app) as root.

I hope the KDE people will come and have a look at this since I believe KDE behaves the same. Agreed, a bad idea running BB as root, you'd even have to set the owner of ~/.Xauthority to root in some cases.

Interesting only that older Mint/Xfce didn't have the root requirement.

@easyteacher
Copy link

By commenting out

+ if (priv->menu == NULL) return;
tray icon can show without root.

@Betterbird
Copy link
Owner

Hey, thanks, that appears to work. New test program here:
appindicator-dynamic-test-with-tooltip-new.zip

We'll make another Betterbird preview soon.

@mfschumann
Copy link
Contributor

I can confirm that the change from #20 (comment) makes the icon behave as intended when running as non-root under Gnome 43.2.

@Betterbird
Copy link
Owner

Newest BB preview:
https://www.betterbird.eu/downloads/LinuxArchive/betterbird-102.7.0-preview-14-01-2023.en-US.linux-x86_64.tar.bz2

This should show the icon on Gnome, Xfce and KDE without root privileges. On Xfce and KDE an additional tooltip/title should be displayed as shown in #20 (comment).

@Zahrun
Copy link

Zahrun commented Jan 15, 2023

demo variant OS DE Run as root? Icon shown? Icon changes as intended? Tooltip shown?
14-01-2023 Kubuntu 22.10 KDE no yes yes yes

Very nice! Ideally, I would love to have a "close to tray" option, and even nicer that a click on the tray icon would minimize to tray if betterbird is open and show betterbird if it was closed. But that could be a separate FR.

@Betterbird
Copy link
Owner

A propos "minimise to tray": Check this question and this answer. It's now tracked here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1627479
Getting the indicator in the systray was hard enough and still doesn't work fully on Gnome. Hiding the taskbar "button" to instead show the icon seems even harder. Or is there some API that can do it? Or maybe the code from this add-on https://addons.thunderbird.net/en-GB/thunderbird/addon/minimizetotray-reanimated/ could be used. Anyway, different feature.

Just digging through some old TB bugs: This feature request here is https://bugzilla.mozilla.org/show_bug.cgi?id=18732 from 1999. Worth the 24-year wait.

@Zahrun
Copy link

Zahrun commented Jan 15, 2023

Ok I think the correct issue to discuss that is this one #71

@felixoi
Copy link

felixoi commented Jan 15, 2023

Tested with Manjaro GNOME. Results as expected:

demo variant OS DE Run as root? Icon shown? Icon changes as intended? Tooltip shown?
14-01-2023 Manjaro 22.0.0 GNOME no yes yes no

I do not really need a tooltip like that, so it's no big deal for me. I'm more wondering if we get the "unread/new" message count somewhere? Saw it's available in the taskbar logo for windows but it isn't for linux (at least not for me).
Windows
Implementation of #111 would be very nice too, then the count on the systray icon would make more sense.

@Betterbird
Copy link
Owner

Yes, that's called the task bar badge on Windows. It's only shown for a wide/large taskbar. TB did that in https://bugzilla.mozilla.org/show_bug.cgi?id=715799#c35 with this code:
https://searchfox.org/comm-central/source/mailnews/base/src/WinUnreadBadge.jsm from https://github.com/bstreiff/unread-badge.
That has always been "Windows only".

@Betterbird
Copy link
Owner

@hockeymikey @Zahrun @Posi81 @mfschumann @felixoi : could be please attach some screenshots of the icon in the systray. Currently we supply (old?) standard size of 22px, but that might look bad/fuzzy on some high resolution displays, like seen here:
#20 (comment) or here
https://www.thunderbird-mail.de/forum/thread/88737-hilfe-beim-testen-des-systray-panel-indicators-auf-linux/?postID=489690#post489690 (this was taken with a test program that had a 64px icon and it still looks fuzzy).

We're happy to supply larger icons, of course then running the risk that it will look bad when scaled down. Not sure what the right size should be. Windows uses .ico files which combine various sizes into the one file. Experiments showed that SVGs also appear to work. In theory they should scale well to whatever size is required.

BTW, the 22px size is observed on our Xfce systems and also described here.

@Zahrun
Copy link

Zahrun commented Jan 16, 2023

KDE (panel height set to 36px, it can be set to anything in KDE)
tray icon with message image
tray icon without message image

tray icon when it is "hidden" in the tray drop-down menu
with message image
without message image

I think SVG would be the best option since it would adapt to any size

@Betterbird
Copy link
Owner

OK, yet another test program with SVG coming up.

Uff, KDE breaks the title into multiple lines, that will run into trouble with long folder lists.

@Zahrun
Copy link

Zahrun commented Jan 16, 2023

Hehe no problem, we get a tooltip in that case
image

@Betterbird
Copy link
Owner

So here's the test program with SVGs. I've that's good, I'll ship it in BB.
appindicator-dynamic-test-with-tooltip-svg.zip

Mind you, on our older Xfce 4.14 the SVGs are not clipped properly, on Xfce 4.16 they are.

@felixoi
Copy link

felixoi commented Jan 16, 2023

Tested for GNOME 43 (Manjaro). You can configure the icon size:

Icon large:

Icon small:

So it's indeed not very good quality.

Icons large. Left new demo, right old betterbird included demo.

So it's a lot better.

@Zahrun
Copy link

Zahrun commented Jan 16, 2023

SVG
image
image

image
image

It seems the maximal size possible for icons in the system tray is 136px²:
image

@Betterbird
Copy link
Owner

Betterbird commented Jan 16, 2023

Thanks. OK, let's go with the SVGs. 102.7.0 is shipping today tomorrow. I hope we're finally done here. I need a break before moving onto Issue #111.

@Betterbird
Copy link
Owner

You can download the official version from the BB website now.

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

No branches or pull requests

9 participants