--- rxvt-unicode/src/init.C 2004/08/15 22:09:24 1.79 +++ rxvt-unicode/src/init.C 2006/01/06 02:11:15 1.132 @@ -33,9 +33,12 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ +#include "rxvtutil.h" #include "init.h" -#include +#include + +#include const char *const def_colorName[] = { @@ -43,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) */ @@ -61,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) */ @@ -69,248 +70,81 @@ "Magenta", /* 5/13: bright magenta (#FF00FF) */ "Cyan", /* 6/14: bright cyan (#00FFFF) */ "White", /* 7/15: bright white (#FFFFFF) */ -#ifdef TTY_256COLOR - "rgbi:0/0/0", /* default 16-255 color table */ - "rgbi:0/0/.2", /* consists of 6 6x6 colour cubes */ - "rgbi:0/0/.4", /* and a 24 greyscale ramp w/o */ - "rgbi:0/0/.6", /* black or white */ - "rgbi:0/0/.8", - "rgbi:0/0/1", - "rgbi:0/.2/0", - "rgbi:0/.2/.2", - "rgbi:0/.2/.4", - "rgbi:0/.2/.6", - "rgbi:0/.2/.8", - "rgbi:0/.2/1", - "rgbi:0/.4/0", - "rgbi:0/.4/.2", - "rgbi:0/.4/.4", - "rgbi:0/.4/.6", - "rgbi:0/.4/.8", - "rgbi:0/.4/1", - "rgbi:0/.6/0", - "rgbi:0/.6/.2", - "rgbi:0/.6/.4", - "rgbi:0/.6/.6", - "rgbi:0/.6/.8", - "rgbi:0/.6/1", - "rgbi:0/.8/0", - "rgbi:0/.8/.2", - "rgbi:0/.8/.4", - "rgbi:0/.8/.6", - "rgbi:0/.8/.8", - "rgbi:0/.8/1", - "rgbi:0/1/0", - "rgbi:0/1/.2", - "rgbi:0/1/.4", - "rgbi:0/1/.6", - "rgbi:0/1/.8", - "rgbi:0/1/1", - "rgbi:.2/0/0", - "rgbi:.2/0/.2", - "rgbi:.2/0/.4", - "rgbi:.2/0/.6", - "rgbi:.2/0/.8", - "rgbi:.2/0/1", - "rgbi:.2/.2/0", - "rgbi:.2/.2/.2", - "rgbi:.2/.2/.4", - "rgbi:.2/.2/.6", - "rgbi:.2/.2/.8", - "rgbi:.2/.2/1", - "rgbi:.2/.4/0", - "rgbi:.2/.4/.2", - "rgbi:.2/.4/.4", - "rgbi:.2/.4/.6", - "rgbi:.2/.4/.8", - "rgbi:.2/.4/1", - "rgbi:.2/.6/0", - "rgbi:.2/.6/.2", - "rgbi:.2/.6/.4", - "rgbi:.2/.6/.6", - "rgbi:.2/.6/.8", - "rgbi:.2/.6/1", - "rgbi:.2/.8/0", - "rgbi:.2/.8/.2", - "rgbi:.2/.8/.4", - "rgbi:.2/.8/.6", - "rgbi:.2/.8/.8", - "rgbi:.2/.8/1", - "rgbi:.2/1/0", - "rgbi:.2/1/.2", - "rgbi:.2/1/.4", - "rgbi:.2/1/.6", - "rgbi:.2/1/.8", - "rgbi:.2/1/1", - "rgbi:.4/0/0", - "rgbi:.4/0/.2", - "rgbi:.4/0/.4", - "rgbi:.4/0/.6", - "rgbi:.4/0/.8", - "rgbi:.4/0/1", - "rgbi:.4/.2/0", - "rgbi:.4/.2/.2", - "rgbi:.4/.2/.4", - "rgbi:.4/.2/.6", - "rgbi:.4/.2/.8", - "rgbi:.4/.2/1", - "rgbi:.4/.4/0", - "rgbi:.4/.4/.2", - "rgbi:.4/.4/.4", - "rgbi:.4/.4/.6", - "rgbi:.4/.4/.8", - "rgbi:.4/.4/1", - "rgbi:.4/.6/0", - "rgbi:.4/.6/.2", - "rgbi:.4/.6/.4", - "rgbi:.4/.6/.6", - "rgbi:.4/.6/.8", - "rgbi:.4/.6/1", - "rgbi:.4/.8/0", - "rgbi:.4/.8/.2", - "rgbi:.4/.8/.4", - "rgbi:.4/.8/.6", - "rgbi:.4/.8/.8", - "rgbi:.4/.8/1", - "rgbi:.4/1/0", - "rgbi:.4/1/.2", - "rgbi:.4/1/.4", - "rgbi:.4/1/.6", - "rgbi:.4/1/.8", - "rgbi:.4/1/1", - "rgbi:.6/0/0", - "rgbi:.6/0/.2", - "rgbi:.6/0/.4", - "rgbi:.6/0/.6", - "rgbi:.6/0/.8", - "rgbi:.6/0/1", - "rgbi:.6/.2/0", - "rgbi:.6/.2/.2", - "rgbi:.6/.2/.4", - "rgbi:.6/.2/.6", - "rgbi:.6/.2/.8", - "rgbi:.6/.2/1", - "rgbi:.6/.4/0", - "rgbi:.6/.4/.2", - "rgbi:.6/.4/.4", - "rgbi:.6/.4/.6", - "rgbi:.6/.4/.8", - "rgbi:.6/.4/1", - "rgbi:.6/.6/0", - "rgbi:.6/.6/.2", - "rgbi:.6/.6/.4", - "rgbi:.6/.6/.6", - "rgbi:.6/.6/.8", - "rgbi:.6/.6/1", - "rgbi:.6/.8/0", - "rgbi:.6/.8/.2", - "rgbi:.6/.8/.4", - "rgbi:.6/.8/.6", - "rgbi:.6/.8/.8", - "rgbi:.6/.8/1", - "rgbi:.6/1/0", - "rgbi:.6/1/.2", - "rgbi:.6/1/.4", - "rgbi:.6/1/.6", - "rgbi:.6/1/.8", - "rgbi:.6/1/1", - "rgbi:.8/0/0", - "rgbi:.8/0/.2", - "rgbi:.8/0/.4", - "rgbi:.8/0/.6", - "rgbi:.8/0/.8", - "rgbi:.8/0/1", - "rgbi:.8/.2/0", - "rgbi:.8/.2/.2", - "rgbi:.8/.2/.4", - "rgbi:.8/.2/.6", - "rgbi:.8/.2/.8", - "rgbi:.8/.2/1", - "rgbi:.8/.4/0", - "rgbi:.8/.4/.2", - "rgbi:.8/.4/.4", - "rgbi:.8/.4/.6", - "rgbi:.8/.4/.8", - "rgbi:.8/.4/1", - "rgbi:.8/.6/0", - "rgbi:.8/.6/.2", - "rgbi:.8/.6/.4", - "rgbi:.8/.6/.6", - "rgbi:.8/.6/.8", - "rgbi:.8/.6/1", - "rgbi:.8/.8/0", - "rgbi:.8/.8/.2", - "rgbi:.8/.8/.4", - "rgbi:.8/.8/.6", - "rgbi:.8/.8/.8", - "rgbi:.8/.8/1", - "rgbi:.8/1/0", - "rgbi:.8/1/.2", - "rgbi:.8/1/.4", - "rgbi:.8/1/.6", - "rgbi:.8/1/.8", - "rgbi:.8/1/1", - "rgbi:1/0/0", - "rgbi:1/0/.2", - "rgbi:1/0/.4", - "rgbi:1/0/.6", - "rgbi:1/0/.8", - "rgbi:1/0/1", - "rgbi:1/.2/0", - "rgbi:1/.2/.2", - "rgbi:1/.2/.4", - "rgbi:1/.2/.6", - "rgbi:1/.2/.8", - "rgbi:1/.2/1", - "rgbi:1/.4/0", - "rgbi:1/.4/.2", - "rgbi:1/.4/.4", - "rgbi:1/.4/.6", - "rgbi:1/.4/.8", - "rgbi:1/.4/1", - "rgbi:1/.6/0", - "rgbi:1/.6/.2", - "rgbi:1/.6/.4", - "rgbi:1/.6/.6", - "rgbi:1/.6/.8", - "rgbi:1/.6/1", - "rgbi:1/.8/0", - "rgbi:1/.8/.2", - "rgbi:1/.8/.4", - "rgbi:1/.8/.6", - "rgbi:1/.8/.8", - "rgbi:1/.8/1", - "rgbi:1/1/0", - "rgbi:1/1/.2", - "rgbi:1/1/.4", - "rgbi:1/1/.6", - "rgbi:1/1/.8", - "rgbi:1/1/1", - "rgb:08/08/08", - "rgb:12/12/12", - "rgb:1c/1c/1c", - "rgb:26/26/26", - "rgb:30/30/30", - "rgb:3a/3a/3a", - "rgb:44/44/44", - "rgb:4e/4e/4e", - "rgb:58/58/58", - "rgb:62/62/62", - "rgb:6c/6c/6c", - "rgb:76/76/76", - "rgb:80/80/80", - "rgb:8a/8a/8a", - "rgb:94/94/94", - "rgb:9e/9e/9e", - "rgb:a8/a8/a8", - "rgb:b2/b2/b2", - "rgb:bc/bc/bc", - "rgb:c6/c6/c6", + + // 88 xterm colours + "rgb:00/00/00", + "rgb:00/00/8b", + "rgb:00/00/cd", + "rgb:00/00/ff", + "rgb:00/8b/00", + "rgb:00/8b/8b", + "rgb:00/8b/cd", + "rgb:00/8b/ff", + "rgb:00/cd/00", + "rgb:00/cd/8b", + "rgb:00/cd/cd", + "rgb:00/cd/ff", + "rgb:00/ff/00", + "rgb:00/ff/8b", + "rgb:00/ff/cd", + "rgb:00/ff/ff", + "rgb:8b/00/00", + "rgb:8b/00/8b", + "rgb:8b/00/cd", + "rgb:8b/00/ff", + "rgb:8b/8b/00", + "rgb:8b/8b/8b", + "rgb:8b/8b/cd", + "rgb:8b/8b/ff", + "rgb:8b/cd/00", + "rgb:8b/cd/8b", + "rgb:8b/cd/cd", + "rgb:8b/cd/ff", + "rgb:8b/ff/00", + "rgb:8b/ff/8b", + "rgb:8b/ff/cd", + "rgb:8b/ff/ff", + "rgb:cd/00/00", + "rgb:cd/00/8b", + "rgb:cd/00/cd", + "rgb:cd/00/ff", + "rgb:cd/8b/00", + "rgb:cd/8b/8b", + "rgb:cd/8b/cd", + "rgb:cd/8b/ff", + "rgb:cd/cd/00", + "rgb:cd/cd/8b", + "rgb:cd/cd/cd", + "rgb:cd/cd/ff", + "rgb:cd/ff/00", + "rgb:cd/ff/8b", + "rgb:cd/ff/cd", + "rgb:cd/ff/ff", + "rgb:ff/00/00", + "rgb:ff/00/8b", + "rgb:ff/00/cd", + "rgb:ff/00/ff", + "rgb:ff/8b/00", + "rgb:ff/8b/8b", + "rgb:ff/8b/cd", + "rgb:ff/8b/ff", + "rgb:ff/cd/00", + "rgb:ff/cd/8b", + "rgb:ff/cd/cd", + "rgb:ff/cd/ff", + "rgb:ff/ff/00", + "rgb:ff/ff/8b", + "rgb:ff/ff/cd", + "rgb:ff/ff/ff", + "rgb:2e/2e/2e", + "rgb:5c/5c/5c", + "rgb:73/73/73", + "rgb:8b/8b/8b", + "rgb:a2/a2/a2", + "rgb:b9/b9/b9", "rgb:d0/d0/d0", - "rgb:da/da/da", - "rgb:e4/e4/e4", - "rgb:ee/ee/ee", -#endif + "rgb:e7/e7/e7", + #ifndef NO_CURSORCOLOR COLOR_CURSOR_BACKGROUND, COLOR_CURSOR_FOREGROUND, @@ -320,9 +154,13 @@ NULL, /* Color_border */ #ifndef NO_BOLD_UNDERLINE_REVERSE NULL, /* Color_BD */ + NULL, /* Color_IT */ NULL, /* Color_UL */ NULL, /* Color_RV */ #endif /* ! NO_BOLD_UNDERLINE_REVERSE */ +#if ENABLE_FRILLS + NULL, // Color_underline +#endif #ifdef OPTION_HC NULL, #endif @@ -333,9 +171,12 @@ #if TINTING NULL, #endif +#if OFF_FOCUS_FADING + "black", +#endif }; -const char *const xa_names[NUM_XA] = +const char *const xa_names[] = { "TEXT", "COMPOUND_TEXT", @@ -345,15 +186,33 @@ "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 - "CLIPBOARD" +#if ENABLE_XEMBED + "_XEMBED", + "_XEMBED_INFO", +#endif }; bool @@ -369,29 +228,23 @@ return false; #if defined(XPM_BACKGROUND) || defined(TRANSPARENT) - TermWin.pixmap = None; + pixmap = None; #endif MEvent.time = CurrentTime; MEvent.button = AnyButton; options = DEFAULT_OPTIONS; want_refresh = 1; - cmd_pid = -1; - pty.pty = pty.tty = -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; -#ifndef NO_BRIGHTCOLOR - colorfgbg = DEFAULT_RSTYLE; -#endif - refresh_limit = 1; refresh_type = SLOW_REFRESH; prev_nrow = prev_ncol = 0; @@ -408,7 +261,7 @@ #ifdef MENUBAR menu_readonly = 1; # if ! (MENUBAR_MAX > 1) - CurrentBar = & (BarList); + CurrentBar = &BarList; # endif /* (MENUBAR_MAX > 1) */ #endif @@ -492,24 +345,12 @@ rs[Rs_display_name] = ":0"; get_options (r_argc, r_argv); - free (r_argv); -#ifdef LOCAL_X_IS_UNIX - if (rs[Rs_display_name][0] == ':') - { - val = rxvt_malloc (5 + strlen (rs[Rs_display_name])); - strcpy (val, "unix"); - strcat (val, rs[Rs_display_name]); - display = displays.get (val); - free (val); - } -#endif - - if (!display - && ! (display = displays.get (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 (display->display, rs[Rs_name]); + extract_resources (); + free (r_argv); /* * set any defaults not already set @@ -530,18 +371,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 */ -#endif + ext_bwidth = min (i, std::numeric_limits::max ()); -#ifndef NO_LINESPACE 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 @@ -552,8 +392,8 @@ #endif /* no point having a scrollbar without having any scrollback! */ - if (!TermWin.saveLines) - options &= ~Opt_scrollBar; + if (!saveLines) + CLR_OPTION (Opt_scrollBar); #ifdef PRINTPIPE if (!rs[Rs_print_pipe]) @@ -601,13 +441,12 @@ } #ifdef HAVE_SCROLLBARS - setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], - rs[Rs_scrollBar_thickness]); + setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]); #endif #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]; @@ -622,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 */ @@ -642,6 +481,9 @@ color_aliases (Color_RV); #endif /* ! NO_BOLD_UNDERLINE_REVERSE */ + if (!rs[Rs_color + Color_border]) + rs[Rs_color + Color_border] = rs[Rs_color + Color_bg]; + return cmd_argv; } @@ -680,14 +522,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 @@ -758,15 +600,17 @@ SET_LOCALE (this->locale); mbstate.reset (); #endif -#if 0 + #if HAVE_NL_LANGINFO + char *codeset = strdup (nl_langinfo (CODESET)); + // /^UTF.?8/i + enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u') + && (codeset[1] == 'T' || codeset[1] == 't') + && (codeset[2] == 'F' || codeset[2] == 'f') + && (codeset[3] == '8' || codeset[4] == '8'); free (codeset); - codeset = strdup (nl_langinfo (CODESET)); - enc_utf8 = !strcasecmp (codeset, "UTF-8") - || !strcasecmp (codeset, "UTF8"); #else - enc_utf8 = 1; -#endif + enc_utf8 = 0; #endif } @@ -778,16 +622,11 @@ rxvt_warn ("setting locale failed, working without locale support.\n"); else { - Atom wmlocale; - - wmlocale = XInternAtom (display->display, "WM_LOCALE_NAME", False); - XChangeProperty (display->display, TermWin.parent[0], wmlocale, - XA_STRING, 8, PropModeReplace, - (unsigned char *)locale, strlen (locale)); + set_string_property (xa[XA_WM_LOCALE_NAME], locale); if (!XSupportsLocale ()) { - rxvt_warn ("the locale is not supported by Xlib, working withotu locale support.\n"); + rxvt_warn ("the locale is not supported by Xlib, working without locale support.\n"); return; } @@ -807,31 +646,18 @@ * Initialize the command connection. * This should be called after the X server connection is established. */ - int i; - - for (i = 0; i < NUM_XA; i++) - xa[i] = XInternAtom (display->display, xa_names[i], False); - - /* Enable delete window protocol */ - XSetWMProtocols (display->display, TermWin.parent[0], - & (xa[XA_WMDELETEWINDOW]), 1); - -#ifdef USING_W11LIB - /* enable W11 callbacks */ - W11AddEventHandler (display->display, rxvt_W11_process_x_event); -#endif #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 @@ -845,17 +671,13 @@ priv_modes |= PrivMode_scrollBar; SavedModes |= PrivMode_scrollBar; } + if (menubar_visible ()) { priv_modes |= PrivMode_menuBar; SavedModes |= PrivMode_menuBar; } -#ifdef CURSOR_BLINK - if (options & Opt_cursorBlink) - (void)gettimeofday (&lastcursorchange, NULL); -#endif - run_command (argv); } @@ -879,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 @@ -914,13 +736,15 @@ } pix_colors[i] = xcol; -#ifdef OFF_FOCUS_FADING - if (rs[Rs_fade]) - pix_colors_unfocused[i] = xcol.fade (display, atoi (rs[Rs_fade])); -#endif SET_PIXCOLOR (i); } +#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 (!rs[Rs_color + Color_pointer_fg]) pix_colors[Color_pointer_fg] = pix_colors[Color_fg]; @@ -937,7 +761,8 @@ #ifdef KEEP_SCROLLCOLOR if (display->depth <= 2) - { /* Monochrome */ + { + /* 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]; @@ -983,11 +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 */ @@ -1003,11 +825,11 @@ void rxvt_term::get_ourmods () { - int i, j, k; - int requestedmeta, realmeta, realalt; - const char *cm, *rsmod; + int i, j, k; + int requestedmeta, realmeta, realalt; + const char *cm, *rsmod; XModifierKeymap *map; - KeyCode *kc; + KeyCode *kc; const unsigned int modmasks[] = { Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask @@ -1015,53 +837,71 @@ requestedmeta = realmeta = realalt = 0; rsmod = rs[Rs_modifier]; + if (rsmod && strcasecmp (rsmod, "mod1") >= 0 && strcasecmp (rsmod, "mod5") <= 0) requestedmeta = rsmod[3] - '0'; map = XGetModifierMapping (display->display); kc = map->modifiermap; + for (i = 1; i < 6; i++) { k = (i + 2) * map->max_keypermod; /* skip shift/lock/control */ + for (j = map->max_keypermod; j--; k++) { if (kc[k] == 0) break; + switch (XKeycodeToKeysym (display->display, kc[k], 0)) { case XK_Num_Lock: ModNumLockMask = modmasks[i - 1]; - /* FALLTHROUGH */ - default: - continue; /* for (;;) */ + continue; + + case XK_ISO_Level3_Shift: + ModLevel3Mask = modmasks[i - 1]; + continue; + case XK_Meta_L: case XK_Meta_R: cm = "meta"; realmeta = i; break; + case XK_Alt_L: case XK_Alt_R: cm = "alt"; realalt = i; break; + case XK_Super_L: case XK_Super_R: cm = "super"; break; + case XK_Hyper_L: case XK_Hyper_R: cm = "hyper"; break; + + default: + continue; } + if (rsmod && strncasecmp (rsmod, cm, strlen (cm)) == 0) requestedmeta = i; } } + XFreeModifiermap (map); - i = (requestedmeta ? requestedmeta - : (realmeta ? realmeta - : (realalt ? realalt : 0))); + + i = requestedmeta ? requestedmeta + : realmeta ? realmeta + : realalt ? realalt + : 0; + if (i) ModMetaMask = modmasks[i - 1]; } @@ -1081,17 +921,28 @@ 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 + + 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 (display->display, RootWindow (display->display, display->screen), &gattr); + 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(display->display, "_MOTIF_WM_INFO", True); + prop = XInternAtom(disp, "_MOTIF_WM_INFO", True); + if (prop == None) { /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/ @@ -1107,47 +958,59 @@ } } else - { - mwmhints.flags = 0; - } + mwmhints.flags = 0; #endif /* grab colors before netscape does */ Get_Colours (); - if (!change_font (rs[Rs_font])) + 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]) { - fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); - destroy (); - return; + XWindowAttributes wattr; + + parent = strtol (rs[Rs_embed], 0, 0); + + if (!XGetWindowAttributes (disp, parent, &wattr)) + rxvt_fatal ("invalid window-id specified with -embed, aborting.\n"); + + window_calc (wattr.width, wattr.height); } +#endif window_calc (0, 0); - old_width = szHint.width; - old_height = szHint.height; /* sub-window placement & size in rxvt_resize_subwindows () */ - #ifdef PREFER_24BIT - attributes.background_pixel = pix_colors[Color_bg]; - attributes.border_pixel = pix_colors[Color_border]; + attributes.background_pixel = pix_colors_focused[Color_border]; + attributes.border_pixel = pix_colors_focused[Color_border]; attributes.colormap = display->cmap; - TermWin.parent[0] = XCreateWindow (display->display, DefaultRootWindow (display->display), - szHint.x, szHint.y, - szHint.width, szHint.height, - TermWin.ext_bwidth, - display->depth, InputOutput, - display->visual, - CWColormap | CWBackPixel | CWBorderPixel, &attributes); + top = XCreateWindow (disp, parent, + szHint.x, szHint.y, + szHint.width, szHint.height, + ext_bwidth, + display->depth, InputOutput, + display->visual, + CWColormap | CWBackPixel | CWBorderPixel, &attributes); #else - TermWin.parent[0] = XCreateSimpleWindow (display->display, DefaultRootWindow (display->display), - szHint.x, szHint.y, - szHint.width, szHint.height, - TermWin.ext_bwidth, - pix_colors[Color_border], - pix_colors[Color_bg]); + 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 + 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_iconName, rs[Rs_iconName], CHAR_ST); @@ -1156,118 +1019,112 @@ wmHint.flags = InputHint | StateHint | WindowGroupHint; wmHint.input = True; - wmHint.initial_state = options & Opt_iconic ? IconicState : NormalState; - wmHint.window_group = TermWin.parent[0]; + wmHint.initial_state = OPTION (Opt_iconic) ? IconicState : NormalState; + wmHint.window_group = top; - XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL, - (char **)argv, argc, &szHint, &wmHint, &classHint); + XmbSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc, + &szHint, &wmHint, &classHint); -#if ENABLE_FRILLS + Atom protocols[] = { + xa[XA_WM_DELETE_WINDOW], +#if ENABLE_EWMH + xa[XA_NET_WM_PING], +#endif + }; + + XSetWMProtocols (disp, top, protocols, sizeof (protocols) / sizeof (protocols[0])); + +#if ENABLE_EWMH long pid = getpid (); - XChangeProperty (display->display, TermWin.parent[0], - display->atom ("_NET_WM_PID"), XA_CARDINAL, 32, + + XChangeProperty (disp, 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 (display->display, TermWin.parent[0], + XSelectInput (disp, top, KeyPressMask -#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) +#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755 | KeyReleaseMask #endif | FocusChangeMask | VisibilityChangeMask - | ExposureMask - | StructureNotifyMask); - termwin_ev.start (display, TermWin.parent[0]); + | ExposureMask | StructureNotifyMask); + + termwin_ev.start (display, top); #if ENABLE_FRILLS if (mwmhints.flags) - { - prop = XInternAtom(display->display, "_MOTIF_WM_HINTS", False); - XChangeProperty(display->display, TermWin.parent[0], prop, prop, 32, PropModeReplace, (unsigned char *) &mwmhints, PROP_MWM_HINTS_ELEMENTS); - } + 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 (display->display, XC_xterm); + TermWin_cursor = XCreateFontCursor (disp, XC_xterm); #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) /* cursor (menuBar/scrollBar): Black-on-White */ - leftptr_cursor = XCreateFontCursor (display->display, XC_left_ptr); -#endif - -#ifdef POINTER_BLANK - { - XColor blackcolour; - blackcolour.red = 0; - blackcolour.green = 0; - blackcolour.blue = 0; - Font f = XLoadFont (display->display, "fixed"); - blank_cursor = XCreateGlyphCursor (display->display, f, f, ' ', ' ', - &blackcolour, &blackcolour); - XUnloadFont (display->display, f); - } + leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); #endif /* the vt window */ - TermWin.vt = XCreateSimpleWindow (display->display, TermWin.parent[0], - window_vt_x, - window_vt_y, - TermWin_TotalWidth (), - TermWin_TotalHeight (), - 0, - pix_colors[Color_fg], - pix_colors[Color_bg]); + 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 (display->display, TermWin.vt, "vt window"); + XStoreName (disp, vt, "vt window"); #endif attributes.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (display->display, TermWin.vt, CWBitGravity, &attributes); + XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes); vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; - pointer_unblank (); - #ifdef POINTER_BLANK - if (options & Opt_pointerBlank) + if (OPTION (Opt_pointerBlank)) vt_emask |= PointerMotionMask; else #endif vt_emask |= Button1MotionMask | Button3MotionMask; - XSelectInput (display->display, 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 (display->display, TermWin.parent[0], + menuBar.win = XCreateSimpleWindow (disp, top, window_vt_x, 0, - TermWin_TotalWidth (), + width, menuBar_TotalHeight (), 0, - pix_colors[Color_fg], - pix_colors[Color_scroll]); + pix_colors_focused[Color_fg], + pix_colors_focused[Color_scroll]); #ifdef DEBUG_X - XStoreName (display->display, menuBar.win, "menubar"); + XStoreName (disp, menuBar.win, "menubar"); #endif menuBar.drawable = new rxvt_drawable (display, menuBar.win); - XDefineCursor (display->display, menuBar.win, - XCreateFontCursor (display->display, XC_left_ptr)); + XDefineCursor (disp, menuBar.win, + XCreateFontCursor (disp, XC_left_ptr)); - XSelectInput (display->display, menuBar.win, - (ExposureMask | ButtonPressMask | ButtonReleaseMask - | Button1MotionMask)); + XSelectInput (disp, menuBar.win, + (ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask)); menubar_ev.start (display, menuBar.win); } #endif #ifdef XPM_BACKGROUND if (rs[Rs_backgroundPixmap] != NULL - && ! (options & Opt_transparent)) + && ! OPTION (Opt_transparent)) { const char *p = rs[Rs_backgroundPixmap]; @@ -1276,8 +1133,9 @@ p++; scale_pixmap (p); } + set_bgPixmap (rs[Rs_backgroundPixmap]); - scr_touch (True); + scr_touch (true); } #endif @@ -1285,19 +1143,19 @@ gcvalue.foreground = pix_colors[Color_fg]; gcvalue.background = pix_colors[Color_bg]; gcvalue.graphics_exposures = 1; - TermWin.gc = XCreateGC (display->display, 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 (display->display, TermWin.vt, GCForeground, &gcvalue); + topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[Color_bottomShadow]; - botShadowGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); + botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)]; - scrollbarGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); + scrollbarGC = XCreateGC (disp, vt, GCForeground, &gcvalue); #endif #ifdef OFF_FOCUS_FADING @@ -1305,6 +1163,19 @@ if (rs[Rs_fade]) pix_colors = pix_colors_unfocused; #endif + + 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 } /* ------------------------------------------------------------------------- * @@ -1319,56 +1190,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 @@ -1406,6 +1273,7 @@ tio->sg.sg_erase = CERASE; /* ^H */ tio->sg.sg_kill = CKILL; /* ^U */ } + if (erase != -1) tio->sg.sg_erase = (char)erase; @@ -1421,6 +1289,7 @@ tio->tc.t_eofc = CEOF; /* ^D */ tio->tc.t_brkc = -1; } + /* get local special chars */ if (ioctl (STDIN_FILENO, TIOCGLTC, & (tio->lc)) < 0) { @@ -1434,7 +1303,6 @@ /* get line discipline */ ioctl (STDIN_FILENO, TIOCGETD, & (tio->line)); # ifdef NTTYDISC - tio->line = NTTYDISC; # endif /* NTTYDISC */ @@ -1467,15 +1335,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 @@ -1492,39 +1357,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 @@ -1543,10 +1399,31 @@ void rxvt_term::run_command (const char *const *argv) { - int er; +#if ENABLE_FRILLS + if (rs[Rs_pty_fd]) + { + pty.pty = atoi (rs[Rs_pty_fd]); + + 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 + if (!pty.get ()) + rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); - 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]) @@ -1559,15 +1436,20 @@ rxvt_get_ttymode (&tio, er); - /* 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 ()) { case -1: - rxvt_fatal ("can't fork, aborting.\n"); + { + cmd_pid = 0; + rxvt_fatal ("can't fork, aborting.\n"); + } case 0: init_env (); @@ -1640,7 +1522,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; @@ -1700,7 +1582,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)); @@ -1745,7 +1627,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));