examples: make output-power-management oneshot by default

This commit is contained in:
Ilia Bozhinov 2020-05-18 13:07:29 +02:00 committed by Simon Ser
parent 2176c63856
commit 72f28ed0b3
1 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -72,7 +73,8 @@ static const struct wl_registry_listener registry_listener = {
static const char usage[] = "usage: output-power-management [options...]\n" static const char usage[] = "usage: output-power-management [options...]\n"
" -h: show this help message\n" " -h: show this help message\n"
" -e: turn outputs on\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[]) { int main(int argc, char *argv[]) {
wl_list_init(&outputs); wl_list_init(&outputs);
@ -80,7 +82,8 @@ int main(int argc, char *argv[]) {
int opt; int opt;
enum zwlr_output_power_v1_mode mode = enum zwlr_output_power_v1_mode mode =
ZWLR_OUTPUT_POWER_V1_MODE_ON; 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) { switch (opt) {
case 'e': case 'e':
mode = ZWLR_OUTPUT_POWER_V1_MODE_ON; mode = ZWLR_OUTPUT_POWER_V1_MODE_ON;
@ -88,6 +91,9 @@ int main(int argc, char *argv[]) {
case 'd': case 'd':
mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF; mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF;
break; break;
case 'w':
watch_mode = true;
break;
case 'h': case 'h':
default: default:
fprintf(stderr, usage); fprintf(stderr, usage);
@ -126,6 +132,11 @@ int main(int argc, char *argv[]) {
mode); mode);
} }
if (!watch_mode) {
wl_display_roundtrip(display);
return EXIT_SUCCESS;
}
while (wl_display_dispatch(display) != -1) { while (wl_display_dispatch(display) != -1) {
// nothing to see here, please move along // nothing to see here, please move along
} }