2018-10-24 18:24:11 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-10-11 05:02:58 +00:00
|
|
|
From: Jeremy Apthorp <jeremya@chromium.org>
|
|
|
|
Date: Wed, 10 Oct 2018 15:07:34 -0700
|
|
|
|
Subject: define Command::IsMediaKey on mac
|
|
|
|
|
|
|
|
the definition is copied from //chrome/common/extensions/command.cc,
|
|
|
|
which also defines a bunch of other stuff that depends on extensions.
|
|
|
|
since we only need IsMediaKey, and we don't want the extensions stuff
|
|
|
|
(and aren't compiling command.cc), it's safe to duplicate the
|
|
|
|
definition. A candidate for upstreaming would be to move the IsMediaKey
|
|
|
|
function into //ui.
|
|
|
|
|
|
|
|
Also apply electron/electron@0f67b1866a9f00b852370e721affa4efda623f3a
|
|
|
|
and electron/electron@d2368d2d3b3de9eec4cc32b6aaf035cc89921bf1 as
|
|
|
|
patches.
|
|
|
|
|
|
|
|
diff --git a/chrome/browser/extensions/global_shortcut_listener_mac.mm b/chrome/browser/extensions/global_shortcut_listener_mac.mm
|
2018-10-24 18:24:11 +00:00
|
|
|
index f612ba2fb7952654663cbce596c43b0b65d5ea29..77c2c68e6f9bfec3fc887e2119243cee1321cd17 100644
|
2018-10-11 05:02:58 +00:00
|
|
|
--- a/chrome/browser/extensions/global_shortcut_listener_mac.mm
|
|
|
|
+++ b/chrome/browser/extensions/global_shortcut_listener_mac.mm
|
2018-10-24 23:25:48 +00:00
|
|
|
@@ -20,6 +20,26 @@
|
2018-10-11 05:02:58 +00:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
+// NOTE: this is defined in command.cc, but command.cc is full of
|
|
|
|
+// chrome-extensions-specific logic that we don't want to depend on.
|
|
|
|
+// Since we don't build command.cc in Electron, it's safe to re-define this
|
|
|
|
+// function here. Ideally, though, `IsMediaKey` would be the responsibility of
|
|
|
|
+// `ui::Accelerator`, rather than `extensions::Command`.
|
|
|
|
+
|
|
|
|
+// static
|
|
|
|
+bool Command::IsMediaKey(const ui::Accelerator& accelerator) {
|
|
|
|
+ if (accelerator.modifiers() != 0)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_MEDIA_STOP ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_VOLUME_UP ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_VOLUME_DOWN ||
|
|
|
|
+ accelerator.key_code() == ui::VKEY_VOLUME_MUTE);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
// static
|
|
|
|
GlobalShortcutListener* GlobalShortcutListener::GetInstance() {
|
|
|
|
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
diff --git a/chrome/browser/extensions/global_shortcut_listener_win.cc b/chrome/browser/extensions/global_shortcut_listener_win.cc
|
2018-10-24 18:24:11 +00:00
|
|
|
index 65b244d55441b07f55e61c7b634d6cec57f2b1e7..a217f0a1ad965331502dc01fde9ff0a2d0399326 100644
|
2018-10-11 05:02:58 +00:00
|
|
|
--- a/chrome/browser/extensions/global_shortcut_listener_win.cc
|
|
|
|
+++ b/chrome/browser/extensions/global_shortcut_listener_win.cc
|
|
|
|
@@ -63,6 +63,8 @@ void GlobalShortcutListenerWin::OnWndProc(HWND hwnd,
|
|
|
|
modifiers |= (LOWORD(lparam) & MOD_SHIFT) ? ui::EF_SHIFT_DOWN : 0;
|
|
|
|
modifiers |= (LOWORD(lparam) & MOD_ALT) ? ui::EF_ALT_DOWN : 0;
|
|
|
|
modifiers |= (LOWORD(lparam) & MOD_CONTROL) ? ui::EF_CONTROL_DOWN : 0;
|
|
|
|
+ modifiers |= (LOWORD(lparam) & MOD_WIN) ? ui::EF_COMMAND_DOWN : 0;
|
|
|
|
+
|
|
|
|
ui::Accelerator accelerator(
|
|
|
|
ui::KeyboardCodeForWindowsKeyCode(key_code), modifiers);
|
|
|
|
|
|
|
|
@@ -77,6 +79,8 @@ bool GlobalShortcutListenerWin::RegisterAcceleratorImpl(
|
|
|
|
modifiers |= accelerator.IsShiftDown() ? MOD_SHIFT : 0;
|
|
|
|
modifiers |= accelerator.IsCtrlDown() ? MOD_CONTROL : 0;
|
|
|
|
modifiers |= accelerator.IsAltDown() ? MOD_ALT : 0;
|
|
|
|
+ modifiers |= accelerator.IsCmdDown() ? MOD_WIN : 0;
|
|
|
|
+
|
|
|
|
static int hotkey_id = 0;
|
|
|
|
bool success = !!RegisterHotKey(
|
|
|
|
gfx::SingletonHwnd::GetInstance()->hwnd(),
|
|
|
|
diff --git a/chrome/browser/extensions/global_shortcut_listener_x11.cc b/chrome/browser/extensions/global_shortcut_listener_x11.cc
|
2018-10-24 18:24:11 +00:00
|
|
|
index 362811063a426c27993563f236b0aa8b7034aa3f..fc407da7047b6d1b57db44eca65da6e1d743431f 100644
|
2018-10-11 05:02:58 +00:00
|
|
|
--- a/chrome/browser/extensions/global_shortcut_listener_x11.cc
|
|
|
|
+++ b/chrome/browser/extensions/global_shortcut_listener_x11.cc
|
|
|
|
@@ -38,6 +38,7 @@ int GetNativeModifiers(const ui::Accelerator& accelerator) {
|
|
|
|
modifiers |= accelerator.IsShiftDown() ? ShiftMask : 0;
|
|
|
|
modifiers |= accelerator.IsCtrlDown() ? ControlMask : 0;
|
|
|
|
modifiers |= accelerator.IsAltDown() ? Mod1Mask : 0;
|
|
|
|
+ modifiers |= accelerator.IsCmdDown() ? Mod4Mask : 0;
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
@@ -151,6 +152,8 @@ void GlobalShortcutListenerX11::OnXKeyPressEvent(::XEvent* x_event) {
|
|
|
|
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 & Mod1Mask) ? ui::EF_ALT_DOWN : 0;
|
|
|
|
+ // For Windows key
|
|
|
|
+ modifiers |= (x_event->xkey.state & Mod4Mask) ? ui::EF_COMMAND_DOWN: 0;
|
|
|
|
|
|
|
|
ui::Accelerator accelerator(
|
|
|
|
ui::KeyboardCodeFromXKeyEvent(x_event), modifiers);
|
|
|
|
diff --git a/ui/base/accelerators/media_keys_listener_mac.mm b/ui/base/accelerators/media_keys_listener_mac.mm
|
2018-10-24 18:24:11 +00:00
|
|
|
index cd595b0c017d6e36a5d94f7c99fe0a098a52b067..941c1a76a1c3ebe542aebcc9dc301d19bab47057 100644
|
2018-10-11 05:02:58 +00:00
|
|
|
--- a/ui/base/accelerators/media_keys_listener_mac.mm
|
|
|
|
+++ b/ui/base/accelerators/media_keys_listener_mac.mm
|
2018-10-24 23:25:48 +00:00
|
|
|
@@ -30,6 +30,12 @@
|
2018-10-11 05:02:58 +00:00
|
|
|
case NX_KEYTYPE_NEXT:
|
|
|
|
case NX_KEYTYPE_FAST:
|
|
|
|
return ui::VKEY_MEDIA_NEXT_TRACK;
|
|
|
|
+ case NX_KEYTYPE_SOUND_UP:
|
|
|
|
+ return ui::VKEY_VOLUME_UP;
|
|
|
|
+ case NX_KEYTYPE_SOUND_DOWN:
|
|
|
|
+ return ui::VKEY_VOLUME_DOWN;
|
|
|
|
+ case NX_KEYTYPE_MUTE:
|
|
|
|
+ return ui::VKEY_VOLUME_MUTE;
|
|
|
|
}
|
|
|
|
return ui::VKEY_UNKNOWN;
|
|
|
|
}
|
2018-10-24 23:25:48 +00:00
|
|
|
@@ -180,7 +186,10 @@ static CGEventRef EventTapCallback(CGEventTapProxy proxy,
|
2018-10-11 05:02:58 +00:00
|
|
|
int key_code = (data1 & 0xFFFF0000) >> 16;
|
|
|
|
if (key_code != NX_KEYTYPE_PLAY && key_code != NX_KEYTYPE_NEXT &&
|
|
|
|
key_code != NX_KEYTYPE_PREVIOUS && key_code != NX_KEYTYPE_FAST &&
|
|
|
|
- key_code != NX_KEYTYPE_REWIND) {
|
|
|
|
+ key_code != NX_KEYTYPE_REWIND &&
|
|
|
|
+ key_code != NX_KEYTYPE_SOUND_UP &&
|
|
|
|
+ key_code != NX_KEYTYPE_SOUND_DOWN &&
|
|
|
|
+ key_code != NX_KEYTYPE_MUTE) {
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|