2018-04-21 11:26:38 +03:00
|
|
|
/* vim: ts=4 sw=4 noexpandtab
|
|
|
|
*
|
|
|
|
* Menu tool / eventual library.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2018-04-24 14:25:42 +03:00
|
|
|
#include <math.h>
|
2018-04-21 11:26:38 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <toaru/yutani.h>
|
|
|
|
#include <toaru/graphics.h>
|
|
|
|
#include <toaru/sdf.h>
|
|
|
|
#include <toaru/hashmap.h>
|
|
|
|
#include <toaru/list.h>
|
2018-04-24 14:58:41 +03:00
|
|
|
#include <toaru/menu.h>
|
2018-04-21 11:26:38 +03:00
|
|
|
|
|
|
|
static yutani_t * yctx;
|
|
|
|
|
2018-04-24 14:58:41 +03:00
|
|
|
static void _action_callback(struct MenuEntry * self) {
|
|
|
|
struct MenuEntry_Normal * _self = (void *)self;
|
2018-04-24 14:25:42 +03:00
|
|
|
|
|
|
|
fprintf(stdout, "%s\n", _self->action);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2018-04-21 11:26:38 +03:00
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "%s: expected argument\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
yctx = yutani_init();
|
|
|
|
|
|
|
|
/* Create menu from file. */
|
2018-04-24 14:58:41 +03:00
|
|
|
struct MenuSet * menu = menu_set_from_description(argv[1], _action_callback);
|
|
|
|
menu_show(menu_set_get_root(menu), yctx);
|
2018-04-21 11:26:38 +03:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
yutani_msg_t * m = yutani_poll(yctx);
|
2018-04-24 15:19:06 +03:00
|
|
|
if (menu_process_event(yctx, m)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2018-04-24 15:32:39 +03:00
|
|
|
free(m);
|
2018-04-21 11:26:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|