-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Allow closing sub download OSD using escape #4996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow closing sub download OSD using escape #4996
Conversation
When escape is pressed, if a persistent OSD is being shown (non-interruptible, and without a scheduled hide), the window now gives the OSD view the opportunity to handle the event.
Looks like a good idea to me, but it needs some changes to the implementation. I would keep the changes you made to override func keyDown(with event: NSEvent) {
if isShowingPersistentOSD {
let keyCode = KeyCodeHelper.mpvKeyCode(from: event)
let normalizedKeyCode = KeyCodeHelper.normalizeMpv(keyCode)
if normalizedKeyCode == "ESC", osdStackView.performKeyEquivalent(with: event) {
Logger.log("ESC key was handled by OSD", level: .verbose)
return
}
}
super.keyDown(with: event)
} Rationale:
|
Rationale by svobs: 1. You need to add code in keyDown instead of handleKeyBinding, because that will only get called if there is a key binding for ESC in the Settings > Key Bindings table. (And that binding would have to be for a different action because there is no support for any kind of "dismiss OSD" action there.) 2. Check for isShowingPersistentOSD first because it's the fastest check and will require less CPU when it is false (which is most of the time). 3. No need to check hideOSDTimer now. The function osdStackView.performKeyEquivalent will return true only if it recognized the event and accepted it. Other OSDs such as "screenshot taken" do not recognize ESC and will return false, so those will fall through and call super.keyDown which will allow the key to be processed normally.
Thank you for the feedback! These are good points—I've updated the PR with exactly the code you suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I think keyUp
is a better place for key shortcuts. keyDown
can be called repeatedly if the key is long-pressed, while keyUp
is only fired once and represents the action better. Could you change it?
I don't think so. Changing it to |
I'd agree with staying on |
Sounds reasonable, you are right. @Cykelero thanks for your contribution! |
Currently, it's impossible to dismiss the “online subtitle download” OSD using the keyboard. This PR allows using escape to do just that.
MainWindowController
gives the OSD view the opportunity to handle the event.keyBinding.normalizedMpvKey == "ESC"
condition might be safely removed, allowing OSD VCs to opt into handling any event; but I'm not confident enough that it won't disrupt anything.Specifically, the forwarding is made necessary by the
MainWindow.keyDown()
override, which I don't fully understand.hideOSDTimer
in addition toisShowingPersistentOSD
, as this boolean is sometimes true even for auto-dismissed OSDs (i.e. the “screenshot taken” OSD)