yutani-query.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2015-2018 K. Lange
  5. *
  6. * yutani-query - Query display server information
  7. *
  8. * At the moment, this only supports querying the display
  9. * resolution. An older version of this application had
  10. * support for getting the default font names, but the
  11. * font server is no longer part of the compositor, so
  12. * that functionality doesn't make sense here.
  13. */
  14. #include <stdio.h>
  15. #include <unistd.h>
  16. #include <toaru/yutani.h>
  17. yutani_t * yctx;
  18. int quiet = 0;
  19. void show_usage(int argc, char * argv[]) {
  20. printf(
  21. "yutani-query - show misc. information about the display system\n"
  22. "\n"
  23. "usage: %s [-r?]\n"
  24. "\n"
  25. " -r \033[3mprint display resoluton\033[0m\n"
  26. " -e \033[3mask compositor to reload extensions\033[0m\n"
  27. " -? \033[3mshow this help text\033[0m\n"
  28. "\n", argv[0]);
  29. }
  30. int show_resolution(void) {
  31. if (!yctx) {
  32. if (!quiet) printf("(not connected)\n");
  33. return 1;
  34. }
  35. printf("%dx%d\n", (int)yctx->display_width, (int)yctx->display_height);
  36. return 0;
  37. }
  38. int reload(void) {
  39. if (!yctx) {
  40. if (!quiet) printf("(not connected)\n");
  41. return 1;
  42. }
  43. yutani_special_request(yctx, NULL, YUTANI_SPECIAL_REQUEST_RELOAD);
  44. return 0;
  45. }
  46. int main(int argc, char * argv[]) {
  47. yctx = yutani_init();
  48. int opt;
  49. while ((opt = getopt(argc, argv, "?qre")) != -1) {
  50. switch (opt) {
  51. case 'q':
  52. quiet = 1;
  53. break;
  54. /* Legacy options */
  55. case 'r':
  56. return show_resolution();
  57. case 'e':
  58. return reload();
  59. case '?':
  60. show_usage(argc,argv);
  61. return 0;
  62. }
  63. }
  64. if (optind < argc) {
  65. if (!strcmp(argv[optind], "resolution")) {
  66. return show_resolution();
  67. } else if (!strcmp(argv[optind], "reload")) {
  68. return reload();
  69. } else {
  70. fprintf(stderr, "%s: unsupported command: %s\n", argv[0], argv[optind]);
  71. return 1;
  72. }
  73. }
  74. return 0;
  75. }