From cddfed13d0847bc62474fd3fadbafba834856ac7 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 10 Aug 2017 16:26:51 -0400 Subject: [PATCH] added property getters and setters and auto-set property with file path of file in given window --- inc/x11.h | 3 +++ lib/win.c | 3 +++ lib/x11.c | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/inc/x11.h b/inc/x11.h index 3279b8c..dd820ba 100644 --- 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); diff --git a/lib/win.c b/lib/win.c index 96779fa..cc63663 100644 --- 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) { diff --git a/lib/x11.c b/lib/x11.c index c089a96..e184b83 100644 --- 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; +} -- 2.49.0