Commit 5f1bea39 authored by sebt3's avatar sebt3

Added configuration for "Alt key" mapping (aka start button and second right trigger)

parent 7ac4196f
......@@ -46,6 +46,8 @@ nubs.right.x = [mouse_x|mouse_y|*mouse_btn*|scroll_x|scroll_y]
nubs.right.y = [mouse_x|mouse_y|mouse_btn|scroll_x|*scroll_y*]
nubs.left.click = [*mouse_left*|mouse_right]
nubs.right.click = [mouse_left|*mouse_right*]
altmode.start.button = [*left_alt*|right_alt]
altmode.right.trigger = [*left_alt*|right_alt]
gamepad.export = 1
keypad.export = 1
mouse.export = 1
......
......@@ -101,6 +101,9 @@ struct Settings {
NUB_CLICK_LEFT, NUB_CLICK_RIGHT,
MOUSE_LEFT, MOUSE_RIGHT
};
enum AltMode {
LEFT_ALT, RIGHT_ALT
};
NubAxisMode leftNubModeX = MOUSE_X;
NubAxisMode leftNubModeY = MOUSE_Y;
......@@ -108,6 +111,9 @@ struct Settings {
NubAxisMode rightNubModeY = SCROLL_Y;
NubClickMode leftNubClickMode = MOUSE_LEFT;
NubClickMode rightNubClickMode = MOUSE_RIGHT;
AltMode startButton = LEFT_ALT;
AltMode rightTrigger = LEFT_ALT;
// May be changed from any thread at any time
int joyDeadzone = 10;
......@@ -124,6 +130,12 @@ struct Settings {
Scripts brightness;
};
using AltModeMap = std::unordered_map<std::string, Settings::AltMode>;
AltModeMap const ALT_MODES = {
{ "left_alt", Settings::LEFT_ALT },
{ "right_alt", Settings::RIGHT_ALT }
};
using NubAxisModeMap = std::unordered_map<std::string, Settings::NubAxisMode>;
NubAxisModeMap const NUB_AXIS_MODES = {
{ "mouse_x", Settings::MOUSE_X },
......@@ -145,6 +157,7 @@ void handleArgs(char const** argv, unsigned int argc, Settings& settings);
void loadConfig(std::string const& filename, Settings& settings);
Settings::NubAxisMode parseNubAxisMode(std::string const& str);
Settings::NubClickMode parseNubClickMode(std::string const& str);
Settings::AltMode parseAltMode(std::string const& str);
void handleNubAxis(Settings::NubAxisMode mode, int value, Mouse* mouse, UinputDevice* gamepad, Settings const& settings);
void handleNubClick(Settings::NubClickMode mode, int value, Mouse* mouse, UinputDevice* gamepad, Settings const& settings);
......@@ -214,9 +227,9 @@ void init(char const** argv, unsigned int argc) {
global.Fn.pressed = global.Fn.left || global.Fn.right;
});
//TODO: make the alt mapping configurable
global.behaviors->altmap(KEY_ESC, &global.Fn.pressed, KEY_ESC, KEY_SYSRQ);
global.behaviors->altmap(KEY_PAUSE, &global.Fn.pressed, KEY_PAUSE, KEY_SCALE); global.behaviors->script(KEY_BRIGHTNESSUP, &global.settings.brightness);
global.behaviors->altmap(KEY_PAUSE, &global.Fn.pressed, KEY_PAUSE, KEY_SCALE);
global.behaviors->script(KEY_BRIGHTNESSUP, &global.settings.brightness);
//global.behaviors->altmap(KEY_BRIGHTNESSUP, &global.Fn.pressed, KEY_BRIGHTNESSUP, KEY_BRIGHTNESSDOWN);
global.behaviors->altmap(KEY_F11, &global.Fn.pressed, KEY_F11, KEY_F12);
global.behaviors->altmap(KEY_1, &global.Fn.pressed, KEY_1, KEY_F1);
......@@ -349,14 +362,14 @@ void handle(input_event const& e, unsigned int role) {
case BTN_THUMBL:
case BTN_THUMBR:
if (role == ROLE_LEFT_NUB && global.settings.exportMouse) {
std::cout << "left nub click\n";
//std::cout << "left nub click\n";
handleNubClick(global.settings.leftNubClickMode, e.value, global.mouse, global.gamepad, global.settings);
if (global.settings.exportGamepad) {
global.gamepad->send(EV_KEY, BTN_THUMBL, e.value);
global.gamepad->send(EV_SYN, 0, 0);
}
} else if (role == ROLE_RIGHT_NUB && global.settings.exportMouse) {
std::cout << "right nub click\n";
//std::cout << "right nub click\n";
handleNubClick(global.settings.rightNubClickMode, e.value, global.mouse, global.gamepad, global.settings);
if (global.settings.exportGamepad) {
global.gamepad->send(EV_KEY, BTN_THUMBR, e.value);
......@@ -501,6 +514,12 @@ SettingHandlerMap const SETTING_HANDLERS = {
} },
{ "nubs.right.click", [](std::string const& value, Settings& settings) {
settings.rightNubClickMode = parseNubClickMode(value);
} },
{ "altmode.start.button", [](std::string const& value, Settings& settings) {
settings.startButton = parseAltMode(value);
} },
{ "altmode.right.trigger", [](std::string const& value, Settings& settings) {
settings.rightTrigger = parseAltMode(value);
} }
};
......@@ -534,6 +553,15 @@ void loadConfig(std::string const& filename, Settings& settings) {
std::cerr << "Invalid line in config file: " << line << std::endl;
}
}
/* Apply "Alt Keys" mapping configuration */
if (settings.startButton == Settings::LEFT_ALT)
global.behaviors->gpmap2(KEY_LEFTALT, BTN_START, &global.Alt.left, &global.Alt);
else
global.behaviors->gpmap2(KEY_RIGHTALT, BTN_START, &global.Alt.right, &global.Alt);
if (settings.rightTrigger == Settings::LEFT_ALT)
global.behaviors->gpmap2(KEY_LEFTALT, BTN_TR2, &global.Alt.left, &global.Alt);
else
global.behaviors->gpmap2(KEY_RIGHTALT, BTN_TR2, &global.Alt.right, &global.Alt);
}
Settings::NubAxisMode parseNubAxisMode(std::string const& str) {
......@@ -558,6 +586,17 @@ Settings::NubClickMode parseNubClickMode(std::string const& str) {
}
}
Settings::AltMode parseAltMode(std::string const& str) {
std::string s(str);
std::transform(s.begin(), s.end(), s.begin(), tolower);
auto iter = ALT_MODES.find(s);
if(iter == ALT_MODES.end()) {
return Settings::LEFT_ALT;
} else {
return iter->second;
}
}
void handleNubAxis(Settings::NubAxisMode mode, int value, Mouse* mouse, UinputDevice* gamepad, Settings const& settings) {
switch(mode) {
case Settings::MOUSE_X:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment