From d0d340003a834bfd4cffc8cc55f1816e5506e5ac Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 23 Jan 2019 10:23:30 -0500 Subject: [PATCH] update registrar to group windows by hostname --- TODO.md | 3 ++- src/edit.c | 3 +++ src/registrar.c | 16 +++++++++++----- src/tide.c | 5 +++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 2c285b5..80d388d 100644 --- a/TODO.md +++ b/TODO.md @@ -2,9 +2,10 @@ ## VERIFYING +* registrar: group by hostname or group env var in registrar + ## STAGING -* registrar: group by hostname or group env var in registrar * tide: gap buffer does not handle UTF-8 currently ## BACKLOG diff --git a/src/edit.c b/src/edit.c index c210f37..982ed59 100644 --- a/src/edit.c +++ b/src/edit.c @@ -32,9 +32,12 @@ void prop_set(XConf* x, Window win, char* prop, char* value) { } void edit_file(XConf* x, Window registrar, char* path, char* addr, int force) { + char host[8192]; char* rpath = realpath(path, NULL); prop_set(x, x->self, "FILE", (rpath ? rpath : path)); prop_set(x, x->self, "ADDR", addr); + if (!gethostname(host, sizeof(host))) + prop_set(x, x->self, "HOST", host); free(rpath); XChangeProperty( x->display, registrar, XA_OPEN, XA_WINDOW, 32, PropModeAppend, diff --git a/src/registrar.c b/src/registrar.c index 564e2ce..7509dba 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -7,6 +7,7 @@ typedef struct TWindow { struct TWindow* next; Window win; char* path; + char* host; } TWindow; char* ARGV0; @@ -55,6 +56,7 @@ void win_add(XConf* x, Window id) { win->win = id; win->next = Windows; win->path = path; + win->host = readprop(x, id, "HOST", XA_STRING, NULL); Windows = win; } @@ -70,6 +72,8 @@ void win_del(Window id) { if (w && w->next) { TWindow* deadite = w->next; w->next = deadite->next; + free(deadite->path), deadite->path = NULL; + free(deadite->host), deadite->host = NULL; free(deadite); } } @@ -86,7 +90,7 @@ void win_send(XConf* x, Window from, Window to, int mask, char* atom, size_t val XSendEvent(x->display, to, False, mask, &ev); } -void win_open(XConf* x, Window winid, char* path, char* addr) { +void win_open(XConf* x, Window winid, char* path, char* addr, char* host) { if (!path) return; /* search for an existing window */ for (TWindow* win = Windows; win; win = win->next) { @@ -96,15 +100,16 @@ void win_open(XConf* x, Window winid, char* path, char* addr) { char* file = readprop(x, win->win, "FILE", XA_STRING, NULL); win->path = (file ? file : NULL); - if (win->path && !strcmp(win->path, path)) { + if (win->host && !strcmp(win->host, host) && + 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); if (!type || x11_error_get()) { puts("window invalid, marking for cleanup"); - free(win->path); - win->path = NULL; + free(win->path), win->path = NULL; + free(win->host), win->host = NULL; free(type); break; } else { @@ -173,7 +178,8 @@ void propnotify(XConf* x, XEvent* e) { for (Window* win = (Window*)data; datalen && win && *win; win++, datalen--) { char* file = readprop(x, *win, "FILE", XA_STRING, NULL); char* addr = readprop(x, *win, "ADDR", XA_STRING, NULL); - win_open(x, *win, file, (addr ? addr : "0")); + char* host = readprop(x, *win, "HOST", XA_STRING, NULL); + win_open(x, *win, file, (addr ? addr : "0"), host); if(file) XFree(file); if(addr) XFree(addr); } diff --git a/src/tide.c b/src/tide.c index f3d7d3d..51579b6 100644 --- a/src/tide.c +++ b/src/tide.c @@ -934,6 +934,11 @@ int main(int argc, char** argv) { free(path); } + /* set host name property */ + char host[8192]; + if (!gethostname(host, sizeof(host))) + win_prop_set("HOST", "host", host); + /* now create the window and start the event loop */ xupdate(NULL); win_loop(); -- 2.52.0