Commit dcd31ce4 authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Pass in the time of the user's last activity timestamp with the _NET_ACTIVE_WINDOW event.

_NET_ACTIVE_WINDOW events with a CurrentTime timestamp are ignored by Unity.

BUG=365450, 355667
TEST=Manual, see bug

Review URL: https://codereview.chromium.org/317783012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275372 0039d316-1c4b-4281-b951-d872f2087c98
parent b221bd66
......@@ -1192,6 +1192,29 @@ void DesktopWindowTreeHostX11::OnFrameExtentsUpdated() {
}
}
void DesktopWindowTreeHostX11::UpdateWMUserTime(
const ui::PlatformEvent& event) {
if (!IsActive())
return;
ui::EventType type = ui::EventTypeFromNative(event);
if (type == ui::ET_MOUSE_PRESSED ||
type == ui::ET_KEY_PRESSED ||
type == ui::ET_TOUCH_PRESSED) {
unsigned long wm_user_time_ms = static_cast<unsigned long>(
ui::EventTimeFromNative(event).InMilliseconds());
XChangeProperty(xdisplay_,
xwindow_,
atom_cache_.GetAtom("_NET_WM_USER_TIME"),
XA_CARDINAL,
32,
PropModeReplace,
reinterpret_cast<const unsigned char *>(&wm_user_time_ms),
1);
X11DesktopHandler::get()->set_wm_user_time_ms(wm_user_time_ms);
}
}
void DesktopWindowTreeHostX11::SetWMSpecState(bool enabled,
::Atom state1,
::Atom state2) {
......@@ -1405,22 +1428,17 @@ void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) {
// If SHOW_STATE_INACTIVE, tell the window manager not to focus the window
// when mapping. This is done by setting the _NET_WM_USER_TIME to 0. See e.g.
// http://standards.freedesktop.org/wm-spec/latest/ar01s05.html
if (show_state == ui::SHOW_STATE_INACTIVE) {
unsigned long value = 0;
unsigned long wm_user_time_ms = (show_state == ui::SHOW_STATE_INACTIVE) ?
0 : X11DesktopHandler::get()->wm_user_time_ms();
if (show_state == ui::SHOW_STATE_INACTIVE || wm_user_time_ms != 0) {
XChangeProperty(xdisplay_,
xwindow_,
atom_cache_.GetAtom("_NET_WM_USER_TIME"),
XA_CARDINAL,
32,
PropModeReplace,
reinterpret_cast<const unsigned char *>(&value),
reinterpret_cast<const unsigned char *>(&wm_user_time_ms),
1);
} else {
// TODO(piman): if this window was created in response to an X event, we
// should set the time to the server time of the event that caused this.
// https://crbug.com/355667
XDeleteProperty(
xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME"));
}
XMapWindow(xdisplay_, xwindow_);
......@@ -1456,6 +1474,8 @@ uint32_t DesktopWindowTreeHostX11::DispatchEvent(
TRACE_EVENT1("views", "DesktopWindowTreeHostX11::Dispatch",
"event->type", event->type);
UpdateWMUserTime(event);
// May want to factor CheckXEventForConsistency(xev); into a common location
// since it is called here.
switch (xev->type) {
......
......@@ -172,6 +172,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// Called when |xwindow_|'s _NET_FRAME_EXTENTS property is updated.
void OnFrameExtentsUpdated();
// Updates |xwindow_|'s _NET_WM_USER_TIME if |xwindow_| is active.
void UpdateWMUserTime(const ui::PlatformEvent& event);
// Sends a message to the x11 window manager, enabling or disabling the
// states |state1| and |state2|.
void SetWMSpecState(bool enabled, ::Atom state1, ::Atom state2);
......
......@@ -42,6 +42,7 @@ X11DesktopHandler* X11DesktopHandler::get() {
X11DesktopHandler::X11DesktopHandler()
: xdisplay_(gfx::GetXDisplay()),
x_root_window_(DefaultRootWindow(xdisplay_)),
wm_user_time_ms_(0),
current_window_(None),
atom_cache_(xdisplay_, kAtomsToCache),
wm_supports_active_window_(false) {
......@@ -78,7 +79,7 @@ void X11DesktopHandler::ActivateWindow(::Window window) {
xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW");
xclient.xclient.format = 32;
xclient.xclient.data.l[0] = 1; // Specified we are an app.
xclient.xclient.data.l[1] = CurrentTime;
xclient.xclient.data.l[1] = wm_user_time_ms_;
xclient.xclient.data.l[2] = None;
xclient.xclient.data.l[3] = 0;
xclient.xclient.data.l[4] = 0;
......
......@@ -30,6 +30,15 @@ class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher,
// Returns the singleton handler.
static X11DesktopHandler* get();
// Gets/sets the X11 server time of the most recent mouse click, touch or
// key press on a Chrome window.
int wm_user_time_ms() const {
return wm_user_time_ms_;
}
void set_wm_user_time_ms(unsigned long time_ms) {
wm_user_time_ms_ = time_ms;
}
// Sends a request to the window manager to activate |window|.
// This method should only be called if the window is already mapped.
void ActivateWindow(::Window window);
......@@ -63,6 +72,10 @@ class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher,
// The native root window.
::Window x_root_window_;
// The X11 server time of the most recent mouse click, touch, or key press
// on a Chrome window.
unsigned long wm_user_time_ms_;
// The activated window.
::Window current_window_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment