Skip to content

Commit

Permalink
x11: Allow overriding default X visuals
Browse files Browse the repository at this point in the history
Otherwise, it crashes with recent GTK+ 3 versions.

Signed-off-by: Jiří Janoušek <[email protected]>
  • Loading branch information
jiri-janousek committed Mar 12, 2018
1 parent 2c8185d commit e57798f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/internal/cef_types_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

typedef union _XEvent XEvent;
typedef struct _XDisplay XDisplay;
typedef unsigned long VisualID;

#include "include/internal/cef_export.h"
#include "include/internal/cef_string.h"
Expand All @@ -60,6 +61,17 @@ extern "C" {
///
CEF_EXPORT XDisplay* cef_get_xdisplay();

///
// Set the system X visual to used by Chromium. It must only be accessed on the browser process UI thread.
// CEF is likely to crash if the visual of the toplevel window is different from the default Chromium visual.
///
CEF_EXPORT void cef_override_system_visual(VisualID visual_id);

///
// Set the RGBA X visual to used by Chromium. It must only be accessed on the browser process UI thread.
///
CEF_EXPORT void cef_override_rgba_visual(VisualID visual_id);

///
// Structure representing CefExecuteProcess arguments.
///
Expand Down
13 changes: 13 additions & 0 deletions libcef/browser/native/window_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <X11/extensions/XInput2.h>

#include "ui/base/x/x11_util.h"
#include "ui/base/x/x11_util_internal.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
Expand Down Expand Up @@ -99,6 +100,18 @@ CEF_EXPORT XDisplay* cef_get_xdisplay() {
return gfx::GetXDisplay();
}

CEF_EXPORT void cef_override_system_visual(VisualID visual_id) {
if (!CEF_CURRENTLY_ON(CEF_UIT))
return;
ui::XVisualManager::GetInstance()->OverrideSystemVisual(visual_id);
}

CEF_EXPORT void cef_override_rgba_visual(VisualID visual_id) {
if (!CEF_CURRENTLY_ON(CEF_UIT))
return;
ui::XVisualManager::GetInstance()->OverrideTransparentVisual(visual_id);
}

CefWindowX11::CefWindowX11(CefRefPtr<CefBrowserHostImpl> browser,
::Window parent_xwindow,
const gfx::Rect& bounds)
Expand Down
4 changes: 4 additions & 0 deletions patch/patch.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,8 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2314
'name': 'mac_widevine_2314',
},
{
# x11: Allow overriding of default X visuals.
'name': 'x11_util',
},
]
36 changes: 36 additions & 0 deletions patch/patches/x11_util.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git ui/base/x/x11_util.cc ui/base/x/x11_util.cc
index dbb8cc534e30..2f79de19b128 100644
--- ui/base/x/x11_util.cc
+++ ui/base/x/x11_util.cc
@@ -1403,6 +1403,14 @@ XVisualManager::XVisualManager()
DCHECK(visuals_.find(transparent_visual_id_) != visuals_.end());
}

+void XVisualManager::OverrideSystemVisual(VisualID visual_id) {
+ system_visual_id_ = visual_id;
+}
+
+void XVisualManager::OverrideTransparentVisual(VisualID visual_id) {
+ transparent_visual_id_ = visual_id;
+}
+
XVisualManager::~XVisualManager() {}

void XVisualManager::ChooseVisualForWindow(bool want_argb_visual,
diff --git ui/base/x/x11_util_internal.h ui/base/x/x11_util_internal.h
index 100d215f6a0d..44c430acc168 100644
--- ui/base/x/x11_util_internal.h
+++ ui/base/x/x11_util_internal.h
@@ -80,6 +80,12 @@ class UI_BASE_X_EXPORT XVisualManager {

// Are all of the system requirements met for using transparent visuals?
bool ArgbVisualAvailable() const;
+
+ // Set a different system visual.
+ void OverrideSystemVisual(VisualID visual_id);
+
+ // Set a different transparent visual.
+ void OverrideTransparentVisual(VisualID visual_id);

~XVisualManager();

0 comments on commit e57798f

Please sign in to comment.