]> git.mdlowis.com Git - projs/tide.git/commitdiff
added property getters and setters and auto-set property with file path of file in...
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Aug 2017 20:26:51 +0000 (16:26 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Aug 2017 20:26:51 +0000 (16:26 -0400)
inc/x11.h
lib/win.c
lib/x11.c

index 3279b8c3632c9bb7547b3717958eca51d1ac99a5..dd820babf91bd31a10029a18bb376ab0f8a3336d 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -147,3 +147,6 @@ void x11_draw_utf8(XFont font, int fg, int bg, int x, int y, char* str);
 
 bool x11_sel_get(int selid, void(*cbfn)(char*));
 bool x11_sel_set(int selid, char* str);
+
+void x11_prop_set(char* name, char* val);
+char* x11_prop_get(char* name);
index 96779faec1fbd66ca277cb5364f24001b7854fc4..cc63663c8e9c9b3427bb08e0d381262be2d3b060 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -68,6 +68,8 @@ static void win_update(int xfd, void* data) {
 void win_load(char* path) {
     View* view = win_view(EDIT);
     view_init(view, path, view->buffer.errfn);
+    if (path)
+        x11_prop_set("TIDE_FILE", path);
 }
 
 void win_save(char* path) {
@@ -78,6 +80,7 @@ void win_save(char* path) {
     free(view->buffer.path);
     view->buffer.path = path;
     buf_save(&(view->buffer));
+    x11_prop_set("TIDE_FILE", path);
 }
 
 void win_loop(void) {
index c089a961d7a150b37e7b4a8341a703fb6418aa1f..e184b83ad2425d2b8eaab1cac1bc49df9cbace86 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -638,7 +638,21 @@ bool x11_sel_set(int selid, char* str) {
     }
 }
 
-/* Tide Server Communication
+/* Tide Server Communication and Property Handling
  *****************************************************************************/
 static void propnotify(XEvent* evnt) {
 }
+
+void x11_prop_set(char* name, char* val) {
+    Atom prop = XInternAtom(X.display, name, False);
+    XChangeProperty(X.display, X.self, prop, XA_STRING, 8, PropModeReplace, val, strlen(val)+1);
+}
+
+char* x11_prop_get(char* name) {
+    Atom rtype, prop = XInternAtom(X.display, name, False);
+    unsigned long format = 0, nitems = 0, nleft = 0, nread = 0;
+    unsigned char* data = NULL;
+    XGetWindowProperty(X.display, X.self, prop, 0, -1, False, XA_STRING, &rtype,
+                       &format, &nitems, &nleft, &data);
+    return data;
+}