]> git.mdlowis.com Git - projs/tide.git/commitdiff
reworked window search and cleanup to ensure invalid windows get cleaned up when...
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 22 Jan 2019 20:33:39 +0000 (15:33 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 22 Jan 2019 20:33:39 +0000 (15:33 -0500)
TODO.md
foo [deleted file]
src/registrar.c

diff --git a/TODO.md b/TODO.md
index 7b175484c133b5191e4081467b85a8c114e3dc7b..2c285b565722699a649a09506aebc18bb101f32e 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -4,9 +4,7 @@
 
 ## STAGING
 
-* registrar: doesnt match open windows when new file created and is then opened for edit or line number
 * registrar: group by hostname or group env var in registrar
-* registrar: should cleanup invalid windows
 * tide: gap buffer does not handle UTF-8 currently
 
 ## BACKLOG
diff --git a/foo b/foo
deleted file mode 100644 (file)
index 28d44e9..0000000
--- a/foo
+++ /dev/null
@@ -1 +0,0 @@
-asdsad
\ No newline at end of file
index c396d5bd7aec9d2a963814636bf6434c85a3da6c..564e2ce0a483318073ce00c537467b9474a55643 100644 (file)
@@ -90,7 +90,14 @@ void win_open(XConf* x, Window winid, char* path, char* addr) {
     if (!path) return;
     /* search for an existing window */
     for (TWindow* win = Windows; win; win = win->next) {
+        /* refresh the filepath and crudely determine if window still valid */
+        free(win->path);
+        win->path = NULL;
+        char* file = readprop(x, win->win, "FILE", XA_STRING, NULL);
+        win->path = (file ? file : NULL);
+
         if (win->path && !strcmp(win->path, path)) {
+            /* double check that the window id didnt get reassigned to a non-tide window */
             printf("found open window: 0x%x '%s'\n", (unsigned int)win->win, win->path);
             x11_error_clear();
             char* type = readprop(x, win->win, "TIDE", XA_STRING, 0);
@@ -139,6 +146,20 @@ void clientmsg(XConf* x, XEvent* e) {
     XSync(x->display, False);
 }
 
+TWindow* win_sweep(TWindow* win) {
+    if (win) {
+        if (win->path) {
+            win->next = win_sweep(win->next);
+        } else {
+            TWindow* dead = win;
+            printf("swept: %x\n", (unsigned)win->win);
+            win = win_sweep(win->next);
+            free(dead);
+        }
+    }
+    return win;
+}
+
 void propnotify(XConf* x, XEvent* e) {
     (void)e;
     Atom type;
@@ -159,18 +180,7 @@ void propnotify(XConf* x, XEvent* e) {
     XSync(x->display, False);
 
     /* cleanup any invalid windows */
-//    TWindow* wins = Windows;
-//    Windows = NULL;
-//    while (wins && wins->next) {
-//        TWindow* curr = wins;
-//        wins = curr->next;
-//        if (!wins->path) {
-//            free(curr);
-//        } else {
-//            curr->next = Windows;
-//            Windows = curr;
-//        }
-//    }
+    Windows = win_sweep(Windows);
 }
 
 void find_windows(XConf* x) {