Update V8 to version 4.7.57.
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / x11_desktop_handler.h
blob48072e8d67c17ffae2b64132adeebd3ad34fa9eb
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_
8 #include <X11/Xlib.h>
9 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
10 #undef RootWindow
12 #include <vector>
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 namespace base {
21 template <typename T> struct DefaultSingletonTraits;
24 namespace views {
26 // A singleton that owns global objects related to the desktop and listens for
27 // X11 events on the X11 root window. Destroys itself when aura::Env is
28 // deleted.
29 class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher,
30 public aura::EnvObserver {
31 public:
32 // Returns the singleton handler.
33 static X11DesktopHandler* get();
35 // Gets/sets the X11 server time of the most recent mouse click, touch or
36 // key press on a Chrome window.
37 int wm_user_time_ms() const {
38 return wm_user_time_ms_;
40 void set_wm_user_time_ms(unsigned long time_ms) {
41 wm_user_time_ms_ = time_ms;
44 // Sends a request to the window manager to activate |window|.
45 // This method should only be called if the window is already mapped.
46 void ActivateWindow(::Window window);
48 // Attempts to get the window manager to deactivate |window| by moving it to
49 // the bottom of the stack. Regardless of whether |window| was actually
50 // deactivated, sets the window as inactive in our internal state.
51 void DeactivateWindow(::Window window);
53 // Checks if the current active window is |window|.
54 bool IsActiveWindow(::Window window) const;
56 // Processes activation/focus related events. Some of these events are
57 // dispatched to the X11 window dispatcher, and not to the X11 root-window
58 // dispatcher. The window dispatcher sends these events to here.
59 void ProcessXEvent(XEvent* event);
61 // ui::PlatformEventDispatcher
62 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
63 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
65 // Overridden from aura::EnvObserver:
66 void OnWindowInitialized(aura::Window* window) override;
67 void OnWillDestroyEnv() override;
69 private:
70 enum ActiveState {
71 ACTIVE,
72 NOT_ACTIVE
75 X11DesktopHandler();
76 ~X11DesktopHandler() override;
78 // Handles changes in activation.
79 void OnActiveWindowChanged(::Window window, ActiveState active_state);
81 // Called when |window| has been created or destroyed. |window| may not be
82 // managed by Chrome.
83 void OnWindowCreatedOrDestroyed(int event_type, XID window);
85 // The display and the native X window hosting the root window.
86 XDisplay* xdisplay_;
88 // The native root window.
89 ::Window x_root_window_;
91 // The last known active X window
92 ::Window x_active_window_;
94 // The X11 server time of the most recent mouse click, touch, or key press
95 // on a Chrome window.
96 unsigned long wm_user_time_ms_;
98 // The active window according to X11 server.
99 ::Window current_window_;
101 // Whether we should treat |current_window_| as active. In particular, we
102 // pretend that a window is deactivated after a call to DeactivateWindow().
103 ActiveState current_window_active_state_;
105 ui::X11AtomCache atom_cache_;
107 bool wm_supports_active_window_;
109 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler);
112 } // namespace views
114 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_