Recent

Author Topic: Hints in TTrayIcon  (Read 1091 times)

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Hints in TTrayIcon
« on: November 27, 2025, 09:25:47 am »
I tried to use hints with TTrayIcon.
Here is the code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     TrayIcon1: TTrayIcon;
  16.     procedure FormCreate(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. begin
  34.     TrayIcon1.Show;
  35.     TrayIcon1.hint := 'sdfasdfasdfsaddfassad1' + #13#10
  36.                     + 'sdfasdfasdfsaddfassad2' + #13#10
  37.                     + 'sdfasdfasdfsaddfassad3' + #13#10
  38.                     + 'sdfasdfasdfsaddfassad4' + #13#10
  39.                     + 'sdfasdfasdfsaddfassad5' + #13#10
  40.                     + 'sdfasdfasdfsaddfassad6' + #13#10
  41.                     + 'sdfasdfasdfsaddfassad7' + #13#10
  42.                     + 'sdfasdfasdfsaddfassad8' + #13#10
  43.                     + 'sdfasdfasdfsaddfassad9' + #13#10;
  44. end;
  45.  
  46. end.

In Windows 11 the hint is truncated.
In Linux Mint Mate the hint is not shown at all.
In Linux Mint XFCE the trayicon is not shown at all  :o
In MacOS the hint is not shown at all.

Are there some bugs in Lazarus or simply hints shall not be used?
There are no OnMouseEnter and OnMouseLeave events for TTrayIcon, so showing a custom hint is even harder.
« Last Edit: November 27, 2025, 09:42:31 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

dbannon

  • Hero Member
  • *****
  • Posts: 3647
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Hints in TTrayIcon
« Reply #1 on: November 27, 2025, 12:39:00 pm »
All the different widget sets implement the TrayIcon their own way, all LCL can do is get the information together and pass it to the GUI OS.

I note you did not test Gnome !

The issue is that people like Gnome put some very heavy limitations on just what they will handle so I am not surprised a multi line hint fails. Its really not what a hint is supposed to be. A single line of text without the new-lines might be a lot more interesting test.

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: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Hints in TTrayIcon
« Reply #2 on: November 27, 2025, 03:53:06 pm »
...
I note you did not test Gnome !
...
Neither I tested KDE. I am using Explorer Patcher, so I tried it on a Windows 11 without Explorer Patcher and on a Windows 10 - on both the hint is truncated.

Edit: It occurs that systray hints are truncated to 128 chars in Windows. There is some workaround in C (https://stackoverflow.com/questions/579665/how-can-i-show-a-systray-tooltip-longer-than-63-chars) but I cannot understand it.

Linux Mint Mate is able to show hints for tooltips, so maybe there is a bug in Lazarus?
What makes things even odder is that DoubleCommander's icon in the tray has a hint.

And there is even more: On another computer with Mint Mate the tray icon is not shown at all  :o

And even more: The TrayIcon is not displayed in Mint. But if I link a Popup menu to it and select an icon for the Icon, it starts showing.
If I unlink the popup meu and rebuild - the icon is not shown.
If I link again popup meu and rebuild - the icon is still not shown.
But if I add an icon again and rebuild - then it starts showing  >:D

And it shows a hint! But the hint is always the name of the project! TrayIcon1.Hint := 'sfgdsf' ; is simply ignored.
« Last Edit: November 27, 2025, 11:04:19 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

dbannon

  • Hero Member
  • *****
  • Posts: 3647
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Hints in TTrayIcon
« Reply #3 on: November 28, 2025, 12:23:36 am »
It is necessary on some gnome and gtk based systems to have some menu items in the popup menu before you show the TrayIcon. That started, maybe, 2 or 3 years ago ?

No current Gnome system will show a TrayIcon unless you have installed an appindicator pugin AND activated it. Messy process.

My advice is to do as little as possible with the TrayIcon. Have an icon visible, when clicked, popup a menu. Do not try to use it for anything more than that.

My application has quite extensive code that determines what Desktop a Linux box is running and then trying its best to do just that display icon, show menu. On Gnome it initially tells user that they may not see the icon, what to install and, if they have installed the plugin, it will activate it.  On other desktops it tries to use Ayatanya in some cases, libappindicator in others.

Support for libayatana seems to be flagging, and many desktops are reverting to traditional TrayIcon (but not gnome).

In LCL there are some env vars you can set to force one model or another. See https://wiki.freepascal.org/How_to_use_a_TrayIcon - probably time for a revision.

Overall, its not good. So, do not try to do things that the TrayIcon was not intended, in the past, people did silly, very complicated things in there and that triggered this current negative attitude to it, particularly amongst the Gnome Developers.

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: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Hints in TTrayIcon
« Reply #4 on: December 04, 2025, 08:04:34 am »
It turns out that in KUbuntu hints are not shown at all 
All other tray icons have hints, mine has none :'(
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

avra

  • Hero Member
  • *****
  • Posts: 2580
    • Additional info
Re: Hints in TTrayIcon
« Reply #5 on: December 05, 2025, 01:58:19 am »
There used to be a Delphi component which allowed multiline long hints on Windows tray icon. I can search for it if you need it.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

dbannon

  • Hero Member
  • *****
  • Posts: 3647
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Hints in TTrayIcon
« Reply #6 on: December 05, 2025, 02:11:20 am »
It turns out that in KUbuntu hints are not shown at all 
All other tray icons have hints, mine has none :'(

On KDE Trixie, hints do not show with GTK2 but gtk2 is becoming more and more badly supported, no surprise IMHO.

But with Qt5 and Qt6 hints work. Using Wayland or XWayland.

I cannot build my app with GTK3 so, cannot, easily, test. 

Question, are you changing the hint after showing the TrayIcon ?

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: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Hints in TTrayIcon
« Reply #7 on: December 05, 2025, 04:11:15 pm »
There used to be a Delphi component which allowed multiline long hints on Windows tray icon. I can search for it if you need it.
Thanks, please do not bother, but if you come across it might be useful for some other time.
I just set .Hint := 'Right-click for details';.

...
But with Qt5 and Qt6 hints work. Using Wayland or XWayland.
I have no idea what Wayland and XWayland are. Just the latest KUbuntu.
Quote
$ hostnamectl
...
  Operating System: Ubuntu 25.10                   
   Kernel: Linux 6.17.0-7-generic
   Architecture: x86-6
...


Quote
~$ find /usr/lib -iname "Qt"
/usr/lib/python3/dist-packages/softwareproperties/qt
/usr/lib/python3/dist-packages/orca/scripts/toolkits/Qt
/usr/lib/x86_64-linux-gnu/qt6/qml/Qt

Question, are you changing the hint after showing the TrayIcon ?
1. During design time.
2. During runtime before .Show
3. During runtime after .Show

All the same. No hint. I cannot think of any other sequence to try.
« Last Edit: December 05, 2025, 04:21:28 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

dbannon

  • Hero Member
  • *****
  • Posts: 3647
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Hints in TTrayIcon
« Reply #8 on: December 06, 2025, 12:44:28 am »
...
But with Qt5 and Qt6 hints work. Using Wayland or XWayland.
I have no idea what Wayland and XWayland are. Just the latest KUbuntu.
In this case, you don't need to know, Wayland or XWayland makes no difference, hints work for me. Why not you ?

But for the record -
But long term, you do need to know !  Most Wayland using systems run your QT app directly to Wayland. A very few systems, out of the box, have an environment variable, QT_QPA_PLATFORM set to "xcb" or you can set it yourself that makes your QT app use XWayland, a compatibility layer that looks a bit more like X11. Your QT app has the means to use either but generally XWayland works better (I note that recently, Wayland seems to not work as well as it used to.)

Start your QT app like this to get XWayland -

Code: Bash  [Select][+][-]
  1. >$ QT_QPA_PLATFORM=xcb   myapp  [enter]
  2. or
  3. >$ myapp -platform xcb [enter]

Note that the command line switch version uses only one dash and a space between the switch and parameter, incorrect but thats what it wants.

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

avra

  • Hero Member
  • *****
  • Posts: 2580
    • Additional info
Re: Hints in TTrayIcon
« Reply #9 on: December 09, 2025, 07:01:02 pm »
There used to be a Delphi component which allowed multiline long hints on Windows tray icon. I can search for it if you need it.
Thanks, please do not bother, but if you come across it might be useful for some other time.

It was Text Tray Icon component and I used it in D7 days. It was the only one that could overcome Windows limitation and show several Kb of multiline text in tray icon hint.

Now it has a new home at https://github.com/coolshou/CoolTrayIcon.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018