Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gui_handler_linux.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2017-06-29
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#if !defined(_MSC_VER)
14#pragma GCC diagnostic ignored "-Wunused-parameter"
15#pragma GCC diagnostic ignored "-Wshadow"
16#endif
17
18#include "gui_handler.h"
19
20#include "include/cef_config.h"
21
22#ifdef CEF_X11
23
24#include <X11/Xatom.h>
25#include <X11/Xlib.h>
26#include <string>
27
28#include "include/base/cef_logging.h"
29#include "include/cef_browser.h"
30
31int x11_errhandler( Display *dpy, XErrorEvent *err )
32{
33 // special for modality usage: XGetWindowProperty + XQueryTree()
34 if (err->error_code == BadWindow) {
35 // if ( err->request_code == 25 && qt_xdnd_handle_badwindow() )
36 return 0;
37 } else if (err->error_code == BadMatch && err->request_code == 42) {
38 // special case for X_SetInputFocus
39 return 0;
40 } else if (err->error_code == BadDrawable && err->request_code == 14) {
41 return 0;
42 }
43
44 // here XError are forwarded
45 char errstr[512];
46 XGetErrorText( dpy, err->error_code, errstr, sizeof(errstr) );
47 printf( "X11 Error: %d opcode: %d info: %s\n", err->error_code, err->request_code, errstr );
48 return 0;
49}
50
52{
53 // install custom X11 error handler to avoid application exit in case of X11 failure
54 XSetErrorHandler( x11_errhandler );
55
56 return false; // do not use view framework
57}
58
59
60
61void GuiHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString &title)
62{
63
64 std::string titleStr(title);
65
66 // Retrieve the X11 display shared with Chromium.
67 ::Display *display = cef_get_xdisplay();
68 DCHECK(display);
69
70 // Retrieve the X11 window handle for the browser.
71 ::Window window = browser->GetHost()->GetWindowHandle();
72 DCHECK(window != kNullWindowHandle);
73
74 // Retrieve the atoms required by the below XChangeProperty call.
75 const char *kAtoms[] = {"_NET_WM_NAME", "UTF8_STRING"};
76 Atom atoms[2];
77 int result = XInternAtoms(display, const_cast<char **>(kAtoms), 2, false, atoms);
78 if (!result) NOTREACHED();
79
80 // Set the window title.
81 XChangeProperty(display, window, atoms[0], atoms[1], 8, PropModeReplace,
82 reinterpret_cast<const unsigned char *>(titleStr.c_str()), titleStr.size());
83
84 // TODO(erg): This is technically wrong. So XStoreName and friends expect
85 // this in Host Portable Character Encoding instead of UTF-8, which I believe
86 // is Compound Text. This shouldn't matter 90% of the time since this is the
87 // fallback to the UTF8 property above.
88 XStoreName(display, browser->GetHost()->GetWindowHandle(), titleStr.c_str());
89}
90
91#else
92
94{
95 return true; // use view framework
96}
97
98void GuiHandler::PlatformTitleChange(CefRefPtr<CefBrowser>, const CefString &)
99{
100 // do nothing
101}
102
103
104#endif
105
XID Window
Definition TGX11.h:39
void PlatformTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title)
static bool PlatformInit()
unsigned long Atom
Definition xatom.h:9