#include <vector>
-#include "base/message_loop/message_pump_dispatcher.h"
#include "ui/aura/env_observer.h"
+#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/views/views_export.h"
// A singleton that owns global objects related to the desktop and listens for
// X11 events on the X11 root window. Destroys itself when aura::Env is
// deleted.
-class VIEWS_EXPORT X11DesktopHandler : public base::MessagePumpDispatcher,
+class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher,
public aura::EnvObserver {
public:
// Returns the singleton handler.
static X11DesktopHandler* get();
+ // Gets/sets the X11 server time of the most recent mouse click, touch or
+ // key press on a Chrome window.
+ int wm_user_time_ms() const {
+ return wm_user_time_ms_;
+ }
+ void set_wm_user_time_ms(unsigned long time_ms) {
+ wm_user_time_ms_ = time_ms;
+ }
+
// Sends a request to the window manager to activate |window|.
// This method should only be called if the window is already mapped.
void ActivateWindow(::Window window);
- // Deactivates the |window| and activates the window just below it in z-order.
- // |window| must be active.
+ // Attempts to get the window manager to deactivate |window| by moving it to
+ // the bottom of the stack. Regardless of whether |window| was actually
+ // deactivated, sets the window as inactive in our internal state.
void DeactivateWindow(::Window window);
// Checks if the current active window is |window|.
// Processes activation/focus related events. Some of these events are
// dispatched to the X11 window dispatcher, and not to the X11 root-window
// dispatcher. The window dispatcher sends these events to here.
- void ProcessXEvent(const base::NativeEvent& event);
+ void ProcessXEvent(XEvent* event);
- // Overridden from MessagePumpDispatcher:
- virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
+ // ui::PlatformEventDispatcher
+ virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
+ virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
// Overridden from aura::EnvObserver:
virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
virtual void OnWillDestroyEnv() OVERRIDE;
- // Allows to override wm_supports_active_window_ value for tests. If the WM
- // supports _NET_ACTIVE_WINDOW, activation is async otherwise it is sync.
- void SetWMSupportsActiveWindowForTests(bool value) {
- wm_supports_active_window_ = value;
- }
-
private:
- explicit X11DesktopHandler();
+ enum ActiveState {
+ ACTIVE,
+ NOT_ACTIVE
+ };
+
+ X11DesktopHandler();
virtual ~X11DesktopHandler();
// Handles changes in activation.
- void OnActiveWindowChanged(::Window window);
+ void OnActiveWindowChanged(::Window window, ActiveState active_state);
- // Return the next window to activate based on the current list of windows.
- // This should only be called if there is an active window. In other words, if
- // current_window_ is different from None.
- ::Window GetNextToActivateInStack(const std::vector< ::Window >& windows);
+ // Called when |window| has been created or destroyed. |window| may not be
+ // managed by Chrome.
+ void OnWindowCreatedOrDestroyed(int event_type, XID window);
// The display and the native X window hosting the root window.
XDisplay* xdisplay_;
// The native root window.
::Window x_root_window_;
- // The activated window.
+ // The X11 server time of the most recent mouse click, touch, or key press
+ // on a Chrome window.
+ unsigned long wm_user_time_ms_;
+
+ // The active window according to X11 server.
::Window current_window_;
+ // Whether we should treat |current_window_| as active. In particular, we
+ // pretend that a window is deactivated after a call to DeactivateWindow().
+ ActiveState current_window_active_state_;
+
ui::X11AtomCache atom_cache_;
bool wm_supports_active_window_;