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.c126
1 files changed, 64 insertions, 62 deletions
diff --git a/sys/cmd/dvtm/dvtm.c b/sys/cmd/dvtm/dvtm.c
index a2ba03b..802f891 100644
--- a/sys/cmd/dvtm/dvtm.c
+++ b/sys/cmd/dvtm/dvtm.c
@@ -2,19 +2,21 @@
/* global variables */
uint waw, wah, wax, way;
-Client *clients = NULL;
+Client *clients = nil;
char *title;
const char *dvtm_name = "dvtm";
Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY };
-static Client *stack = NULL;
-static Client *sel = NULL;
-static Client *lastsel = NULL;
-static Client *msel = NULL;
+static Client *stack = nil;
+static Client *sel = nil;
+static Client *lastsel = nil;
+static Client *msel = nil;
+
static uint seltags;
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 CmdFifo cmdfifo = { .fd = -1 };
static const char *shell;
@@ -235,7 +237,7 @@ draw(Client *c) {
static void
draw_all(void) {
if (!nextvisible(clients)) {
- sel = NULL;
+ sel = nil;
curs_set(0);
erase();
drawbar();
@@ -287,7 +289,7 @@ arrange(void) {
}
wah++;
}
- focus(NULL);
+ focus(nil);
wnoutrefresh(stdscr);
drawbar();
draw_all();
@@ -298,7 +300,7 @@ attach(Client *c) {
if (clients)
clients->prev = c;
c->next = clients;
- c->prev = NULL;
+ c->prev = nil;
clients = c;
for (int o = 1; c; c = nextvisible(c->next), o++)
c->order = o;
@@ -340,7 +342,7 @@ detach(Client *c) {
}
if (c == clients)
clients = c->next;
- c->next = c->prev = NULL;
+ c->next = c->prev = nil;
}
static void
@@ -483,7 +485,7 @@ static
Client*
get_client_by_coord(uint x, unsigned int y) {
if (y < way || y >= way+wah)
- return NULL;
+ return nil;
if (isarrange(fullscreen))
return sel;
for (Client *c = nextvisible(clients); c; c = nextvisible(c->next)) {
@@ -492,7 +494,7 @@ get_client_by_coord(uint x, unsigned int y) {
return c;
}
}
- return NULL;
+ return nil;
}
static
@@ -575,7 +577,7 @@ keybinding(KeyCombo keys, uint keycount)
return &bindings[b];
}
}
- return NULL;
+ return nil;
}
static
@@ -599,8 +601,8 @@ tagschanged() {
}
}
if (allminimized && nextvisible(clients)) {
- focus(NULL);
- toggleminimize(NULL);
+ focus(nil);
+ toggleminimize(nil);
}
arrange();
}
@@ -726,13 +728,13 @@ mouse_setup(void) {
for (uint i = 0; i < arrlen(buttons); i++)
mask |= buttons[i].mask;
}
- mousemask(mask, NULL);
+ mousemask(mask, nil);
#endif /* CONFIG_MOUSE */
}
static bool
checkshell(const char *shell) {
- if (shell == NULL || *shell == '\0' || *shell != '/')
+ if (shell == nil || *shell == '\0' || *shell != '/')
return false;
if (!strcmp(strrchr(shell, '/')+1, dvtm_name))
return false;
@@ -781,41 +783,41 @@ setup(void) {
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigwinch_handler;
- sigaction(SIGWINCH, &sa, NULL);
+ sigaction(SIGWINCH, &sa, nil);
sa.sa_handler = sigchld_handler;
- sigaction(SIGCHLD, &sa, NULL);
+ sigaction(SIGCHLD, &sa, nil);
sa.sa_handler = sigterm_handler;
- sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGTERM, &sa, nil);
sa.sa_handler = SIG_IGN;
- sigaction(SIGPIPE, &sa, NULL);
+ sigaction(SIGPIPE, &sa, nil);
}
static void
destroy(Client *c) {
if (sel == c)
- focusnextnm(NULL);
+ focusnextnm(nil);
detach(c);
detachstack(c);
if (sel == c) {
Client *next = nextvisible(clients);
if (next) {
focus(next);
- toggleminimize(NULL);
+ toggleminimize(nil);
} else {
- sel = NULL;
+ sel = nil;
}
}
if (lastsel == c)
- lastsel = NULL;
+ lastsel = nil;
werase(c->window);
wnoutrefresh(c->window);
vt_destroy(c->term);
delwin(c->window);
if (!clients && arrlen(actions)) {
if (!strcmp(c->cmd, shell))
- quit(NULL);
+ quit(nil);
else
- create(NULL);
+ create(nil);
}
free(c);
arrange();
@@ -840,26 +842,26 @@ cleanup(void) {
static char *getcwd_by_pid(Client *c) {
if (!c)
- return NULL;
+ return nil;
char buf[32];
snprintf(buf, sizeof buf, "/proc/%d/cwd", c->pid);
- return realpath(buf, NULL);
+ return realpath(buf, nil);
}
void
create(const char *args[])
{
- const char *pargs[4] = { shell, NULL };
- char buf[8], *cwd = NULL;
+ const char *pargs[4] = { shell, nil };
+ char buf[8], *cwd = nil;
const char *env[] = {
"DVTM_WINDOW_ID", buf,
- NULL
+ nil
};
if (args && args[0]) {
pargs[1] = "-c";
pargs[2] = args[0];
- pargs[3] = NULL;
+ pargs[3] = nil;
}
Client *c = calloc(1, sizeof(Client));
if (!c)
@@ -896,7 +898,7 @@ create(const char *args[])
if (args && args[2])
cwd = !strcmp(args[2], "$CWD") ? getcwd_by_pid(sel) : (char*)args[2];
- c->pid = vt_forkpty(c->term, shell, pargs, cwd, env, NULL, NULL);
+ c->pid = vt_forkpty(c->term, shell, pargs, cwd, env, nil, nil);
if (args && args[2] && !strcmp(args[2], "$CWD"))
free(cwd);
vt_data_set(c->term, c);
@@ -917,31 +919,31 @@ copymode(const char *args[])
if (!args || !args[0] || !sel || sel->editor)
return;
- bool colored = strstr(args[0], "pager") != NULL;
+ bool colored = strstr(args[0], "pager") != nil;
if (!(sel->editor = vt_create(sel->h - sel->has_title_line, sel->w, 0)))
return;
int *to = &sel->editor_fds[0];
- int *from = strstr(args[0], "editor") ? &sel->editor_fds[1] : NULL;
+ int *from = strstr(args[0], "editor") ? &sel->editor_fds[1] : nil;
sel->editor_fds[0] = sel->editor_fds[1] = -1;
- const char *argv[3] = { args[0], NULL, NULL };
+ const char *argv[3] = { args[0], nil, nil };
char argline[32];
int line = vt_content_start(sel->app);
snprintf(argline, sizeof(argline), "+%d", line);
argv[1] = argline;
- if (vt_forkpty(sel->editor, args[0], argv, NULL, NULL, to, from) < 0) {
+ if (vt_forkpty(sel->editor, args[0], argv, nil, nil, to, from) < 0) {
vt_destroy(sel->editor);
- sel->editor = NULL;
+ sel->editor = nil;
return;
}
sel->term = sel->editor;
if (sel->editor_fds[0] != -1) {
- char *buf = NULL;
+ char *buf = nil;
size_t len = vt_content_get(sel->app, &buf, colored);
char *cur = buf;
while (len > 0) {
@@ -970,7 +972,7 @@ focusn(const char *args[])
if (c->order == atoi(args[0])) {
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
return;
}
}
@@ -987,7 +989,7 @@ focusid(const char *args[])
if (c->id == win_id) {
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
if (!isvisible(c)) {
c->tags |= tagset[seltags];
tagschanged();
@@ -1196,7 +1198,7 @@ incnmaster(const char *args[])
if (isarrange(fullscreen) || isarrange(grid))
return;
/* arg handling, manipulate nmaster */
- if (args[0] == NULL) {
+ if (args[0] == nil) {
screen.nmaster = NMASTER;
} else if (sscanf(args[0], "%d", &delta) == 1) {
if (args[0][0] == '+' || args[0][0] == '-')
@@ -1217,7 +1219,7 @@ setmfact(const char *args[])
if (isarrange(fullscreen) || isarrange(grid))
return;
/* arg handling, manipulate mfact */
- if (args[0] == NULL) {
+ if (args[0] == nil) {
screen.mfact = MFACT;
} else if (sscanf(args[0], "%f", &delta) == 1) {
if (args[0][0] == '+' || args[0][0] == '-')
@@ -1248,7 +1250,7 @@ togglebar(const char *args[])
hidebar();
bar.autohide = false;
updatebarpos();
- redraw(NULL);
+ redraw(nil);
}
void
@@ -1263,7 +1265,7 @@ togglebarpos(const char *args[])
break;
}
updatebarpos();
- redraw(NULL);
+ redraw(nil);
}
void
@@ -1295,7 +1297,7 @@ toggleminimize(const char *args[])
} else if (m->minimized) {
/* non master window got minimized move it above all other
* minimized ones */
- focusnextnm(NULL);
+ focusnextnm(nil);
detach(m);
for (c = nextvisible(clients); c && (t = nextvisible(c->next)) && !t->minimized; c = t);
attachafter(m, c);
@@ -1338,7 +1340,7 @@ zoom(const char *args[])
attach(c);
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
arrange();
}
@@ -1348,28 +1350,28 @@ mouse_focus(const char *args[])
{
focus(msel);
if (msel->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
}
void
mouse_fullscreen(const char *args[])
{
- mouse_focus(NULL);
- setlayout(isarrange(fullscreen) ? NULL : args);
+ mouse_focus(nil);
+ setlayout(isarrange(fullscreen) ? nil : args);
}
void
mouse_minimize(const char *args[])
{
focus(msel);
- toggleminimize(NULL);
+ toggleminimize(nil);
}
void
mouse_zoom(const char *args[])
{
focus(msel);
- zoom(NULL);
+ zoom(nil);
}
static
@@ -1379,7 +1381,7 @@ get_cmd_by_name(const char *name) {
if (!strcmp(name, commands[i].name))
return &commands[i];
}
- return NULL;
+ return nil;
}
static
@@ -1403,7 +1405,7 @@ handle_cmdfifo(void) {
for (s = p; *p && *p != ' ' && *p != '\n'; p++);
if ((c = *p))
*p++ = '\0';
- if (*s && (cmd = get_cmd_by_name(s)) != NULL) {
+ if (*s && (cmd = get_cmd_by_name(s)) != nil) {
bool quote = false;
int argc = 0;
const char *args[MAX_ARGS], *arg;
@@ -1499,7 +1501,7 @@ handle_mouse(void) {
buttons[i].action.cmd(buttons[i].action.args);
}
- msel = NULL;
+ msel = nil;
#endif /* CONFIG_MOUSE */
}
@@ -1553,7 +1555,7 @@ handle_editor(Client *c) {
c->editor_died = false;
c->editor_fds[1] = -1;
vt_destroy(c->editor);
- c->editor = NULL;
+ c->editor = nil;
c->term = c->app;
vt_dirty(c->term);
draw_content(c);
@@ -1603,7 +1605,7 @@ parse_args(int argc, char *argv[]) {
set_escdelay(100);
for (int arg = 1; arg < argc; arg++) {
if (argv[arg][0] != '-') {
- const char *args[] = { argv[arg], NULL, NULL };
+ const char *args[] = { argv[arg], nil, nil };
if (!init) {
setup();
init = true;
@@ -1649,7 +1651,7 @@ parse_args(int argc, char *argv[]) {
case 'c': {
const char *fifo;
cmdfifo.fd = open_or_create_fifo(argv[++arg], &cmdfifo.file);
- if (!(fifo = realpath(argv[arg], NULL)))
+ if (!(fifo = realpath(argv[arg], nil)))
fatal("%s\n", strerror(errno));
setenv("DVTM_CMD_FIFO", fifo, 1);
break;
@@ -1671,14 +1673,14 @@ main(int argc, char *argv[]) {
setenv("DVTM", VERSION, 1);
if (!parse_args(argc, argv)) {
setup();
- startup(NULL);
+ startup(nil);
}
sigemptyset(&emptyset);
sigemptyset(&blockset);
sigaddset(&blockset, SIGWINCH);
sigaddset(&blockset, SIGCHLD);
- sigprocmask(SIG_BLOCK, &blockset, NULL);
+ sigprocmask(SIG_BLOCK, &blockset, nil);
while (running) {
int r, nfds = 0;
@@ -1718,7 +1720,7 @@ main(int argc, char *argv[]) {
}
doupdate();
- r = pselect(nfds + 1, &rd, NULL, NULL, NULL, &emptyset);
+ r = pselect(nfds + 1, &rd, nil, nil, nil, &emptyset);
if (r < 0) {
if (errno == EINTR)
@@ -1731,7 +1733,7 @@ main(int argc, char *argv[]) {
int code = getch();
if (code >= 0) {
keys[key_index++] = code;
- KeyBinding *binding = NULL;
+ KeyBinding *binding = nil;
if (code == KEY_MOUSE) {
key_index = 0;
handle_mouse();