mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-22 06:08:17 +02:00
LCL-GTK3: Improve TrayIcon support. Issue #38909, patch by David.
git-svn-id: trunk@65214 -
This commit is contained in:
parent
595fb2c21d
commit
229352c40d
@ -13,10 +13,10 @@
|
|||||||
for details about the license.
|
for details about the license.
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
A unit that uses LibAppIndicator3 to display a TrayIcon in GTK3. Based on a
|
A unit that uses LibAppIndicator3-1 or libAyatana-AppIndicator3-1 to display a
|
||||||
GTK2 version by Anthony Walter, now works with many common Linux systems "out
|
TrayIcon in GTK3. Based on a GTK2 version by Anthony Walter, now works with
|
||||||
of the box" and almost all of the remainder with addition of LibAppIndicator3
|
many common Linux systems "out of the box" or with the addition of one of the
|
||||||
and TopIconsPlus or similar Gnome Extension.
|
above mentioned libraries and possibly gnome-shell-extension-appindicator.
|
||||||
|
|
||||||
See Wiki for details and Limitations (Menu only, one Icon only....)
|
See Wiki for details and Limitations (Menu only, one Icon only....)
|
||||||
Also refer to discussion in ../gtk2/UnityWSCtrls.pas
|
Also refer to discussion in ../gtk2/UnityWSCtrls.pas
|
||||||
@ -43,15 +43,20 @@ type
|
|||||||
class function GetPosition(const {%H-}ATrayIcon: TCustomTrayIcon): TPoint; override;
|
class function GetPosition(const {%H-}ATrayIcon: TCustomTrayIcon): TPoint; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Gtk3AppIndicatorInit returns true if LibAppIndicator_3 library has been loaded }
|
{ Gtk3AppIndicatorInit returns true if a LibAppIndicator3 library has been loaded }
|
||||||
function Gtk3AppIndicatorInit: Boolean;
|
function Gtk3AppIndicatorInit: Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
{X$define DEBUGAPPIND}
|
||||||
|
|
||||||
uses gtk3objects; // TGtk3Image
|
uses gtk3objects; // TGtk3Image
|
||||||
|
|
||||||
const
|
const
|
||||||
libappindicator_3 = 'libappindicator3.so.1';
|
libappindicator_3 = 'libappindicator3.so.1'; // Unity or Canonical libappindicator3-1
|
||||||
|
LibAyatanaAppIndicator = 'libayatana-appindicator3.so.1'; // Ayatana - typically called libayatana-appindicator3-1
|
||||||
|
IconThemePath = '/tmp/appindicators/'; // We must write our icon to a file.
|
||||||
|
IconType = 'png';
|
||||||
|
|
||||||
type
|
type
|
||||||
TAppIndicatorCategory = (
|
TAppIndicatorCategory = (
|
||||||
@ -109,9 +114,6 @@ type
|
|||||||
procedure Update;
|
procedure Update;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
|
||||||
IconThemePath = '/tmp/appindicators/'; // We must write our icon to a file.
|
|
||||||
IconType = 'png';
|
|
||||||
|
|
||||||
var
|
var
|
||||||
GlobalAppIndicator: PAppIndicator;
|
GlobalAppIndicator: PAppIndicator;
|
||||||
@ -148,6 +150,14 @@ begin
|
|||||||
GlobalAppIndicator := app_indicator_new_with_path(PChar(FName), PChar(FIconName),
|
GlobalAppIndicator := app_indicator_new_with_path(PChar(FName), PChar(FIconName),
|
||||||
APP_INDICATOR_CATEGORY_APPLICATION_STATUS, IconThemePath);
|
APP_INDICATOR_CATEGORY_APPLICATION_STATUS, IconThemePath);
|
||||||
Update;
|
Update;
|
||||||
|
{$ifdef DEBUGAPPIND}
|
||||||
|
case app_indicator_get_status(GlobalAppIndicator) of
|
||||||
|
APP_INDICATOR_STATUS_PASSIVE : writeln('AppInd statis is Passive');
|
||||||
|
APP_INDICATOR_STATUS_ACTIVE : writeln('AppInd status is Active');
|
||||||
|
APP_INDICATOR_STATUS_ATTENTION : writeln('AppInd is Attention');
|
||||||
|
else writeln('AppInd status is unknown');
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TAppIndTrayIconHandle.Destroy;
|
destructor TAppIndTrayIconHandle.Destroy;
|
||||||
@ -249,9 +259,16 @@ begin
|
|||||||
Loaded := True;
|
Loaded := True;
|
||||||
if Initialized then
|
if Initialized then
|
||||||
Exit(True);
|
Exit(True);
|
||||||
Module := LoadLibrary(libappindicator_3); // might have several package names, see wiki
|
Module := LoadLibrary(libappindicator_3);
|
||||||
if Module = 0 then
|
if Module = 0 then begin
|
||||||
|
Module := LoadLibrary(LibAyatanaAppIndicator);
|
||||||
|
if Module = 0 then begin // Sorry, no TrayIcon !
|
||||||
|
{$ifdef DEBUGAPPIND}
|
||||||
|
writeln('Failed to load an appindicator library');{$endif}
|
||||||
Exit;
|
Exit;
|
||||||
|
end
|
||||||
|
{$ifdef DEBUGAPPIND} else writeln('Loaded ' + LibAyatanaAppIndicator){$endif};
|
||||||
|
end {$ifdef DEBUGAPPIND} else writeln('Loaded ' + libappindicator_3){$endif};
|
||||||
Result :=
|
Result :=
|
||||||
TryLoad('app_indicator_get_type', @app_indicator_get_type) and
|
TryLoad('app_indicator_get_type', @app_indicator_get_type) and
|
||||||
TryLoad('app_indicator_new', @app_indicator_new) and
|
TryLoad('app_indicator_new', @app_indicator_new) and
|
||||||
|
Loading…
Reference in New Issue
Block a user