From 0a97240c4c73c968874d4ea40e96bc2ca3376d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Tue, 9 Sep 2025 17:36:08 +0200 Subject: [PATCH] Added code comments to GTKBrowser Removed overloaded UseDefaultX11VisualForGtk Removed overloaded FlushDisplay Added Linux Mint 22.2 mention --- README.md | 2 +- .../GTKBrowser/umainwindow.pas | 40 ++++++++++++++++--- source/uCEFLinuxFunctions.pas | 16 +------- update_CEF4Delphi.json | 2 +- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bd58d946..0cd649af 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The CEF binaries used by CEF4Delphi are available for download at Spotify : CEF4Delphi was developed and tested on Delphi 12.3 and it has been tested in Delphi 6, Delphi XE, Delphi 10, Delphi 11 and Lazarus 4.2/FPC 3.2.2. CEF4Delphi includes VCL, FireMonkey (FMX) and Lazarus components. -CEF4Delphi demos have been tested in Windows 10, Windows 11, Linux Mint 22.1 and Raspberry Pi OS. +CEF4Delphi demos have been tested in Windows 10, Windows 11, Linux Mint 22.2 and Raspberry Pi OS. ## Links * [Installation instructions and more information about CEF4Delphi](https://www.briskbard.com/index.php?lang=en&pageid=cef) diff --git a/demos/Lazarus_Linux_GTK3/GTKBrowser/umainwindow.pas b/demos/Lazarus_Linux_GTK3/GTKBrowser/umainwindow.pas index 4754d147..ba9ef984 100644 --- a/demos/Lazarus_Linux_GTK3/GTKBrowser/umainwindow.pas +++ b/demos/Lazarus_Linux_GTK3/GTKBrowser/umainwindow.pas @@ -15,8 +15,6 @@ type private FCanClose : boolean; FClosing : boolean; - FInitializing : boolean; - FLoading : boolean; FWindow : PGtkWidget; FChromium : TChromium; @@ -63,6 +61,30 @@ function StartMainProcess: boolean; implementation +// This demo is a rough and incomplete translation of the official cefclient +// application for GTK3. + +// There are several missing features and pending issues. This demo was just +// used to test the CEF initialization in GTK3 using low level API functions in +// Lazarus. + +// If you need to add a CEF browser to your GTK3 application then use the code +// in SimpleOSRBrowser. + +// Trying to use the GTK3 WidgetSet in Lazarus to initialize CEF is not possible +// at this moment because: +// - GTK >3.15.1 uses an X11 visual optimized for GTK+'s OpenGL stuff which +// breaks CEF/Chromium. +// - It's necessary to call the UseDefaultX11VisualForGtk procedure before the +// GtkWindow is realized to use the default X11 visual. +// - TGtk3Window.CreateWidget (Gtk3Widgets.pas) realizes the window almost +// immediately after its creation. + +// At this point we can only wait until the CEF/Chromium requirements change. +// Perhaps with Wayland support. + +// Meanwhile GTK3 applications can use CEF browsers in OSR mode only. + var MainAppEvent : TEventObject = nil; @@ -151,8 +173,6 @@ begin FCanClose := False; FClosing := False; - FInitializing := True; - FLoading := False; FWindow := nil; FChromium := nil; end; @@ -195,6 +215,7 @@ procedure TMainWindow.Show; begin // Show the GTK window. UseDefaultX11VisualForGtk(FWindow); + gtk_widget_show_all(FWindow); // Flush the display to make sure the underlying X11 window gets created @@ -235,13 +256,20 @@ end; {%Region} procedure TMainWindow.OnAfterCreated(Sender: TObject; const browser: ICefBrowser); begin - TThread.Synchronize(nil, @DoAfterCreated); + if GlobalCEFApp.MultiThreadedMessageLoop then + TThread.Synchronize(nil, @DoAfterCreated) + else + DoAfterCreated; end; procedure TMainWindow.OnBeforeClose(Sender: TObject; const browser: ICefBrowser); begin FCanClose := True; - TThread.Synchronize(nil, @DoBeforeClose); + + if GlobalCEFApp.MultiThreadedMessageLoop then + TThread.Synchronize(nil, @DoBeforeClose) + else + DoBeforeClose; end; procedure TMainWindow.OnBeforePopup(Sender: TObject; diff --git a/source/uCEFLinuxFunctions.pas b/source/uCEFLinuxFunctions.pas index 3373ca05..3947fc88 100644 --- a/source/uCEFLinuxFunctions.pas +++ b/source/uCEFLinuxFunctions.pas @@ -65,10 +65,8 @@ procedure gdk_set_allowed_backends(const backends: PGchar); cdecl; external 'lib function gdk_x11_display_get_xdisplay(display: PGdkDisplay): PDisplay; cdecl; external 'libgdk-3.so.0'; function gdk_x11_screen_get_screen_number(screen: PGdkScreen): longint; cdecl; external 'libgdk-3.so.0'; function gdk_x11_visual_get_xvisual(visual: PGdkVisual): PVisual; cdecl; external 'libgdk-3.so.0'; -procedure UseDefaultX11VisualForGtk(widget : PGtkWidget); overload; -procedure UseDefaultX11VisualForGtk(aHandle : TCefWindowHandle); overload; -procedure FlushDisplay(widget : PGtkWidget); overload; -procedure FlushDisplay(aHandle : TCefWindowHandle); overload; +procedure UseDefaultX11VisualForGtk(widget : PGtkWidget); +procedure FlushDisplay(widget : PGtkWidget); {$ENDIF} procedure ShowX11Message(const aMessage : string); {$ENDIF}{$ENDIF} @@ -735,11 +733,6 @@ begin g_list_free(visuals); end; -procedure UseDefaultX11VisualForGtk(aHandle : TCefWindowHandle); -begin - UseDefaultX11VisualForGtk(TGtk3Widget(aHandle).Widget); -end; - procedure FlushDisplay(widget : PGtkWidget); var gdk_window : PGdkWindow; @@ -749,11 +742,6 @@ begin display := gdk_window_get_display(gdk_window); gdk_display_flush(display); end; - -procedure FlushDisplay(aHandle : TCefWindowHandle); -begin - FlushDisplay(TGtk3Widget(aHandle).Widget); -end; {$ENDIF} {$ENDIF} diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index 7f204361..cff6e926 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 780, + "InternalVersion" : 781, "Name" : "cef4delphi_lazarus.lpk", "Version" : "139.0.38" }