1// Copyright 2013 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. 4 5#ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ 6#define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ 7 8#include <X11/Xlib.h> 9#include <set> 10 11#include "chrome/browser/extensions/global_shortcut_listener.h" 12#include "ui/events/platform/platform_event_dispatcher.h" 13 14namespace extensions { 15 16// X11-specific implementation of the GlobalShortcutListener class that 17// listens for global shortcuts. Handles basic keyboard intercepting and 18// forwards its output to the base class for processing. 19class GlobalShortcutListenerX11 : public GlobalShortcutListener, 20 public ui::PlatformEventDispatcher { 21 public: 22 GlobalShortcutListenerX11(); 23 virtual ~GlobalShortcutListenerX11(); 24 25 // ui::PlatformEventDispatcher implementation. 26 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; 27 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; 28 29 private: 30 // GlobalShortcutListener implementation. 31 virtual void StartListening() OVERRIDE; 32 virtual void StopListening() OVERRIDE; 33 virtual bool RegisterAcceleratorImpl( 34 const ui::Accelerator& accelerator) OVERRIDE; 35 virtual void UnregisterAcceleratorImpl( 36 const ui::Accelerator& accelerator) OVERRIDE; 37 38 // Invoked when a global shortcut is pressed. 39 void OnXKeyPressEvent(::XEvent* x_event); 40 41 // Whether this object is listening for global shortcuts. 42 bool is_listening_; 43 44 // The x11 default display and the native root window. 45 ::Display* x_display_; 46 ::Window x_root_window_; 47 48 // A set of registered accelerators. 49 typedef std::set<ui::Accelerator> RegisteredHotKeys; 50 RegisteredHotKeys registered_hot_keys_; 51 52 DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerX11); 53}; 54 55} // namespace extensions 56 57#endif // CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ 58