MCPcopy Create free account
hub / github.com/cztomczak/cefpython / CefBrowser_GetGtkWindow

Function CefBrowser_GetGtkWindow

src/client_handler/x11.cpp:54–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54GtkWindow* CefBrowser_GetGtkWindow(CefRefPtr<CefBrowser> browser) {
55 // TODO: Should return NULL when using the Views framework
56 // -- REWRITTEN FOR CEF PYTHON USE CASE --
57 // X11 window handle
58 ::Window xwindow = browser->GetHost()->GetWindowHandle();
59 // X11 display
60 ::Display* xdisplay = cef_get_xdisplay();
61 // GDK display
62 GdkDisplay* gdk_display = NULL;
63 if (xdisplay) {
64 // See if we can find GDK display using X11 display
65 gdk_display = gdk_x11_lookup_xdisplay(xdisplay);
66 }
67 if (!gdk_display) {
68 // If not then get the default display
69 gdk_display = gdk_display_get_default();
70 }
71 if (!gdk_display) {
72 // The tkinter_.py and hello_world.py examples do not use GTK
73 // internally, so GTK wasn't yet initialized and must do it
74 // now, so that display is available. Also must install X11
75 // error handlers to avoid 'BadWindow' errors.
76 // --
77 // A similar code is in cefpython_app.cpp and it might already
78 // been executed. If making changes here, make changes there
79 // as well.
80 LOG(INFO) << "[Browser process] Initialize GTK";
81 gtk_init(0, NULL);
82 InstallX11ErrorHandlers();
83 // Now the display is available
84 gdk_display = gdk_display_get_default();
85 }
86 // In kivy_.py example getting error message:
87 // > Can't create GtkPlug as child of non-GtkSocket
88 // However dialog handler works just fine.
89 GtkWidget* widget = gtk_plug_new_for_display(gdk_display, xwindow);
90 // Getting top level widget doesn't seem to be required.
91 // OFF: GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
92 GtkWindow* window = GTK_WINDOW(widget);
93 if (!window) {
94 LOG(ERROR) << "No GtkWindow for browser";
95 }
96 return window;
97}
98
99XImage* CefBrowser_GetImage(CefRefPtr<CefBrowser> browser) {
100 ::Display* display = cef_get_xdisplay();

Callers 3

OnFileDialogMethod · 0.85
OnJSDialogMethod · 0.85
OnPrintDialogMethod · 0.85

Calls 1

InstallX11ErrorHandlersFunction · 0.85

Tested by

no test coverage detected