Update x11 global shortcut listeners

This commit is contained in:
Brian R. Bondy 2016-04-30 20:31:07 -04:00 committed by Cheng Zhao
parent f93fa53aea
commit 37ccd34a88
2 changed files with 16 additions and 15 deletions

View file

@ -4,10 +4,13 @@
#include "chrome/browser/extensions/global_shortcut_listener_x11.h" #include "chrome/browser/extensions/global_shortcut_listener_x11.h"
#include <stddef.h>
#include "base/macros.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h" #include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/x11_error_tracker.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
@ -35,7 +38,6 @@ int GetNativeModifiers(const ui::Accelerator& accelerator) {
modifiers |= accelerator.IsShiftDown() ? ShiftMask : 0; modifiers |= accelerator.IsShiftDown() ? ShiftMask : 0;
modifiers |= accelerator.IsCtrlDown() ? ControlMask : 0; modifiers |= accelerator.IsCtrlDown() ? ControlMask : 0;
modifiers |= accelerator.IsAltDown() ? Mod1Mask : 0; modifiers |= accelerator.IsAltDown() ? Mod1Mask : 0;
modifiers |= accelerator.IsCmdDown() ? Mod4Mask : 0;
return modifiers; return modifiers;
} }
@ -69,7 +71,7 @@ void GlobalShortcutListenerX11::StartListening() {
DCHECK(!registered_hot_keys_.empty()); // Also don't start if no hotkey is DCHECK(!registered_hot_keys_.empty()); // Also don't start if no hotkey is
// registered. // registered.
ui::X11EventSource::GetInstance()->AddPlatformEventDispatcher(this); ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
is_listening_ = true; is_listening_ = true;
} }
@ -79,7 +81,7 @@ void GlobalShortcutListenerX11::StopListening() {
DCHECK(registered_hot_keys_.empty()); // Make sure the set is clean before DCHECK(registered_hot_keys_.empty()); // Make sure the set is clean before
// ending. // ending.
ui::X11EventSource::GetInstance()->RemovePlatformEventDispatcher(this); ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
is_listening_ = false; is_listening_ = false;
} }
@ -149,8 +151,6 @@ void GlobalShortcutListenerX11::OnXKeyPressEvent(::XEvent* x_event) {
modifiers |= (x_event->xkey.state & ShiftMask) ? ui::EF_SHIFT_DOWN : 0; modifiers |= (x_event->xkey.state & ShiftMask) ? ui::EF_SHIFT_DOWN : 0;
modifiers |= (x_event->xkey.state & ControlMask) ? ui::EF_CONTROL_DOWN : 0; modifiers |= (x_event->xkey.state & ControlMask) ? ui::EF_CONTROL_DOWN : 0;
modifiers |= (x_event->xkey.state & Mod1Mask) ? ui::EF_ALT_DOWN : 0; modifiers |= (x_event->xkey.state & Mod1Mask) ? ui::EF_ALT_DOWN : 0;
// For Windows key
modifiers |= (x_event->xkey.state & Mod4Mask) ? ui::EF_COMMAND_DOWN: 0;
ui::Accelerator accelerator( ui::Accelerator accelerator(
ui::KeyboardCodeFromXKeyEvent(x_event), modifiers); ui::KeyboardCodeFromXKeyEvent(x_event), modifiers);

View file

@ -5,9 +5,12 @@
#ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ #ifndef CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_
#define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_ #define CHROME_BROWSER_EXTENSIONS_GLOBAL_SHORTCUT_LISTENER_X11_H_
#include <stdint.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <set> #include <set>
#include "base/macros.h"
#include "chrome/browser/extensions/global_shortcut_listener.h" #include "chrome/browser/extensions/global_shortcut_listener.h"
#include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_dispatcher.h"
@ -20,20 +23,18 @@ class GlobalShortcutListenerX11 : public GlobalShortcutListener,
public ui::PlatformEventDispatcher { public ui::PlatformEventDispatcher {
public: public:
GlobalShortcutListenerX11(); GlobalShortcutListenerX11();
virtual ~GlobalShortcutListenerX11(); ~GlobalShortcutListenerX11() override;
// ui::PlatformEventDispatcher implementation. // ui::PlatformEventDispatcher implementation.
virtual bool CanDispatchEvent(const ui::PlatformEvent& event) override; bool CanDispatchEvent(const ui::PlatformEvent& event) override;
virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) override; uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
private: private:
// GlobalShortcutListener implementation. // GlobalShortcutListener implementation.
virtual void StartListening() override; void StartListening() override;
virtual void StopListening() override; void StopListening() override;
virtual bool RegisterAcceleratorImpl( bool RegisterAcceleratorImpl(const ui::Accelerator& accelerator) override;
const ui::Accelerator& accelerator) override; void UnregisterAcceleratorImpl(const ui::Accelerator& accelerator) override;
virtual void UnregisterAcceleratorImpl(
const ui::Accelerator& accelerator) override;
// Invoked when a global shortcut is pressed. // Invoked when a global shortcut is pressed.
void OnXKeyPressEvent(::XEvent* x_event); void OnXKeyPressEvent(::XEvent* x_event);