|
| 1 | +// Copyright (c) 2016 The CEF Python authors. All rights reserved. |
| 2 | + |
| 3 | +#include <X11/Xlib.h> |
| 4 | +#include "LOG_DEBUG.h" |
| 5 | +#include "include/cef_browser.h" |
| 6 | + |
| 7 | +int XErrorHandlerImpl(Display *display, XErrorEvent *event) { |
| 8 | + LOG_DEBUG |
| 9 | + << "X error received: " |
| 10 | + << "type " << event->type << ", " |
| 11 | + << "serial " << event->serial << ", " |
| 12 | + << "error_code " << static_cast<int>(event->error_code) << ", " |
| 13 | + << "request_code " << static_cast<int>(event->request_code) << ", " |
| 14 | + << "minor_code " << static_cast<int>(event->minor_code); |
| 15 | + return 0; |
| 16 | +} |
| 17 | + |
| 18 | +int XIOErrorHandlerImpl(Display *display) { |
| 19 | + return 0; |
| 20 | +} |
| 21 | + |
| 22 | +void InstallX11ErrorHandlers() { |
| 23 | + // Copied from upstream cefclient. |
| 24 | + // Install xlib error handlers so that the application won't be terminated |
| 25 | + // on non-fatal errors. Must be done after initializing GTK. |
| 26 | + XSetErrorHandler(XErrorHandlerImpl); |
| 27 | + XSetIOErrorHandler(XIOErrorHandlerImpl); |
| 28 | +} |
| 29 | + |
| 30 | +void SetXWindowBounds(::Window xwindow, |
| 31 | + int x, int y, size_t width, size_t height) { |
| 32 | + ::Display* xdisplay = cef_get_xdisplay(); |
| 33 | + XWindowChanges changes = {0}; |
| 34 | + changes.x = x; |
| 35 | + changes.y = y; |
| 36 | + changes.width = static_cast<int>(width); |
| 37 | + changes.height = static_cast<int>(height); |
| 38 | + XConfigureWindow(xdisplay, xwindow, |
| 39 | + CWX | CWY | CWHeight | CWWidth, &changes); |
| 40 | +} |
| 41 | + |
| 42 | +void SetX11WindowBounds(CefRefPtr<CefBrowser> browser, |
| 43 | + int x, int y, int width, int height) { |
| 44 | + ::Window xwindow = browser->GetHost()->GetWindowHandle(); |
| 45 | + SetXWindowBounds(xwindow, x, y, width, height); |
| 46 | +} |
0 commit comments