lazarus编译的程序在树莓派运行前先出一个空白窗口,要关闭这个窗口后才能显示正常的窗体(使用wayland窗口类型的linux也可能存在同样情况)。
Gtk2: better recognition of wayland session, do not create dummy frame. (54ba042f) · 提交 · FPC / Lazarus / Lazarus · GitLab
以下是官方的修改方法(lazarus 4.0RC1),其他版本可以参考修改:
1、lcl/interfaces/gtk2/gtk2int.pas
在79行添加红色代码:
Gtk2: better recognition of wayland session, do not create dummy frame. (54ba042f) · 提交 · FPC / Lazarus / Lazarus · GitLab
以下是官方的修改方法(lazarus 4.0RC1),其他版本可以参考修改:
1、lcl/interfaces/gtk2/gtk2int.pas
在79行添加红色代码:
{$IFNDEF USE_GTK_MAIN_OLD_ITERATION} FMainPoll: PGPollFD; {$ENDIF} {$IFDEF HASX} FIsWayland: boolean; {$ENDIF} FIsLibraryInstance: Boolean; FGtkTerminated: Boolean; FMultiThreadingEnabled: boolean;
在321行添加红色代码:
public {$IFDEF HASX} function CreateDummyWidgetFrame(const ALeft, ATop, AWidth, AHeight: integer): boolean; function GetDummyWidgetFrame: TRect; function compositeManagerRunning: Boolean; function GetDesktopWidget: PGtkWidget; //function X11Raise(AHandle: HWND): boolean; currently not used function GetWindowManager: String; function IsWayland: boolean; function IsCurrentDesktop(AWindow: PGdkWindow): Boolean; function X11GetActiveWindow: HWND; function GetAlwaysOnTopX11(AWindow: PGdkWindow): boolean; procedure HideAllHints; procedure RestoreAllHints; {$ENDIF} procedure StartFocusTimer;
2、lcl/interfaces/gtk2/gtk2widgetset.inc
在1537行添加红色代码:
FIsLibraryInstance := False; FGtkTerminated := False; {$IFDEF HASX} FIsWayland := UTF8LowerCase(GetEnvironmentVariableUTF8('XDG_SESSION_TYPE')) = 'wayland'; {$ELSE} FIsWayland := False; {$ENDIF} {$IFDEF EnabledGtkThreading} {$IFNDEF Win32}
修改红色代码(1942行):
function TGtk2WidgetSet.CreateDummyWidgetFrame(const ALeft, ATop, AWidth, AHeight: integer): boolean; var ADummy: TDummyWidget; WM: String; begin Result := False; WM := GetWindowManager; if (WM = '') or (WM = 'wayland') or IsWayland then exit; ADummy := TDummyWidget.Create; ADummy.ShowDummyWidget(ALeft, ATop, AWidth, AHeight); FWSFrameRect := ADummy.GetWidgetFrame; ADummy.Free; Result := not IsRectEmpty(FWSFrameRect); end;
添加红色代码(4641行)
function TGtk2WidgetSet.IsWayland: boolean; begin Result := FIsWayland; end; function TGtk2WidgetSet.X11GetActiveWindow: HWND; var Display: PDisplay;
3、 lcl/interfaces/gtk2/gtk2wsforms.pp
修改红色代码(428行)
end; {$IFDEF HASX} if (AWinControl = Application.MainForm) and not Gtk2WidgetSet.IsWayland and not Application.HasOption('disableaccurateframe') then Gtk2WidgetSet.CreateDummyWidgetFrame(-1, -1, -1, -1); {$ENDIF}
按上述修改后重新编译应用就可以。