From 22cb968b641b2bc3189ae9b2454cc100c67aa674 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Sat, 30 Sep 2023 23:50:33 +0200 Subject: [PATCH] Motion sync loaded in UI, support in g-wolves --- drivers/g-wolves/g-wolves.c | 28 ++++++++++++++++++++++++++++ src/ui/panels/mouse-panel.c | 12 ++++++++++++ ui/panel-mouse.ui | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/g-wolves/g-wolves.c b/drivers/g-wolves/g-wolves.c index 8b1a541..d7d1bff 100644 --- a/drivers/g-wolves/g-wolves.c +++ b/drivers/g-wolves/g-wolves.c @@ -183,3 +183,31 @@ int driver_mouse_dpi_get(void* handle, struct MOUSE_DPI_LEVELS* output) libusb_close(hand); return 0; } + +int driver_mouse_motion_sync_get(void* handle, bool* output) +{ + libusb_device* dev = handle; + + // Prepare usb device for transfer + libusb_device_handle* hand; + int openres = libusb_open(dev, &hand); + if(openres) return -1; + libusb_detach_kernel_driver(hand, 0x2); + + // Send command + struct REPORT_MOTION_SYNC report = {0}; + + bool wireless = false; + if(driver_get_capacity(handle) & DEVICE_CAPACITY_WIRELESS) wireless = true; + + int res = send_command(hand, COMMAND_MOTION_SYNC, REPORT_MOTION_SYNC_SIZE, &report, wireless); + if(res <= 0) return -1; + + // Format output boolean + *output = report.motion_sync; + + // Close and return + libusb_attach_kernel_driver(hand, 0x2); + libusb_close(hand); + return 0; +} diff --git a/src/ui/panels/mouse-panel.c b/src/ui/panels/mouse-panel.c index 430ed4b..b11ebeb 100644 --- a/src/ui/panels/mouse-panel.c +++ b/src/ui/panels/mouse-panel.c @@ -9,6 +9,7 @@ struct _MousePanel GtkLabel* mouse_name; AdwPreferencesGroup* dpi_preference_group; AdwButtonContent* dpi_stage_add_button; + AdwSwitchRow* motion_sync_switchrow; }; G_DEFINE_TYPE (MousePanel, mouse_panel, panel_get_type()) @@ -25,6 +26,7 @@ mouse_panel_class_init(MousePanelClass* klass) gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_name); gtk_widget_class_bind_template_child(widget_class, MousePanel, dpi_preference_group); gtk_widget_class_bind_template_child(widget_class, MousePanel, dpi_stage_add_button); + gtk_widget_class_bind_template_child(widget_class, MousePanel, motion_sync_switchrow); } static void @@ -95,4 +97,14 @@ void mouse_panel_set_device(MousePanel* self, device_t* device) adw_preferences_group_add(self->dpi_preference_group, GTK_WIDGET(row)); } } + + // Set mouse 'motion sync' feature + bool motion_sync = false; + int (*driver_mouse_motion_sync_get)(void*, bool*) = dlsym(device_driver(device), "driver_mouse_motion_sync_get"); + int motionsync_res = driver_mouse_motion_sync_get(device_handle(device), &motion_sync); + if(!motionsync_res) + { + adw_switch_row_set_active(self->motion_sync_switchrow, motion_sync); + } + } diff --git a/ui/panel-mouse.ui b/ui/panel-mouse.ui index 4acc244..adab739 100644 --- a/ui/panel-mouse.ui +++ b/ui/panel-mouse.ui @@ -183,7 +183,7 @@ 10 - + true 200 false