ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/init.C
(Generate patch)

Comparing rxvt-unicode/src/init.C (file contents):
Revision 1.139 by root, Wed Jan 11 03:13:26 2006 UTC vs.
Revision 1.148 by root, Wed Jan 18 19:43:51 2006 UTC

256 bgPixmap.pixmap = None; 256 bgPixmap.pixmap = None;
257#endif 257#endif
258 258
259 last_bot = last_state = -1; 259 last_bot = last_state = -1;
260 260
261#ifdef MENUBAR
262 menu_readonly = 1;
263# if ! (MENUBAR_MAX > 1)
264 CurrentBar = &BarList;
265# endif /* (MENUBAR_MAX > 1) */
266#endif
267
268 return true; 261 return true;
269} 262}
270 263
271void 264void
272rxvt_term::init_secondary () 265rxvt_term::init_secondary ()
339 rs[Rs_name] = rxvt_r_basename (argv[0]); 332 rs[Rs_name] = rxvt_r_basename (argv[0]);
340 333
341 /* 334 /*
342 * Open display, get options/resources and create the window 335 * Open display, get options/resources and create the window
343 */ 336 */
344 {
345 TEMP_ENV;
346 337
347 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) 338 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL)
348 rs[Rs_display_name] = ":0"; 339 rs[Rs_display_name] = ":0";
349 340
350 get_options (r_argc, r_argv); 341 get_options (r_argc, r_argv);
351 342
352 if (!(display = displays.get (rs[Rs_display_name]))) 343 if (!(display = displays.get (rs[Rs_display_name])))
353 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); 344 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]);
354 345
355 extract_resources (); 346 extract_resources ();
356 }
357 347
358 free (r_argv); 348 free (r_argv);
359 349
360 /* 350 /*
361 * set any defaults not already set 351 * set any defaults not already set
581 * This should support all European type languages. 571 * This should support all European type languages.
582 */ 572 */
583void 573void
584rxvt_term::set_locale (const char *locale) 574rxvt_term::set_locale (const char *locale)
585{ 575{
586 TEMP_ENV; 576 set_environ (envv);
587 577
588#if HAVE_XSETLOCALE || HAVE_SETLOCALE 578#if HAVE_XSETLOCALE || HAVE_SETLOCALE
589 free (this->locale); 579 free (this->locale);
590 this->locale = setlocale (LC_CTYPE, locale); 580 this->locale = setlocale (LC_CTYPE, locale);
591 581
622} 612}
623 613
624void 614void
625rxvt_term::init_xlocale () 615rxvt_term::init_xlocale ()
626{ 616{
627 TEMP_ENV; 617 set_environ (envv);
628 618
629#ifdef USE_XIM 619#ifdef USE_XIM
630 if (!locale) 620 if (!locale)
631 rxvt_warn ("setting locale failed, working without locale support.\n"); 621 rxvt_warn ("setting locale failed, working without locale support.\n");
632 else 622 else
673 if (strcmp (key_backspace, "DEC") == 0) 663 if (strcmp (key_backspace, "DEC") == 0)
674 priv_modes |= PrivMode_HaveBackSpace; 664 priv_modes |= PrivMode_HaveBackSpace;
675#endif 665#endif
676 666
677 /* add value for scrollBar */ 667 /* add value for scrollBar */
678 if (scrollbar_visible ()) 668 if (scrollBar.state)
679 { 669 {
680 priv_modes |= PrivMode_scrollBar; 670 priv_modes |= PrivMode_scrollBar;
681 SavedModes |= PrivMode_scrollBar; 671 SavedModes |= PrivMode_scrollBar;
682 }
683
684 if (menubar_visible ())
685 {
686 priv_modes |= PrivMode_menuBar;
687 SavedModes |= PrivMode_menuBar;
688 } 672 }
689 673
690 run_command (argv); 674 run_command (argv);
691} 675}
692 676
760 if (!rs[Rs_color + Color_pointer_bg]) pix_colors[Color_pointer_bg] = pix_colors[Color_bg]; 744 if (!rs[Rs_color + Color_pointer_bg]) pix_colors[Color_pointer_bg] = pix_colors[Color_bg];
761 if (!rs[Rs_color + Color_border] ) pix_colors[Color_border] = pix_colors[Color_fg]; 745 if (!rs[Rs_color + Color_border] ) pix_colors[Color_border] = pix_colors[Color_fg];
762 } 746 }
763 747
764 /* 748 /*
765 * get scrollBar/menuBar shadow colors 749 * get scrollBar shadow colors
766 * 750 *
767 * The calculations of topShadow/bottomShadow values are adapted 751 * The calculations of topShadow/bottomShadow values are adapted
768 * from the fvwm window manager. 752 * from the fvwm window manager.
769 */ 753 */
770#ifdef KEEP_SCROLLCOLOR 754#ifdef KEEP_SCROLLCOLOR
925#if ENABLE_FRILLS 909#if ENABLE_FRILLS
926 Atom prop = None; 910 Atom prop = None;
927 MWMHints mwmhints; 911 MWMHints mwmhints;
928#endif 912#endif
929 XGCValues gcvalue; 913 XGCValues gcvalue;
930 long vt_emask;
931 XSetWindowAttributes attributes; 914 XSetWindowAttributes attributes;
932 XWindowAttributes gattr; 915 XWindowAttributes gattr;
933 Window top, parent; 916 Window top, parent;
934 dDisp; 917 dDisp;
935 918
945 { 928 {
946 XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr); 929 XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr);
947 display->depth = gattr.depth; // doh //TODO, per-term not per-display? 930 display->depth = gattr.depth; // doh //TODO, per-term not per-display?
948 } 931 }
949 932
933 /* grab colors before netscape does */
934 Get_Colours ();
935
936 if (!set_fonts ())
937 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
938
939 parent = DefaultRootWindow (disp);
940
941 attributes.override_redirect = !!OPTION (Opt_override_redirect);
942
950#if ENABLE_FRILLS 943#if ENABLE_FRILLS
951 if (OPTION (Opt_borderLess)) 944 if (OPTION (Opt_borderLess))
952 { 945 {
953 prop = XInternAtom(disp, "_MOTIF_WM_INFO", True); 946 prop = XInternAtom (disp, "_MOTIF_WM_INFO", True);
954 947
955 if (prop == None) 948 if (prop == None)
956 { 949 {
957 /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/ 950 /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/
958#ifdef PREFER_24BIT
959 attributes.override_redirect = TRUE; 951 attributes.override_redirect = TRUE;
960#endif
961 mwmhints.flags = 0; 952 mwmhints.flags = 0;
962 } 953 }
963 else 954 else
964 { 955 {
965 mwmhints.flags = MWM_HINTS_DECORATIONS; 956 mwmhints.flags = MWM_HINTS_DECORATIONS;
968 } 959 }
969 else 960 else
970 mwmhints.flags = 0; 961 mwmhints.flags = 0;
971#endif 962#endif
972 963
973 /* grab colors before netscape does */
974 Get_Colours ();
975
976 if (!set_fonts ())
977 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
978
979 parent = DefaultRootWindow (disp);
980
981#if ENABLE_XEMBED 964#if ENABLE_XEMBED
982 if (rs[Rs_embed]) 965 if (rs[Rs_embed])
983 { 966 {
984 XWindowAttributes wattr; 967 XWindowAttributes wattr;
985 968
993#endif 976#endif
994 977
995 window_calc (0, 0); 978 window_calc (0, 0);
996 979
997 /* sub-window placement & size in rxvt_resize_subwindows () */ 980 /* sub-window placement & size in rxvt_resize_subwindows () */
998#ifdef PREFER_24BIT
999 attributes.background_pixel = pix_colors_focused[Color_border]; 981 attributes.background_pixel = pix_colors_focused[Color_border];
1000 attributes.border_pixel = pix_colors_focused[Color_border]; 982 attributes.border_pixel = pix_colors_focused[Color_border];
1001 attributes.colormap = display->cmap; 983 attributes.colormap = display->cmap;
1002 top = XCreateWindow (disp, parent, 984 top = XCreateWindow (disp, parent,
1003 szHint.x, szHint.y, 985 szHint.x, szHint.y,
1004 szHint.width, szHint.height, 986 szHint.width, szHint.height,
1005 ext_bwidth, 987 ext_bwidth,
1006 display->depth, InputOutput, 988 display->depth, InputOutput,
1007 display->visual, 989 display->visual,
1008 CWColormap | CWBackPixel | CWBorderPixel, &attributes); 990 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
1009#else 991 &attributes);
1010 top = XCreateSimpleWindow (disp, parent,
1011 szHint.x, szHint.y,
1012 szHint.width, szHint.height,
1013 ext_bwidth,
1014 pix_colors_focused[Color_border],
1015 pix_colors_focused[Color_border]);
1016#endif
1017 992
1018 this->parent[0] = top; 993 this->parent[0] = top;
1019 994
1020 old_width = szHint.width; 995 old_width = szHint.width;
1021 old_height = szHint.height; 996 old_height = szHint.height;
1075#endif 1050#endif
1076 1051
1077 /* vt cursor: Black-on-White is standard, but this is more popular */ 1052 /* vt cursor: Black-on-White is standard, but this is more popular */
1078 TermWin_cursor = XCreateFontCursor (disp, XC_xterm); 1053 TermWin_cursor = XCreateFontCursor (disp, XC_xterm);
1079 1054
1080#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 1055#ifdef HAVE_SCROLLBARS
1081 /* cursor (menuBar/scrollBar): Black-on-White */ 1056 /* cursor scrollBar: Black-on-White */
1082 leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); 1057 leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr);
1083#endif 1058#endif
1084 1059
1085 /* the vt window */ 1060 /* the vt window */
1086 vt = XCreateSimpleWindow (disp, top, 1061 vt = XCreateSimpleWindow (disp, top,
1098 attributes.bit_gravity = NorthWestGravity; 1073 attributes.bit_gravity = NorthWestGravity;
1099 XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes); 1074 XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes);
1100 1075
1101 vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; 1076 vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask;
1102 1077
1103 if (OPTION (Opt_pointerBlank) 1078 if (OPTION (Opt_pointerBlank))
1104#ifdef ENABLE_PERL
1105 || perl.self
1106#endif
1107 )
1108 vt_emask |= PointerMotionMask; 1079 vt_emask |= PointerMotionMask;
1109 else 1080 else
1110 vt_emask |= Button1MotionMask | Button3MotionMask; 1081 vt_emask |= Button1MotionMask | Button3MotionMask;
1111 1082
1112 XSelectInput (disp, vt, vt_emask); 1083 vt_select_input ();
1084
1113 vt_ev.start (display, vt); 1085 vt_ev.start (display, vt);
1114
1115#if defined(MENUBAR) && (MENUBAR_MAX > 1)
1116 if (menuBar_height ())
1117 {
1118 menuBar.win = XCreateSimpleWindow (disp, top,
1119 window_vt_x, 0,
1120 width,
1121 menuBar_TotalHeight (),
1122 0,
1123 pix_colors_focused[Color_fg],
1124 pix_colors_focused[Color_scroll]);
1125
1126#ifdef DEBUG_X
1127 XStoreName (disp, menuBar.win, "menubar");
1128#endif
1129
1130 menuBar.drawable = new rxvt_drawable (display, menuBar.win);
1131
1132 XDefineCursor (disp, menuBar.win,
1133 XCreateFontCursor (disp, XC_left_ptr));
1134
1135 XSelectInput (disp, menuBar.win,
1136 (ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask));
1137 menubar_ev.start (display, menuBar.win);
1138 }
1139#endif
1140 1086
1141#ifdef XPM_BACKGROUND 1087#ifdef XPM_BACKGROUND
1142 if (rs[Rs_backgroundPixmap] != NULL 1088 if (rs[Rs_backgroundPixmap] != NULL
1143 && ! OPTION (Opt_transparent)) 1089 && ! OPTION (Opt_transparent))
1144 { 1090 {
1163 GCForeground | GCBackground | GCGraphicsExposures, 1109 GCForeground | GCBackground | GCGraphicsExposures,
1164 &gcvalue); 1110 &gcvalue);
1165 1111
1166 drawable = new rxvt_drawable (display, vt); 1112 drawable = new rxvt_drawable (display, vt);
1167 1113
1168#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 1114#ifdef RXVT_SCROLLBAR
1169 gcvalue.foreground = pix_colors[Color_topShadow]; 1115 gcvalue.foreground = pix_colors[Color_topShadow];
1170 topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); 1116 topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue);
1171 gcvalue.foreground = pix_colors[Color_bottomShadow]; 1117 gcvalue.foreground = pix_colors[Color_bottomShadow];
1172 botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue); 1118 botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue);
1173 gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)]; 1119 gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)];
1413 * the slave. 1359 * the slave.
1414 */ 1360 */
1415void 1361void
1416rxvt_term::run_command (const char *const *argv) 1362rxvt_term::run_command (const char *const *argv)
1417{ 1363{
1418 TEMP_ENV; // not very temporary...
1419
1420#if ENABLE_FRILLS 1364#if ENABLE_FRILLS
1421 if (rs[Rs_pty_fd]) 1365 if (rs[Rs_pty_fd])
1422 { 1366 {
1423 pty.pty = atoi (rs[Rs_pty_fd]); 1367 pty->pty = atoi (rs[Rs_pty_fd]);
1424 1368
1425 if (pty.pty >= 0) 1369 if (pty->pty >= 0)
1426 { 1370 {
1427 if (getfd_hook) 1371 if (getfd_hook)
1428 pty.pty = (*getfd_hook) (pty.pty); 1372 pty->pty = (*getfd_hook) (pty->pty);
1429 1373
1430 if (pty.pty < 0 || fcntl (pty.pty, F_SETFL, O_NONBLOCK)) 1374 if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK))
1431 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); 1375 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n");
1432 } 1376 }
1433 } 1377 }
1434 else 1378 else
1435#endif 1379#endif
1436 if (!pty.get ()) 1380 if (!pty->get ())
1437 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); 1381 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
1438 1382
1439 pty.set_utf8_mode (enc_utf8); 1383 pty->set_utf8_mode (enc_utf8);
1440 1384
1441 /* set initial window size */ 1385 /* set initial window size */
1442 tt_winch (); 1386 tt_winch ();
1443 1387
1444 int er; 1388 int er;
1457#if ENABLE_FRILLS 1401#if ENABLE_FRILLS
1458 if (rs[Rs_pty_fd]) 1402 if (rs[Rs_pty_fd])
1459 return; 1403 return;
1460#endif 1404#endif
1461 1405
1462#ifndef __QNX__
1463 /* spin off the command interpreter */ 1406 /* spin off the command interpreter */
1464 switch (cmd_pid = fork ()) 1407 switch (cmd_pid = fork ())
1465 { 1408 {
1466 case -1: 1409 case -1:
1467 { 1410 {
1469 rxvt_fatal ("can't fork, aborting.\n"); 1412 rxvt_fatal ("can't fork, aborting.\n");
1470 } 1413 }
1471 case 0: 1414 case 0:
1472 init_env (); 1415 init_env ();
1473 1416
1474 if (!pty.make_controlling_tty ()) 1417 if (!pty->make_controlling_tty ())
1475 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME); 1418 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME);
1476 else 1419 else
1477 { 1420 {
1478 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1421 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1479 dup2 (pty.tty, STDIN_FILENO); 1422 dup2 (pty->tty, STDIN_FILENO);
1480 dup2 (pty.tty, STDOUT_FILENO); 1423 dup2 (pty->tty, STDOUT_FILENO);
1481 dup2 (pty.tty, STDERR_FILENO); 1424 dup2 (pty->tty, STDERR_FILENO);
1482 1425
1483 // close all our file handles that we do no longer need 1426 // close all our file handles that we do no longer need
1484 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 1427 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
1485 { 1428 {
1486 if ((*t)->pty.pty > 2) close ((*t)->pty.pty); 1429 if ((*t)->pty->pty > 2) close ((*t)->pty->pty);
1487 if ((*t)->pty.tty > 2) close ((*t)->pty.tty); 1430 if ((*t)->pty->tty > 2) close ((*t)->pty->tty);
1488 } 1431 }
1489 1432
1490 run_child (argv); 1433 run_child (argv);
1491 fprintf (stderr, "%s: unable to exec child.", RESNAME); 1434 fprintf (stderr, "%s: unable to exec child.", RESNAME);
1492 } 1435 }
1493 1436
1494 _exit (EXIT_FAILURE); 1437 _exit (EXIT_FAILURE);
1495 1438
1496 default: 1439 default:
1497 {
1498#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1499 int fdstdin;
1500
1501 fdstdin = dup (STDIN_FILENO);
1502 dup2 (pty.tty, STDIN_FILENO);
1503#endif
1504
1505#ifdef UTMP_SUPPORT 1440#if UTMP_SUPPORT
1506 privileged_utmp (SAVE); 1441 if (!OPTION (Opt_utmpInhibit))
1442 pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]);
1507#endif 1443#endif
1508 1444
1509#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1445 pty->close_tty ();
1510
1511 dup2 (fdstdin, STDIN_FILENO);
1512 close (fdstdin);
1513#endif
1514 }
1515
1516 pty.close_tty (); /* keep STDERR_FILENO, pty.pty, display->fd () open */
1517 break; 1446 break;
1518 } 1447 }
1519#else /* __QNX__ uses qnxspawn () */
1520 fchmod (pty.tty, 0622);
1521 fcntl (pty.tty, F_SETFD, FD_CLOEXEC);
1522 fcntl (pty.pty, F_SETFD, FD_CLOEXEC);
1523
1524 if (run_child (argv) == -1)
1525 exit (EXIT_FAILURE);
1526#endif
1527} 1448}
1528 1449
1529/* ------------------------------------------------------------------------- * 1450/* ------------------------------------------------------------------------- *
1530 * CHILD PROCESS OPERATIONS * 1451 * CHILD PROCESS OPERATIONS *
1531 * ------------------------------------------------------------------------- */ 1452 * ------------------------------------------------------------------------- */
1575 // unblock signals (signals are blocked by iom.C 1496 // unblock signals (signals are blocked by iom.C
1576 sigset_t ss; 1497 sigset_t ss;
1577 sigemptyset (&ss); 1498 sigemptyset (&ss);
1578 sigprocmask (SIG_SETMASK, &ss, 0); 1499 sigprocmask (SIG_SETMASK, &ss, 0);
1579 1500
1580#ifndef __QNX__
1581 /* command interpreter path */ 1501 /* command interpreter path */
1582 if (argv != NULL) 1502 if (argv != NULL)
1583 { 1503 {
1584# ifdef DEBUG_CMD 1504# ifdef DEBUG_CMD
1585 int i; 1505 int i;
1611 1531
1612 execlp (shell, argv0, NULL); 1532 execlp (shell, argv0, NULL);
1613 /* no error message: STDERR is closed! */ 1533 /* no error message: STDERR is closed! */
1614 } 1534 }
1615 1535
1616#else /* __QNX__ uses qnxspawn () */
1617
1618 char iov_a[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
1619 char *command = NULL, fullcommand[_MAX_PATH];
1620 char **arg_v, *arg_a[2] = { NULL, NULL };
1621
1622 if (argv != NULL)
1623 {
1624 if (access (argv[0], X_OK) == -1)
1625 {
1626 if (strchr (argv[0], '/') == NULL)
1627 {
1628 searchenv (argv[0], "PATH", fullcommand);
1629
1630 if (fullcommand[0] != '\0')
1631 command = fullcommand;
1632 }
1633
1634 if (access (command, X_OK) == -1)
1635 return -1;
1636 }
1637 else
1638 command = argv[0];
1639
1640 arg_v = argv;
1641 }
1642 else
1643 {
1644 if ((command = getenv ("SHELL")) == NULL || *command == '\0')
1645 command = "/bin/sh";
1646
1647 arg_a[0] = my_basename (command);
1648
1649 if (OPTION (Opt_loginShell))
1650 {
1651 login = rxvt_malloc ((strlen (arg_a[0]) + 2) * sizeof (char));
1652
1653 login[0] = '-';
1654 strcpy (&login[1], arg_a[0]);
1655 arg_a[0] = login;
1656 }
1657
1658 arg_v = arg_a;
1659 }
1660
1661 iov_a[0] = iov_a[1] = iov_a[2] = pty.tty;
1662 cmd_pid = qnx_spawn (0, 0, 0, -1, -1,
1663 _SPAWN_SETSID | _SPAWN_TCSETPGRP,
1664 command, arg_v, environ, iov_a, 0);
1665 if (login)
1666 free (login);
1667
1668 pty.close_tty ();
1669 return pty.pty;
1670#endif
1671
1672 return -1; 1536 return -1;
1673} 1537}
1674 1538
1675/*----------------------- end-of-file (C source) -----------------------*/ 1539/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines