--- rxvt-unicode/src/init.C 2004/09/08 17:23:02 1.92 +++ rxvt-unicode/src/init.C 2005/02/19 04:16:49 1.113 @@ -33,9 +33,10 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ +#include "rxvtutil.h" #include "init.h" -#include +#include const char *const def_colorName[] = { @@ -157,6 +158,9 @@ NULL, /* Color_UL */ NULL, /* Color_RV */ #endif /* ! NO_BOLD_UNDERLINE_REVERSE */ +#if ENABLE_FRILLS + NULL, // Color_underline +#endif #ifdef OPTION_HC NULL, #endif @@ -169,7 +173,7 @@ #endif }; -const char *const xa_names[NUM_XA] = +const char *const xa_names[] = { "TEXT", "COMPOUND_TEXT", @@ -179,21 +183,36 @@ "TIMESTAMP", "VT_SELECTION", "INCR", + "WM_PROTOCOLS", "WM_DELETE_WINDOW", + "CLIPBOARD", +#if ENABLE_FRILLS + "_NET_WM_PID", + "_MOTIF_WM_HINTS", + "_NET_WM_NAME", + "_NET_WM_ICON_NAME", +#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", +#endif }; 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 @@ -212,8 +231,6 @@ 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; @@ -240,7 +257,7 @@ #ifdef MENUBAR menu_readonly = 1; # if ! (MENUBAR_MAX > 1) - CurrentBar = & (BarList); + CurrentBar = &BarList; # endif /* (MENUBAR_MAX > 1) */ #endif @@ -324,7 +341,6 @@ 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] == ':') @@ -341,7 +357,8 @@ && ! (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 @@ -369,9 +386,6 @@ TermWin.int_bwidth = min (i, 100); /* arbitrary limit */ if (rs[Rs_ext_bwidth] && (i = atoi (rs[Rs_ext_bwidth])) >= 0) TermWin.ext_bwidth = min (i, 100); /* arbitrary limit */ -#endif - -#ifndef NO_LINESPACE if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0) TermWin.lineSpace = min (i, 100); /* arbitrary limit */ #endif @@ -592,15 +606,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 } @@ -612,12 +628,7 @@ 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 ()) { @@ -641,19 +652,6 @@ * 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); @@ -679,6 +677,7 @@ priv_modes |= PrivMode_scrollBar; SavedModes |= PrivMode_scrollBar; } + if (menubar_visible ()) { priv_modes |= PrivMode_menuBar; @@ -836,11 +835,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 @@ -848,53 +847,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]; } @@ -914,17 +931,28 @@ long vt_emask; XSetWindowAttributes attributes; XWindowAttributes gattr; + Window top; + 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) { - 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) { - 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");*/ @@ -949,33 +977,66 @@ Get_Colours (); if (!set_fonts ()) - rxvt_fatal ("unable to load base fontset, please specify one using -fn, aborting.\n"); + rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); - window_calc (0, 0); - old_width = szHint.width; - old_height = szHint.height; +#if ENABLE_XEMBED + if (rs[Rs_embed]) + { + XWindowAttributes wattr; + + top = strtol (rs[Rs_embed], 0, 0); - /* sub-window placement & size in rxvt_resize_subwindows () */ + if (!XGetWindowAttributes (disp, top, &wattr)) + rxvt_fatal ("invalid window-id specified with -embed, aborting.\n"); + window_calc (wattr.width, wattr.height); + +#if 0 + if (wattr.map_state == IsViewable) + { + TermWin.mapped = 1; + refresh_type = FAST_REFRESH; + XClearWindow (disp, top); + // TODO: make XMapNotify-event-code a function and call it + // TODO: how can I detect visibility without unmap/map? + // TODO: focusin etc. + } +#else + // it's easiest just to unmap/map to get all state correctly set-up + XUnmapWindow (disp, top); +#endif + } + else +#endif + { + 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; - 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); + attributes.background_pixel = pix_colors_focused[Color_border]; + attributes.border_pixel = pix_colors_focused[Color_border]; + attributes.colormap = display->cmap; + top = XCreateWindow (disp, DefaultRootWindow (disp), + szHint.x, szHint.y, + szHint.width, szHint.height, + TermWin.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_focused[Color_border], - pix_colors_focused[Color_border]); + top = XCreateSimpleWindow (disp, DefaultRootWindow (disp), + szHint.x, szHint.y, + szHint.width, szHint.height, + TermWin.ext_bwidth, + pix_colors_focused[Color_border], + pix_colors_focused[Color_border]); #endif + } + + TermWin.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); @@ -986,77 +1047,64 @@ wmHint.flags = InputHint | StateHint | WindowGroupHint; wmHint.input = True; wmHint.initial_state = options & Opt_iconic ? IconicState : NormalState; - wmHint.window_group = TermWin.parent[0]; + wmHint.window_group = top; - XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL, + XSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc, &szHint, &wmHint, &classHint); + /* Enable delete window protocol */ + XSetWMProtocols (disp, top, &xa[XA_WM_DELETE_WINDOW], 1); + #if ENABLE_FRILLS 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); #endif - XSelectInput (display->display, TermWin.parent[0], + XSelectInput (disp, top, KeyPressMask #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_focused[Color_fg], - pix_colors_focused[Color_bg]); + TermWin.vt = XCreateSimpleWindow (disp, top, + window_vt_x, + window_vt_y, + TermWin_TotalWidth (), + TermWin_TotalHeight (), + 0, + pix_colors_focused[Color_fg], + pix_colors_focused[Color_bg]); #ifdef DEBUG_X - XStoreName (display->display, TermWin.vt, "vt window"); + XStoreName (disp, TermWin.vt, "vt window"); #endif attributes.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (display->display, TermWin.vt, CWBitGravity, &attributes); + XChangeWindowAttributes (disp, TermWin.vt, CWBitGravity, &attributes); vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; - pointer_unblank (); - #ifdef POINTER_BLANK if (options & Opt_pointerBlank) vt_emask |= PointerMotionMask; @@ -1064,13 +1112,13 @@ #endif vt_emask |= Button1MotionMask | Button3MotionMask; - XSelectInput (display->display, TermWin.vt, vt_emask); + XSelectInput (disp, TermWin.vt, vt_emask); vt_ev.start (display, TermWin.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 (), menuBar_TotalHeight (), @@ -1079,17 +1127,16 @@ 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 @@ -1115,7 +1162,7 @@ gcvalue.foreground = pix_colors[Color_fg]; gcvalue.background = pix_colors[Color_bg]; gcvalue.graphics_exposures = 1; - TermWin.gc = XCreateGC (display->display, TermWin.vt, + TermWin.gc = XCreateGC (disp, TermWin.vt, GCForeground | GCBackground | GCGraphicsExposures, &gcvalue); @@ -1123,11 +1170,11 @@ #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) gcvalue.foreground = pix_colors[Color_topShadow]; - topShadowGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); + topShadowGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[Color_bottomShadow]; - botShadowGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); + botShadowGC = XCreateGC (disp, TermWin.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, TermWin.vt, GCForeground, &gcvalue); #endif #ifdef OFF_FOCUS_FADING @@ -1136,7 +1183,13 @@ pix_colors = pix_colors_unfocused; #endif + pointer_unblank (); scr_recolour (); + +#if ENABLE_XEMBED + // why this is necessary, I don't know, race condition?? + XMoveWindow (disp, TermWin.vt, window_vt_x, window_vt_y); +#endif } /* ------------------------------------------------------------------------- * @@ -1375,10 +1428,23 @@ 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]); + fcntl (pty.pty, F_SETFL, O_NONBLOCK); + } + else +#endif + if (!pty.get ()) + rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); + + pty.set_utf8_mode (enc_utf8); + + /* set initial window size */ + tt_winch (); - if (!pty.get ()) - rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); + int er; #ifndef NO_BACKSPACE_KEY if (key_backspace[0] && !key_backspace[1]) @@ -1391,8 +1457,10 @@ rxvt_get_ttymode (&tio, er); - /* set initial window size */ - tt_winch (); +#if ENABLE_FRILLS + if (rs[Rs_pty_fd]) + return; +#endif sw_chld.start (SIGCHLD); @@ -1401,7 +1469,10 @@ 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 ();