OLD | NEW |
---|---|
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 "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/base/x/x11_foreign_window_manager.h" | 14 #include "ui/base/x/x11_foreign_window_manager.h" |
14 #include "ui/base/x/x11_menu_list.h" | 15 #include "ui/base/x/x11_menu_list.h" |
15 #include "ui/base/x/x11_util.h" | 16 #include "ui/base/x/x11_util.h" |
17 #include "ui/display/desktop_observer.h" | |
16 #include "ui/events/platform/platform_event_source.h" | 18 #include "ui/events/platform/platform_event_source.h" |
17 #include "ui/gfx/x/x11_error_tracker.h" | 19 #include "ui/gfx/x/x11_error_tracker.h" |
18 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 20 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char* kAtomsToCache[] = { | 24 const char* kAtomsToCache[] = { |
Lei Zhang
2016/06/29 18:30:53
BTW, please make this: const char* const
Tom (Use chromium acct)
2016/06/29 20:16:05
Done.
| |
23 "_NET_ACTIVE_WINDOW", | 25 "_NET_ACTIVE_WINDOW", |
26 "_NET_CURRENT_DESKTOP", | |
24 NULL | 27 NULL |
25 }; | 28 }; |
26 | 29 |
27 // Our global instance. Deleted when our Env() is deleted. | 30 // Our global instance. Deleted when our Env() is deleted. |
28 views::X11DesktopHandler* g_handler = NULL; | 31 views::X11DesktopHandler* g_handler = NULL; |
29 | 32 |
30 } // namespace | 33 } // namespace |
31 | 34 |
32 namespace views { | 35 namespace views { |
33 | 36 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 180 |
178 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { | 181 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { |
179 return event->type == CreateNotify || event->type == DestroyNotify || | 182 return event->type == CreateNotify || event->type == DestroyNotify || |
180 (event->type == PropertyNotify && | 183 (event->type == PropertyNotify && |
181 event->xproperty.window == x_root_window_); | 184 event->xproperty.window == x_root_window_); |
182 } | 185 } |
183 | 186 |
184 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { | 187 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { |
185 switch (event->type) { | 188 switch (event->type) { |
186 case PropertyNotify: { | 189 case PropertyNotify: { |
187 // Check for a change to the active window. | 190 if (event->xproperty.atom == atom_cache_.GetAtom("_NET_ACTIVE_WINDOW")) { |
188 CHECK_EQ(x_root_window_, event->xproperty.window); | |
189 ::Atom active_window_atom = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); | |
190 if (event->xproperty.atom == active_window_atom) { | |
191 ::Window window; | 191 ::Window window; |
192 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && | 192 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && |
193 window) { | 193 window) { |
194 x_active_window_ = window; | 194 x_active_window_ = window; |
195 OnActiveWindowChanged(window, ACTIVE); | 195 OnActiveWindowChanged(window, ACTIVE); |
196 } else { | 196 } else { |
197 x_active_window_ = None; | 197 x_active_window_ = None; |
198 } | 198 } |
199 } else if (event->xproperty.atom == | |
200 atom_cache_.GetAtom("_NET_CURRENT_DESKTOP")) { | |
201 int desktop; | |
202 if (ui::GetCurrentDesktop(&desktop)) { | |
203 const std::string desktop_string = base::IntToString(desktop); | |
204 FOR_EACH_OBSERVER(display::DesktopObserver, | |
205 display::g_desktop_observer_list, | |
206 OnWorkspaceChanged(desktop_string)); | |
207 } | |
199 } | 208 } |
200 break; | 209 break; |
201 } | 210 } |
202 | |
203 case CreateNotify: | 211 case CreateNotify: |
204 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); | 212 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); |
205 break; | 213 break; |
206 case DestroyNotify: | 214 case DestroyNotify: |
207 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); | 215 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); |
208 // If the current active window is being destroyed, reset our tracker. | 216 // If the current active window is being destroyed, reset our tracker. |
209 if (x_active_window_ == event->xdestroywindow.window) { | 217 if (x_active_window_ == event->xdestroywindow.window) { |
210 x_active_window_ = None; | 218 x_active_window_ = None; |
211 } | 219 } |
212 break; | 220 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); | 275 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); |
268 } | 276 } |
269 | 277 |
270 if (event_type == DestroyNotify) { | 278 if (event_type == DestroyNotify) { |
271 // Notify the XForeignWindowManager that |window| has been destroyed. | 279 // Notify the XForeignWindowManager that |window| has been destroyed. |
272 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); | 280 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); |
273 } | 281 } |
274 } | 282 } |
275 | 283 |
276 } // namespace views | 284 } // namespace views |
OLD | NEW |