menu.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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) 2018 K. Lange
  5. *
  6. * menu - Display a menu file and print actions
  7. *
  8. * This is a demo of the menu library, and can be used by scripts
  9. * to display menus. It may be broken without a root window for
  10. * the menus to display on, though?
  11. */
  12. #include <stdio.h>
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include <math.h>
  16. #include <sys/types.h>
  17. #include <toaru/yutani.h>
  18. #include <toaru/graphics.h>
  19. #include <toaru/sdf.h>
  20. #include <toaru/hashmap.h>
  21. #include <toaru/list.h>
  22. #include <toaru/menu.h>
  23. static yutani_t * yctx;
  24. static void _action_callback(struct MenuEntry * self) {
  25. struct MenuEntry_Normal * _self = (void *)self;
  26. fprintf(stdout, "%s\n", _self->action);
  27. exit(0);
  28. }
  29. int main(int argc, char * argv[]) {
  30. if (argc < 2) {
  31. fprintf(stderr, "%s: expected argument\n", argv[0]);
  32. return 1;
  33. }
  34. yctx = yutani_init();
  35. /* Create menu from file. */
  36. struct MenuSet * menu = menu_set_from_description(argv[1], _action_callback);
  37. menu_show(menu_set_get_root(menu), yctx);
  38. while (1) {
  39. yutani_msg_t * m = yutani_poll(yctx);
  40. if (menu_process_event(yctx, m)) {
  41. return 1;
  42. }
  43. free(m);
  44. }
  45. return 0;
  46. }