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

Side by Side Diff: ui/views/widget/desktop_aura/x11_desktop_handler.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
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/views/widget/desktop_aura/x11_desktop_handler.h" 5 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "ui/aura/env.h" 12 #include "ui/aura/env.h"
13 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/base/x/x11_menu_list.h" 14 #include "ui/base/x/x11_menu_list.h"
15 #include "ui/base/x/x11_util.h" 15 #include "ui/base/x/x11_util.h"
16 #include "ui/base/x/x11_window_event_manager.h" 16 #include "ui/base/x/x11_window_event_manager.h"
17 #include "ui/events/platform/platform_event_source.h" 17 #include "ui/events/platform/platform_event_source.h"
18 #include "ui/gfx/x/x11_error_tracker.h" 18 #include "ui/gfx/x/x11_error_tracker.h"
19 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 19 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
20 20
21 namespace { 21 namespace {
22 22
23 const char* const kAtomsToCache[] = {
24 "_NET_CURRENT_DESKTOP",
25 nullptr
26 };
27
28 // Our global instance. Deleted when our Env() is deleted. 23 // Our global instance. Deleted when our Env() is deleted.
29 views::X11DesktopHandler* g_handler = NULL; 24 views::X11DesktopHandler* g_handler = NULL;
30 25
31 } // namespace 26 } // namespace
32 27
33 namespace views { 28 namespace views {
34 29
35 // static 30 // static
36 X11DesktopHandler* X11DesktopHandler::get() { 31 X11DesktopHandler* X11DesktopHandler::get() {
37 if (!g_handler) 32 if (!g_handler)
38 g_handler = new X11DesktopHandler; 33 g_handler = new X11DesktopHandler;
39 34
40 return g_handler; 35 return g_handler;
41 } 36 }
42 37
43 // static 38 // static
44 X11DesktopHandler* X11DesktopHandler::get_dont_create() { 39 X11DesktopHandler* X11DesktopHandler::get_dont_create() {
45 return g_handler; 40 return g_handler;
46 } 41 }
47 42
48 X11DesktopHandler::X11DesktopHandler() 43 X11DesktopHandler::X11DesktopHandler()
49 : xdisplay_(gfx::GetXDisplay()), 44 : xdisplay_(gfx::GetXDisplay()),
50 x_root_window_(DefaultRootWindow(xdisplay_)), 45 x_root_window_(DefaultRootWindow(xdisplay_)) {
51 atom_cache_(xdisplay_, kAtomsToCache) {
52 if (ui::PlatformEventSource::GetInstance()) 46 if (ui::PlatformEventSource::GetInstance())
53 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 47 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
54 aura::Env::GetInstance()->AddObserver(this); 48 aura::Env::GetInstance()->AddObserver(this);
55 49
56 x_root_window_events_.reset(new ui::XScopedEventSelector( 50 x_root_window_events_.reset(new ui::XScopedEventSelector(
57 x_root_window_, 51 x_root_window_,
58 PropertyChangeMask | StructureNotifyMask | SubstructureNotifyMask)); 52 PropertyChangeMask | StructureNotifyMask | SubstructureNotifyMask));
59 } 53 }
60 54
61 X11DesktopHandler::~X11DesktopHandler() { 55 X11DesktopHandler::~X11DesktopHandler() {
(...skipping 27 matching lines...) Expand all
89 83
90 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { 84 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) {
91 return event->type == CreateNotify || event->type == DestroyNotify || 85 return event->type == CreateNotify || event->type == DestroyNotify ||
92 (event->type == PropertyNotify && 86 (event->type == PropertyNotify &&
93 event->xproperty.window == x_root_window_); 87 event->xproperty.window == x_root_window_);
94 } 88 }
95 89
96 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { 90 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) {
97 switch (event->type) { 91 switch (event->type) {
98 case PropertyNotify: { 92 case PropertyNotify: {
99 if (event->xproperty.atom == 93 if (event->xproperty.atom == ui::GetAtom("_NET_CURRENT_DESKTOP")) {
100 atom_cache_.GetAtom("_NET_CURRENT_DESKTOP")) {
101 if (UpdateWorkspace()) { 94 if (UpdateWorkspace()) {
102 for (views::X11DesktopHandlerObserver& observer : observers_) 95 for (views::X11DesktopHandlerObserver& observer : observers_)
103 observer.OnWorkspaceChanged(workspace_); 96 observer.OnWorkspaceChanged(workspace_);
104 } 97 }
105 } 98 }
106 break; 99 break;
107 } 100 }
108 case CreateNotify: 101 case CreateNotify:
109 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); 102 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window);
110 break; 103 break;
(...skipping 28 matching lines...) Expand all
139 // The window might be destroyed if the message pump did not get a chance to 132 // The window might be destroyed if the message pump did not get a chance to
140 // run but we can safely ignore the X error. 133 // run but we can safely ignore the X error.
141 gfx::X11ErrorTracker error_tracker; 134 gfx::X11ErrorTracker error_tracker;
142 ui::XMenuList::GetInstance()->MaybeRegisterMenu(window); 135 ui::XMenuList::GetInstance()->MaybeRegisterMenu(window);
143 } else { 136 } else {
144 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); 137 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window);
145 } 138 }
146 } 139 }
147 140
148 } // namespace views 141 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698