mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
implement 'DeviceType' property
Signed-off-by: Julian Kandlhofer <julian.kandlhofer@gmail.com>
This commit is contained in:
committed by
Yaroslav Chvanov
parent
931ec44ff2
commit
4f36371af3
@@ -113,6 +113,7 @@ struct ratbag_device_data {
|
||||
char *driver;
|
||||
|
||||
enum driver drivertype;
|
||||
enum ratbag_device_type devicetype;
|
||||
|
||||
union {
|
||||
struct data_hidpp20 hidpp20;
|
||||
@@ -449,6 +450,12 @@ ratbag_device_data_get_name(const struct ratbag_device_data *data)
|
||||
return data->name;
|
||||
}
|
||||
|
||||
enum ratbag_device_type
|
||||
ratbag_device_data_get_device_type(const struct ratbag_device_data *data)
|
||||
{
|
||||
return data->devicetype;
|
||||
}
|
||||
|
||||
enum ratbag_led_type
|
||||
ratbag_device_data_get_led_type(const struct ratbag_device_data *data,
|
||||
unsigned int index)
|
||||
@@ -596,6 +603,7 @@ file_data_matches(struct ratbag *ratbag,
|
||||
_cleanup_(g_strfreevp) char **match_strv = NULL;
|
||||
_cleanup_(g_strfreevp) char **ledtypes_strv = NULL;
|
||||
_cleanup_(ratbag_device_data_unrefp) struct ratbag_device_data *data = NULL;
|
||||
_cleanup_free_ char *devicetype = NULL;
|
||||
int rc;
|
||||
|
||||
keyfile = g_key_file_new();
|
||||
@@ -645,6 +653,24 @@ file_data_matches(struct ratbag *ratbag,
|
||||
}
|
||||
}
|
||||
|
||||
devicetype = g_key_file_get_string(keyfile, GROUP_DEVICE, "DeviceType", NULL);
|
||||
if (devicetype == NULL) {
|
||||
log_error(ratbag, "No DeviceType found in '%s'\n", basename(path));
|
||||
data->devicetype = TYPE_UNSPECIFIED;
|
||||
return false;
|
||||
}
|
||||
if (streq(devicetype, "keyboard")) {
|
||||
data->devicetype = TYPE_KEYBOARD;
|
||||
} else if (streq(devicetype, "mouse")) {
|
||||
data->devicetype = TYPE_MOUSE;
|
||||
} else if (streq(devicetype, "other")) {
|
||||
data->devicetype = TYPE_OTHER;
|
||||
} else {
|
||||
log_error(ratbag, "Invalid DeviceType '%s' in '%s'\n", devicetype, basename(path));
|
||||
data->devicetype = TYPE_UNSPECIFIED;
|
||||
return false;
|
||||
}
|
||||
|
||||
ledtypes_strv = g_key_file_get_string_list(keyfile, GROUP_DEVICE, "LedTypes", NULL, NULL);
|
||||
if (parse_ledtypes(ledtypes_strv, data->led_types, ARRAY_LENGTH(data->led_types)) < 0) {
|
||||
log_error(ratbag, "Invalid LedTypes string in '%s'\n", basename(path));
|
||||
|
||||
@@ -42,6 +42,8 @@ const char *
|
||||
ratbag_device_data_get_driver(const struct ratbag_device_data *data);
|
||||
const char *
|
||||
ratbag_device_data_get_name(const struct ratbag_device_data *data);
|
||||
enum ratbag_device_type
|
||||
ratbag_device_data_get_device_type(const struct ratbag_device_data *data);
|
||||
enum ratbag_led_type
|
||||
ratbag_device_data_get_led_type(const struct ratbag_device_data *data,
|
||||
unsigned int index);
|
||||
|
||||
@@ -341,3 +341,29 @@ enum ratbag_macro_event_type {
|
||||
RATBAG_MACRO_EVENT_KEY_RELEASED,
|
||||
RATBAG_MACRO_EVENT_WAIT,
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup enums
|
||||
*
|
||||
* Device Types
|
||||
* Describes the types specified in the .device files
|
||||
*/
|
||||
enum ratbag_device_type {
|
||||
/**
|
||||
* Used when no DeviceType property could be found
|
||||
*/
|
||||
TYPE_UNSPECIFIED = 0,
|
||||
/**
|
||||
* Used for any other device type than a mouse or a keyboard
|
||||
* for example headsets, mousepads etc.
|
||||
*/
|
||||
TYPE_OTHER,
|
||||
/**
|
||||
* Used for mice
|
||||
*/
|
||||
TYPE_MOUSE,
|
||||
/**
|
||||
* Used for keyboards
|
||||
*/
|
||||
TYPE_KEYBOARD,
|
||||
};
|
||||
|
||||
@@ -132,6 +132,7 @@ struct ratbag {
|
||||
struct ratbag_device {
|
||||
char *name;
|
||||
void *userdata;
|
||||
enum ratbag_device_type devicetype;
|
||||
|
||||
struct udev_device *udev_device;
|
||||
struct ratbag_hidraw hidraw[MAX_HIDRAW];
|
||||
|
||||
@@ -71,6 +71,8 @@ ratbag_device_new_test_device(struct ratbag *ratbag,
|
||||
|
||||
device = ratbag_device_new(ratbag, NULL, "Test device", &id);
|
||||
|
||||
device->devicetype = TYPE_MOUSE;
|
||||
|
||||
if (!ratbag_assign_driver(device, &device->ids, test_device)) {
|
||||
ratbag_device_destroy(device);
|
||||
return NULL;
|
||||
|
||||
@@ -196,6 +196,10 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device,
|
||||
device->udev_device = udev_device_ref(udev_device);
|
||||
device->ids = *id;
|
||||
device->data = ratbag_device_data_new_for_id(ratbag, id);
|
||||
|
||||
if (device->data != NULL)
|
||||
device->devicetype = ratbag_device_data_get_device_type(device->data);
|
||||
|
||||
list_init(&device->profiles);
|
||||
|
||||
list_insert(&ratbag->devices, &device->link);
|
||||
@@ -521,6 +525,12 @@ ratbag_device_get_name(const struct ratbag_device* device)
|
||||
return device->name;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT enum ratbag_device_type
|
||||
ratbag_device_get_device_type(const struct ratbag_device *device)
|
||||
{
|
||||
return device->devicetype;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT const char *
|
||||
ratbag_device_get_bustype(const struct ratbag_device *device)
|
||||
{
|
||||
|
||||
@@ -450,6 +450,15 @@ ratbag_device_get_firmware_version(const struct ratbag_device *device);
|
||||
const char *
|
||||
ratbag_device_get_name(const struct ratbag_device* device);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* @param device A previously initialized ratbag device
|
||||
* @return the type of the device: unspecified, mouse, keyboard or other
|
||||
*/
|
||||
enum ratbag_device_type
|
||||
ratbag_device_get_device_type(const struct ratbag_device* device);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user