diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 20:19:54 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 20:19:54 +0000 |
commit | 82838b02f4b0943196f7e7b4ac7fca78885cbe54 (patch) | |
tree | a98be86ffa39b206dd839bb6ebefcc59bafc6c48 /app/active_window_watcher_x.cc | |
parent | 6affd92124f01ee0eb2b75af96d4ab5576cbccf2 (diff) | |
download | chromium_src-82838b02f4b0943196f7e7b4ac7fca78885cbe54.zip chromium_src-82838b02f4b0943196f7e7b4ac7fca78885cbe54.tar.gz chromium_src-82838b02f4b0943196f7e7b4ac7fca78885cbe54.tar.bz2 |
Pulls ActiveWindowWatcher into app so that we can use it in
views. Converts from using notification server to observer as
notification service is chrome only.
Also changes the pointer type used by window_gtk to be a left arrow.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/245016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/active_window_watcher_x.cc')
-rw-r--r-- | app/active_window_watcher_x.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/app/active_window_watcher_x.cc b/app/active_window_watcher_x.cc new file mode 100644 index 0000000..d834a5c --- /dev/null +++ b/app/active_window_watcher_x.cc @@ -0,0 +1,63 @@ +// 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 "app/active_window_watcher_x.h" + +// static +void ActiveWindowWatcherX::AddObserver(Observer* observer) { + Singleton<ActiveWindowWatcherX>::get()->observers_.AddObserver(observer); +} + +// static +void ActiveWindowWatcherX::RemoveObserver(Observer* observer) { + Singleton<ActiveWindowWatcherX>::get()->observers_.RemoveObserver(observer); +} + +ActiveWindowWatcherX::ActiveWindowWatcherX() { + Init(); +} + +void ActiveWindowWatcherX::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, &ActiveWindowWatcherX::OnWindowXEvent, this); + XSelectInput(GDK_WINDOW_XDISPLAY(root), GDK_WINDOW_XID(root), + PropertyChangeMask); +} + +void ActiveWindowWatcherX::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; + + FOR_EACH_OBSERVER(Observer, observers_, ActiveWindowChanged(active_window)); +} + +GdkFilterReturn ActiveWindowWatcherX::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); + + ActiveWindowWatcherX* watcher = reinterpret_cast<ActiveWindowWatcherX*>( + window_watcher); + XEvent* xev = static_cast<XEvent*>(xevent); + + if (xev->xany.type == PropertyNotify && + xev->xproperty.atom == kNetActiveWindowAtom) { + watcher->NotifyActiveWindowChanged(); + } + + return GDK_FILTER_CONTINUE; +} |