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