From c9c6a1675ff62ce2c97e7c41611df73acf9f9516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 5 Feb 2021 01:15:03 +0000 Subject: [PATCH] openinput: add barebones driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the minimal code required to have a working driver, now we just need a .device file. Note the hardcoding of `profile->is_active = true` in openinput_read_profile, this works because we just have one profile. Signed-off-by: Filipe Laíns --- meson.build | 1 + src/driver-openinput.c | 79 +++++++++++++++++++++++++++++++++++++++++ src/libratbag-data.c | 2 ++ src/libratbag-private.h | 1 + src/libratbag.c | 1 + 5 files changed, 84 insertions(+) create mode 100644 src/driver-openinput.c diff --git a/meson.build b/meson.build index fca44524..05ddfba5 100644 --- a/meson.build +++ b/meson.build @@ -174,6 +174,7 @@ src_libratbag = [ 'src/driver-roccat.c', 'src/driver-roccat-kone-pure.c', 'src/driver-gskill.c', + 'src/driver-openinput.c', 'src/driver-steelseries.c', 'src/driver-sinowealth.c', 'src/driver-sinowealth-nubwo.c', diff --git a/src/driver-openinput.c b/src/driver-openinput.c new file mode 100644 index 00000000..3d5e00a6 --- /dev/null +++ b/src/driver-openinput.c @@ -0,0 +1,79 @@ +/* + * Copyright © 2021 Filipe Laíns + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" + +#include "libratbag-private.h" + +static unsigned int report_rates[] = { 125, 250, 500, 750, 1000 }; + +struct openinput_drv_data { + unsigned int num_profiles; + unsigned int num_resolutions; + unsigned int num_buttons; + unsigned int num_leds; +}; + +static void +openinput_read_profile(struct ratbag_profile *profile) +{ + ratbag_profile_set_report_rate_list(profile, report_rates, sizeof(*report_rates)); + profile->is_active = true; +} + +static int +openinput_probe(struct ratbag_device *device) +{ + struct openinput_drv_data *drv_data; + struct ratbag_profile *profile; + + drv_data = zalloc(sizeof(*drv_data)); + + drv_data->num_profiles = 1; + + ratbag_set_drv_data(device, drv_data); + ratbag_device_init_profiles(device, + drv_data->num_profiles, + drv_data->num_resolutions, + drv_data->num_buttons, + drv_data->num_leds); + + ratbag_device_for_each_profile(device, profile) + openinput_read_profile(profile); + + return 0; +} + +static void +openinput_remove(struct ratbag_device *device) +{ + ratbag_close_hidraw(device); + free(ratbag_get_drv_data(device)); +} + +struct ratbag_driver openinput_driver = { + .name = "openinput", + .id = "openinput", + .probe = openinput_probe, + .remove = openinput_remove, +}; diff --git a/src/libratbag-data.c b/src/libratbag-data.c index 1016e649..c4d90540 100644 --- a/src/libratbag-data.c +++ b/src/libratbag-data.c @@ -54,6 +54,7 @@ enum driver { STEELSERIES, SINOWEALTH, SINOWEALTH_NUBWO, + OPENINPUT, }; struct data_hidpp20 { @@ -272,6 +273,7 @@ static const struct driver_map { { STEELSERIES, "steelseries", init_data_steelseries }, { SINOWEALTH, "sinowealth", NULL }, { SINOWEALTH_NUBWO, "sinowealth_nubwo", NULL}, + { OPENINPUT, "openinput", NULL }, }; const char * diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 7a9ab5ac..d933b538 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -597,6 +597,7 @@ extern struct ratbag_driver gskill_driver; extern struct ratbag_driver steelseries_driver; extern struct ratbag_driver sinowealth_driver; extern struct ratbag_driver sinowealth_nubwo_driver; +extern struct ratbag_driver openinput_driver; struct ratbag_device* ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device, diff --git a/src/libratbag.c b/src/libratbag.c index ef9aa8bd..9e30a29b 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -604,6 +604,7 @@ ratbag_create_context(const struct ratbag_interface *interface, ratbag_register_driver(ratbag, &steelseries_driver); ratbag_register_driver(ratbag, &sinowealth_driver); ratbag_register_driver(ratbag, &sinowealth_nubwo_driver); + ratbag_register_driver(ratbag, &openinput_driver); return ratbag; }