From: Michael D. Lowis Date: Mon, 10 Sep 2018 17:30:35 +0000 (-0400) Subject: update title based on file path X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f24a52c3929e7d5bfc276425d22c8ac13a3d7d19;p=projs%2Ftide.git update title based on file path --- diff --git a/inc/win.h b/inc/win.h index ff80b3e..7bccab1 100644 --- 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); diff --git a/lib/x11.c b/lib/x11.c index 064bcda..9aecb7f 100644 --- 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); diff --git a/tests/lib/win.c b/tests/lib/win.c index c4a2881..e4b8e55 100644 --- a/tests/lib/win.c +++ b/tests/lib/win.c @@ -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 16ea030..9ab21e3 100644 --- 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 */