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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_
9 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
14 #include "ui/aura/env_observer.h"
15 #include "ui/events/platform/platform_event_dispatcher.h"
16 #include "ui/gfx/x/x11_atom_cache.h"
17 #include "ui/gfx/x/x11_types.h"
18 #include "ui/views/views_export.h"
20 template <typename T
> struct DefaultSingletonTraits
;
24 // A singleton that owns global objects related to the desktop and listens for
25 // X11 events on the X11 root window. Destroys itself when aura::Env is
27 class VIEWS_EXPORT X11DesktopHandler
: public ui::PlatformEventDispatcher
,
28 public aura::EnvObserver
{
30 // Returns the singleton handler.
31 static X11DesktopHandler
* get();
33 // Gets/sets the X11 server time of the most recent mouse click, touch or
34 // key press on a Chrome window.
35 int wm_user_time_ms() const {
36 return wm_user_time_ms_
;
38 void set_wm_user_time_ms(unsigned long time_ms
) {
39 wm_user_time_ms_
= time_ms
;
42 // Sends a request to the window manager to activate |window|.
43 // This method should only be called if the window is already mapped.
44 void ActivateWindow(::Window window
);
46 // Attempts to get the window manager to deactivate |window| by moving it to
47 // the bottom of the stack. Regardless of whether |window| was actually
48 // deactivated, sets the window as inactive in our internal state.
49 void DeactivateWindow(::Window window
);
51 // Checks if the current active window is |window|.
52 bool IsActiveWindow(::Window window
) const;
54 // Processes activation/focus related events. Some of these events are
55 // dispatched to the X11 window dispatcher, and not to the X11 root-window
56 // dispatcher. The window dispatcher sends these events to here.
57 void ProcessXEvent(XEvent
* event
);
59 // ui::PlatformEventDispatcher
60 bool CanDispatchEvent(const ui::PlatformEvent
& event
) override
;
61 uint32_t DispatchEvent(const ui::PlatformEvent
& event
) override
;
63 // Overridden from aura::EnvObserver:
64 void OnWindowInitialized(aura::Window
* window
) override
;
65 void OnWillDestroyEnv() override
;
74 ~X11DesktopHandler() override
;
76 // Handles changes in activation.
77 void OnActiveWindowChanged(::Window window
, ActiveState active_state
);
79 // Called when |window| has been created or destroyed. |window| may not be
81 void OnWindowCreatedOrDestroyed(int event_type
, XID window
);
83 // The display and the native X window hosting the root window.
86 // The native root window.
87 ::Window x_root_window_
;
89 // The X11 server time of the most recent mouse click, touch, or key press
90 // on a Chrome window.
91 unsigned long wm_user_time_ms_
;
93 // The active window according to X11 server.
94 ::Window current_window_
;
96 // Whether we should treat |current_window_| as active. In particular, we
97 // pretend that a window is deactivated after a call to DeactivateWindow().
98 ActiveState current_window_active_state_
;
100 ui::X11AtomCache atom_cache_
;
102 bool wm_supports_active_window_
;
104 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler
);
109 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_