Skip to content
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

Disable hotkeys on static QFileDialog calls #10155

Merged
merged 1 commit into from Oct 12, 2021

Conversation

malleoz
Copy link
Contributor

@malleoz malleoz commented Oct 8, 2021

Previously, if you had "Hotkeys Require Window Focus" disabled, you could repeatedly use the "Open" hotkey, for example, to stack File Open windows over top of each other over and over.

This PR just adds a wrapper function to toggle hotkeys for QFileDialogs. Thank you to lioncache for the approach.

@malleoz malleoz force-pushed the toggle-hotkeys-on-qfiledialog branch 3 times, most recently from cfe3986 to 9593de3 Compare October 8, 2021 03:05
@lioncash
Copy link
Member

lioncash commented Oct 8, 2021

I think you may want to create wrapper functions for using the QFileDialog functions, e.g.

// Feel free to put all of this behind a descriptive namespace.

class HotkeyDisabler final
{
public:
  HotkeyDisabler() { HotkeyManagerEmu::Enable(false); }
  ~HotkeyDisabler() { HotkeyManagerEmu::Enable(true); }
};

QString GetExistingDirectory(QWidget *parent = nullptr, const QString& caption = {},
                             const QString& dir = {}, QFileDialog::Options options = QFileDialog::ShowDirsOnly)
{
  const HotkeyDisabler disabler;
  return QFileDialog::getExistingDirectory(parent, caption, dir, options);
}

// ... etc for other relevant functions.

and then using those wrappers over the direct QFileDialog ones.

Pasting the enable and disable calls around every single call individually is both super fragile and error-prone (and not to mention pretty ugly), so reducing the need to do that as much as possible would be nice.

@malleoz
Copy link
Contributor Author

malleoz commented Oct 8, 2021

This is the approach I was hoping for, I wasn't able to conceptualize how to do it. I'll mark this as a draft while I take time to implement your suggestion between travelling this weekend. Thanks!

@malleoz malleoz marked this pull request as draft October 8, 2021 16:24
@malleoz malleoz force-pushed the toggle-hotkeys-on-qfiledialog branch 3 times, most recently from c46a16b to 839b040 Compare October 10, 2021 02:43
Previously, if you have "Hotkeys Require Window Focus" disabled, you could repeatedly use the "Open" hotkey, for example, to stack File Open windows over top of each other over and over.

This commit allows the hotkey manager to disable/enable on QFileDialog creation and destruction.
@malleoz
Copy link
Contributor Author

malleoz commented Oct 10, 2021

Hopefully this was done in a proper way. Works on my end perfectly!

@malleoz malleoz marked this pull request as ready for review October 10, 2021 02:48
Copy link
Member

@leoetlino leoetlino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sane, though I cannot reproduce the Open hotkey issue on Linux.

Reviewed 16 of 16 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @malleoz)

@leoetlino leoetlino merged commit 0315fcf into dolphin-emu:master Oct 12, 2021
10 checks passed
@malleoz malleoz deleted the toggle-hotkeys-on-qfiledialog branch October 13, 2021 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants