From 72f28ed0b36e4f8a6a8732788bc557533ac36ab1 Mon Sep 17 00:00:00 2001 From: Ilia Bozhinov Date: Mon, 18 May 2020 13:07:29 +0200 Subject: [PATCH] examples: make output-power-management oneshot by default --- examples/output-power-management.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/output-power-management.c b/examples/output-power-management.c index 19bc8271b..8d91c6c05 100644 --- a/examples/output-power-management.c +++ b/examples/output-power-management.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -72,7 +73,8 @@ static const struct wl_registry_listener registry_listener = { static const char usage[] = "usage: output-power-management [options...]\n" " -h: show this help message\n" " -e: turn outputs on\n" - " -d: turn outputs off\n"; + " -d: turn outputs off\n" + " -w: continuously watch for power mode changes\n"; int main(int argc, char *argv[]) { wl_list_init(&outputs); @@ -80,7 +82,8 @@ int main(int argc, char *argv[]) { int opt; enum zwlr_output_power_v1_mode mode = ZWLR_OUTPUT_POWER_V1_MODE_ON; - while ((opt = getopt(argc, argv, "edh")) != -1) { + bool watch_mode = false; + while ((opt = getopt(argc, argv, "edhw")) != -1) { switch (opt) { case 'e': mode = ZWLR_OUTPUT_POWER_V1_MODE_ON; @@ -88,6 +91,9 @@ int main(int argc, char *argv[]) { case 'd': mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF; break; + case 'w': + watch_mode = true; + break; case 'h': default: fprintf(stderr, usage); @@ -126,6 +132,11 @@ int main(int argc, char *argv[]) { mode); } + if (!watch_mode) { + wl_display_roundtrip(display); + return EXIT_SUCCESS; + } + while (wl_display_dispatch(display) != -1) { // nothing to see here, please move along }