void term_set_font(GtkWidget *win, VteTerminal *term, size_t index) { PangoFontDescription *font_desc = NULL; glong width, height; if (index >= sizeof fonts / sizeof fonts[0]) { fprintf(stderr, __NAME__": Warning: Invalid font index\n"); return; } width = vte_terminal_get_column_count(term); height = vte_terminal_get_row_count(term); font_desc = pango_font_description_from_string(fonts[index]); vte_terminal_set_font(term, font_desc); pango_font_description_free(font_desc); vte_terminal_set_font_scale(term, 1); term_set_size(win, term, width, height); if (win != NULL) vte_terminal_set_geometry_hints_for_window(VTE_TERMINAL(term), GTK_WINDOW(win)); }
static void term_resize(int w, int h) { minsize.width = w; minsize.height = h; // try to set the terminal size if the terminal will let us: term_set_size(h, w); // (this works in gnome-terminal, but causes trouble for curses on maximized windows.) // now make sure it worked, and ask the user to resize the terminal if it didn't ensure_size(); // make a new cell buffer if (cell_buffer) free(cell_buffer); cell_buffer = malloc(sizeof(pairmode_cell) * w * h); // add error checking int i; for (i = 0; i < w * h; i++) { // I guess we could just zero it all, hmm cell_buffer[i].ch = 0; cell_buffer[i].pair = 0; cell_buffer[i].fore.idx = 0; cell_buffer[i].back.idx = 0; } }
void winchforwarder(int sig) { struct winsize win; ioctl(STDIN_FILENO, TIOCGWINSZ, &win); win.ws_row-=2; term_set_size(term, win.ws_row, win.ws_col); term_set_offset(term, 0, 0); ioctl(master, TIOCSWINSZ, &win); term_set_size(term2, 2, win.ws_col); term_set_offset(term2, win.ws_row, 0); win.ws_row=2; ioctl(master2, TIOCSWINSZ, &win); }
void term_set_font_scale(GtkWidget *win, VteTerminal *term, gdouble mult) { gdouble s; glong width, height; width = vte_terminal_get_column_count(term); height = vte_terminal_get_row_count(term); s = vte_terminal_get_font_scale(term); s *= mult; vte_terminal_set_font_scale(term, s); term_set_size(win, term, width, height); vte_terminal_set_geometry_hints_for_window(VTE_TERMINAL(term), GTK_WINDOW(win)); }
void sig_window_resize(VteTerminal *term, guint width, guint height, gpointer data) { term_set_size((GtkWidget *)data, term, width, height); }
int main(int argc, char *argv[]) { int cc; struct termios rtt, stt; struct winsize win; int ch, n; struct timeval tv, *tvp; time_t tvec, start; char obuf[BUFSIZ]; char ibuf[BUFSIZ]; fd_set rfd; int flushtime = 30; int readstdin; int nfds=0; while ((ch = getopt(argc, argv, "hnw")) != -1) switch(ch) { case 'n': ambi_width=1; break; case 'w': ambi_width=2; break; case 'h': case '?': default: usage(); } argc -= optind; argv += optind; if(getenv("TERMIM")!=NULL) err(1, "already in termim"); if(pipe(tube)==-1) err(1, "pipe"); sprintf(obuf, "%d", tube[1]); setenv("TERMIM", obuf, 1); if ((ttyflg = isatty(STDIN_FILENO)) != 0) { if (tcgetattr(STDIN_FILENO, &tt) == -1) err(1, "tcgetattr"); if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) err(1, "ioctl"); win.ws_row-=2; term=term_create(); term_assoc_output(term, STDOUT_FILENO); term_set_size(term, win.ws_row, win.ws_col); term_set_offset(term, 0, 0); if (openpty(&master, &slave, NULL, &tt, &win) == -1) err(1, "openpty"); term2=term_create(); term_assoc_output(term2, STDOUT_FILENO); term_set_size(term2, 2, win.ws_col); term_set_offset(term2, win.ws_row, 0); win.ws_row=2; if (openpty(&master2, &slave2, NULL, &tt, &win) == -1) err(1, "openpty"); } else { if (openpty(&master, &slave, NULL, NULL, NULL) == -1) err(1, "openpty"); if (openpty(&master2, &slave2, NULL, NULL, NULL) == -1) err(1, "openpty"); } if (!qflg) { tvec = time(NULL); } if (ttyflg) { rtt = tt; cfmakeraw(&rtt); rtt.c_lflag &= ~ECHO; (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt); } tcgetattr(master2, &rtt); cfmakeraw(&rtt); rtt.c_lflag &= ~ECHO; tcsetattr(master2, TCSAFLUSH, &rtt); signal(SIGCHLD, &sigchild); child = fork(); if (child < 0) { warn("fork"); done(1); } if (child == 0) doshell(argv); close(slave); child2 = fork(); if (child2 < 0) { warn("fork"); done(1); } if (child2 == 0) dodock(); close(tube[1]); fcntl(tube[0], F_SETFL, O_NONBLOCK); fcntl(master, F_SETFL, O_NONBLOCK); signal(SIGINT, &sigforwarder); signal(SIGQUIT, &sigforwarder); signal(SIGPIPE, &sigforwarder); #ifndef __linux signal(SIGINFO, &sigforwarder); #endif signal(SIGUSR1, &sigforwarder); signal(SIGUSR2, &sigforwarder); signal(SIGWINCH, &winchforwarder); #define RESET "\033[m\033[2J\033[H" term_write(term, RESET, sizeof(RESET)); term_write(term2, RESET, sizeof(RESET)); start = tvec = time(0); readstdin = 1; if(master2 > tube[0]) nfds = tube[0]; if(master > nfds) nfds = master; if(master2 > nfds) nfds = master2; if(STDIN_FILENO > nfds) nfds = STDIN_FILENO; nfds+=1; for (;;) { FD_ZERO(&rfd); FD_SET(tube[0], &rfd); FD_SET(master, &rfd); FD_SET(master2, &rfd); if (readstdin) FD_SET(STDIN_FILENO, &rfd); if (!readstdin && ttyflg) { tv.tv_sec = 1; tv.tv_usec = 0; tvp = &tv; readstdin = 1; } else if (flushtime > 0) { tv.tv_sec = flushtime - (tvec - start); tv.tv_usec = 0; tvp = &tv; } else { tvp = NULL; } n = select(nfds, &rfd, 0, 0, tvp); if (n < 0 && errno != EINTR) break; if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) { cc = read(STDIN_FILENO, ibuf, sizeof (ibuf)); if (cc < 0) break; if (cc == 0) { if (tcgetattr(master, &stt) == 0 && (stt.c_lflag & ICANON) != 0) { (void)write(master, &stt.c_cc[VEOF], 1); } readstdin = 0; } write(master2, ibuf, cc); } if (n > 0 && FD_ISSET(master, &rfd)) { while(1){ cc = read(master, obuf, sizeof (obuf)); if (cc <= 0) break; term_write(term, obuf, cc); } } if (n > 0 && FD_ISSET(master2, &rfd)) { cc = read(master2, obuf, sizeof (obuf)); if (cc <= 0) break; term_write(term2, obuf, cc); } if (n > 0 && FD_ISSET(tube[0], &rfd)) { cc = read(tube[0], ibuf, sizeof (ibuf)); if(cc < 0 && errno!=EAGAIN) break; write(master, ibuf, cc); } tvec = time(0); if (tvec - start >= flushtime) { start = tvec; } } finish(); done(0); }