--- rxvt-unicode/src/init.C 2006/01/06 05:28:55 1.133 +++ rxvt-unicode/src/init.C 2007/10/18 09:11:42 1.218 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: init.C *----------------------------------------------------------------------* * @@ -7,11 +7,14 @@ * - original version * Copyright (c) 1994 Robert Nation * - extensive modifications + * Copyright (c) 1996 Chuck Blake + * Copyright (c) 1997 mj olesen + * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing * - 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 @@ -40,36 +43,137 @@ #include +#ifdef HAVE_XSETLOCALE +# define X_LOCALE +# include +#else +# ifdef HAVE_SETLOCALE +# include +# endif +#endif + +#ifdef HAVE_NL_LANGINFO +# include +#endif + +#ifdef DISPLAY_IS_IP +/* On Solaris link with -lsocket and -lnsl */ +#include +#include + +/* these next two are probably only on Sun (not Solaris) */ +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#ifdef HAVE_SYS_BYTEORDER_H +#include +#endif + +#include +#include +#include +#include + +static char * +rxvt_network_display (const char *display) +{ + char buffer[1024], *rval = NULL; + struct ifconf ifc; + struct ifreq *ifr; + int i, skfd; + + if (display[0] != ':' && strncmp (display, "unix:", 5)) + return (char *) display; /* nothing to do */ + + ifc.ifc_len = sizeof (buffer); /* Get names of all ifaces */ + ifc.ifc_buf = buffer; + + if ((skfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) + { + perror ("socket"); + return NULL; + } + + if (ioctl (skfd, SIOCGIFCONF, &ifc) < 0) + { + perror ("SIOCGIFCONF"); + close (skfd); + return NULL; + } + + for (i = 0, ifr = ifc.ifc_req; + i < (ifc.ifc_len / sizeof (struct ifreq)); + i++, ifr++) + { + struct ifreq ifr2; + + strcpy (ifr2.ifr_name, ifr->ifr_name); + + if (ioctl (skfd, SIOCGIFADDR, &ifr2) >= 0) + { + unsigned long addr; + struct sockaddr_in *p_addr; + + p_addr = (struct sockaddr_in *) &ifr2.ifr_addr; + addr = htonl ((unsigned long)p_addr->sin_addr.s_addr); + + /* + * not "0.0.0.0" or "127.0.0.1" - so format the address + */ + if (addr && addr != 0x7F000001) + { + char *colon = strchr (display, ':'); + + if (colon == NULL) + colon = ":0.0"; + + rval = rxvt_malloc (strlen (colon) + 16); + sprintf (rval, "%d.%d.%d.%d%s", + (int) ((addr >> 030) & 0xFF), + (int) ((addr >> 020) & 0xFF), + (int) ((addr >> 010) & 0xFF), + (int) (addr & 0xFF), colon); + break; + } + } + } + + close (skfd); + + return rval; +} +#endif + const char *const def_colorName[] = { COLOR_FOREGROUND, COLOR_BACKGROUND, /* low-intensity colors */ - "Black", /* 0: black (#000000) */ - "Red3", /* 1: red (#CD0000) */ - "Green3", /* 2: green (#00CD00) */ - "Yellow3", /* 3: yellow (#CDCD00) */ - "Blue3", /* 4: blue (#0000CD) */ - "Magenta3", /* 5: magenta (#CD00CD) */ - "Cyan3", /* 6: cyan (#00CDCD) */ -# ifdef XTERM_COLORS - "Grey90", /* 7: white (#E5E5E5) */ -# else - "AntiqueWhite", /* 7: white (#FAEBD7) */ + "rgb:00/00/00", // 0: black (Black) + "rgb:cd/00/00", // 1: red (Red3) + "rgb:00/cd/00", // 2: green (Green3) + "rgb:cd/cd/00", // 3: yellow (Yellow3) + "rgb:00/00/cd", // 4: blue (Blue3) + "rgb:cd/00/cd", // 5: magenta (Magenta3) + "rgb:00/cd/cd", // 6: cyan (Cyan3) +# ifdef XTERM_COLORS + "rgb:e5/e5/e5", // 7: white (Grey90) +# else + "rgb:fa/eb/d7", // 7: white (AntiqueWhite) # endif /* high-intensity colors */ # ifdef XTERM_COLORS - "Grey30", /* 8: bright black (#4D4D4D) */ + "rgb:4d/4d/4d", // 8: bright black (Grey30) # else - "Grey25", /* 8: bright black (#404040) */ + "rgb:40/40/40", // 8: bright black (Grey25) # endif - "Red", /* 1/9: bright red (#FF0000) */ - "Green", /* 2/10: bright green (#00FF00) */ - "Yellow", /* 3/11: bright yellow (#FFFF00) */ - "Blue", /* 4/12: bright blue (#0000FF) */ - "Magenta", /* 5/13: bright magenta (#FF00FF) */ - "Cyan", /* 6/14: bright cyan (#00FFFF) */ - "White", /* 7/15: bright white (#FFFFFF) */ + "rgb:ff/00/00", // 1/9: bright red (Reed) + "rgb:00/ff/00", // 2/10: bright green (Green) + "rgb:ff/ff/00", // 3/11: bright yellow (Yellow) + "rgb:00/00/ff", // 4/12: bright blue (Blue) + "rgb:ff/00/ff", // 5/13: bright magenta (Magenta) + "rgb:00/ff/ff", // 6/14: bright cyan (Cyan) + "rgb:ff/ff/ff", // 7/15: bright white (White) // 88 xterm colours "rgb:00/00/00", @@ -168,75 +272,28 @@ COLOR_SCROLLBAR, COLOR_SCROLLTROUGH, #endif /* KEEP_SCROLLCOLOR */ -#if TINTING +#if ENABLE_TRANSPARENCY NULL, #endif #if OFF_FOCUS_FADING - "black", -#endif - }; - -const char *const xa_names[] = - { - "TEXT", - "COMPOUND_TEXT", - "UTF8_STRING", - "MULTIPLE", - "TARGETS", - "TIMESTAMP", - "VT_SELECTION", - "INCR", - "WM_PROTOCOLS", - "WM_DELETE_WINDOW", - "CLIPBOARD", -#if ENABLE_FRILLS - "_MOTIF_WM_HINTS", -#endif -#if ENABLE_EWMH - "_NET_WM_PID", - "_NET_WM_NAME", - "_NET_WM_ICON_NAME", - "_NET_WM_PING", -#endif -#if USE_XIM - "WM_LOCALE_NAME", -#endif -#ifdef TRANSPARENT - "_XROOTPMAP_ID", - "ESETROOT_PMAP_ID", -#endif -#ifdef OFFIX_DND - "DndProtocol", - "DndSelection", -#endif -#if ENABLE_XEMBED - "_XEMBED", - "_XEMBED_INFO", + "rgb:00/00/00", #endif }; bool rxvt_term::init_vars () { - pix_colors_focused = new rxvt_color [TOTAL_COLORS]; + pix_colors = // + pix_colors_focused = new rxvt_color [TOTAL_COLORS]; #ifdef OFF_FOCUS_FADING pix_colors_unfocused = new rxvt_color [TOTAL_COLORS]; #endif - pix_colors = pix_colors_focused; - if (pix_colors == NULL) - return false; - -#if defined(XPM_BACKGROUND) || defined(TRANSPARENT) - pixmap = None; -#endif MEvent.time = CurrentTime; MEvent.button = AnyButton; - options = DEFAULT_OPTIONS; want_refresh = 1; priv_modes = SavedModes = PrivMode_Default; - focus = 0; ncol = 80; nrow = 24; int_bwidth = INTERNALBORDERWIDTH; @@ -245,25 +302,20 @@ saveLines = SAVELINES; numpix_colors = TOTAL_COLORS; - refresh_limit = 1; refresh_type = SLOW_REFRESH; - prev_nrow = prev_ncol = 0; oldcursor.row = oldcursor.col = -1; -#ifdef XPM_BACKGROUND - /* bgPixmap.w = bgPixmap.h = 0; */ - bgPixmap.x = bgPixmap.y = 50; - bgPixmap.pixmap = None; -#endif - last_bot = last_state = -1; -#ifdef MENUBAR - menu_readonly = 1; -# if ! (MENUBAR_MAX > 1) - CurrentBar = &BarList; -# endif /* (MENUBAR_MAX > 1) */ -#endif + set_option (Opt_scrollBar); + set_option (Opt_scrollTtyOutput); + set_option (Opt_jumpScroll); + set_option (Opt_skipScroll); + set_option (Opt_secondaryScreen); + set_option (Opt_secondaryScroll); + set_option (Opt_pastableTabs); + set_option (Opt_intensityStyles); + set_option (Opt_iso14755_52); return true; } @@ -282,7 +334,7 @@ /* TODO: BOO HISS */ dup2 (STDERR_FILENO, STDIN_FILENO); } - else if (i > STDIN_FILENO) + else if (i != STDIN_FILENO) { dup2 (i, STDIN_FILENO); close (i); @@ -307,25 +359,19 @@ rxvt_term::init_resources (int argc, const char *const *argv) { int i, r_argc; - char *val; const char **cmd_argv, **r_argv; /* - * Look for -exec option. Find => split and make cmd_argv[] of command args + * Look for -e option. Find => split and make cmd_argv[] of command args */ for (r_argc = 0; r_argc < argc; r_argc++) - if (!strcmp (argv[r_argc], "-e") || !strcmp (argv[r_argc], "-exec")) + if (!strcmp (argv[r_argc], "-e")) break; - r_argv = (const char **)rxvt_malloc (sizeof (char *) * (r_argc + 1)); - - for (i = 0; i < r_argc; i++) - r_argv[i] = (const char *)argv[i]; - - r_argv[i] = NULL; - if (r_argc == argc) cmd_argv = NULL; + else if (!argv[r_argc + 1]) + rxvt_fatal ("-e requires an argument\n"); else { cmd_argv = (const char **)rxvt_malloc (sizeof (char *) * (argc - r_argc)); @@ -336,29 +382,70 @@ cmd_argv[i] = NULL; } - rs[Rs_name] = rxvt_r_basename (argv[0]); + r_argv = (const char **)rxvt_malloc (sizeof (char *) * (r_argc + 1)); + + for (i = 0; i < r_argc; i++) + r_argv[i] = (const char *)argv[i]; + + r_argv[i] = NULL; + + rs[Rs_name] = rxvt_basename (argv[0]); /* * Open display, get options/resources and create the window */ + if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) rs[Rs_display_name] = ":0"; 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]); + { + free (r_argv); + rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); + } + + // using a local pointer decreases code size a lot + xa = display->xa; + set (display); extract_resources (); + +#if XFT + if (rs[Rs_depth]) + select_visual (strtol (rs[Rs_depth], 0, 0)); +#endif + +#ifdef HAVE_AFTERIMAGE + asv = create_asvisual_for_id (dpy, display->screen, depth, XVisualIDFromVisual (visual), cmap, NULL); +#endif free (r_argv); + for (int i = NUM_RESOURCES; i--; ) + if (rs [i] == resval_undef) + rs [i] = 0; + +#if ENABLE_PERL + if (!rs[Rs_perl_ext_1]) + rs[Rs_perl_ext_1] = "default"; + + if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) + || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) + || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) + { + rxvt_perl.init (this); + HOOK_INVOKE ((this, HOOK_INIT, DT_END)); + } +#endif + /* * set any defaults not already set */ if (cmd_argv && cmd_argv[0]) { if (!rs[Rs_title]) - rs[Rs_title] = rxvt_r_basename (cmd_argv[0]); + rs[Rs_title] = rxvt_basename (cmd_argv[0]); if (!rs[Rs_iconName]) rs[Rs_iconName] = rs[Rs_title]; } @@ -393,7 +480,7 @@ /* no point having a scrollbar without having any scrollback! */ if (!saveLines) - CLR_OPTION (Opt_scrollBar); + set_option (Opt_scrollBar, 0); #ifdef PRINTPIPE if (!rs[Rs_print_pipe]) @@ -406,39 +493,20 @@ #ifndef NO_BACKSPACE_KEY if (!rs[Rs_backspace_key]) # ifdef DEFAULT_BACKSPACE - key_backspace = DEFAULT_BACKSPACE; + rs[Rs_backspace_key] = DEFAULT_BACKSPACE; # else - key_backspace = "DEC"; /* can toggle between \010 or \177 */ + rs[Rs_backspace_key] = "DEC"; /* can toggle between \010 or \177 */ # endif - else - { - val = strdup (rs[Rs_backspace_key]); - rxvt_Str_trim (val); - rxvt_Str_escaped (val); - key_backspace = val; - } #endif #ifndef NO_DELETE_KEY if (!rs[Rs_delete_key]) # ifdef DEFAULT_DELETE - key_delete = DEFAULT_DELETE; + rs[Rs_delete_key] = DEFAULT_DELETE; # else - key_delete = "\033[3~"; + rs[Rs_delete_key] = "\033[3~"; # endif - else - { - val = strdup (rs[Rs_delete_key]); - rxvt_Str_trim (val); - rxvt_Str_escaped (val); - key_delete = val; - } #endif - if (rs[Rs_answerbackstring]) - { - rxvt_Str_trim ((char *)rs[Rs_answerbackstring]); - rxvt_Str_escaped ((char *)rs[Rs_answerbackstring]); - } #ifdef HAVE_SCROLLBARS setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]); @@ -446,10 +514,11 @@ #ifdef XTERM_REVERSE_VIDEO /* this is how xterm implements reverseVideo */ - if (OPTION (Opt_reverseVideo)) + if (option (Opt_reverseVideo)) { if (!rs[Rs_color + Color_fg]) rs[Rs_color + Color_fg] = def_colorName[Color_bg]; + if (!rs[Rs_color + Color_bg]) rs[Rs_color + Color_bg] = def_colorName[Color_fg]; } @@ -461,7 +530,7 @@ #ifndef XTERM_REVERSE_VIDEO /* this is how we implement reverseVideo */ - if (OPTION (Opt_reverseVideo)) + if (option (Opt_reverseVideo)) ::swap (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg]); #endif @@ -492,7 +561,6 @@ rxvt_term::init_env () { int i; - unsigned int u; char *val; #ifdef DISPLAY_IS_IP @@ -511,25 +579,17 @@ if (val == NULL) #endif /* DISPLAY_IS_IP */ - val = XDisplayString (display->display); + val = XDisplayString (dpy); if (rs[Rs_display_name] == NULL) rs[Rs_display_name] = val; /* use broken `:0' value */ i = strlen (val); - env_display = (char *)rxvt_malloc ((i + 9) * sizeof (char)); + env_display = (char *)rxvt_malloc (i + 9); sprintf (env_display, "DISPLAY=%s", val); - /* avoiding the math library: - * i = (int) (ceil (log10 ((unsigned int)parent[0]))) */ - for (i = 0, u = (unsigned int)parent[0]; u; u /= 10, i++) - ; - max_it (i, 1); - env_windowid = (char *)rxvt_malloc ((i + 10) * sizeof (char)); - - sprintf (env_windowid, "WINDOWID=%u", - (unsigned int)parent[0]); + sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent[0]); /* add entries to the environment: * @ DISPLAY: in case we started with -display @@ -541,6 +601,7 @@ */ putenv (env_display); putenv (env_windowid); + if (env_colorfgbg) putenv (env_colorfgbg); @@ -548,14 +609,14 @@ putenv ("TERMINFO=" RXVT_TERMINFO); #endif - if (display->depth <= 2) + if (depth <= 2) putenv ("COLORTERM=" COLORTERMENV "-mono"); else putenv ("COLORTERM=" COLORTERMENVFULL); if (rs[Rs_term_name] != NULL) { - env_term = (char *)rxvt_malloc ((strlen (rs[Rs_term_name]) + 6) * sizeof (char)); + env_term = (char *)rxvt_malloc (strlen (rs[Rs_term_name]) + 6); sprintf (env_term, "TERM=%s", rs[Rs_term_name]); putenv (env_term); } @@ -578,6 +639,8 @@ void rxvt_term::set_locale (const char *locale) { + set_environ (envv); + #if HAVE_XSETLOCALE || HAVE_SETLOCALE free (this->locale); this->locale = setlocale (LC_CTYPE, locale); @@ -586,13 +649,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"; } @@ -617,6 +680,8 @@ void rxvt_term::init_xlocale () { + set_environ (envv); + #ifdef USE_XIM if (!locale) rxvt_warn ("setting locale failed, working without locale support.\n"); @@ -648,36 +713,30 @@ */ #ifdef META8_OPTION - meta_char = OPTION (Opt_meta8) ? 0x80 : C0_ESC; + meta_char = option (Opt_meta8) ? 0x80 : C0_ESC; #endif get_ourmods (); - if (!OPTION (Opt_scrollTtyOutput)) + if (!option (Opt_scrollTtyOutput)) priv_modes |= PrivMode_TtyOutputInh; - if (OPTION (Opt_scrollTtyKeypress)) + if (option (Opt_scrollTtyKeypress)) priv_modes |= PrivMode_Keypress; - if (!OPTION (Opt_jumpScroll)) + if (!option (Opt_jumpScroll)) priv_modes |= PrivMode_smoothScroll; #ifndef NO_BACKSPACE_KEY - if (strcmp (key_backspace, "DEC") == 0) + if (strcmp (rs[Rs_backspace_key], "DEC") == 0) priv_modes |= PrivMode_HaveBackSpace; #endif /* add value for scrollBar */ - if (scrollbar_visible ()) + if (scrollBar.state) { priv_modes |= PrivMode_scrollBar; SavedModes |= PrivMode_scrollBar; } - if (menubar_visible ()) - { - priv_modes |= PrivMode_menuBar; - SavedModes |= PrivMode_menuBar; - } - run_command (argv); } @@ -691,109 +750,99 @@ pix_colors = pix_colors_focused; #endif - for (i = 0; i < (display->depth <= 2 ? 2 : NRS_COLORS); i++) + for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) { - rxvt_color xcol; + const char *name = rs[Rs_color + i]; - if (!rs[Rs_color + i]) + if (!name) continue; - if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) + rxvt_color xcol; + + if (!set_color (xcol, name)) { #ifndef XTERM_REVERSE_VIDEO - if (i < 2 && OPTION (Opt_reverseVideo)) - rs[Rs_color + i] = def_colorName[!i]; + if (i < 2 && option (Opt_reverseVideo)) + name = def_colorName [1 - i]; else #endif - rs[Rs_color + i] = def_colorName[i]; + name = def_colorName [i]; - if (!rs[Rs_color + i]) + if (!name) continue; - if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) + if (!set_color (xcol, name)) { switch (i) { case Color_fg: case Color_bg: - /* fatal: need bg/fg color */ - rxvt_fatal ("unable to get foreground/background colour, aborting.\n"); - /* NOTREACHED */ + rxvt_warn ("unable to get foreground/background colour, continuing.\n"); + name = ""; break; #ifndef NO_CURSORCOLOR case Color_cursor2: - xcol = pix_colors[Color_fg]; - break; -#endif /* ! NO_CURSORCOLOR */ +#endif case Color_pointer_fg: - xcol = pix_colors[Color_fg]; + name = rs[Rs_color + Color_fg]; + xcol.set (this, name); break; default: - xcol = pix_colors[Color_bg]; /* None */ + name = rs[Rs_color + Color_bg]; + xcol.set (this, name); break; } } } pix_colors[i] = xcol; - SET_PIXCOLOR (i); + rs[Rs_color + i] = name; } -#ifdef OFF_FOCUS_FADING - if (rs[Rs_fade]) - for (i = 0; i < (display->depth <= 2 ? 2 : NRS_COLORS); i++) - pix_colors_unfocused[i] = pix_colors_focused[i].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]); -#endif - - if (display->depth <= 2) + if (depth <= 2) { - if (!rs[Rs_color + Color_pointer_fg]) pix_colors[Color_pointer_fg] = pix_colors[Color_fg]; - if (!rs[Rs_color + Color_pointer_bg]) pix_colors[Color_pointer_bg] = pix_colors[Color_bg]; - if (!rs[Rs_color + Color_border] ) pix_colors[Color_border] = pix_colors[Color_fg]; + if (!rs[Rs_color + Color_pointer_fg]) alias_color (Color_pointer_fg, Color_fg); + if (!rs[Rs_color + Color_pointer_bg]) alias_color (Color_pointer_bg, Color_bg); + if (!rs[Rs_color + Color_border] ) alias_color (Color_border, Color_fg); } /* - * get scrollBar/menuBar shadow colors + * get scrollBar shadow colors * * The calculations of topShadow/bottomShadow values are adapted * from the fvwm window manager. */ #ifdef KEEP_SCROLLCOLOR - - if (display->depth <= 2) + if (depth <= 2) { /* Monochrome */ - pix_colors[Color_scroll] = pix_colors[Color_fg]; - pix_colors[Color_topShadow] = pix_colors[Color_bg]; - pix_colors[Color_bottomShadow] = pix_colors[Color_bg]; + alias_color (Color_scroll, Color_fg); + alias_color (Color_topShadow, Color_bg); + alias_color (Color_bottomShadow, Color_bg); } else { - rxvt_color xcol[2]; - /* xcol[0] == white - * xcol[1] == top shadow - * xcol[2] == bot shadow */ + pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]); - xcol[1] = pix_colors[Color_scroll]; - xcol[0].set (display, 65535, 65535, 65535); - - unsigned short pr1, pg1, pb1, pr0, pg0, pb0; - - xcol[0].get (display, pr0, pg0, pb0); - xcol[1].get (display, pr1, pg1, pb1); - - pix_colors[Color_bottomShadow] = xcol[1].fade (display, 50); + rgba cscroll; + pix_colors [Color_scroll].get (cscroll); /* topShadowColor */ - if (!xcol[1].set (display, - min (pr0, max (pr0 / 5, pr1) * 7 / 5), - min (pg0, max (pg0 / 5, pg1) * 7 / 5), - min (pb0, max (pb0 / 5, pb1) * 7 / 5))) - xcol[1] = pix_colors[Color_White]; - - pix_colors[Color_topShadow] = xcol[1]; + if (!pix_colors[Color_topShadow].set (this, + rgba ( + min ((int)rgba::MAX_CC, max (cscroll.r / 5, cscroll.r) * 7 / 5), + min ((int)rgba::MAX_CC, max (cscroll.g / 5, cscroll.g) * 7 / 5), + min ((int)rgba::MAX_CC, max (cscroll.b / 5, cscroll.b) * 7 / 5), + cscroll.a) + )) + alias_color (Color_topShadow, Color_White); } #endif /* KEEP_SCROLLCOLOR */ + +#ifdef OFF_FOCUS_FADING + for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) + update_fade_color (i); +#endif } /*----------------------------------------------------------------------*/ @@ -842,7 +891,7 @@ && strcasecmp (rsmod, "mod1") >= 0 && strcasecmp (rsmod, "mod5") <= 0) requestedmeta = rsmod[3] - '0'; - map = XGetModifierMapping (display->display); + map = XGetModifierMapping (dpy); kc = map->modifiermap; for (i = 1; i < 6; i++) @@ -854,7 +903,7 @@ if (kc[k] == 0) break; - switch (XKeycodeToKeysym (display->display, kc[k], 0)) + switch (XKeycodeToKeysym (dpy, kc[k], 0)) { case XK_Num_Lock: ModNumLockMask = modmasks[i - 1]; @@ -914,61 +963,39 @@ XClassHint classHint; XWMHints wmHint; #if ENABLE_FRILLS - Atom prop = None; - MWMHints mwmhints; + MWMHints mwmhints = { }; #endif XGCValues gcvalue; - long vt_emask; XSetWindowAttributes attributes; - XWindowAttributes gattr; Window top, parent; - dDisp; -#ifdef USING_W11LIB - /* enable W11 callbacks */ - W11AddEventHandler (disp, rxvt_W11_process_x_event); -#endif + dLocal (Display *, dpy); - assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); - XInternAtoms (disp, (char **)xa_names, NUM_XA, False, xa); + /* grab colors before netscape does */ + Get_Colours (); - if (OPTION (Opt_transparent)) - { - XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr); - display->depth = gattr.depth; // doh //TODO, per-term not per-display? - } + if (!set_fonts ()) + rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); + + parent = display->root; + + attributes.override_redirect = !!option (Opt_override_redirect); #if ENABLE_FRILLS - if (OPTION (Opt_borderLess)) + if (option (Opt_borderLess)) { - prop = XInternAtom(disp, "_MOTIF_WM_INFO", True); - - if (prop == None) + if (XInternAtom (dpy, "_MOTIF_WM_INFO", True) == None) { - /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/ -#ifdef PREFER_24BIT - attributes.override_redirect = TRUE; -#endif - mwmhints.flags = 0; + // rxvt_warn("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n"); + attributes.override_redirect = true; } else { mwmhints.flags = MWM_HINTS_DECORATIONS; - mwmhints.decorations = 0; } } - else - mwmhints.flags = 0; #endif - /* grab colors before netscape does */ - Get_Colours (); - - if (!set_fonts ()) - rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); - - parent = DefaultRootWindow (disp); - #if ENABLE_XEMBED if (rs[Rs_embed]) { @@ -976,7 +1003,7 @@ parent = strtol (rs[Rs_embed], 0, 0); - if (!XGetWindowAttributes (disp, parent, &wattr)) + if (!XGetWindowAttributes (dpy, parent, &wattr)) rxvt_fatal ("invalid window-id specified with -embed, aborting.\n"); window_calc (wattr.width, wattr.height); @@ -986,45 +1013,43 @@ window_calc (0, 0); /* sub-window placement & size in rxvt_resize_subwindows () */ -#ifdef PREFER_24BIT - attributes.background_pixel = pix_colors_focused[Color_border]; - attributes.border_pixel = pix_colors_focused[Color_border]; - attributes.colormap = display->cmap; - top = XCreateWindow (disp, parent, + attributes.background_pixel = pix_colors_focused [Color_border]; + attributes.border_pixel = pix_colors_focused [Color_border]; + attributes.colormap = cmap; + + top = XCreateWindow (dpy, parent, szHint.x, szHint.y, szHint.width, szHint.height, ext_bwidth, - display->depth, InputOutput, - display->visual, - CWColormap | CWBackPixel | CWBorderPixel, &attributes); -#else - top = XCreateSimpleWindow (disp, parent, - szHint.x, szHint.y, - szHint.width, szHint.height, - ext_bwidth, - pix_colors_focused[Color_border], - pix_colors_focused[Color_border]); -#endif + depth, InputOutput, visual, + CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, + &attributes); this->parent[0] = top; old_width = szHint.width; old_height = szHint.height; - process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); + process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); - classHint.res_name = (char *)rs[Rs_name]; + classHint.res_name = (char *)rs[Rs_name]; classHint.res_class = (char *)RESCLASS; - wmHint.flags = InputHint | StateHint | WindowGroupHint; - wmHint.input = True; - wmHint.initial_state = OPTION (Opt_iconic) ? IconicState : NormalState; - wmHint.window_group = top; + wmHint.flags = InputHint | StateHint | WindowGroupHint; + wmHint.input = True; + wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; + wmHint.window_group = top; - XmbSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc, + XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, &szHint, &wmHint, &classHint); +#if ENABLE_FRILLS + if (mwmhints.flags) + XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, + PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS); +#endif + Atom protocols[] = { xa[XA_WM_DELETE_WINDOW], #if ENABLE_EWMH @@ -1032,24 +1057,24 @@ #endif }; - XSetWMProtocols (disp, top, protocols, sizeof (protocols) / sizeof (protocols[0])); + XSetWMProtocols (dpy, 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)); + XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); #endif #if ENABLE_EWMH long pid = getpid (); - XChangeProperty (disp, top, + XChangeProperty (dpy, top, xa[XA_NET_WM_PID], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1); // _NET_WM_WINDOW_TYPE is NORMAL, which is the default #endif - XSelectInput (disp, top, + XSelectInput (dpy, top, KeyPressMask #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755 | KeyReleaseMask @@ -1059,110 +1084,54 @@ termwin_ev.start (display, top); -#if ENABLE_FRILLS - if (mwmhints.flags) - XChangeProperty (disp, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, - PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS); -#endif - /* vt cursor: Black-on-White is standard, but this is more popular */ - TermWin_cursor = XCreateFontCursor (disp, XC_xterm); + TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); -#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) - /* cursor (menuBar/scrollBar): Black-on-White */ - leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); +#ifdef HAVE_SCROLLBARS + /* cursor scrollBar: Black-on-White */ + leftptr_cursor = XCreateFontCursor (dpy, XC_left_ptr); #endif /* the vt window */ - vt = XCreateSimpleWindow (disp, top, - window_vt_x, - window_vt_y, - width, - height, - 0, - pix_colors_focused[Color_fg], - pix_colors_focused[Color_bg]); -#ifdef DEBUG_X - XStoreName (disp, vt, "vt window"); -#endif + vt = XCreateSimpleWindow (dpy, top, + window_vt_x, window_vt_y, + width, height, + 0, + pix_colors_focused[Color_fg], + pix_colors_focused[Color_bg]); attributes.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes); + XChangeWindowAttributes (dpy, vt, CWBitGravity, &attributes); vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; - if (OPTION (Opt_pointerBlank) -#ifdef ENABLE_PERL - || self -#endif - ) + if (option (Opt_pointerBlank)) vt_emask |= PointerMotionMask; else vt_emask |= Button1MotionMask | Button3MotionMask; - 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, - width, - menuBar_TotalHeight (), - 0, - pix_colors_focused[Color_fg], - pix_colors_focused[Color_scroll]); - -#ifdef DEBUG_X - XStoreName (disp, menuBar.win, "menubar"); -#endif - - menuBar.drawable = new rxvt_drawable (display, menuBar.win); - - XDefineCursor (disp, menuBar.win, - XCreateFontCursor (disp, XC_left_ptr)); - - XSelectInput (disp, menuBar.win, - (ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask)); - menubar_ev.start (display, menuBar.win); - } -#endif + vt_select_input (); -#ifdef XPM_BACKGROUND - if (rs[Rs_backgroundPixmap] != NULL - && ! OPTION (Opt_transparent)) - { - const char *p = rs[Rs_backgroundPixmap]; - - if ((p = strchr (p, ';')) != NULL) - { - p++; - scale_pixmap (p); - } - - set_bgPixmap (rs[Rs_backgroundPixmap]); - scr_touch (true); - } -#endif + vt_ev.start (display, vt); /* graphics context for the vt window */ - gcvalue.foreground = pix_colors[Color_fg]; - gcvalue.background = pix_colors[Color_bg]; - gcvalue.graphics_exposures = 1; - gc = XCreateGC (disp, vt, - GCForeground | GCBackground | GCGraphicsExposures, - &gcvalue); + gcvalue.foreground = pix_colors[Color_fg]; + gcvalue.background = pix_colors[Color_bg]; + gcvalue.graphics_exposures = 0; + + gc = XCreateGC (dpy, vt, + GCForeground | GCBackground | GCGraphicsExposures, + &gcvalue); - drawable = new rxvt_drawable (display, vt); + drawable = new rxvt_drawable (this, vt); -#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) +#ifdef RXVT_SCROLLBAR gcvalue.foreground = pix_colors[Color_topShadow]; - topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); + topShadowGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[Color_bottomShadow]; - botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); - gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)]; - scrollbarGC = XCreateGC (disp, vt, GCForeground, &gcvalue); + botShadowGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); + gcvalue.foreground = pix_colors[ (depth <= 2 ? Color_fg : Color_scroll)]; + scrollbarGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); #endif #ifdef OFF_FOCUS_FADING @@ -1173,16 +1142,6 @@ pointer_unblank (); scr_recolour (); - -#if ENABLE_XEMBED - if (rs[Rs_embed]) - { - long info[2] = { 0, XEMBED_MAPPED }; - - XChangeProperty (disp, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], - 32, PropModeReplace, (unsigned char *)&info, 2); - } -#endif } /* ------------------------------------------------------------------------- * @@ -1191,7 +1150,6 @@ void rxvt_get_ttymode (ttymode_t *tio, int erase) { -#ifdef HAVE_TERMIOS_H /* * standard System V termios interface */ @@ -1268,53 +1226,6 @@ | ECHOCTL | ECHOKE # endif | ECHOE | ECHOK); -# else /* HAVE_TERMIOS_H */ - - /* - * sgtty interface - */ - - /* get parameters -- gtty */ - if (ioctl (STDIN_FILENO, TIOCGETP, & (tio->sg)) < 0) - { - tio->sg.sg_erase = CERASE; /* ^H */ - tio->sg.sg_kill = CKILL; /* ^U */ - } - - if (erase != -1) - tio->sg.sg_erase = (char)erase; - - tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP); - - /* get special characters */ - if (ioctl (STDIN_FILENO, TIOCGETC, & (tio->tc)) < 0) - { - tio->tc.t_intrc = CINTR; /* ^C */ - tio->tc.t_quitc = CQUIT; /* ^\ */ - tio->tc.t_startc = CSTART; /* ^Q */ - tio->tc.t_stopc = CSTOP; /* ^S */ - tio->tc.t_eofc = CEOF; /* ^D */ - tio->tc.t_brkc = -1; - } - - /* get local special chars */ - if (ioctl (STDIN_FILENO, TIOCGLTC, & (tio->lc)) < 0) - { - tio->lc.t_suspc = CSUSP; /* ^Z */ - tio->lc.t_dsuspc = CDSUSP; /* ^Y */ - tio->lc.t_rprntc = CRPRNT; /* ^R */ - tio->lc.t_flushc = CFLUSH; /* ^O */ - tio->lc.t_werasc = CWERASE; /* ^W */ - tio->lc.t_lnextc = CLNEXT; /* ^V */ - } - /* get line discipline */ - ioctl (STDIN_FILENO, TIOCGETD, & (tio->line)); -# ifdef NTTYDISC - tio->line = NTTYDISC; -# endif /* NTTYDISC */ - - tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL); -#endif /* HAVE_TERMIOS_H */ /* * Debugging @@ -1409,46 +1320,45 @@ #if ENABLE_FRILLS if (rs[Rs_pty_fd]) { - pty.pty = atoi (rs[Rs_pty_fd]); + pty->pty = atoi (rs[Rs_pty_fd]); - if (pty.pty >= 0) + if (pty->pty >= 0) { if (getfd_hook) - pty.pty = (*getfd_hook) (pty.pty); + pty->pty = (*getfd_hook) (pty->pty); - if (pty.pty < 0 || fcntl (pty.pty, F_SETFL, O_NONBLOCK)) + if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK)) rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); } } else #endif - if (!pty.get ()) + if (!pty->get ()) rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); - pty.set_utf8_mode (enc_utf8); - - /* set initial window size */ - tt_winch (); - int er; #ifndef NO_BACKSPACE_KEY - if (key_backspace[0] && !key_backspace[1]) - er = key_backspace[0]; - else if (strcmp (key_backspace, "DEC") == 0) + if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) + er = rs[Rs_backspace_key][0]; + else if (strcmp (rs[Rs_backspace_key], "DEC") == 0) er = '\177'; /* the initial state anyway */ else #endif er = -1; rxvt_get_ttymode (&tio, er); + SET_TERMIOS (pty->tty, &tio); /* init terminal attributes */ + pty->set_utf8_mode (enc_utf8); + + /* set initial window size */ + tt_winch (); #if ENABLE_FRILLS if (rs[Rs_pty_fd]) return; #endif -#ifndef __QNX__ /* spin off the command interpreter */ switch (cmd_pid = fork ()) { @@ -1460,20 +1370,20 @@ case 0: init_env (); - if (!pty.make_controlling_tty ()) + if (!pty->make_controlling_tty ()) fprintf (stderr, "%s: could not obtain control of tty.", RESNAME); else { /* Reopen stdin, stdout and stderr over the tty file descriptor */ - dup2 (pty.tty, STDIN_FILENO); - dup2 (pty.tty, STDOUT_FILENO); - dup2 (pty.tty, STDERR_FILENO); + dup2 (pty->tty, STDIN_FILENO); + dup2 (pty->tty, STDOUT_FILENO); + dup2 (pty->tty, STDERR_FILENO); // close all our file handles that we do no longer need for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) { - if ((*t)->pty.pty > 2) close ((*t)->pty.pty); - if ((*t)->pty.tty > 2) close ((*t)->pty.tty); + if ((*t)->pty->pty > 2) close ((*t)->pty->pty); + if ((*t)->pty->tty > 2) close ((*t)->pty->tty); } run_child (argv); @@ -1483,36 +1393,16 @@ _exit (EXIT_FAILURE); default: - { -#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) - int fdstdin; + if (!option (Opt_utmpInhibit)) + pty->login (cmd_pid, option (Opt_loginShell), rs[Rs_display_name]); - fdstdin = dup (STDIN_FILENO); - dup2 (pty.tty, STDIN_FILENO); -#endif - -#ifdef UTMP_SUPPORT - privileged_utmp (SAVE); -#endif + pty->close_tty (); -#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) + child_ev.start (cmd_pid); - dup2 (fdstdin, STDIN_FILENO); - close (fdstdin); -#endif - } - - pty.close_tty (); /* keep STDERR_FILENO, pty.pty, display->fd () open */ + HOOK_INVOKE ((this, HOOK_CHILD_START, DT_INT, cmd_pid, DT_END)); break; } -#else /* __QNX__ uses qnxspawn () */ - fchmod (pty.tty, 0622); - fcntl (pty.tty, F_SETFD, FD_CLOEXEC); - fcntl (pty.pty, F_SETFD, FD_CLOEXEC); - - if (run_child (argv) == -1) - exit (EXIT_FAILURE); -#endif } /* ------------------------------------------------------------------------- * @@ -1527,9 +1417,7 @@ { char *login; - SET_TTYMODE (STDIN_FILENO, &tio); /* init terminal attributes */ - - if (OPTION (Opt_console)) + if (option (Opt_console)) { /* be virtual console, fail silently */ #ifdef TIOCCONS unsigned int on = 1; @@ -1566,9 +1454,8 @@ sigemptyset (&ss); sigprocmask (SIG_SETMASK, &ss, 0); -#ifndef __QNX__ /* command interpreter path */ - if (argv != NULL) + if (argv) { # ifdef DEBUG_CMD int i; @@ -1582,81 +1469,26 @@ } 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); + argv0 = (const char *)rxvt_basename (shell); - if (OPTION (Opt_loginShell)) + if (option (Opt_loginShell)) { - login = (char *)rxvt_malloc ((strlen (argv0) + 2) * sizeof (char)); + login = (char *)rxvt_malloc (strlen (argv0) + 2); login[0] = '-'; strcpy (&login[1], argv0); argv0 = login; } - execlp (shell, argv0, NULL); - /* no error message: STDERR is closed! */ - } - -#else /* __QNX__ uses qnxspawn () */ - - char iov_a[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; - char *command = NULL, fullcommand[_MAX_PATH]; - char **arg_v, *arg_a[2] = { NULL, NULL }; - - if (argv != NULL) - { - if (access (argv[0], X_OK) == -1) - { - if (strchr (argv[0], '/') == NULL) - { - searchenv (argv[0], "PATH", fullcommand); - - if (fullcommand[0] != '\0') - command = fullcommand; - } - - if (access (command, X_OK) == -1) - return -1; - } - else - command = argv[0]; - arg_v = argv; - } - else - { - if ((command = getenv ("SHELL")) == NULL || *command == '\0') - command = "/bin/sh"; - - arg_a[0] = my_basename (command); - - if (OPTION (Opt_loginShell)) - { - login = rxvt_malloc ((strlen (arg_a[0]) + 2) * sizeof (char)); - - login[0] = '-'; - strcpy (&login[1], arg_a[0]); - arg_a[0] = login; - } - - arg_v = arg_a; + execlp (shell, argv0, (char *)0); + /* no error message: STDERR is closed! */ } - iov_a[0] = iov_a[1] = iov_a[2] = pty.tty; - cmd_pid = qnx_spawn (0, 0, 0, -1, -1, - _SPAWN_SETSID | _SPAWN_TCSETPGRP, - command, arg_v, environ, iov_a, 0); - if (login) - free (login); - - pty.close_tty (); - return pty.pty; -#endif - return -1; }