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" |
16 #include "ui/events/platform/platform_event_source.h" | 17 #include "ui/events/platform/platform_event_source.h" |
17 #include "ui/gfx/x/x11_error_tracker.h" | 18 #include "ui/gfx/x/x11_error_tracker.h" |
18 #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" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char* kAtomsToCache[] = { | 23 const char* const kAtomsToCache[] = { |
23 "_NET_ACTIVE_WINDOW", | 24 "_NET_ACTIVE_WINDOW", |
24 NULL | 25 "_NET_CURRENT_DESKTOP", |
| 26 nullptr |
25 }; | 27 }; |
26 | 28 |
27 // Our global instance. Deleted when our Env() is deleted. | 29 // Our global instance. Deleted when our Env() is deleted. |
28 views::X11DesktopHandler* g_handler = NULL; | 30 views::X11DesktopHandler* g_handler = NULL; |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 namespace views { | 34 namespace views { |
33 | 35 |
34 // static | 36 // static |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 XRaiseWindow(xdisplay_, window); | 119 XRaiseWindow(xdisplay_, window); |
118 // Directly ask the X server to give focus to the window. Note | 120 // Directly ask the X server to give focus to the window. Note |
119 // that the call will raise an X error if the window is not | 121 // that the call will raise an X error if the window is not |
120 // mapped. | 122 // mapped. |
121 XSetInputFocus(xdisplay_, window, RevertToParent, CurrentTime); | 123 XSetInputFocus(xdisplay_, window, RevertToParent, CurrentTime); |
122 | 124 |
123 OnActiveWindowChanged(window, ACTIVE); | 125 OnActiveWindowChanged(window, ACTIVE); |
124 } | 126 } |
125 } | 127 } |
126 | 128 |
| 129 void X11DesktopHandler::AddObserver(X11DesktopHandlerObserver* observer) { |
| 130 observers_.AddObserver(observer); |
| 131 } |
| 132 |
| 133 void X11DesktopHandler::RemoveObserver(X11DesktopHandlerObserver* observer) { |
| 134 observers_.RemoveObserver(observer); |
| 135 } |
| 136 |
127 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) { | 137 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) { |
128 if (time_ms != CurrentTime) { | 138 if (time_ms != CurrentTime) { |
129 int64_t event_time_64 = time_ms; | 139 int64_t event_time_64 = time_ms; |
130 int64_t time_difference = wm_user_time_ms_ - event_time_64; | 140 int64_t time_difference = wm_user_time_ms_ - event_time_64; |
131 // Ignore timestamps that go backwards. However, X server time is a 32-bit | 141 // Ignore timestamps that go backwards. However, X server time is a 32-bit |
132 // millisecond counter, so if the time goes backwards by more than half the | 142 // millisecond counter, so if the time goes backwards by more than half the |
133 // range of the 32-bit counter, treat it as a rollover. | 143 // range of the 32-bit counter, treat it as a rollover. |
134 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) | 144 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) |
135 wm_user_time_ms_ = time_ms; | 145 wm_user_time_ms_ = time_ms; |
136 } | 146 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 187 |
178 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { | 188 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { |
179 return event->type == CreateNotify || event->type == DestroyNotify || | 189 return event->type == CreateNotify || event->type == DestroyNotify || |
180 (event->type == PropertyNotify && | 190 (event->type == PropertyNotify && |
181 event->xproperty.window == x_root_window_); | 191 event->xproperty.window == x_root_window_); |
182 } | 192 } |
183 | 193 |
184 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { | 194 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { |
185 switch (event->type) { | 195 switch (event->type) { |
186 case PropertyNotify: { | 196 case PropertyNotify: { |
187 // Check for a change to the active window. | 197 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; | 198 ::Window window; |
192 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && | 199 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && |
193 window) { | 200 window) { |
194 x_active_window_ = window; | 201 x_active_window_ = window; |
195 OnActiveWindowChanged(window, ACTIVE); | 202 OnActiveWindowChanged(window, ACTIVE); |
196 } else { | 203 } else { |
197 x_active_window_ = None; | 204 x_active_window_ = None; |
198 } | 205 } |
| 206 } else if (event->xproperty.atom == |
| 207 atom_cache_.GetAtom("_NET_CURRENT_DESKTOP")) { |
| 208 int desktop; |
| 209 if (ui::GetCurrentDesktop(&desktop)) { |
| 210 std::string desktop_string = base::IntToString(desktop); |
| 211 FOR_EACH_OBSERVER(views::X11DesktopHandlerObserver, observers_, |
| 212 OnWorkspaceChanged(desktop_string)); |
| 213 } |
199 } | 214 } |
200 break; | 215 break; |
201 } | 216 } |
202 | |
203 case CreateNotify: | 217 case CreateNotify: |
204 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); | 218 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); |
205 break; | 219 break; |
206 case DestroyNotify: | 220 case DestroyNotify: |
207 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); | 221 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); |
208 // If the current active window is being destroyed, reset our tracker. | 222 // If the current active window is being destroyed, reset our tracker. |
209 if (x_active_window_ == event->xdestroywindow.window) { | 223 if (x_active_window_ == event->xdestroywindow.window) { |
210 x_active_window_ = None; | 224 x_active_window_ = None; |
211 } | 225 } |
212 break; | 226 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); | 281 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); |
268 } | 282 } |
269 | 283 |
270 if (event_type == DestroyNotify) { | 284 if (event_type == DestroyNotify) { |
271 // Notify the XForeignWindowManager that |window| has been destroyed. | 285 // Notify the XForeignWindowManager that |window| has been destroyed. |
272 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); | 286 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); |
273 } | 287 } |
274 } | 288 } |
275 | 289 |
276 } // namespace views | 290 } // namespace views |
OLD | NEW |