summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/active_window_watcher.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 21:20:52 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 21:20:52 +0000
commit90b6707fe7bdd8dea5d908040e3a2c1f17feb838 (patch)
tree90d3538522d78e296f8f2d15f10058054b183211 /chrome/browser/gtk/active_window_watcher.cc
parent1d4efb6bc9f956cdbca55c7a4ba99d1bb76e42f8 (diff)
downloadchromium_src-90b6707fe7bdd8dea5d908040e3a2c1f17feb838.zip
chromium_src-90b6707fe7bdd8dea5d908040e3a2c1f17feb838.tar.gz
chromium_src-90b6707fe7bdd8dea5d908040e3a2c1f17feb838.tar.bz2
Change the window background color to the inactive color when the
window manager says the window isn't active. ActiveWindowWatcher listens for X events and notifies the browser windows when the active window changes. We can't just use focus events because popup menus cause browser windows to lose focus, but it's still the "active" window. Some window managers don't track active window, in which case we don't get the x event and we just say that all windows are active (our current behavior). BUG=14649 Review URL: http://codereview.chromium.org/155303 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/active_window_watcher.cc')
-rw-r--r--chrome/browser/gtk/active_window_watcher.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/gtk/active_window_watcher.cc b/chrome/browser/gtk/active_window_watcher.cc
new file mode 100644
index 0000000..5028b25
--- /dev/null
+++ b/chrome/browser/gtk/active_window_watcher.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <X11/Xlib.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include "chrome/browser/gtk/active_window_watcher.h"
+#include "chrome/common/notification_service.h"
+
+ActiveWindowWatcher::ActiveWindowWatcher() {
+ Init();
+}
+
+void ActiveWindowWatcher::Init() {
+ // Set up X Event filter to listen for PropertyChange X events. These events
+ // tell us when the active window changes.
+ GdkWindow* root = gdk_screen_get_root_window(gdk_screen_get_default());
+ gdk_window_add_filter(root, &ActiveWindowWatcher::OnWindowXEvent, this);
+ XSelectInput(GDK_WINDOW_XDISPLAY(root), GDK_WINDOW_XID(root),
+ PropertyChangeMask);
+}
+
+void ActiveWindowWatcher::NotifyActiveWindowChanged() {
+ GdkWindow* active_window = gdk_screen_get_active_window(
+ gdk_screen_get_default());
+
+ // If the window manager doesn't support _NET_ACTIVE_WINDOW, we don't know
+ // which window is active and just give up.
+ if (!active_window)
+ return;
+
+ NotificationService::current()->Notify(
+ NotificationType::ACTIVE_WINDOW_CHANGED,
+ Source<ActiveWindowWatcher>(this),
+ Details<const GdkWindow>(active_window));
+}
+
+GdkFilterReturn ActiveWindowWatcher::OnWindowXEvent(GdkXEvent* xevent,
+ GdkEvent* event, gpointer window_watcher) {
+ static const GdkAtom kNetActiveWindow = gdk_atom_intern(
+ "_NET_ACTIVE_WINDOW", FALSE);
+ static const Atom kNetActiveWindowAtom = gdk_x11_atom_to_xatom_for_display(
+ gdk_screen_get_display(gdk_screen_get_default()), kNetActiveWindow);
+
+ ActiveWindowWatcher* watcher = reinterpret_cast<ActiveWindowWatcher*>(
+ window_watcher);
+ XEvent* xev = static_cast<XEvent*>(xevent);
+
+ if (xev->xany.type == PropertyNotify &&
+ xev->xproperty.atom == kNetActiveWindowAtom) {
+ watcher->NotifyActiveWindowChanged();
+ }
+
+ return GDK_FILTER_CONTINUE;
+}