--- rxvt-unicode/src/init.C 2006/01/20 11:02:46 1.150 +++ rxvt-unicode/src/init.C 2006/02/18 15:24:39 1.170 @@ -45,31 +45,31 @@ 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: ywlloe (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", @@ -172,56 +172,18 @@ 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 -#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; @@ -232,7 +194,6 @@ options = DEFAULT_OPTIONS; want_refresh = 1; priv_modes = SavedModes = PrivMode_Default; - focus = 0; ncol = 80; nrow = 24; int_bwidth = INTERNALBORDERWIDTH; @@ -243,7 +204,6 @@ refresh_limit = 1; refresh_type = SLOW_REFRESH; - prev_nrow = prev_ncol = 0; oldcursor.row = oldcursor.col = -1; #ifdef XPM_BACKGROUND @@ -339,10 +299,37 @@ if (!(display = displays.get (rs[Rs_display_name]))) 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; + +#if XFT + if (rs[Rs_depth]) + set (display, strtol (rs[Rs_depth], 0, 0)); + else +#endif + set (display); + extract_resources (); 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 */ @@ -441,6 +428,7 @@ { 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]; } @@ -502,7 +490,7 @@ 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 */ @@ -512,15 +500,7 @@ 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 @@ -532,6 +512,7 @@ */ putenv (env_display); putenv (env_windowid); + if (env_colorfgbg) putenv (env_colorfgbg); @@ -539,7 +520,7 @@ putenv ("TERMINFO=" RXVT_TERMINFO); #endif - if (display->depth <= 2) + if (depth <= 2) putenv ("COLORTERM=" COLORTERMENV "-mono"); else putenv ("COLORTERM=" COLORTERMENVFULL); @@ -680,65 +661,60 @@ 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]; + 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); } /* @@ -748,41 +724,41 @@ * 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 + if (rs[Rs_fade]) + for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) + { + rgba c; + pix_colors [Color_fade].get (c); + pix_colors_focused [i].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused[i],c); + } +#endif } /*----------------------------------------------------------------------*/ @@ -831,7 +807,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++) @@ -843,7 +819,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]; @@ -903,28 +879,13 @@ XClassHint classHint; XWMHints wmHint; #if ENABLE_FRILLS - Atom prop = None; MWMHints mwmhints; #endif XGCValues gcvalue; 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 (OPTION (Opt_transparent)) - { - XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr); - display->depth = gattr.depth; // doh //TODO, per-term not per-display? - } + dLocal (Display *, dpy); /* grab colors before netscape does */ Get_Colours (); @@ -932,19 +893,17 @@ if (!set_fonts ()) rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); - parent = DefaultRootWindow (disp); + parent = display->root; attributes.override_redirect = !!OPTION (Opt_override_redirect); #if ENABLE_FRILLS 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");*/ - attributes.override_redirect = TRUE; + attributes.override_redirect = true; mwmhints.flags = 0; } else @@ -964,7 +923,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); @@ -974,15 +933,15 @@ window_calc (0, 0); /* sub-window placement & size in rxvt_resize_subwindows () */ - 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, + depth, InputOutput, visual, CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, &attributes); @@ -991,20 +950,26 @@ 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.flags = InputHint | StateHint | WindowGroupHint; + wmHint.input = True; wmHint.initial_state = OPTION (Opt_iconic) ? IconicState : NormalState; - wmHint.window_group = top; + 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 @@ -1012,24 +977,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 @@ -1039,35 +1004,24 @@ 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); #ifdef HAVE_SCROLLBARS /* cursor scrollBar: Black-on-White */ - leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); + 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; @@ -1082,7 +1036,7 @@ #ifdef XPM_BACKGROUND if (rs[Rs_backgroundPixmap] != NULL - && ! OPTION (Opt_transparent)) + && !OPTION (Opt_transparent)) { const char *p = rs[Rs_backgroundPixmap]; @@ -1098,22 +1052,23 @@ #endif /* 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); #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 @@ -1124,16 +1079,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 } /* ------------------------------------------------------------------------- * @@ -1433,10 +1378,8 @@ _exit (EXIT_FAILURE); default: -#if UTMP_SUPPORT if (!OPTION (Opt_utmpInhibit)) pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]); -#endif pty->close_tty ();