aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/dvtm/dvtm.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/dvtm/dvtm.c')
-rw-r--r--sys/cmd/dvtm/dvtm.c161
1 files changed, 103 insertions, 58 deletions
diff --git a/sys/cmd/dvtm/dvtm.c b/sys/cmd/dvtm/dvtm.c
index 802f891..9d35b25 100644
--- a/sys/cmd/dvtm/dvtm.c
+++ b/sys/cmd/dvtm/dvtm.c
@@ -181,12 +181,14 @@ drawbar(void)
wnoutrefresh(stdscr);
}
-static int
+static
+int
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;
@@ -218,13 +220,17 @@ 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);
@@ -234,8 +240,10 @@ draw(Client *c) {
wnoutrefresh(c->window);
}
-static void
-draw_all(void) {
+static
+void
+draw_all(void)
+{
if (!nextvisible(clients)) {
sel = nil;
curs_set(0);
@@ -259,8 +267,10 @@ 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;
@@ -295,10 +305,13 @@ 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;
@@ -306,8 +319,10 @@ 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)
@@ -324,14 +339,18 @@ attachafter(Client *c, Client *a) { /* attach c after 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;
@@ -345,8 +364,10 @@ 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;
@@ -356,15 +377,19 @@ 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)
@@ -394,10 +419,12 @@ focus(Client *c) {
curs_set(c && !c->minimized && vt_cursor_visible(c->term));
}
-static void
-applycolorrules(Client *c) {
+static
+void
+applycolorrules(Client *c)
+{
const ColorRule *r = colorrules;
- short fg = r->color->fg, bg = r->color->bg;
+ int fg = r->color->fg, bg = r->color->bg;
attr_t attrs = r->attrs;
for (uint i = 1; i < arrlen(colorrules); i++) {
@@ -413,8 +440,10 @@ applycolorrules(Client *c) {
vt_default_colors_set(c->term, attrs, fg, bg);
}
-static void
-term_title_handler(Vt *term, const char *title) {
+static
+void
+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);
@@ -425,7 +454,8 @@ term_title_handler(Vt *term, const char *title) {
applycolorrules(c);
}
-static void
+static
+void
term_urgent_handler(Vt *term) {
Client *c = (Client *)vt_data_get(term);
c->urgent = true;
@@ -684,9 +714,11 @@ viewprevtag(const char *args[])
tagschanged();
}
-static void
-keypress(int code) {
- int key = -1;
+static
+void
+keypress(int code)
+{
+ int key = -1;
uint len = 1;
char buf[8] = { '\e' };
@@ -710,6 +742,7 @@ keypress(int code) {
vt_write(c->term, buf, len);
else
vt_keypress(c->term, code);
+
if (key != -1)
vt_keypress(c->term, key);
}
@@ -718,8 +751,10 @@ keypress(int code) {
}
}
-static void
-mouse_setup(void) {
+static
+void
+mouse_setup(void)
+{
#ifdef CONFIG_MOUSE
mmask_t mask = 0;
@@ -755,8 +790,10 @@ getshell(void) {
return "/bin/sh";
}
-static void
-setup(void) {
+static
+void
+setup(void)
+{
shell = getshell();
setlocale(LC_CTYPE, "");
initscr();
@@ -778,6 +815,7 @@ setup(void) {
colors[i].pair = vt_color_reserve(colors[i].fg, colors[i].bg);
}
resize_screen();
+
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_flags = 0;
@@ -792,7 +830,8 @@ setup(void) {
sigaction(SIGPIPE, &sa, nil);
}
-static void
+static
+void
destroy(Client *c) {
if (sel == c)
focusnextnm(nil);
@@ -823,7 +862,8 @@ destroy(Client *c) {
arrange();
}
-static void
+static
+void
cleanup(void) {
while (clients)
destroy(clients);
@@ -840,7 +880,8 @@ cleanup(void) {
unlink(cmdfifo.file);
}
-static char *getcwd_by_pid(Client *c) {
+static
+char *getcwd_by_pid(Client *c) {
if (!c)
return nil;
char buf[32];
@@ -1664,11 +1705,12 @@ parse_args(int argc, char *argv[]) {
}
int
-main(int argc, char *argv[]) {
+main(int argc, char *argv[])
+{
KeyCombo keys;
uint key_index = 0;
memset(keys, 0, sizeof(keys));
- sigset_t emptyset, blockset;
+ sigset_t emptysigs, blockset;
setenv("DVTM", VERSION, 1);
if (!parse_args(argc, argv)) {
@@ -1676,7 +1718,7 @@ main(int argc, char *argv[]) {
startup(nil);
}
- sigemptyset(&emptyset);
+ sigemptyset(&emptysigs);
sigemptyset(&blockset);
sigaddset(&blockset, SIGWINCH);
sigaddset(&blockset, SIGCHLD);
@@ -1684,27 +1726,27 @@ main(int argc, char *argv[]) {
while (running) {
int r, nfds = 0;
- fd_set rd;
+ fd_set rdrs; /* set of file descriptors we watch */
if (screen.need_resize) {
resize_screen();
screen.need_resize = false;
}
- FD_ZERO(&rd);
- FD_SET(STDIN_FILENO, &rd);
+ FD_ZERO(&rdrs);
+ FD_SET(STDIN_FILENO, &rdrs);
if (cmdfifo.fd != -1) {
- FD_SET(cmdfifo.fd, &rd);
+ FD_SET(cmdfifo.fd, &rdrs);
nfds = cmdfifo.fd;
}
if (bar.fd != -1) {
- FD_SET(bar.fd, &rd);
+ FD_SET(bar.fd, &rdrs);
nfds = MAX(nfds, bar.fd);
}
- for (Client *c = clients; c; ) {
+ for (Client *c = clients; c;) {
if (c->editor && c->editor_died)
handle_editor(c);
if (!c->editor && c->died) {
@@ -1714,13 +1756,13 @@ main(int argc, char *argv[]) {
continue;
}
int pty = c->editor ? vt_pty_get(c->editor) : vt_pty_get(c->app);
- FD_SET(pty, &rd);
+ FD_SET(pty, &rdrs);
nfds = MAX(nfds, pty);
- c = c->next;
+ c = c->next;
}
doupdate();
- r = pselect(nfds + 1, &rd, nil, nil, nil, &emptyset);
+ r = pselect(nfds + 1, &rdrs, nil, nil, nil, &emptysigs);
if (r < 0) {
if (errno == EINTR)
@@ -1729,11 +1771,13 @@ main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
- if (FD_ISSET(STDIN_FILENO, &rd)) {
+ if (FD_ISSET(STDIN_FILENO, &rdrs)) {
+ /* NOTE: this is the input handling step */
int code = getch();
if (code >= 0) {
- keys[key_index++] = code;
+ keys[key_index++] = code;
KeyBinding *binding = nil;
+
if (code == KEY_MOUSE) {
key_index = 0;
handle_mouse();
@@ -1752,18 +1796,19 @@ main(int argc, char *argv[]) {
keypress(code);
}
}
- if (r == 1) /* no data available on pty's */
+ /* no data available on pty's */
+ if (r == 1)
continue;
}
- if (cmdfifo.fd != -1 && FD_ISSET(cmdfifo.fd, &rd))
+ if (cmdfifo.fd != -1 && FD_ISSET(cmdfifo.fd, &rdrs))
handle_cmdfifo();
- if (bar.fd != -1 && FD_ISSET(bar.fd, &rd))
+ if (bar.fd != -1 && FD_ISSET(bar.fd, &rdrs))
handle_statusbar();
for (Client *c = clients; c; c = c->next) {
- if (FD_ISSET(vt_pty_get(c->term), &rd)) {
+ if (FD_ISSET(vt_pty_get(c->term), &rdrs)) {
if (vt_process(c->term) < 0 && errno == EIO) {
if (c->editor)
c->editor_died = true;