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

Support "minimise to tray" on Linux #111

Closed
Betterbird opened this issue Jan 15, 2023 · 69 comments
Closed

Support "minimise to tray" on Linux #111

Betterbird opened this issue Jan 15, 2023 · 69 comments

Comments

@Betterbird
Copy link
Owner

From #20 (comment):

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 (Issue #20) 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.

@Betterbird Betterbird changed the title Support "minimise to tray" Support "minimise to tray" on Linux Jan 15, 2023
@Zahrun
Copy link

Zahrun commented Jan 15, 2023

Yes, I actually got to know about Betterbird when I was looking for good alternatives for Thunderbird closing to tray on linux. MinimizeToTray Reanimated has versions that work with Thunderbird 60.0 - 63.*, I think it is not maintained anymore. I used to use Birdtray, but had some issues with it. I am currently using SysTray-X, and it is fine on X11 but does not work on Wayland. Since now we have a tray icon that is working properly on Linux systems, I wish that Betterbird could support close to tray. It seems more attainable now.

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.

@Betterbird
Copy link
Owner Author

Betterbird commented Jan 16, 2023

So we've made a start here:
https://github.com/Betterbird/thunderbird-patches/blob/main/102/features/13-feature-linux-minimise-to-tray.patch

Sadly we ran into AyatanaIndicators/libayatana-appindicator#4:
Currently there is no way to get notified for clicks onto the app indicator, that is, the system tray icon. With the patch applied, the window is hidden and the systray icon is displayed, the "minimise to tray" effect, but clicking the icon doesn't maximise/unhide again since we can't get a click event/signal.

We'll see how this can be solved in libayatana-appindicator.

@felixoi
Copy link

felixoi commented Jan 16, 2023

How about adding a menu instead with a "Show/Hide" button? That was working out even for GNOME in the official appindicator demo.

@Betterbird
Copy link
Owner Author

How about adding a menu instead with a "Show/Hide" button? That was working out even for GNOME in the official appindicator demo.

Well, any additional text strings bring localisation issues. Two clicks instead of one are also clumsy and they are also different to what the Windows version does.

Yes, people have been adding menus to work around the non-ability of getting the clicks, see here for example:
https://bugzilla.redhat.com/show_bug.cgi?id=1319869
https://bugs.launchpad.net/ubuntu/+source/libappindicator/+bug/1910521
electron/electron@f7adf85 <-- this shows the dummy menu.

We're in a better position: We use a fork of the library, so with the right knowledge (which we don't have) we could just add code for the click event.

@renyhp
Copy link

renyhp commented Feb 17, 2023

I landed here after installing Betterbird on linux and finding out there is still active development in trying to make a systray fully work (thanks!). I will just leave my comment here for anybody else that is in my same situation and immediately wants something that gives at least some basic functionality: gyunaev/birdtray fully works with Betterbird, once you set the correct path to the betterbird executable and use Betterbird as the window pattern.

@Betterbird
Copy link
Owner Author

Yes, we have a patch that works in minimising the windows to the tray:
https://github.com/Betterbird/thunderbird-patches/blob/main/102/features/13-feature-linux-minimise-to-tray.patch
Sadly due to functionality missing from the upstream libayatana-appindicator, we can't get clicks onto the system tray icon to restore the window, so with the patch it's: Minimise once, not able to restore, kill the process 😭

We made an effort here https://bugs.kde.org/show_bug.cgi?id=465438 to get some idea on how to implement that, so far to no avail. We need to start an initiative on one of the KDE mailing lists as suggested in the bug, [email protected].

@Zahrun
Copy link

Zahrun commented Apr 10, 2023

I found that the Qt library provides the QSystemTrayIcon Class https://doc.qt.io/qt-6/qsystemtrayicon.html, which provides an icon for an application in the system tray.

The QSystemTrayIcon class can be used on the following platforms:
All supported versions of Windows.
All Linux desktop environments that implement the D-Bus StatusNotifierItem specification, including KDE, Gnome, Xfce, LXQt, and DDE.
All window managers and independent tray implementations for X11 that implement the freedesktop.org XEmbed system tray specification.
All supported versions of macOS.

It has an "activated" signal which gives an "ActivationReason", which can be of type "QSystemTrayIcon::Trigger": The system tray entry was clicked

@rauldipeas
Copy link

@Betterbird do You know the KDocker?

I'm using it to provide a tray icon to Betterbird and Thunderbird.

Maybe You can use something from the KDocker code to provide a decent solution.

@Betterbird
Copy link
Owner Author

Thanks for the suggestion. We're using AyatanaIndicators/libayatana-appindicator, and that's not moving forward, see latest comment here:
AyatanaIndicators/libayatana-appindicator#4 (comment)

@Zahrun
Copy link

Zahrun commented May 20, 2023

@Betterbird do You know the KDocker?

I'm using it to provide a tray icon to Betterbird and Thunderbird.

Maybe You can use something from the KDocker code to provide a decent solution.

KDocker does not support Wayland atm, so it’s not very future-proof. I would rather repeat my suggestion: QSystemTrayIcon. I understand that it would take some work to replace the existing code that uses libayatana-appindicator though.

@Betterbird
Copy link
Owner Author

Activation support for system tray icons has arrived, see AyatanaIndicators/libayatana-appindicator#71.

Sadly it's only working for KDE, so we can implement "minimise to tray" on KDE only. Thoughts? Anyone willing to test?

@Zahrun
Copy link

Zahrun commented Aug 26, 2023

I'm willing to test this on KDE

@Betterbird
Copy link
Owner Author

Thanks, I'll get it done in the next 48 hours. We already have a patch that is 95% complete:
https://github.com/Betterbird/thunderbird-patches/blob/main/102/features/13-feature-linux-minimise-to-tray.patch

@Betterbird
Copy link
Owner Author

Betterbird commented Aug 26, 2023

OK, like on Windows, you can now enable this under "System Integration":

image

We tested the minimise part, we can't test the restore part since we currently don't have KDE. It's possible that it crashes on restore, that is, click onto the system tray icon after minimising it. If it's not minimised, a click onto the system tray icon should just bring the window to the foreground.

Please run Betterbird from a terminal window, if it doesn't even mininise to tray, it will tell you why.
Download: http://www.betterbird.eu/downloads2/betterbird-115.1.1-bb9-minimise-to-tray.en-US.linux-x86_64.tar.bz2

P.S.: In case anything works, does a maximised window get restored as non-maximised? That could be fixed.

@Zahrun
Copy link

Zahrun commented Aug 27, 2023

Thank you for that. It works. The only catch is that I have to click twice on the icon before the window is actually restored. It seems that the first time it tries to restore but then immediately goes back to tray. The second time, the window is restored fine.
https://github.com/Betterbird/thunderbird-patches/assets/10415894/59ae1590-bf2d-4f5f-967f-42cbd8f4966d

PS: with the extension "Minimize on Close", we also get the same behavior on close: close to tray, which is nice

PPS: my first test and video were in X11. It also works the same in Wayland

PPPS: yes, maximised window get restored as non-maximised

@Betterbird
Copy link
Owner Author

Betterbird commented Aug 27, 2023

Thanks for testing. I can't see the "first time it tries to restore but then immediately goes back to tray", maybe it's not captured in the video.

There was a question you didn't answer: If it's not minimised, a click onto the system tray icon should just bring the window to the foreground. But I realise that for testing that, you need to set pref mail.biff.show_tray_icon_always first.

Looks like I have to get a KDE desktop somehow 😞.

P.S.: OK, got a KDE desktop now. So yes, if not minimised, a click on the "always on" icon activates the window. That's good. I can also see the "failed" attempt to restore which is not in the video.

@Zahrun
Copy link

Zahrun commented Aug 27, 2023

It works perfectly in KDE on X11 and Wayland. Just one question: is there an option to start betterbird minimized in the tray?

@Betterbird
Copy link
Owner Author

Betterbird commented Aug 27, 2023

Yes, set pref mail.startupMinimized (no UI for that one). In our testing that also works, but we've just made another tweak to make it more stable. Let me know if it doesn't work and I'll send another binary.

@felixoi
Copy link

felixoi commented Aug 27, 2023

I'll also leave my 2 cents here. Disclaimer: I know it should only work for KDE but I tried it with GNOME explicitly (by adjusting the config value). Even if there are no tooltips for GNOME I'd like to have this as feature.
This first take was very glitchy and not reliable at all. This one has reproducible behavior tho.

Here is a desktop recording:
https://github.com/Betterbird/thunderbird-patches/assets/14966472/edaf9fee-258d-4204-bf67-5e123fbe3f8a

  1. Opening the application back up from the tray somehow opens it but in background (only visible in the taskbar). I'll have to actually select it in the taskbar again so it's shown.
  2. Only the first time it's working with one click, after having it opened back from tray once I'll have to double click the tray icon for the next times
  3. Seems like it's always opening to the same location on the screen, not the one selected before

@Betterbird
Copy link
Owner Author

Betterbird commented Aug 27, 2023

Gotta love those different desktops. Did the first version ever restore the window without having to click on the taskbar? We changed the code to restore the window, the first code was more Gtk-ish, so perhaps this works better.

The aim is to ship this in 115.2.0 in a few days, so there's not much time for experiments. I can compile a "take 3" later on for you to check.

P.S.: what string did you add to the pref? "gnome" or something longer?

@felixoi
Copy link

felixoi commented Aug 27, 2023

The first one was very unreliable as I said, so I can't really tell you what it did when 😄
Yes I just replaced "kde" with "gnome" in my case as I didn't know if adding works with commas or something different.

@Betterbird
Copy link
Owner Author

Betterbird commented Feb 9, 2024

If I see it correctly, Wayland isn't fully supported by the Mozilla platform, see all the "Depends on" in this meta bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=635134

That the window doesn't minimise is due to the fact that internally a "sizemodechange" is not received. We debugged this with another BB user, who in the end reported this upstream bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=1872790

You can repeat the steps in the description of this bug, that is, paste
top.window.addEventListener("sizemodechange", () => console.log("sizemodechange received"))
into the error console and see what gets logged when minimising the window.

@githubuser6000
Copy link

top.window.addEventListener("sizemodechange", () => console.log("sizemodechange received"))

Yeah it doesn't print anything :/

@lockie
Copy link

lockie commented May 30, 2024

This doesn't seem to work on tiling window manager (namely, XMonad). Clicking the icon does not do anything, closing the window, well, closes Betterbird instead of minimizing to tray. Welp, back to Thunderbird then.

@Betterbird
Copy link
Owner Author

Do you use Wayland? Anyway, TB doesn't offer the feature.

@lockie
Copy link

lockie commented May 30, 2024

Nope, plain old X11.
I know, but neither does BB.

@Betterbird
Copy link
Owner Author

What you write is rather irritating. Yes, BB does offer system tray support incl. minimise to tray on known configurations and it's also documented at https://www.betterbird.eu/expert-tips/

System Tray support (Windows and Linux)

The following is supported:

OS / Desktop System tray System tray always Tooltip with folder list Minimize to tray
Windows Yes Yes Yes Yes
Linux / KDE Yes Yes Yes Yes
Linux / Gnome Yes Yes No Yes(*)
Linux / Cinnamon Yes Yes Yes No
Linux / Mate Yes Yes Yes Yes(**)
Linux / Xfce Yes Yes Yes Yes

"Minimize to tray" on Linux from version 102.5.0 and 115.2.0. 102.5.0 only supports KDE and Gnome.

(*) For Gnome you need to install the "AppIndicator and KStatusNotifierItem Support" extension. Double-click to activate.
(**) The Mate desktop is supported from BB 115.3.1-bb14 build after 2 October 2023.

Relevant preferences:

  • System tray: mail.biff.show_tray_icon (has UI)
  • System tray always: mail.biff.show_tray_icon_always (no UI)
  • Minimize to tray: mail.minimizeToTray (has UI)
  • Linux only: mail.minimizeToTray.supportedDesktops ("kde,gnome,xfce,mate") and mail.minimizeToTray.desktopsGtkWindowPresentWithTime (special activation, "mate") (no UI)
  • Start minimized: mail.startupMinimized (no UI)
  • Windows only: Show count in taskbar badge: mail.biff.show_badge (has UI)
  • Show new count: mail.biff.use_new_count_in_badge (has UI)
  • Only count unread message in inboxes: mail.notification.count.inbox_only (no UI)

You will understand that it's impossible to support all possible Linux variations.

Which desktop are you using and have you started BB from the command line to see which desktop it reports. If that's not in the list of supported desktops, it won't work.

@dark-penguin
Copy link

@Betterbird He just means, "Since it's not working for me, and this is the only feature I needed, I'll stick with the unpatched Thunderbird for now". 🙂

@Betterbird
Copy link
Owner Author

I know what he means. But it's written as a threat "back to Thunderbird then" and a false statement "neither does BB".

@lockie
Copy link

lockie commented May 30, 2024

@Betterbird I'm sorry I've offended you, I was just stating the fact that I'm not going to use your product since it does not work for me and, I guess, for a whole lot of professional Linux users since tiling window managers occupy a lot of places in the lists of most popular desktop environments, e.g. this one — it even has one on 2nd place.
Is it ok for me to open separate issue regarding tray icon on tiling window managers and help with resolving it?

@Betterbird
Copy link
Owner Author

First of all, there is some confusion here. For system tray and minimise to tray to work, your Linux desktop needs to provide a system tray. As you can see in #111 (comment), some desktops support this, Gnome only after an additional software installation.

Reading https://askubuntu.com/questions/18078/what-is-the-difference-between-a-desktop-environment-and-a-window-manager, there is a difference between desktop and windows manager. We're running Xfce with xfwm4, KDE with KWin, Mate with Metacity and Gnome with "GNOME Shell".

The system tray support depends on the desktop environment. That's why BB on Linux, when run from the command, line reports the DE is has detected.

Why don't you read the comment above again, run BB from the command line and see which DE it reports? You can add the DE name string to pref mail.minimizeToTray.supportedDesktops and see whether it works.

BTW, your comment #111 (comment) is unclear. Which icon do you click? The close button will always close the application. And minimise to tray needs to be enabled via an option.

Over to you to provide the necessary details instead of a "doesn't work".

@dark-penguin
Copy link

@lockie Tray functionality sucks because it's implemented via GTK3 - and we can't change this because that's what Thunderbird uses. And GTK3 is that famous one when the Gnome devs decided that they have their vision for the future of desktop computing, and that future does not have trays at all (and made Gnome 3). 😵‍💫 So the only way to have an icon is to use something called libayatana-appindicator, which does not make things easy either. And on top of all that, each DE has their own tray implementation... and there are multiple different protocols...

If you are curious to see what we had to go through to make this work at all, and pick up where we left, there are a few issues around the time of this one (numbered something about 100-111 IIRC). There's even a minimal test source to fiddle around with. There are a couple different issues for different DEs, so we had to implement an option to switch between the behaviour that doesn't work on KDE and the one that doesn't work on MATE. 😵 So if you can figure out how to get tray icons working in your DE, and it doesn't break the other ones too much, then it could potentially be added as well. (I'm not a core dev though - I just did the same for MATE to get it working for me. 🙂 )

@Betterbird
Copy link
Owner Author

Right.

Since competition is good for business, the TB folks have now started to implement something themselves:
https://bugzilla.mozilla.org/show_bug.cgi?id=18732
https://phabricator.services.mozilla.com/D211940
https://github.com/thunderbird/linux-sys-tray

Good luck to them.

@lockie
Copy link

lockie commented May 31, 2024

Right, I wasn't providing enough details. I'm using polybar panel to display a system tray. Betterbird correctly identifies my desktop as xmonad, and I already have added it to mail.minimizeToTray.supportedDesktops. Thing is, tiling window managers do not have the concept of "minimizing" windows per se, so it'd be nice if BB would minimize by clicking on the icon. Or perhaps minimize to tray instead of closing when the window gets the close event.

@dark-penguin
Copy link

Thing is, tiling window managers do not have the concept of "minimizing" windows per se

Then that's the problem. @Betterbird refuses to make it minimize on tray icon click, in order to keep the behaviour consistent with Windows, so if you don't have a way to issue a "minimize" command normally, there's no other way to do it.

I do remember some discussion about minimizing instead of closing, but I don't remember @Betterbird 's position on it...

@Betterbird
Copy link
Owner Author

Hmm, not enough details. You haven't stated whether "minimise to tray" is actually selected as an option:
image

You've added xmonad to pref mail.minimizeToTray.supportedDesktops and then what happened? But you're saying that your wm doesn't have a concept of minimising? How do you want to minimise if the wm doesn't support it? Behind the scenes, we're using libayatana-appindicator and that's doing a bunch of Gtk and dbus calls at the backend. If the receiving wm or DE doesn't do the "right thing", we won't be able to fix it.

Next you talk about "the icon", but there are several, at least one to minimise and one to closes.

With the add-on https://addons.thunderbird.net/en-us/thunderbird/addon/minimize-on-close/ you can change the action of the close icon, the app will minimise instead, but then again, I don't know whether minimise means anything in you wm.

@lockie
Copy link

lockie commented May 31, 2024

The Minimize on close addon looks promising, but it does nothing on a WM - the window just blinks and then reappears again.

@Betterbird
Copy link
Owner Author

Betterbird commented May 31, 2024 via email

@doronbehar
Copy link

I see that this thread is old, but a alive. I too can't get system tray support to work. Here are my settings:

image

Any my betterbird version:

image

I'm using NixOS (Thanks to @SuperSandro2000 who packaged it for us). I also have a full build log of Betterbird to share (sharing it so you could maybe find a patch we are missing or something alike):

https://cache.nixos.org/log/q6cw2g05v27jypqyni60rpnzvdjsp11i-betterbird-unwrapped-115.9.0.drv

On the contrary, the flatpak version of this does show the systray, and together with minimize-on-close the experience is perfect.

Still I'd like to get this working natively on NixOS.

@Betterbird
Copy link
Owner Author

I think that if the FlatPak works but the NixOS build doesn't then that wasn't built correctly. Hard to say. Have you tried our binary release (.tar.bz2 files)?

Looks like these patches
12-feature-linux-systray.patch
12-feature-linux-systray-compile.patch
12-feature-linux-systray-tooltip.patch
12a-feature-linux-systray-tooltip.patch
12-feature-linux-systray-no-root.patch
12-feature-linux-systray-example.patch
13-feature-linux-systray-activate.patch
13-feature-linux-systray-activate-xfce.patch
13-feature-linux-systray-activate-mate.patch
12+13-feature-linux-systray-incl-minimise.patch
were successfully applied. It's strange though that these lines occur:

Checking patch third_party/appindicator/app-indicator.c...
Hunk #1 succeeded at 125 (offset 1 line).
Hunk #2 succeeded at 708 (offset 1 line).
Hunk #3 succeeded at 1366 (offset 2 lines)

I don't know how the patches are applied, let's assume the patches all applied and only the process is more noisy.

@doronbehar
Copy link

@Betterbird I suspect that this is related to Ayatana dependency not available during the build. For sure our package libayatana-appindicator (built from this source), is not added to the build. If this is indeed the reason. I'm surprised that the build didn't fail due to this missing dependency. I'm also wondering why didn't the build log mention even a search for this dependency.

@Betterbird
Copy link
Owner Author

No. We include the library ourselves.

@doronbehar
Copy link

I think that if the FlatPak works but the NixOS build doesn't then that wasn't built correctly. Hard to say.
...
It's strange though that these lines occur:

Checking patch third_party/appindicator/app-indicator.c...
Hunk #1 succeeded at 125 (offset 1 line).
Hunk #2 succeeded at 708 (offset 1 line).
Hunk #3 succeeded at 1366 (offset 2 lines)

This is how we do it:

https://github.com/NixOS/nixpkgs/blob/9b19ff75c0338513ee5732ab8ebfd58ac7e5a770/pkgs/applications/networking/mailreaders/betterbird/default.nix#L56-L95

@Betterbird
Copy link
Owner Author

OK, the git apply -v makes it more noisy. I'm not thrilled that you remove 14-feature-regexp-searchterm.patch. In the current version there are more patches relying on ICU.

Other than that, I can't tell why the system tray stuff doesn't work.

@doronbehar
Copy link

OK, the git apply -v makes it more noisy. I'm not thrilled that you remove 14-feature-regexp-searchterm.patch. In the current version there are more patches relying on ICU.

Other than that, I can't tell why the system tray stuff doesn't work.

Maybe @SuperSandro2000 will have a clue 🙏.

@MarsAstro
Copy link

The minimize option doesn't seem to work right on Linux Mint 22 Cinnamon edition either. I've installed Betterbird via the Software Manager (Flathub), and with the option on minimizing leaves the app on the bar instead of moving it to tray.

@Betterbird
Copy link
Owner Author

Betterbird commented Jul 30, 2024 via email

@MarsAstro
Copy link

Cinnamon doesn't work: http://www.betterbird.eu/expert-tips/ Thanks for confirming.

Ah, I see! Is this a limitation with the distro, or is it something that could potentially be fixed in future updates?

@Betterbird
Copy link
Owner Author

Betterbird commented Jul 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants