Replace tabs with spaces because github displays things weirdly
This commit is contained in:
144
tradjust.cpp
144
tradjust.cpp
@@ -6,97 +6,97 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct input_event {
|
struct input_event {
|
||||||
timeval time;
|
timeval time;
|
||||||
unsigned short type;
|
unsigned short type;
|
||||||
unsigned short code;
|
unsigned short code;
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum button_code {
|
enum button_code {
|
||||||
BTN_LEFT = 272,
|
BTN_LEFT = 272,
|
||||||
BTN_TOUCH = 330,
|
BTN_TOUCH = 330,
|
||||||
BTN_TOOL_FINGER = 325,
|
BTN_TOOL_FINGER = 325,
|
||||||
BTN_TOOL_DOUBLETAP = 333,
|
BTN_TOOL_DOUBLETAP = 333,
|
||||||
BTN_TOOL_TRIPLETAP = 334,
|
BTN_TOOL_TRIPLETAP = 334,
|
||||||
BTN_TOOL_QUADTAP = 335,
|
BTN_TOOL_QUADTAP = 335,
|
||||||
BTN_TOOL_QUINTTAP = 328,
|
BTN_TOOL_QUINTTAP = 328,
|
||||||
};
|
};
|
||||||
|
|
||||||
float operator-(timeval a, timeval b) {
|
float operator-(timeval a, timeval b) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjustVolume (float diff) {
|
void adjustVolume (float diff) {
|
||||||
char cmd[45];
|
char cmd[45];
|
||||||
if (diff >= 0)
|
if (diff >= 0)
|
||||||
sprintf(cmd, "pactl set-sink-volume @DEFAULT_SINK@ +%d%%", abs((int) diff));
|
sprintf(cmd, "pactl set-sink-volume @DEFAULT_SINK@ +%d%%", abs((int) diff));
|
||||||
else
|
else
|
||||||
sprintf(cmd, "pactl set-sink-volume @DEFAULT_SINK@ -%d%%", abs((int) diff));
|
sprintf(cmd, "pactl set-sink-volume @DEFAULT_SINK@ -%d%%", abs((int) diff));
|
||||||
system(cmd);
|
system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjustBrightness (float diff) {
|
void adjustBrightness (float diff) {
|
||||||
char cmd[45];
|
char cmd[45];
|
||||||
if (diff > 0)
|
if (diff > 0)
|
||||||
sprintf(cmd, "brightnessctl set +%d > /dev/null", (int) diff);
|
sprintf(cmd, "brightnessctl set +%d > /dev/null", (int) diff);
|
||||||
else
|
else
|
||||||
sprintf(cmd, "brightnessctl set %d- -n 1 > /dev/null", (int) diff * -1);
|
sprintf(cmd, "brightnessctl set %d- -n 1 > /dev/null", (int) diff * -1);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void adjust(int y, bool side) {
|
void adjust(int y, bool side) {
|
||||||
if (y == 0) return;
|
if (y == 0) return;
|
||||||
if (side)
|
if (side)
|
||||||
adjustBrightness (y*8);
|
adjustBrightness (y*8);
|
||||||
else
|
else
|
||||||
adjustVolume ((float)y/8);
|
adjustVolume ((float)y/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
ifstream device (
|
ifstream device (
|
||||||
"/dev/input/by-path/pci-0000:00:15.0-platform-i2c_designware.0-event-mouse",
|
"/dev/input/by-path/pci-0000:00:15.0-platform-i2c_designware.0-event-mouse",
|
||||||
ios_base::binary
|
ios_base::binary
|
||||||
);
|
);
|
||||||
input_event event;
|
input_event event;
|
||||||
button_code button;
|
button_code button;
|
||||||
bool down;
|
bool down;
|
||||||
time_t tv_sec = 0;
|
time_t tv_sec = 0;
|
||||||
long int tv_usec = 0;
|
long int tv_usec = 0;
|
||||||
int y_value = 0;
|
int y_value = 0;
|
||||||
int y_diff;
|
int y_diff;
|
||||||
bool side; // False is left, true is right
|
bool side; // False is left, true is right
|
||||||
|
|
||||||
while (device.read(reinterpret_cast<char*>(&event), sizeof(input_event))) {
|
while (device.read(reinterpret_cast<char*>(&event), sizeof(input_event))) {
|
||||||
if (event.type == 1) {
|
if (event.type == 1) {
|
||||||
if (event.code == button_code::BTN_TOUCH)
|
if (event.code == button_code::BTN_TOUCH)
|
||||||
down = false;
|
down = false;
|
||||||
button = (button_code) event.code;
|
button = (button_code) event.code;
|
||||||
}
|
}
|
||||||
if (button == button_code::BTN_TOOL_FINGER) {
|
if (button == button_code::BTN_TOOL_FINGER) {
|
||||||
if (event.type == 0 &&
|
if (event.type == 0 &&
|
||||||
event.code == 0 &&
|
event.code == 0 &&
|
||||||
event.time.tv_sec - tv_sec
|
event.time.tv_sec - tv_sec
|
||||||
+ (float)(event.time.tv_usec - tv_usec)/1000000 > 0.03
|
+ (float)(event.time.tv_usec - tv_usec)/1000000 > 0.03
|
||||||
) {
|
) {
|
||||||
tv_sec = event.time.tv_sec;
|
tv_sec = event.time.tv_sec;
|
||||||
tv_usec = event.time.tv_usec;
|
tv_usec = event.time.tv_usec;
|
||||||
if (down) {
|
if (down) {
|
||||||
adjust(y_diff, side);
|
adjust(y_diff, side);
|
||||||
}
|
}
|
||||||
y_diff = 0;
|
y_diff = 0;
|
||||||
down = true;
|
down = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == 3) {
|
if (event.type == 3) {
|
||||||
if (event.code == 0) {
|
if (event.code == 0) {
|
||||||
side = (event.value > 1682); // Trackpad resolution is 3364x1669
|
side = (event.value > 1682); // Trackpad resolution is 3364x1669
|
||||||
}
|
}
|
||||||
if (event.code == 1) {
|
if (event.code == 1) {
|
||||||
y_diff += y_value - event.value;
|
y_diff += y_value - event.value;
|
||||||
y_value = event.value;
|
y_value = event.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user