Recent

Author Topic: TrayIcon Events  (Read 2073 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
TrayIcon Events
« on: March 26, 2019, 02:05:36 am »
On Linux (at least) I don't seem to be able to see any events from clicking on a System Tray Icon.  OnClick, OnDblClick, OnMouseDown, OnMouseMove, OnMouseUp.

And even trying to hook into its PopupMenu fails, OnPopup does not get fired either.

Anyone know any background to this please ?

Easy to reproduce, drop a TrayIcon ('Additional') on a form, make a menu for it, set an icon and then point all the events to a method (or each to own method) and that method never gets called. The menu pops up OK, its items get responded to etc.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: TrayIcon Events
« Reply #1 on: March 26, 2019, 04:41:58 am »
I have a small tray icon program, so far it is working good.

I checked the code, I think you may need to add this:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.TrayIconClick(Sender: TObject);
  2. begin
  3.   mnuTray.PopUp; // mnuTray is a TPopupMenu instance
  4. end;

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TrayIcon Events
« Reply #2 on: March 26, 2019, 07:39:25 am »
Thanks Handoko, no, my popup menu is working fine, for what we generally do with a TTrayIcon, its all OK. But the other events included with TrayIcon don't work.

I need to know where the user has clicked so started experimenting with the other Events, its the other events that are not working.

Anyone interested in why I want to know where the user clicks ?  I thought not but I'll tell you anyway. The TrayIcon is not usable in any recent Gnome based distro. The Gnome Devs have a thing about it apparently. So, its been dropped. But lots of people are making lots of Gnome Extensions because people want and need this functionality. But every one I tried pops the menu up in the wrong part of screen, most disturbing. So, I want to experiment with setting the menu where I think it should popup, top left near the Icon .....

The TrayIcon itself does not seem to have a 'Left' or 'Top' property.

EDIT: Interesting, its OS dependent, In Fedora29, Gnome 3.30.2 (with a Gnome Tray Icon extension added) it does show those Events, but in my normal desktop, Ubuntu Mate 18.04 it does not. Wow, scary if you depend on something like that !

Davo
« Last Edit: March 26, 2019, 07:56:41 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TrayIcon Events
« Reply #3 on: March 29, 2019, 01:35:28 am »
Just to record my findings so far. Will put this on Wiki if and when I understand it better.

Depending on the (Linux) desktop, TrayIcon events such as OnClick, OnDblClick, OnMouseDown, OnMouseMove, OnMouseUp do not get fired. This does not stop (eg) a popup menu associated with the TrayIcon from working as expected.

On some Gnome desktops such as Fedora29, the TrayIcon does not appear at all. You can add one of several Gnome Extensions with names like "Top Icons", TopIcons Plus" etc and it will appear but when clicked, the associated menu appears half a screen away.

There is no opportunity to override the position of where the menu appears, the problem relates to the use of Wayland in window manager, if you disable Wayland, window manager will fall back to X11 and all will work as expected. While this may seem to be a Gnome/Wayland bug, their developers are unlikely to accept it as such, they disapprove of the GTK2 SystemTray/Appindicator model that Lazarus uses.

Availability and use of libappindicator3 might indicate things will work OK but not 100% reliable. I cannot find a reliable means to even warn the user things are broken !

Sigh

Davo



Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018