int LuaUnsyncedRead::GetKeyBindings(lua_State* L) { const int args = lua_gettop(L); // number of arguments if ((args != 1) || !lua_isstring(L, 1)) { luaL_error(L, "Incorrect arguments to GetKeyBindings(\"keyset\")"); } const string keysetStr = lua_tostring(L, 1); CKeySet ks; if (!ks.Parse(keysetStr)) { return 0; } const CKeyBindings::ActionList& actions = keyBindings->GetActionList(ks); lua_newtable(L); for (int i = 0; i < (int)actions.size(); i++) { const Action& action = actions[i]; lua_pushnumber(L, i + 1); lua_newtable(L); lua_pushstring(L, action.command.c_str()); lua_pushstring(L, action.extra.c_str()); lua_rawset(L, -3); lua_rawset(L, -3); } lua_pushstring(L, "n"); lua_pushnumber(L, actions.size()); lua_rawset(L, -3); return 1; }
bool CKeyBindings::AddKeySymbol(const string& keysym, const string& code) { CKeySet ks; if (!ks.Parse(code)) { LOG_L(L_WARNING, "AddKeySymbol: could not parse key: %s", code.c_str()); return false; } if (!keyCodes->AddKeySymbol(keysym, ks.Key())) { LOG_L(L_WARNING, "AddKeySymbol: could not add: %s", keysym.c_str()); return false; } return true; }
bool CKeyBindings::AddKeySymbol(const string& keysym, const string& code) { CKeySet ks; if (!ks.Parse(code)) { logOutput.Print("AddKeySymbol: could not parse key: %s\n", code.c_str()); return false; } if (!keyCodes->AddKeySymbol(keysym, ks.Key())) { logOutput.Print("AddKeySymbol: could not add: %s\n", keysym.c_str()); return false; } return true; }
bool CKeyBindings::AddNamedKeySet(const string& name, const string& keystr) { CKeySet ks; if (!ks.Parse(keystr)) { printf("AddNamedKeySet: could not parse keyset: %s\n", keystr.c_str()); return false; } if ((ks.Key() < 0) || !CKeyCodes::IsValidLabel(name)) { printf("AddNamedKeySet: bad custom keyset name: %s\n", name.c_str()); return false; } namedKeySets[name] = ks; }
bool CKeyBindings::SetFakeMetaKey(const string& keystr) { CKeySet ks; if (StringToLower(keystr) == "none") { fakeMetaKey = -1; return true; } if (!ks.Parse(keystr)) { LOG_L(L_WARNING, "SetFakeMetaKey: could not parse key: %s", keystr.c_str()); return false; } fakeMetaKey = ks.Key(); return true; }
bool CKeyBindings::SetFakeMetaKey(const string& keystr) { CKeySet ks; if (StringToLower(keystr) == "none") { fakeMetaKey = -1; return true; } if (!ks.Parse(keystr)) { logOutput.Print("SetFakeMetaKey: could not parse key: %s\n", keystr.c_str()); return false; } fakeMetaKey = ks.Key(); return true; }
bool CKeyBindings::ParseKeySet(const string& keystr, CKeySet& ks) const { if (keystr[0] != NamedKeySetChar) { return ks.Parse(keystr); } else { const string keysetName = keystr.substr(1); NamedKeySetMap::const_iterator it = namedKeySets.find(keysetName); if (it != namedKeySets.end()) { ks = it->second; } else { return false; } } return true; }
bool CKeyBindings::UnBindKeyset(const std::string& keystr) { CKeySet ks; if (!ks.Parse(keystr)) { LOG_L(L_WARNING, "UnBindKeyset: could not parse key: %s", keystr.c_str()); return false; } bool success = false; KeyMap::iterator it = bindings.find(ks); if (it != bindings.end()) { bindings.erase(it); success = true; } return success; }
bool CKeyBindings::UnBind(const std::string& keystr, const std::string& command) { CKeySet ks; if (!ks.Parse(keystr)) { LOG_L(L_WARNING, "UnBind: could not parse key: %s", keystr.c_str()); return false; } bool success = false; KeyMap::iterator it = bindings.find(ks); if (it != bindings.end()) { ActionList& al = it->second; success = RemoveCommandFromList(al, command); if (al.empty()) { bindings.erase(it); } } return success; }
static bool ParseSingleChain(const std::string& keystr, CKeyChain* kc) { kc->clear(); CKeySet ks; // note: this will fail if keystr contains spaces std::stringstream ss(keystr); while (ss.good()) { char kcstr[256]; ss.getline(kcstr, 256, ','); std::string kstr(kcstr); if (!ks.Parse(kstr, false)) return false; kc->emplace_back(ks); } return true; }