| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ | 5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ |
| 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ | 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 11 #undef RootWindow | 11 #undef RootWindow |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/observer_list.h" |
| 16 #include "ui/aura/env_observer.h" | 17 #include "ui/aura/env_observer.h" |
| 17 #include "ui/events/platform/platform_event_dispatcher.h" | 18 #include "ui/events/platform/platform_event_dispatcher.h" |
| 18 #include "ui/events/platform/x11/x11_event_source.h" | 19 #include "ui/events/platform/x11/x11_event_source.h" |
| 19 #include "ui/gfx/x/x11_atom_cache.h" | 20 #include "ui/gfx/x/x11_atom_cache.h" |
| 20 #include "ui/gfx/x/x11_types.h" | 21 #include "ui/gfx/x/x11_types.h" |
| 21 #include "ui/views/views_export.h" | 22 #include "ui/views/views_export.h" |
| 23 #include "ui/views/widget/desktop_aura/x11_desktop_handler_observer.h" |
| 22 | 24 |
| 23 namespace base { | 25 namespace base { |
| 24 template <typename T> struct DefaultSingletonTraits; | 26 template <typename T> struct DefaultSingletonTraits; |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace views { | 29 namespace views { |
| 28 | 30 |
| 29 // A singleton that owns global objects related to the desktop and listens for | 31 // A singleton that owns global objects related to the desktop and listens for |
| 30 // X11 events on the X11 root window. Destroys itself when aura::Env is | 32 // X11 events on the X11 root window. Destroys itself when aura::Env is |
| 31 // deleted. | 33 // deleted. |
| 32 class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher, | 34 class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher, |
| 33 public aura::EnvObserver { | 35 public aura::EnvObserver { |
| 34 public: | 36 public: |
| 35 // Returns the singleton handler. | 37 // Returns the singleton handler. |
| 36 static X11DesktopHandler* get(); | 38 static X11DesktopHandler* get(); |
| 37 | 39 |
| 40 // Adds/removes X11DesktopHandlerObservers. |
| 41 void AddObserver(X11DesktopHandlerObserver* observer); |
| 42 void RemoveObserver(X11DesktopHandlerObserver* observer); |
| 43 |
| 44 // Gets the current workspace ID. |
| 45 std::string GetWorkspace(); |
| 46 |
| 38 // Gets/sets the X11 server time of the most recent mouse click, touch or | 47 // Gets/sets the X11 server time of the most recent mouse click, touch or |
| 39 // key press on a Chrome window. | 48 // key press on a Chrome window. |
| 40 int wm_user_time_ms() const { return wm_user_time_ms_; } | 49 int wm_user_time_ms() const { return wm_user_time_ms_; } |
| 41 void set_wm_user_time_ms(Time time_ms); | 50 void set_wm_user_time_ms(Time time_ms); |
| 42 | 51 |
| 43 // Sends a request to the window manager to activate |window|. | 52 // Sends a request to the window manager to activate |window|. |
| 44 // This method should only be called if the window is already mapped. | 53 // This method should only be called if the window is already mapped. |
| 45 void ActivateWindow(::Window window); | 54 void ActivateWindow(::Window window); |
| 46 | 55 |
| 47 // Attempts to get the window manager to deactivate |window| by moving it to | 56 // Attempts to get the window manager to deactivate |window| by moving it to |
| (...skipping 26 matching lines...) Expand all Loading... |
| 74 X11DesktopHandler(); | 83 X11DesktopHandler(); |
| 75 ~X11DesktopHandler() override; | 84 ~X11DesktopHandler() override; |
| 76 | 85 |
| 77 // Handles changes in activation. | 86 // Handles changes in activation. |
| 78 void OnActiveWindowChanged(::Window window, ActiveState active_state); | 87 void OnActiveWindowChanged(::Window window, ActiveState active_state); |
| 79 | 88 |
| 80 // Called when |window| has been created or destroyed. |window| may not be | 89 // Called when |window| has been created or destroyed. |window| may not be |
| 81 // managed by Chrome. | 90 // managed by Chrome. |
| 82 void OnWindowCreatedOrDestroyed(int event_type, XID window); | 91 void OnWindowCreatedOrDestroyed(int event_type, XID window); |
| 83 | 92 |
| 93 // Makes a round trip to the X server to get the current workspace. |
| 94 bool UpdateWorkspace(); |
| 95 |
| 84 // The display and the native X window hosting the root window. | 96 // The display and the native X window hosting the root window. |
| 85 XDisplay* xdisplay_; | 97 XDisplay* xdisplay_; |
| 86 | 98 |
| 87 // The native root window. | 99 // The native root window. |
| 88 ::Window x_root_window_; | 100 ::Window x_root_window_; |
| 89 | 101 |
| 90 // The last known active X window | 102 // The last known active X window |
| 91 ::Window x_active_window_; | 103 ::Window x_active_window_; |
| 92 | 104 |
| 93 // The X11 server time of the most recent mouse click, touch, or key press | 105 // The X11 server time of the most recent mouse click, touch, or key press |
| 94 // on a Chrome window. | 106 // on a Chrome window. |
| 95 Time wm_user_time_ms_; | 107 Time wm_user_time_ms_; |
| 96 | 108 |
| 97 // The active window according to X11 server. | 109 // The active window according to X11 server. |
| 98 ::Window current_window_; | 110 ::Window current_window_; |
| 99 | 111 |
| 100 // Whether we should treat |current_window_| as active. In particular, we | 112 // Whether we should treat |current_window_| as active. In particular, we |
| 101 // pretend that a window is deactivated after a call to DeactivateWindow(). | 113 // pretend that a window is deactivated after a call to DeactivateWindow(). |
| 102 ActiveState current_window_active_state_; | 114 ActiveState current_window_active_state_; |
| 103 | 115 |
| 104 ui::X11AtomCache atom_cache_; | 116 ui::X11AtomCache atom_cache_; |
| 105 | 117 |
| 106 bool wm_supports_active_window_; | 118 bool wm_supports_active_window_; |
| 107 | 119 |
| 120 base::ObserverList<X11DesktopHandlerObserver> observers_; |
| 121 |
| 122 std::string workspace_; |
| 123 |
| 108 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler); | 124 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler); |
| 109 }; | 125 }; |
| 110 | 126 |
| 111 } // namespace views | 127 } // namespace views |
| 112 | 128 |
| 113 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ | 129 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_ |
| OLD | NEW |