Chromium Code Reviews| Index: ui/base/x/active_window_watcher_x.cc |
| diff --git a/ui/base/x/active_window_watcher_x.cc b/ui/base/x/active_window_watcher_x.cc |
| index 01c4a88ccc786c611229532659ba660fc34a49a7..e7cfe26419d1873a3159fa7a7864d6e6fe2a2c38 100644 |
| --- a/ui/base/x/active_window_watcher_x.cc |
| +++ b/ui/base/x/active_window_watcher_x.cc |
| @@ -2,15 +2,17 @@ |
| // 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 "ui/base/x/active_window_watcher_x.h" |
|
sky
2011/11/18 17:54:22
This include should be first, then system includes
prasadt
2011/11/18 22:31:42
Done.
|
| +#include "ui/base/x/root_window_property_watcher_x.h" |
| +#include "ui/base/x/x11_util.h" |
| + |
| namespace ui { |
| -static Atom g_net_active_window_atom = None; |
| +static const char* kNetActiveWindow = "_NET_ACTIVE_WINDOW"; |
| // static |
| ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() { |
| @@ -19,6 +21,8 @@ ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() { |
| // static |
| void ActiveWindowWatcherX::AddObserver(Observer* observer) { |
| + // Ensure that RootWindowPropertyWatcherX exists. |
| + RootWindowPropertyWatcherX::GetInstance(); |
| GetInstance()->observers_.AddObserver(observer); |
| } |
| @@ -28,35 +32,20 @@ void ActiveWindowWatcherX::RemoveObserver(Observer* observer) { |
| } |
| // static |
| -bool ActiveWindowWatcherX::WMSupportsActivation() { |
| - return gdk_x11_screen_supports_net_wm_hint( |
| - gdk_screen_get_default(), |
| - gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW")); |
| +Atom ActiveWindowWatcherX::GetPropertyAtom() { |
| + return GetAtomForScreenProperty(kNetActiveWindow); |
| } |
| -ActiveWindowWatcherX::ActiveWindowWatcherX() { |
| - Init(); |
| -} |
| - |
| -ActiveWindowWatcherX::~ActiveWindowWatcherX() { |
| +// static |
| +void ActiveWindowWatcherX::Notify() { |
| + GetInstance()->NotifyActiveWindowChanged(); |
| } |
| -void ActiveWindowWatcherX::Init() { |
| - GdkAtom net_active_window = |
| - gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW"); |
| - g_net_active_window_atom = gdk_x11_atom_to_xatom_for_display( |
| - gdk_screen_get_display(gdk_screen_get_default()), net_active_window); |
| - |
| - GdkWindow* root = gdk_get_default_root_window(); |
| - |
| - // Set up X Event filter to listen for PropertyChange X events. These events |
| - // tell us when the active window changes. |
| - // Don't use XSelectInput directly here, as gdk internally seems to cache the |
| - // mask and reapply XSelectInput after this, resetting any mask we set here. |
| - gdk_window_set_events(root, |
| - static_cast<GdkEventMask>(gdk_window_get_events(root) | |
| - GDK_PROPERTY_CHANGE_MASK)); |
| - gdk_window_add_filter(NULL, &ActiveWindowWatcherX::OnWindowXEventThunk, this); |
| +// static |
| +bool ActiveWindowWatcherX::WMSupportsActivation() { |
| + return gdk_x11_screen_supports_net_wm_hint( |
| + gdk_screen_get_default(), |
| + gdk_atom_intern_static_string(kNetActiveWindow)); |
| } |
| void ActiveWindowWatcherX::NotifyActiveWindowChanged() { |
| @@ -70,7 +59,7 @@ void ActiveWindowWatcherX::NotifyActiveWindowChanged() { |
| XGetWindowProperty(gdk_x11_get_default_xdisplay(), |
| GDK_WINDOW_XID(gdk_get_default_root_window()), |
| - g_net_active_window_atom, |
| + GetAtomForScreenProperty(kNetActiveWindow), |
| 0, // offset into property data to read |
| 1, // length to get in 32-bit quantities |
| False, // deleted |
| @@ -88,25 +77,10 @@ void ActiveWindowWatcherX::NotifyActiveWindowChanged() { |
| if (format == 32 && num_items == 1) { |
| int xid = *reinterpret_cast<int*>(property); |
| GdkWindow* active_window = gdk_window_lookup(xid); |
| - FOR_EACH_OBSERVER( |
| - Observer, |
| - observers_, |
| - ActiveWindowChanged(active_window)); |
| + FOR_EACH_OBSERVER(Observer, observers_, ActiveWindowChanged(active_window)); |
| } |
| if (property) |
| XFree(property); |
| } |
| -GdkFilterReturn ActiveWindowWatcherX::OnWindowXEvent(GdkXEvent* xevent, |
| - GdkEvent* event) { |
| - XEvent* xev = static_cast<XEvent*>(xevent); |
| - |
| - if (xev->xany.type == PropertyNotify && |
| - xev->xproperty.atom == g_net_active_window_atom) { |
| - NotifyActiveWindowChanged(); |
| - } |
| - |
| - return GDK_FILTER_CONTINUE; |
| -} |
| - |
| } // namespace ui |