Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ui/aura/window_tree_host_x11.cc

Issue 2914103002: Remove usages of XInternAtom (Closed)
Patch Set: Address sadrul and sergeyu comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/window_tree_host_x11.h ('k') | ui/base/clipboard/clipboard_aurax11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window_tree_host_x11.h" 5 #include "ui/aura/window_tree_host_x11.h"
6 6
7 #include <strings.h> 7 #include <strings.h>
8 #include <X11/cursorfont.h> 8 #include <X11/cursorfont.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/extensions/Xrandr.h> 10 #include <X11/extensions/Xrandr.h>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "ui/events/platform/platform_event_source.h" 52 #include "ui/events/platform/platform_event_source.h"
53 #include "ui/events/platform/x11/x11_event_source.h" 53 #include "ui/events/platform/x11/x11_event_source.h"
54 54
55 using std::max; 55 using std::max;
56 using std::min; 56 using std::min;
57 57
58 namespace aura { 58 namespace aura {
59 59
60 namespace { 60 namespace {
61 61
62 const char* kAtomsToCache[] = {
63 "WM_DELETE_WINDOW",
64 "_NET_WM_PING",
65 "_NET_WM_PID",
66 NULL
67 };
68
69 constexpr uint32_t kInputEventMask = 62 constexpr uint32_t kInputEventMask =
70 ButtonPressMask | ButtonReleaseMask | FocusChangeMask | KeyPressMask | 63 ButtonPressMask | ButtonReleaseMask | FocusChangeMask | KeyPressMask |
71 KeyReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask; 64 KeyReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask;
72 65
73 constexpr uint32_t kEventMask = kInputEventMask | ExposureMask | 66 constexpr uint32_t kEventMask = kInputEventMask | ExposureMask |
74 VisibilityChangeMask | StructureNotifyMask | 67 VisibilityChangeMask | StructureNotifyMask |
75 PropertyChangeMask; 68 PropertyChangeMask;
76 69
77 ::Window FindEventTarget(const base::NativeEvent& xev) { 70 ::Window FindEventTarget(const base::NativeEvent& xev) {
78 ::Window target = xev->xany.window; 71 ::Window target = xev->xany.window;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 108
116 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
117 // WindowTreeHostX11 110 // WindowTreeHostX11
118 111
119 WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds) 112 WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds)
120 : xdisplay_(gfx::GetXDisplay()), 113 : xdisplay_(gfx::GetXDisplay()),
121 xwindow_(0), 114 xwindow_(0),
122 x_root_window_(DefaultRootWindow(xdisplay_)), 115 x_root_window_(DefaultRootWindow(xdisplay_)),
123 current_cursor_(ui::CursorType::kNull), 116 current_cursor_(ui::CursorType::kNull),
124 window_mapped_(false), 117 window_mapped_(false),
125 bounds_(bounds), 118 bounds_(bounds) {
126 atom_cache_(xdisplay_, kAtomsToCache) {
127 XSetWindowAttributes swa; 119 XSetWindowAttributes swa;
128 memset(&swa, 0, sizeof(swa)); 120 memset(&swa, 0, sizeof(swa));
129 swa.background_pixmap = None; 121 swa.background_pixmap = None;
130 swa.bit_gravity = NorthWestGravity; 122 swa.bit_gravity = NorthWestGravity;
131 swa.override_redirect = ui::UseTestConfigForPlatformWindows(); 123 swa.override_redirect = ui::UseTestConfigForPlatformWindows();
132 xwindow_ = XCreateWindow( 124 xwindow_ = XCreateWindow(
133 xdisplay_, x_root_window_, 125 xdisplay_, x_root_window_,
134 bounds.x(), bounds.y(), bounds.width(), bounds.height(), 126 bounds.x(), bounds.y(), bounds.width(), bounds.height(),
135 0, // border width 127 0, // border width
136 CopyFromParent, // depth 128 CopyFromParent, // depth
137 InputOutput, 129 InputOutput,
138 CopyFromParent, // visual 130 CopyFromParent, // visual
139 CWBackPixmap | CWBitGravity | CWOverrideRedirect, 131 CWBackPixmap | CWBitGravity | CWOverrideRedirect,
140 &swa); 132 &swa);
141 if (ui::PlatformEventSource::GetInstance()) 133 if (ui::PlatformEventSource::GetInstance())
142 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 134 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
143 135
144 xwindow_events_.reset(new ui::XScopedEventSelector(xwindow_, kEventMask)); 136 xwindow_events_.reset(new ui::XScopedEventSelector(xwindow_, kEventMask));
145 XFlush(xdisplay_); 137 XFlush(xdisplay_);
146 138
147 if (ui::IsXInput2Available()) { 139 if (ui::IsXInput2Available()) {
148 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); 140 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_);
149 SelectXInput2EventsForRootWindow(xdisplay_, x_root_window_); 141 SelectXInput2EventsForRootWindow(xdisplay_, x_root_window_);
150 } 142 }
151 143
152 // TODO(erg): We currently only request window deletion events. We also 144 // TODO(erg): We currently only request window deletion events. We also
153 // should listen for activation events and anything else that GTK+ listens 145 // should listen for activation events and anything else that GTK+ listens
154 // for, and do something useful. 146 // for, and do something useful.
155 ::Atom protocols[2]; 147 ::Atom protocols[2];
156 protocols[0] = atom_cache_.GetAtom("WM_DELETE_WINDOW"); 148 protocols[0] = ui::GetAtom("WM_DELETE_WINDOW");
157 protocols[1] = atom_cache_.GetAtom("_NET_WM_PING"); 149 protocols[1] = ui::GetAtom("_NET_WM_PING");
158 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2); 150 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2);
159 151
160 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with 152 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with
161 // the desktop environment. 153 // the desktop environment.
162 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL); 154 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL);
163 ui::SetWindowClassHint(xdisplay_, xwindow_, "chromiumos", "ChromiumOS"); 155 ui::SetWindowClassHint(xdisplay_, xwindow_, "chromiumos", "ChromiumOS");
164 156
165 // Likewise, the X server needs to know this window's pid so it knows which 157 // Likewise, the X server needs to know this window's pid so it knows which
166 // program to kill if the window hangs. 158 // program to kill if the window hangs.
167 // XChangeProperty() expects "pid" to be long. 159 // XChangeProperty() expects "pid" to be long.
168 static_assert(sizeof(long) >= sizeof(pid_t), 160 static_assert(sizeof(long) >= sizeof(pid_t),
169 "pid_t should not be larger than long"); 161 "pid_t should not be larger than long");
170 long pid = getpid(); 162 long pid = getpid();
171 XChangeProperty(xdisplay_, 163 XChangeProperty(xdisplay_, xwindow_, ui::GetAtom("_NET_WM_PID"), XA_CARDINAL,
172 xwindow_, 164 32, PropModeReplace, reinterpret_cast<unsigned char*>(&pid),
173 atom_cache_.GetAtom("_NET_WM_PID"), 165 1);
174 XA_CARDINAL,
175 32,
176 PropModeReplace,
177 reinterpret_cast<unsigned char*>(&pid), 1);
178
179 // Allow subclasses to create and cache additional atoms.
180 atom_cache_.allow_uncached_atoms();
181 166
182 XRRSelectInput(xdisplay_, x_root_window_, 167 XRRSelectInput(xdisplay_, x_root_window_,
183 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); 168 RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
184 CreateCompositor(); 169 CreateCompositor();
185 OnAcceleratedWidgetAvailable(); 170 OnAcceleratedWidgetAvailable();
186 } 171 }
187 172
188 WindowTreeHostX11::~WindowTreeHostX11() { 173 WindowTreeHostX11::~WindowTreeHostX11() {
189 if (ui::PlatformEventSource::GetInstance()) 174 if (ui::PlatformEventSource::GetInstance())
190 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 175 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 OnHostResizedInPixels(bounds.size()); 300 OnHostResizedInPixels(bounds.size());
316 if (origin_changed) 301 if (origin_changed)
317 OnHostMovedInPixels(bounds_.origin()); 302 OnHostMovedInPixels(bounds_.origin());
318 break; 303 break;
319 } 304 }
320 case GenericEvent: 305 case GenericEvent:
321 DispatchXI2Event(xev); 306 DispatchXI2Event(xev);
322 break; 307 break;
323 case ClientMessage: { 308 case ClientMessage: {
324 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); 309 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]);
325 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { 310 if (message_type == ui::GetAtom("WM_DELETE_WINDOW")) {
326 // We have received a close message from the window manager. 311 // We have received a close message from the window manager.
327 OnHostCloseRequested(); 312 OnHostCloseRequested();
328 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { 313 } else if (message_type == ui::GetAtom("_NET_WM_PING")) {
329 XEvent reply_event = *xev; 314 XEvent reply_event = *xev;
330 reply_event.xclient.window = x_root_window_; 315 reply_event.xclient.window = x_root_window_;
331 316
332 XSendEvent(xdisplay_, 317 XSendEvent(xdisplay_,
333 reply_event.xclient.window, 318 reply_event.xclient.window,
334 False, 319 False,
335 SubstructureRedirectMask | SubstructureNotifyMask, 320 SubstructureRedirectMask | SubstructureNotifyMask,
336 &reply_event); 321 &reply_event);
337 XFlush(xdisplay_); 322 XFlush(xdisplay_);
338 } 323 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 ui::LocatedEvent* event) { 552 ui::LocatedEvent* event) {
568 SendEventToSink(event); 553 SendEventToSink(event);
569 } 554 }
570 555
571 // static 556 // static
572 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds_in_pixels) { 557 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds_in_pixels) {
573 return new WindowTreeHostX11(bounds_in_pixels); 558 return new WindowTreeHostX11(bounds_in_pixels);
574 } 559 }
575 560
576 } // namespace aura 561 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_tree_host_x11.h ('k') | ui/base/clipboard/clipboard_aurax11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698