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 "base/message_loop/message_pump_dispatcher.h"
15 #include "ui/aura/env_observer.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 base::MessagePumpDispatcher,
28 public aura::EnvObserver {
30 // Returns the singleton handler.
31 static X11DesktopHandler* get();
33 // Sends a request to the window manager to activate |window|.
34 // This method should only be called if the window is already mapped.
35 void ActivateWindow(::Window window);
37 // Deactivates the |window| and activates the window just below it in z-order.
38 // |window| must be active.
39 void DeactivateWindow(::Window window);
41 // Checks if the current active window is |window|.
42 bool IsActiveWindow(::Window window) const;
44 // Processes activation/focus related events. Some of these events are
45 // dispatched to the X11 window dispatcher, and not to the X11 root-window
46 // dispatcher. The window dispatcher sends these events to here.
47 void ProcessXEvent(const base::NativeEvent& event);
49 // Overridden from MessagePumpDispatcher:
50 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
52 // Overridden from aura::EnvObserver:
53 virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
54 virtual void OnWillDestroyEnv() OVERRIDE;
56 // Allows to override wm_supports_active_window_ value for tests. If the WM
57 // supports _NET_ACTIVE_WINDOW, activation is async otherwise it is sync.
58 void SetWMSupportsActiveWindowForTests(bool value) {
59 wm_supports_active_window_ = value;
63 explicit X11DesktopHandler();
64 virtual ~X11DesktopHandler();
66 // Handles changes in activation.
67 void OnActiveWindowChanged(::Window window);
69 // Return the next window to activate based on the current list of windows.
70 // This should only be called if there is an active window. In other words, if
71 // current_window_ is different from None.
72 ::Window GetNextToActivateInStack(const std::vector< ::Window >& windows);
74 // The display and the native X window hosting the root window.
77 // The native root window.
78 ::Window x_root_window_;
80 // The activated window.
81 ::Window current_window_;
83 ui::X11AtomCache atom_cache_;
85 bool wm_supports_active_window_;
87 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler);
92 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_