Fix includes for new libtwin
[petitboot] / petitboot.c
index 44e1cc87b394755b0cdc745725e07916a6f028be..dfb293cbcd1bbf5f3bfd14f34db30450dc82a792 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <unistd.h>
@@ -7,19 +8,23 @@
 
 #include <linux/input.h>
 
+#undef _USE_X11
+
 #include <libtwin/twin.h>
-#include <libtwin/twin_fbdev.h>
-#include <libtwin/twin_x11.h>
 #include <libtwin/twin_linux_mouse.h>
 #include <libtwin/twin_png.h>
 
 #include "petitboot.h"
 #include "petitboot-paths.h"
 
-#define _USE_X11
-
-static twin_fbdev_t *pboot_fbdev;
+#ifdef _USE_X11
+#include <libtwin/twin_x11.h>
 static twin_x11_t *pboot_x11;
+#else
+#include <libtwin/twin_fbdev.h>
+static twin_fbdev_t *pboot_fbdev;
+#endif
+
 static twin_screen_t *pboot_screen;
 
 #define PBOOT_LEFT_PANE_SIZE           200
@@ -76,6 +81,7 @@ struct _pboot_option
        twin_pixmap_t   *badge;
        twin_pixmap_t   *cache;
        twin_rect_t     box;
+       void            *data;
 };
 
 struct _pboot_device
@@ -400,6 +406,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)
 {
@@ -412,6 +429,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:
@@ -425,6 +445,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;
                }
@@ -437,7 +459,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;
@@ -474,6 +496,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;
 }
 
@@ -832,9 +855,11 @@ int pboot_remove_device(const char *dev_id)
 
 static void exitfunc(void)
 {
+#ifndef _USE_X11
        if (pboot_fbdev)
                twin_fbdev_destroy(pboot_fbdev);
        pboot_fbdev = NULL;
+#endif
 }
 
 static void sigint(int sig)
@@ -867,7 +892,6 @@ int main(int argc, char **argv)
        }
        pboot_screen = pboot_fbdev->screen;
        twin_linux_mouse_create(NULL, pboot_screen);
-#endif
 
        if (pboot_fbdev != NULL) {
                char *cursor_path = artwork_pathname("cursor");
@@ -879,6 +903,7 @@ int main(int argc, char **argv)
                                twin_get_default_cursor(&pboot_cursor_hx,
                                                        &pboot_cursor_hy);
        }
+#endif
 
        /* Set background pixmap */
        background_path = artwork_pathname("background.png");
@@ -903,8 +928,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 ();