// g++ nobump.c -std=c++14 -lXi -lXext -lX11 // SPDX-License-Identifier: GPL-3.0-or-later // Copyright © 2019 Jeff Epler #include #include #include #include #include #include // Customize this to match your mouse (device string shown by 'xinput list') const char *device_name = "Logitech USB-PS/2 Optical Mouse"; const char *property = "Device Enabled"; int32_t int_from_buffer(unsigned char *buffer) { int32_t result; memcpy(&result, buffer, sizeof(result)); return result; } unsigned char *buffer_from_int(unsigned char *buffer, int32_t data) { memcpy(buffer, &data, sizeof(data)); return buffer; } int find_deviceid_by_name(Display *display, const char *name) { auto ndevices = int{}; auto info = XIQueryDevice(display, XIAllDevices, &ndevices); auto result = -1; for(auto i = info; i != info+ndevices; i++) { if(strcmp(i->name, name) == 0) { result = i->deviceid; break; } } XIFreeDeviceInfo(info); return result; } int main() { auto display = XOpenDisplay(nullptr); auto deviceid = find_deviceid_by_name(display, device_name); auto property_atom = XInternAtom(display, property, true); Atom type_atom; int format; unsigned char *data = {}; unsigned long num_items, bytes_after; auto status = XIGetProperty( display, deviceid, property_atom, 0, 1, false, 0, &type_atom, &format, &num_items, &bytes_after, &data); auto old_state = -1; while(1) { CARD16 power; BOOL enable; auto status = DPMSInfo(display, &power, &enable); auto new_state = !(enable && power != DPMSModeOn); if(new_state != old_state) { buffer_from_int(data, new_state); XIChangeProperty(display, deviceid, property_atom, type_atom, format, XIPropModeReplace, data, num_items); } old_state = new_state; sleep(1); } }