Skip to content

Commit d688f42

Browse files
committed
Update print handler on Linux (#403) and fix print dialog error (#435)
1 parent 357a7fb commit d688f42

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

src/cef_v59..v66_changes.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ MISC
6464
----
6565
+ Compare src/client_handler/dialog_handler_gtk.cpp (and .h) with upstream
6666
cefclient files
67-
- In subprocess/print_handler_gtk.cpp use GetWindow implementation
67+
+ In subprocess/print_handler_gtk.cpp use GetWindow implementation
6868
from x11.cpp
6969

7070
NEW FEATURES

src/client_handler/x11.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// All rights reserved. Licensed under BSD 3-clause license.
33
// Project website: https://github.com/cztomczak/cefpython
44

5+
// NOTE: This file is also used by "subprocess" and "libcefpythonapp"
6+
// targets during build.
7+
58
#include "x11.h"
69
#include "include/base/cef_logging.h"
710

@@ -24,6 +27,7 @@ void InstallX11ErrorHandlers() {
2427
// Copied from upstream cefclient.
2528
// Install xlib error handlers so that the application won't be terminated
2629
// on non-fatal errors. Must be done after initializing GTK.
30+
LOG(INFO) << "[Browser process] Install X11 error handlers";
2731
XSetErrorHandler(XErrorHandlerImpl);
2832
XSetIOErrorHandler(XIOErrorHandlerImpl);
2933
}
@@ -48,6 +52,7 @@ void SetX11WindowTitle(CefRefPtr<CefBrowser> browser, char* title) {
4852
}
4953

5054
GtkWindow* CefBrowser_GetGtkWindow(CefRefPtr<CefBrowser> browser) {
55+
// TODO: Should return NULL when using the Views framework
5156
// -- REWRITTEN FOR CEF PYTHON USE CASE --
5257
// X11 window handle
5358
::Window xwindow = browser->GetHost()->GetWindowHandle();
@@ -68,6 +73,10 @@ GtkWindow* CefBrowser_GetGtkWindow(CefRefPtr<CefBrowser> browser) {
6873
// internally, so GTK wasn't yet initialized and must do it
6974
// now, so that display is available. Also must install X11
7075
// 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.
7180
LOG(INFO) << "[Browser process] Initialize GTK";
7281
gtk_init(0, NULL);
7382
InstallX11ErrorHandlers();

src/subprocess/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ else ifeq ($(UNAME_S), Darwin)
3535
endif
3636

3737
ifeq ($(UNAME_S), Linux)
38-
CPP_FILES = print_handler_gtk.cpp
39-
LIBS = -lcef -lgobject-2.0 -lglib-2.0 -lgtk-x11-2.0
38+
CPP_FILES = print_handler_gtk.cpp ../client_handler/x11.cpp
39+
LIBS = -lcef -lX11 -lgobject-2.0 -lglib-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0
4040
else ifeq ($(UNAME_S), Darwin)
4141
CPP_FILES =
4242
# Include framework before libcef_dll_wrapper

src/subprocess/Makefile-libcefpythonapp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ UNAME_S = $(shell uname -s)
1212
CCFLAGS = -fPIC -DBROWSER_PROCESS $(CEF_CCFLAGS)
1313

1414
ifeq ($(UNAME_S), Linux)
15-
SRC_MORE = print_handler_gtk.cpp \
15+
SRC_MORE = print_handler_gtk.cpp ../client_handler/x11.cpp \
1616
main_message_loop/main_message_loop_external_pump_linux.cpp
1717
else ifeq ($(UNAME_S), Darwin)
1818
SRC_MORE = main_message_loop/main_message_loop_external_pump_mac.mm

src/subprocess/cefpython_app.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <gtk/gtk.h>
2222
#include <gdk/gdk.h>
2323
#include <gdk/gdkx.h>
24+
#include "client_handler/x11.h"
2425
#include "print_handler_gtk.h"
2526
#endif // OS_LINUX
2627
#endif // BROWSER_PROCESS
@@ -221,10 +222,14 @@ CefRefPtr<CefPrintHandler> CefPythonApp::GetPrintHandler() {
221222
#if defined(OS_LINUX)
222223
// For print handler to work GTK must be initialized. This is
223224
// required for some of the examples.
225+
// --
226+
// A similar code is in client_handler/x11.cpp. If making changes here,
227+
// make changes there as well.
224228
GdkDisplay* gdk_display = gdk_display_get_default();
225229
if (!gdk_display) {
226230
LOG(INFO) << "[Browser process] Initialize GTK";
227231
gtk_init(0, NULL);
232+
InstallX11ErrorHandlers();
228233
}
229234
#endif
230235
#endif

src/subprocess/print_handler_gtk.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "include/wrapper/cef_helpers.h"
2020
#include "include/wrapper/cef_closure_task.h"
2121

22+
#include "client_handler/x11.h"
23+
2224
namespace {
2325

2426
// CUPS Duplex attribute and values.
@@ -374,7 +376,7 @@ struct ClientPrintHandlerGtk::PrintHandler {
374376
CefRefPtr<CefPrintDialogCallback> callback) {
375377
dialog_callback_ = callback;
376378

377-
GtkWindow* parent = GetWindow();
379+
GtkWindow* parent = CefBrowser_GetGtkWindow(browser_);
378380
// TODO(estade): We need a window title here.
379381
dialog_ = gtk_print_unix_dialog_new(NULL, parent);
380382
g_signal_connect(dialog_, "delete-event",
@@ -429,18 +431,6 @@ struct ClientPrintHandlerGtk::PrintHandler {
429431
}
430432

431433
private:
432-
// Returns the GtkWindow* for the browser. Will return NULL when using the
433-
// Views framework.
434-
GtkWindow* GetWindow() {
435-
// TODO(cefpython): Test the code that is commented out whether it works
436-
/*
437-
CefWindowHandle hwnd = browser_->GetWindowHandle();
438-
if (hwnd)
439-
return GTK_WINDOW(hwnd);
440-
*/
441-
return NULL;
442-
}
443-
444434
void OnDialogResponse(GtkDialog* dialog, gint response_id) {
445435
int num_matched_handlers = g_signal_handlers_disconnect_by_func(
446436
dialog_, reinterpret_cast<gpointer>(&OnDialogResponseThunk), this);

0 commit comments

Comments
 (0)