Recent

Author Topic: More TrayIcon Issues  (Read 1720 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3011
    • tomboy-ng, a rewrite of the classic Tomboy
More TrayIcon Issues
« on: November 26, 2023, 10:51:20 am »
Hi Folks, more TrayIcon issues I am afraid.

Several years ago I patched the GTK2 (and GTK3) code so that the TrayIcon would use libappindicator and then, later, libayatana as workaround as Gnome waged war on the System Tray. It was not too bad for a while but I just did a survey of the various distros I test against and it needs more work. Ideally, before release of Lazarus 3.0 ?

I find that some Desktop's tried to address the problem but its still broken in various ways. All the Gnome Disrributions must still go direct to libayatana, many Distro/Desktop combinations can work with either and some, KDE and (strangely) 32bit Debian won't work with Ayanta but are OK with the old, traditional TrayIcon ! And it keeps changing.

I suggest a small change to gtk2/unitywsctrls.pas to export out a Global var that allows the application programmer to determine which Tray Icon model to use. If the programmer does not want to, it has a usable default.

Attached is a patch against lazarus main that adds that Global var, adds a type that the var is and alters the way  RegisterCustomTrayIcon() in gtk2wsfactory decides which sort of TrayIcon to use.

Also attached is a small lazarus project that demonstrates how to use this Global var and how to protect from the Access Violation that results when its wrong. It has a bit of code in the lpr file that looks at command line switches and environment vars to set the vars. A more in depth test would easily slot in there. The patch affects ONLY gtk2 and the default behavior remains the same as it was.

If no problems identified, I will create a bug report.

David

Edit : sorry, apparently the patch file was not attached the first time. I'll try again.
« Last Edit: November 27, 2023, 01:51:11 am by dbannon »
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

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: More TrayIcon Issues
« Reply #1 on: November 26, 2023, 11:03:50 am »
I tried your code but I got compile time error, see the attached screenshot. I am using Ubuntu Mate 23.10 Lazarus 2.2.6 GTK2.

dbannon

  • Hero Member
  • *****
  • Posts: 3011
    • tomboy-ng, a rewrite of the classic Tomboy
Re: More TrayIcon Issues
« Reply #2 on: November 26, 2023, 11:22:34 am »
I tried your code but I got compile time error, see the attached screenshot. I am using Ubuntu Mate 23.10 Lazarus 2.2.6 GTK2.

Did you apply the patch to your Lazarus source ?  That variable is a new addition in gtk2/unityctrls.pas.

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

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: More TrayIcon Issues
« Reply #3 on: November 26, 2023, 11:46:37 am »
I am sorry, I didn't read the comment in source code. It works now.

But for your information, my Lazarus-created program still works correctly even without the patch. From the screenshot below, yours is the green icon with a pencil. My program (SideNote) is the blue circle with a cheetah paw. I just formatted and reinstall my OS and Lazarus some weeks ago, I had no problem recompiling and running my SideNote.

I don't know why I didn't have any TrayIcon-GTK issue, perhaps because I am using Ubuntu Mate.
« Last Edit: November 26, 2023, 11:56:36 am by Handoko »

dbannon

  • Hero Member
  • *****
  • Posts: 3011
    • tomboy-ng, a rewrite of the classic Tomboy
Re: More TrayIcon Issues
« Reply #4 on: November 26, 2023, 12:31:04 pm »
Ah, Handoko, the truth is that Mate is one of the better ones in this space, for real trouble, try Gnome (can be made to work is you install gnome-shell-extension-appindicator and enable gnome-extensions). I too use Mate (I think I might have suggested it to you ?) and a quite old Ubuntu, it works in both modes.

Here is the list I tested today, the really surprising ones is the difference between 32bit and 64bit Debian Mate, with 32bit, must use old traditional System Tray, with 64bit either will work.

Its the erratic nature of these things, changes with each release, that convinced me that allowing the programmer to manage the situation was the only way forward.

Bad with App Indicator only ie OK with Traditional
  • 32bit Bookworm and Bullseye - both fail in AppIndicator mode, either 1 or 3
  • Bookworm KDE - has no AppIndicator by default, AV
  • Trixie KDE -has no AppIndicator by default, AV
Bad with Traditional SysTray only ie OK with App Indicator
  • Ubuntu 2304 Gnome (in Traditional, menu pops up in random places)
  • Ubuntu 2310 Gnome, as above
Good with either works with both App Indicator and Traditional
  • Ubuntu 2004 Mate
  • Bookworm Cinnamon
  • Bookworm LXDE
  • Bookworm Mate
  • Bullseye Mate
  • Trixie Mate
  • Mint 21.1 Cinnamon
  • Ubuntu2304 XFCe
  • Ubuntu 2204 Mate
Bad with Either #@1 Gnome
  • Bookworm Gnome (but can be made work)
  • OpenBox, no (default) System Tray.
  • Fedora Gnome


(Gnome generally fixable for App Indicator by installing gnome-shell-extension-appindicator and enabling it in in gnome-extension-app but traditional sys tray is still non-functional as menu appears in random locations.)

By Traditional, I mean hitting the DE's api, by using an App Indicator, we bypass the DE, directly open the library and use it's calls to do what we must. Most of the "works with either" ones also rely on LibAyatana and connect their API to that Library.

KDE implements its own solution.

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

Handoko

  • Hero Member
  • *****
  • Posts: 5290
  • My goal: build my own game engine using Lazarus
Re: More TrayIcon Issues
« Reply #5 on: November 26, 2023, 06:56:43 pm »
Glad to know Ubuntu Mate does not have the issue.
And thank you for spending time for testing and making the patch.

dbannon

  • Hero Member
  • *****
  • Posts: 3011
    • tomboy-ng, a rewrite of the classic Tomboy
Re: More TrayIcon Issues
« Reply #6 on: November 27, 2023, 01:55:25 am »
Thanks Handoko, I just realised that the patch file did not appear in the first post. I have re-attached it, I guess I did something wrong there.

So, first post in this thread now has the patch (or diff) file (affecting /lcl/interfaces/gtk2/gtk2wsfactory and unityctrls.pas in same directory) that should be applied to Lazarus Main and a small demo of how to use the global variable that the patch makes available.

David
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

 

TinyPortal © 2005-2018