mirror-chatterino2/src/controllers/hotkeys
SputNikPlop 7079729591
fix: change viewer list to chatter list (#4732)
* fix: change viewer list to chatter list

* fix: enter changelog entry
2023-07-29 10:47:24 +00:00
..
ActionNames.hpp fix: change viewer list to chatter list (#4732) 2023-07-29 10:47:24 +00:00
Hotkey.cpp Add custom hotkeys. (#2340) 2021-11-21 17:46:21 +00:00
Hotkey.hpp Add missing vector header (#3724) 2022-05-11 22:36:57 +00:00
HotkeyCategory.hpp Add custom hotkeys. (#2340) 2021-11-21 17:46:21 +00:00
HotkeyController.cpp Add setting to only show tabs with live channels (#4358) 2023-06-11 11:34:28 +02:00
HotkeyController.hpp Make menus and placeholders display appropriate custom key combos. (#4045) 2022-10-09 17:20:44 +02:00
HotkeyHelpers.cpp Improve editing of hotkeys (#4628) 2023-05-27 14:04:30 +00:00
HotkeyHelpers.hpp Improve editing of hotkeys (#4628) 2023-05-27 14:04:30 +00:00
HotkeyModel.cpp Remove Unnecessary Includes in Headers (#4275) 2022-12-31 14:41:01 +00:00
HotkeyModel.hpp Remove Unnecessary Includes in Headers (#4275) 2022-12-31 14:41:01 +00:00
README.md Add custom hotkeys. (#2340) 2021-11-21 17:46:21 +00:00

Custom Hotkeys

Table of Contents

Glossary

Word Meaning
Shortcut QShortcut object created from a hotkey.
Hotkey Template for creating shortcuts in the right categories. See Hotkey object.
Category Place where hotkeys' actions are executed.
Action Code that makes a hotkey do something.
Keybinding or key combo The keys you press on the keyboard to do something.

Adding new hotkeys

Adding new hotkeys to a widget that already has hotkeys is quite easy.

Add an action

  1. Locate the call to getApp()->hotkeys->shortcutsForCategory(...), it is located in the addShortcuts() method
  2. Above that should be a HotkeyController::HotkeyMap named actions
  3. Add your new action inside that map, it should return a non-empty QString only when configuration errors are found.
  4. Go to ActionNames.hpp and add a definition for your hotkey with a nice user-friendly name. Be sure to double-check the argument count.

Add a default

Defaults are stored in HotkeyController.cpp in the resetToDefaults() method. To add a default just add a call to tryAddDefault in the appropriate section. Make sure that the name you gave the hotkey is unique.

void HotkeyController::tryAddDefault(std::set<QString> &addedHotkeys,
                                     HotkeyCategory category,
                                     QKeySequence keySequence, QString action,
                                     std::vector<QString> args, QString name)
  • where action is the action you added before,
  • category — same category that is in the shortcutsForCategory call
  • nameunique name of the default hotkey
  • keySequence - key combo for the hotkey

Adding new hotkey categories

If you want to add hotkeys to new widget that doesn't already have them it's a bit more work.

Add the HotkeyCategory value

Add a value for the HotkeyCategory enum in HotkeyCategory.hpp. If you widget is a popup, it's best to use the existing PopupWindow category.

Add a nice name for the category

Add a string name and display name for the category in HotkeyController.hpp to hotkeyCategoryNames and hotkeyCategoryDisplayNames.

Add a shortcut context

To make sure shortcuts created from your hotkeys are only executed in the right places, you need to add a shortcut context for Qt. This is done in Hotkey.cpp in Hotkey::getContext(). See the ShortcutContext enum docs for possible values

Override addShortcuts

If the widget you're adding Hotkeys is a BaseWidget or a BaseWindow. You can override the addShortcuts() method. You should also add a call to it in the constructor. Here is some template/example code:

void YourWidget::addShortcuts()
{
    HotkeyController::HotkeyMap actions{
        {"barrelRoll", // replace this with your action code
         [this](std::vector<QString> arguments) -> QString {
             // DO A BARREL ROLL
             return ""; // only return text if there is a configuration error.
         }},
    };
    this->shortcuts_ = getApp()->hotkeys->shortcutsForCategory(HotkeyCategory::PopupWindow /* or your category name */,
                                                            actions, this);
}

Renaming defaults

Renaming defaults is currently not possible. If you were to rename one, it would get recreated for everyone probably leading to broken shortcuts, don't do this until a proper mechanism has been made.