--- rxvt-unicode/src/init.C 2005/12/18 00:59:42 1.122 +++ rxvt-unicode/src/init.C 2006/01/07 19:29:17 1.135 @@ -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) */ @@ -371,15 +371,17 @@ } if (rs[Rs_saveLines] && (i = atoi (rs[Rs_saveLines])) >= 0) - 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) - 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) - 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) - lineSpace = min (i, 100); /* arbitrary limit */ + lineSpace = min (i, std::numeric_limits::max ()); #endif #ifdef POINTER_BLANK @@ -391,7 +393,7 @@ /* no point having a scrollbar without having any scrollback! */ if (!saveLines) - options &= ~Opt_scrollBar; + CLR_OPTION (Opt_scrollBar); #ifdef PRINTPIPE if (!rs[Rs_print_pipe]) @@ -444,7 +446,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]; @@ -459,8 +461,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,7 +525,7 @@ * 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", @@ -646,16 +648,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 @@ -676,11 +678,6 @@ SavedModes |= PrivMode_menuBar; } -#ifdef CURSOR_BLINK - if (options & Opt_cursorBlink) - (void)gettimeofday (&lastcursorchange, NULL); -#endif - run_command (argv); } @@ -704,7 +701,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 @@ -811,10 +808,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 */ @@ -937,14 +932,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); @@ -1024,7 +1019,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, @@ -1039,6 +1034,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,8 +1077,8 @@ 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]); @@ -1091,11 +1091,13 @@ 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, vt, vt_emask); @@ -1106,7 +1108,7 @@ { menuBar.win = XCreateSimpleWindow (disp, top, window_vt_x, 0, - TermWin_TotalWidth (), + width, menuBar_TotalHeight (), 0, pix_colors_focused[Color_fg], @@ -1129,7 +1131,7 @@ #ifdef XPM_BACKGROUND if (rs[Rs_backgroundPixmap] != NULL - && ! (options & Opt_transparent)) + && ! OPTION (Opt_transparent)) { const char *p = rs[Rs_backgroundPixmap]; @@ -1195,10 +1197,16 @@ */ 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; @@ -1402,7 +1410,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 @@ -1513,7 +1529,7 @@ 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; @@ -1573,7 +1589,7 @@ argv0 = (const char *)rxvt_r_basename (shell); - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) { login = (char *)rxvt_malloc ((strlen (argv0) + 2) * sizeof (char)); @@ -1618,7 +1634,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));