From ee540010321678d70b7477a1934a56f4e8d1072c Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Mon, 31 Jan 2022 19:56:25 +0300 Subject: [PATCH] roccat-kone-pure: migrate to profile-oriented API --- src/driver-roccat-kone-pure.c | 55 ++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/driver-roccat-kone-pure.c b/src/driver-roccat-kone-pure.c index 2762d918..dcfc4f04 100644 --- a/src/driver-roccat-kone-pure.c +++ b/src/driver-roccat-kone-pure.c @@ -603,9 +603,9 @@ roccat_write_macro(struct ratbag_button *button, } static int -roccat_write_button(struct ratbag_button *button, - const struct ratbag_button_action *action) +roccat_write_button(struct ratbag_button *button) { + const struct ratbag_button_action *action = &button->action; struct ratbag_profile *profile = button->profile; struct ratbag_device *device = profile->device; struct roccat_data *drv_data = ratbag_get_drv_data(device); @@ -639,8 +639,7 @@ roccat_write_button(struct ratbag_button *button, } static int -roccat_write_resolution_dpi(struct ratbag_resolution *resolution, - int dpi_x, int dpi_y) +roccat_write_resolution(struct ratbag_resolution *resolution) { struct ratbag_profile *profile = resolution->profile; struct ratbag_device *device = profile->device; @@ -649,7 +648,10 @@ roccat_write_resolution_dpi(struct ratbag_resolution *resolution, uint8_t *buf; int rc; - if (dpi_x < 100 || dpi_x > 5000 || dpi_x % 50) + const unsigned int dpi_x = resolution->dpi_x; + const unsigned int dpi_y = resolution->dpi_y; + + if (dpi_x < 200 || dpi_x > 8200 || dpi_x % 50) return -EINVAL; if (dpi_y < 100 || dpi_y > 5000 || dpi_y % 50) return -EINVAL; @@ -833,13 +835,50 @@ roccat_remove(struct ratbag_device *device) free(ratbag_get_drv_data(device)); } +static int +roccat_commit(struct ratbag_device *device) +{ + + int rc = 0; + struct ratbag_button *button = NULL; + struct ratbag_profile *profile = NULL; + struct ratbag_resolution *resolution = NULL; + + ratbag_device_for_each_profile(device, profile) { + if (!profile->dirty) + continue; + + rc = roccat_write_profile(profile); + if (rc) + return rc; + + ratbag_profile_for_each_resolution(profile, resolution) { + if (!resolution->dirty) + continue; + + rc = roccat_write_resolution(resolution); + if (rc) + return rc; + } + + ratbag_profile_for_each_button(profile, button) { + if (!button->dirty) + continue; + + rc = roccat_write_button(button); + if (rc) + return rc; + } + } + + return 0; +} + struct ratbag_driver roccat_kone_pure_driver = { .name = "Roccat Kone Pure", .id = "roccat-kone-pure", .probe = roccat_probe, .remove = roccat_remove, - .write_profile = roccat_write_profile, + .commit = roccat_commit, .set_active_profile = roccat_set_current_profile, - .write_button = roccat_write_button, - .write_resolution_dpi = roccat_write_resolution_dpi, };