From 0253ae147230697ffcdfdf0be9abdc49eedfd066 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Thu, 16 Feb 2012 11:23:34 +0100 Subject: [PATCH] Bug 721498 - Use remote timestamp when available for focus requests. r=karlt --- toolkit/components/remote/nsGTKRemoteService.cpp | 9 +++++---- widget/gtk2/nsWindow.cpp | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/toolkit/components/remote/nsGTKRemoteService.cpp b/toolkit/components/remote/nsGTKRemoteService.cpp index 4c8c3c3026ea..9da8f057a867 100644 --- a/toolkit/components/remote/nsGTKRemoteService.cpp +++ b/toolkit/components/remote/nsGTKRemoteService.cpp @@ -164,19 +164,20 @@ nsGTKRemoteService::Shutdown() // Set desktop startup ID to the passed ID, if there is one, so that any created // windows get created with the right window manager metadata, and any windows // that get new tabs and are activated also get the right WM metadata. -// If there is no desktop startup ID, then use the X event's timestamp -// for _NET_ACTIVE_WINDOW when the window gets focused or shown. +// The timestamp will be used if there is no desktop startup ID, or if we're +// raising an existing window rather than showing a new window for the first time. void nsGTKRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID, PRUint32 aTimestamp) { nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit(); if (!toolkit) return; + if (!aDesktopStartupID.IsEmpty()) { toolkit->SetDesktopStartupID(aDesktopStartupID); - } else { - toolkit->SetFocusTimestamp(aTimestamp); } + + toolkit->SetFocusTimestamp(aTimestamp); } diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index 6ef9829e12e2..9d77d274a883 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -1438,6 +1438,9 @@ SetUserTimeAndStartupIDForActivatedWindow(GtkWidget* aWindow) sn_display_unref(snd); #endif + // If we used the startup ID, that already contains the focus timestamp; + // we don't want to reuse the timestamp next time we raise the window + GTKToolkit->SetFocusTimestamp(0); GTKToolkit->SetDesktopStartupID(EmptyCString()); } @@ -1501,11 +1504,20 @@ nsWindow::SetFocus(bool aRaise) if (gRaiseWindows && owningWindow->mIsShown && owningWindow->mShell && !gtk_window_is_active(GTK_WINDOW(owningWindow->mShell))) { + PRUint32 timestamp = GDK_CURRENT_TIME; + + nsGTKToolkit* GTKToolkit = nsGTKToolkit::GetToolkit(); + if (GTKToolkit) + timestamp = GTKToolkit->GetFocusTimestamp(); + LOGFOCUS((" requesting toplevel activation [%p]\n", (void *)this)); NS_ASSERTION(owningWindow->mWindowType != eWindowType_popup || mParent, "Presenting an override-redirect window"); - gtk_window_present(GTK_WINDOW(owningWindow->mShell)); + gtk_window_present_with_time(GTK_WINDOW(owningWindow->mShell), timestamp); + + if (GTKToolkit) + GTKToolkit->SetFocusTimestamp(0); } return NS_OK;