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

Side by Side Diff: ui/platform_window/x11/x11_window_base.cc

Issue 2924343002: Move ui::GetAtom to gfx::GetAtom (Closed)
Patch Set: fix CrOs build 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/gfx/x/x11_atom_cache.cc ('k') | ui/views/test/ui_controls_factory_desktop_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/platform_window/x11/x11_window_base.h" 5 #include "ui/platform_window/x11/x11_window_base.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h> 10 #include <X11/Xutil.h>
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "ui/base/platform_window_defaults.h" 15 #include "ui/base/platform_window_defaults.h"
16 #include "ui/base/x/x11_util.h"
17 #include "ui/base/x/x11_window_event_manager.h" 16 #include "ui/base/x/x11_window_event_manager.h"
18 #include "ui/events/devices/x11/touch_factory_x11.h" 17 #include "ui/events/devices/x11/touch_factory_x11.h"
19 #include "ui/events/event.h" 18 #include "ui/events/event.h"
20 #include "ui/events/event_utils.h" 19 #include "ui/events/event_utils.h"
21 #include "ui/events/platform/platform_event_dispatcher.h" 20 #include "ui/events/platform/platform_event_dispatcher.h"
22 #include "ui/events/platform/platform_event_source.h" 21 #include "ui/events/platform/platform_event_source.h"
23 #include "ui/events/platform/x11/x11_event_source.h" 22 #include "ui/events/platform/x11/x11_event_source.h"
24 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
24 #include "ui/gfx/x/x11_atom_cache.h"
25 #include "ui/platform_window/platform_window_delegate.h" 25 #include "ui/platform_window/platform_window_delegate.h"
26 26
27 namespace ui { 27 namespace ui {
28 28
29 namespace { 29 namespace {
30 30
31 XID FindXEventTarget(const XEvent& xev) { 31 XID FindXEventTarget(const XEvent& xev) {
32 XID target = xev.xany.window; 32 XID target = xev.xany.window;
33 if (xev.type == GenericEvent) 33 if (xev.type == GenericEvent)
34 target = static_cast<XIDeviceEvent*>(xev.xcookie.data)->event; 34 target = static_cast<XIDeviceEvent*>(xev.xcookie.data)->event;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 XISetMask(mask, XI_HierarchyChanged); 106 XISetMask(mask, XI_HierarchyChanged);
107 107
108 XIEventMask evmask; 108 XIEventMask evmask;
109 evmask.deviceid = XIAllDevices; 109 evmask.deviceid = XIAllDevices;
110 evmask.mask_len = sizeof(mask); 110 evmask.mask_len = sizeof(mask);
111 evmask.mask = mask; 111 evmask.mask = mask;
112 XISelectEvents(xdisplay_, xwindow_, &evmask, 1); 112 XISelectEvents(xdisplay_, xwindow_, &evmask, 1);
113 XFlush(xdisplay_); 113 XFlush(xdisplay_);
114 114
115 ::Atom protocols[2]; 115 ::Atom protocols[2];
116 protocols[0] = GetAtom("WM_DELETE_WINDOW"); 116 protocols[0] = gfx::GetAtom("WM_DELETE_WINDOW");
117 protocols[1] = GetAtom("_NET_WM_PING"); 117 protocols[1] = gfx::GetAtom("_NET_WM_PING");
118 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2); 118 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2);
119 119
120 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with 120 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with
121 // the desktop environment. 121 // the desktop environment.
122 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL); 122 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL);
123 123
124 // Likewise, the X server needs to know this window's pid so it knows which 124 // Likewise, the X server needs to know this window's pid so it knows which
125 // program to kill if the window hangs. 125 // program to kill if the window hangs.
126 // XChangeProperty() expects "pid" to be long. 126 // XChangeProperty() expects "pid" to be long.
127 static_assert(sizeof(long) >= sizeof(pid_t), 127 static_assert(sizeof(long) >= sizeof(pid_t),
128 "pid_t should not be larger than long"); 128 "pid_t should not be larger than long");
129 long pid = getpid(); 129 long pid = getpid();
130 XChangeProperty(xdisplay_, xwindow_, GetAtom("_NET_WM_PID"), XA_CARDINAL, 32, 130 XChangeProperty(xdisplay_, xwindow_, gfx::GetAtom("_NET_WM_PID"), XA_CARDINAL,
131 PropModeReplace, reinterpret_cast<unsigned char*>(&pid), 1); 131 32, PropModeReplace, reinterpret_cast<unsigned char*>(&pid),
132 1);
132 // Before we map the window, set size hints. Otherwise, some window managers 133 // Before we map the window, set size hints. Otherwise, some window managers
133 // will ignore toplevel XMoveWindow commands. 134 // will ignore toplevel XMoveWindow commands.
134 XSizeHints size_hints; 135 XSizeHints size_hints;
135 size_hints.flags = PPosition | PWinGravity; 136 size_hints.flags = PPosition | PWinGravity;
136 size_hints.x = bounds_.x(); 137 size_hints.x = bounds_.x();
137 size_hints.y = bounds_.y(); 138 size_hints.y = bounds_.y();
138 // Set StaticGravity so that the window position is not affected by the 139 // Set StaticGravity so that the window position is not affected by the
139 // frame width when running with window manager. 140 // frame width when running with window manager.
140 size_hints.win_gravity = StaticGravity; 141 size_hints.win_gravity = StaticGravity;
141 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); 142 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 208
208 gfx::Rect X11WindowBase::GetBounds() { 209 gfx::Rect X11WindowBase::GetBounds() {
209 return bounds_; 210 return bounds_;
210 } 211 }
211 212
212 void X11WindowBase::SetTitle(const base::string16& title) { 213 void X11WindowBase::SetTitle(const base::string16& title) {
213 if (window_title_ == title) 214 if (window_title_ == title)
214 return; 215 return;
215 window_title_ = title; 216 window_title_ = title;
216 std::string utf8str = base::UTF16ToUTF8(title); 217 std::string utf8str = base::UTF16ToUTF8(title);
217 XChangeProperty(xdisplay_, xwindow_, GetAtom("_NET_WM_NAME"), 218 XChangeProperty(xdisplay_, xwindow_, gfx::GetAtom("_NET_WM_NAME"),
218 GetAtom("UTF8_STRING"), 8, PropModeReplace, 219 gfx::GetAtom("UTF8_STRING"), 8, PropModeReplace,
219 reinterpret_cast<const unsigned char*>(utf8str.c_str()), 220 reinterpret_cast<const unsigned char*>(utf8str.c_str()),
220 utf8str.size()); 221 utf8str.size());
221 XTextProperty xtp; 222 XTextProperty xtp;
222 char* c_utf8_str = const_cast<char*>(utf8str.c_str()); 223 char* c_utf8_str = const_cast<char*>(utf8str.c_str());
223 if (Xutf8TextListToTextProperty(xdisplay_, &c_utf8_str, 1, XUTF8StringStyle, 224 if (Xutf8TextListToTextProperty(xdisplay_, &c_utf8_str, 1, XUTF8StringStyle,
224 &xtp) == Success) { 225 &xtp) == Success) {
225 XSetWMName(xdisplay_, xwindow_, &xtp); 226 XSetWMName(xdisplay_, xwindow_, &xtp);
226 XFree(xtp.value); 227 XFree(xtp.value);
227 } 228 }
228 } 229 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 xev->xconfigure.width, xev->xconfigure.height); 287 xev->xconfigure.width, xev->xconfigure.height);
287 if (bounds_ != bounds) { 288 if (bounds_ != bounds) {
288 bounds_ = bounds; 289 bounds_ = bounds;
289 delegate_->OnBoundsChanged(bounds_); 290 delegate_->OnBoundsChanged(bounds_);
290 } 291 }
291 break; 292 break;
292 } 293 }
293 294
294 case ClientMessage: { 295 case ClientMessage: {
295 Atom message = static_cast<Atom>(xev->xclient.data.l[0]); 296 Atom message = static_cast<Atom>(xev->xclient.data.l[0]);
296 if (message == GetAtom("WM_DELETE_WINDOW")) { 297 if (message == gfx::GetAtom("WM_DELETE_WINDOW")) {
297 delegate_->OnCloseRequest(); 298 delegate_->OnCloseRequest();
298 } else if (message == GetAtom("_NET_WM_PING")) { 299 } else if (message == gfx::GetAtom("_NET_WM_PING")) {
299 XEvent reply_event = *xev; 300 XEvent reply_event = *xev;
300 reply_event.xclient.window = xroot_window_; 301 reply_event.xclient.window = xroot_window_;
301 302
302 XSendEvent(xdisplay_, reply_event.xclient.window, False, 303 XSendEvent(xdisplay_, reply_event.xclient.window, False,
303 SubstructureRedirectMask | SubstructureNotifyMask, 304 SubstructureRedirectMask | SubstructureNotifyMask,
304 &reply_event); 305 &reply_event);
305 XFlush(xdisplay_); 306 XFlush(xdisplay_);
306 } 307 }
307 break; 308 break;
308 } 309 }
309 } 310 }
310 } 311 }
311 312
312 } // namespace ui 313 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/x/x11_atom_cache.cc ('k') | ui/views/test/ui_controls_factory_desktop_aurax11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698