From: Michael D. Lowis Date: Tue, 9 Oct 2018 14:01:34 +0000 (-0400) Subject: fork into the background when in selection daemon mode X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=39af89fc32ec1ba5041d05d5b06be0dcc9a2efc9;p=projs%2Ftide.git fork into the background when in selection daemon mode --- 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; }