ui/ncurses: in lockdown ensure system reboot in ncurses menu exit
[petitboot] / ui / twin / pbt-scr.c
index 3a5a70bc48128662170cc0e393d7a37b952b8b70..c360047cb5879ca7bce16e4629f46da7031f0cad 100644 (file)
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#if defined(HAVE_CONFIG_H)
 #include "config.h"
-#define _GNU_SOURCE
+#endif
+
 #include <assert.h>
 
 #include <string.h>
@@ -136,7 +138,7 @@ twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen,
        raw_background = twin_jpeg_to_pixmap(filename, TWIN_ARGB32);
 
        if (!raw_background) {
-               pb_log("%s: loading image '%s' failed\n", __func__, filename);
+               pb_log_fn("loading image '%s' failed\n", filename);
 
                /* Fallback to a default pattern */
 
@@ -156,7 +158,7 @@ twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen,
                                tscreen->width,
                                tscreen->height);
        if (!scaled_background) {
-               pb_log("%s: scale '%s' failed\n", __func__, filename);
+               pb_log_fn("scale '%s' failed\n", filename);
                twin_pixmap_destroy(raw_background);
                return twin_make_pattern();
        }
@@ -222,7 +224,7 @@ retry:
        new.icon = twin_png_to_pixmap(filename, TWIN_ARGB32);
 
        if (!new.icon) {
-               pb_log("%s: loading image '%s' failed\n", __func__, filename);
+               pb_log_fn("loading image '%s' failed\n", filename);
 
                if (filename == default_icon_file)
                        return NULL;
@@ -361,14 +363,16 @@ static int pbt_twin_waiter_cb(struct pbt_twin_ctx *twin_ctx)
 
 static void pbt_scr_destructor(struct pbt_scr *scr)
 {
-       pb_log("%s\n", __func__);
+       pb_debug("%s\n", __func__);
 
        twin_x11_destroy(scr->twin_ctx.x11);
        // FIXME: need cursor cleanup???
        memset(scr, 0, sizeof(*scr));
 }
 
-struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
+struct pbt_scr *pbt_scr_init(void *talloc_ctx,
+       struct waitset *waitset,
+       enum pbt_twin_backend backend,
        unsigned int width, unsigned int height,
        const char *filename_background,
        twin_bool_t (*scr_event_cb)(twin_screen_t *tscreen,
@@ -380,7 +384,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
        assert(backend && backend < 3);
 
        if (!scr) {
-               pb_log("%s: alloc pbt_scr failed.\n", __func__);
+               pb_log_fn("alloc pbt_scr failed.\n");
                goto fail_alloc;
        }
 
@@ -391,37 +395,37 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
        scr->twin_ctx.backend = backend;
 
        if (backend == pbt_twin_x11) {
-               pb_log("%s: using twin x11 backend.\n", __func__);
+               pb_log_fn("using twin x11 backend.\n");
                assert(width > 100);
                assert(height > 100);
 
 #if !defined(HAVE_LIBTWIN_TWIN_X11_H)
                assert(0);
 #else
-               scr->twin_ctx.x11 = twin_x11_create_ext(XOpenDisplay(0), width,
-                       height, 0);
+               scr->twin_ctx.x11 = twin_x11_create_ext(XOpenDisplay(NULL),
+                       width, height, 0);
 
                if (!scr->twin_ctx.x11) {
-                       pb_log("%s: twin_x11_create_ext failed.\n", __func__);
+                       pb_log_fn("twin_x11_create_ext failed.\n");
                        perror("failed to create twin x11 context\n");
                        goto fail_ctx_create;
                }
 
-               pb_log("%s: x11: %p\n", __func__, scr->twin_ctx.x11);
+               pb_debug("%s: x11: %p\n", __func__, scr->twin_ctx.x11);
 
                assert(scr->twin_ctx.x11->screen);
                scr->tscreen = scr->twin_ctx.x11->screen;
                waiter_fd = ConnectionNumber(scr->twin_ctx.x11->dpy);
 #endif
        } else if (backend == pbt_twin_fbdev) {
-               pb_log("%s: using twin fbdev backend.\n", __func__);
+               pb_log_fn("using twin fbdev backend.\n");
 #if !defined(HAVE_LIBTWIN_TWIN_FBDEV_H)
                assert(0);
 #else
                scr->twin_ctx.fbdev = twin_fbdev_create_ext(-1, SIGUSR1, 0);
 
                if (!scr->twin_ctx.fbdev) {
-                       pb_log("%s: twin_fbdev_create_ext failed.\n", __func__);
+                       pb_log_fn("twin_fbdev_create_ext failed.\n");
                        perror("failed to create twin fbdev context\n");
                        goto fail_ctx_create;
                }
@@ -441,8 +445,8 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
 
        assert(waiter_fd != -1);
 
-       waiter_register(waiter_fd, WAIT_IN, (void *)pbt_twin_waiter_cb,
-               &scr->twin_ctx);
+       waiter_register_io(waitset, waiter_fd, WAIT_IN,
+                       (void *)pbt_twin_waiter_cb, &scr->twin_ctx);
 
        return scr;