2011-09-13 17:50:18 +03:00
|
|
|
#include "keymapper.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "lua.hpp"
|
2011-09-17 09:55:35 +03:00
|
|
|
#include "window.hpp"
|
2011-09-13 17:50:18 +03:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include "misc.hpp"
|
|
|
|
#include "memorymanip.hpp"
|
2011-09-14 20:06:36 +03:00
|
|
|
#include "command.hpp"
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2011-09-17 11:29:10 +03:00
|
|
|
function_ptr_command bind_key("bind-key", "Bind a (pseudo-)key",
|
|
|
|
"Syntax: bind-key [<mod>/<modmask>] <key> <command>\nBind command to specified key (with specified "
|
|
|
|
" modifiers)\n",
|
|
|
|
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
2011-09-14 20:06:36 +03:00
|
|
|
std::string mod, modmask, keyname, command;
|
|
|
|
tokensplitter t(args);
|
|
|
|
std::string mod_or_key = t;
|
|
|
|
if(mod_or_key.find_first_of("/") < mod_or_key.length()) {
|
|
|
|
//Mod field.
|
|
|
|
size_t split = mod_or_key.find_first_of("/");
|
|
|
|
mod = mod_or_key.substr(0, split);
|
|
|
|
modmask = mod_or_key.substr(split + 1);
|
|
|
|
mod_or_key = static_cast<std::string>(t);
|
|
|
|
}
|
|
|
|
if(mod_or_key == "")
|
|
|
|
throw std::runtime_error("Expected optional modifiers and key");
|
|
|
|
keyname = mod_or_key;
|
|
|
|
command = t.tail();
|
|
|
|
if(command == "")
|
|
|
|
throw std::runtime_error("Expected command");
|
2011-09-17 01:05:41 +03:00
|
|
|
window::bind(mod, modmask, keyname, command);
|
2011-09-17 11:29:10 +03:00
|
|
|
});
|
2011-09-13 17:50:18 +03:00
|
|
|
|
2011-09-17 11:29:10 +03:00
|
|
|
function_ptr_command unbind_key("unbind-key", "Unbind a (pseudo-)key",
|
|
|
|
"Syntax: unbind-key [<mod>/<modmask>] <key>\nUnbind specified key (with specified modifiers)\n",
|
|
|
|
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
2011-09-14 20:06:36 +03:00
|
|
|
std::string mod, modmask, keyname, command;
|
|
|
|
tokensplitter t(args);
|
|
|
|
std::string mod_or_key = t;
|
|
|
|
if(mod_or_key.find_first_of("/") < mod_or_key.length()) {
|
|
|
|
//Mod field.
|
|
|
|
size_t split = mod_or_key.find_first_of("/");
|
|
|
|
mod = mod_or_key.substr(0, split);
|
|
|
|
modmask = mod_or_key.substr(split + 1);
|
|
|
|
mod_or_key = static_cast<std::string>(t);
|
|
|
|
}
|
|
|
|
if(mod_or_key == "")
|
|
|
|
throw std::runtime_error("Expected optional modifiers and key");
|
|
|
|
keyname = mod_or_key;
|
|
|
|
command = t.tail();
|
|
|
|
if(command != "")
|
|
|
|
throw std::runtime_error("Unexpected argument");
|
2011-09-17 01:05:41 +03:00
|
|
|
window::unbind(mod, modmask, keyname);
|
2011-09-17 11:29:10 +03:00
|
|
|
});
|
2011-09-14 20:06:36 +03:00
|
|
|
|
2011-09-17 11:29:10 +03:00
|
|
|
function_ptr_command show_bindings("show-bindings", "Show active bindings",
|
|
|
|
"Syntax: show-bindings\nShow bindings that are currently active.\n",
|
|
|
|
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
2011-09-14 20:06:36 +03:00
|
|
|
if(args != "")
|
|
|
|
throw std::runtime_error("This command does not take parameters");
|
2011-09-17 01:05:41 +03:00
|
|
|
window::dumpbindings();
|
2011-09-17 11:29:10 +03:00
|
|
|
});
|
2011-09-13 17:50:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string fixup_command_polarity(std::string cmd, bool polarity) throw(std::bad_alloc)
|
|
|
|
{
|
|
|
|
if(cmd == "")
|
|
|
|
return "";
|
|
|
|
if(cmd[0] != '+' && polarity)
|
|
|
|
return "";
|
|
|
|
if(cmd[0] == '+' && !polarity)
|
|
|
|
cmd[0] = '-';
|
|
|
|
return cmd;
|
|
|
|
}
|