From 8e223c396b8f4f15401ff9b2c417b2930067d46f Mon Sep 17 00:00:00 2001 From: maxim Date: Fri, 18 Oct 2019 22:05:33 +0000 Subject: [PATCH] Merged revision(s) 62003 #d3daac07ac, 62020 #690b7498e7, 62062 #c164409c0a from trunk: LCL-GTK2: Improve logic for loading LibAppIndicator3 for TrayIcon. Based on research by D.Bannon. Issue #35723. ........ LCL-GTK2: Add Debian to the list of distros that need the AppIndicator lib. Optimize a little. Issue #35723. ........ LCL-GTK2: Improve the logic for loading LibAppIndicator3 lib. Support an environment variable LAZUSEAPPIND. Issue #35723, patch from David. ........ git-svn-id: branches/fixes_2_0@62083 - --- lcl/interfaces/gtk2/unitywsctrls.pas | 86 ++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/lcl/interfaces/gtk2/unitywsctrls.pas b/lcl/interfaces/gtk2/unitywsctrls.pas index 1dc7e805a8..5f0fc8a2a0 100644 --- a/lcl/interfaces/gtk2/unitywsctrls.pas +++ b/lcl/interfaces/gtk2/unitywsctrls.pas @@ -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 } @@ -253,9 +260,40 @@ var Initialized: Boolean; function UnityAppIndicatorInit: Boolean; -var - Module: HModule; - DeskTop: String; + 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 @@ -268,17 +306,29 @@ begin if Loaded then Exit(Initialized); Loaded := True; - DeskTop := GetEnvironmentVariableUTF8('XDG_CURRENT_DESKTOP'); - if (DeskTop = 'KDE') or (DeskTop = 'X-Cinnamon') then - begin - Initialized := False; - Exit; - end; if Initialized then Exit(True); - Module := LoadLibrary(libappindicator_3); // thats the one we want here. - if Module = 0 then // no libappindicator_3 - Exit; // hope libappindicator_1 can help you .... + 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 TryLoad('app_indicator_new', @app_indicator_new) and @@ -300,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;