| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ | 5 #ifndef UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ |
| 6 #define UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ | 6 #define UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <gdk/gdk.h> | |
| 10 | |
| 11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 12 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 13 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 14 #include "ui/base/gtk/gtk_signal.h" | |
| 15 #include "ui/base/ui_export.h" | 12 #include "ui/base/ui_export.h" |
| 13 #include "ui/base/x/x11_util.h" |
| 16 | 14 |
| 17 namespace ui { | 15 namespace ui { |
| 18 | 16 |
| 17 class ActiveWindowWatcherXObserver; |
| 18 |
| 19 namespace internal { |
| 20 class RootWindowPropertyWatcherX; |
| 21 } |
| 22 |
| 19 // This is a helper class that is used to keep track of which window the X | 23 // This is a helper class that is used to keep track of which window the X |
| 20 // window manager thinks is active. Add an Observer to listener for changes to | 24 // window manager thinks is active. Add an Observer to listen for changes to |
| 21 // the active window. | 25 // the active window. |
| 22 class UI_EXPORT ActiveWindowWatcherX { | 26 class UI_EXPORT ActiveWindowWatcherX { |
| 23 public: | 27 public: |
| 24 class Observer { | |
| 25 public: | |
| 26 // |active_window| will be NULL if the active window isn't one of Chrome's. | |
| 27 virtual void ActiveWindowChanged(GdkWindow* active_window) = 0; | |
| 28 | |
| 29 protected: | |
| 30 virtual ~Observer() {} | |
| 31 }; | |
| 32 | |
| 33 static ActiveWindowWatcherX* GetInstance(); | 28 static ActiveWindowWatcherX* GetInstance(); |
| 34 | 29 static void AddObserver(ActiveWindowWatcherXObserver* observer); |
| 35 static void AddObserver(Observer* observer); | 30 static void RemoveObserver(ActiveWindowWatcherXObserver* observer); |
| 36 static void RemoveObserver(Observer* observer); | |
| 37 | 31 |
| 38 // Checks if the WM supports the active window property. Note that the return | 32 // Checks if the WM supports the active window property. Note that the return |
| 39 // value can change, especially during system startup. | 33 // value can change, especially during system startup. |
| 40 static bool WMSupportsActivation(); | 34 static bool WMSupportsActivation(); |
| 41 | 35 |
| 42 private: | 36 private: |
| 43 friend struct DefaultSingletonTraits<ActiveWindowWatcherX>; | 37 friend struct DefaultSingletonTraits<ActiveWindowWatcherX>; |
| 38 friend class ui::internal::RootWindowPropertyWatcherX; |
| 44 | 39 |
| 45 ActiveWindowWatcherX(); | 40 ActiveWindowWatcherX(); |
| 46 ~ActiveWindowWatcherX(); | 41 ~ActiveWindowWatcherX(); |
| 47 | 42 |
| 48 void Init(); | 43 // Gets the atom for the default display for the property this class is |
| 44 // watching for. |
| 45 static Atom GetPropertyAtom(); |
| 49 | 46 |
| 50 // Sends a notification out through the NotificationService that the active | 47 // Notify observers that the active window has changed. |
| 51 // window has changed. | 48 static void Notify(); |
| 49 |
| 50 // Instance method that implements Notify(). |
| 52 void NotifyActiveWindowChanged(); | 51 void NotifyActiveWindowChanged(); |
| 53 | 52 |
| 54 // Callback for PropertyChange XEvents. | 53 ObserverList<ActiveWindowWatcherXObserver> observers_; |
| 55 CHROMEG_CALLBACK_1(ActiveWindowWatcherX, GdkFilterReturn, | |
| 56 OnWindowXEvent, GdkXEvent*, GdkEvent*); | |
| 57 | |
| 58 ObserverList<Observer> observers_; | |
| 59 | 54 |
| 60 DISALLOW_COPY_AND_ASSIGN(ActiveWindowWatcherX); | 55 DISALLOW_COPY_AND_ASSIGN(ActiveWindowWatcherX); |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 } // namespace ui | 58 } // namespace ui |
| 64 | 59 |
| 65 #endif // UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ | 60 #endif // UI_BASE_X_ACTIVE_WINDOW_WATCHER_X_H_ |
| OLD | NEW |