diff options
Diffstat (limited to 'sys/cmd/dvtm/dvtm.c')
-rw-r--r-- | sys/cmd/dvtm/dvtm.c | 116 |
1 files changed, 41 insertions, 75 deletions
diff --git a/sys/cmd/dvtm/dvtm.c b/sys/cmd/dvtm/dvtm.c index 68f4b8a..3c0f52b 100644 --- a/sys/cmd/dvtm/dvtm.c +++ b/sys/cmd/dvtm/dvtm.c @@ -5,7 +5,6 @@ uint waw, wah, wax, way; Client *clients = nil; char *title; const char *dvtm_name = "dvtm"; - Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY }; static Client *stack = nil; static Client *sel = nil; @@ -17,15 +16,7 @@ static uint tagset[2] = { 1, 1 }; static bool mouse_events_enabled = ENABLE_MOUSE; static Layout *layout = layouts; -static StatusBar bar = -{ - .fd = -1, - .lastpos = BAR_POS, - .pos = BAR_POS, - .autohide = BAR_AUTOHIDE, - .h = 1 -}; - +static StatusBar bar = { .fd = -1, .lastpos = BAR_POS, .pos = BAR_POS, .autohide = BAR_AUTOHIDE, .h = 1 }; static CmdFifo cmdfifo = { .fd = -1 }; static const char *shell; static Register copyreg; @@ -33,6 +24,7 @@ static volatile sig_atomic_t running = true; static bool runinall = false; /* function implementations */ + static void eprint(const char *errstr, ...) @@ -195,8 +187,7 @@ show_border(void) { return (bar.pos != BAR_OFF) || (clients && clients->next); } -static -void +static void draw_border(Client *c) { char t = '\0'; int x, y, maxlen, attrs = NORMAL_ATTR; @@ -228,17 +219,13 @@ draw_border(Client *c) { wmove(c->window, y, x); } -static -void -draw_content(Client *c) -{ +static void +draw_content(Client *c) { vt_draw(c->term, c->window, c->has_title_line, 0); } -static -void -draw(Client *c) -{ +static void +draw(Client *c) { if (is_content_visible(c)) { redrawwin(c->window); draw_content(c); @@ -248,10 +235,8 @@ draw(Client *c) wnoutrefresh(c->window); } -static -void -draw_all(void) -{ +static void +draw_all(void) { if (!nextvisible(clients)) { sel = nil; curs_set(0); @@ -275,10 +260,8 @@ draw_all(void) draw(sel); } -static -void -arrange(void) -{ +static void +arrange(void) { uint m = 0, n = 0; for (Client *c = nextvisible(clients); c; c = nextvisible(c->next)) { c->order = ++n; @@ -313,13 +296,10 @@ arrange(void) draw_all(); } -static -void -attach(Client *c) -{ +static void +attach(Client *c) { if (clients) clients->prev = c; - c->next = clients; c->prev = nil; clients = c; @@ -327,10 +307,8 @@ attach(Client *c) c->order = o; } -static -void -attachafter(Client *c, Client *a) -{ /* attach c after a */ +static void +attachafter(Client *c, Client *a) { /* attach c after a */ if (c == a) return; if (!a) @@ -347,18 +325,14 @@ attachafter(Client *c, Client *a) } } -static -void -attachstack(Client *c) -{ +static void +attachstack(Client *c) { c->snext = stack; stack = c; } -static -void -detach(Client *c) -{ +static void +detach(Client *c) { Client *d; if (c->prev) c->prev->next = c->next; @@ -372,10 +346,8 @@ detach(Client *c) c->next = c->prev = nil; } -static -void -settitle(Client *c) -{ +static void +settitle(Client *c) { char *term, *t = title; if (!t && sel == c && *c->title) t = c->title; @@ -385,19 +357,15 @@ settitle(Client *c) } } -static -void -detachstack(Client *c) -{ +static void +detachstack(Client *c) { Client **tc; - for (tc = &stack; *tc && *tc != c; tc = &(*tc)->snext) - ; + for (tc = &stack; *tc && *tc != c; tc = &(*tc)->snext); *tc = c->snext; } void -focus(Client *c) -{ +focus(Client *c) { if (!c) for (c = stack; c && !isvisible(c); c = c->snext); if (sel == c) @@ -450,8 +418,7 @@ applycolorrules(Client *c) static void -term_title_handler(Vt *term, const char *title) -{ +term_title_handler(Vt *term, const char *title) { Client *c = (Client *)vt_data_get(term); if (title) strncpy(c->title, title, sizeof(c->title) - 1); @@ -1718,7 +1685,7 @@ main(int argc, char *argv[]) KeyCombo keys; uint key_index = 0; memset(keys, 0, sizeof(keys)); - sigset_t emptysigs, blockset; + sigset_t emptyset, blockset; setenv("DVTM", VERSION, 1); if (!parse_args(argc, argv)) { @@ -1726,7 +1693,7 @@ main(int argc, char *argv[]) startup(nil); } - sigemptyset(&emptysigs); + sigemptyset(&emptyset); sigemptyset(&blockset); sigaddset(&blockset, SIGWINCH); sigaddset(&blockset, SIGCHLD); @@ -1734,23 +1701,23 @@ main(int argc, char *argv[]) while (running) { int r, nfds = 0; - fd_set rdrs; /* set of file descriptors we watch */ + fd_set rd; if (screen.need_resize) { resize_screen(); screen.need_resize = false; } - FD_ZERO(&rdrs); - FD_SET(STDIN_FILENO, &rdrs); + FD_ZERO(&rd); + FD_SET(STDIN_FILENO, &rd); if (cmdfifo.fd != -1) { - FD_SET(cmdfifo.fd, &rdrs); + FD_SET(cmdfifo.fd, &rd); nfds = cmdfifo.fd; } if (bar.fd != -1) { - FD_SET(bar.fd, &rdrs); + FD_SET(bar.fd, &rd); nfds = MAX(nfds, bar.fd); } @@ -1764,13 +1731,13 @@ main(int argc, char *argv[]) continue; } int pty = c->editor ? vt_pty_get(c->editor) : vt_pty_get(c->app); - FD_SET(pty, &rdrs); + FD_SET(pty, &rd); nfds = MAX(nfds, pty); - c = c->next; + c = c->next; } doupdate(); - r = pselect(nfds + 1, &rdrs, nil, nil, nil, &emptysigs); + r = pselect(nfds + 1, &rd, nil, nil, nil, &emptyset); if (r < 0) { if (errno == EINTR) @@ -1779,7 +1746,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if (FD_ISSET(STDIN_FILENO, &rdrs)) { + if (FD_ISSET(STDIN_FILENO, &rd)) { /* NOTE: this is the input handling step */ int code = getch(); if (code >= 0) { @@ -1804,19 +1771,18 @@ main(int argc, char *argv[]) keypress(code); } } - /* no data available on pty's */ - if (r == 1) + if (r == 1) /* no data available on pty's */ continue; } - if (cmdfifo.fd != -1 && FD_ISSET(cmdfifo.fd, &rdrs)) + if (cmdfifo.fd != -1 && FD_ISSET(cmdfifo.fd, &rd)) handle_cmdfifo(); - if (bar.fd != -1 && FD_ISSET(bar.fd, &rdrs)) + if (bar.fd != -1 && FD_ISSET(bar.fd, &rd)) handle_statusbar(); for (Client *c = clients; c; c = c->next) { - if (FD_ISSET(vt_pty_get(c->term), &rdrs)) { + if (FD_ISSET(vt_pty_get(c->term), &rd)) { if (vt_process(c->term) < 0 && errno == EIO) { if (c->editor) c->editor_died = true; |