From a65aba6587f9fa7c78c2853ecb894a495624a830 Mon Sep 17 00:00:00 2001 From: chlorospingus Date: Thu, 12 Jun 2025 18:52:16 -0700 Subject: [PATCH] Replace tabs with spaces because github displays things weirdly --- tradjust.cpp | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/tradjust.cpp b/tradjust.cpp index 45caa78..4806b9b 100644 --- a/tradjust.cpp +++ b/tradjust.cpp @@ -6,97 +6,97 @@ using namespace std; struct input_event { - timeval time; - unsigned short type; - unsigned short code; - unsigned int value; + 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, + 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; + 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); + 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); + 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); + 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 + 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; - } + 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; - } - } - } - } + 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; + } + } + } + } }