dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 8cf609f9cfc42abec324412986fd5125ba03ac84
parent 3a18d4dcd3dc15aef3e5b9332650e8d9a2b6fbde
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Sun, 12 Jun 2011 14:08:09 +0200

Group statusbar related variables into a struct

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
dvtm.c | 27++++++++++++++++++---------
statusbar.c | 59+++++++++++++++++++++++++++--------------------------------
2 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/dvtm.c b/dvtm.c @@ -97,7 +97,16 @@ typedef struct { Action action; } Cmd; -enum { BarTop, BarBot, BarOff }; +enum BarPos { BarTop, BarBot, BarOff }; +enum { ALIGN_LEFT, ALIGN_RIGHT }; + +typedef struct { + int fd; + char text[512]; + int pos; + unsigned short int h; + unsigned short int y; +} StatusBar; #define countof(arr) (sizeof(arr) / sizeof((arr)[0])) #define sstrlen(str) (sizeof(str) - 1) @@ -130,7 +139,6 @@ static void zoom(const char *args[]); static void lock(const char *key[]); static void togglerunall(const char *args[]); -enum { ALIGN_LEFT, ALIGN_RIGHT }; static void togglebar(const char *args[]); static void mouse_focus(const char *args[]); @@ -160,6 +168,7 @@ extern double mwfact; static Client *sel = NULL; double mwfact = MWFACT; static Layout *layout = layouts; +static StatusBar bar = { -1, "", BARPOS, 1, 0 }; static const char *shell; static bool need_screen_resize; static int width, height, scroll_buf_size = SCROLL_BUF_SIZE; @@ -855,8 +864,8 @@ setup() { static void cleanup() { endwin(); - if (statusfd > 0) - close(statusfd); + if (bar.fd > 0) + close(bar.fd); if (cmdfd > 0) close(cmdfd); if (cmdpath) @@ -938,7 +947,7 @@ parse_args(int argc, char *argv[]) { scroll_buf_size = atoi(argv[++arg]); break; case 's': - statusfd = open_or_create_fifo(argv[++arg]); + bar.fd = open_or_create_fifo(argv[++arg]); updatebarpos(); break; case 'c': @@ -1005,9 +1014,9 @@ main(int argc, char *argv[]) { nfds = cmdfd; } - if (statusfd != -1) { - FD_SET(statusfd, &rd); - nfds = max(nfds, statusfd); + if (bar.fd != -1) { + FD_SET(bar.fd, &rd); + nfds = max(nfds, bar.fd); } for (c = clients; c; ) { @@ -1059,7 +1068,7 @@ main(int argc, char *argv[]) { if (cmdfd != -1 && FD_ISSET(cmdfd, &rd)) handle_cmdfifo(); - if (statusfd != -1 && FD_ISSET(statusfd, &rd)) + if (bar.fd != -1 && FD_ISSET(bar.fd, &rd)) handle_statusbar(); for (c = clients; c; ) { diff --git a/statusbar.c b/statusbar.c @@ -1,36 +1,31 @@ -static int statusfd = -1; -static char stext[512]; -static int barpos = BARPOS; -static unsigned int bh = 1, by; - static void updatebarpos(void) { - by = 0; + bar.y = 0; wax = 0; way = 0; wah = height; - if (statusfd == -1) + if (bar.fd == -1) return; - if (barpos == BarTop) { - wah -= bh; - way += bh; - } else if (barpos == BarBot) { - wah -= bh; - by = wah; + if (bar.pos == BarTop) { + wah -= bar.h; + way += bar.h; + } else if (bar.pos == BarBot) { + wah -= bar.h; + bar.y = wah; } } static void drawbar() { - wchar_t wbuf[sizeof stext]; + wchar_t wbuf[sizeof bar.text]; int w, maxwidth = width - 2; - if (barpos == BarOff || !*stext) + if (bar.pos == BarOff || !bar.text[0]) return; curs_set(0); attrset(BAR_ATTR); wcolor_set(stdscr, madtty_color_get(BAR_FG, BAR_BG), NULL); - mvaddch(by, 0, '['); - if (mbstowcs(wbuf, stext, sizeof stext) == (size_t)-1) + mvaddch(bar.y, 0, '['); + if (mbstowcs(wbuf, bar.text, sizeof bar.text) == (size_t)-1) return; if ((w = wcswidth(wbuf, maxwidth)) == -1) return; @@ -38,12 +33,12 @@ drawbar() { for (int i = 0; i + w < maxwidth; i++) addch(' '); } - addstr(stext); + addstr(bar.text); if (BAR_ALIGN == ALIGN_LEFT) { for (; w < maxwidth; w++) addch(' '); } - mvaddch(by, width - 1, ']'); + mvaddch(bar.y, width - 1, ']'); attrset(NORMAL_ATTR); if (sel) curs_set(madtty_cursor(sel->term)); @@ -52,10 +47,10 @@ drawbar() { static void togglebar(const char *args[]) { - if (barpos == BarOff) - barpos = (BARPOS == BarOff) ? BarTop : BARPOS; + if (bar.pos == BarOff) + bar.pos = (BARPOS == BarOff) ? BarTop : BARPOS; else - barpos = BarOff; + bar.pos = BarOff; updatebarpos(); arrange(); drawbar(); @@ -65,21 +60,21 @@ static void handle_statusbar() { char *p; int r; - switch (r = read(statusfd, stext, sizeof stext - 1)) { + switch (r = read(bar.fd, bar.text, sizeof bar.text - 1)) { case -1: - strncpy(stext, strerror(errno), sizeof stext - 1); - stext[sizeof stext - 1] = '\0'; - statusfd = -1; + strncpy(bar.text, strerror(errno), sizeof bar.text - 1); + bar.text[sizeof bar.text - 1] = '\0'; + bar.fd = -1; break; case 0: - statusfd = -1; + bar.fd = -1; break; default: - stext[r] = '\0'; p = stext + strlen(stext) - 1; - for (; p >= stext && *p == '\n'; *p-- = '\0'); - for (; p >= stext && *p != '\n'; --p); - if (p > stext) - strncpy(stext, p + 1, sizeof stext); + bar.text[r] = '\0'; p = bar.text + strlen(bar.text) - 1; + for (; p >= bar.text && *p == '\n'; *p-- = '\0'); + for (; p >= bar.text && *p != '\n'; --p); + if (p > bar.text) + strncpy(bar.text, p + 1, sizeof bar.text); drawbar(); } }