Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROG=strix-claw

CC=gcc
CFLAGS=-std=gnu99 -W -Wall -Werror -lusb-1.0
CFLAGS=-std=gnu11 -W -Wall -Werror -lusb-1.0

SOURCES := $(wildcard *.c)
OBJS := $(patsubst %.c, %.o,$(SOURCES))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# strix-claw
This is an userspace utility for prevention of hanging Strix Claw mouse when DPI
or side buttons are pressed. are pressed. It reads events from interface 2, which
This is an userspace utility for prevention of hanging Itron Technology mice when DPI
or side buttons are pressed. It reads events from interface 2, which
is commonly used for additional features for mices and keyboards.


As an example, a part of `lsusb` and `lsusb -t` with Strix Tactic Pro and Strix Claw:

Bus 001 Device 009: ID 195d:1016 Itron Technology iONE
Expand Down Expand Up @@ -47,5 +48,4 @@ To install strix-claw to your system:
# systemctl start strix-claw.service

## TODO
* support of multiple devices simulatenously
* implement a kernel module or patch usbhid subsystem
53 changes: 45 additions & 8 deletions strix-claw.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,64 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <signal.h>
#include <libusb-1.0/libusb.h>
#include <signal.h>
#include <stdio.h>

void callback(struct libusb_transfer *transfer);
void sighandler(int sig);
#define DEVICE_DESC(vendor, product) ((((vendor))<<16) | (product))

uint32_t devices[] = {
DEVICE_DESC(0x195d, 0x1016), // ASUS CLAW
DEVICE_DESC(0x195d, 0x1017), // SAGITTA
DEVICE_DESC(0x12cf, 0x700b), // COUGAR 700M
0
};

static int do_exit = 0;

void callback(struct libusb_transfer *transfer);
void sighandler(int sig);
uint16_t vendor_of(uint32_t usb_device_desc);
uint16_t product_of(uint32_t usb_device_desc);

int main(void) {
struct sigaction sigact;
struct libusb_context *ctx;
struct libusb_device **list;
struct libusb_device_handle *handle;
struct libusb_transfer *transfer;
unsigned char data[8];
uint8_t data[8];
int completed;

libusb_init(&ctx);

if(libusb_get_device_list(ctx, &list) < 0)
if (libusb_get_device_list(ctx, &list) < 0)
goto fail_0;

if ((handle = libusb_open_device_with_vid_pid(ctx, 0x195d, 0x1016)) == NULL)
goto fail_1;
int i = 0;
while (devices[i] != 0) {
uint16_t vendor = (uint16_t)(devices[i] >> 16);
uint16_t product = (uint16_t)(devices[i]);
handle = libusb_open_device_with_vid_pid(ctx, vendor, product);

if (devices[i] == 0) {
goto fail_1;
}
if (handle == NULL) {
i++;
continue;
}
break;
}

// Interface 0x02, Endpoint 0x83 (EP3 IN)
(void)libusb_detach_kernel_driver(handle, 2);
if (libusb_claim_interface(handle, 2))
goto fail_2;

transfer = libusb_alloc_transfer(0);
libusb_fill_interrupt_transfer(transfer, handle, 0x83, data, sizeof(data), callback, &completed, 0);
libusb_fill_interrupt_transfer(transfer, handle, 0x83, data,
sizeof(data), callback, &completed, 0);

sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
Expand All @@ -69,10 +95,13 @@ int main(void) {

libusb_free_transfer(transfer);
fail_2:
fprintf(stderr,"No device or no handle.\n");
libusb_close(handle);
fail_1:
fprintf(stderr,"Couldn't get device list.\n");
libusb_free_device_list(list, 1);
fail_0:
fprintf(stdout,"Quit.\n");
libusb_exit(ctx);
return 0;
}
Expand All @@ -85,3 +114,11 @@ void sighandler(int sig) {
(void)sig;
do_exit = 1;
}

uint16_t vendor_of(uint32_t usb_device_desc) {
return (uint16_t)(usb_device_desc >> 16);
}

uint16_t product_of(uint32_t usb_device_desc) {
return (uint16_t)usb_device_desc;
}
2 changes: 1 addition & 1 deletion strix-claw.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Strix Claw hang-prevention daemon
Description=Itron Technology mice hang-prevention daemon

[Service]
User=root
Expand Down
2 changes: 1 addition & 1 deletion strix-claw.upstart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description "Strix Claw hang-prevention daemon"
description "Itron Technology mice hang-prevention daemon"

start on runlevel [2345]
stop on runlevel [!2345]
Expand Down