-
Notifications
You must be signed in to change notification settings - Fork 23
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
Clicking the tray icon does not raise the window on Linux #202
Comments
The first line of the report isn't accurate. For KDE/Gnome the window was always brought forward when minimised before. This will have improved via Issue #200 for Gnome and KDE, so even non-minimised windows will now be brought forward. The one missing out is Mate (and likely Cinnamon), it works on Xfce. |
So I've been playing with my Mate installation. Setting
So this is a can of worms of Mate, its windows manager (likely I'm using a different one, IIRC I'm using lightdm since this came with the original Mint/Xfce installation) and the gsettings 👎 💢 🤯 |
I have two machines (a real one and a test one) running different versions of Debian with MATE, and never encountered the "no icon" situation. Are you sure you did a logoff/login after enabling SNI support, and not only after disabling it? But the issue with the window appearing below other windows or not being raised properly is not always reproducible - sometimes it would work a few times, and sometimes it wouldn't. %) Let's see... Hm, it seems like it works correctly at first (appears raised), but it stops working (starts appearing below other windows) after something happens. I did some testing, and I think what causes it to break is "clicking the interface"! Testing setup: I open one folder (one window), start a terminal (one more window), then launch BB from the terminal. -> It appears properly, with an icon (I have "always" enabled) I minimize BB, "do the shuffle" (click folder, click terminal, click folder, click terminal), click tray icon -> BB appears on top of other windows, i.e. properly (This can be repeated multiple times, and it works every time) Next, I click the tray icon (BB appears properly), then click any button in BB ("Write", "Quick Filter", or even simply a different mail folder). Then I minimize BB, "do the shuffle" (this step is important! otherwise no magic happens!), and click tray icon again -> BB appears below the topmost window - between the topmost window and the "next" window! |
I don't see why you need a restart, the UI should be set up after logon. Be that as it may, icons disappeared after restart, reappeared after logoff/logon. I really don't think the experience you've described in the previous comment justifies any more hacky coding effort (of creating and hiding unwanted windows just to pull others forward) on the overall flaky Mate desktop. How about you start a discussion with its maintainers? |
We're more interested in why |
If MATE was the only one with this issue, then I would agree that it doesn't make much sense to pursue. However, people were reporting the same things from both Gnome and KDE too. I'm setting up more test machines. On KDE, the icon does not appear. On Gnome, not only the icon does not appear, but I can't even figure out how to minimize a window. Everything you are describing - including "no icon" - is applicable to all three of them. I'll continue trying other environments. |
No. KDE works fine, activation, window to the foreground. Based on our own testing and user feedback in related tickets. For now we have no intention to action this ticket. |
#198 (comment) |
A trick to confirm that the window is not focused when restored: focus a terminal window before you click the tray icon. After you restore the BB window, press arrow keys on the keyboard, and you'll see that it does not move the highlighting on messages - instead, it falls to the terminal, which appears to be in the background. I'd say MATE does a better job by at least correctly showing the focused window actually on top, which is why this is easier to spot in MATE. :) |
https://docs.gtk.org/gtk3/method.Window.present.html says:
Unfortunately, it does not say what to use instead. So far I've tried:
None of those work. %) I'm looking for a way to raise the window in GTK - something that, allegedly, "just works" in the Python bindings for GTK. |
Interesting research. We tried |
Here is the code I'm using to test what helps. Just put any attempts into the first function. (Is it possible to hide it under a spoiler or something?..)
|
Let's see what the GTK developers can say about this... |
I used to have a Gnome/GIMP account ages ago, now they've changed everything. Please let me know if this ticket moves forward. |
Their Gitlab accepts "Log in with Github", if you want to join. :) |
Hm, that's strange, I just registered there with Github... Maybe I already had an existing account from long ago, that was already bound to Github?.. |
There is an update: https://gitlab.gnome.org/GNOME/gtk/-/issues/6095#note_1843146 |
The Gnome response is disappointing. As you rightly pointed out, the documentation is incomplete and should be fixed. Also, if Gtk offers that function, what would have been wrong in saying: Do x, y and z and for further details, go to the forums. KDE is more helpful, here https://bugs.kde.org/show_bug.cgi?id=464264#c9 they helped me to fix libappindicator, and here https://bugs.kde.org/show_bug.cgi?id=465438#c4 they also suggested to take it to a forum. A few days ago I tested on KDE again. Without minimising BB, so just putting some other window on top, the activation is patchy. Sometimes the window is raised to the front, sometimes the (Windows speak) taskbar button is focused and the window stays where it was. I wonder whether it's worth filing another KDE bug. That said, I think it may be a problem of the window manager. As I wrote, on my test VM I'm using lightdm since that came with Xfce initially. So it doesn't make sense to point the finger at the desktop when it's used with a non-compatible windows manager. EDIT: Note https://bugs.kde.org/show_bug.cgi?id=465438#c8. |
Actually, they did after my clarification. And there is a response on the forum, with a link to StackExchange. So, as I understand it, you are supposed to grab the timestamp from the tray-icon-click event, and pass it to I assume this problem is with GTK, and it does not depend on the window manager. Using |
Without having read the linked articles, how does the call know that
we're not faking the timestamp? Or the WM logs all clicks and we need to
refer to a valid one? By how many milli/micro/nanoseconds?
We have no access to the click event, activation comes via a callback
that triggers when libayatana-appindicator receives activation from the
system tray. The click event is about two levels away.
https://github.com/Betterbird/thunderbird-patches/blob/main/115/features/13-feature-linux-systray-activate.patch
https://github.com/Betterbird/thunderbird-patches/blob/main/115/features/13-feature-linux-systray-activate-xfce.patch
https://github.com/Betterbird/thunderbird-patches/blob/1570b1a3ac4f99edb5e0a531c9f8baec03da892a/115/features/13-feature-linux-minimise-to-tray.patch#L368
|
I'd assume the WM does not care if you're lying. But the timestamp must be between the last event and the current time, otherwise it's either outdated or invalid. Well, would it be possible to traverse those two levels? There are NULLs that seem perfectly suitable to pass it as the only parameter, and you can modify libayatana to do that if I understand correctly. :) This situation is already fixed in GTK4, and |
libayatana-appindicator doesn't see the event either, it gets activated
via the system tray app which does process the click (or double-click on
Gnome), see the first patch I quoted. From their code into ours should be
in the realm of nanoseconds. So no, neither us nor
libayatana-appindicator has access to the raw event.
We can try the "with time" variant with a fake timestamp of the time of
the call. That shouldn't be much later than the time of the click.
However, if the activation happens on button down and there is an
immediate button up or the user clicks and moves, there may be an event
in between. That could make matters worse. We'll try it.
What's the deal with GTK4?
|
GTK4 "just works":
I don't know the specifics of the timestamp stuff - those are just my guesses based on common sense: the timestamp shouldn't be in the future, and it shouldn't be too long in the past. I can't imagine why would the WM check your timestamp for anything else. So I think anywhere between the click and current time should be fine. |
I meant: when does GTK4 ship?
|
December 16, 2020. But the question is not "when does it ship", but "when does Thunderbird migrate to it". %) |
Just to clarify, from the perspective of a GTK development team member:
We are aware that the documentation is a bit iffy, at the moment; the GTK3 docs should be fixed to reflect the For the time being and for GTK3, we recommend using |
As a side note: applications should never fake event serials. Either they should use a serial from the latest event they have, or they should use |
...And by specifying 0, you get the same behaviour as the default So could it be possible to grab a serial from some other event, like for example... the window unminimizing? And then pass that serial to "...and also raise it". |
Yes.
No, because that particular action doesn't necessarily come with an event. You can look at the serial for the event at the top of the event queue, using |
So that's nearly impossible. But how come window activation works just fine in Thunderbird 45 with FireTray... T_T It's just using |
That code looks X11-specific, and I assume it relies on the tray icon being a real windowing system surface embedded into another window using the XEMBED protocol; whereas the crux of this issue seems to be that you're using libappindicator, which normally does not embed windowing system surfaces (except as a fallback) and instead activates processes through D-Bus. |
So we are royally out of luck. Come to think of it... Why do my PyQt applications properly raise when I create a modal messagebox? I mean, of course there might be some Qt magic sauce that would take too much effort to figure out, but isn't a modal messagebox supposed to raise a window? Maybe that would generate some events we could capture? Failing that, maybe there is something else we can do to generate a suitable event? And by the way, how did you solve this problem in GTK4? Maybe that could help us build some workaround. |
Hmm, "except as a fallback"... Another idea is to try and force that fallback - which should also fix the issue with sometimes not working without SNI, and sometimes not working with SNI. |
Or we could avoid using ayatana and use native GTK facilities for a tray icon - they not removed yet in GTK3, are they?.. I can't find any examples newer than GTK2 though. %) |
Look, Betterbird is about improving Thunderbird, and we have a lot of expertise in this area. We don't have any expertise in GTK, D-Bus or all the the other stuff mentioned here. We've chosen libayatana-appindicator beacuse the API was rather simple and it had tooltips and even some activation callback. If you want to replace the code with a different library, feel free to supply patches that do that. The patches we're currently using are all here and they start with Patches to add libayatana-appindicator as third party code, make it compile, add tooltips and a sample program: Integration with BB, mostly in nsMessengerUnixIntegration.cpp: These two patches add activation to libayatana-appindicator, they are from PR 71 Finally we have So if you want to switch from libayatana-appindicator to a different library and adjust nsMessengerUnixIntegration.cpp accordingly, go right ahead. |
Yeah, I'm considering trying it - I have no expertise in GTK or C, but I don't mind learning that as it's generally relevant to me as a heavy Linux user/developer . This is likely not the last time I'm fixing a GTK application. :) Seems like those patches go on top of each other. Is there some development command you are using to apply all patches correctly and then store changes back into patches? It does not look like you're using |
@ebassi Do you have any suggestions about what we could do?
|
You basically need to build the entire application: https://github.com/Betterbird/thunderbird-patches/blob/main/README.md. That uses Mercurial queues and you can replace patches. My suggestion would be to remove the ones you don't want and add changed to the top of the queue. We can do the integration later. |
An interesting observation: I've switched to the "Thunderbird notification" instead of the system one, and now clicking the notification raises the window correctly. So, once we substitute a popup from a separate application with a popup owned by BB, it suddenly works with exactly the same code. I would assume the timestamp gets automatically passed to |
I have no idea how the "system notification" interfaces with TB/BB. On Windows, it isn't any good, so I don't use it. |
I've tried everything I could, and now I'm out of ideas. The problem here is GTK - they have a vision that "the future of computing does not have tray icons", so they've removed tray icon support. There is libayatana to partly make up for that, but it can't send the necessary data to the main application. There is no other library to replace it, and doing it "the old way" via XEMBED is said to "work poorly". I've found some code that seems to create an invisible tray icon, but I don't know how to assign an actual icon to it, or put any actions on that icon. And it seems too complex anyway.
|
And old friend helped me, and seems like this works! I've tried it on two MATE machines and one KDE machine - it works every time! I've only tried my examples and not actually rebuilt BB, but the change is trivial - and it was actually kinda your idea in the very beginning. :) |
I've added another patch on top, will merge that eventually: |
Try this: |
It works!! On MATE and KDE at least! On MATE, with SNI ( |
Be our guest! Thanks for the contribution, the insistance, the research, the testing, etc. This will ship officially in 115.3.1 likely next week. |
起動オプションがマルチモード(--multi)ではなく、メインプロセスでもない 場合はメインプロセスのウインドウを最前面に表示するように起動処理を 変更します。 これはGNOMEをはじめとするGTKアプリケーションに導入されている アプリケーションの一意性の管理(多重起動の防止)に基づいた挙動です。 注意 「ウインドウを最前面に表示する」動作はデスクトップ環境によって 挙動が異なる可能性があります。 参考文献 Betterbird/thunderbird-patches#202
…#1371) 起動オプションがマルチモード(--multi)ではなく、メインプロセスでもない 場合はメインプロセスのウインドウを最前面に表示するように起動処理を 変更します。 これはGNOMEをはじめとするGTKアプリケーションに導入されている アプリケーションの一意性の管理(多重起動の防止)に基づいた挙動です。 注意 「ウインドウを最前面に表示する」動作はデスクトップ環境によって 挙動が異なる可能性があります。 参考文献 Betterbird/thunderbird-patches#202
This happens at least on KDE #198 (comment) , on MATE #198 (comment) , and on Gnome #198 (comment) , regardless of whether the window was previously minimized or not #198 (comment) .
According to Qt docs I remember once reading, functions like
gtk_windows_present()
don't work regardless of the library - probably because they use the same call that window managers ignore for sake of "focus steal prevention". The recommended solution from that same documentation is to create a child window (a simple messagebox will do fine) and then hide it a few milliseconds later (in my experience, 10 ms is enough, but any less might not be). That would raise the window on any window manager.The text was updated successfully, but these errors were encountered: