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-2023, 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
91bool GuiHandler::PlatformResize(CefRefPtr<CefBrowser> browser, int width, int height)
92{
93 ::Display *display = cef_get_xdisplay();
94 if (!display) return false;
95
96 // Retrieve the X11 window handle for the browser.
97 ::Window window = browser->GetHost()->GetWindowHandle();
98 if (window == kNullWindowHandle)
99 return false;
100
101 int result = XResizeWindow(display, window, width, height);
102 if (result == BadWindow) {
103 printf(" bad window in XResizeWindow\n");
104 return false;
105 }
106
107 if (result == BadValue) {
108 printf(" bad values in XResizeWindow %d %d\n", width, height);
109 return false;
110 }
111 XFlush(display);
112 return true;
113}
114
115#else
116
118{
119 return true; // use view framework
120}
121
122void GuiHandler::PlatformTitleChange(CefRefPtr<CefBrowser>, const CefString &)
123{
124 // do nothing
125}
126
127bool GuiHandler::PlatformResize(CefRefPtr<CefBrowser>, int, int)
128{
129 return false;
130}
131
132
133#endif
134
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
XID Window
Definition TGX11.h:39
static bool PlatformResize(CefRefPtr< CefBrowser > browser, int width, int height)
void PlatformTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title)
static bool PlatformInit()
unsigned long Atom
Definition xatom.h:9