Skip to content

Commit 9c87028

Browse files
committed
Allow "Super" as a hotkey modifier
1 parent 68e0d5b commit 9c87028

7 files changed

Lines changed: 15 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# linux backup files
22
*~
3-
3+
.cache
44
# Kdevelop project files
55
*.kdev4
66
.kdev4

docs/builtins/keybinding.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Like any other command, it can be used at any time from the console, but
99
bindings are not remembered between runs of the game unless re-created in
1010
:file:`dfhack-config/init/dfhack.init`.
1111

12-
Hotkeys can be any combinations of Ctrl/Alt/Shift with any key recognized by SDL.
12+
Hotkeys can be any combinations of Ctrl/Alt/Super/Shift with any key recognized by SDL.
1313
You can also represent mouse buttons beyond the first three with ``MOUSE4``
1414
through ``MOUSE15``.
1515

@@ -29,7 +29,7 @@ Usage
2929

3030
The ``<key>`` parameter above has the following case-insensitive syntax::
3131

32-
[Ctrl-][Alt-][Shift-]KEY[@context[|context...]]
32+
[Ctrl-][Alt-][Super-][Shift-]KEY[@context[|context...]]
3333

3434
where the ``KEY`` part can be any recognized key and :kbd:`[`:kbd:`]` denote
3535
optional parts.

docs/dev/Lua API.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,7 @@ and are only documented here for completeness:
35353535
* ``dfhack.internal.getModifiers()``
35363536

35373537
Returns the state of the keyboard modifier keys in a table of string ->
3538-
boolean. The keys are ``ctrl``, ``shift``, and ``alt``.
3538+
boolean. The keys are ``ctrl``, ``shift``, ``super``, and ``alt``.
35393539

35403540
* ``dfhack.internal.getSuppressDuplicateKeyboardEvents()``
35413541
* ``dfhack.internal.setSuppressDuplicateKeyboardEvents(suppress)``

library/Core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,8 @@ bool Core::doSdlInputEvent(SDL_Event* ev)
24392439
modstate = (ev->type == SDL_KEYDOWN) ? modstate | DFH_MOD_CTRL : modstate & ~DFH_MOD_CTRL;
24402440
else if (sym == SDLK_LALT || sym == SDLK_RALT)
24412441
modstate = (ev->type == SDL_KEYDOWN) ? modstate | DFH_MOD_ALT : modstate & ~DFH_MOD_ALT;
2442+
else if (sym == SDLK_LGUI || sym == SDLK_RGUI) // Renamed to LMETA/RMETA in SDL3
2443+
modstate = (ev->type == SDL_KEYDOWN) ? modstate | DFH_MOD_SUPER : modstate & ~DFH_MOD_SUPER;
24422444
else if (ke.state == SDL_PRESSED && !hotkey_states[sym])
24432445
{
24442446
// the check against hotkey_states[sym] ensures we only process keybindings once per keypress

library/LuaApi.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,6 +4073,9 @@ static int internal_getModifiers(lua_State *L)
40734073
lua_pushstring(L, "alt");
40744074
lua_pushboolean(L, modstate & DFH_MOD_ALT);
40754075
lua_settable(L, -3);
4076+
lua_pushstring(L, "super");
4077+
lua_pushboolean(L, modstate & DFH_MOD_SUPER);
4078+
lua_settable(L, -3);
40764079
return 1;
40774080
}
40784081

library/include/Core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace DFHack
5858
constexpr auto DFH_MOD_SHIFT = 1;
5959
constexpr auto DFH_MOD_CTRL = 2;
6060
constexpr auto DFH_MOD_ALT = 4;
61+
constexpr auto DFH_MOD_SUPER = 8;
6162

6263
class Process;
6364
class Module;

library/modules/Hotkey.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ std::string Hotkey::keyspec_to_string(const KeySpec &spec, bool include_focus) {
4242
std::string sym;
4343
if (spec.modifiers & DFH_MOD_CTRL) sym += "Ctrl-";
4444
if (spec.modifiers & DFH_MOD_ALT) sym += "Alt-";
45+
if (spec.modifiers & DFH_MOD_SUPER) sym += "Super-";
4546
if (spec.modifiers & DFH_MOD_SHIFT) sym += "Shift-";
4647

4748
std::string key_name;
@@ -91,7 +92,10 @@ std::optional<KeySpec> Hotkey::parseKeySpec(std::string spec, std::string* err)
9192
}
9293
return found;
9394
};
94-
while (match_modifier("shift-", DFH_MOD_SHIFT) || match_modifier("ctrl-", DFH_MOD_CTRL) || match_modifier("alt-", DFH_MOD_ALT)) {}
95+
while (match_modifier("shift-", DFH_MOD_SHIFT)
96+
|| match_modifier("ctrl-", DFH_MOD_CTRL)
97+
|| match_modifier("alt-", DFH_MOD_ALT)
98+
|| match_modifier("super-", DFH_MOD_SUPER)) {}
9599

96100
out.sym = DFSDL::DFSDL_GetKeyFromName(spec.c_str());
97101
if (out.sym != SDLK_UNKNOWN)

0 commit comments

Comments
 (0)