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

Improved functions to read the screen scale in FMX

Fixed FMXExternalPumpBrowser2 initialization issue in Linux
This commit is contained in:
salvadordf
2022-06-26 17:53:54 +02:00
parent 1239c09282
commit 63d5156cec
7 changed files with 68 additions and 8 deletions

View File

@@ -0,0 +1,22 @@
{*******************************************************}
{ }
{ Linux FireMonkey Platform }
{ }
{ Copyright(c) 2017-2019 Eugene Kryukov. }
{ All rights reserved }
{ }
{*******************************************************}
unit FMUX.Config;
interface
// Chromium requires that the process has only one thread when it's initialized.
// FmuxInit must be called after the Chromium initialization.
// Setting DoNotCallFmuxInit to True allows us to call FmuxInit after that.
var
DoNotCallFmuxInit: Boolean = True;
implementation
end.

View File

@@ -38,6 +38,9 @@
program FMXExternalPumpBrowser2; program FMXExternalPumpBrowser2;
uses uses
// FMUX.Config.pas belongs to the FMXLinux project but we need to override it.
// Read the comments in that unit for more details.
FMUX.Config in 'FMUX.Config.pas',
// FMX initializes GTK in the initialization section of some of its units and // FMX initializes GTK in the initialization section of some of its units and
// that means that GTK is already initialized when the code in the DPR is // that means that GTK is already initialized when the code in the DPR is
// executed. // executed.
@@ -58,6 +61,8 @@ uses
{$R *.res} {$R *.res}
begin begin
// At this point it's safe to initialize GTK
InitializeGTK;
Application.Initialize; Application.Initialize;
Application.CreateForm(TFMXExternalPumpBrowserFrm, FMXExternalPumpBrowserFrm); Application.CreateForm(TFMXExternalPumpBrowserFrm, FMXExternalPumpBrowserFrm);
Application.Run; Application.Run;

View File

@@ -142,6 +142,7 @@
<DelphiCompile Include="$(MainSource)"> <DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource> <MainSource>MainSource</MainSource>
</DelphiCompile> </DelphiCompile>
<DCCReference Include="FMUX.Config.pas"/>
<DCCReference Include="uCEFLoader.pas"/> <DCCReference Include="uCEFLoader.pas"/>
<DCCReference Include="uFMXExternalPumpBrowser2.pas"> <DCCReference Include="uFMXExternalPumpBrowser2.pas">
<Form>FMXExternalPumpBrowserFrm</Form> <Form>FMXExternalPumpBrowserFrm</Form>

View File

@@ -48,9 +48,12 @@ uses
// Read the answer to this question for more more information : // Read the answer to this question for more more information :
// https://stackoverflow.com/questions/52103407/changing-the-initialization-order-of-the-unit-in-delphi // https://stackoverflow.com/questions/52103407/changing-the-initialization-order-of-the-unit-in-delphi
System.IOUtils, System.IOUtils,
FMUX.Api, // FMUX.Api is part of the FMXLinux project
uCEFApplication, uCEFConstants, uCEFTimerWorkScheduler, uCEFLinuxFunctions, uCEFApplication, uCEFConstants, uCEFTimerWorkScheduler, uCEFLinuxFunctions,
uCEFLinuxTypes; uCEFLinuxTypes;
procedure InitializeGTK;
implementation implementation
function CustomX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent):longint;cdecl; function CustomX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent):longint;cdecl;
@@ -107,11 +110,25 @@ begin
GlobalCEFApp.DisableFeatures := 'HardwareMediaKeyHandling'; GlobalCEFApp.DisableFeatures := 'HardwareMediaKeyHandling';
GlobalCEFApp.StartMainProcess; GlobalCEFApp.StartMainProcess;
end;
procedure FmuxLog(S: PChar); cdecl;
begin
Writeln(S);
end;
procedure InitializeGTK;
begin
FmuxSetLog(FmuxLog);
FmuxInit(FMUX_INIT_NOWAYLAND);
// Install xlib error handlers so that the application won't be terminated // Install xlib error handlers so that the application won't be terminated
// on non-fatal errors. Must be done after initializing GTK. // on non-fatal errors. Must be done after initializing GTK.
XSetErrorHandler(@CustomX11ErrorHandler); XSetErrorHandler(@CustomX11ErrorHandler);
XSetIOErrorHandler(@CustomXIOErrorHandler); XSetIOErrorHandler(@CustomXIOErrorHandler);
// GTK is now initialized and we can read the screen scale.
GlobalCEFApp.UpdateDeviceScaleFactor;
end; end;
initialization initialization

View File

@@ -417,9 +417,12 @@ begin
{$ENDIF} {$ENDIF}
{$IFDEF LINUX} {$IFDEF LINUX}
// TODO: Get the scale of the screen where the parent form is located in FMXLinux if (Screen.DisplayCount = 1) then
Result := False; aResultScale := Screen.Displays[0].Scale
aResultScale := 1; else
aResultScale := Screen.DisplayFromForm(GetParentForm).Scale;
Result := True;
{$ENDIF} {$ENDIF}
{$IFDEF MACOS} {$IFDEF MACOS}

View File

@@ -2369,7 +2369,8 @@ var
{$ELSE} {$ELSE}
{$IFDEF FMX} {$IFDEF FMX}
var var
TempService: IFMXScreenService; TempService : IFMXScreenService;
TempWidth, TempWidthMM : integer;
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}
begin begin
@@ -2396,13 +2397,24 @@ begin
else else
Result := USER_DEFAULT_SCREEN_DPI; Result := USER_DEFAULT_SCREEN_DPI;
{$ELSE} {$ELSE}
Result := -1;
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, TempService) then if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, TempService) then
Result := round(TempService.GetScreenScale * USER_DEFAULT_SCREEN_DPI) Result := round(TempService.GetScreenScale * USER_DEFAULT_SCREEN_DPI);
else
if (Result < 0) then
begin begin
Result := round(gdk_screen_get_resolution(gdk_screen_get_default)); Result := round(gdk_screen_get_resolution(gdk_screen_get_default));
if (Result < 0) then if (Result < 0) then
Result := round(gdk_screen_width / (gdk_screen_width_mm / 25.4)); begin
TempWidthMM := gdk_screen_width_mm;
TempWidth := gdk_screen_width;
if (TempWidthMM > 0) and (TempWidth > 0) then
Result := round(TempWidth / (TempWidthMM / 25.4))
else
Result := USER_DEFAULT_SCREEN_DPI;
end;
end; end;
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}

View File

@@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 406, "InternalVersion" : 407,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "102.0.10.0" "Version" : "102.0.10.0"
} }