--- rxvt-unicode/src/init.C 2005/01/17 00:59:23 1.105 +++ rxvt-unicode/src/init.C 2005/02/20 02:00:43 1.115 @@ -183,6 +183,7 @@ "TIMESTAMP", "VT_SELECTION", "INCR", + "WM_PROTOCOLS", "WM_DELETE_WINDOW", "CLIPBOARD", #if ENABLE_FRILLS @@ -202,12 +203,17 @@ "DndProtocol", "DndSelection", #endif +#if ENABLE_XEMBED + "_XEMBED", + "_XEMBED_INFO", +#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 @@ -226,8 +232,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; @@ -254,7 +258,7 @@ #ifdef MENUBAR menu_readonly = 1; # if ! (MENUBAR_MAX > 1) - CurrentBar = & (BarList); + CurrentBar = &BarList; # endif /* (MENUBAR_MAX > 1) */ #endif @@ -338,7 +342,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] == ':') @@ -355,7 +358,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 @@ -674,6 +678,7 @@ priv_modes |= PrivMode_scrollBar; SavedModes |= PrivMode_scrollBar; } + if (menubar_visible ()) { priv_modes |= PrivMode_menuBar; @@ -831,11 +836,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 @@ -927,25 +932,27 @@ long vt_emask; XSetWindowAttributes attributes; XWindowAttributes gattr; + Window top, parent; + dDisp; #ifdef USING_W11LIB /* enable W11 callbacks */ - W11AddEventHandler (display->display, rxvt_W11_process_x_event); + W11AddEventHandler (disp, rxvt_W11_process_x_event); #endif assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); - XInternAtoms (display->display, (char **)xa_names, NUM_XA, False, 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) { @@ -973,32 +980,50 @@ 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]) + { + 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_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, + 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, parent, + 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); @@ -1008,67 +1033,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, - (char **)argv, argc, &szHint, &wmHint, &classHint); + XmbSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc, + &szHint, &wmHint, &classHint); /* Enable delete window protocol */ - XSetWMProtocols (display->display, TermWin.parent[0], - &xa[XA_WMDELETEWINDOW], 1); + XSetWMProtocols (disp, top, &xa[XA_WM_DELETE_WINDOW], 1); #if ENABLE_FRILLS long pid = getpid (); - XChangeProperty (display->display, TermWin.parent[0], + 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) - XChangeProperty (display->display, TermWin.parent[0], xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, + 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); + 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; @@ -1076,13 +1098,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 (), @@ -1091,17 +1113,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 @@ -1127,7 +1148,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); @@ -1135,11 +1156,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 @@ -1148,7 +1169,18 @@ 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 } /* ------------------------------------------------------------------------- * @@ -1387,8 +1419,16 @@ void rxvt_term::run_command (const char *const *argv) { - if (!pty.get ()) - rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); +#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); @@ -1408,6 +1448,11 @@ rxvt_get_ttymode (&tio, er); +#if ENABLE_FRILLS + if (rs[Rs_pty_fd]) + return; +#endif + sw_chld.start (SIGCHLD); #ifndef __QNX__ @@ -1415,7 +1460,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 ();