mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-25 04:20:24 +02:00
LCL-GTK2: Improve the logic for loading LibAppIndicator3 lib. Support an environment variable LAZUSEAPPIND. Issue #35723, patch from David.
git-svn-id: trunk@62062 -
This commit is contained in:
parent
bb2517cbf1
commit
c164409c0a
@ -10,14 +10,21 @@ interface
|
||||
uses
|
||||
GLib2, Gtk2, Gdk2Pixbuf,
|
||||
Classes, SysUtils, dynlibs,
|
||||
Graphics, Controls, Forms, ExtCtrls, WSExtCtrls, LCLType, LazUTF8;
|
||||
Graphics, Controls, Forms, ExtCtrls, WSExtCtrls, LCLType, LazUTF8,
|
||||
FileUtil;
|
||||
|
||||
{ Changed priority, now use libappindicator_3 if available. ~_3 is, nominally
|
||||
a Unity thing but Ubuntu and several other distros ship it (and support it) with
|
||||
Gnome desktops.
|
||||
{ Changed October 2019, we now try and identify those Linux distributions that
|
||||
need to use LibAppIndicator3 and allow the remainder to use the older and
|
||||
more functional SystemTray. Only a few old distributions can use LibAppIndicator_1
|
||||
so don't bother to try it, rely, here on LibAppIndicator3
|
||||
|
||||
As of U19.04, libappindicator_1, even if present, does not seem to work.
|
||||
The 'look up table' in NeedAppIndicator() can be overridden.
|
||||
Introduce an optional env var, LAZUSEAPPIND that can be unset or set to
|
||||
YES, NO or INFO - YES forces an attempt to use LibAppIndicator3, NO prevents
|
||||
an attempt, any non blank value (eg INFO) displays to std out what is happening.
|
||||
|
||||
Note we assume this env var will only be used in Linux were its always safe to
|
||||
write to stdout.
|
||||
DRB
|
||||
}
|
||||
|
||||
@ -252,35 +259,41 @@ var
|
||||
Loaded: Boolean;
|
||||
Initialized: Boolean;
|
||||
|
||||
function NeedAppIndicator: boolean;
|
||||
var
|
||||
DeskTop, VersionSt : String;
|
||||
ProcFile: TextFile;
|
||||
begin
|
||||
DeskTop := GetEnvironmentVariableUTF8('XDG_CURRENT_DESKTOP');
|
||||
if DeskTop = 'Unity' then exit(True);
|
||||
// GNOME needs AppIndicator lib only with some distros. Check them.
|
||||
if (DeskTop = 'GNOME') then
|
||||
begin
|
||||
AssignFile(ProcFile, '/proc/version');
|
||||
try
|
||||
reset(ProcFile);
|
||||
readln(ProcFile, VersionSt);
|
||||
finally
|
||||
CloseFile(ProcFile);
|
||||
end;
|
||||
if (pos('Debian', VersionSt) > 0)
|
||||
or (pos('mageia', VersionSt) > 0)
|
||||
or (pos('Red Hat', VersionSt) > 0)
|
||||
or (pos('SUSE', VersionSt) > 0)
|
||||
then exit(True);
|
||||
end;
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
function UnityAppIndicatorInit: Boolean;
|
||||
var
|
||||
Module: HModule;
|
||||
var
|
||||
Module: HModule;
|
||||
UseAppInd : string;
|
||||
|
||||
function NeedAppIndicator: boolean;
|
||||
var
|
||||
DeskTop, VersionSt : String;
|
||||
ProcFile: TextFile;
|
||||
begin
|
||||
DeskTop := GetEnvironmentVariableUTF8('XDG_CURRENT_DESKTOP');
|
||||
// See the wiki for details of what extras these desktops require !!
|
||||
if (DeskTop = 'Unity')
|
||||
or (Desktop = 'Enlightenment')
|
||||
then exit(True);
|
||||
if (DeskTop = 'GNOME') then begin
|
||||
{$PUSH}
|
||||
{$IOChecks off}
|
||||
AssignFile(ProcFile, '/proc/version');
|
||||
reset(ProcFile);
|
||||
if IOResult<>0 then exit(false);
|
||||
{$POP}
|
||||
readln(ProcFile, VersionSt);
|
||||
CloseFile(ProcFile);
|
||||
if ( (pos('mageia', VersionSt) > 0) or
|
||||
(pos('Debian', VersionSt) > 0) or
|
||||
(pos('Red Hat', VersionSt) > 0) or
|
||||
(pos('SUSE', VersionSt) > 0) )
|
||||
// 19.04 and earlier Ubuntu Gnome does not need LibAppIndicator3
|
||||
then exit(True);
|
||||
end;
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function TryLoad(const ProcName: string; var Proc: Pointer): Boolean;
|
||||
begin
|
||||
@ -293,15 +306,28 @@ begin
|
||||
if Loaded then
|
||||
Exit(Initialized);
|
||||
Loaded := True;
|
||||
if not NeedAppIndicator then
|
||||
begin
|
||||
Initialized := False;
|
||||
Exit;
|
||||
end;
|
||||
if Initialized then
|
||||
Exit(True);
|
||||
Module := LoadLibrary(libappindicator_3); // libappindicator v. 3
|
||||
if Module = 0 then // no libappindicator_3
|
||||
UseAppInd := getEnvironmentVariable('LAZUSEAPPIND');
|
||||
if UseAppInd = 'NO' then
|
||||
begin
|
||||
Initialized := False;
|
||||
writeln('APPIND Debug : Choosing to not try AppIndicator3');
|
||||
Exit;
|
||||
end;
|
||||
if (UseAppInd <> 'YES') and (not NeedAppIndicator()) then // ie its NO or blank or INFO
|
||||
begin
|
||||
Initialized := False;
|
||||
if UseAppInd <> '' then
|
||||
writeln('APPIND Debug : Will not use AppIndicator3');
|
||||
Exit;
|
||||
end;
|
||||
if UseAppInd = 'YES' then // either a YES or OS needs it
|
||||
writeln('APPIND Debug : Will try to force AppIndicator3')
|
||||
else
|
||||
if UseAppInd <> '' then writeln('APPIND Debug : OS and Desktop request AppIndicator3');
|
||||
Module := LoadLibrary(libappindicator_3); // might have several package names, see wiki
|
||||
if Module = 0 then
|
||||
Exit;
|
||||
Result :=
|
||||
TryLoad('app_indicator_get_type', @app_indicator_get_type) and
|
||||
@ -324,6 +350,8 @@ begin
|
||||
TryLoad('app_indicator_get_label', @app_indicator_get_label) and
|
||||
TryLoad('app_indicator_get_label_guide', @app_indicator_get_label_guide) and
|
||||
TryLoad('app_indicator_get_ordering_index', @app_indicator_get_ordering_index);
|
||||
if UseAppInd <> '' then
|
||||
writeln('APPIND Debug : AppIndicator3 has loaded ' + booltostr(Result, True));
|
||||
Initialized := Result;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user