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

Side by Side Diff: ui/views/widget/desktop_aura/x11_desktop_handler.cc

Issue 2108933003: Reorder browser list on workspace switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cache workspace, address comments Created 4 years, 5 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 "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
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
152
127 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) { 153 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) {
128 if (time_ms != CurrentTime) { 154 if (time_ms != CurrentTime) {
129 int64_t event_time_64 = time_ms; 155 int64_t event_time_64 = time_ms;
130 int64_t time_difference = wm_user_time_ms_ - event_time_64; 156 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 157 // 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 158 // 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. 159 // range of the 32-bit counter, treat it as a rollover.
134 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) 160 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1))
135 wm_user_time_ms_ = time_ms; 161 wm_user_time_ms_ = time_ms;
136 } 162 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 203
178 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) { 204 bool X11DesktopHandler::CanDispatchEvent(const ui::PlatformEvent& event) {
179 return event->type == CreateNotify || event->type == DestroyNotify || 205 return event->type == CreateNotify || event->type == DestroyNotify ||
180 (event->type == PropertyNotify && 206 (event->type == PropertyNotify &&
181 event->xproperty.window == x_root_window_); 207 event->xproperty.window == x_root_window_);
182 } 208 }
183 209
184 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) { 210 uint32_t X11DesktopHandler::DispatchEvent(const ui::PlatformEvent& event) {
185 switch (event->type) { 211 switch (event->type) {
186 case PropertyNotify: { 212 case PropertyNotify: {
187 // Check for a change to the active window. 213 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; 214 ::Window window;
192 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) && 215 if (ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &window) &&
193 window) { 216 window) {
194 x_active_window_ = window; 217 x_active_window_ = window;
195 OnActiveWindowChanged(window, ACTIVE); 218 OnActiveWindowChanged(window, ACTIVE);
196 } else { 219 } else {
197 x_active_window_ = None; 220 x_active_window_ = None;
198 } 221 }
222 } else if (event->xproperty.atom ==
223 atom_cache_.GetAtom("_NET_CURRENT_DESKTOP")) {
224 if (UpdateWorkspace()) {
225 FOR_EACH_OBSERVER(views::X11DesktopHandlerObserver, observers_,
226 OnWorkspaceChanged(workspace_));
227 }
199 } 228 }
200 break; 229 break;
201 } 230 }
202
203 case CreateNotify: 231 case CreateNotify:
204 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window); 232 OnWindowCreatedOrDestroyed(event->type, event->xcreatewindow.window);
205 break; 233 break;
206 case DestroyNotify: 234 case DestroyNotify:
207 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window); 235 OnWindowCreatedOrDestroyed(event->type, event->xdestroywindow.window);
208 // If the current active window is being destroyed, reset our tracker. 236 // If the current active window is being destroyed, reset our tracker.
209 if (x_active_window_ == event->xdestroywindow.window) { 237 if (x_active_window_ == event->xdestroywindow.window) {
210 x_active_window_ = None; 238 x_active_window_ = None;
211 } 239 }
212 break; 240 break;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); 295 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window);
268 } 296 }
269 297
270 if (event_type == DestroyNotify) { 298 if (event_type == DestroyNotify) {
271 // Notify the XForeignWindowManager that |window| has been destroyed. 299 // Notify the XForeignWindowManager that |window| has been destroyed.
272 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); 300 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window);
273 } 301 }
274 } 302 }
275 303
276 } // namespace views 304 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698