Recent

Author Topic: TTrayIcon do not work properly on Raspberry Pi OS(Raspi400)  (Read 591 times)

atell

  • New member
  • *
  • Posts: 9
TTrayIcon do not work properly on Raspberry Pi OS(Raspi400)
« on: December 06, 2024, 06:10:05 am »
Hi, All.

I'm a programming beginner living Sapporo City, Hokkaido, Japan.

Raspberry Pi 400 and Raspberry Pi OS 64bit 6.6.51+... with Lazarus 4.0RC1 and FPC 3.2.3. Revision: Unknown, aarch64-linux-gtk2. On Wayland.

My test-program of task tray icon won't activate. Please help me.

https://forum.lazarus.freepascal.org/index.php/topic,68967.msg534292.html#msg534292
https://wiki.freepascal.org/How_to_use_a_TrayIcon

Panel?..., 'ONLY gtk2 and Lazarus >= 3.0.0'? higher?

Below is my source code.

Best Regard,
Thank you.

atell.

---

(lpr)

Code: Pascal  [Select][+][-]
  1. program trayon01;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   {$IFDEF HASAMIGA}
  10.   athreads,
  11.   {$ENDIF}
  12.   Interfaces, // this includes the LCL widgetset
  13.   Forms, Unit1_trayon01
  14.   {$ifdef LCLGTK2}
  15.   , unitywsctrls
  16.   {$endif}
  17.   { you can add units after this };
  18.  
  19. {$R *.res}
  20.  
  21. // ----------------------------------------------------------------------------
  22. //   This about reading the command line and env for instructions re TrayIcon
  23. //   It applies to ONLY gtk2 and Lazarus >= 3.0.0 !
  24. // ----------------------------------------------------------------------------
  25. {$ifdef LCLGTK2}
  26.  function GetUseAppInd() : UnityWSCtrls.TUseAppIndInstruction;
  27.  var
  28.     EnvVar : string;
  29.  begin
  30.  Result := UnityWSCtrls.GlobalUseAppInd;
  31.  if Application.HasOption('useappind') then begin              // Command line
  32.     if Application.GetOptionValue('useappind') = 'yes' then    // if not set, leave it alone.
  33.         Result := UseAppIndYes
  34.     else if Application.GetOptionValue('useappind') = 'no' then
  35.         Result := UseAppIndNo;                            // Anything other than yes or no is ignored
  36.  end else begin
  37.     EnvVar := Application.EnvironmentVariable['LAZUSEAPPIND'];   // EnvironmentVariable
  38.     if EnvVar = 'YES' then
  39.         Result := UseAppIndYes
  40.     else if EnvVar = 'NO' then
  41.         Result := UseAppIndNo;
  42.     end;                        // EnvVar : 0x0
  43. end;
  44. {$endif}
  45.  
  46. begin
  47.   RequireDerivedFormResource:=True;
  48.   Application.Scaled:=True;
  49.   Application.{%H-}MainFormOnTaskbar:=True;
  50.   Application.Initialize;
  51.   {$ifdef LCLGTK2 }
  52.       {$ifdef CPUi386}             // Note: unless Ayatana fix their problem, no option for Gnome users
  53.                                   // https://github.com/AyatanaIndicators/libayatana-appindicator/issues/76
  54.       UnityWSCtrls.GlobalUseAppInd := UnityWSCtrls.UseAppIndNo;     // 32bit must be a 'no'.
  55.       {$endif}
  56.       UnityWSCtrls.GlobalUseAppInd := GetUseAppInd();
  57.       //UnityWSCtrls.GlobalUseAppInd := UnityWSCtrls.UseAppIndAuto;
  58.   {$endif}
  59.   Application.CreateForm(TForm1, Form1);
  60.   Application.Run;
  61. end.
  62.  


(pas)

Code: Pascal  [Select][+][-]
  1. unit Unit1_trayon01;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, Forms, Controls, Menus, ExtCtrls, Dialogs, StdCtrls;//, UnityWSCtrls;
  7.  
  8. type
  9.  
  10.   { TForm1 }
  11.  
  12.   TForm1 = class(TForm)
  13.     Button1: TButton;
  14.     MainMenu1: TMainMenu;
  15.     TrayIcon1: TTrayIcon;
  16.     PopupMenu1: TPopupMenu;
  17.     MenuItem1: TMenuItem;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure MenuItem1Click(Sender: TObject);
  21.   private
  22.     { private declarations }
  23.   public
  24.     { public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. begin
  36.   //Application.ShowMainForm := False;
  37.   //Form1.Hide;
  38. end;
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. begin
  42.   TrayIcon1.Icon := Application.Icon;
  43.   TrayIcon1.PopupMenu := PopupMenu1;
  44.   TrayIcon1.Visible := True;
  45.   TrayIcon1.Show;
  46. end;
  47.  
  48. procedure TForm1.MenuItem1Click(Sender: TObject);
  49. begin
  50.   ShowMessage('Menu item clicked!');
  51. end;
  52.  
  53. end.
  54.  


(lfm)
Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 1480
  3.   Height = 300
  4.   Top = 250
  5.   Width = 500
  6.   Caption = 'Form1'
  7.   ClientHeight = 300
  8.   ClientWidth = 500
  9.   Menu = MainMenu1
  10.   LCLVersion = '4.0.0.1'
  11.   OnCreate = FormCreate
  12.   object Button1: TButton
  13.     Left = 341
  14.     Height = 25
  15.     Top = 170
  16.     Width = 75
  17.     Caption = 'Trayon!'
  18.     TabOrder = 0
  19.     OnClick = Button1Click
  20.   end
  21.   object TrayIcon1: TTrayIcon
  22.     PopUpMenu = PopupMenu1
  23.     Left = 176
  24.     Top = 152
  25.   end
  26.   object PopupMenu1: TPopupMenu
  27.     Left = 176
  28.     Top = 88
  29.     object MenuItem1: TMenuItem
  30.       Caption = 'Menu Item'
  31.       OnClick = MenuItem1Click
  32.     end
  33.   end
  34.   object MainMenu1: TMainMenu
  35.     Left = 129
  36.     Top = 232
  37.   end
  38. end
  39.  


Thanks.

Thaddy

  • Hero Member
  • *****
  • Posts: 16411
  • Censorship about opinions does not belong here.
Re: TTrayIcon do not work properly on Raspberry Pi OS(Raspi400)
« Reply #1 on: December 06, 2024, 07:36:19 am »
MainformOnTaskbar is only for Windows. you don?'t need it for Raspberry Pi OS.
If everything is installed correctly it should work out of the box.
(will test later for aarch64 Pi)
As a side note: did you make sure that the OS is up-to-date?
That is important, because Wayland is a moving target and a lot of updates happen to improve compatibility with X-windows.
So:
sudo apt update && sudo apt upgrade -y

You may also add backports to the apt configuration to get even more recent updates.
So for the moment don't touch fpc and lazarus, but do upgrade the system.
Big chance that is enough.
[edit]
TTrayIcon works on one of my RPi aarch64's. Not extensively tested.
« Last Edit: December 06, 2024, 08:20:15 am by Thaddy »
There is nothing wrong with being blunt. At a minimum it is also honest.

atell

  • New member
  • *
  • Posts: 9
Re: TTrayIcon do not work properly on Raspberry Pi OS(Raspi400)
« Reply #2 on: December 06, 2024, 10:31:11 pm »
Thanks, Thaddy  :D

Sorry it took so long. I was trying other Raspberry Pi OS.

The result is a difficult situation. It works on one Raspberry Pi OS, but not on the other. :(

Both are supposed to be the latest versions, "Linux raspberrypi 6.6.62+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.62-1+rpt1 (2024-11-25) aarch64 GNU/Linux".

As you pointed out, I tried other Raspberry Pi OS and it worked.

Thank you...

Atell at Japan.
« Last Edit: December 07, 2024, 01:05:48 am by atell »

 

TinyPortal © 2005-2018