From 336072773e5a94d357d1dd55d028d8fc70a289f9 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 22 Jan 2019 15:33:39 -0500 Subject: [PATCH] reworked window search and cleanup to ensure invalid windows get cleaned up when detected --- TODO.md | 2 -- foo | 1 - src/registrar.c | 34 ++++++++++++++++++++++------------ 3 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 foo diff --git a/TODO.md b/TODO.md index 7b17548..2c285b5 100644 --- 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 index 28d44e9..0000000 --- a/foo +++ /dev/null @@ -1 +0,0 @@ -asdsad \ No newline at end of file diff --git a/src/registrar.c b/src/registrar.c index c396d5b..564e2ce 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -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) { -- 2.51.0