Commit b69c2a01 authored by Teemu Erkkola's avatar Teemu Erkkola
Browse files

Refactor brightness button handling into a complex behavior

parent c2cb7f83
......@@ -54,20 +54,18 @@ public:
void altmap(unsigned int code, bool* flag, unsigned int regular, unsigned int alternative);
void altcomplex(unsigned int code, bool* flag, unsigned int regular, std::function<void(int)> function);
void complex(unsigned int code, std::function<void(int)> function);
void script(unsigned int code, Scripts *s);
void handle(unsigned int code, int value);
private:
struct KeyBehavior {
KeyBehavior() : type(PASSTHROUGH), mapping(0), function() {}
enum Type { PASSTHROUGH, MAPPED, ALTMAPPED, COMPLEX, ALTCOMPLEX, GPMAPPED,GPMAP2, GPHAT, SCRIPT };
enum Type { PASSTHROUGH, MAPPED, ALTMAPPED, COMPLEX, ALTCOMPLEX, GPMAPPED,GPMAP2, GPHAT };
Type type;
int mapping;
int alternative;
bool pressed_as;
bool* flag;
LeftRight* lr;
Scripts *scripts;
std::function<void(int)> function;
};
......@@ -173,6 +171,7 @@ 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);
void handleBrightness(int value);
// Mouse movement/scroll thread handler
void handleMouse(Mouse* mouse, Settings* settings, bool* stop);
......@@ -253,7 +252,7 @@ void init(char const** argv, unsigned int argc) {
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.scripts);
global.behaviors->complex(KEY_BRIGHTNESSUP, handleBrightness);
//global.behaviors->altmap(KEY_BRIGHTNESSUP, &global.Fn.pressed, KEY_BRIGHTNESSUP, KEY_BRIGHTNESSDOWN);
global.behaviors->altmap(KEY_F11, &global.Fn.pressed, KEY_F11, KEY_F12);
......@@ -801,6 +800,51 @@ void handleNubClick(Settings::NubClickMode mode, int value, Mouse* mouse, Uinput
}
}
void handleBrightness(int value) {
if (value!=1) return;
int ret = 0;
if (global.Shift.pressed && global.Ctrl.pressed && global.Fn.pressed) {
if (!global.settings.scripts.brightnessFnShiftCtrl.empty())
ret=system(global.settings.scripts.brightnessFnShiftCtrl.c_str());
} else if (global.Shift.pressed && global.Alt.pressed && global.Fn.pressed) {
if (!global.settings.scripts.brightnessFnShiftAlt.empty())
ret=system(global.settings.scripts.brightnessFnShiftAlt.c_str());
} else if (global.Shift.pressed && global.Alt.pressed) {
if (!global.settings.scripts.brightnessShiftAlt.empty())
ret=system(global.settings.scripts.brightnessShiftAlt.c_str());
} else if (global.Shift.pressed && global.Ctrl.pressed) {
if (!global.settings.scripts.brightnessShiftCtrl.empty())
ret=system(global.settings.scripts.brightnessShiftCtrl.c_str());
} else if (global.Fn.pressed && global.Alt.pressed) {
if (!global.settings.scripts.brightnessFnAlt.empty())
ret=system(global.settings.scripts.brightnessFnAlt.c_str());
} else if (global.Fn.pressed && global.Ctrl.pressed) {
if (!global.settings.scripts.brightnessFnCtrl.empty())
ret=system(global.settings.scripts.brightnessFnCtrl.c_str());
} else if (global.Alt.pressed && global.Ctrl.pressed) {
if (!global.settings.scripts.brightnessAltCtrl.empty())
ret=system(global.settings.scripts.brightnessAltCtrl.c_str());
} else if (global.Fn.pressed && global.Shift.pressed) {
if (!global.settings.scripts.brightnessFnShift.empty())
ret=system(global.settings.scripts.brightnessFnShift.c_str());
} else if (global.Alt.pressed) {
if (!global.settings.scripts.brightnessAlt.empty())
ret=system(global.settings.scripts.brightnessAlt.c_str());
} else if (global.Alt.pressed) {
if (!global.settings.scripts.brightnessAlt.empty())
ret=system(global.settings.scripts.brightnessAlt.c_str());
} else if (global.Shift.pressed) {
if (!global.settings.scripts.brightnessShift.empty())
ret=system(global.settings.scripts.brightnessShift.c_str());
} else if (global.Fn.pressed) {
if (!global.settings.scripts.brightnessFn.empty())
ret=system(global.settings.scripts.brightnessFn.c_str());
} else {
if (!global.settings.scripts.brightnessNormal.empty())
ret=system(global.settings.scripts.brightnessNormal.c_str());
}
}
void handleMouse(Mouse* mouse, Settings* settings, bool* stop) {
while(!*stop) {
if((mouse->dx > settings->mouseDeadzone || mouse->dx < -settings->mouseDeadzone || mouse->dy > settings->mouseDeadzone || mouse->dy < -settings->mouseDeadzone || mouse->dwx > settings->mouseClickDeadzone || mouse->dwx < -settings->mouseClickDeadzone || mouse->dwy > settings->mouseWheelDeadzone || mouse->dwy < -settings->mouseWheelDeadzone)&&global.settings.exportMouse) {
......@@ -897,11 +941,6 @@ template<int FIRST_KEY, int LAST_KEY> void KeyBehaviors<FIRST_KEY, LAST_KEY>::gp
b.type = KeyBehavior::GPHAT;
b.alternative = gamepad;
}
template<int FIRST_KEY, int LAST_KEY> void KeyBehaviors<FIRST_KEY, LAST_KEY>::script(unsigned int code, Scripts *s) {
auto& b = behaviors.at(code - FIRST_KEY);
b.type = KeyBehavior::SCRIPT;
b.scripts = s;
}
template<int FIRST_KEY, int LAST_KEY> void KeyBehaviors<FIRST_KEY, LAST_KEY>::handle(unsigned int code, int value) {
if (code <FIRST_KEY || code >LAST_KEY) return;
......@@ -968,49 +1007,5 @@ template<int FIRST_KEY, int LAST_KEY> void KeyBehaviors<FIRST_KEY, LAST_KEY>::ha
global.gamepad->send(EV_SYN, 0, 0);
}
break;
case KeyBehavior::SCRIPT:
if (value!=1) return;
int ret = 0;
if (global.Shift.pressed && global.Ctrl.pressed && global.Fn.pressed) {
if (!kb.scripts->brightnessFnShiftCtrl.empty())
ret=system(kb.scripts->brightnessFnShiftCtrl.c_str());
} else if (global.Shift.pressed && global.Alt.pressed && global.Fn.pressed) {
if (!kb.scripts->brightnessFnShiftAlt.empty())
ret=system(kb.scripts->brightnessFnShiftAlt.c_str());
} else if (global.Shift.pressed && global.Alt.pressed) {
if (!kb.scripts->brightnessShiftAlt.empty())
ret=system(kb.scripts->brightnessShiftAlt.c_str());
} else if (global.Shift.pressed && global.Ctrl.pressed) {
if (!kb.scripts->brightnessShiftCtrl.empty())
ret=system(kb.scripts->brightnessShiftCtrl.c_str());
} else if (global.Fn.pressed && global.Alt.pressed) {
if (!kb.scripts->brightnessFnAlt.empty())
ret=system(kb.scripts->brightnessFnAlt.c_str());
} else if (global.Fn.pressed && global.Ctrl.pressed) {
if (!kb.scripts->brightnessFnCtrl.empty())
ret=system(kb.scripts->brightnessFnCtrl.c_str());
} else if (global.Alt.pressed && global.Ctrl.pressed) {
if (!kb.scripts->brightnessAltCtrl.empty())
ret=system(kb.scripts->brightnessAltCtrl.c_str());
} else if (global.Fn.pressed && global.Shift.pressed) {
if (!kb.scripts->brightnessFnShift.empty())
ret=system(kb.scripts->brightnessFnShift.c_str());
} else if (global.Alt.pressed) {
if (!kb.scripts->brightnessAlt.empty())
ret=system(kb.scripts->brightnessAlt.c_str());
} else if (global.Alt.pressed) {
if (!kb.scripts->brightnessAlt.empty())
ret=system(kb.scripts->brightnessAlt.c_str());
} else if (global.Shift.pressed) {
if (!kb.scripts->brightnessShift.empty())
ret=system(kb.scripts->brightnessShift.c_str());
} else if (global.Fn.pressed) {
if (!kb.scripts->brightnessFn.empty())
ret=system(kb.scripts->brightnessFn.c_str());
} else {
if (!kb.scripts->brightnessNormal.empty())
ret=system(kb.scripts->brightnessNormal.c_str());
}
break;
};
}
}
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