Recent

Author Topic: TrayIcon doesn't work using the lastest Lazarus  (Read 708 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 470
  • Programming is FUN only when it works :)
    • Cool Technology
TrayIcon doesn't work using the lastest Lazarus
« on: March 21, 2025, 03:27:10 pm »
Lazarus 2.2.4
FPC 3.2.2

I am trying to use TrayIcon component that came with Lazarus compiler, but it doesn't work with my program.

My project files compile and run successfully, but I don't see my program's icon in the system tray. However, programs I wrote with previous version of Lazarus does display their icon in the system tray. I can't seem to get my head around this issue. This is supposed to be very simple task to do using TrayIcon.

Code: Pascal  [Select][+][-]
  1. procedure TMainFrm.FormCreate(Sender: TObject);
  2. begin
  3.      TrayIcon1.Hint:='My Program';
  4.      TrayIcon1.Visible:=true;
  5. end;
  6.  
  7. procedure TMainFrm.TrayIcon1MouseUp(Sender: TObject; Button: TMouseButton;
  8.   Shift: TShiftState; X, Y: Integer);
  9. begin
  10.   if (Button = mbRight) then
  11.   begin
  12.      Show;
  13.      Application.BringToFront;
  14.   end;
  15. end;
  16.  
  17. procedure TMainFrm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  18. begin
  19.      TrayIcon1.Visible:=false;
  20. end;
  21.  

Is there something I am missing here? Does the icon have to be ICO or can it be anything like PNG or JPEG or BMP?

Thanks in advance.

AlexTP

  • Hero Member
  • *****
  • Posts: 2557
    • UVviewsoft
Re: TrayIcon doesn't work using the lastest Lazarus
« Reply #1 on: March 21, 2025, 04:43:30 pm »
Lazarus 2.2.4 is too old, can you try Lazarus 4.0 RC2?
https://forum.lazarus.freepascal.org/index.php/topic,69820.0.html

zeljko

  • Hero Member
  • *****
  • Posts: 1734
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: TrayIcon doesn't work using the lastest Lazarus
« Reply #2 on: March 21, 2025, 05:56:03 pm »
TrayIcon under modern x11 and wayland is problematic (I know it from Qt implementation), since it use DBUS now, it is not pure widget anymore.

CM630

  • Hero Member
  • *****
  • Posts: 1311
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TrayIcon doesn't work using the lastest Lazarus
« Reply #3 on: March 21, 2025, 09:44:23 pm »
I have an app using an icon in the systray, it also shows is ot Mintos.
...
Is there something I am missing here? Does the icon have to be ICO or can it be anything like PNG or JPEG or BMP?
...
I have an app with a tray icon, in Mintos it shows it in the systray (Lazarus 4.0RC1).
But the icon is in a TImageList. I do not remember how I didd it, so it should probably be easy.
« Last Edit: March 21, 2025, 09:53:45 pm by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

dbannon

  • Hero Member
  • *****
  • Posts: 3308
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TrayIcon doesn't work using the lastest Lazarus
« Reply #4 on: March 22, 2025, 06:17:13 am »
The problem relates to which Desktop (ie, Gnome, KDE, Mate etc) rather that the OS.  And, in particular, if your Desktop uses Wayland instead of X11.

Newer Lazarus does have extra smarts to work with problematic Desktops, you certainly need something newer than 2.2.4. But that, alone will not solve all problems.

Gnome in particular is a problem, designers of Gnome declared an end to Tray Icons some years ago. So, now, workarounds are needed. Have you read https://wiki.freepascal.org/How_to_use_a_TrayIcon ?

Also, if feeling brave, look at https://github.com/tomboy-notes/tomboy-ng/blob/master/source/mainunit.pas#L539  -  function TMainForm.CheckForSysTray() : boolean;

Its quite complicated, you need to test for Gnome, ask the user to install a particular Gnome Extension and enable it.

The TrayIcon does generally work OK on non-wayland systems, Mate, XFCe, Cinnamon etc. 

On KDE, I have to force the user to use the right hand mouse button, all down to Wayland I am afraid. But at least no plugin needed, KDE do not seem to deliberately break the SystemTray.

Qt5 and Qt6 generally work better than gt2 but still not perfect every time.

The diversity of Linux is both a feature and a curse !

Davo

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

CM630

  • Hero Member
  • *****
  • Posts: 1311
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TrayIcon doesn't work using the lastest Lazarus
« Reply #5 on: March 22, 2025, 08:31:45 pm »
...
Is there something I am missing here? Does the icon have to be ICO or can it be anything like PNG or JPEG or BMP?
...
Maybe we can start with a simple test - run this app and if shows an x-mas tree in the tray, then an icon in the systray is achieveble for you and we can proceed further?
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018