ncurses/nc-cui: musl libc fixes
[petitboot] / ui / twin / pbt-scr.c
index 3d10b9590a8c6e783fb603722f53d2781c39d864..e10cab10e9c9b817d8ae06a5c6a9da27b6c8fac7 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>
@@ -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,
@@ -378,8 +382,6 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
        int waiter_fd = -1;
 
        assert(backend && backend < 3);
-       assert(width > 100);
-       assert(height > 100);
 
        if (!scr) {
                pb_log("%s: alloc pbt_scr failed.\n", __func__);
@@ -394,11 +396,14 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
 
        if (backend == pbt_twin_x11) {
                pb_log("%s: using twin x11 backend.\n", __func__);
+               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__);
@@ -406,7 +411,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
                        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;
@@ -440,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;