Merge pull request #3584 from myk002/myk_key_dedup_corify

move SUPPRESS_DUPLICATE_KEYBOARD_EVENTS pref into cpp
develop
Myk 2023-07-19 08:14:41 -07:00 committed by GitHub
commit 65daf56865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 20 deletions

@ -394,9 +394,6 @@ restarting DF.
- ``dfhack.HIDE_ARMOK_TOOLS``: Whether to hide "armok" tools in command lists.
- ``dfhack.SUPPRESS_DUPLICATE_KEYBOARD_EVENTS``: Whether to prevent DFHack
keybindings from producing DF key events.
Miscellaneous notes
===================
This section is for odd but important notes that don't fit anywhere else.

@ -2857,6 +2857,12 @@ and are only documented here for completeness:
Sets the system clipboard text from a CP437 string.
* ``dfhack.internal.getSuppressDuplicateKeyboardEvents()``
* ``dfhack.internal.setSuppressDuplicateKeyboardEvents(suppress)``
Gets and sets the flag for whether to suppress DF key events when a DFHack
keybinding is matched and a command is launched.
.. _lua-core-context:
Core interpreter context

@ -1423,6 +1423,7 @@ Core::Core() :
memset(&(s_mods), 0, sizeof(s_mods));
// set up hotkey capture
suppress_duplicate_keyboard_events = true;
hotkey_set = NO;
last_world_data_ptr = NULL;
last_local_map_ptr = NULL;
@ -1430,7 +1431,6 @@ Core::Core() :
top_viewscreen = NULL;
color_ostream::log_errors_to_stderr = true;
};
void Core::fatal (std::string output)
@ -2356,12 +2356,14 @@ bool Core::DFH_ncurses_key(int key)
return ncurses_wgetch(key, dummy);
}
static bool getSuppressDuplicateKeyboardEvents() {
auto L = Lua::Core::State;
color_ostream_proxy out(Core::getInstance().getConsole());
Lua::StackUnwinder top(L);
return DFHack::Lua::PushModulePublic(out, L, "dfhack", "SUPPRESS_DUPLICATE_KEYBOARD_EVENTS") &&
lua_toboolean(L, -1);
bool Core::getSuppressDuplicateKeyboardEvents() {
return suppress_duplicate_keyboard_events;
}
void Core::setSuppressDuplicateKeyboardEvents(bool suppress) {
DEBUG(keybinding).print("setting suppress_duplicate_keyboard_events to %s\n",
suppress ? "true" : "false");
suppress_duplicate_keyboard_events = suppress;
}
// returns true if the event is handled
@ -2396,9 +2398,10 @@ bool Core::DFH_SDL_Event(SDL_Event* ev)
DEBUG(keybinding).print("key down: sym=%d (%c)\n", sym, sym);
bool handled = SelectHotkey(sym, modstate);
if (handled) {
DEBUG(keybinding).print("inhibiting SDL key down event\n");
DEBUG(keybinding).print("%sinhibiting SDL key down event\n",
suppress_duplicate_keyboard_events ? "" : "not ");
hotkey_states[sym] = true;
return getSuppressDuplicateKeyboardEvents();
return suppress_duplicate_keyboard_events;
}
}
else if (ke.state == SDL_RELEASED)
@ -2411,8 +2414,9 @@ bool Core::DFH_SDL_Event(SDL_Event* ev)
auto &te = ev->text;
DEBUG(keybinding).print("text input: '%s'\n", te.text);
if (strlen(te.text) == 1 && hotkey_states[te.text[0]]) {
DEBUG(keybinding).print("inhibiting SDL text event\n");
return true;
DEBUG(keybinding).print("%sinhibiting SDL text event\n",
suppress_duplicate_keyboard_events ? "" : "not ");
return suppress_duplicate_keyboard_events;
}
}

@ -3611,13 +3611,23 @@ static int internal_md5file(lua_State *L)
}
}
static int internal_getSuppressDuplicateKeyboardEvents(lua_State *L) {
Lua::Push(L, Core::getInstance().getSuppressDuplicateKeyboardEvents());
return 1;
}
static int internal_setSuppressDuplicateKeyboardEvents(lua_State *L) {
bool suppress = lua_toboolean(L, 1);
Core::getInstance().setSuppressDuplicateKeyboardEvents(suppress);
return 0;
}
static const luaL_Reg dfhack_internal_funcs[] = {
{ "getPE", internal_getPE },
{ "getMD5", internal_getmd5 },
{ "getAddress", internal_getAddress },
{ "setAddress", internal_setAddress },
{ "getVTable", internal_getVTable },
{ "adjustOffset", internal_adjustOffset },
{ "getMemRanges", internal_getMemRanges },
{ "patchMemory", internal_patchMemory },
@ -3639,6 +3649,8 @@ static const luaL_Reg dfhack_internal_funcs[] = {
{ "getCommandDescription", internal_getCommandDescription },
{ "threadid", internal_threadid },
{ "md5File", internal_md5file },
{ "getSuppressDuplicateKeyboardEvents", internal_getSuppressDuplicateKeyboardEvents },
{ "setSuppressDuplicateKeyboardEvents", internal_setSuppressDuplicateKeyboardEvents },
{ NULL, NULL }
};

@ -159,6 +159,9 @@ namespace DFHack
std::string findScript(std::string name);
void getScriptPaths(std::vector<std::string> *dest);
bool getSuppressDuplicateKeyboardEvents();
void setSuppressDuplicateKeyboardEvents(bool suppress);
bool ClearKeyBindings(std::string keyspec);
bool AddKeyBinding(std::string keyspec, std::string cmdline);
std::vector<std::string> ListKeyBindings(std::string keyspec);
@ -249,6 +252,7 @@ namespace DFHack
};
int8_t modstate;
bool suppress_duplicate_keyboard_events;
std::map<int, std::vector<KeyBinding> > key_bindings;
std::string hotkey_cmd;
enum hotkey_set_t {

@ -63,11 +63,6 @@ function dfhack.getHideArmokTools()
return dfhack.HIDE_ARMOK_TOOLS
end
dfhack.SUPPRESS_DUPLICATE_KEYBOARD_EVENTS = true
function dfhack.getSuppressDuplicateKeyboardEvents()
return dfhack.SUPPRESS_DUPLICATE_KEYBOARD_EVENTS
end
-- Error handling
safecall = dfhack.safecall