toaruos/apps/yutani-query.c

87 lines
1.9 KiB
C
Raw Permalink Normal View History

/**
* @brief yutani-query - Query display server information
2018-08-14 11:13:38 +03:00
*
* At the moment, this only supports querying the display
* resolution. An older version of this application had
* support for getting the default font names, but the
* font server is no longer part of the compositor, so
* that functionality doesn't make sense here.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2015-2018 K. Lange
2018-08-14 11:13:38 +03:00
*/
2018-02-25 17:05:57 +03:00
#include <stdio.h>
2018-08-08 12:15:34 +03:00
#include <unistd.h>
2018-02-25 17:05:57 +03:00
2018-03-19 05:38:11 +03:00
#include <toaru/yutani.h>
2018-02-25 17:05:57 +03:00
yutani_t * yctx;
2018-11-07 06:44:19 +03:00
int quiet = 0;
2018-02-25 17:05:57 +03:00
void show_usage(int argc, char * argv[]) {
printf(
"yutani-query - show misc. information about the display system\n"
"\n"
2018-08-08 05:46:10 +03:00
"usage: %s [-r?]\n"
2018-02-25 17:05:57 +03:00
"\n"
" -r \033[3mprint display resoluton\033[0m\n"
" -e \033[3mask compositor to reload extensions\033[0m\n"
2018-02-25 17:05:57 +03:00
" -? \033[3mshow this help text\033[0m\n"
"\n", argv[0]);
}
int show_resolution(void) {
2018-11-07 06:44:19 +03:00
if (!yctx) {
if (!quiet) printf("(not connected)\n");
return 1;
}
2018-04-25 08:03:29 +03:00
printf("%dx%d\n", (int)yctx->display_width, (int)yctx->display_height);
2018-02-25 17:05:57 +03:00
return 0;
}
2018-11-07 06:44:19 +03:00
int reload(void) {
2018-02-25 17:05:57 +03:00
if (!yctx) {
2018-11-07 06:44:19 +03:00
if (!quiet) printf("(not connected)\n");
2018-02-25 17:05:57 +03:00
return 1;
}
2018-11-07 06:44:19 +03:00
yutani_special_request(yctx, NULL, YUTANI_SPECIAL_REQUEST_RELOAD);
return 0;
}
int main(int argc, char * argv[]) {
yctx = yutani_init();
2018-08-08 05:46:10 +03:00
int opt;
2018-11-07 06:44:19 +03:00
while ((opt = getopt(argc, argv, "?qre")) != -1) {
2018-08-08 05:46:10 +03:00
switch (opt) {
2018-11-07 06:44:19 +03:00
case 'q':
quiet = 1;
break;
/* Legacy options */
2018-08-08 05:46:10 +03:00
case 'r':
return show_resolution();
case 'e':
2018-11-07 06:44:19 +03:00
return reload();
2018-08-08 05:46:10 +03:00
case '?':
show_usage(argc,argv);
return 0;
2018-02-25 17:05:57 +03:00
}
}
if (optind < argc) {
if (!strcmp(argv[optind], "resolution")) {
return show_resolution();
} else if (!strcmp(argv[optind], "reload")) {
return reload();
} else {
fprintf(stderr, "%s: unsupported command: %s\n", argv[0], argv[optind]);
return 1;
}
}
2018-02-25 17:05:57 +03:00
return 0;
}