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.40 by pcg, Sun Mar 14 23:14:39 2004 UTC vs.
Revision 1.50 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: init.c 2 * File: init.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
7 * - original version 7 * - original version
313#endif 313#endif
314#ifndef NO_CURSORCOLOR 314#ifndef NO_CURSORCOLOR
315 COLOR_CURSOR_BACKGROUND, 315 COLOR_CURSOR_BACKGROUND,
316 COLOR_CURSOR_FOREGROUND, 316 COLOR_CURSOR_FOREGROUND,
317#endif /* ! NO_CURSORCOLOR */ 317#endif /* ! NO_CURSORCOLOR */
318 NULL, /* Color_pointer */ 318 NULL, /* Color_pointer_fg */
319 NULL, /* Color_pointer_bg */
319 NULL, /* Color_border */ 320 NULL, /* Color_border */
320#ifndef NO_BOLD_UNDERLINE_REVERSE 321#ifndef NO_BOLD_UNDERLINE_REVERSE
321 NULL, /* Color_BD */ 322 NULL, /* Color_BD */
322 NULL, /* Color_UL */ 323 NULL, /* Color_UL */
323 NULL, /* Color_RV */ 324 NULL, /* Color_RV */
324#endif /* ! NO_BOLD_UNDERLINE_REVERSE */ 325#endif /* ! NO_BOLD_UNDERLINE_REVERSE */
325#ifdef OPTION_HC 326#ifdef OPTION_HC
327 NULL,
328#endif
329#if TINTING
326 NULL, 330 NULL,
327#endif 331#endif
328#ifdef KEEP_SCROLLCOLOR 332#ifdef KEEP_SCROLLCOLOR
329 COLOR_SCROLLBAR, 333 COLOR_SCROLLBAR,
330 COLOR_SCROLLTROUGH, 334 COLOR_SCROLLTROUGH,
494 cmd_argv[i] = (const char *)argv[i + r_argc + 1]; 498 cmd_argv[i] = (const char *)argv[i + r_argc + 1];
495 499
496 cmd_argv[i] = NULL; 500 cmd_argv[i] = NULL;
497 } 501 }
498 502
499 /* clear all resources */
500 for (i = 0; i < NUM_RESOURCES;)
501 rs[i++] = NULL;
502
503 rs[Rs_name] = rxvt_r_basename (argv[0]); 503 rs[Rs_name] = rxvt_r_basename (argv[0]);
504 504
505 /* 505 /*
506 * Open display, get options/resources and create the window 506 * Open display, get options/resources and create the window
507 */ 507 */
522 } 522 }
523#endif 523#endif
524 524
525 if (!display 525 if (!display
526 && ! (display = displays.get (rs[Rs_display_name]))) 526 && ! (display = displays.get (rs[Rs_display_name])))
527 {
528 rxvt_print_error ("can't open display %s", rs[Rs_display_name]); 527 rxvt_fatal ("can't open display %s", rs[Rs_display_name]);
529 exit (EXIT_FAILURE);
530 }
531 528
532 extract_resources (display->display, rs[Rs_name]); 529 extract_resources (display->display, rs[Rs_name]);
533 530
534 /* 531 /*
535 * set any defaults not already set 532 * set any defaults not already set
651 color_aliases (Color_bg); 648 color_aliases (Color_bg);
652#ifndef NO_CURSORCOLOR 649#ifndef NO_CURSORCOLOR
653 color_aliases (Color_cursor); 650 color_aliases (Color_cursor);
654 color_aliases (Color_cursor2); 651 color_aliases (Color_cursor2);
655#endif /* NO_CURSORCOLOR */ 652#endif /* NO_CURSORCOLOR */
656 color_aliases (Color_pointer); 653 color_aliases (Color_pointer_fg);
654 color_aliases (Color_pointer_bg);
657 color_aliases (Color_border); 655 color_aliases (Color_border);
658#ifndef NO_BOLD_UNDERLINE_REVERSE 656#ifndef NO_BOLD_UNDERLINE_REVERSE
659 color_aliases (Color_BD); 657 color_aliases (Color_BD);
660 color_aliases (Color_UL); 658 color_aliases (Color_UL);
661 color_aliases (Color_RV); 659 color_aliases (Color_RV);
759 free (this->locale); 757 free (this->locale);
760 this->locale = rxvt_strdup (setlocale (LC_CTYPE, locale)); 758 this->locale = rxvt_strdup (setlocale (LC_CTYPE, locale));
761 SET_LOCALE (this->locale); 759 SET_LOCALE (this->locale);
762 mbstate.reset (); 760 mbstate.reset ();
763#endif 761#endif
762#if 0
764#if HAVE_NL_LANGINFO 763#if HAVE_NL_LANGINFO
765 free (codeset); 764 free (codeset);
766 codeset = strdup (nl_langinfo (CODESET)); 765 codeset = strdup (nl_langinfo (CODESET));
767 enc_utf8 = !STRCASECMP (codeset, "UTF-8") 766 enc_utf8 = !STRCASECMP (codeset, "UTF-8")
768 || !STRCASECMP (codeset, "UTF8"); 767 || !STRCASECMP (codeset, "UTF8");
769#else 768#else
770 enc_utf8 = 1; 769 enc_utf8 = 1;
771#endif 770#endif
771#endif
772} 772}
773 773
774void 774void
775rxvt_term::init_xlocale () 775rxvt_term::init_xlocale ()
776{ 776{
777#ifdef USE_XIM 777#ifdef USE_XIM
778 if (!locale) 778 if (!locale)
779 rxvt_print_error ("Setting locale failed."); 779 rxvt_warn ("setting locale failed, working without locale support.\n");
780 else 780 else
781 { 781 {
782 Atom wmlocale; 782 Atom wmlocale;
783 783
784 wmlocale = XInternAtom (display->display, "WM_LOCALE_NAME", False); 784 wmlocale = XInternAtom (display->display, "WM_LOCALE_NAME", False);
786 XA_STRING, 8, PropModeReplace, 786 XA_STRING, 8, PropModeReplace,
787 (unsigned char *)locale, STRLEN (locale)); 787 (unsigned char *)locale, STRLEN (locale));
788 788
789 if (!XSupportsLocale ()) 789 if (!XSupportsLocale ())
790 { 790 {
791 rxvt_print_error ("The locale is not supported by Xlib"); 791 rxvt_warn ("the locale is not supported by Xlib, working withotu locale support.\n");
792 return; 792 return;
793 } 793 }
794 794
795 im_ev.start (display); 795 im_ev.start (display);
796 796
856 if (Options & Opt_cursorBlink) 856 if (Options & Opt_cursorBlink)
857 (void)gettimeofday (&lastcursorchange, NULL); 857 (void)gettimeofday (&lastcursorchange, NULL);
858#endif 858#endif
859 859
860 if ((cmd_fd = run_command (argv)) < 0) 860 if ((cmd_fd = run_command (argv)) < 0)
861 { 861 rxvt_fatal ("failure while running command, aborting");
862 rxvt_print_error ("aborting");
863 exit (EXIT_FAILURE);
864 }
865} 862}
866 863
867/*----------------------------------------------------------------------*/ 864/*----------------------------------------------------------------------*/
868void 865void
869rxvt_term::Get_Colours () 866rxvt_term::Get_Colours ()
894 switch (i) 891 switch (i)
895 { 892 {
896 case Color_fg: 893 case Color_fg:
897 case Color_bg: 894 case Color_bg:
898 /* fatal: need bg/fg color */ 895 /* fatal: need bg/fg color */
899 rxvt_print_error ("aborting"); 896 rxvt_fatal ("unable to get foreground/background colour, aborting");
900 exit (EXIT_FAILURE);
901 /* NOTREACHED */ 897 /* NOTREACHED */
902 break; 898 break;
903#ifndef NO_CURSORCOLOR 899#ifndef NO_CURSORCOLOR
904 case Color_cursor2: 900 case Color_cursor2:
905 xcol = PixColors[Color_fg]; 901 xcol = PixColors[Color_fg];
906 break; 902 break;
907#endif /* ! NO_CURSORCOLOR */ 903#endif /* ! NO_CURSORCOLOR */
908 case Color_pointer: 904 case Color_pointer_fg:
909 xcol = PixColors[Color_fg]; 905 xcol = PixColors[Color_fg];
910 break; 906 break;
911 default: 907 default:
912 xcol = PixColors[Color_bg]; /* None */ 908 xcol = PixColors[Color_bg]; /* None */
913 break; 909 break;
917 913
918 PixColors[i] = xcol; 914 PixColors[i] = xcol;
919 SET_PIXCOLOR (i); 915 SET_PIXCOLOR (i);
920 } 916 }
921 917
922 if (XDEPTH <= 2 || !rs[Rs_color + Color_pointer]) 918 if (XDEPTH <= 2)
923 PixColors[Color_pointer] = PixColors[Color_fg]; 919 {
924 if (XDEPTH <= 2 || !rs[Rs_color + Color_border]) 920 if (!rs[Rs_color + Color_pointer_fg]) PixColors[Color_pointer_fg] = PixColors[Color_fg];
925 PixColors[Color_border] = PixColors[Color_fg]; 921 if (!rs[Rs_color + Color_pointer_bg]) PixColors[Color_pointer_bg] = PixColors[Color_bg];
922 if (!rs[Rs_color + Color_border] ) PixColors[Color_border] = PixColors[Color_fg];
923 }
926 924
927 /* 925 /*
928 * get scrollBar/menuBar shadow colors 926 * get scrollBar/menuBar shadow colors
929 * 927 *
930 * The calculations of topShadow/bottomShadow values are adapted 928 * The calculations of topShadow/bottomShadow values are adapted
1128 TermWin.ext_bwidth, 1126 TermWin.ext_bwidth,
1129 PixColors[Color_border], 1127 PixColors[Color_border],
1130 PixColors[Color_fg]); 1128 PixColors[Color_fg]);
1131#endif 1129#endif
1132 1130
1133 xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); 1131 process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST);
1134 xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); 1132 process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST);
1135 1133
1136 classHint.res_name = (char *)rs[Rs_name]; 1134 classHint.res_name = (char *)rs[Rs_name];
1137 classHint.res_class = (char *)RESCLASS; 1135 classHint.res_class = (char *)RESCLASS;
1138 1136
1139 wmHint.flags = (InputHint | StateHint | WindowGroupHint); 1137 wmHint.flags = (InputHint | StateHint | WindowGroupHint);
1141 wmHint.initial_state = (Options & Opt_iconic ? IconicState 1139 wmHint.initial_state = (Options & Opt_iconic ? IconicState
1142 : NormalState); 1140 : NormalState);
1143 wmHint.window_group = TermWin.parent[0]; 1141 wmHint.window_group = TermWin.parent[0];
1144 1142
1145 XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL, 1143 XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL,
1146 (char **)argv, argc, &szHint, &wmHint, &classHint); 1144 (char **)argv, argc, &szHint, &wmHint, &classHint);
1145
1146#ifndef NO_FRILLS
1147 long pid = getpid ();
1148 XChangeProperty (display->display, TermWin.parent[0],
1149 display->atom ("_NET_WM_PID"), XA_CARDINAL, 32,
1150 PropModeReplace, (unsigned char *)&pid, 1);
1151#endif
1147 1152
1148 XSelectInput (display->display, TermWin.parent[0], 1153 XSelectInput (display->display, TermWin.parent[0],
1149 KeyPressMask 1154 KeyPressMask
1150#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1155#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1151 | KeyReleaseMask 1156 | KeyReleaseMask
1249 /* graphics context for the vt window */ 1254 /* graphics context for the vt window */
1250 gcvalue.foreground = PixColors[Color_fg]; 1255 gcvalue.foreground = PixColors[Color_fg];
1251 gcvalue.background = PixColors[Color_bg]; 1256 gcvalue.background = PixColors[Color_bg];
1252 gcvalue.graphics_exposures = 1; 1257 gcvalue.graphics_exposures = 1;
1253 TermWin.gc = XCreateGC (display->display, TermWin.vt, 1258 TermWin.gc = XCreateGC (display->display, TermWin.vt,
1254 GCForeground | GCBackground 1259 GCForeground | GCBackground | GCGraphicsExposures,
1255 | GCGraphicsExposures, &gcvalue); 1260 &gcvalue);
1256 1261
1257 TermWin.drawable = new rxvt_drawable (display, TermWin.vt); 1262 TermWin.drawable = new rxvt_drawable (display, TermWin.vt);
1258 1263
1259#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 1264#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
1260 gcvalue.foreground = PixColors[Color_topShadow]; 1265 gcvalue.foreground = PixColors[Color_topShadow];
1277{ 1282{
1278 int cfd, er; 1283 int cfd, er;
1279 1284
1280 /* get master (pty) */ 1285 /* get master (pty) */
1281 if ((cfd = rxvt_get_pty (& (tty_fd), & (ttydev))) < 0) 1286 if ((cfd = rxvt_get_pty (& (tty_fd), & (ttydev))) < 0)
1282 {
1283 rxvt_print_error ("can't open pseudo-tty"); 1287 rxvt_fatal ("can't open pseudo-tty");
1284 return -1;
1285 }
1286 1288
1287 fcntl (cfd, F_SETFL, O_NONBLOCK); 1289 fcntl (cfd, F_SETFL, O_NONBLOCK);
1288 1290
1289 /* get slave (tty) */ 1291 /* get slave (tty) */
1290 if (tty_fd < 0) 1292 if (tty_fd < 0)
1294#endif 1296#endif
1295 1297
1296 if ((tty_fd = rxvt_get_tty (ttydev)) < 0) 1298 if ((tty_fd = rxvt_get_tty (ttydev)) < 0)
1297 { 1299 {
1298 close (cfd); 1300 close (cfd);
1299 rxvt_print_error ("can't open slave tty %s", ttydev); 1301 rxvt_fatal ("can't open slave tty %s", ttydev);
1300 return -1;
1301 } 1302 }
1302 } 1303 }
1303#ifndef NO_BACKSPACE_KEY 1304#ifndef NO_BACKSPACE_KEY
1304 if (key_backspace[0] && !key_backspace[1]) 1305 if (key_backspace[0] && !key_backspace[1])
1305 er = key_backspace[0]; 1306 er = key_backspace[0];
1315#ifndef __QNX__ 1316#ifndef __QNX__
1316 /* spin off the command interpreter */ 1317 /* spin off the command interpreter */
1317 switch (cmd_pid = fork ()) 1318 switch (cmd_pid = fork ())
1318 { 1319 {
1319 case -1: 1320 case -1:
1320 rxvt_print_error ("can't fork"); 1321 rxvt_fatal ("can't fork");
1321 return -1;
1322 case 0: 1322 case 0:
1323 close (cfd); /* only keep tty_fd and STDERR open */ 1323 close (cfd); /* only keep tty_fd and STDERR open */
1324 1324
1325 init_env (); 1325 init_env ();
1326 1326
1327 if (rxvt_control_tty (tty_fd, ttydev) < 0) 1327 if (rxvt_control_tty (tty_fd, ttydev) < 0)
1328 rxvt_print_error ("could not obtain control of tty"); 1328 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME);
1329 else 1329 else
1330 { 1330 {
1331 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1331 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1332 dup2 (tty_fd, STDIN_FILENO); 1332 dup2 (tty_fd, STDIN_FILENO);
1333 dup2 (tty_fd, STDOUT_FILENO); 1333 dup2 (tty_fd, STDOUT_FILENO);
1335 1335
1336 if (tty_fd > 2) 1336 if (tty_fd > 2)
1337 close (tty_fd); 1337 close (tty_fd);
1338 1338
1339 run_child (argv); 1339 run_child (argv);
1340 fprintf (stderr, "%s: unable to exec child.", RESNAME);
1340 } 1341 }
1342
1341 exit (EXIT_FAILURE); 1343 _exit (EXIT_FAILURE);
1342 /* NOTREACHED */ 1344
1343 default: 1345 default:
1344 { 1346 {
1345#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1347#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1346 int fdstdin; 1348 int fdstdin;
1347 1349
1356#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1358#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1357 1359
1358 dup2 (fdstdin, STDIN_FILENO); 1360 dup2 (fdstdin, STDIN_FILENO);
1359 close (fdstdin); 1361 close (fdstdin);
1360#endif 1362#endif
1361
1362 } 1363 }
1364
1363 close (tty_fd); /* keep STDERR_FILENO, cmd_fd, display->fd () open */ 1365 close (tty_fd); /* keep STDERR_FILENO, cmd_fd, display->fd () open */
1364 break; 1366 break;
1365 } 1367 }
1366#else /* __QNX__ uses qnxspawn () */ 1368#else /* __QNX__ uses qnxspawn () */
1367 fchmod (tty_fd, 0622); 1369 fchmod (tty_fd, 0622);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines