X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=petitboot.c;h=d566e3ff188ff7dc8cf20d36b52545fe2e894205;hp=e69353e6b4dbc0bd70300d6d70507a5fd87749f0;hb=f2c8c4c7197ef61c0378ffbeb4649d28bfcbba06;hpb=f60d0b2e7dbd9d85980866c68d0f87b6bc823663 diff --git a/petitboot.c b/petitboot.c index e69353e..d566e3f 100644 --- a/petitboot.c +++ b/petitboot.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,18 +8,24 @@ #include +#undef _USE_X11 + #include -#include -#include #include #include +#include #include "petitboot.h" +#include "petitboot-paths.h" -#define _USE_X11 - -static twin_fbdev_t *pboot_fbdev; +#ifdef _USE_X11 +#include static twin_x11_t *pboot_x11; +#else +#include +static twin_fbdev_t *pboot_fbdev; +#endif + static twin_screen_t *pboot_screen; #define PBOOT_LEFT_PANE_SIZE 200 @@ -75,6 +82,7 @@ struct _pboot_option twin_pixmap_t *badge; twin_pixmap_t *cache; twin_rect_t box; + void *data; }; struct _pboot_device @@ -399,6 +407,17 @@ static void pboot_rpane_mousetrack(twin_coord_t x, twin_coord_t y) pboot_rpane->mouse_target = candidate; } +static void pboot_choose_option(void) +{ + pboot_device_t *dev = pboot_devices[pboot_dev_sel]; + pboot_option_t *opt = &dev->options[pboot_rpane->focus_curindex]; + + LOG("Selected device %s\n", opt->title); + + /* Give user feedback, make sure errors and panics will be seen */ + pboot_exec_option(opt->data); +} + static twin_bool_t pboot_rpane_event (twin_window_t *window, twin_event_t *event) { @@ -411,6 +430,9 @@ static twin_bool_t pboot_rpane_event (twin_window_t *window, pboot_rpane_mousetrack(event->u.pointer.x, event->u.pointer.y); return TWIN_TRUE; case TwinEventButtonDown: + pboot_select_rpane(); + pboot_rpane_mousetrack(event->u.pointer.x, event->u.pointer.y); + pboot_choose_option(); case TwinEventButtonUp: return TWIN_TRUE; case TwinEventKeyDown: @@ -424,6 +446,8 @@ static twin_bool_t pboot_rpane_event (twin_window_t *window, case KEY_LEFT: pboot_select_lpane(); return TWIN_TRUE; + case KEY_ENTER: + pboot_choose_option(); default: break; } @@ -436,7 +460,7 @@ static twin_bool_t pboot_rpane_event (twin_window_t *window, int pboot_add_option(int devindex, const char *title, - const char *subtitle, twin_pixmap_t *badge) + const char *subtitle, twin_pixmap_t *badge, void *data) { pboot_device_t *dev; pboot_option_t *opt; @@ -473,6 +497,7 @@ int pboot_add_option(int devindex, const char *title, index * PBOOT_RIGHT_OPTION_STRIDE; opt->box.bottom = opt->box.top + PBOOT_RIGHT_OPTION_HEIGHT; + opt->data = data; return index; } @@ -829,11 +854,58 @@ int pboot_remove_device(const char *dev_id) return TWIN_TRUE; } +static void pboot_make_background(void) +{ + twin_pixmap_t *filepic, *scaledpic; + const char *background_path; + + /* Set background pixmap */ + LOG("loading background..."); + background_path = artwork_pathname("background.jpg"); + filepic = twin_jpeg_to_pixmap(background_path, TWIN_ARGB32); + LOG("%s\n", filepic ? "ok" : "failed"); + + if (filepic == NULL) + return; + + if (pboot_screen->height == filepic->height && + pboot_screen->width == filepic->width) + scaledpic = filepic; + else { + twin_fixed_t sx, sy; + twin_operand_t srcop; + + scaledpic = twin_pixmap_create(TWIN_ARGB32, + pboot_screen->width, + pboot_screen->height); + if (scaledpic == NULL) { + twin_pixmap_destroy(filepic); + return; + } + sx = twin_fixed_div(twin_int_to_fixed(filepic->width), + twin_int_to_fixed(pboot_screen->width)); + sy = twin_fixed_div(twin_int_to_fixed(filepic->height), + twin_int_to_fixed(pboot_screen->height)); + + twin_matrix_scale(&filepic->transform, sx, sy); + srcop.source_kind = TWIN_PIXMAP; + srcop.u.pixmap = filepic; + twin_composite(scaledpic, 0, 0, &srcop, 0, 0, + NULL, 0, 0, TWIN_SOURCE, + pboot_screen->width, pboot_screen->height); + twin_pixmap_destroy(filepic); + + } + twin_screen_set_background(pboot_screen, scaledpic); +} + static void exitfunc(void) { +#ifndef _USE_X11 if (pboot_fbdev) twin_fbdev_destroy(pboot_fbdev); pboot_fbdev = NULL; +#endif } static void sigint(int sig) @@ -842,9 +914,34 @@ static void sigint(int sig) syscall(__NR_exit); } +static void usage(const char *progname) +{ + fprintf(stderr, "Usage: %s [-u] [-h]\n", progname); +} + int main(int argc, char **argv) { - twin_pixmap_t *pic; + int c; + int udev_trigger = 0; + + for (;;) { + c = getopt(argc, argv, "u::h"); + if (c == -1) + break; + + switch (c) { + case 'u': + udev_trigger = 1; + break; + case 'h': + usage(argv[0]); + return EXIT_SUCCESS; + default: + fprintf(stderr, "Unknown option '%c'\n", c); + usage(argv[0]); + return EXIT_FAILURE; + } + } atexit(exitfunc); signal(SIGINT, sigint); @@ -865,10 +962,10 @@ int main(int argc, char **argv) } pboot_screen = pboot_fbdev->screen; twin_linux_mouse_create(NULL, pboot_screen); -#endif if (pboot_fbdev != NULL) { - pboot_cursor = twin_load_X_cursor("artwork/cursor", 2, + char *cursor_path = artwork_pathname("cursor"); + pboot_cursor = twin_load_X_cursor(cursor_path, 2, &pboot_cursor_hx, &pboot_cursor_hy); if (pboot_cursor == NULL) @@ -876,20 +973,17 @@ int main(int argc, char **argv) twin_get_default_cursor(&pboot_cursor_hx, &pboot_cursor_hy); } +#endif /* Set background pixmap */ - LOG("loading background..."); - pic = twin_png_to_pixmap("artwork/background.png", TWIN_ARGB32); - LOG("%s\n", pic ? "ok" : "failed"); - if (pic) - twin_screen_set_background(pboot_screen, pic); + pboot_make_background(); /* Init more stuffs */ pboot_create_panels(); twin_window_queue_paint(pboot_lpane->window); twin_window_queue_paint(pboot_rpane->window); - if (!pboot_start_device_discovery()) { + if (!pboot_start_device_discovery(udev_trigger)) { LOG("Couldn't start device discovery!\n"); return 1; } @@ -899,8 +993,10 @@ int main(int argc, char **argv) pboot_screen->event_filter = pboot_event_filter; /* Console switch */ +#ifndef _USE_X11 if (pboot_fbdev) twin_fbdev_activate(pboot_fbdev); +#endif /* Process events */ twin_dispatch ();