Bug 3922 - minimize to tray on startup not working
Summary: minimize to tray on startup not working
Status: RESOLVED FIXED
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: Plugins/Notification (show other bugs)
Version: 3.17.5
Hardware: PC Linux
: P3 normal
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2017-11-21 06:47 UTC by Daniel Kirchner
Modified: 2020-06-24 16:38 UTC (History)
2 users (show)

See Also:


Attachments
Prevent notification_toggle_hide_show_window from being called on first run of notification_trayicon_on_activate. (888 bytes, patch)
2017-11-21 06:47 UTC, Daniel Kirchner
no flags Details | Diff
5 seconds delay between after showing the main window again on startup (1.26 KB, patch)
2020-06-22 14:21 UTC, Holger Berndt
no flags Details | Diff

Description Daniel Kirchner 2017-11-21 06:47:07 UTC
Created attachment 1815 [details]
Prevent notification_toggle_hide_show_window from being called on first run of notification_trayicon_on_activate.

The minimize to tray on startup option of the notification plugin is not working for me. Even if the option is enabled, the main window pops up whenever claws-mail is run.

I tracked down the issue to the following: it seems that notification_trayicon_on_activate in notification_trayicon.c is called on startup, which then unconditionally calls notification_toggle_hide_show_window(). Since the notification plugin prevented the main window from being shown on startup, this toggle now shows the main window.

I'm using a dirty workaround adjusts notification_trayicon_on_activate, so that it does not call notification_toggle_hide_show_window() on its first run - I'm attaching the corresponding patch. With this patch claws-mail behaves as desired and indeed starts up as tray icon. However, this dirty workaround is of course not a real solution, especially since it doesn't respect the configuration options, but I hope it can indicate to you what's actually going wrong.

My system is x86_64 Archlinux using a current LXQt Desktop. I've been experiencing the issue for quite a while using different versions of LXQt and LXDE on Archlinux. The issue is present when starting claws-mail from command-line (or menu) as well as when running via autostart.

Thank you very much for looking into this!
Comment 1 Yamashita Ren 2020-01-21 16:18:00 UTC
I confirm this bug on LXQt on Archlinux.

Thanks a lot for this patch ! This issue was driving me mad...
Comment 2 renyhp 2020-04-22 09:42:54 UTC
I confirm I have this bug too on Ubuntu 20.04 GNOME
Comment 3 Daniel Kirchner 2020-06-20 16:55:12 UTC
Any news on this? I've been patching claws-mail like this for years now - and by now there is independent confirmation of the issue. It would be really cool to see this fixed upstream at some point :-). Is there any way to help with that?
Comment 4 Daniel Kirchner 2020-06-20 17:00:03 UTC
The issue is not limited to LXQt/LXDE by the way - over the years I switched over to KDE and I have the same issue there as well...
Comment 5 Michael Rasmussen 2020-06-20 17:33:49 UTC
I assume it concerns Preferences -> Plugins -> Notification -> SysTrayicon
and having checked 'Hide at start-up'?

I have just tested it here and it works as expected.

DE: Mate 1.24.0
OS: Debian Sid
CM: 3.17.5git20
Comment 6 Daniel Kirchner 2020-06-20 17:41:16 UTC
Be sure not to just run claws-mail during an already running DE session (that does in fact work), but as autostart on session login. It most assuredly does *not* work, at least not everywhere.

I'll spend some time to spawn a few VMs with minimal system setups to reproduce the issue and will post the results here.
Comment 7 Michael Rasmussen 2020-06-20 17:53:57 UTC
I haven't tried this special use case so I will have to see what happens next time I login.
Comment 8 Daniel Kirchner 2020-06-20 18:35:08 UTC
Detailed steps to reproduce the issue:

I tested in a default-configured libvirt QEMU/KVM Virtual Machine with a clean Debian 10 netinst installation. During setup I selected all available desktop environments (GNOME, Xfce, KDE Plasma, Cinnamon, MATE, LXDE, LXQt) and I chose sddm as display manager.

After setup I installed claws-mails from git as follows:

  sudo apt-get install build-essential git autoconf automake bison flex libtool pkg-config libglib2.0-dev libgtk2.0-dev gnutls-dev libetpan-dev

  git clone https://git.claws-mail.org/readonly/claws.git
  cd claws
  ./autogen.sh && make
  sudo make install


Now (on KDE plasma) I ran claws-mail, enabled the notifications plugin and in Configuration->Preferences->Plugins->Notification->SysTrayIcon I enabled "Enable Trayicon", "Hide at start-up", "Close to tray" and "Hide when iconified". And closed claws-mail again.

Now I tried the following on each Display Environment:

KDE Plasma:
 - Running "claws-mail" from terminal in a running session works (hides in tray).
 - Enable in System Settings -> Startup and Shutdown -> Autostart -> Add Program "Claws Mail"
 - Logout
 - Login
 - claws mail windows *opens* and does *not* hide in tray.

GNOME:
 - Running "claws-mail" from terminal in a running session does *not* work (opens window, no tray icon).

MATE:
 - Respects autostart as setup in Plasma, but opens claws-mail window on first login.
 - However, exiting and opening again from terminal correctly hides in tray.

Xfce:
 - Running "claws-mail" from terminal works (hides in tray).
 - "Settings Manager -> Session and Startup -> Application Autostart -> Add" command "claws-mail".
 - On next login: works perfectly, claws-mail correctly hides in tray.


Cinnamon:
 - Respects autostart as setup in Plasma, but opens claws-mail window on first login.
 - Exiting and starting claws-mail again does not work either (opens a window).


LXDE:
 - Running "claws-mail" from terminal in a running session works (hides in tray).
 - "Preferences->Desktop Session Settings->Automatically Started Applications" enable "claws-mail" entry.
 - Logout
 - Login
 - Works, correctly hides in tray.

LXQt (using KWin):
 - Respects autostart as setup in Plasma, but opens claws-mail window on first login.
 - Closing and reopening from terminal does not work (also opens window).

LXQt (using Openbox): same as LXQt with KWin
Comment 9 Daniel Kirchner 2020-06-20 18:35:40 UTC
So in short: while this works on *some* setups, it does not work in most setups in varying degrees.
Comment 10 Daniel Kirchner 2020-06-20 18:38:46 UTC
Also the hack I attached as a patch three years ago, still seems to work for me and prevents the issue for my use cases. But it's not a proper solution and I haven't tested it in all environments.
Comment 11 Daniel Kirchner 2020-06-20 18:41:21 UTC
Ah yes - the git commit I compiled was abfab686.

So I hope this is enough information for this to be finally properly fixed ;-).
Comment 12 Michael Rasmussen 2020-06-21 06:14:09 UTC
I have now tried what happens when I log in from a not running computer. The result was as expected - CM started an stayed iconified.
Comment 13 Daniel Kirchner 2020-06-21 08:17:30 UTC
That's pretty surprising. How exactly did you set CM up to start at session login? As I wrote earlier I can reproduce the issue in a clean Debian 10 VM... I'll setup another VM with Debian Sid to check if I can also reproduce it there.
Comment 14 Daniel Kirchner 2020-06-21 08:46:54 UTC
I just installed an up-to-date Debian SID system with MATE as Desktop Environment.
I installed CM with
    apt-get install claws-mail claws-mail-extra-plugins

I then enabled the notification plugin and configured it as
"Enable Trayicon" + "Hide at start-up" + "Close to tray" + "Hide when iconified".

I then enabled autostart using MATE's "System -> Preferences -> Personal -> Startup Applications" "Startup Programs -> Add" with Name and Command set to "claws-mail".

I then logged out of the session and logged back in - and I *do* get an opened CM window.
Comment 15 Daniel Kirchner 2020-06-21 09:47:51 UTC
Ok, this behaves a bit less predictably than I expected, but definitely not as it should. Here's a YouTube video of a screen capture of the VM to avoid any misunderstanding:

https://youtu.be/jCPpIN3DrbY


This is in a clean, updated Debian Sid Installation with MATE as desktop - claws-mail version is "3.17.5-2". But as I mentioned earlier the current git head abfab686 as well as most other Desktop Environments show the same erratic behavior.

And having claws-mail start automatically as a tray icon on login doesn't seem like that much of an exotic thing to do to me...

I hope you will be able to reproduce this now! Let me know if there is anything else I can do.
Comment 16 Michael Rasmussen 2020-06-21 12:02:19 UTC
What display manager do you use? I use compton.

Another thing: When configuring CM to autostart on login I have configured a start-up delay of 5 sec.
Comment 17 Daniel Kirchner 2020-06-22 12:11:36 UTC
As I said earlier, I'm using an unmodified stock Debian 10 install of MATE for my latest tests with their standard display manager and without any additional modifications as compton. Using compton doesn't make a difference, though.

Adding a startup delay may help on some desktop environments, but it's (1) not a proper solution, (2) doesn't work reliably and (3) there are desktop environments as LXQt or Cinnamon for which this won't work at all either.

This really needs a proper fix in CM. As the patch I attached to this issue demonstrates, this *can* be prevented, even without startup delay, it just needs someone who knows the claws-mail codebase better than I to properly integrate that and some appropriate logic around it.

A much easier solution would be to add a command line argument for CM that makes it unconditionally hide into tray when first starting up - that's what most other software that can hide as tray icon and that I know does.
Comment 18 Daniel Kirchner 2020-06-22 13:55:53 UTC
Ok, I had another look at the code itself and I have a better idea what happens now:

"plugin_init" in "notification_plugin.c" creates the trayicon early, if there are messages:

  if(notify_config.urgency_hint_new || notify_config.urgency_hint_unread)
        notification_update_msg_counts(NULL);

notification_update_msg_counts will ultimately create the tray icon, if it doesn't exist yet.

It also adds an idle callback:

  g_idle_add(trayicon_startup_idle,NULL);

Which looks like this:

static gboolean trayicon_startup_idle(gpointer data)
{
        /* if the trayicon is not available,
                 simulate click on it to show mainwindow */
        if(!notification_trayicon_is_available())
                notification_trayicon_on_activate(NULL,data);
        return FALSE;
}


So when the main event loop starts, this simulates a click on the tray icon, if "notification_trayicon_is_available" returns false.

Now "notification_trayicon_is_available" in "notification_trayicon.c" checks for "trayicon" to be non-NULL, but also for "gtk_status_icon_is_embedded(trayicon)" and "gtk_status_icon_get_visible(trayicon)".

While "trayicon" is not NULL and "gtk_status_icon_get_visible(trayicon)" is TRUE in the problematic cases, "gtk_status_icon_is_embedded(trayicon)" does return FALSE.
Consequently "notification_trayicon_is_available" returns FALSE and "trayicon_startup_idle" simulates a click on the tray icon causing the window to pop up.
Comment 19 Holger Berndt 2020-06-22 14:00:32 UTC
Actually, I'm afraid it won't get any more "proper" than adding some kind of delay during startup (except if you're fixing it in your DE directly).

Basically, what happens is the following: On startup, the plugin registers the trayicon, and then hides the main window if the corresponding preference is set.

However, there's a safety net: If the application startup is completed, and the tray icon is still not visible, then the main window is shown again. My strong guess is that this happens for you.

This is done because there is no way that Claws-Mail can guarantee that the trayicon will actually ever be shown. Your IDE might not even have a system tray area! Then, if the main window was hidden, how would you get access to it without a tray icon? Right - you can't. You're locked out with no (obvious) way to ever get your main window back - not even by killing the application and starting it again. It's pretty obvious that this is not desirable, therefore the safety net. That's not a bug, that's a feature.

So, if duing the logon in your DE, Claws-Mail is racing against the loading of the tray area and wins the race, you're hitting this issue.

Since you're for proper fixes, I recommend asking the DE-developers to load the tray area and other infrastructure before applications.

Otherwise, there's only the chance of a workaround using  be some kind of delay - be it in the autostart, or in the plugin.
Comment 20 Daniel Kirchner 2020-06-22 14:04:10 UTC
The issue does occur even in fully loaded display environments, for which the system tray is definitely already available (for example in LXQt).

At least in this case, a delay won't help at all.

So the main question is why "gtk_status_icon_is_embedded" returns "FALSE", even though the icon is visible in the tray under some circumstances.
Comment 21 Holger Berndt 2020-06-22 14:07:03 UTC
This is a bug that you can report to LXQt and/or gtk+.
Comment 22 Holger Berndt 2020-06-22 14:21:33 UTC
Created attachment 2065 [details]
5 seconds delay between after showing the main window again on startup
Comment 23 Holger Berndt 2020-06-22 14:24:15 UTC
That's probably going to be even more annoying on LXQt..
Comment 24 Daniel Kirchner 2020-06-22 14:27:37 UTC
Haha, you were quicker than me - I was just about to suggest to at least do something like what you just attached.

But yeah, true, it may indeed not be nice on LXQt or Cinnamon.

It's unfortunate that this still won't work properly in all and every environment, for which "gtk_status_icon_is_embedded" just doesn't work, but it's fair enough to consider that a bug in that desktop environment or tray implementation then.

So at least as far as I'm concerned, this does look like a nice workaround to the main issue and the rest can then indeed be put off to whichever desktop environment in which this just doesn't work in general (luckily I don't use LXQt anymore myself recently :-)).
Comment 25 Daniel Kirchner 2020-06-22 14:28:47 UTC
As a matter of fact I'll report this at least to LXQt.
Comment 26 Daniel Kirchner 2020-06-22 14:55:40 UTC
For the record: https://github.com/lxqt/lxqt/issues/1817

In any case I'll hope you'll still merge the timeout solution for the fallback mechanism that will fix this without unnecessary delays at least on *most* platforms and thank you very much for your time so far!
Comment 27 Daniel Kirchner 2020-06-22 15:16:14 UTC
But as I was afraid: not the most welcoming response on their end :-).
Comment 28 Yamashita Ren 2020-06-22 16:43:10 UTC
I agree with tsujan than the main issue is claws-mail reliance on gtk2/systray.
First we lost fancy plugin because we could not upgrade to webkit2gtk, now we discover that systray is not well supported by some DE (ie LXQt) ...

From my experience, Claws Mail is one of the best mail clients for Linux, especially given how Mozilla/Thunderbird Linux/"Tray" support is lacking and KMail has all this akonadi bloat... And I am not even talking about memory footprint.
So it's a bit sad to have Claws being kept back by its gtk2 dependency :/
Comment 29 Paul 2020-06-22 17:22:17 UTC
> So it's a bit sad to have Claws being kept back by its gtk2 dependency :/

The GTK-3 port is usable but not yet ready for release.
Comment 30 Daniel Kirchner 2020-06-23 15:39:53 UTC
Interestingly, I just discovered that "gtk_status_icon_is_embedded" does *start* to return TRUE after a while even on LXQt, just not immediately.
So the change from "g_idle_add" to "g_timeout_add" actually solves this issue entirely even on LXQt.

I'm not quite sure if this is still a bug in the LXQt system tray or not - I'm just looking at lxqt-panel code - I guess it has something to do with the precise way it implements the XEmbed protocol. Arguably, there is probably no guarantee that the tray icon will already be embedded when the gtk main loop starts, even if there is a tray available already, so I think the "g_timeout_add" instead of "g_idle_add" solution might really be a "proper" solution to all this...
Comment 31 Daniel Kirchner 2020-06-23 16:20:49 UTC
Funnily, in lxqt this is actually the result of them trying to fix a different issue with claws-mail - see https://github.com/lxqt/lxqt-panel/pull/1428 and the linked issues there.

So either them merging that PR or you merging the delay patch to claws-mail would close this issue. As far as I'm concerned, actually both should be done :-).
Comment 32 Holger Berndt 2020-06-24 16:38:47 UTC
Committed the workaround. Closing bug report, we cannot do more about it.

Note You need to log in before you can comment on or make changes to this bug.