]> git.mdlowis.com Git - projs/tide.git/commitdiff
update title based on file path
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 10 Sep 2018 17:30:35 +0000 (13:30 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 10 Sep 2018 17:30:35 +0000 (13:30 -0400)
inc/win.h
lib/x11.c
tests/lib/win.c
tide.c

index ff80b3e76f9c6dd6aad93d1099df1e5396f2b728..7bccab16bc7521c32f43dc838d69689f7617c92c 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -130,9 +130,9 @@ typedef struct {
     int h, w;
 } drawcsr;
 
-void win_init(char* title, KeyBinding* bindings);
+void win_init(KeyBinding* bindings);
+void win_title(char* path);
 void win_prop_set(char* xname, char* ename, char* value);
-void win_save(char* path);
 void win_update(int ms);
 void win_loop(void);
 void win_quit(void);
index 064bcdac0128124b74c3cd606b778dc0c48f97be..9aecb7fd77b54d11bc8bacb38bbb62b34137d665 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -526,7 +526,7 @@ static void xupdate(Job* job) {
 
 /******************************************************************************/
 
-void win_init(char* title, KeyBinding* bindings) {
+void win_init(KeyBinding* bindings) {
     Keys = bindings;
     view_init(&Regions[TAGS], NULL);
     view_init(&Regions[EDIT], NULL);
@@ -544,7 +544,7 @@ void win_init(char* title, KeyBinding* bindings) {
     X.screen   = DefaultScreen(X.display);
     X.depth    = DefaultDepth(X.display, X.screen);
     font_load(FontString);
-    x11_window("tide");
+    x11_window("unnamed");
     /* initialize selection atoms */
     for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++)
         Selections[i].atom = XInternAtom(X.display, Selections[i].name, 0);
@@ -557,6 +557,10 @@ void win_init(char* title, KeyBinding* bindings) {
     buf_logclear(&(view->buffer));
 }
 
+void win_title(char* path) {
+    XStoreName(X.display, X.self, path);
+}
+
 void win_prop_set(char* xname, char* ename, char* value) {
     Atom propname = XInternAtom(X.display, xname, 0);
     XChangeProperty(X.display, X.self, propname, XA_STRING, 8, PropModeReplace,
@@ -564,17 +568,6 @@ void win_prop_set(char* xname, char* ename, char* value) {
     if (ename) setenv(ename, value, 1);
 }
 
-void win_save(char* path) {
-    View* view = win_view(EDIT);
-    if (!path) path = view->buffer.path;
-    if (!path) return;
-    path = realpath(path, NULL);
-    free(view->buffer.path);
-    view->buffer.path = path;
-    buf_save(&(view->buffer));
-    win_prop_set("TIDE_FILE", "file", path);
-}
-
 void win_update(int ms) {
     job_poll(Timeout);
     xupdate(NULL);
index c4a2881f2198967919b36a23cb25adfbf6c873e4..e4b8e55bb0c507cdd8cdb9eb5e003dddf168b84c 100644 (file)
@@ -75,7 +75,7 @@ static void send_resize(int width, int height) {
 TEST_SUITE(WinTests) {
     /* Suite Setup
      *************************************************************************/
-    win_init("tide", Bindings);
+    win_init(Bindings);
 
     /* Focus Events
      *************************************************************************/
diff --git a/tide.c b/tide.c
index 16ea030d5b82353eaace2c63556385ecbac73c5d..9ab21e36ccf06dc72c9811a95903c556bd0a7d1b 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -258,7 +258,15 @@ static void quit(char* arg) {
 }
 
 static void put(char* arg) {
-    win_save(arg);
+    View* view = win_view(EDIT);
+    if (!arg) arg = view->buffer.path;
+    if (!arg) return;
+    char* path = realpath(arg, NULL);
+    free(view->buffer.path);
+    view->buffer.path = path;
+    buf_save(&(view->buffer));
+    win_title(path);
+    win_prop_set("TIDE_FILE", "file", path);
 }
 
 static void save(char* arg) {
@@ -473,13 +481,16 @@ int main(int argc, char** argv) {
     if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
 
     /* create the window */
-    win_init("tide", Bindings);
+    win_init(Bindings);
 
     /* if we still have args left we're going to open it in this instance */
     if (*argv) {
         char* path = realpath(*argv, NULL);
         view_init(win_view(EDIT), path);
+        win_title(path);
         win_prop_set("TIDE_FILE", "file", path);
+    } else {
+        win_title("*scratch*");
     }
 
     /* now create the window and start the event loop */