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 // 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 // Checks if the current active window is |window|.
38 bool IsActiveWindow(::Window window) const;
40 // Processes activation/focus related events. Some of these events are
41 // dispatched to the X11 window dispatcher, and not to the X11 root-window
42 // dispatcher. The window dispatcher sends these events to here.
43 void ProcessXEvent(XEvent* event);
45 // ui::PlatformEventDispatcher
46 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
47 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
49 // Overridden from aura::EnvObserver:
50 virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
51 virtual void OnWillDestroyEnv() OVERRIDE;
54 explicit X11DesktopHandler();
55 virtual ~X11DesktopHandler();
57 // Handles changes in activation.
58 void OnActiveWindowChanged(::Window window);
60 // The display and the native X window hosting the root window.
63 // The native root window.
64 ::Window x_root_window_;
66 // The activated window.
67 ::Window current_window_;
69 ui::X11AtomCache atom_cache_;
71 bool wm_supports_active_window_;
73 DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler);
78 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_