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 |
| 137 std::string X11DesktopHandler::GetWorkspace() { |
| 138 if (workspace_.empty()) |
| 139 UpdateWorkspace(); |
| 140 return workspace_; |
| 141 } |
| 142 |
| 143 bool X11DesktopHandler::UpdateWorkspace() { |
| 144 int desktop; |
| 145 if (ui::GetCurrentDesktop(&desktop)) { |
| 146 workspace_ = base::IntToString(desktop); |
| 147 return true; |
| 148 } |
| 149 return false; |
| 150 } |
| 151 |
127 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) { | 152 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) { |
128 if (time_ms != CurrentTime) { | 153 if (time_ms != CurrentTime) { |
129 int64_t event_time_64 = time_ms; | 154 int64_t event_time_64 = time_ms; |
130 int64_t time_difference = wm_user_time_ms_ - event_time_64; | 155 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 | 156 // 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 | 157 // 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. | 158 // range of the 32-bit counter, treat it as a rollover. |
134 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) | 159 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) |
135 wm_user_time_ms_ = time_ms; | 160 wm_user_time_ms_ = time_ms; |
136 } | 161 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 202 |
178 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { | 203 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { |
179 return event->type == CreateNotify || event->type == DestroyNotify || | 204 return event->type == CreateNotify || event->type == DestroyNotify || |
180 (event->type == PropertyNotify && | 205 (event->type == PropertyNotify && |
181 event->xproperty.window == x_root_window_); | 206 event->xproperty.window == x_root_window_); |
182 } | 207 } |
183 | 208 |
184 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { | 209 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { |
185 switch (event->type) { | 210 switch (event->type) { |
186 case PropertyNotify: { | 211 case PropertyNotify: { |
187 // Check for a change to the active window. | 212 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; | 213 ::Window window; |
192 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && | 214 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && |
193 window) { | 215 window) { |
194 x_active_window_ = window; | 216 x_active_window_ = window; |
195 OnActiveWindowChanged(window, ACTIVE); | 217 OnActiveWindowChanged(window, ACTIVE); |
196 } else { | 218 } else { |
197 x_active_window_ = None; | 219 x_active_window_ = None; |
198 } | 220 } |
| 221 } else if (event->xproperty.atom == |
| 222 atom_cache_.GetAtom("_NET_CURRENT_DESKTOP")) { |
| 223 if (UpdateWorkspace()) { |
| 224 FOR_EACH_OBSERVER(views::X11DesktopHandlerObserver, observers_, |
| 225 OnWorkspaceChanged(workspace_)); |
| 226 } |
199 } | 227 } |
200 break; | 228 break; |
201 } | 229 } |
202 | |
203 case CreateNotify: | 230 case CreateNotify: |
204 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); | 231 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); |
205 break; | 232 break; |
206 case DestroyNotify: | 233 case DestroyNotify: |
207 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); | 234 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); |
208 // If the current active window is being destroyed, reset our tracker. | 235 // If the current active window is being destroyed, reset our tracker. |
209 if (x_active_window_ == event->xdestroywindow.window) { | 236 if (x_active_window_ == event->xdestroywindow.window) { |
210 x_active_window_ = None; | 237 x_active_window_ = None; |
211 } | 238 } |
212 break; | 239 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); | 294 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); |
268 } | 295 } |
269 | 296 |
270 if (event_type == DestroyNotify) { | 297 if (event_type == DestroyNotify) { |
271 // Notify the XForeignWindowManager that |window| has been destroyed. | 298 // Notify the XForeignWindowManager that |window| has been destroyed. |
272 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); | 299 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); |
273 } | 300 } |
274 } | 301 } |
275 | 302 |
276 } // namespace views | 303 } // namespace views |
OLD | NEW |