--- rxvt-unicode/src/init.C 2006/01/04 04:42:45 1.130 +++ rxvt-unicode/src/init.C 2006/01/19 09:47:15 1.149 @@ -11,7 +11,7 @@ * - 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 @@ -46,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) */ @@ -64,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) */ @@ -260,13 +258,6 @@ last_bot = last_state = -1; -#ifdef MENUBAR - menu_readonly = 1; -# if ! (MENUBAR_MAX > 1) - CurrentBar = &BarList; -# endif /* (MENUBAR_MAX > 1) */ -#endif - return true; } @@ -343,6 +334,7 @@ /* * Open display, get options/resources and create the window */ + if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) rs[Rs_display_name] = ":0"; @@ -352,6 +344,7 @@ rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); extract_resources (); + free (r_argv); /* @@ -395,7 +388,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]) @@ -580,6 +573,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); @@ -588,13 +583,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"; } @@ -619,6 +614,8 @@ void rxvt_term::init_xlocale () { + set_environ (envv); + #ifdef USE_XIM if (!locale) rxvt_warn ("setting locale failed, working without locale support.\n"); @@ -668,18 +665,12 @@ #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); } @@ -755,7 +746,7 @@ } /* - * get scrollBar/menuBar shadow colors + * get scrollBar shadow colors * * The calculations of topShadow/bottomShadow values are adapted * from the fvwm window manager. @@ -810,10 +801,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 */ @@ -922,7 +911,6 @@ MWMHints mwmhints; #endif XGCValues gcvalue; - long vt_emask; XSetWindowAttributes attributes; XWindowAttributes gattr; Window top, parent; @@ -942,17 +930,25 @@ display->depth = gattr.depth; // doh //TODO, per-term not per-display? } + /* 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); + + attributes.override_redirect = !!OPTION (Opt_override_redirect); + #if ENABLE_FRILLS if (OPTION (Opt_borderLess)) { - prop = XInternAtom(disp, "_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");*/ -#ifdef PREFER_24BIT attributes.override_redirect = TRUE; -#endif mwmhints.flags = 0; } else @@ -965,14 +961,6 @@ 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]) { @@ -990,7 +978,6 @@ 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; @@ -1000,15 +987,8 @@ 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 + CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, + &attributes); this->parent[0] = top; @@ -1038,6 +1018,11 @@ XSetWMProtocols (disp, 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)); +#endif + #if ENABLE_EWMH long pid = getpid (); @@ -1067,8 +1052,8 @@ /* vt cursor: Black-on-White is standard, but this is more popular */ TermWin_cursor = XCreateFontCursor (disp, XC_xterm); -#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) - /* cursor (menuBar/scrollBar): Black-on-White */ +#ifdef HAVE_SCROLLBARS + /* cursor scrollBar: Black-on-White */ leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); #endif @@ -1090,41 +1075,14 @@ vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; -#ifdef POINTER_BLANK if (OPTION (Opt_pointerBlank)) vt_emask |= PointerMotionMask; else -#endif 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); + vt_select_input (); - 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_ev.start (display, vt); #ifdef XPM_BACKGROUND if (rs[Rs_backgroundPixmap] != NULL @@ -1153,7 +1111,7 @@ drawable = new rxvt_drawable (display, vt); -#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) +#ifdef RXVT_SCROLLBAR gcvalue.foreground = pix_colors[Color_topShadow]; topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); gcvalue.foreground = pix_colors[Color_bottomShadow]; @@ -1406,20 +1364,23 @@ #if ENABLE_FRILLS if (rs[Rs_pty_fd]) { - pty.pty = atoi (rs[Rs_pty_fd]); + pty->pty = atoi (rs[Rs_pty_fd]); - if (getfd_hook) - pty.pty = (*getfd_hook) (pty.pty); + 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"); + 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); + pty->set_utf8_mode (enc_utf8); /* set initial window size */ tt_winch (); @@ -1442,7 +1403,6 @@ return; #endif -#ifndef __QNX__ /* spin off the command interpreter */ switch (cmd_pid = fork ()) { @@ -1454,20 +1414,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); @@ -1477,36 +1437,18 @@ _exit (EXIT_FAILURE); default: - { -#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) - int fdstdin; - - fdstdin = dup (STDIN_FILENO); - dup2 (pty.tty, STDIN_FILENO); +#if UTMP_SUPPORT + if (!OPTION (Opt_utmpInhibit)) + pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]); #endif -#ifdef UTMP_SUPPORT - privileged_utmp (SAVE); -#endif + pty->close_tty (); -#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) - - dup2 (fdstdin, STDIN_FILENO); - close (fdstdin); -#endif - } + child_ev.start (cmd_pid); - 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 } /* ------------------------------------------------------------------------- * @@ -1560,7 +1502,6 @@ sigemptyset (&ss); sigprocmask (SIG_SETMASK, &ss, 0); -#ifndef __QNX__ /* command interpreter path */ if (argv != NULL) { @@ -1576,7 +1517,7 @@ } else { - const char *argv0, *shell; + const char *argv0, *shell; if ((shell = getenv ("SHELL")) == NULL || *shell == '\0') shell = "/bin/sh"; @@ -1591,66 +1532,11 @@ 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; - } - - 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; }