Exemple #1
0
static int
ratbag_cmd_resolution_active_get(const struct ratbag_cmd *cmd,
				 struct ratbag *ratbag,
				 struct ratbag_cmd_options *options,
				 int argc, char **argv)
{
	struct ratbag_profile *profile;
	struct ratbag_resolution *resolution = NULL;
	int num_resolutions;
	int active_resolution = -1;
	int i;
	int rc = SUCCESS;

	profile = options->profile;

	num_resolutions = ratbag_profile_get_num_resolutions(profile);

	for (i = 0; i < num_resolutions && active_resolution < 0; i++) {
		resolution = ratbag_profile_get_resolution(profile, i);
		if (ratbag_resolution_is_active(resolution))
			active_resolution = i;

		ratbag_resolution_unref(resolution);
	}

	if (active_resolution < 0) {
		error("BUG: Unable to find active resolution\n");
		rc = ERR_DEVICE;
	}

	if (rc == SUCCESS)
		printf("%d\n", active_resolution);

	return rc;
}
Exemple #2
0
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);
}
Exemple #3
0
static inline struct ratbag_resolution *
ratbag_cmd_get_active_resolution(struct ratbag_profile *profile)
{
	struct ratbag_resolution *resolution = NULL;
	int i;

	for (i = 0; i < ratbag_profile_get_num_resolutions(profile); i++) {
		resolution = ratbag_profile_get_resolution(profile, i);
		if (ratbag_resolution_is_active(resolution))
			return resolution;

		ratbag_resolution_unref(resolution);
		resolution = NULL;
	}

	if (!resolution)
		error("Failed to retrieve the active resolution\n");

	return NULL;
}
Exemple #4
0
static int
ratbag_cmd_info(const struct ratbag_cmd *cmd,
		struct ratbag *ratbag,
		struct ratbag_cmd_options *options,
		int argc, char **argv)
{
	struct ratbag_device *device;
	struct ratbag_profile *profile;
	struct ratbag_button *button;
	char *action;
	int num_profiles, num_buttons;
	int i, j, b;

	device = options->device;

	printf("Device '%s'\n", ratbag_device_get_name(device));

	printf("Capabilities:");
	if (ratbag_device_has_capability(device,
					 RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION))
		printf(" res");
	if (ratbag_device_has_capability(device,
					 RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE))
		printf(" profile");
	if (ratbag_device_has_capability(device,
					 RATBAG_DEVICE_CAP_BUTTON_KEY))
		printf(" btn-key");
	if (ratbag_device_has_capability(device,
					 RATBAG_DEVICE_CAP_BUTTON_MACROS))
		printf(" btn-macros");
	printf("\n");

	num_buttons = ratbag_device_get_num_buttons(device);
	printf("Number of buttons: %d\n", num_buttons);

	num_profiles = ratbag_device_get_num_profiles(device);
	printf("Profiles supported: %d\n", num_profiles);

	for (i = 0; i < num_profiles; i++) {
		int dpi, rate;
		profile = ratbag_device_get_profile(device, i);
		if (!profile)
			continue;

		printf("  Profile %d%s\n", i,
		       ratbag_profile_is_active(profile) ? " (active)" : "");
		printf("    Resolutions:\n");
		for (j = 0; j < ratbag_profile_get_num_resolutions(profile); j++) {
			struct ratbag_resolution *res;

			res = ratbag_profile_get_resolution(profile, j);
			dpi = ratbag_resolution_get_dpi(res);
			rate = ratbag_resolution_get_report_rate(res);
			if (dpi == 0)
				printf("      %d: <disabled>\n", j);
			else if (ratbag_resolution_has_capability(res,
								  RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION))
				printf("      %d: %dx%ddpi @ %dHz%s%s\n", j,
				       ratbag_resolution_get_dpi_x(res),
				       ratbag_resolution_get_dpi_y(res),
				       rate,
				       ratbag_resolution_is_active(res) ? " (active)" : "",
				       ratbag_resolution_is_default(res) ? " (default)" : "");
			else
				printf("      %d: %ddpi @ %dHz%s%s\n", j, dpi, rate,
				       ratbag_resolution_is_active(res) ? " (active)" : "",
				       ratbag_resolution_is_default(res) ? " (default)" : "");

			ratbag_resolution_unref(res);
		}

		for (b = 0; b < num_buttons; b++) {
			enum ratbag_button_type type;

			button = ratbag_profile_get_button(profile, b);
			type = ratbag_button_get_type(button);
			action = button_action_to_str(button);
			printf("    Button: %d type %s is mapped to '%s'\n",
			       b, button_type_to_str(type), action);
			free(action);
			button = ratbag_button_unref(button);
		}

		profile = ratbag_profile_unref(profile);
	}

	return SUCCESS;
}
Exemple #5
0
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);
}
Exemple #6
0
static inline bool
ratbag_sanity_check_device(struct ratbag_device *device)
{
	struct ratbag *ratbag = device->ratbag;
	struct ratbag_profile *profile = NULL;
	bool has_active = false;
	unsigned int nres;
	bool rc = false;

	/* arbitrary number: max 16 profiles, does any mouse have more? but
	 * since we have num_profiles unsigned, it also checks for
	 * accidental negative */
	if (device->num_profiles == 0 || device->num_profiles > 16) {
		log_bug_libratbag(ratbag,
				  "%s: invalid number of profiles (%d)\n",
				  device->name,
				  device->num_profiles);
		goto out;
	}

	ratbag_device_for_each_profile(device, profile) {
		struct ratbag_resolution *resolution;

		/* Allow max 1 active profile */
		if (profile->is_active) {
			if (has_active) {
				log_bug_libratbag(ratbag,
						  "%s: multiple active profiles\n",
						  device->name);
				goto out;
			}
			has_active = true;
		}

		nres = ratbag_profile_get_num_resolutions(profile);
		if (nres == 0 || nres > 16) {
				log_bug_libratbag(ratbag,
						  "%s: invalid number of resolutions (%d)\n",
						  device->name,
						  nres);
				goto out;
		}

		ratbag_profile_for_each_resolution(profile, resolution) {
			unsigned int vals[300];
			unsigned int nvals = ARRAY_LENGTH(vals);

			if (!ratbag_device_has_capability(device, RATBAG_DEVICE_CAP_RESOLUTION))
				break;

			nvals = ratbag_resolution_get_dpi_list(resolution, vals, nvals);
			if (nvals == 0) {
				log_bug_libratbag(ratbag,
						  "%s: invalid dpi list\n",
						  device->name);
				goto out;
			}

			nvals = ratbag_resolution_get_report_rate_list(resolution, vals, nvals);
			if (nvals == 0) {
				log_bug_libratbag(ratbag,
						  "%s: invalid report rate list\n",
						  device->name);
				goto out;
			}
		}
	}