quake-style console with xterm
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove debugging

jcs 40d9d1ea 220a658c

+7 -45
+7 -45
qconsole.c
··· 1 1 /* vim:ts=8 2 - * $Id: qconsole.c,v 1.3 2008/11/14 04:24:05 jcs Exp $ 2 + * $Id: qconsole.c,v 1.4 2008/11/14 04:26:21 jcs Exp $ 3 3 * 4 4 * Copyright (c) 2005, 2008 joshua stein <jcs@jcs.org> 5 5 * ··· 47 47 #define DIR_DOWN -1 48 48 49 49 #define MAX_SPEED 10 50 - #define DEF_SPEED 8 50 + #define DEF_SPEED 9 51 51 #define DEF_HEIGHT 157 52 52 53 53 #define BORDER 4 ··· 85 85 86 86 extern char *__progname; 87 87 88 - void dprintf(char *fmt, ...); 89 88 void draw_window(const char *); 90 89 void scroll(int direction, int quick); 91 90 void xterm_handler(int sig); 92 91 void exit_handler(int sig); 93 92 void x_error_handler(Display * d, XErrorEvent * e); 94 93 void usage(void); 95 - 96 - void 97 - dprintf(char *fmt, ...) 98 - { 99 - static char buf[1024]; 100 - va_list args; 101 - 102 - char timestr[50]; 103 - struct tm *parts; 104 - time_t now; 105 - 106 - (void)time(&now); 107 - parts = localtime(&now); 108 - strftime(timestr, sizeof timestr, "%H:%M:%S", parts); 109 - 110 - va_start(args, fmt); 111 - (void) vsnprintf(buf, sizeof(buf), fmt, args); 112 - va_end(args); 113 - 114 - printf("%s - %d - %s", timestr, respawning, buf); 115 - } 116 94 117 95 int 118 96 main(int argc, char* argv[]) ··· 121 99 int c; 122 100 123 101 bzero(&main_win, sizeof(struct xinfo)); 124 - 125 102 main_win.height = DEF_HEIGHT; 126 103 main_win.speed = DEF_SPEED; 127 104 main_win.cur_direction = DIR_UP; ··· 167 144 signal(SIGCHLD, xterm_handler); 168 145 xterm_handler(0); 169 146 147 + /* wait for events */ 170 148 for (;;) { 171 149 XEvent event; 172 150 bzero(&event, sizeof(XEvent)); 173 151 XNextEvent(main_win.dpy, &event); 174 - 175 - dprintf("got event %d\n", event.type); 176 152 177 153 switch (event.type) { 178 154 case ReparentNotify: 179 155 { 180 156 /* xterm spawned and reparented to us */ 181 - dprintf("got reparentnotify\n"); 182 - 183 157 XReparentEvent *e = (XReparentEvent *) &event; 184 158 main_win.xterm = e->window; 185 159 ··· 275 249 unsigned width, height, bw, depth; 276 250 Window root; 277 251 278 - dprintf("scrolling %s %s\n", (direction == DIR_DOWN ? "down" : "up"), 279 - (quick ? "quickly" : "")); 280 - 281 252 if (direction == DIR_DOWN) { 282 253 XSetInputFocus(main_win.dpy, main_win.xterm, RevertToParent, 283 254 CurrentTime); ··· 321 292 { 322 293 pid_t pid; 323 294 324 - dprintf("in xterm_handler with sig %d\n", sig); 325 - 326 - if (shutting_down || respawning) { 327 - dprintf("returning from xterm_handler\n"); 295 + if (shutting_down || respawning) 328 296 return; 329 - } else if (sig) { 330 - dprintf("respawning\n"); 297 + else if (sig) 331 298 respawning = 1; 332 - } 333 299 334 300 /* clean up if previous xterm died */ 335 301 if (xterm_pid) { 336 - if (waitpid(-1, NULL, WNOHANG)) 337 - dprintf("wait returned something\n"); 338 - else 339 - dprintf("no wait\n"); 340 - 302 + waitpid(-1, NULL, WNOHANG); 341 303 xterm_pid = 0; 342 304 343 305 scroll(DIR_UP, 1); 306 + 344 307 XUnmapSubwindows(main_win.dpy, main_win.win); 345 308 } 346 309 ··· 351 314 352 315 case 0: 353 316 /* fork xterm and pass our window id to -into opt */ 354 - dprintf("running xterm\n"); 355 317 asprintf(&xterm_args[4], "%d", (int)main_win.win); 356 318 execvp("xterm", xterm_args); 357 319 exit(0);