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

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

Issue 1949393007: X11: Better timestamp handling for _NET_ACTIVE_WINDOW (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ms->microseconds Created 4 years, 7 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
« no previous file with comments | « ui/views/widget/desktop_aura/x11_desktop_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 25 matching lines...) Expand all
36 if (!g_handler) 36 if (!g_handler)
37 g_handler = new X11DesktopHandler; 37 g_handler = new X11DesktopHandler;
38 38
39 return g_handler; 39 return g_handler;
40 } 40 }
41 41
42 X11DesktopHandler::X11DesktopHandler() 42 X11DesktopHandler::X11DesktopHandler()
43 : xdisplay_(gfx::GetXDisplay()), 43 : xdisplay_(gfx::GetXDisplay()),
44 x_root_window_(DefaultRootWindow(xdisplay_)), 44 x_root_window_(DefaultRootWindow(xdisplay_)),
45 x_active_window_(None), 45 x_active_window_(None),
46 wm_user_time_ms_(0), 46 wm_user_time_ms_(CurrentTime),
47 current_window_(None), 47 current_window_(None),
48 current_window_active_state_(NOT_ACTIVE), 48 current_window_active_state_(NOT_ACTIVE),
49 atom_cache_(xdisplay_, kAtomsToCache), 49 atom_cache_(xdisplay_, kAtomsToCache),
50 wm_supports_active_window_(false) { 50 wm_supports_active_window_(false) {
51 if (ui::PlatformEventSource::GetInstance()) 51 if (ui::PlatformEventSource::GetInstance())
52 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 52 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
53 aura::Env::GetInstance()->AddObserver(this); 53 aura::Env::GetInstance()->AddObserver(this);
54 54
55 XWindowAttributes attr; 55 XWindowAttributes attr;
56 XGetWindowAttributes(xdisplay_, x_root_window_, &attr); 56 XGetWindowAttributes(xdisplay_, x_root_window_, &attr);
(...skipping 27 matching lines...) Expand all
84 // Go through the regular activation path such that calling 84 // Go through the regular activation path such that calling
85 // DeactivateWindow() and ActivateWindow() immediately afterwards results 85 // DeactivateWindow() and ActivateWindow() immediately afterwards results
86 // in an active X window. 86 // in an active X window.
87 } 87 }
88 88
89 if (wm_supports_active_window_) { 89 if (wm_supports_active_window_) {
90 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_); 90 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_);
91 91
92 // If the window is not already active, send a hint to activate it 92 // If the window is not already active, send a hint to activate it
93 if (x_active_window_ != window) { 93 if (x_active_window_ != window) {
94 if (wm_user_time_ms_ == CurrentTime) {
95 set_wm_user_time_ms(
96 ui::X11EventSource::GetInstance()->UpdateLastSeenServerTime());
97 }
94 XEvent xclient; 98 XEvent xclient;
95 memset(&xclient, 0, sizeof(xclient)); 99 memset(&xclient, 0, sizeof(xclient));
96 xclient.type = ClientMessage; 100 xclient.type = ClientMessage;
97 xclient.xclient.window = window; 101 xclient.xclient.window = window;
98 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); 102 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW");
99 xclient.xclient.format = 32; 103 xclient.xclient.format = 32;
100 xclient.xclient.data.l[0] = 1; // Specified we are an app. 104 xclient.xclient.data.l[0] = 1; // Specified we are an app.
101 xclient.xclient.data.l[1] = wm_user_time_ms_; 105 xclient.xclient.data.l[1] = wm_user_time_ms_;
102 xclient.xclient.data.l[2] = None; 106 xclient.xclient.data.l[2] = None;
103 xclient.xclient.data.l[3] = 0; 107 xclient.xclient.data.l[3] = 0;
104 xclient.xclient.data.l[4] = 0; 108 xclient.xclient.data.l[4] = 0;
105 109
106 XSendEvent(xdisplay_, x_root_window_, False, 110 XSendEvent(xdisplay_, x_root_window_, False,
107 SubstructureRedirectMask | SubstructureNotifyMask, 111 SubstructureRedirectMask | SubstructureNotifyMask,
108 &xclient); 112 &xclient);
109 } else { 113 } else {
110 OnActiveWindowChanged(window, ACTIVE); 114 OnActiveWindowChanged(window, ACTIVE);
111 } 115 }
112 } else { 116 } else {
113 XRaiseWindow(xdisplay_, window); 117 XRaiseWindow(xdisplay_, window);
114 // Directly ask the X server to give focus to the window. Note 118 // Directly ask the X server to give focus to the window. Note
115 // that the call will raise an X error if the window is not 119 // that the call will raise an X error if the window is not
116 // mapped. 120 // mapped.
117 XSetInputFocus(xdisplay_, window, RevertToParent, CurrentTime); 121 XSetInputFocus(xdisplay_, window, RevertToParent, CurrentTime);
118 122
119 OnActiveWindowChanged(window, ACTIVE); 123 OnActiveWindowChanged(window, ACTIVE);
120 } 124 }
121 } 125 }
122 126
127 void X11DesktopHandler::set_wm_user_time_ms(Time time_ms) {
128 if (time_ms != CurrentTime) {
129 int64_t event_time_64 = time_ms;
130 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
132 // 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.
134 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1))
135 wm_user_time_ms_ = time_ms;
136 }
137 }
138
123 void X11DesktopHandler::DeactivateWindow(::Window window) { 139 void X11DesktopHandler::DeactivateWindow(::Window window) {
124 if (!IsActiveWindow(window)) 140 if (!IsActiveWindow(window))
125 return; 141 return;
126 142
127 XLowerWindow(xdisplay_, window); 143 XLowerWindow(xdisplay_, window);
128 144
129 // Per ICCCM: http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7 145 // Per ICCCM: http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
130 // "Clients should not give up the input focus of their own volition. 146 // "Clients should not give up the input focus of their own volition.
131 // They should ignore input that they receive instead." 147 // They should ignore input that they receive instead."
132 // 148 //
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window); 267 ui::XMenuList::GetInstance()->MaybeUnregisterMenu(window);
252 } 268 }
253 269
254 if (event_type == DestroyNotify) { 270 if (event_type == DestroyNotify) {
255 // Notify the XForeignWindowManager that |window| has been destroyed. 271 // Notify the XForeignWindowManager that |window| has been destroyed.
256 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window); 272 ui::XForeignWindowManager::GetInstance()->OnWindowDestroyed(window);
257 } 273 }
258 } 274 }
259 275
260 } // namespace views 276 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/x11_desktop_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698