diff --git a/.gitignore b/.gitignore index 0660d91..9a3a0ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ KD100 +*.deb +.vscode diff --git a/KD100.c b/KD100.c index 244ba7b..7614f0a 100644 --- a/KD100.c +++ b/KD100.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include int keycodes[] = {1, 2, 4, 8, 16, 32, 64, 128, 129, 130, 132, 136, 144, 160, 192, 256, 257, 258, 260, 641, 642}; char* file = "default.cfg"; @@ -31,10 +33,22 @@ struct wheel { void GetDevice(int, int, int); void Handler(char*, int); +void HandlerX11(char*, int); +void HandlerWayland(char*, int); char* Substring(char*, int, int); const int vid = 0x256c; -const int pid = 0x006d; +const int pid[2] = {0x006d, 0x0069}; + +typedef enum System { + X11, + WAYLAND, + NONE +} System; + +System getWindowSystem(); + +System windowsystem = NONE; void GetDevice(int debug, int accept, int dry){ int err=0, wheelFunction=0, button=-1, totalButtons=0, wheelType=0, leftWheels=0, rightWheels=0, totalWheels=0; @@ -185,7 +199,7 @@ void GetDevice(int debug, int accept, int dry){ if (debug > 0){ printf("Unable to retrieve info from device #%d. Ignoring...\n", d); } - }else if (devDesc.idVendor == vid && devDesc.idProduct == pid){ + }else if (devDesc.idVendor == vid && (devDesc.idProduct == pid[0] || devDesc.idProduct == pid[1])){ if (accept == 1){ if (uid != 0){ err=libusb_open(dev, &handle); @@ -198,7 +212,7 @@ void GetDevice(int debug, int accept, int dry){ } } if (debug > 0){ - printf("\nUsing: %04x:%04x (Bus: %03d Device: %03d)\n", vid, pid, libusb_get_bus_number(dev), libusb_get_device_address(dev)); + printf("\nUsing: %04x:%04x (Bus: %03d Device: %03d)\n", devDesc.idVendor, devDesc.idProduct, libusb_get_bus_number(dev), libusb_get_device_address(dev)); } break; }else{ // If the driver is ran as root, it can safely execute the following @@ -209,7 +223,7 @@ void GetDevice(int debug, int accept, int dry){ } err = libusb_get_string_descriptor_ascii(handle, devDesc.iProduct, info, 200); if (debug > 0){ - printf("\n#%d | %04x:%04x : %s\n", d, vid, pid, info); + printf("\n#%d | %04x:%04x : %s\n", d, devDesc.idVendor, devDesc.idProduct, info); } if (strlen(info) == 0 || strcmp("Huion Tablet_KD100", info) == 0){ break; @@ -419,8 +433,25 @@ void GetDevice(int debug, int accept, int dry){ } } - void Handler(char* key, int type){ + switch(windowsystem) { + X11: + HandlerX11(key, type); + break; + WAYLAND: + HandlerWayland(key, type); + break; + default: + printf("Wayland or X11 not found."); + break; + } +} + +void HandlerWayland(char* key, int type){ + system("Not implemented yet..."); +} + +void HandlerX11(char* key, int type){ if (strcmp(key, "NULL") == 0) return; @@ -455,7 +486,7 @@ void Handler(char* key, int type){ temp[strlen(cmd)+2] = '\0'; } system(temp); - } + } } char* Substring(char* in, int start, int end){ @@ -471,6 +502,18 @@ char* Substring(char* in, int start, int end){ int main(int args, char *in[]){ + windowsystem = getWindowSystem(); + switch(windowsystem) { + X11: + printf("X11 identified."); + break; + WAYLAND: + printf("Wayland identified."); + break; + default: + printf("Wayland or X11 not found."); + break; + } int debug=0, accept=0, dry=0, err; err = system("xdotool sleep 0.01"); @@ -482,7 +525,7 @@ int main(int args, char *in[]){ for (int arg = 1; arg < args; arg++){ if (strcmp(in[arg],"-h") == 0 || strcmp(in[arg],"--help") == 0){ printf("Usage: KD100 [option]...\n"); - printf("\t-a\t\tAssume the first device that matches %04x:%04x is the Keydial\n", vid, pid); + printf("\t-a\t\tAssume the first device that matches %04x:%04x is the Keydial\n", vid, pid[0]); printf("\t-c [path]\tSpecifies a config file to use\n"); printf("\t-d [-d]\t\tEnable debug outputs (use twice to view data sent by the device)\n"); printf("\t-dry \t\tDisplay data sent by the device without sending events\n"); @@ -522,3 +565,20 @@ int main(int args, char *in[]){ libusb_exit(ctx); return 0; } + +System getWindowSystem() { + Display *display = XOpenDisplay(NULL); + if (display != NULL) { + XCloseDisplay(display); + return X11; + } else { + struct wl_display *display = wl_display_connect(NULL); + if (display != NULL) { + wl_display_disconnect(display); + return WAYLAND; + } else { + return NONE; + } + } + return NONE; +} \ No newline at end of file diff --git a/Makefile b/Makefile index 23c14a4..2fb04e0 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,11 @@ -FLAGS = -lusb-1.0 -USER = $(shell id -u) -DIR = $(shell pwd) -HOME = "/home/"$(shell logname) +FLAGS = -lusb-1.0 -lX11 -lwayland-client install: - @if [ "${USER}" = "0" ]; then\ - ${CC} KD100.c ${FLAGS} -o /bin/KD100;\ - mkdir "${HOME}/.config/KD100";\ - cp "default.cfg" "${HOME}/.config/KD100/";\ - chmod a+wr "${HOME}/.config/KD100/default.cfg";\ - echo "Default config file is located in: ${HOME}/.config/KD100/";\ - else\ - ${CC} KD100.c ${FLAGS} -o KD100;\ - fi - - + ${CC} KD100.c ${FLAGS} -o KD100; clean: rm -f KD100 + rm -f ./debian-dpkg/usr/local/bin/KD100 + rm -f huion-k20-kd100.deb +deb: + ${CC} KD100.c ${FLAGS} -o ./debian-dpkg/usr/local/bin/KD100; + dpkg-deb --build debian-dpkg huion-k20-kd100.deb \ No newline at end of file diff --git a/debian-dpkg/DEBIAN/control b/debian-dpkg/DEBIAN/control new file mode 100644 index 0000000..3bc01ed --- /dev/null +++ b/debian-dpkg/DEBIAN/control @@ -0,0 +1,5 @@ +Package: huion-kd100-k20 +Version: 1.4.1 +Maintainer: mckset +Architecture: i386 +Description: Huion KD100 / K20 Linux Driver diff --git a/debian-dpkg/DEBIAN/postinst b/debian-dpkg/DEBIAN/postinst new file mode 100755 index 0000000..9fc636e --- /dev/null +++ b/debian-dpkg/DEBIAN/postinst @@ -0,0 +1,4 @@ +#!/bin/bash + +udevadm control --reload +udevadm trigger diff --git a/debian-dpkg/etc/udev/rules.d/99-huion.rules b/debian-dpkg/etc/udev/rules.d/99-huion.rules new file mode 100644 index 0000000..980931c --- /dev/null +++ b/debian-dpkg/etc/udev/rules.d/99-huion.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="usb",ATTRS{idVendor}=="256c",ATTRS{idProduct}=="0069",MODE="0666" +SUBSYSTEM=="usb",ATTRS{idVendor}=="256c",ATTRS{idProduct}=="006d",MODE="0666" \ No newline at end of file