From 39af89fc32ec1ba5041d05d5b06be0dcc9a2efc9 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 9 Oct 2018 10:01:34 -0400 Subject: [PATCH] fork into the background when in selection daemon mode --- lib/x11.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/x11.c b/lib/x11.c index 06f19dc..099bdb6 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -22,6 +22,7 @@ struct XSel { }; struct XWin { + Bool running; Time now; Window root; Display* display; @@ -429,7 +430,7 @@ static void xbtnmotion(XEvent* e) { } static void xselclear(XEvent* e) { - struct XSel* sel = selfetch(e->xselectionrequest.selection); + struct XSel* sel = selfetch(e->xselectionclear.selection); if (!sel) return; free(sel->text); sel->text = NULL; @@ -437,7 +438,8 @@ static void xselclear(XEvent* e) { static void xselquit(XEvent* e) { xselclear(e); - exit(0); + if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text) + X.running = False; } static void xselnotify(XEvent* e) { @@ -611,10 +613,11 @@ void win_update(int ms) { } void win_loop(void) { + X.running = True; XMapWindow(X.display, X.self); tide_send("ADD"); job_spawn(ConnectionNumber(X.display), xupdate, 0, 0); - while (1) { + while (X.running) { win_update(Timeout); } } @@ -625,8 +628,11 @@ void win_quit(void) { tide_send("DEL"); EventHandlers[SelectionClear] = xselquit; XUnmapWindow(X.display, X.self); - if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text) - exit(0); + if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text) { + X.running = False; + } else { + if (fork()) exit(0); /* fork into background if we still have selection */ + } } before = X.now; } -- 2.52.0