Exemple #1
0
static int
ratbag_cmd_profile_disable(const struct ratbag_cmd *cmd,
			   struct ratbag *ratbag,
			   struct ratbag_cmd_options *options,
			   int argc, char **argv)
{
	int rc;

	if (!ratbag_device_has_capability(options->device,
					  RATBAG_DEVICE_CAP_DISABLE_PROFILE))
		return ERR_UNSUPPORTED;

	ratbag_profile_set_enabled(options->profile, false);
	rc = ratbag_device_commit(options->device);

	return rc ? ERR_DEVICE : SUCCESS;
}
Exemple #2
0
int
main(int argc, char **argv)
{
	struct ratbag *ratbag;
	const char *command;
	int rc = SUCCESS;
	struct ratbag_cmd_options options = {0};

	ratbag = ratbag_create_context(&interface, NULL);
	if (!ratbag) {
		rc = ERR_DEVICE;
		error("Failed to initialize ratbag\n");
		goto out;
	}

	options.flags = 0;

	while (1) {
		int c;
		int option_index = 0;
		static struct option opts[] = {
			{ "verbose", 2, 0, OPT_VERBOSE },
			{ "help", 0, 0, OPT_HELP },
		};

		c = getopt_long(argc, argv, "+h", opts, &option_index);
		if (c == -1)
			break;
		switch(c) {
		case 'h':
		case OPT_HELP:
			usage();
			goto out;
		case OPT_VERBOSE:
			if (optarg && streq(optarg, "raw"))
				options.flags |= FLAG_VERBOSE_RAW;
			else
				options.flags |= FLAG_VERBOSE;
			break;
		default:
			goto out;
		}
	}

	if (optind >= argc) {
		rc = ERR_USAGE;
		goto out;
	}

	if (options.flags & FLAG_VERBOSE_RAW)
		ratbag_log_set_priority(ratbag, RATBAG_LOG_PRIORITY_RAW);
	else if (options.flags & FLAG_VERBOSE)
		ratbag_log_set_priority(ratbag, RATBAG_LOG_PRIORITY_DEBUG);

	argc -= optind;
	argv += optind;

	command = argv[0];
	rc = run_subcommand(command,
			    ratbag_commands,
			    ratbag,
			    &options,
			    argc, argv);

	if (options.device)
		rc = ratbag_device_commit(options.device);

out:
	ratbag_resolution_unref(options.resolution);
	ratbag_button_unref(options.button);
	ratbag_profile_unref(options.profile);
	ratbag_device_unref(options.device);
	ratbag_unref(ratbag);

	if (rc == ERR_USAGE)
		usage();

	return rc;
}