~emersion/public-inbox

wlr-randr: add a new special output name `*` v1 PROPOSED

Leonardo Hernández Hernández: 1
 add a new special output name `*`

 1 files changed, 23 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/35081/mbox | git am -3
Learn more about email & git

[PATCH wlr-randr] add a new special output name `*` Export this patch

this allow control all outputs at the same time
the most common use case is turn on/off all outputs

Signed-off-by: Leonardo Hernández Hernández <leohdz172@protonmail.com>
---
 main.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/main.c b/main.c
index 87f94af..a228066 100644
--- a/main.c
+++ b/main.c
@@ -623,7 +623,7 @@ static const char usage[] =
	"usage: wlr-randr [options…]\n"
	"--help\n"
	"--dryrun\n"
	"--output <name>\n"
	"--output <name>|*\n"
	"  --on\n"
	"  --off\n"
	"  --toggle\n"
@@ -661,7 +661,7 @@ int main(int argc, char *argv[]) {
		}
	}

	bool changed = false, dry_run = false;
	bool changed = false, dry_run = false, all = false;
	struct randr_head *current_head = NULL;
	while (1) {
		int option_index = -1;
@@ -679,12 +679,18 @@ int main(int argc, char *argv[]) {
		const char *value = optarg;
		if (strcmp(name, "output") == 0) {
			bool found = false;
			wl_list_for_each(current_head, &state.heads, link) {
				if (strcmp(current_head->name, value) == 0) {
					found = true;
					break;
			if (strcmp("*", value) == 0) {
				found = true;
				all = true;
			} else {
				wl_list_for_each(current_head, &state.heads, link) {
					if (strcmp(current_head->name, value) == 0) {
						found = true;
						break;
					}
				}
			}

			if (!found) {
				fprintf(stderr, "unknown output %s\n", value);
				return EXIT_FAILURE;
@@ -692,13 +698,21 @@ int main(int argc, char *argv[]) {
		} else if (strcmp(name, "dryrun") == 0) {
			dry_run = true;
		} else { // output sub-option
			if (current_head == NULL) {
			if (current_head == NULL && !all) {
				fprintf(stderr, "no --output specified before --%s\n", name);
				return EXIT_FAILURE;
			}

			if (!parse_output_arg(current_head, name, value)) {
				return EXIT_FAILURE;
			if (all) {
				wl_list_for_each(current_head, &state.heads, link) {
					if (!parse_output_arg(current_head, name, value)) {
						return EXIT_FAILURE;
					}
				}
			} else {
				if (!parse_output_arg(current_head, name, value)) {
					return EXIT_FAILURE;
				}
			}

			changed = true;
-- 
2.37.3