mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
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 <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -9,6 +9,41 @@
|
||||
#include <shared.h>
|
||||
%}
|
||||
#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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user