Merge branch 'gtk1-fix-startup-warnings' into 'main'

LCL-GTK1: Fix various startup warnings and Gtk1 assertions

See merge request freepascal.org/lazarus/lazarus!255
This commit is contained in:
Maxim Ganetsky 2023-11-30 23:43:43 +00:00
commit 686e828103
5 changed files with 59 additions and 10 deletions

View File

@ -37,10 +37,13 @@ begin
Exit; // the GTKAPIWidget is self drawn, so no use to change the widget style.
if (GTK_WIDGET_REALIZED(AWidget)) then
WindowStyle := gtk_style_copy(gtk_widget_get_style(AWidget))
WindowStyle := gtk_widget_get_style(AWidget)
else
WindowStyle := gtk_style_copy(gtk_rc_get_style(AWidget));
WindowStyle := gtk_rc_get_style(AWidget);
if WindowStyle <> nil then
WindowStyle := gtk_style_copy(WindowStyle);
if (Windowstyle = nil) then
Windowstyle := gtk_style_new;

View File

@ -33,8 +33,22 @@
{off $Define Disable_GC_SysColors}
{$define HideKeyTableWarnings}
{$define RawimageConsistencyChecks}
(*
Gtk1 uses a GTK_MODULES environment variable that causes it to load modules
at startup, however this variable is also used by Gtk2 and Gtk3, meaning
that if a referenced module is not part of the available Gtk1 modules the
program will display a warning at startup time. Since as of 2023 pretty much
no distribution comes with Gtk1 this is always a bogus warning and to avoid
this, the GTK_MODULES environment variable will be cleaned during startup and
reset after the toolkit has been initialized to allow for Gtk2 and later child
processes.
*)
{$define ClearGtkModulesEnvVar}
(*
keep track of keystates instead of using OS
This is the old mode and might be removed

View File

@ -3193,7 +3193,7 @@ var
XKeyEvent: TXKeyEvent;
KeySymStart, KeySymNext: PKeySym;
UpKeySym, LoKeySym: TKeySym;
KeySyms: array of TKeySym;
KeySyms: array of TKeySym = nil;
{$else}
KeySyms: array of guint;
KeyVals: Pguint;
@ -3214,7 +3214,7 @@ var
KeyCode: Byte;
m: Integer;
LoKey, HiKey: Integer;
LoKey, HiKey, I: Integer;
VKey, FreeVK: Byte;
HasMultiVK, DummyBool, Extended, SecondKey, HasKey, ComputeVK: Boolean;
@ -3258,8 +3258,14 @@ begin
then XFree(KeySymStart);
Exit;
end;
if KeySymCount > Length(MVKeyInfo[0].KeySym)
then DebugLn('[WARNING] keysymcount=%u larger than expected=%u', [KeySymCount, Length(MVKeyInfo[0].KeySym)]);
// The code in Accelerate below assumes at least 2 items in the KeySym array
if KeySymCount > 2 then begin
for I:=Low(MVKeyInfo) to High(MVKeyInfo) do
SetLength(MVKeyInfo[I].KeySym, KeySymCount);
end else begin
for I:=Low(MVKeyInfo) to High(MVKeyInfo) do
SetLength(MVKeyInfo[I].KeySym, 2);
end;
SetLength(KeySyms, KeySymCount);
{$else gtk1}
LoKey := 0;

View File

@ -417,7 +417,7 @@ type
TVKeyUTF8Char = array[0..7] of Char;
TVKeyInfo = record
KeyCode: array[Boolean] of Byte; // false is primary keycode, true the keycode of the other key when 2 keys exist (like CTRL or extended key)
KeySym: array[0..7] of Integer;
KeySym: array of Integer;
KeyChar: array[0..3] of TVKeyUTF8Char;
end;

View File

@ -148,6 +148,10 @@ begin
fpsigaction(SIGCHLD, @child_action, nil);
end;
{$ifdef ClearGtkModulesEnvVar}
function setenv(envname, envvar: PAnsiChar; overwrite: cint): cint; cdecl; external 'c' name 'setenv';
{$endif}
{$endif}
{------------------------------------------------------------------------------
@ -164,6 +168,10 @@ var
TM: TThreadManager;
{$ENDIF}
{$ENDIF}
{$ifdef ClearGtkModulesEnvVar}
var
OldGtkModulesValue: AnsiString;
{$endif}
begin
if ClassType = TGtkWidgetSet
then raise EInvalidOperation.Create('Cannot create the base gtkwidgetset, use gtk1 or gtk2 instead');
@ -226,9 +234,20 @@ begin
// initialize app level gtk engine
gtk_set_locale ();
// clear the GTK_MODULES environment variable if needed
{$ifdef ClearGtkModulesEnvVar}
OldGtkModulesValue:=GetEnvironmentVariable('GTK_MODULES');
setenv('GTK_MODULES', '', 1);
{$endif}
// call init and pass cmd line args
PassCmdLineOptions;
// restore the GTK_MODULES environment variable
{$ifdef ClearGtkModulesEnvVar}
setenv('GTK_MODULES', PAnsiChar(OldGtkModulesValue), 1);
{$endif}
// set glib log handler
FLogHandlerID := g_log_set_handler(nil, -1, @GLogFunc, Self);
@ -1054,9 +1073,11 @@ begin
{$ENDIF}
if (GTK_WIDGET_REALIZED(AWidget)) then
WindowStyle := gtk_style_copy(gtk_widget_get_style(AWidget))
WindowStyle := gtk_widget_get_style(AWidget)
else
WindowStyle := gtk_style_copy(gtk_rc_get_style(AWidget));
WindowStyle := gtk_rc_get_style(AWidget);
if WindowStyle <> nil then WindowStyle := gtk_style_copy(WindowStyle);
if (Windowstyle = nil) then
Windowstyle := gtk_style_new;
@ -3791,6 +3812,11 @@ begin
LM_DROPFILES:
ConnectSenderSignal(gCore, 'drag_data_received', @GtkDragDataReceived);
LM_CONTEXTMENU:
begin
// Gtk1 does not have an explicit context menu signal, LM_CONTEXTMENU
// support is emulated in gtkMouseBtnPress
end;
(*
LM_WINDOWPOSCHANGED:
begin