UI wireless state support
This commit is contained in:
parent
ad28b82bb8
commit
c644e75cbd
@ -61,6 +61,12 @@ char* device_get_name(device_t* device)
|
|||||||
return getname_fn(device->handle);
|
return getname_fn(device->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device_capacity_t device_get_capacity(device_t* device)
|
||||||
|
{
|
||||||
|
device_capacity_t (*getcapacity_fn)(void*) = dlsym(device->driver, "driver_get_capacity");
|
||||||
|
return getcapacity_fn(device->handle);
|
||||||
|
}
|
||||||
|
|
||||||
void* device_handle(device_t* device)
|
void* device_handle(device_t* device)
|
||||||
{
|
{
|
||||||
return device->handle;
|
return device->handle;
|
||||||
|
@ -20,5 +20,6 @@ void* device_driver(device_t* device);
|
|||||||
device_t* device_register(void* driver, void* handle);
|
device_t* device_register(void* driver, void* handle);
|
||||||
char* device_get_image(device_t* device);
|
char* device_get_image(device_t* device);
|
||||||
char* device_get_name(device_t* device);
|
char* device_get_name(device_t* device);
|
||||||
|
device_capacity_t device_get_capacity(device_t* device);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,11 +4,22 @@ struct _MousePanel
|
|||||||
{
|
{
|
||||||
Panel parent_instance;
|
Panel parent_instance;
|
||||||
|
|
||||||
|
// Mouse presentation
|
||||||
GtkImage* mouse_image;
|
GtkImage* mouse_image;
|
||||||
GtkLabel* mouse_manufacturer;
|
GtkLabel* mouse_manufacturer;
|
||||||
GtkLabel* mouse_name;
|
GtkLabel* mouse_name;
|
||||||
|
|
||||||
|
// Wireless informations
|
||||||
|
AdwPreferencesGroup* wireless;
|
||||||
|
GtkLevelBar* battery_level;
|
||||||
|
GtkLabel* battery_level_label;
|
||||||
|
GtkLabel* charging_state;
|
||||||
|
|
||||||
|
// DPI
|
||||||
AdwPreferencesGroup* dpi_preference_group;
|
AdwPreferencesGroup* dpi_preference_group;
|
||||||
AdwButtonContent* dpi_stage_add_button;
|
AdwButtonContent* dpi_stage_add_button;
|
||||||
|
|
||||||
|
// Features
|
||||||
AdwSwitchRow* motion_sync_switchrow;
|
AdwSwitchRow* motion_sync_switchrow;
|
||||||
AdwSwitchRow* angle_snap_switchrow;
|
AdwSwitchRow* angle_snap_switchrow;
|
||||||
};
|
};
|
||||||
@ -25,6 +36,10 @@ mouse_panel_class_init(MousePanelClass* klass)
|
|||||||
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_image);
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_image);
|
||||||
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_manufacturer);
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_manufacturer);
|
||||||
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_name);
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, mouse_name);
|
||||||
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, wireless);
|
||||||
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, battery_level);
|
||||||
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, battery_level_label);
|
||||||
|
gtk_widget_class_bind_template_child(widget_class, MousePanel, charging_state);
|
||||||
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);
|
||||||
@ -59,6 +74,31 @@ void mouse_panel_set_device(MousePanel* self, device_t* device)
|
|||||||
char* device_name = device_get_name(device);
|
char* device_name = device_get_name(device);
|
||||||
gtk_label_set_label(self->mouse_name, device_name);
|
gtk_label_set_label(self->mouse_name, device_name);
|
||||||
|
|
||||||
|
// Set mouse wireless status
|
||||||
|
if(device_get_capacity(device) & DEVICE_CAPACITY_WIRELESS)
|
||||||
|
{
|
||||||
|
int (*driver_wireless_battery_state_get)(void*, int*, bool*) = dlsym(device_driver(device), "driver_wireless_battery_state_get");
|
||||||
|
int battery_level;
|
||||||
|
bool charging;
|
||||||
|
int battery_res = driver_wireless_battery_state_get(device_handle(device), &battery_level, &charging);
|
||||||
|
|
||||||
|
if(!battery_res)
|
||||||
|
{
|
||||||
|
// Set battery level
|
||||||
|
gtk_level_bar_set_value(self->battery_level, (double) battery_level);
|
||||||
|
char battery_level_str[10];
|
||||||
|
sprintf(battery_level_str, "%u %%", battery_level);
|
||||||
|
gtk_label_set_label(self->battery_level_label, battery_level_str);
|
||||||
|
|
||||||
|
// Set battery status
|
||||||
|
if(charging)
|
||||||
|
gtk_label_set_label(self->charging_state, "Charging");
|
||||||
|
else
|
||||||
|
gtk_label_set_label(self->charging_state, "Not charging");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else gtk_widget_set_visible(GTK_WIDGET(self->wireless), false);
|
||||||
|
|
||||||
// Set mouse dpi
|
// Set mouse dpi
|
||||||
struct MOUSE_DPI_LEVELS dpi;
|
struct MOUSE_DPI_LEVELS dpi;
|
||||||
int (*driver_mouse_dpi_get)(void*, void*) = dlsym(device_driver(device), "driver_mouse_dpi_get");
|
int (*driver_mouse_dpi_get)(void*, void*) = dlsym(device_driver(device), "driver_mouse_dpi_get");
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
</child>
|
</child>
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<object class="AdwPreferencesGroup">
|
<object class="AdwPreferencesGroup" id="wireless">
|
||||||
<property name="margin-top">20</property>
|
<property name="margin-top">20</property>
|
||||||
<property name="margin-start">20</property>
|
<property name="margin-start">20</property>
|
||||||
<property name="margin-end">20</property>
|
<property name="margin-end">20</property>
|
||||||
@ -82,7 +82,7 @@
|
|||||||
<property name="spacing">10</property>
|
<property name="spacing">10</property>
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel" id="charging_state">
|
||||||
<property name="halign">start</property>
|
<property name="halign">start</property>
|
||||||
<property name="label">Not charging</property>
|
<property name="label">Not charging</property>
|
||||||
<property name="margin-start">10</property>
|
<property name="margin-start">10</property>
|
||||||
@ -90,7 +90,7 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel" id="battery_level_label">
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="label">50%</property>
|
<property name="label">50%</property>
|
||||||
<property name="margin-start">120</property>
|
<property name="margin-start">120</property>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user