From f1d20f1f3538f4df44757df40c8be966589212cb Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Mon, 16 Oct 2017 15:31:46 +0200 Subject: [PATCH] tools: ratbag-command.py: fix new resolutions list This one gets a little bit meesy given that the libratbag expects a C array. Provide some wrapping aound it and hope we won't have to do it again and again. Signed-off-by: Benjamin Tissoires --- src/libratbag.i | 35 +++++++++++++++++++++++++++++++++++ tools/ratbagc.py | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/src/libratbag.i b/src/libratbag.i index f3c5ced8..171d76b0 100644 --- a/src/libratbag.i +++ b/src/libratbag.i @@ -9,6 +9,41 @@ #include %} #define __attribute__(x) + +/* custom typemap for handling ratbag_resolution_get_dpi */ +%typemap(in) (unsigned int *resolutions, size_t nres) { + unsigned int i; + if (!PyList_Check($input)) { + PyErr_SetString(PyExc_ValueError, "Expecting a list"); + return NULL; + } + $2 = PyList_Size($input); + $1 = (unsigned int *) malloc(($2 + 1) * sizeof(unsigned int)); + for (i = 0; i < $2; i++) { + PyObject *s = PyList_GetItem($input, i); + if (!PyInt_Check(s)) { + free($1); + PyErr_SetString(PyExc_ValueError, "List items must be integers"); + return NULL; + } + $1[i] = PyInt_AsLong(s); + } + $1[i] = 0; +} + +%typemap(argout) (unsigned int *resolutions, size_t nres) { + unsigned int i; + for (i = 0; i < $2; i++) { + PyList_SetItem($input, i, PyInt_FromLong($1[i])); + } +} + +%typemap(freearg) (unsigned int *resolutions, size_t nres) { + if ($1) + free($1); +} +/* END OF custom typemap for handling ratbag_resolution_get_dpi */ + /* 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 13eb8984..f273db53 100644 --- a/tools/ratbagc.py +++ b/tools/ratbagc.py @@ -477,6 +477,13 @@ class RatbagdResolution(metaclass=MetaRatbag): """ libratbag.ratbag_resolution_set_report_rate(self._res, rate) + @property + def resolutions(self): + """The list of supported DPI values""" + dpis = [0 for i in range(300)] + n = libratbag.ratbag_resolution_get_dpi_list(self._res, dpis) + return dpis[:n] + @property def is_active(self): """True if this is the currently active resolution, False