]> git.mdlowis.com Git - projs/tide.git/commitdiff
fork into the background when in selection daemon mode
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 9 Oct 2018 14:01:34 +0000 (10:01 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 9 Oct 2018 14:01:34 +0000 (10:01 -0400)
lib/x11.c

index 06f19dcff24cb4ac12c004b506b1f7a4b3245110..099bdb6f686ea90554d6b73fc70231873cd3b12a 100644 (file)
--- 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;
 }