]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to send messages on window creation and deletion to the registrar service
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 13 May 2018 01:22:28 +0000 (21:22 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 13 May 2018 01:22:28 +0000 (21:22 -0400)
lib/x11.c

index 4ab4fb5911520da4a81d6a81ced79af6660fa490..8735b0e819b77cecf7e8f538f5e3d1d874d96319 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -45,7 +45,7 @@ struct XWin {
 };
 
 /******************************************************************************/
-
+static Atom XA_REGISTER, XA_DEREGISTER;
 static struct XWin X;
 static int KeyBtnState;
 static WinRegion Focused = EDIT;
@@ -146,6 +146,22 @@ static void x11_window(char* name) {
     X.gc = XCreateGC(X.display, X.self, GCForeground|GCGraphicsExposures, &gcv);
 }
 
+static void tide_send(char* type) {
+    XEvent ev;
+    memset(&ev, 0, sizeof (ev));
+    Atom xa_registrar = XInternAtom(X.display, "TIDE_REGISTRAR", 0);
+    Window regwin = XGetSelectionOwner(X.display, xa_registrar);
+    if (None != regwin) {
+        ev.xclient.type = ClientMessage;
+        ev.xclient.window = X.self;
+        ev.xclient.message_type = xa_registrar;
+        ev.xclient.format = 32;
+        ev.xclient.data.l[0] = XInternAtom(X.display, type, 0);
+        XSendEvent(X.display, regwin, False, NoEventMask, &ev);
+        XFlush(X.display);
+    }
+}
+
 /******************************************************************************/
 
 static uint32_t special_keys(uint32_t key) {
@@ -557,7 +573,7 @@ void win_save(char* path) {
 
 void win_loop(void) {
     XMapWindow(X.display, X.self);
-    XFlush(X.display);
+    tide_send("ADD");
     job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
     while (1) {
         job_poll(Timeout);
@@ -567,8 +583,10 @@ void win_loop(void) {
 
 void win_quit(void) {
     static uint64_t before = 0;
-    if ((win_buf(EDIT)->status != MODIFIED) || (X.now - before) <= (uint64_t)ClickTime)
+    if ((win_buf(EDIT)->status != MODIFIED) || (X.now - before) <= (uint64_t)ClickTime) {
+        tide_send("DEL");
         exit(0);
+    }
     before = X.now;
 }