bool KwmParseHotkey(std::string KeySym, std::string Command, hotkey *Hotkey) { std::vector<std::string> KeyTokens = SplitString(KeySym, '-'); if(KeyTokens.size() != 2) return false; std::vector<std::string> Modifiers = SplitString(KeyTokens[0], '+'); for(std::size_t ModIndex = 0; ModIndex < Modifiers.size(); ++ModIndex) { if(Modifiers[ModIndex] == "cmd") Hotkey->Mod.CmdKey = true; else if(Modifiers[ModIndex] == "alt") Hotkey->Mod.AltKey = true; else if(Modifiers[ModIndex] == "ctrl") Hotkey->Mod.CtrlKey = true; else if(Modifiers[ModIndex] == "shift") Hotkey->Mod.ShiftKey = true; else if(Modifiers[ModIndex] == "prefix") Hotkey->Prefixed = true; } DetermineHotkeyState(Hotkey, Command); Hotkey->IsSystemCommand = IsPrefixOfString(Command, "sys"); Hotkey->Command = Command; CGKeyCode Keycode; bool Result = GetLayoutIndependentKeycode(KeyTokens[1], &Keycode); if(!Result) Result = KeycodeForChar(KeyTokens[1][0], &Keycode); Hotkey->Key = Keycode; return Result; }
internal void KwmExecuteHotkey(hotkey *Hotkey) { if(Hotkey->Command.empty()) return; std::vector<std::string> Commands = SplitString(Hotkey->Command, ';'); DEBUG("KwmExecuteHotkey: Number of commands " << Commands.size()); for(int CmdIndex = 0; CmdIndex < Commands.size(); ++CmdIndex) { std::string &Command = TrimString(Commands[CmdIndex]); if(!Command.empty()) { DEBUG("KwmExecuteHotkey() " << Command); if(IsPrefixOfString(Command, "exec")) KwmExecuteThreadedSystemCommand(Command); else KwmInterpretCommand(Command, 0); if(KWMHotkeys.ActiveMode->Prefix) KWMHotkeys.ActiveMode->Time = std::chrono::steady_clock::now(); } } }