From cb4be02a561bee5361440f2ac739b75ea25e5f64 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Oct 2017 11:58:16 +1000 Subject: [PATCH] tools: add 'rate get-all' to the resolutions Signed-off-by: Peter Hutterer --- src/libratbag.i | 8 ++++++++ tools/ratbagc.py | 7 +++++++ tools/ratbagctl.1 | 3 +++ tools/ratbagctl.in | 12 ++++++++++++ tools/ratbagctl.test.in | 9 +++++++++ 5 files changed, 39 insertions(+) diff --git a/src/libratbag.i b/src/libratbag.i index eca72dda..d398b115 100644 --- a/src/libratbag.i +++ b/src/libratbag.i @@ -44,6 +44,14 @@ } /* END OF custom typemap for handling ratbag_resolution_get_dpi_list */ + +/* custom typemap for handling ratbag_resolution_get_report_rate_list */ +/* We re-use the ratbag_resolution_get_dpi_list typemap */ +%typemap(in) (unsigned int *rates, size_t nrates) = (unsigned int *resolutions, size_t nres); +%typemap(argout) (unsigned int *rates, size_t nrates) = (unsigned int *resolutions, size_t nres); +%typemap(freearg) (unsigned int *rates, size_t nrates) = (unsigned int *resolutions, size_t nres); +/* END OF custom typemap for handling ratbag_resolution_get_report_rate_list */ + /* Parse the header file to generate wrappers */ %include "libratbag.h" %include "libratbag-enums.h" diff --git a/tools/ratbagc.py b/tools/ratbagc.py index f273db53..14a602cd 100644 --- a/tools/ratbagc.py +++ b/tools/ratbagc.py @@ -484,6 +484,13 @@ class RatbagdResolution(metaclass=MetaRatbag): n = libratbag.ratbag_resolution_get_dpi_list(self._res, dpis) return dpis[:n] + @property + def report_rates(self): + """The list of supported report rates""" + rates = [0 for i in range(300)] + n = libratbag.ratbag_resolution_get_report_rate_list(self._res, rates) + return rates[:n] + @property def is_active(self): """True if this is the currently active resolution, False diff --git a/tools/ratbagctl.1 b/tools/ratbagctl.1 index ad34d731..6ac496fc 100644 --- a/tools/ratbagctl.1 +++ b/tools/ratbagctl.1 @@ -112,6 +112,9 @@ resolution of the active profile if none are given. .B rate get Print the report rate in ms .TP 8 +.B rate get-all +Print the supported report rates in ms +.TP 8 .B rate set N Set the report rate in N ms .SH Button Commands diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index b73a4c2e..aba86939 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -450,6 +450,12 @@ def func_report_rate_get(r, args): print(r.report_rate) +def func_report_rate_get_all(r, args): + r, p, d = find_resolution(r, args) + rates = r.report_rates + print(" ".join([str(x) for x in rates])) + + def func_report_rate_set(r, args): r, p, d = find_resolution(r, args) r.report_rate = args.rate_n @@ -915,6 +921,12 @@ active resolution of the active profile if none are given.""", help_str: 'Show current report rate', func: func_report_rate_get, }, + { + of_type: command, + name: 'get-all', + help_str: 'Show all available report rates', + func: func_report_rate_get_all, + }, { of_type: command, name: 'set', diff --git a/tools/ratbagctl.test.in b/tools/ratbagctl.test.in index ffb1ba13..1f9d45b1 100755 --- a/tools/ratbagctl.test.in +++ b/tools/ratbagctl.test.in @@ -353,6 +353,15 @@ class TestRatbagCtlReportRate(TestRatbagCtl): self.launch_fail_test(command + " 1 test_device") self.launch_fail_test(command + " test_device X") + def test_rate_get_all(self): + rate_list = "500 1000" + command = "rate get-all" + r = self.launch_good_test(command + " test_device") + self.assertEqual(r, rate_list) + self.setProfile(1) + r = self.launch_good_test(command + " test_device") + self.assertEqual(r, rate_list) + def test_rate_set(self): command = "rate set" r = self.launch_good_test("rate get test_device")