20std::string _hotkeys_file;
30 const std::string_view
name;
42 {
"BACKSPACE", WKC_BACKSPACE},
45 {
"PAGEUP", WKC_PAGEUP},
46 {
"PAGEDOWN", WKC_PAGEDOWN},
49 {
"RETURN", WKC_RETURN},
63 {
"BACKQUOTE", WKC_BACKQUOTE},
65 {
"NUM_DIV", WKC_NUM_DIV},
66 {
"NUM_MUL", WKC_NUM_MUL},
67 {
"NUM_MINUS", WKC_NUM_MINUS},
68 {
"NUM_PLUS", WKC_NUM_PLUS},
69 {
"NUM_ENTER", WKC_NUM_ENTER},
70 {
"NUM_DOT", WKC_NUM_DECIMAL},
97static std::optional<uint16_t>
ParseCode(std::string_view keystr)
105 if (keystr.size() == 1) {
107 if (c >=
'a' && c <=
'z')
return c - (
'a'-
'A');
109 if (
static_cast<uint8_t
>(c) < 128)
return c;
97static std::optional<uint16_t>
ParseCode(std::string_view keystr) {
…}
121 if (keystr.empty())
return std::nullopt;
123 uint16_t keycode = 0;
124 while (consumer.AnyBytesLeft()) {
127 if (!code.has_value())
return std::nullopt;
128 if (*code & WKC_SPECIAL_KEYS) {
130 if (*code & ~WKC_SPECIAL_KEYS)
return std::nullopt;
134 if (keycode & ~WKC_SPECIAL_KEYS)
return std::nullopt;
149 while (consumer.AnyBytesLeft()) {
152 if (keycode.has_value()) hotkey.
AddKeycode(*keycode);
169 if (keycode & WKC_SHIFT) {
170 if (!str.empty()) str +=
"+";
173 if (keycode & WKC_CTRL) {
174 if (!str.empty()) str +=
"+";
177 if (keycode & WKC_ALT) {
178 if (!str.empty()) str +=
"+";
181 if (keycode & WKC_META) {
182 if (!str.empty()) str +=
"+";
185 if (!str.empty()) str +=
"+";
186 keycode = keycode & ~WKC_SPECIAL_KEYS;
189 if (kn.keycode == keycode) {
194 assert(keycode < 128);
195 str.push_back(keycode);
208 for (
auto keycode : hotkey.keycodes) {
209 if (!str.empty()) str +=
",";
225 if (default_keycode != 0) this->
AddKeycode(default_keycode);
234Hotkey::Hotkey(
const std::vector<uint16_t> &default_keycodes,
const std::string &name,
int num) :
238 for (uint16_t keycode : default_keycodes) {
234Hotkey::Hotkey(
const std::vector<uint16_t> &default_keycodes,
const std::string &name,
int num) : {
…}
250 this->keycodes.insert(keycode);
253HotkeyList::HotkeyList(
const std::string &ini_group,
const std::vector<Hotkey> &items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
254 global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
260HotkeyList::~HotkeyList()
272 if (group ==
nullptr)
return;
273 for (
Hotkey &hotkey : this->items) {
275 if (item !=
nullptr) {
276 hotkey.keycodes.clear();
289 for (
const Hotkey &hotkey : this->items) {
303 for (
const Hotkey &hotkey : this->items) {
304 auto begin = hotkey.keycodes.begin();
305 auto end = hotkey.keycodes.end();
306 if (std::find(begin, end, keycode |
WKC_GLOBAL_HOTKEY) != end || (!global_only && std::find(begin, end, keycode) != end)) {
314static void SaveLoadHotkeys(
bool save)
327 if (save) ini.SaveToDisk(_hotkeys_file);
334 SaveLoadHotkeys(
false);
340 SaveLoadHotkeys(
true);
343void HandleGlobalHotkeys([[maybe_unused]]
char32_t key, uint16_t keycode)
346 if (list->global_hotkey_handler ==
nullptr)
continue;
348 int hotkey = list->CheckMatch(keycode,
true);
349 if (hotkey >= 0 && (list->global_hotkey_handler(hotkey) ==
ES_HANDLED))
return;
Parse data from a string / buffer.
std::string_view ReadUntilChar(char c, SeparatorUsage sep)
Read data until the first occurrence of 8-bit char 'c', and advance reader.
@ SKIP_ONE_SEPARATOR
Read and discard one separator, do not include it in the result.
static const std::string_view WHITESPACE_NO_NEWLINE
ASCII whitespace characters, excluding new-line.
@ NO_DIRECTORY
A path without any base directory.
@ WKC_BACKSLASH
\ Backslash
@ WKC_SLASH
/ Forward slash
@ WKC_SINGLEQUOTE
' Single quote
@ WKC_R_BRACKET
] Right square bracket
@ WKC_L_BRACKET
[ Left square bracket
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
@ WKC_SEMICOLON
; Semicolon
static std::vector< HotkeyList * > * _hotkey_lists
List of all HotkeyLists.
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
static std::optional< uint16_t > ParseCode(std::string_view keystr)
Try to parse a single part of a keycode.
static void ParseHotkeys(Hotkey &hotkey, std::string_view value)
Parse a string to the keycodes it represents.
std::string SaveKeycodes(const Hotkey &hotkey)
Convert all keycodes attached to a hotkey to a single string.
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
static std::optional< uint16_t > ParseKeycode(std::string_view keystr)
Parse a string representation of a keycode.
static std::string KeycodeToString(uint16_t keycode)
Convert a hotkey to it's string representation so it can be written to the config file.
static const std::initializer_list< KeycodeNames > _keycode_to_name
Array of non-standard keycodes that can be used in the hotkeys config file.
Hotkey related functions.
Types related to reading/writing '*.ini' files.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
bool StrEqualsIgnoreCase(std::string_view str1, std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
Functions related to low-level strings.
List of hotkeys for a window.
void Save(IniFile &ini) const
Save HotkeyList to IniFile.
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
void Load(const IniFile &ini)
Load HotkeyList from IniFile.
All data for a single hotkey.
Hotkey(uint16_t default_keycode, const std::string &name, int num)
Create a new Hotkey object with a single default keycode.
void AddKeycode(uint16_t keycode)
Add a keycode to this hotkey, from now that keycode will be matched in addition to any previously add...
Ini file that supports both loading and saving.
A group within an ini file.
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
IniItem & GetOrCreateItem(std::string_view name)
Get the item with the given name, and if it doesn't exist create a new item.
A single "line" in an ini file.
std::optional< std::string > value
The value of this item.
void SetValue(std::string_view value)
Replace the current value with another value.
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
void LoadFromDisk(std::string_view filename, Subdirectory subdir)
Load the Ini file's data from the disk.
IniGroup & GetOrCreateGroup(std::string_view name)
Get the group with the given name, and if it doesn't exist create a new group.
String representation of a keycode.
WindowKeyCodes keycode
The keycode.
const std::string_view name
Name of the keycode.
Functions, definitions and such used only by the GUI.
@ ES_HANDLED
The passed event is handled.