]> git.mdlowis.com Git - projs/tide.git/commitdiff
update registrar to group windows by hostname
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 23 Jan 2019 15:23:30 +0000 (10:23 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 23 Jan 2019 15:23:30 +0000 (10:23 -0500)
TODO.md
src/edit.c
src/registrar.c
src/tide.c

diff --git a/TODO.md b/TODO.md
index 2c285b565722699a649a09506aebc18bb101f32e..80d388d229e7d30966a4fec89e2b2ee8523f2a18 100644 (file)
--- 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
index c210f37bdb721a2c1e6c2f05762e54603d5446e4..982ed59a6a184b1adc9fcbdd26005708eecd9c99 100644 (file)
@@ -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,
index 564e2ce0a483318073ce00c537467b9474a55643..7509dba8cb670f183ea24dc4513aededd6afcb0d 100644 (file)
@@ -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);
     }
index f3d7d3d40399a32e0682167e6705bc4da3f052a2..51579b60bc1c3de189d8109ba8f76764dc278e1d 100644 (file)
@@ -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();