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.51 by pcg, Sun May 9 18:19:49 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
1074/*----------------------------------------------------------------------*/ 1072/*----------------------------------------------------------------------*/
1075/* rxvt_Create_Windows () - Open and map the window */ 1073/* rxvt_Create_Windows () - Open and map the window */
1076void 1074void
1077rxvt_term::create_windows (int argc, const char *const *argv) 1075rxvt_term::create_windows (int argc, const char *const *argv)
1078{ 1076{
1079 XClassHint classHint; 1077 XClassHint classHint;
1080 XWMHints wmHint; 1078 XWMHints wmHint;
1081 XGCValues gcvalue; 1079 XGCValues gcvalue;
1082 long vt_emask; 1080 long vt_emask;
1083 1081 XSetWindowAttributes attributes;
1084 XWindowAttributes gattr; 1082 XWindowAttributes gattr;
1085 1083
1086 if (Options & Opt_transparent) 1084 if (Options & Opt_transparent)
1087 { 1085 {
1088 XGetWindowAttributes (display->display, RootWindow (display->display, display->screen), &gattr); 1086 XGetWindowAttributes (display->display, RootWindow (display->display, display->screen), &gattr);
1101 1099
1102 window_calc (0, 0); 1100 window_calc (0, 0);
1103 old_width = szHint.width; 1101 old_width = szHint.width;
1104 old_height = szHint.height; 1102 old_height = szHint.height;
1105 1103
1106 /* parent window - reverse video so we can see placement errors
1107 * sub-window placement & size in rxvt_resize_subwindows () 1104 /* sub-window placement & size in rxvt_resize_subwindows () */
1108 */
1109 1105
1110#ifdef PREFER_24BIT 1106#ifdef PREFER_24BIT
1111 XSetWindowAttributes attributes;
1112
1113 attributes.background_pixel = PixColors[Color_fg]; 1107 attributes.background_pixel = PixColors[Color_bg];
1114 attributes.border_pixel = PixColors[Color_border]; 1108 attributes.border_pixel = PixColors[Color_border];
1115 attributes.colormap = display->cmap; 1109 attributes.colormap = display->cmap;
1116 TermWin.parent[0] = XCreateWindow (display->display, DefaultRootWindow (display->display), 1110 TermWin.parent[0] = XCreateWindow (display->display, DefaultRootWindow (display->display),
1117 szHint.x, szHint.y, 1111 szHint.x, szHint.y,
1118 szHint.width, szHint.height, 1112 szHint.width, szHint.height,
1119 TermWin.ext_bwidth, 1113 TermWin.ext_bwidth,
1120 display->depth, InputOutput, 1114 display->depth, InputOutput,
1121 display->visual, 1115 display->visual,
1122 CWBackPixel | CWBorderPixel | CWColormap, &attributes); 1116 CWColormap | CWBackPixel | CWBorderPixel, &attributes);
1123#else 1117#else
1124 TermWin.parent[0] = XCreateSimpleWindow (display->display, DefaultRootWindow (display->display), 1118 TermWin.parent[0] = XCreateSimpleWindow (display->display, DefaultRootWindow (display->display),
1125 szHint.x, szHint.y, 1119 szHint.x, szHint.y,
1126 szHint.width, 1120 szHint.width, szHint.height,
1127 szHint.height,
1128 TermWin.ext_bwidth, 1121 TermWin.ext_bwidth,
1129 PixColors[Color_border], 1122 PixColors[Color_border],
1130 PixColors[Color_fg]); 1123 PixColors[Color_bg]);
1131#endif 1124#endif
1132 1125
1133 xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); 1126 process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST);
1134 xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); 1127 process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST);
1135 1128
1136 classHint.res_name = (char *)rs[Rs_name]; 1129 classHint.res_name = (char *)rs[Rs_name];
1137 classHint.res_class = (char *)RESCLASS; 1130 classHint.res_class = (char *)RESCLASS;
1138 1131
1139 wmHint.flags = (InputHint | StateHint | WindowGroupHint); 1132 wmHint.flags = InputHint | StateHint | WindowGroupHint;
1140 wmHint.input = True; 1133 wmHint.input = True;
1141 wmHint.initial_state = (Options & Opt_iconic ? IconicState 1134 wmHint.initial_state = Options & Opt_iconic ? IconicState : NormalState;
1142 : NormalState);
1143 wmHint.window_group = TermWin.parent[0]; 1135 wmHint.window_group = TermWin.parent[0];
1144 1136
1145 XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL, 1137 XSetWMProperties (display->display, TermWin.parent[0], NULL, NULL,
1146 (char **)argv, argc, &szHint, &wmHint, &classHint); 1138 (char **)argv, argc, &szHint, &wmHint, &classHint);
1139
1140#ifndef NO_FRILLS
1141 long pid = getpid ();
1142 XChangeProperty (display->display, TermWin.parent[0],
1143 display->atom ("_NET_WM_PID"), XA_CARDINAL, 32,
1144 PropModeReplace, (unsigned char *)&pid, 1);
1145#endif
1147 1146
1148 XSelectInput (display->display, TermWin.parent[0], 1147 XSelectInput (display->display, TermWin.parent[0],
1149 KeyPressMask 1148 KeyPressMask
1150#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1149#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1151 | KeyReleaseMask 1150 | KeyReleaseMask
1186 1185
1187#ifdef DEBUG_X 1186#ifdef DEBUG_X
1188 XStoreName (display->display, TermWin.vt, "vt window"); 1187 XStoreName (display->display, TermWin.vt, "vt window");
1189#endif 1188#endif
1190 1189
1190 attributes.bit_gravity = NorthWestGravity;
1191 XChangeWindowAttributes (display->display, TermWin.vt, CWBitGravity, &attributes);
1192
1191 vt_emask = (ExposureMask | ButtonPressMask | ButtonReleaseMask 1193 vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask;
1192 | PropertyChangeMask);
1193 1194
1194#ifdef POINTER_BLANK 1195#ifdef POINTER_BLANK
1195 pointer_unblank (); 1196 pointer_unblank ();
1196 1197
1197 if ((Options & Opt_pointerBlank)) 1198 if (Options & Opt_pointerBlank)
1198 vt_emask |= PointerMotionMask; 1199 vt_emask |= PointerMotionMask;
1199 else 1200 else
1200#endif 1201#endif
1201 vt_emask |= (Button1MotionMask | Button3MotionMask); 1202 vt_emask |= Button1MotionMask | Button3MotionMask;
1202 1203
1203 XSelectInput (display->display, TermWin.vt, vt_emask); 1204 XSelectInput (display->display, TermWin.vt, vt_emask);
1204 vt_ev.start (display, TermWin.vt); 1205 vt_ev.start (display, TermWin.vt);
1205 1206
1206#if defined(MENUBAR) && (MENUBAR_MAX > 1) 1207#if defined(MENUBAR) && (MENUBAR_MAX > 1)
1249 /* graphics context for the vt window */ 1250 /* graphics context for the vt window */
1250 gcvalue.foreground = PixColors[Color_fg]; 1251 gcvalue.foreground = PixColors[Color_fg];
1251 gcvalue.background = PixColors[Color_bg]; 1252 gcvalue.background = PixColors[Color_bg];
1252 gcvalue.graphics_exposures = 1; 1253 gcvalue.graphics_exposures = 1;
1253 TermWin.gc = XCreateGC (display->display, TermWin.vt, 1254 TermWin.gc = XCreateGC (display->display, TermWin.vt,
1254 GCForeground | GCBackground 1255 GCForeground | GCBackground | GCGraphicsExposures,
1255 | GCGraphicsExposures, &gcvalue); 1256 &gcvalue);
1256 1257
1257 TermWin.drawable = new rxvt_drawable (display, TermWin.vt); 1258 TermWin.drawable = new rxvt_drawable (display, TermWin.vt);
1258 1259
1259#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 1260#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
1260 gcvalue.foreground = PixColors[Color_topShadow]; 1261 gcvalue.foreground = PixColors[Color_topShadow];
1277{ 1278{
1278 int cfd, er; 1279 int cfd, er;
1279 1280
1280 /* get master (pty) */ 1281 /* get master (pty) */
1281 if ((cfd = rxvt_get_pty (& (tty_fd), & (ttydev))) < 0) 1282 if ((cfd = rxvt_get_pty (& (tty_fd), & (ttydev))) < 0)
1282 {
1283 rxvt_print_error ("can't open pseudo-tty"); 1283 rxvt_fatal ("can't open pseudo-tty");
1284 return -1;
1285 }
1286 1284
1287 fcntl (cfd, F_SETFL, O_NONBLOCK); 1285 fcntl (cfd, F_SETFL, O_NONBLOCK);
1288 1286
1289 /* get slave (tty) */ 1287 /* get slave (tty) */
1290 if (tty_fd < 0) 1288 if (tty_fd < 0)
1294#endif 1292#endif
1295 1293
1296 if ((tty_fd = rxvt_get_tty (ttydev)) < 0) 1294 if ((tty_fd = rxvt_get_tty (ttydev)) < 0)
1297 { 1295 {
1298 close (cfd); 1296 close (cfd);
1299 rxvt_print_error ("can't open slave tty %s", ttydev); 1297 rxvt_fatal ("can't open slave tty %s", ttydev);
1300 return -1;
1301 } 1298 }
1302 } 1299 }
1303#ifndef NO_BACKSPACE_KEY 1300#ifndef NO_BACKSPACE_KEY
1304 if (key_backspace[0] && !key_backspace[1]) 1301 if (key_backspace[0] && !key_backspace[1])
1305 er = key_backspace[0]; 1302 er = key_backspace[0];
1315#ifndef __QNX__ 1312#ifndef __QNX__
1316 /* spin off the command interpreter */ 1313 /* spin off the command interpreter */
1317 switch (cmd_pid = fork ()) 1314 switch (cmd_pid = fork ())
1318 { 1315 {
1319 case -1: 1316 case -1:
1320 rxvt_print_error ("can't fork"); 1317 rxvt_fatal ("can't fork");
1321 return -1;
1322 case 0: 1318 case 0:
1323 close (cfd); /* only keep tty_fd and STDERR open */ 1319 close (cfd); /* only keep tty_fd and STDERR open */
1324 1320
1325 init_env (); 1321 init_env ();
1326 1322
1327 if (rxvt_control_tty (tty_fd, ttydev) < 0) 1323 if (rxvt_control_tty (tty_fd, ttydev) < 0)
1328 rxvt_print_error ("could not obtain control of tty"); 1324 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME);
1329 else 1325 else
1330 { 1326 {
1331 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1327 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1332 dup2 (tty_fd, STDIN_FILENO); 1328 dup2 (tty_fd, STDIN_FILENO);
1333 dup2 (tty_fd, STDOUT_FILENO); 1329 dup2 (tty_fd, STDOUT_FILENO);
1335 1331
1336 if (tty_fd > 2) 1332 if (tty_fd > 2)
1337 close (tty_fd); 1333 close (tty_fd);
1338 1334
1339 run_child (argv); 1335 run_child (argv);
1336 fprintf (stderr, "%s: unable to exec child.", RESNAME);
1340 } 1337 }
1338
1341 exit (EXIT_FAILURE); 1339 _exit (EXIT_FAILURE);
1342 /* NOTREACHED */ 1340
1343 default: 1341 default:
1344 { 1342 {
1345#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1343#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1346 int fdstdin; 1344 int fdstdin;
1347 1345
1356#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1354#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT)
1357 1355
1358 dup2 (fdstdin, STDIN_FILENO); 1356 dup2 (fdstdin, STDIN_FILENO);
1359 close (fdstdin); 1357 close (fdstdin);
1360#endif 1358#endif
1361
1362 } 1359 }
1360
1363 close (tty_fd); /* keep STDERR_FILENO, cmd_fd, display->fd () open */ 1361 close (tty_fd); /* keep STDERR_FILENO, cmd_fd, display->fd () open */
1364 break; 1362 break;
1365 } 1363 }
1366#else /* __QNX__ uses qnxspawn () */ 1364#else /* __QNX__ uses qnxspawn () */
1367 fchmod (tty_fd, 0622); 1365 fchmod (tty_fd, 0622);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines