};
struct XWin {
+ Bool running;
Time now;
Window root;
Display* display;
}
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;
static void xselquit(XEvent* e) {
xselclear(e);
- exit(0);
+ if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text)
+ X.running = False;
}
static void xselnotify(XEvent* e) {
}
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);
}
}
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;
}