| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <X11/Xlib.h> | 5 #include <X11/Xlib.h> |
| 6 #include <gdk/gdk.h> | 6 #include <gdk/gdk.h> |
| 7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 | 8 |
| 9 #include "app/active_window_watcher_x.h" | 9 #include "app/active_window_watcher_x.h" |
| 10 | 10 |
| 11 static Atom kNetActiveWindowAtom = None; | 11 static Atom kNetActiveWindowAtom = None; |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 void ActiveWindowWatcherX::AddObserver(Observer* observer) { | 14 void ActiveWindowWatcherX::AddObserver(Observer* observer) { |
| 15 Singleton<ActiveWindowWatcherX>::get()->observers_.AddObserver(observer); | 15 Singleton<ActiveWindowWatcherX>::get()->observers_.AddObserver(observer); |
| 16 } | 16 } |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 void ActiveWindowWatcherX::RemoveObserver(Observer* observer) { | 19 void ActiveWindowWatcherX::RemoveObserver(Observer* observer) { |
| 20 Singleton<ActiveWindowWatcherX>::get()->observers_.RemoveObserver(observer); | 20 Singleton<ActiveWindowWatcherX>::get()->observers_.RemoveObserver(observer); |
| 21 } | 21 } |
| 22 | 22 |
| 23 ActiveWindowWatcherX::ActiveWindowWatcherX() { | 23 ActiveWindowWatcherX::ActiveWindowWatcherX() { |
| 24 Init(); | 24 Init(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 ActiveWindowWatcherX::~ActiveWindowWatcherX() { |
| 28 } |
| 29 |
| 27 void ActiveWindowWatcherX::Init() { | 30 void ActiveWindowWatcherX::Init() { |
| 28 GdkAtom kNetActiveWindow = gdk_atom_intern("_NET_ACTIVE_WINDOW", FALSE); | 31 GdkAtom kNetActiveWindow = gdk_atom_intern("_NET_ACTIVE_WINDOW", FALSE); |
| 29 kNetActiveWindowAtom = gdk_x11_atom_to_xatom_for_display( | 32 kNetActiveWindowAtom = gdk_x11_atom_to_xatom_for_display( |
| 30 gdk_screen_get_display(gdk_screen_get_default()), kNetActiveWindow); | 33 gdk_screen_get_display(gdk_screen_get_default()), kNetActiveWindow); |
| 31 | 34 |
| 32 GdkWindow* root = gdk_get_default_root_window(); | 35 GdkWindow* root = gdk_get_default_root_window(); |
| 33 | 36 |
| 34 // Set up X Event filter to listen for PropertyChange X events. These events | 37 // Set up X Event filter to listen for PropertyChange X events. These events |
| 35 // tell us when the active window changes. | 38 // tell us when the active window changes. |
| 36 // Don't use XSelectInput directly here, as gdk internally seems to cache the | 39 // Don't use XSelectInput directly here, as gdk internally seems to cache the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 window_watcher); | 88 window_watcher); |
| 86 XEvent* xev = static_cast<XEvent*>(xevent); | 89 XEvent* xev = static_cast<XEvent*>(xevent); |
| 87 | 90 |
| 88 if (xev->xany.type == PropertyNotify && | 91 if (xev->xany.type == PropertyNotify && |
| 89 xev->xproperty.atom == kNetActiveWindowAtom) { | 92 xev->xproperty.atom == kNetActiveWindowAtom) { |
| 90 watcher->NotifyActiveWindowChanged(); | 93 watcher->NotifyActiveWindowChanged(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 return GDK_FILTER_CONTINUE; | 96 return GDK_FILTER_CONTINUE; |
| 94 } | 97 } |
| OLD | NEW |