From 4570d891f2b6df86eb959205f841eb9c69e1d3d1 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Mon, 13 Sep 2010 10:14:46 +0000 Subject: [PATCH] Change global shortcuts on Mac to be eaten. Update issue #722 Fixed on Mac. --- src/core/macglobalshortcutbackend.h | 2 +- src/core/macglobalshortcutbackend.mm | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/macglobalshortcutbackend.h b/src/core/macglobalshortcutbackend.h index c6be5dcfe..b53ea33f4 100644 --- a/src/core/macglobalshortcutbackend.h +++ b/src/core/macglobalshortcutbackend.h @@ -44,7 +44,7 @@ protected: void DoUnregister(); private: - void KeyPressed(const QKeySequence& sequence); + bool KeyPressed(const QKeySequence& sequence); QMap shortcuts_; diff --git a/src/core/macglobalshortcutbackend.mm b/src/core/macglobalshortcutbackend.mm index c125e60a8..a62de14ff 100644 --- a/src/core/macglobalshortcutbackend.mm +++ b/src/core/macglobalshortcutbackend.mm @@ -49,8 +49,8 @@ class MacGlobalShortcutBackendPrivate : boost::noncopyable { }]; local_monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent* event) { - HandleKeyEvent(event); - return event; + // Filter event if we handle it as a global shortcut. + return HandleKeyEvent(event) ? nil : event; }]; return true; #else @@ -108,9 +108,9 @@ class MacGlobalShortcutBackendPrivate : boost::noncopyable { return QKeySequence(key); } - void HandleKeyEvent(NSEvent* event) { + bool HandleKeyEvent(NSEvent* event) { QKeySequence sequence = GetSequence(event); - backend_->KeyPressed(sequence); + return backend_->KeyPressed(sequence); } static int MapFunctionKey(int keycode) { @@ -218,14 +218,16 @@ void MacGlobalShortcutBackend::MacMediaKeyPressed(int key) { } } -void MacGlobalShortcutBackend::KeyPressed(const QKeySequence& sequence) { +bool MacGlobalShortcutBackend::KeyPressed(const QKeySequence& sequence) { if (sequence.isEmpty()) { - return; + return false; } QAction* action = shortcuts_[sequence]; if (action) { action->trigger(); + return true; } + return false; } bool MacGlobalShortcutBackend::IsAccessibilityEnabled() const {