1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Added GlobalCEFApp.DisplayServer

Added TCefLinuxDisplayServer
Check if the display server is X11 before trying to get a PXDisplay value.
This commit is contained in:
Salvador Díaz Fau
2025-10-11 17:16:53 +02:00
parent 3701c7b4b0
commit 30a66a035b
4 changed files with 67 additions and 29 deletions

View File

@@ -174,7 +174,8 @@ type
// Fields used during the CEF initialization
FWindowsSandboxInfo : pointer;
{$IFDEF LINUX}
FArgCopy : TCEFArgCopy;
FArgCopy : TCEFArgCopy;
FDisplayServer : TCefLinuxDisplayServer;
{$ENDIF}
// Fields used by custom properties
@@ -403,6 +404,9 @@ type
{$IFDEF MACOSX}
function CheckMacOSVersion : boolean; virtual;
{$ENDIF}
{$IFDEF LINUX}
procedure ReadDisplayServer;
{$ENDIF}
function CheckOSVersion: boolean; virtual;
procedure ShowErrorMessageDlg(const aError : string); virtual;
function ParseProcessType : TCefProcessType;
@@ -1363,6 +1367,10 @@ type
/// <para><see href="https://peter.sh/experiments/chromium-command-line-switches/#ozone-platform">Uses the following command line switch: --ozone-platform</see></para>
/// </remarks>
property OzonePlatform : TCefOzonePlatform read FOzonePlatform write FOzonePlatform;
/// <summary>
/// Linux display server type.
/// </summary>
property DisplayServer : TCefLinuxDisplayServer read FDisplayServer;
{$ENDIF}
/// <summary>
/// Ignores certificate-related errors.
@@ -2103,6 +2111,7 @@ begin
FPasswordStorage := psDefault;
FGTKVersion := gtkVersionDefault;
FOzonePlatform := ozpDefault;
FDisplayServer := ldsUnknown;
{$ENDIF}
// Fields used during the CEF initialization
@@ -2454,8 +2463,33 @@ begin
FCustomCommandLines := TStringList.Create;
FCustomCommandLineValues := TStringList.Create;
FComponentIDList := TCEFComponentIDList.Create;
{$IFDEF LINUX}
ReadDisplayServer;
{$ENDIF}
end;
{$IFDEF LINUX}
procedure TCefApplicationCore.ReadDisplayServer;
{$IFDEF FPC}
var
TempSession : AnsiString;
{$ENDIF}
begin
{$IFDEF FPC}
TempSession := GetEnvironmentVariable('XDG_SESSION_TYPE');
if (TempSession = 'wayland') then
FDisplayServer := ldsWayland
else
if (TempSession = 'x11') then
FDisplayServer := ldsX11
else
FDisplayServer := ldsUnknown;
{$ENDIF}
// TO-DO : Find a way to get read the value of an environment variable or the display server type in FMXLinux.
end;
{$ENDIF}
procedure TCefApplicationCore.AddCustomCommandLine(const aCommandLine, aValue : string);
begin
if (FCustomCommandLines <> nil) then FCustomCommandLines.Add(aCommandLine);

View File

@@ -5916,38 +5916,38 @@ var
TempParent : TCefWindowHandle;
{$ENDIF}
begin
Result := nil;
try
if (FXDisplay = nil) then
begin
{$IFDEF FPC}
{$IFDEF LCLGTK2}
TempParent := ParentFormHandle;
try
if (FXDisplay = nil) and (GlobalCEFApp.DisplayServer = ldsX11) then
begin
{$IFDEF FPC}
{$IFDEF LCLGTK2}
TempParent := ParentFormHandle;
if ValidCefWindowHandle(TempParent) and
(PGtkWidget(TempParent)^.Window <> nil) then
FXDisplay := GDK_WINDOW_XDISPLAY(PGtkWidget(TempParent)^.Window);
if ValidCefWindowHandle(TempParent) and
(PGtkWidget(TempParent)^.Window <> nil) then
FXDisplay := GDK_WINDOW_XDISPLAY(PGtkWidget(TempParent)^.Window);
{$ENDIF}
{$IFDEF LCLGTK3}
FXDisplay := gdk_x11_get_default_xdisplay();
{$ENDIF}
{$IF DEFINED(LCLQT) OR DEFINED(LCLQT5)}
FXDisplay := QX11Info_display();
{$IFEND}
{$IFDEF LCLQT6}
FXDisplay := TQtWidgetSet(WidgetSet).x11Display;
{$ENDIF}
{$ENDIF}
{$IFDEF LCLGTK3}
FXDisplay := gdk_x11_get_default_xdisplay();
{$ENDIF}
{$IF DEFINED(LCLQT) OR DEFINED(LCLQT5)}
FXDisplay := QX11Info_display();
{$IFEND}
{$IFDEF LCLQT6}
FXDisplay := TQtWidgetSet(WidgetSet).x11Display;
{$ENDIF}
{$ENDIF}
end;
end;
except
on e : exception do
if CustomExceptionHandler('TChromiumCore.GetXDisplay', e) then raise;
end;
finally
if (FXDisplay = nil) then
Result := FGlobalXDisplay
else
Result := FXDisplay;
except
on e : exception do
if CustomExceptionHandler('TChromiumCore.GetXDisplay', e) then raise;
end;
end;
@@ -5955,8 +5955,7 @@ procedure TChromiumCore.ReadGlobalXDisplay;
begin
try
// GlobalCEFApp.XDisplay can only be called in the CEF UI thread.
if (GlobalCEFApp <> nil) then
FGlobalXDisplay := GlobalCEFApp.XDisplay;
FGlobalXDisplay := GlobalCEFApp.XDisplay;
except
on e : exception do
if CustomExceptionHandler('TChromiumCore.ReadGlobalXDisplay', e) then raise;

View File

@@ -1485,6 +1485,11 @@ type
kDefault = 3
);
/// <summary>
/// Linux session type. Used to check whether the display server is Xorg or Wayland.
/// </summary>
TCefLinuxDisplayServer = (ldsX11, ldsWayland, ldsUnknown);
/// <summary>
/// Used by TCEFFileDialogInfo.
/// </summary>

View File

@@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 797,
"InternalVersion" : 798,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "140.1.14"
}