2 * The initial "port" of dwm to curses was done by
4 * © 2007-2013 Marc André Tanner <mat at brain-dump dot org>
6 * It is highly inspired by the original X11 dwm and
7 * reuses some code of it which is mostly
9 * © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
11 * See LICENSE for details.
16 #include <sys/ioctl.h>
19 #include <sys/types.h>
39 #ifndef NCURSES_REENTRANT
40 # define set_escdelay(d) (ESCDELAY = (d))
53 void (*arrange
)(void);
56 typedef struct Client Client
;
65 unsigned short int id
;
83 #define ALT(k) ((k) + (161 - 'a'))
84 #if defined CTRL && defined _AIX
88 #define CTRL(k) ((k) & 0x1F)
90 #define CTRL_ALT(k) ((k) + (129 - 'a'))
95 void (*cmd
)(const char *args
[]);
96 /* needed to avoid an error about initialization
97 * of nested flexible array members */
98 const char *args
[MAX_ARGS
];
117 enum { BAR_TOP
, BAR_BOTTOM
, BAR_OFF
};
118 enum { ALIGN_LEFT
, ALIGN_RIGHT
};
123 unsigned short int h
;
124 unsigned short int y
;
132 unsigned short int id
;
135 #define countof(arr) (sizeof(arr) / sizeof((arr)[0]))
136 #define sstrlen(str) (sizeof(str) - 1)
137 #define max(x, y) ((x) > (y) ? (x) : (y))
140 #define debug(format, args...)
145 /* commands for use by keybindings */
146 static void create(const char *args
[]);
147 static void copymode(const char *args
[]);
148 static void escapekey(const char *args
[]);
149 static void focusn(const char *args
[]);
150 static void focusnext(const char *args
[]);
151 static void focusnextnm(const char *args
[]);
152 static void focusprev(const char *args
[]);
153 static void focusprevnm(const char *args
[]);
154 static void killclient(const char *args
[]);
155 static void lock(const char *key
[]);
156 static void paste(const char *args
[]);
157 static void quit(const char *args
[]);
158 static void redraw(const char *args
[]);
159 static void scrollback(const char *args
[]);
160 static void setlayout(const char *args
[]);
161 static void setmfact(const char *args
[]);
162 static void startup(const char *args
[]);
163 static void togglebar(const char *args
[]);
164 static void togglebell(const char *key
[]);
165 static void toggleminimize(const char *args
[]);
166 static void togglemouse(const char *args
[]);
167 static void togglerunall(const char *args
[]);
168 static void zoom(const char *args
[]);
170 /* commands for use by mouse bindings */
171 static void mouse_focus(const char *args
[]);
172 static void mouse_fullscreen(const char *args
[]);
173 static void mouse_minimize(const char *args
[]);
174 static void mouse_zoom(const char *args
[]);
176 /* functions and variables available to layouts via config.h */
177 static void resize(Client
*c
, int x
, int y
, int w
, int h
);
178 extern Screen screen
;
179 static unsigned int waw
, wah
, wax
, way
;
180 static Client
*clients
= NULL
;
182 #define COLOR(fg, bg) COLOR_PAIR(vt_color_reserve(fg, bg))
186 /* global variables */
187 Screen screen
= { MFACT
, SCROLL_HISTORY
};
188 static Client
*sel
= NULL
;
189 static Client
*msel
= NULL
;
190 static bool mouse_events_enabled
= ENABLE_MOUSE
;
191 static Layout
*layout
= layouts
;
192 static StatusBar bar
= { -1, BAR_POS
, 1 };
193 static CmdFifo cmdfifo
= { -1 };
194 static const char *shell
;
195 static char *copybuf
;
196 static volatile sig_atomic_t running
= true;
197 static bool runinall
= false;
200 eprint(const char *errstr
, ...) {
202 va_start(ap
, errstr
);
203 vfprintf(stderr
, errstr
, ap
);
208 error(const char *errstr
, ...) {
210 va_start(ap
, errstr
);
211 vfprintf(stderr
, errstr
, ap
);
217 isarrange(void (*func
)()) {
218 return func
== layout
->arrange
;
222 is_visible(Client
*c
) {
225 if (isarrange(fullscreen
))
227 return !c
->minimized
;
232 wchar_t wbuf
[sizeof bar
.text
];
233 int x
, y
, w
, maxwidth
= screen
.w
- 2;
234 if (bar
.pos
== BAR_OFF
|| !bar
.text
[0])
239 mvaddch(bar
.y
, 0, '[');
240 if (mbstowcs(wbuf
, bar
.text
, sizeof bar
.text
) == (size_t)-1)
242 if ((w
= wcswidth(wbuf
, maxwidth
)) == -1)
244 if (BAR_ALIGN
== ALIGN_RIGHT
) {
245 for (int i
= 0; i
+ w
< maxwidth
; i
++)
249 if (BAR_ALIGN
== ALIGN_LEFT
) {
250 for (; w
< maxwidth
; w
++)
253 mvaddch(bar
.y
, screen
.w
- 1, ']');
254 attrset(NORMAL_ATTR
);
257 curs_set(vt_cursor(sel
->term
));
258 wnoutrefresh(stdscr
);
262 draw_border(Client
*c
) {
266 wattrset(c
->window
, (sel
== c
|| (runinall
&& !c
->minimized
)) ? SELECTED_ATTR
: NORMAL_ATTR
);
267 getyx(c
->window
, y
, x
);
269 mvwhline(c
->window
, 0, 0, ACS_HLINE
, c
->w
);
270 maxlen
= c
->w
- (2 + sstrlen(TITLE
) - sstrlen("%s%sd") + sstrlen(SEPARATOR
) + 2);
273 if ((size_t)maxlen
< sizeof(c
->title
)) {
274 t
= c
->title
[maxlen
];
275 c
->title
[maxlen
] = '\0';
278 mvwprintw(c
->window
, 0, 2, TITLE
,
279 *c
->title
? c
->title
: "",
280 *c
->title
? SEPARATOR
: "",
283 c
->title
[maxlen
] = t
;
284 wmove(c
->window
, y
, x
);
286 curs_set(vt_cursor(sel
->term
));
290 draw_content(Client
*c
) {
291 vt_draw(c
->term
, c
->window
, 1, 0);
293 curs_set(vt_cursor(sel
->term
));
299 redrawwin(c
->window
);
302 if (!isarrange(fullscreen
) || sel
== c
)
304 wnoutrefresh(c
->window
);
311 if (!isarrange(fullscreen
)) {
312 for (c
= clients
; c
; c
= c
->next
) {
318 /* as a last step the selected window is redrawn,
319 * this has the effect that the cursor position is
330 attrset(NORMAL_ATTR
);
332 wnoutrefresh(stdscr
);
343 for (int o
= 1; c
; c
= c
->next
, o
++)
348 attachafter(Client
*c
, Client
*a
) { /* attach c after a */
352 for (a
= clients
; a
&& a
->next
; a
= a
->next
);
360 for (int o
= a
->order
; c
; c
= c
->next
)
369 c
->prev
->next
= c
->next
;
371 c
->next
->prev
= c
->prev
;
372 for (d
= c
->next
; d
; d
= d
->next
)
377 c
->next
= c
->prev
= NULL
;
381 settitle(Client
*c
) {
383 if (!t
&& sel
== c
&& *c
->title
)
386 printf("\033]0;%s\007", t
);
396 if (tmp
&& !isarrange(fullscreen
)) {
398 wnoutrefresh(tmp
->window
);
400 if (isarrange(fullscreen
)) {
404 wnoutrefresh(c
->window
);
409 applycolorrules(Client
*c
) {
410 const ColorRule
*r
= colorrules
;
411 short fg
= r
->fg
, bg
= r
->bg
;
412 unsigned attrs
= r
->attrs
;
414 for (unsigned int i
= 1; i
< countof(colorrules
); i
++) {
416 if (strstr(c
->title
, r
->title
)) {
424 vt_set_default_colors(c
->term
, attrs
, fg
, bg
);
428 term_event_handler(Vt
*term
, int event
, void *event_data
) {
429 Client
*c
= (Client
*)vt_get_data(term
);
433 strncpy(c
->title
, event_data
, sizeof(c
->title
) - 1);
434 c
->title
[event_data
? sizeof(c
->title
) - 1 : 0] = '\0';
436 if (!isarrange(fullscreen
) || sel
== c
)
440 case VT_EVENT_COPY_TEXT
:
443 copybuf
= event_data
;
450 move_client(Client
*c
, int x
, int y
) {
451 if (c
->x
== x
&& c
->y
== y
)
453 debug("moving, x: %d y: %d\n", x
, y
);
454 if (mvwin(c
->window
, y
, x
) == ERR
)
455 eprint("error moving, x: %d y: %d\n", x
, y
);
463 resize_client(Client
*c
, int w
, int h
) {
464 if (c
->w
== w
&& c
->h
== h
)
466 debug("resizing, w: %d h: %d\n", w
, h
);
467 if (wresize(c
->window
, h
, w
) == ERR
)
468 eprint("error resizing, w: %d h: %d\n", w
, h
);
473 vt_resize(c
->term
, h
- 1, w
);
477 resize(Client
*c
, int x
, int y
, int w
, int h
) {
478 resize_client(c
, w
, h
);
479 move_client(c
, x
, y
);
483 get_client_by_pid(pid_t pid
) {
485 for (c
= clients
; c
; c
= c
->next
) {
493 get_client_by_coord(unsigned int x
, unsigned int y
) {
495 if (y
< way
|| y
>= wah
)
497 if (isarrange(fullscreen
))
499 for (c
= clients
; c
; c
= c
->next
) {
500 if (x
>= c
->x
&& x
< c
->x
+ c
->w
&& y
>= c
->y
&& y
< c
->y
+ c
->h
) {
501 debug("mouse event, x: %d y: %d client: %d\n", x
, y
, c
->order
);
509 sigchld_handler(int sig
) {
515 while ((pid
= waitpid(-1, &status
, WNOHANG
)) != 0) {
517 if (errno
== ECHILD
) {
518 /* no more child processes */
521 eprint("waitpid: %s\n", strerror(errno
));
524 debug("child with pid %d died\n", pid
);
525 if ((c
= get_client_by_pid(pid
)))
533 sigwinch_handler(int sig
) {
534 screen
.need_resize
= true;
538 sigterm_handler(int sig
) {
550 if (bar
.pos
== BAR_TOP
) {
553 } else if (bar
.pos
== BAR_BOTTOM
) {
563 if (ioctl(0, TIOCGWINSZ
, &ws
) == -1) {
564 getmaxyx(stdscr
, screen
.h
, screen
.w
);
566 screen
.w
= ws
.ws_col
;
567 screen
.h
= ws
.ws_row
;
570 debug("resize_screen(), w: %d h: %d\n", screen
.w
, screen
.h
);
572 resizeterm(screen
.h
, screen
.w
);
573 wresize(stdscr
, screen
.h
, screen
.w
);
582 is_modifier(unsigned int mod
) {
584 for (i
= 0; i
< countof(keys
); i
++) {
585 if (keys
[i
].mod
== mod
)
592 keybinding(unsigned int mod
, unsigned int code
) {
594 for (i
= 0; i
< countof(keys
); i
++) {
595 if (keys
[i
].mod
== mod
&& keys
[i
].code
== code
)
604 unsigned int len
= 1;
605 char buf
[8] = { '\e' };
608 /* pass characters following escape to the underlying app */
609 nodelay(stdscr
, TRUE
);
610 for (int t
; len
< sizeof(buf
) && (t
= getch()) != ERR
; len
++)
612 nodelay(stdscr
, FALSE
);
615 for (c
= runinall
? clients
: sel
; c
; c
= c
->next
) {
616 if (!c
->minimized
|| isarrange(fullscreen
)) {
618 vt_write(c
->term
, buf
, len
);
620 vt_keypress(c
->term
, code
);
632 if (mouse_events_enabled
) {
633 mask
= BUTTON1_CLICKED
| BUTTON2_CLICKED
;
634 for (unsigned int i
= 0; i
< countof(buttons
); i
++)
635 mask
|= buttons
[i
].mask
;
637 mousemask(mask
, NULL
);
638 #endif /* CONFIG_MOUSE */
643 if (!(shell
= getenv("SHELL")))
645 setlocale(LC_CTYPE
, "");
649 keypad(stdscr
, TRUE
);
653 vt_set_keytable(keytable
, countof(keytable
));
657 sigemptyset(&sa
.sa_mask
);
658 sa
.sa_handler
= sigwinch_handler
;
659 sigaction(SIGWINCH
, &sa
, NULL
);
660 sa
.sa_handler
= sigchld_handler
;
661 sigaction(SIGCHLD
, &sa
, NULL
);
662 sa
.sa_handler
= sigterm_handler
;
663 sigaction(SIGTERM
, &sa
, NULL
);
674 toggleminimize(NULL
);
679 wnoutrefresh(c
->window
);
682 if (!clients
&& countof(actions
)) {
683 if (!strcmp(c
->cmd
, shell
))
706 unlink(cmdfifo
.file
);
709 static char *getcwd_by_pid(Client
*c
) {
713 snprintf(buf
, sizeof buf
, "/proc/%d/cwd", c
->pid
);
714 return realpath(buf
, NULL
);
717 /* commands for use by keybindings */
719 create(const char *args
[]) {
720 Client
*c
= calloc(1, sizeof(Client
));
723 const char *cmd
= (args
&& args
[0]) ? args
[0] : shell
;
724 const char *pargs
[] = { "/bin/sh", "-c", cmd
, NULL
};
725 c
->id
= ++cmdfifo
.id
;
726 char buf
[8], *cwd
= NULL
;
727 snprintf(buf
, sizeof buf
, "%d", c
->id
);
728 const char *env
[] = {
730 "DVTM_WINDOW_ID", buf
,
734 if (!(c
->window
= newwin(wah
, waw
, way
, wax
))) {
739 if (!(c
->term
= vt_create(screen
.h
- 1, screen
.w
, screen
.history
))) {
746 if (args
&& args
[1]) {
747 strncpy(c
->title
, args
[1], sizeof(c
->title
) - 1);
748 c
->title
[sizeof(c
->title
) - 1] = '\0';
751 cwd
= !strcmp(args
[2], "$CWD") ? getcwd_by_pid(sel
) : (char*)args
[2];
752 c
->pid
= vt_forkpty(c
->term
, "/bin/sh", pargs
, cwd
, env
, &c
->pty
);
753 if (args
&& args
[2] && !strcmp(args
[2], "$CWD"))
755 vt_set_data(c
->term
, c
);
756 vt_set_event_handler(c
->term
, term_event_handler
);
762 c
->minimized
= false;
763 debug("client with pid %d forked\n", c
->pid
);
770 copymode(const char *args
[]) {
773 vt_copymode_enter(sel
->term
);
775 vt_copymode_keypress(sel
->term
, args
[0][0]);
781 escapekey(const char *args
[]) {
783 if ((key
= getch()) >= 0) {
784 debug("escaping key `%c'\n", key
);
790 focusn(const char *args
[]) {
793 for (c
= clients
; c
; c
= c
->next
) {
794 if (c
->order
== atoi(args
[0])) {
797 toggleminimize(NULL
);
804 focusnext(const char *args
[]) {
818 focusnextnm(const char *args
[]) {
828 } while (c
->minimized
&& c
!= sel
);
833 focusprev(const char *args
[]) {
840 for (c
= clients
; c
&& c
->next
; c
= c
->next
);
846 focusprevnm(const char *args
[]) {
855 for (c
= clients
; c
&& c
->next
; c
= c
->next
);
856 } while (c
->minimized
&& c
!= sel
);
861 killclient(const char *args
[]) {
864 debug("killing client with pid: %d\n", sel
->pid
);
865 kill(-sel
->pid
, SIGKILL
);
869 lock(const char *args
[]) {
870 size_t len
= 0, i
= 0;
871 char buf
[16], *pass
= buf
;
877 if (args
&& args
[0]) {
878 len
= strlen(args
[0]);
879 pass
= (char *)args
[0];
881 mvprintw(LINES
/ 2, COLS
/ 2 - 7, "Enter password");
882 while (len
< sizeof buf
&& (c
= getch()) != '\n')
887 mvprintw(LINES
/ 2, COLS
/ 2 - 7, "Screen locked!");
890 for(i
= 0; i
< len
; i
++) {
891 if (getch() != pass
[i
])
900 paste(const char *args
[]) {
902 vt_write(sel
->term
, copybuf
, strlen(copybuf
));
906 quit(const char *args
[]) {
912 redraw(const char *args
[]) {
913 for (Client
*c
= clients
; c
; c
= c
->next
) {
917 wnoutrefresh(c
->window
);
921 wnoutrefresh(stdscr
);
928 scrollback(const char *args
[]) {
931 if (!args
[0] || atoi(args
[0]) < 0)
932 vt_scroll(sel
->term
, -sel
->h
/2);
934 vt_scroll(sel
->term
, sel
->h
/2);
940 setlayout(const char *args
[]) {
943 if (!args
|| !args
[0]) {
944 if (++layout
== &layouts
[countof(layouts
)])
945 layout
= &layouts
[0];
947 for (i
= 0; i
< countof(layouts
); i
++)
948 if (!strcmp(args
[0], layouts
[i
].symbol
))
950 if (i
== countof(layouts
))
952 layout
= &layouts
[i
];
958 setmfact(const char *args
[]) {
961 if (isarrange(fullscreen
) || isarrange(grid
))
963 /* arg handling, manipulate mfact */
965 screen
.mfact
= MFACT
;
966 else if (1 == sscanf(args
[0], "%f", &delta
)) {
967 if (args
[0][0] == '+' || args
[0][0] == '-')
968 screen
.mfact
+= delta
;
970 screen
.mfact
= delta
;
971 if (screen
.mfact
< 0.1)
973 else if (screen
.mfact
> 0.9)
980 startup(const char *args
[]) {
981 for (unsigned int i
= 0; i
< countof(actions
); i
++)
982 actions
[i
].cmd(actions
[i
].args
);
986 togglebar(const char *args
[]) {
987 if (bar
.pos
== BAR_OFF
)
988 bar
.pos
= (BAR_POS
== BAR_OFF
) ? BAR_TOP
: BAR_POS
;
996 togglebell(const char *args
[]) {
997 vt_togglebell(sel
->term
);
1001 toggleminimize(const char *args
[]) {
1006 /* the last window can't be minimized */
1007 if (!sel
->minimized
) {
1008 for (n
= 0, c
= clients
; c
; c
= c
->next
)
1014 sel
->minimized
= !sel
->minimized
;
1016 /* check whether the master client was minimized */
1017 if (sel
== clients
&& sel
->minimized
) {
1023 for (; c
&& c
->next
&& !c
->next
->minimized
; c
= c
->next
);
1025 } else if (m
->minimized
) {
1026 /* non master window got minimized move it above all other
1030 for (c
= clients
; c
&& c
->next
&& !c
->next
->minimized
; c
= c
->next
);
1032 } else { /* window is no longer minimized, move it to the master area */
1041 togglemouse(const char *args
[]) {
1042 mouse_events_enabled
= !mouse_events_enabled
;
1047 togglerunall(const char *args
[]) {
1048 runinall
= !runinall
;
1053 zoom(const char *args
[]) {
1058 if ((c
= sel
) == clients
)
1065 toggleminimize(NULL
);
1069 /* commands for use by mouse bindings */
1071 mouse_focus(const char *args
[]) {
1073 if (msel
->minimized
)
1074 toggleminimize(NULL
);
1078 mouse_fullscreen(const char *args
[]) {
1080 if (isarrange(fullscreen
))
1087 mouse_minimize(const char *args
[]) {
1089 toggleminimize(NULL
);
1093 mouse_zoom(const char *args
[]) {
1099 get_cmd_by_name(const char *name
) {
1100 for (unsigned int i
= 0; i
< countof(commands
); i
++) {
1101 if (!strcmp(name
, commands
[i
].name
))
1102 return &commands
[i
];
1110 char *p
, *s
, cmdbuf
[512], c
;
1112 switch (r
= read(cmdfifo
.fd
, cmdbuf
, sizeof cmdbuf
- 1)) {
1121 /* find the command name */
1122 for (; *p
== ' ' || *p
== '\n'; p
++);
1123 for (s
= p
; *p
&& *p
!= ' ' && *p
!= '\n'; p
++);
1126 if (*s
&& (cmd
= get_cmd_by_name(s
)) != NULL
) {
1129 /* XXX: initializer assumes MAX_ARGS == 2 use a initialization loop? */
1130 const char *args
[MAX_ARGS
] = { NULL
, NULL
, NULL
}, *arg
;
1131 /* if arguments were specified in config.h ignore the one given via
1132 * the named pipe and thus skip everything until we find a new line
1134 if (cmd
->action
.args
[0] || c
== '\n') {
1135 debug("execute %s", s
);
1136 cmd
->action
.cmd(cmd
->action
.args
);
1137 while (*p
&& *p
!= '\n')
1141 /* no arguments were given in config.h so we parse the command line */
1145 for (; (c
= *p
); p
++) {
1148 /* remove the escape character '\\' move every
1149 * following character to the left by one position
1169 /* remove trailing quote if there is one */
1170 if (*(p
- 1) == '\'' || *(p
- 1) == '\"')
1173 /* remove leading quote if there is one */
1174 if (*arg
== '\'' || *arg
== '\"')
1176 if (argc
< MAX_ARGS
)
1186 if (c
== '\n' || *p
== '\n') {
1189 debug("execute %s", s
);
1190 for(int i
= 0; i
< argc
; i
++)
1191 debug(" %s", args
[i
]);
1193 cmd
->action
.cmd(args
);
1207 if (getmouse(&event
) != OK
)
1209 msel
= get_client_by_coord(event
.x
, event
.y
);
1214 debug("mouse x:%d y:%d cx:%d cy:%d mask:%d\n", event
.x
, event
.y
, event
.x
- msel
->x
, event
.y
- msel
->y
, event
.bstate
);
1216 vt_mouse(msel
->term
, event
.x
- msel
->x
, event
.y
- msel
->y
, event
.bstate
);
1218 for (i
= 0; i
< countof(buttons
); i
++) {
1219 if (event
.bstate
& buttons
[i
].mask
)
1220 buttons
[i
].action
.cmd(buttons
[i
].action
.args
);
1224 #endif /* CONFIG_MOUSE */
1228 handle_statusbar() {
1231 switch (r
= read(bar
.fd
, bar
.text
, sizeof bar
.text
- 1)) {
1233 strncpy(bar
.text
, strerror(errno
), sizeof bar
.text
- 1);
1234 bar
.text
[sizeof bar
.text
- 1] = '\0';
1241 bar
.text
[r
] = '\0'; p
= bar
.text
+ strlen(bar
.text
) - 1;
1242 for (; p
>= bar
.text
&& *p
== '\n'; *p
-- = '\0');
1243 for (; p
>= bar
.text
&& *p
!= '\n'; --p
);
1245 strncpy(bar
.text
, p
+ 1, sizeof bar
.text
);
1251 open_or_create_fifo(const char *name
, const char **name_created
) {
1256 if ((fd
= open(name
, O_RDWR
|O_NONBLOCK
)) == -1) {
1257 if (errno
== ENOENT
&& !mkfifo(name
, S_IRUSR
|S_IWUSR
)) {
1258 *name_created
= name
;
1261 error("%s\n", strerror(errno
));
1265 if (fstat(fd
, &info
) == -1)
1266 error("%s\n", strerror(errno
));
1267 if (!S_ISFIFO(info
.st_mode
))
1268 error("%s is not a named pipe\n", name
);
1275 eprint("usage: dvtm [-v] [-M] [-m mod] [-d delay] [-h lines] [-t title] "
1276 "[-s status-fifo] [-c cmd-fifo] [cmd...]\n");
1281 parse_args(int argc
, char *argv
[]) {
1285 if (!getenv("ESCDELAY"))
1287 for (arg
= 1; arg
< argc
; arg
++) {
1288 if (argv
[arg
][0] != '-') {
1289 const char *args
[] = { argv
[arg
], NULL
, NULL
};
1297 if (argv
[arg
][1] != 'v' && argv
[arg
][1] != 'M' && (arg
+ 1) >= argc
)
1299 switch (argv
[arg
][1]) {
1301 puts("dvtm-"VERSION
" © 2007-2013 Marc André Tanner");
1304 mouse_events_enabled
= !mouse_events_enabled
;
1307 char *mod
= argv
[++arg
];
1308 if (mod
[0] == '^' && mod
[1])
1309 *mod
= CTRL(mod
[1]);
1310 for (unsigned int i
= 0; i
< countof(keys
); i
++)
1315 set_escdelay(atoi(argv
[++arg
]));
1318 else if (ESCDELAY
> 1000)
1322 screen
.history
= atoi(argv
[++arg
]);
1325 title
= argv
[++arg
];
1328 bar
.fd
= open_or_create_fifo(argv
[++arg
], &bar
.file
);
1333 cmdfifo
.fd
= open_or_create_fifo(argv
[++arg
], &cmdfifo
.file
);
1334 if (!(fifo
= realpath(argv
[arg
], NULL
)))
1335 error("%s\n", strerror(errno
));
1336 setenv("DVTM_CMD_FIFO", fifo
, 1);
1347 main(int argc
, char *argv
[]) {
1348 if (!parse_args(argc
, argv
)) {
1358 if (screen
.need_resize
) {
1360 screen
.need_resize
= false;
1364 FD_SET(STDIN_FILENO
, &rd
);
1366 if (cmdfifo
.fd
!= -1) {
1367 FD_SET(cmdfifo
.fd
, &rd
);
1372 FD_SET(bar
.fd
, &rd
);
1373 nfds
= max(nfds
, bar
.fd
);
1376 for (c
= clients
; c
; ) {
1383 FD_SET(c
->pty
, &rd
);
1384 nfds
= max(nfds
, c
->pty
);
1388 r
= select(nfds
+ 1, &rd
, NULL
, NULL
, NULL
);
1390 if (r
== -1 && errno
== EINTR
)
1398 if (FD_ISSET(STDIN_FILENO
, &rd
)) {
1402 if (code
== KEY_MOUSE
) {
1404 } else if (is_modifier(code
)) {
1410 else if ((key
= keybinding(mod
, code
)))
1411 key
->action
.cmd(key
->action
.args
);
1413 } else if ((key
= keybinding(0, code
))) {
1414 key
->action
.cmd(key
->action
.args
);
1415 } else if (sel
&& vt_copymode(sel
->term
)) {
1416 vt_copymode_keypress(sel
->term
, code
);
1422 if (r
== 1) /* no data available on pty's */
1426 if (cmdfifo
.fd
!= -1 && FD_ISSET(cmdfifo
.fd
, &rd
))
1429 if (bar
.fd
!= -1 && FD_ISSET(bar
.fd
, &rd
))
1432 for (c
= clients
; c
; ) {
1433 if (FD_ISSET(c
->pty
, &rd
) && !vt_copymode(c
->term
)) {
1434 if (vt_process(c
->term
) < 0 && errno
== EIO
) {
1435 /* client probably terminated */
1441 if (c
!= sel
&& is_visible(c
)) {
1443 wnoutrefresh(c
->window
);
1449 if (is_visible(sel
)) {
1451 wnoutrefresh(sel
->window
);