yutani-query: add quiet option

This commit is contained in:
K. Lange 2018-11-07 12:44:19 +09:00
parent ace77aee9c
commit 1604c43769

View File

@ -17,6 +17,7 @@
#include <toaru/yutani.h> #include <toaru/yutani.h>
yutani_t * yctx; yutani_t * yctx;
int quiet = 0;
void show_usage(int argc, char * argv[]) { void show_usage(int argc, char * argv[]) {
printf( printf(
@ -31,24 +32,35 @@ void show_usage(int argc, char * argv[]) {
} }
int show_resolution(void) { int show_resolution(void) {
if (!yctx) {
if (!quiet) printf("(not connected)\n");
return 1;
}
printf("%dx%d\n", (int)yctx->display_width, (int)yctx->display_height); printf("%dx%d\n", (int)yctx->display_width, (int)yctx->display_height);
return 0; return 0;
} }
int reload(void) {
if (!yctx) {
if (!quiet) printf("(not connected)\n");
return 1;
}
yutani_special_request(yctx, NULL, YUTANI_SPECIAL_REQUEST_RELOAD);
return 0;
}
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
yctx = yutani_init(); yctx = yutani_init();
if (!yctx) {
printf("(not connected)\n");
return 1;
}
int opt; int opt;
while ((opt = getopt(argc, argv, "?re")) != -1) { while ((opt = getopt(argc, argv, "?qre")) != -1) {
switch (opt) { switch (opt) {
case 'q':
quiet = 1;
break;
case 'r': case 'r':
return show_resolution(); return show_resolution();
case 'e': case 'e':
yutani_special_request(yctx, NULL, YUTANI_SPECIAL_REQUEST_RELOAD); return reload();
return 0;
case '?': case '?':
show_usage(argc,argv); show_usage(argc,argv);
return 0; return 0;