--- rxvt-unicode/src/init.C 2005/08/11 02:05:07 1.119 +++ rxvt-unicode/src/init.C 2006/01/11 00:59:58 1.137 @@ -11,7 +11,7 @@ * - extensive modifications * Copyright (c) 1999 D J Hawkey Jr * - QNX support - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,8 @@ #include "rxvtutil.h" #include "init.h" +#include + #include const char *const def_colorName[] = @@ -44,7 +46,6 @@ COLOR_BACKGROUND, /* low-intensity colors */ "Black", /* 0: black (#000000) */ -#ifndef NO_BRIGHTCOLOR "Red3", /* 1: red (#CD0000) */ "Green3", /* 2: green (#00CD00) */ "Yellow3", /* 3: yellow (#CDCD00) */ @@ -62,7 +63,6 @@ # else "Grey25", /* 8: bright black (#404040) */ # endif -#endif /* NO_BRIGHTCOLOR */ "Red", /* 1/9: bright red (#FF0000) */ "Green", /* 2/10: bright green (#00FF00) */ "Yellow", /* 3/11: bright yellow (#FFFF00) */ @@ -218,9 +218,6 @@ bool rxvt_term::init_vars () { - sw_term.start (SIGTERM); - sw_int.start (SIGINT); - pix_colors_focused = new rxvt_color [TOTAL_COLORS]; #ifdef OFF_FOCUS_FADING pix_colors_unfocused = new rxvt_color [TOTAL_COLORS]; @@ -231,7 +228,7 @@ return false; #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) - TermWin.pixmap = None; + pixmap = None; #endif MEvent.time = CurrentTime; @@ -239,13 +236,13 @@ options = DEFAULT_OPTIONS; want_refresh = 1; priv_modes = SavedModes = PrivMode_Default; - TermWin.focus = 0; - TermWin.ncol = 80; - TermWin.nrow = 24; - TermWin.int_bwidth = INTERNALBORDERWIDTH; - TermWin.ext_bwidth = EXTERNALBORDERWIDTH; - TermWin.lineSpace = LINESPACE; - TermWin.saveLines = SAVELINES; + focus = 0; + ncol = 80; + nrow = 24; + int_bwidth = INTERNALBORDERWIDTH; + ext_bwidth = EXTERNALBORDERWIDTH; + lineSpace = LINESPACE; + saveLines = SAVELINES; numpix_colors = TOTAL_COLORS; refresh_limit = 1; @@ -344,13 +341,17 @@ /* * Open display, get options/resources and create the window */ - if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) - rs[Rs_display_name] = ":0"; + { + TEMP_ENV; + + if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) + rs[Rs_display_name] = ":0"; - get_options (r_argc, r_argv); + get_options (r_argc, r_argv); - if (!(display = displays.get (rs[Rs_display_name]))) - rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); + if (!(display = displays.get (rs[Rs_display_name]))) + rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); + } extract_resources (); free (r_argv); @@ -374,15 +375,17 @@ } if (rs[Rs_saveLines] && (i = atoi (rs[Rs_saveLines])) >= 0) - TermWin.saveLines = BOUND_POSITIVE_INT16 (i); + saveLines = min (i, MAX_SAVELINES); #if ENABLE_FRILLS if (rs[Rs_int_bwidth] && (i = atoi (rs[Rs_int_bwidth])) >= 0) - TermWin.int_bwidth = min (i, 100); /* arbitrary limit */ + int_bwidth = min (i, std::numeric_limits::max ()); + if (rs[Rs_ext_bwidth] && (i = atoi (rs[Rs_ext_bwidth])) >= 0) - TermWin.ext_bwidth = min (i, 100); /* arbitrary limit */ + ext_bwidth = min (i, std::numeric_limits::max ()); + if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0) - TermWin.lineSpace = min (i, 100); /* arbitrary limit */ + lineSpace = min (i, std::numeric_limits::max ()); #endif #ifdef POINTER_BLANK @@ -393,8 +396,8 @@ #endif /* no point having a scrollbar without having any scrollback! */ - if (!TermWin.saveLines) - options &= ~Opt_scrollBar; + if (!saveLines) + set_option (Opt_scrollBar, 0); #ifdef PRINTPIPE if (!rs[Rs_print_pipe]) @@ -447,7 +450,7 @@ #ifdef XTERM_REVERSE_VIDEO /* this is how xterm implements reverseVideo */ - if (options & Opt_reverseVideo) + if (OPTION (Opt_reverseVideo)) { if (!rs[Rs_color + Color_fg]) rs[Rs_color + Color_fg] = def_colorName[Color_bg]; @@ -462,8 +465,8 @@ #ifndef XTERM_REVERSE_VIDEO /* this is how we implement reverseVideo */ - if (options & Opt_reverseVideo) - SWAP_IT (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg], const char *); + if (OPTION (Opt_reverseVideo)) + ::swap (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg]); #endif /* convenient aliases for setting fg/bg to colors */ @@ -523,14 +526,14 @@ sprintf (env_display, "DISPLAY=%s", val); /* avoiding the math library: - * i = (int) (ceil (log10 ((unsigned int)TermWin.parent[0]))) */ - for (i = 0, u = (unsigned int)TermWin.parent[0]; u; u /= 10, i++) + * i = (int) (ceil (log10 ((unsigned int)parent[0]))) */ + for (i = 0, u = (unsigned int)parent[0]; u; u /= 10, i++) ; - MAX_IT (i, 1); + max_it (i, 1); env_windowid = (char *)rxvt_malloc ((i + 10) * sizeof (char)); sprintf (env_windowid, "WINDOWID=%u", - (unsigned int)TermWin.parent[0]); + (unsigned int)parent[0]); /* add entries to the environment: * @ DISPLAY: in case we started with -display @@ -579,6 +582,8 @@ void rxvt_term::set_locale (const char *locale) { + TEMP_ENV; + #if HAVE_XSETLOCALE || HAVE_SETLOCALE free (this->locale); this->locale = setlocale (LC_CTYPE, locale); @@ -587,13 +592,13 @@ { if (*locale) { - rxvt_warn ("unable to set locale \"%s\", using default locale instead.\n", locale); - setlocale (LC_CTYPE, ""); + rxvt_warn ("unable to set locale \"%s\", using C locale instead.\n", locale); + setlocale (LC_CTYPE, "C"); } else rxvt_warn ("default locale unavailable, check LC_* and LANG variables. Continuing.\n"); - this->locale = ""; + this->locale = "C"; } @@ -618,6 +623,8 @@ void rxvt_term::init_xlocale () { + TEMP_ENV; + #ifdef USE_XIM if (!locale) rxvt_warn ("setting locale failed, working without locale support.\n"); @@ -649,16 +656,16 @@ */ #ifdef META8_OPTION - meta_char = (options & Opt_meta8 ? 0x80 : C0_ESC); + meta_char = OPTION (Opt_meta8) ? 0x80 : C0_ESC; #endif get_ourmods (); - if (!(options & Opt_scrollTtyOutput)) + if (!OPTION (Opt_scrollTtyOutput)) priv_modes |= PrivMode_TtyOutputInh; - if (options & Opt_scrollTtyKeypress) + if (OPTION (Opt_scrollTtyKeypress)) priv_modes |= PrivMode_Keypress; - if (!(options & Opt_jumpScroll)) + if (!OPTION (Opt_jumpScroll)) priv_modes |= PrivMode_smoothScroll; #ifndef NO_BACKSPACE_KEY @@ -679,11 +686,6 @@ SavedModes |= PrivMode_menuBar; } -#ifdef CURSOR_BLINK - if (options & Opt_cursorBlink) - (void)gettimeofday (&lastcursorchange, NULL); -#endif - run_command (argv); } @@ -707,7 +709,7 @@ if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) { #ifndef XTERM_REVERSE_VIDEO - if (i < 2 && (options & Opt_reverseVideo)) + if (i < 2 && OPTION (Opt_reverseVideo)) rs[Rs_color + i] = def_colorName[!i]; else #endif @@ -814,10 +816,8 @@ if (i >= 8 && i <= 15) { /* bright colors */ i -= 8; -#ifndef NO_BRIGHTCOLOR rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i]; return; -#endif } if (i >= 0 && i <= 7) /* normal colors */ @@ -940,14 +940,14 @@ assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); XInternAtoms (disp, (char **)xa_names, NUM_XA, False, xa); - if (options & Opt_transparent) + if (OPTION (Opt_transparent)) { XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr); display->depth = gattr.depth; // doh //TODO, per-term not per-display? } #if ENABLE_FRILLS - if (options & Opt_borderLess) + if (OPTION (Opt_borderLess)) { prop = XInternAtom(disp, "_MOTIF_WM_INFO", True); @@ -989,8 +989,8 @@ window_calc (wattr.width, wattr.height); } - #endif + window_calc (0, 0); /* sub-window placement & size in rxvt_resize_subwindows () */ @@ -1001,7 +1001,7 @@ top = XCreateWindow (disp, parent, szHint.x, szHint.y, szHint.width, szHint.height, - TermWin.ext_bwidth, + ext_bwidth, display->depth, InputOutput, display->visual, CWColormap | CWBackPixel | CWBorderPixel, &attributes); @@ -1009,12 +1009,12 @@ top = XCreateSimpleWindow (disp, parent, szHint.x, szHint.y, szHint.width, szHint.height, - TermWin.ext_bwidth, + ext_bwidth, pix_colors_focused[Color_border], pix_colors_focused[Color_border]); #endif - TermWin.parent[0] = top; + this->parent[0] = top; old_width = szHint.width; old_height = szHint.height; @@ -1027,7 +1027,7 @@ wmHint.flags = InputHint | StateHint | WindowGroupHint; wmHint.input = True; - wmHint.initial_state = options & Opt_iconic ? IconicState : NormalState; + wmHint.initial_state = OPTION (Opt_iconic) ? IconicState : NormalState; wmHint.window_group = top; XmbSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc, @@ -1042,6 +1042,11 @@ XSetWMProtocols (disp, top, protocols, sizeof (protocols) / sizeof (protocols[0])); +#if ENABLE_FRILLS + if (rs[Rs_transient_for]) + XSetTransientForHint (disp, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); +#endif + #if ENABLE_EWMH long pid = getpid (); @@ -1077,39 +1082,41 @@ #endif /* the vt window */ - TermWin.vt = XCreateSimpleWindow (disp, top, + vt = XCreateSimpleWindow (disp, top, window_vt_x, window_vt_y, - TermWin_TotalWidth (), - TermWin_TotalHeight (), + width, + height, 0, pix_colors_focused[Color_fg], pix_colors_focused[Color_bg]); #ifdef DEBUG_X - XStoreName (disp, TermWin.vt, "vt window"); + XStoreName (disp, vt, "vt window"); #endif attributes.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (disp, TermWin.vt, CWBitGravity, &attributes); + XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes); vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; -#ifdef POINTER_BLANK - if (options & Opt_pointerBlank) + if (OPTION (Opt_pointerBlank) +#ifdef ENABLE_PERL + || perl.self +#endif + ) vt_emask |= PointerMotionMask; else -#endif vt_emask |= Button1MotionMask | Button3MotionMask; - XSelectInput (disp, TermWin.vt, vt_emask); - vt_ev.start (display, TermWin.vt); + XSelectInput (disp, vt, vt_emask); + vt_ev.start (display, vt); #if defined(MENUBAR) && (MENUBAR_MAX > 1) if (menuBar_height ()) { menuBar.win = XCreateSimpleWindow (disp, top, window_vt_x, 0, - TermWin_TotalWidth (), + width, menuBar_TotalHeight (), 0, pix_colors_focused[Color_fg], @@ -1132,7 +1139,7 @@ #ifdef XPM_BACKGROUND if (rs[Rs_backgroundPixmap] != NULL - && ! (options & Opt_transparent)) + && ! OPTION (Opt_transparent)) { const char *p = rs[Rs_backgroundPixmap]; @@ -1151,19 +1158,19 @@ gcvalue.foreground = pix_colors[Color_fg]; gcvalue.background = pix_colors[Color_bg]; gcvalue.graphics_exposures = 1; - TermWin.gc = XCreateGC (disp, TermWin.vt, + gc = XCreateGC (disp, vt, GCForeground | GCBackground | GCGraphicsExposures, &gcvalue); - TermWin.drawable = new rxvt_drawable (display, TermWin.vt); + drawable = new rxvt_drawable (display, vt); #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) gcvalue.foreground = pix_colors[Color_topShadow]; - topShadowGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); + topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[Color_bottomShadow]; - botShadowGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); + botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)]; - scrollbarGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); + scrollbarGC = XCreateGC (disp, vt, GCForeground, &gcvalue); #endif #ifdef OFF_FOCUS_FADING @@ -1198,56 +1205,52 @@ */ if (GET_TERMIOS (STDIN_FILENO, tio) < 0) { - /* return error - use system defaults */ + // return error - use system defaults, + // where possible, and zero elsewhere + memset (tio, 0, sizeof (ttymode_t)); + tio->c_cc[VINTR] = CINTR; tio->c_cc[VQUIT] = CQUIT; tio->c_cc[VERASE] = CERASE; +#ifdef VERASE2 + tio->c_cc[VERASE2] = CERASE2; +#endif tio->c_cc[VKILL] = CKILL; tio->c_cc[VSTART] = CSTART; tio->c_cc[VSTOP] = CSTOP; tio->c_cc[VSUSP] = CSUSP; # ifdef VDSUSP - tio->c_cc[VDSUSP] = CDSUSP; # endif # ifdef VREPRINT - tio->c_cc[VREPRINT] = CRPRNT; # endif # ifdef VDISCRD - tio->c_cc[VDISCRD] = CFLUSH; # endif # ifdef VWERSE - tio->c_cc[VWERSE] = CWERASE; # endif # ifdef VLNEXT - tio->c_cc[VLNEXT] = CLNEXT; # endif - } + tio->c_cc[VEOF] = CEOF; tio->c_cc[VEOL] = VDISABLE; # ifdef VEOL2 - tio->c_cc[VEOL2] = VDISABLE; # endif # ifdef VSWTC - tio->c_cc[VSWTC] = VDISABLE; # endif # ifdef VSWTCH - tio->c_cc[VSWTCH] = VDISABLE; # endif # if VMIN != VEOF - tio->c_cc[VMIN] = 1; # endif # if VTIME != VEOL - tio->c_cc[VTIME] = 0; # endif @@ -1285,6 +1288,7 @@ tio->sg.sg_erase = CERASE; /* ^H */ tio->sg.sg_kill = CKILL; /* ^U */ } + if (erase != -1) tio->sg.sg_erase = (char)erase; @@ -1300,6 +1304,7 @@ tio->tc.t_eofc = CEOF; /* ^D */ tio->tc.t_brkc = -1; } + /* get local special chars */ if (ioctl (STDIN_FILENO, TIOCGLTC, & (tio->lc)) < 0) { @@ -1313,7 +1318,6 @@ /* get line discipline */ ioctl (STDIN_FILENO, TIOCGETD, & (tio->line)); # ifdef NTTYDISC - tio->line = NTTYDISC; # endif /* NTTYDISC */ @@ -1346,15 +1350,12 @@ FOO (IXON, "IXON"); FOO (IXOFF, "IXOFF"); # ifdef IUCLC - FOO (IUCLC, "IUCLC"); # endif # ifdef IXANY - FOO (IXANY, "IXANY"); # endif # ifdef IMAXBEL - FOO (IMAXBEL, "IMAXBEL"); # endif @@ -1371,39 +1372,30 @@ FOO (VEOF, "VEOF"); FOO (VEOL, "VEOL"); # ifdef VEOL2 - FOO (VEOL2, "VEOL2"); # endif # ifdef VSWTC - FOO (VSWTC, "VSWTC"); # endif # ifdef VSWTCH - FOO (VSWTCH, "VSWTCH"); # endif - FOO (VSTART, "VSTART"); FOO (VSTOP, "VSTOP"); FOO (VSUSP, "VSUSP"); # ifdef VDSUSP - FOO (VDSUSP, "VDSUSP"); # endif # ifdef VREPRINT - FOO (VREPRINT, "VREPRINT"); # endif # ifdef VDISCRD - FOO (VDISCRD, "VDISCRD"); # endif # ifdef VWERSE - FOO (VWERSE, "VWERSE"); # endif # ifdef VLNEXT - FOO (VLNEXT, "VLNEXT"); # endif @@ -1426,7 +1418,15 @@ if (rs[Rs_pty_fd]) { pty.pty = atoi (rs[Rs_pty_fd]); - fcntl (pty.pty, F_SETFL, O_NONBLOCK); + + if (pty.pty >= 0) + { + if (getfd_hook) + pty.pty = (*getfd_hook) (pty.pty); + + if (pty.pty < 0 || fcntl (pty.pty, F_SETFL, O_NONBLOCK)) + rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); + } } else #endif @@ -1456,8 +1456,6 @@ return; #endif - sw_chld.start (SIGCHLD); - #ifndef __QNX__ /* spin off the command interpreter */ switch (cmd_pid = fork ()) @@ -1537,9 +1535,11 @@ { char *login; + TEMP_ENV; // not very temporary... + SET_TTYMODE (STDIN_FILENO, &tio); /* init terminal attributes */ - if (options & Opt_console) + if (OPTION (Opt_console)) { /* be virtual console, fail silently */ #ifdef TIOCCONS unsigned int on = 1; @@ -1592,14 +1592,14 @@ } else { - const char *argv0, *shell; + const char *argv0, *shell; if ((shell = getenv ("SHELL")) == NULL || *shell == '\0') shell = "/bin/sh"; argv0 = (const char *)rxvt_r_basename (shell); - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) { login = (char *)rxvt_malloc ((strlen (argv0) + 2) * sizeof (char)); @@ -1607,6 +1607,7 @@ strcpy (&login[1], argv0); argv0 = login; } + execlp (shell, argv0, NULL); /* no error message: STDERR is closed! */ } @@ -1644,7 +1645,7 @@ arg_a[0] = my_basename (command); - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) { login = rxvt_malloc ((strlen (arg_a[0]) + 2) * sizeof (char));