From 29365cd10eb760b345f16497418447aef1fd0999 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 3 Jun 2023 19:14:54 +0200 Subject: [PATCH] fix some x11 stuff --- libs/wl/init.c | 4 +--- libs/wl/wayland.c | 13 ++++++++++--- libs/wl/wayland.h | 1 + spmenu.c | 6 ++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/libs/wl/init.c b/libs/wl/init.c index 2ae448b..65e26a4 100644 --- a/libs/wl/init.c +++ b/libs/wl/init.c @@ -27,9 +27,7 @@ void handle_wl(void) { init_disp(&state); if (no_display) { - protocol = 0; - handle(); - return; + die("spmenu: failed to connect to wayland display"); } create_layer(&state, "spmenu"); diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index fa1834a..2d240d8 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -491,14 +491,21 @@ int roundtrip(struct state *state) { } } +int connect_display(struct state *state) { + state->display = wl_display_connect(NULL); + + if (state->display) { + return 0; + } else { + return 1; + } +} + /* If this function returns 1, something went wrong. * This may be that the user is using X11, or a compositor like Mutter. * In this case, it may be a good idea to fall back to X11. */ int init_disp(struct state *state) { - state->display = wl_display_connect(NULL); - - // Open display if (!state->display) { return 1; } else { diff --git a/libs/wl/wayland.h b/libs/wl/wayland.h index 3f87975..d54de54 100644 --- a/libs/wl/wayland.h +++ b/libs/wl/wayland.h @@ -129,6 +129,7 @@ static void buttonpress_wl(uint32_t button, double ex, double ey); static int is_correct_modifier(struct state *state, char *modifier); static int roundtrip(struct state *state); static int init_disp(struct state *state); +static int connect_display(struct state *state); static int init_keys(struct state *state); static int create_layer(struct state *state, char *name); static int anchor_layer(struct state *state, int position); diff --git a/spmenu.c b/spmenu.c index e0c1846..28f8c9d 100644 --- a/spmenu.c +++ b/spmenu.c @@ -472,6 +472,12 @@ void handle(void) { eventloop_x11(); // function is a loop which checks X11 events and calls other functions accordingly #if USEWAYLAND } else { + if (connect_display(&state)) { + protocol = 0; + handle(); + return; + } + loadhistory(); store_image_vars();