Also provide rootfstype as kernel boot option
[qi-bootmenu/guyou.git] / gui.c
blobf3e93aa54458a2822ac635a952fe72b11805d729
1 #include <stdbool.h>
2 #include <Eina.h>
3 #include <Evas.h>
4 #include <Ecore.h>
5 #include <Ecore_Evas.h>
6 #include "config.h"
7 #include "kexec.h"
8 #include "util.h"
10 /* XXX: replace hardcoded values with runtime information */
11 #define SCREEN_WIDTH 480
12 #define SCREEN_HEIGHT 640
14 /* drawing related stuff */
15 static Ecore_Evas *ee;
16 static Evas *evas;
18 void poweroff(void *data, Evas *evas, Evas_Object *obj, void *event);
19 static void draw_item_border(Evas_Object *item);
21 typedef struct {
22 const char *text;
23 const char *logo;
24 void(*callback)(void*, Evas*, Evas_Object*, void *);
25 } MenuItem;
27 MenuItem menu[] = {
28 { "Power Off", POWEROFF_LOGO, poweroff },
31 void poweroff(void *data, Evas *evas, Evas_Object *item, void *event) {
32 draw_item_border(item);
33 system("poweroff");
36 static void bootitem_clicked(void *data, Evas *evas, Evas_Object *item, void *event) {
37 draw_item_border(item);
38 boot_kernel((BootItem*)data);
39 /* XXX: shouldn't be reached, display an error message? */
42 static bool canvas_init(){
43 if (!ecore_init() || !ecore_evas_init())
44 return false;
46 /* XXX: fixed dimensions */
47 if (getenv("DISPLAY"))
48 ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
49 else
50 ee = ecore_evas_fb_new(NULL, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
52 if (!ee)
53 return false;
55 ecore_evas_title_set(ee, APPNAME);
56 ecore_evas_borderless_set(ee, 0);
57 ecore_evas_show(ee);
59 evas = ecore_evas_get(ee);
60 evas_font_path_append(evas, FONT_PATH);
62 return true;
65 static void draw_item(const char *text, const char *logo, void(*callback)(void*, Evas*, Evas_Object*, void *),
66 void *data, int x, int y) {
68 Evas_Object *ebox, *elogo, *etext;
70 elogo = evas_object_image_add(evas);
71 evas_object_image_file_set(elogo, logo, NULL);
72 evas_object_image_fill_set(elogo, 0, 0, LOGO_WIDTH, LOGO_HEIGHT);
73 evas_object_resize(elogo, LOGO_WIDTH, LOGO_HEIGHT);
74 evas_object_show(elogo);
76 etext = evas_object_text_add(evas);
77 evas_object_text_font_set(etext, FONT, FONT_SIZE);
78 evas_object_text_text_set(etext, text);
79 evas_object_show(etext);
81 ebox = evas_object_box_add(evas);
82 evas_object_box_align_set(ebox, 0, 0.5);
83 evas_object_box_padding_set(ebox, 10, 10);
84 evas_object_move(ebox, x, y);
85 evas_object_resize(ebox, SCREEN_WIDTH, LOGO_HEIGHT);
86 evas_object_box_append(ebox, elogo);
87 evas_object_box_append(ebox, etext);
88 evas_object_event_callback_add(ebox, EVAS_CALLBACK_MOUSE_UP, callback, data);
90 evas_object_show(ebox);
93 static void draw_item_border(Evas_Object *item) {
94 Evas_Object *eline;
95 Evas_Coord x, y, w, h;
96 evas_object_geometry_get(item, &x, &y, &w, &h);
97 eline = evas_object_line_add(evas);
98 evas_object_line_xy_set(eline, x, y, x+w, y);
99 evas_object_show(eline);
100 eline = evas_object_line_add(evas);
101 evas_object_line_xy_set(eline, x, y, x, y+h);
102 evas_object_show(eline);
103 eline = evas_object_line_add(evas);
104 evas_object_line_xy_set(eline, x+w, y, x+w, y+h);
105 evas_object_show(eline);
106 eline = evas_object_line_add(evas);
107 evas_object_line_xy_set(eline, x, y+h, x+w, y+h);
108 evas_object_show(eline);
111 int gui(int argc, char **argv) {
113 if (!canvas_init()) {
114 eprint("Couldn't init GUI\n");
115 return 1;
118 /* search for system images to boot and display them in a list */
119 Eina_List *l, *systems = scan_system();
120 int i, y = 0;
121 BootItem *s;
123 EINA_LIST_FOREACH(systems, l, s) {
124 draw_item(s->dev, s->logo, bootitem_clicked, s, 0, y);
125 y += LOGO_HEIGHT;
128 /* add pre defined menu entries */
129 for (i = 0; i < countof(menu); i++) {
130 draw_item(menu[i].text, menu[i].logo, menu[i].callback, NULL, 0, y);
131 y += LOGO_HEIGHT;
134 ecore_main_loop_begin();
136 return 0;