plex-media-player
plex-media-player copied to clipboard
Investigate layout switching keyboard shortcuts
PMP 2.19.0 split apart fullscreen and window handling keyboard shortcuts. As of 2.21.0 the layout toggle key, host:toggleWebMode isn't toggling between Desktop and TV correctly.
The expected keyboard shortcuts can be seen in keyboard.json at d7dde160fef21428b0033dc46c9b538834bbc534.
Let's figure out why this isn't working.
Related: https://forums.plex.tv/t/no-hotkey-to-exit-tv-mode/330522
The plexmediaplayer.log just says:
[ WARN ] InputComponent.cpp @ 152 - No such host command: "toggleWebMode"
Investigating on macOS High Sierra and PMP 2.21.0, problems from the get go. InputComponent.cpp logging illustrates the problems.
First, in the TV layout, the Meta (Command) is being treated as Control and Control is being treated as Meta. My modifier keys are mapped to their default values.
A single press to Meta:
2018-11-14 09:32:51 [ DEBUG ] InputComponent.cpp @ 160 - Input received: source: "Keyboard" keycode: "Ctrl+0x17c0Q+0xdc21Q" : InputBase::InputkeyState(KeyDown)
2018-11-14 09:32:51 [ DEBUG ] CachedRegexMatcher.cpp @ 68 - No match for: "Ctrl+0x17c0Q+0xdc21Q"
2018-11-14 09:32:51 [ DEBUG ] InputComponent.cpp @ 160 - Input received: source: "Keyboard" keycode: "0x17c0Q+0xdc21Q" : InputBase::InputkeyState(KeyUp)
A single press to Control
2018-11-14 09:33:46 [ DEBUG ] InputComponent.cpp @ 160 - Input received: source: "Keyboard" keycode: "Meta+0x17c0Q+0xdc22Q" : InputBase::InputkeyState(KeyDown)
2018-11-14 09:33:46 [ DEBUG ] CachedRegexMatcher.cpp @ 68 - No match for: "Meta+0x17c0Q+0xdc22Q"
2018-11-14 09:33:46 [ DEBUG ] InputComponent.cpp @ 160 - Input received: source: "Keyboard" keycode: "0x17c0Q+0xdc22Q" : InputBase::InputkeyState(KeyUp)
The mis-mapped keys are coming directly from InputKeyboard.h.
Next, in the Desktop layout, presses to the same keys show no logging. It appears that EventFilter.cpp is intentionally applying a constrained set of keys to Desktop:
https://github.com/plexinc/plex-media-player/blob/4839cbf2c610c6b77656ba40a41bc6754c871ba8/src/ui/EventFilter.cpp#L57-L67
The mis-mapped modifier keys are coming directly from Qt. Eg, logging modifiers.toString() in the below code block logs Ctrl+ when I push the Meta key:
https://github.com/plexinc/plex-media-player/blob/4839cbf2c610c6b77656ba40a41bc6754c871ba8/src/ui/EventFilter.cpp#L26-L29
The modifier key swapping is another Qt bug: https://bugreports.qt.io/browse/QTBUG-51293. Qt is so backwards; swapping Ctrl and Meta isn't logical default behavior.
Introduced in 5.5.1 and resolved in 5.11.0; we're still on 5.9.5. Indeed, the following code, added to main.cpp is ineffectual against the bug:
#ifdef Q_OS_MAC
app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
#endif
Okay, I've worked around the problems above in this branch: https://github.com/plexinc/plex-media-player/commits/mseeley/799-shortcuts.
Changes:
- Manually remap Control and Meta presses on MacOS. I built the remapping to only operate on MacOS+Qt 5.9.5; idea being when we upgrade the remapping will be ignored.
- Various fixups to correctly wire
host:fullscreenandhost:toggleWebMode. - Desktop mode now receives all of the same keyboard filtering and events as TV mode. This allows the host to acknowledge the
host:fullscreenandhost:toggleWebMode. Although all key events are allowed not all events have handlers in Desktop. For example, the volume changing key only works in TV mode; not Desktop.
~Otto mentions the nightly is still triggering this error on Windows. 709f70ab registers the toggleWebMode command in a way that's working for me on MacOS. I'll come back to this in a couple days and test on Windows.~
Correction: I provided Otto the wrong build for verification.