From 009a0b1a519cd20a80471f98e50afd7743515729 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 3 Jan 2012 20:19:17 +0000 Subject: [PATCH] Fork after the window is visible, not before --- i3lock.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/i3lock.c b/i3lock.c index 84c195d..f9255d7 100644 --- a/i3lock.c +++ b/i3lock.c @@ -63,6 +63,7 @@ static bool beep = false; static bool debug_mode = false; static bool dpms = false; static bool unlock_indicator = true; +static bool dont_fork = false; static struct ev_loop *main_loop; static struct ev_timer *clear_pam_wrong_timeout; static struct ev_timer *clear_indicator_timeout; @@ -710,6 +711,19 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) { continue; } + if (type == XCB_MAP_NOTIFY) { + if (!dont_fork) { + /* After the first MapNotify, we never fork again. We don’t + * expect to get another MapNotify, but better be sure… */ + dont_fork = true; + + /* In the parent process, we exit */ + if (fork() != 0) + exit(0); + } + continue; + } + if (type == XCB_MAPPING_NOTIFY) { handle_mapping_notify((xcb_mapping_notify_event_t*)event); continue; @@ -727,7 +741,6 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) { } int main(int argc, char *argv[]) { - bool dont_fork = false; char *username; #ifndef NOLIBCAIRO char *image_path = NULL; @@ -842,12 +855,6 @@ int main(int argc, char *argv[]) { xcb_connection_has_error(conn)) errx(EXIT_FAILURE, "Could not connect to X11, maybe you need to set DISPLAY?"); - if (!dont_fork) { - /* In the parent process, we exit */ - if (fork() != 0) - return 0; - } - /* if DPMS is enabled, check if the X server really supports it */ if (dpms) { xcb_dpms_capable_cookie_t dpmsc = xcb_dpms_capable(conn); -- 2.39.5