Angle snap added to UI and driver support
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
				
			|||||||
#include "g-wolves.h"
 | 
					#include "g-wolves.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DEVICE_WIRELESS(handle) (driver_get_capacity(handle) & DEVICE_CAPACITY_WIRELESS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
					static int send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    report_header_t* head = report;
 | 
					    report_header_t* head = report;
 | 
				
			||||||
@@ -157,11 +159,7 @@ int driver_mouse_dpi_get(void* handle, struct MOUSE_DPI_LEVELS* output)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Send command
 | 
					    // Send command
 | 
				
			||||||
    struct REPORT_DPI_SETTINGS report = {0};
 | 
					    struct REPORT_DPI_SETTINGS report = {0};
 | 
				
			||||||
    
 | 
					    int res = send_command(hand, COMMAND_DPI_SETTINGS, REPORT_DPI_SETTINGS_SIZE, &report, DEVICE_WIRELESS(handle));
 | 
				
			||||||
    bool wireless = false;
 | 
					 | 
				
			||||||
    if(driver_get_capacity(handle) & DEVICE_CAPACITY_WIRELESS) wireless = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int res = send_command(hand, COMMAND_DPI_SETTINGS, REPORT_DPI_SETTINGS_SIZE, &report, wireless);
 | 
					 | 
				
			||||||
    if(res <= 0) return -1;
 | 
					    if(res <= 0) return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Format 'output' packet
 | 
					    // Format 'output' packet
 | 
				
			||||||
@@ -196,11 +194,7 @@ int driver_mouse_motion_sync_get(void* handle, bool* output)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Send command
 | 
					    // Send command
 | 
				
			||||||
    struct REPORT_MOTION_SYNC report = {0};
 | 
					    struct REPORT_MOTION_SYNC report = {0};
 | 
				
			||||||
 | 
					    int res = send_command(hand, COMMAND_MOTION_SYNC, REPORT_MOTION_SYNC_SIZE, &report, DEVICE_WIRELESS(handle));
 | 
				
			||||||
    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;
 | 
					    if(res <= 0) return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Format output boolean
 | 
					    // Format output boolean
 | 
				
			||||||
@@ -211,3 +205,27 @@ int driver_mouse_motion_sync_get(void* handle, bool* output)
 | 
				
			|||||||
    libusb_close(hand);
 | 
					    libusb_close(hand);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int driver_mouse_angle_snap_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_ANGLE_SNAP report = {0};
 | 
				
			||||||
 | 
					    int res = send_command(hand, COMMAND_ANGLE_SNAP, REPORT_ANGLE_SNAP_SIZE, &report, DEVICE_WIRELESS(handle));
 | 
				
			||||||
 | 
					    if(res <= 0) return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Format output boolean
 | 
				
			||||||
 | 
					    *output = report.angle_snap;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Close and return
 | 
				
			||||||
 | 
					    libusb_attach_kernel_driver(hand, 0x2);
 | 
				
			||||||
 | 
					    libusb_close(hand);
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ struct _MousePanel
 | 
				
			|||||||
    AdwPreferencesGroup* dpi_preference_group;
 | 
					    AdwPreferencesGroup* dpi_preference_group;
 | 
				
			||||||
    AdwButtonContent* dpi_stage_add_button;
 | 
					    AdwButtonContent* dpi_stage_add_button;
 | 
				
			||||||
    AdwSwitchRow* motion_sync_switchrow;
 | 
					    AdwSwitchRow* motion_sync_switchrow;
 | 
				
			||||||
 | 
					    AdwSwitchRow* angle_snap_switchrow;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE (MousePanel, mouse_panel, panel_get_type())
 | 
					G_DEFINE_TYPE (MousePanel, mouse_panel, panel_get_type())
 | 
				
			||||||
@@ -27,6 +28,7 @@ mouse_panel_class_init(MousePanelClass* klass)
 | 
				
			|||||||
    gtk_widget_class_bind_template_child(widget_class, MousePanel, dpi_preference_group);
 | 
					    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, dpi_stage_add_button);
 | 
				
			||||||
    gtk_widget_class_bind_template_child(widget_class, MousePanel, motion_sync_switchrow);
 | 
					    gtk_widget_class_bind_template_child(widget_class, MousePanel, motion_sync_switchrow);
 | 
				
			||||||
 | 
					    gtk_widget_class_bind_template_child(widget_class, MousePanel, angle_snap_switchrow);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
@@ -103,8 +105,12 @@ void mouse_panel_set_device(MousePanel* self, device_t* device)
 | 
				
			|||||||
    int (*driver_mouse_motion_sync_get)(void*, bool*) = dlsym(device_driver(device), "driver_mouse_motion_sync_get");
 | 
					    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);
 | 
					    int motionsync_res = driver_mouse_motion_sync_get(device_handle(device), &motion_sync);
 | 
				
			||||||
    if(!motionsync_res)
 | 
					    if(!motionsync_res)
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        adw_switch_row_set_active(self->motion_sync_switchrow, motion_sync);
 | 
					        adw_switch_row_set_active(self->motion_sync_switchrow, motion_sync);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Set mouse 'angle snap' feature
 | 
				
			||||||
 | 
					    bool angle_snap = false;
 | 
				
			||||||
 | 
					    int (*driver_mouse_angle_snap_get)(void*, bool*) = dlsym(device_driver(device), "driver_mouse_angle_snap_get");
 | 
				
			||||||
 | 
					    int anglesnap_res = driver_mouse_angle_snap_get(device_handle(device), &angle_snap);
 | 
				
			||||||
 | 
					    if(!anglesnap_res)
 | 
				
			||||||
 | 
					        adw_switch_row_set_active(self->angle_snap_switchrow, angle_snap);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -204,7 +204,7 @@ the rate of the computer update requests </property>
 | 
				
			|||||||
                        <property name="margin-top">10</property>
 | 
					                        <property name="margin-top">10</property>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    <child>
 | 
					                    <child>
 | 
				
			||||||
                      <object class="AdwSwitchRow">
 | 
					                      <object class="AdwSwitchRow" id="angle_snap_switchrow">
 | 
				
			||||||
                        <property name="activatable">true</property>
 | 
					                        <property name="activatable">true</property>
 | 
				
			||||||
                        <property name="width-request">200</property>
 | 
					                        <property name="width-request">200</property>
 | 
				
			||||||
                        <property name="hexpand">false</property>
 | 
					                        <property name="hexpand">false</property>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user