Update pygtk_.py and expose new functions required on Linux... · yonick/cefpython@c6973a9 · GitHub
Skip to content

Commit c6973a9

Browse files
committed
Update pygtk_.py and expose new functions required on Linux...
Add WindowUtils.InstallX11ErrorHandlers(). Add Browser.SetBounds() - available only on Linux for now. pygtk_example changes: * Fix focus issue * Fix resize issues * Install X11 error handler
1 parent 276aee1 commit c6973a9

14 files changed

Lines changed: 152 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion

docs/api/API-index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* [ParentWindowWillClose](Browser.md#parentwindowwillclose)
107107
* [Reload](Browser.md#reload)
108108
* [ReloadIgnoreCache](Browser.md#reloadignorecache)
109+
* [SetBounds](Browser.md#setbounds)
109110
* [SendKeyEvent](Browser.md#sendkeyevent)
110111
* [SendMouseClickEvent](Browser.md#sendmouseclickevent)
111112
* [SendMouseMoveEvent](Browser.md#sendmousemoveevent)
@@ -401,6 +402,7 @@
401402
* [IsWindowHandle](WindowUtils.md#iswindowhandle)
402403
* [gtk_plug_new ](WindowUtils.md#gtk_plug_new-linux)
403404
* [gtk_widget_show ](WindowUtils.md#gtk_widget_show-linux)
405+
* [InstallX11ErrorHandlers ](WindowUtils.md#installx11errorhandlers-linux)
404406
* [WindowInfo (class)](WindowInfo.md)
405407
* [SetAsChild](WindowInfo.md#setaschild)
406408
* [SetAsPopup](WindowInfo.md#setaspopup)

docs/api/Browser.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Table of contents:
5050
* [ParentWindowWillClose](#parentwindowwillclose)
5151
* [Reload](#reload)
5252
* [ReloadIgnoreCache](#reloadignorecache)
53+
* [SetBounds](#setbounds)
5354
* [SendKeyEvent](#sendkeyevent)
5455
* [SendMouseClickEvent](#sendmouseclickevent)
5556
* [SendMouseMoveEvent](#sendmousemoveevent)
@@ -530,6 +531,19 @@ Reload the current page.
530531
Reload the current page ignoring any cached data.
531532

532533

534+
### SetBounds
535+
536+
| Parameter | Type |
537+
| --- | --- |
538+
| x | int |
539+
| y | int |
540+
| width | int |
541+
| height | int |
542+
| __Return__ | void |
543+
544+
Linux-only. Set window bounds.
545+
546+
533547
### SendKeyEvent
534548

535549
| Parameter | Type |

docs/api/WindowUtils.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Table of contents:
1717
* [IsWindowHandle](#iswindowhandle)
1818
* [gtk_plug_new (Linux)](#gtk_plug_new-linux)
1919
* [gtk_widget_show (Linux)](#gtk_widget_show-linux)
20+
* [InstallX11ErrorHandlers (Linux)](#installx11errorhandlers-linux)
2021

2122

2223
## Methods
@@ -125,3 +126,14 @@ Linux-only. This method is utilized in the PyQt example.
125126
| __Return__ | void |
126127

127128
Linux-only. This method is utilized in the PyQt example.
129+
130+
131+
### InstallX11ErrorHandlers (Linux)
132+
133+
| | |
134+
| --- | --- |
135+
| __Return__ | void |
136+
137+
Linux-only. Install xlib error handlers so that the application
138+
won't be terminated on non-fatal errors. Must be done after
139+
initializing GTK.

src/browser.pyx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
include "cefpython.pyx"
66

7-
# cef_mouse_button_type_t, SendMouseClickEvent().
87
cimport cef_types
8+
IF UNAME_SYSNAME == "Linux":
9+
cimport x11
10+
11+
# cef_mouse_button_type_t, SendMouseClickEvent().
912
MOUSEBUTTON_LEFT = cef_types.MBT_LEFT
1013
MOUSEBUTTON_MIDDLE = cef_types.MBT_MIDDLE
1114
MOUSEBUTTON_RIGHT = cef_types.MBT_RIGHT
@@ -392,6 +395,12 @@ cdef class PyBrowser:
392395
cpdef py_void ReloadIgnoreCache(self):
393396
self.GetCefBrowser().get().ReloadIgnoreCache()
394397

398+
cpdef py_void SetBounds(self, int x, int y, int width, int height):
399+
if platform.system() == "Linux":
400+
x11.SetX11WindowBounds(self.GetCefBrowser(), x, y, width, height)
401+
else:
402+
raise Exception("SetBounds() not impplemented on this platform")
403+
395404
cpdef py_void SetFocus(self, enable):
396405
self.GetCefBrowserHost().get().SetFocus(bool(enable))
397406

src/cefpython.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ CefRenderHandler
9999
OnScrollOffsetChanged - new args: x,y
100100
101101
102-
LINUX TODO:
102+
In upstream cefclient:
103103
1. g_signal_connect(G_OBJECT(window_), "configure-event",
104104
G_CALLBACK(&RootWindowGtk::WindowConfigure), this);
105105
browser->GetHost()->NotifyMoveOrResizeStarted();

src/client_handler/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CCFLAGS = -g -fPIC -Wall -Werror $(CEF_CCFLAGS)
1515

1616
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
1717
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
18-
task.cpp
18+
task.cpp x11.cpp
1919

2020
OBJ = $(SRC:.cpp=.o)
2121

src/client_handler/client_handler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// License: New BSD License.
33
// Website: http://code.google.com/p/cefpython/
44

5-
// ClientHandler code is running in the Browser process only.
5+
// NOTE: clienthandler code is running only in the BROWSER PROCESS.
6+
// cefpythonapp code is running in both BROWSER PROCESS and subprocess
7+
// (see the subprocess/ directory).
68

79
#include "client_handler.h"
810
#include "cefpython_public_api.h"

src/client_handler/x11.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

src/client_handler/x11.h

Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)