forked from drath/libratbag
ratbagd: expose resolutions on the bus
Add a new property to profiles that exposes resolutions on the bus. We simply expose a dictionary entry for each resolution, hence, we can easily extend it in the future. However, we avoid the full overhead of real dbus objects, as there is no real need for it. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
@@ -40,9 +40,140 @@ struct ratbagd_profile {
|
||||
char *path;
|
||||
};
|
||||
|
||||
static int ratbagd_profile_get_resolutions(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_profile *profile = userdata;
|
||||
unsigned int i, n_resolutions;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_open_container(reply, 'a', "a{sv}");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
n_resolutions = ratbag_profile_get_num_resolutions(profile->lib_profile);
|
||||
for (i = 0; i < n_resolutions; ++i) {
|
||||
struct ratbag_resolution *resolution;
|
||||
bool cap_separate_xy_resolution;
|
||||
unsigned int dpi_x, dpi_y, report_rate;
|
||||
|
||||
resolution = ratbag_profile_get_resolution(profile->lib_profile, i);
|
||||
if (!resolution)
|
||||
continue;
|
||||
|
||||
cap_separate_xy_resolution = ratbag_resolution_has_capability(resolution,
|
||||
RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION);
|
||||
report_rate = ratbag_resolution_get_report_rate(resolution);
|
||||
if (cap_separate_xy_resolution) {
|
||||
dpi_x = ratbag_resolution_get_dpi_x(resolution);
|
||||
dpi_y = ratbag_resolution_get_dpi_y(resolution);
|
||||
} else {
|
||||
dpi_x = ratbag_resolution_get_dpi(resolution);
|
||||
}
|
||||
|
||||
r = sd_bus_message_open_container(reply, 'a', "{sv}");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (cap_separate_xy_resolution) {
|
||||
r = sd_bus_message_append(reply, "{sv}",
|
||||
"dpi-x", "u", dpi_x);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(reply, "{sv}",
|
||||
"dpi-y", "u", dpi_y);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
r = sd_bus_message_append(reply, "{sv}",
|
||||
"dpi", "u", dpi_x);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_message_append(reply, "{sv}",
|
||||
"report-rate", "u", report_rate);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_close_container(reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return sd_bus_message_close_container(reply);
|
||||
}
|
||||
|
||||
static int ratbagd_profile_get_active_resolution(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_profile *profile = userdata;
|
||||
unsigned int i, n_resolutions, k = 0;
|
||||
|
||||
n_resolutions = ratbag_profile_get_num_resolutions(profile->lib_profile);
|
||||
for (i = 0; i < n_resolutions; ++i) {
|
||||
struct ratbag_resolution *resolution;
|
||||
|
||||
resolution = ratbag_profile_get_resolution(profile->lib_profile, i);
|
||||
if (!resolution)
|
||||
continue;
|
||||
if (!ratbag_resolution_is_active(resolution)) {
|
||||
++k;
|
||||
continue;
|
||||
}
|
||||
|
||||
return sd_bus_message_append(reply, "u", k);
|
||||
}
|
||||
|
||||
return sd_bus_message_append(reply, "u", (unsigned int)-1);
|
||||
}
|
||||
|
||||
static int ratbagd_profile_get_default_resolution(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_profile *profile = userdata;
|
||||
unsigned int i, n_resolutions, k = 0;
|
||||
|
||||
n_resolutions = ratbag_profile_get_num_resolutions(profile->lib_profile);
|
||||
for (i = 0; i < n_resolutions; ++i) {
|
||||
struct ratbag_resolution *resolution;
|
||||
|
||||
resolution = ratbag_profile_get_resolution(profile->lib_profile, i);
|
||||
if (!resolution)
|
||||
continue;
|
||||
if (!ratbag_resolution_is_default(resolution)) {
|
||||
++k;
|
||||
continue;
|
||||
}
|
||||
|
||||
return sd_bus_message_append(reply, "u", k);
|
||||
}
|
||||
|
||||
return sd_bus_message_append(reply, "u", (unsigned int)-1);
|
||||
}
|
||||
|
||||
const sd_bus_vtable ratbagd_profile_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_profile, index), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Resolutions", "aa{sv}", ratbagd_profile_get_resolutions, 0, 0),
|
||||
SD_BUS_PROPERTY("ActiveResolution", "u", ratbagd_profile_get_active_resolution, 0, 0),
|
||||
SD_BUS_PROPERTY("DefaultResolution", "u", ratbagd_profile_get_default_resolution, 0, 0),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user