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.2 by pcg, Mon Nov 24 17:31:27 2003 UTC vs.
Revision 1.3 by pcg, Tue Nov 25 11:52:42 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: init.c 2 * File: init.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: init.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ 4 * $Id: init.C,v 1.3 2003/11/25 11:52:42 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
365/*----------------------------------------------------------------------*/ 365/*----------------------------------------------------------------------*/
366/* EXTPROTO */ 366/* EXTPROTO */
367int 367int
368rxvt_init_vars(pR) 368rxvt_init_vars(pR)
369{ 369{
370 struct rxvt_hidden *h;
371
372#ifndef NULLS_ARE_NOT_ZEROS
373 MEMSET(R, 0, sizeof(rxvt_t));
374#endif
375 h = R->h = (struct rxvt_hidden *)rxvt_calloc(1, sizeof(struct rxvt_hidden));
376
377 R->PixColors = (rxvt_color *)rxvt_malloc(sizeof(rxvt_color) * TOTAL_COLORS); 370 R->PixColors = (rxvt_color *)rxvt_malloc(sizeof(rxvt_color) * TOTAL_COLORS);
378 if (R->h == NULL || R->PixColors == NULL) 371 if (R->PixColors == NULL)
379 return -1; 372 return -1;
380 373
381#if defined(XPM_BACKGROUND) || defined(TRANSPARENT) 374#if defined(XPM_BACKGROUND) || defined(TRANSPARENT)
382 R->TermWin.pixmap = None; 375 R->TermWin.pixmap = None;
383#endif 376#endif
384#ifdef UTMP_SUPPORT 377#ifdef UTMP_SUPPORT
385 h->next_utmp_action = SAVE; 378 R->next_utmp_action = SAVE;
386#endif 379#endif
387#ifndef NO_SETOWNER_TTYDEV 380#ifndef NO_SETOWNER_TTYDEV
388 h->next_tty_action = SAVE; 381 R->next_tty_action = SAVE;
389#endif 382#endif
390 h->MEvent.time = CurrentTime; 383 R->MEvent.time = CurrentTime;
391 h->MEvent.button = AnyButton; 384 R->MEvent.button = AnyButton;
392 R->Options = DEFAULT_OPTIONS; 385 R->Options = DEFAULT_OPTIONS;
393 h->want_refresh = 1; 386 R->want_refresh = 1;
394 h->cmd_pid = -1; 387 R->cmd_pid = -1;
395 R->cmd_fd = R->tty_fd = R->Xfd = -1; 388 R->cmd_fd = R->tty_fd = R->Xfd = -1;
396 h->PrivateModes = h->SavedModes = PrivMode_Default; 389 R->PrivateModes = R->SavedModes = PrivMode_Default;
397 R->TermWin.focus = 1; 390 R->TermWin.focus = 1;
398 R->TermWin.ncol = 80; 391 R->TermWin.ncol = 80;
399 R->TermWin.nrow = 24; 392 R->TermWin.nrow = 24;
400 R->TermWin.int_bwidth = INTERNALBORDERWIDTH; 393 R->TermWin.int_bwidth = INTERNALBORDERWIDTH;
401 R->TermWin.ext_bwidth = EXTERNALBORDERWIDTH; 394 R->TermWin.ext_bwidth = EXTERNALBORDERWIDTH;
406 R->selection_style = NEW_SELECT; 399 R->selection_style = NEW_SELECT;
407#else 400#else
408 R->selection_style = OLD_SELECT; 401 R->selection_style = OLD_SELECT;
409#endif 402#endif
410#ifndef NO_BRIGHTCOLOR 403#ifndef NO_BRIGHTCOLOR
411 h->colorfgbg = DEFAULT_RSTYLE; 404 R->colorfgbg = DEFAULT_RSTYLE;
412#endif 405#endif
413#if defined (HOTKEY_CTRL) || defined (HOTKEY_META) 406#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)
414 h->ks_bigfont = XK_greater; 407 R->ks_bigfont = XK_greater;
415 h->ks_smallfont = XK_less; 408 R->ks_smallfont = XK_less;
416#endif 409#endif
417#ifdef GREEK_SUPPORT 410#ifdef GREEK_SUPPORT
418 h->ks_greekmodeswith = GREEK_KEYBOARD_MODESWITCH; 411 R->ks_greekmodeswith = GREEK_KEYBOARD_MODESWITCH;
419#endif 412#endif
420 h->refresh_limit = 1; 413 R->refresh_limit = 1;
421 h->refresh_type = SLOW_REFRESH; 414 R->refresh_type = SLOW_REFRESH;
422 h->prev_nrow = h->prev_ncol = 0; 415 R->prev_nrow = R->prev_ncol = 0;
423#ifdef MULTICHAR_SET 416#ifdef MULTICHAR_SET
424# ifdef MULTICHAR_ENCODING 417# ifdef MULTICHAR_ENCODING
425 R->encoding_method = MULTICHAR_ENCODING; 418 R->encoding_method = MULTICHAR_ENCODING;
426# endif 419# endif
427 h->multichar_decode = rxvt_euc2jis; 420 R->multichar_decode = rxvt_euc2jis;
428#endif 421#endif
429 h->oldcursor.row = h->oldcursor.col = -1; 422 R->oldcursor.row = R->oldcursor.col = -1;
430#ifdef XPM_BACKGROUND 423#ifdef XPM_BACKGROUND
431/* h->bgPixmap.w = h->bgPixmap.h = 0; */ 424/* R->bgPixmap.w = R->bgPixmap.h = 0; */
432 h->bgPixmap.x = h->bgPixmap.y = 50; 425 R->bgPixmap.x = R->bgPixmap.y = 50;
433 h->bgPixmap.pixmap = None; 426 R->bgPixmap.pixmap = None;
434#endif 427#endif
435 h->last_bot = h->last_state = -1; 428 R->last_bot = R->last_state = -1;
436#ifdef MENUBAR 429#ifdef MENUBAR
437 h->menu_readonly = 1; 430 R->menu_readonly = 1;
438# if !(MENUBAR_MAX > 1) 431# if !(MENUBAR_MAX > 1)
439 h->CurrentBar = &(h->BarList); 432 R->CurrentBar = &(R->BarList);
440# endif /* (MENUBAR_MAX > 1) */ 433# endif /* (MENUBAR_MAX > 1) */
441#endif 434#endif
442 return 0; 435 return 0;
443} 436}
444 437
449 int i; 442 int i;
450#ifdef TTY_GID_SUPPORT 443#ifdef TTY_GID_SUPPORT
451 struct group *gr = getgrnam("tty"); 444 struct group *gr = getgrnam("tty");
452 445
453 if (gr) { /* change group ownership of tty to "tty" */ 446 if (gr) { /* change group ownership of tty to "tty" */
454 R->h->ttymode = S_IRUSR | S_IWUSR | S_IWGRP; 447 R->ttymode = S_IRUSR | S_IWUSR | S_IWGRP;
455 R->h->ttygid = gr->gr_gid; 448 R->ttygid = gr->gr_gid;
456 } else 449 } else
457#endif /* TTY_GID_SUPPORT */ 450#endif /* TTY_GID_SUPPORT */
458 { 451 {
459 R->h->ttymode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 452 R->ttymode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
460 R->h->ttygid = getgid(); 453 R->ttygid = getgid();
461 } 454 }
462#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 455#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
463 R->h->locale = setlocale(LC_CTYPE, ""); 456 R->locale = setlocale(LC_CTYPE, "");
464#endif 457#endif
465 458
466/* get number of available file descriptors */ 459/* get number of available file descriptors */
467#if defined(_POSIX_VERSION) || ! defined(__svr4__) 460#if defined(_POSIX_VERSION) || ! defined(__svr4__)
468 R->num_fds = (int)sysconf(_SC_OPEN_MAX); 461 R->num_fds = (int)sysconf(_SC_OPEN_MAX);
521 cmd_argv[i] = (const char *)argv[i + r_argc + 1]; 514 cmd_argv[i] = (const char *)argv[i + r_argc + 1];
522 cmd_argv[i] = NULL; 515 cmd_argv[i] = NULL;
523 } 516 }
524 517
525/* clear all resources */ 518/* clear all resources */
526 rs = R->h->rs; 519 rs = R->rs;
527 for (i = 0; i < NUM_RESOURCES;) 520 for (i = 0; i < NUM_RESOURCES;)
528 rs[i++] = NULL; 521 rs[i++] = NULL;
529 522
530 rs[Rs_name] = rxvt_r_basename(argv[0]); 523 rs[Rs_name] = rxvt_r_basename(argv[0]);
531/* 524/*
582 R->TermWin.lineSpace = min(i, 100); /* arbitrary limit */ 575 R->TermWin.lineSpace = min(i, 100); /* arbitrary limit */
583#endif 576#endif
584 577
585#ifdef POINTER_BLANK 578#ifdef POINTER_BLANK
586 if (rs[Rs_pointerBlankDelay] && (i = atoi(rs[Rs_pointerBlankDelay])) >= 0) 579 if (rs[Rs_pointerBlankDelay] && (i = atoi(rs[Rs_pointerBlankDelay])) >= 0)
587 R->h->pointerBlankDelay = i; 580 R->pointerBlankDelay = i;
588 else 581 else
589 R->h->pointerBlankDelay = 2; 582 R->pointerBlankDelay = 2;
590#endif 583#endif
591 584
592/* no point having a scrollbar without having any scrollback! */ 585/* no point having a scrollbar without having any scrollback! */
593 if (!R->TermWin.saveLines) 586 if (!R->TermWin.saveLines)
594 R->Options &= ~Opt_scrollBar; 587 R->Options &= ~Opt_scrollBar;
610 } 603 }
611#endif 604#endif
612#ifndef NO_BACKSPACE_KEY 605#ifndef NO_BACKSPACE_KEY
613 if (!rs[Rs_backspace_key]) 606 if (!rs[Rs_backspace_key])
614# ifdef DEFAULT_BACKSPACE 607# ifdef DEFAULT_BACKSPACE
615 R->h->key_backspace = DEFAULT_BACKSPACE; 608 R->key_backspace = DEFAULT_BACKSPACE;
616# else 609# else
617 R->h->key_backspace = "DEC"; /* can toggle between \010 or \177 */ 610 R->key_backspace = "DEC"; /* can toggle between \010 or \177 */
618# endif 611# endif
619 else { 612 else {
620 val = STRDUP(rs[Rs_backspace_key]); 613 val = STRDUP(rs[Rs_backspace_key]);
621 rxvt_Str_trim(val); 614 rxvt_Str_trim(val);
622 rxvt_Str_escaped(val); 615 rxvt_Str_escaped(val);
623 R->h->key_backspace = val; 616 R->key_backspace = val;
624 } 617 }
625#endif 618#endif
626#ifndef NO_DELETE_KEY 619#ifndef NO_DELETE_KEY
627 if (!rs[Rs_delete_key]) 620 if (!rs[Rs_delete_key])
628# ifdef DEFAULT_DELETE 621# ifdef DEFAULT_DELETE
629 R->h->key_delete = DEFAULT_DELETE; 622 R->key_delete = DEFAULT_DELETE;
630# else 623# else
631 R->h->key_delete = "\033[3~"; 624 R->key_delete = "\033[3~";
632# endif 625# endif
633 else { 626 else {
634 val = STRDUP(rs[Rs_delete_key]); 627 val = STRDUP(rs[Rs_delete_key]);
635 rxvt_Str_trim(val); 628 rxvt_Str_trim(val);
636 rxvt_Str_escaped(val); 629 rxvt_Str_escaped(val);
637 R->h->key_delete = val; 630 R->key_delete = val;
638 } 631 }
639#endif 632#endif
640 if (rs[Rs_answerbackstring]) { 633 if (rs[Rs_answerbackstring]) {
641 rxvt_Str_trim((char *)rs[Rs_answerbackstring]); 634 rxvt_Str_trim((char *)rs[Rs_answerbackstring]);
642 rxvt_Str_escaped((char *)rs[Rs_answerbackstring]); 635 rxvt_Str_escaped((char *)rs[Rs_answerbackstring]);
718 * server is beyond a slow link or overloaded at client startup. Of 711 * server is beyond a slow link or overloaded at client startup. Of
719 * course that only helps the shell's child processes, not us. 712 * course that only helps the shell's child processes, not us.
720 * 713 *
721 * Giving out the display_name also affords a potential security hole 714 * Giving out the display_name also affords a potential security hole
722 */ 715 */
723 val = rxvt_network_display(R->h->rs[Rs_display_name]); 716 val = rxvt_network_display(R->rs[Rs_display_name]);
724 R->h->rs[Rs_display_name] = (const char *)val; 717 R->rs[Rs_display_name] = (const char *)val;
725 if (val == NULL) 718 if (val == NULL)
726#endif /* DISPLAY_IS_IP */ 719#endif /* DISPLAY_IS_IP */
727 val = XDisplayString(R->Xdisplay); 720 val = XDisplayString(R->Xdisplay);
728 if (R->h->rs[Rs_display_name] == NULL) 721 if (R->rs[Rs_display_name] == NULL)
729 R->h->rs[Rs_display_name] = val; /* use broken `:0' value */ 722 R->rs[Rs_display_name] = val; /* use broken `:0' value */
730 723
731 i = STRLEN(val); 724 i = STRLEN(val);
732 R->h->env_display = (char *)rxvt_malloc((i + 9) * sizeof(char)); 725 R->env_display = (char *)rxvt_malloc((i + 9) * sizeof(char));
733 726
734 sprintf(R->h->env_display, "DISPLAY=%s", val); 727 sprintf(R->env_display, "DISPLAY=%s", val);
735 728
736 /* avoiding the math library: 729 /* avoiding the math library:
737 * i = (int)(ceil(log10((unsigned int)R->TermWin.parent[0]))) */ 730 * i = (int)(ceil(log10((unsigned int)R->TermWin.parent[0]))) */
738 for (i = 0, u = (unsigned int)R->TermWin.parent[0]; u; u /= 10, i++) ; 731 for (i = 0, u = (unsigned int)R->TermWin.parent[0]; u; u /= 10, i++) ;
739 MAX_IT(i, 1); 732 MAX_IT(i, 1);
740 R->h->env_windowid = (char *)rxvt_malloc((i + 10) * sizeof(char)); 733 R->env_windowid = (char *)rxvt_malloc((i + 10) * sizeof(char));
741 734
742 sprintf(R->h->env_windowid, "WINDOWID=%u", 735 sprintf(R->env_windowid, "WINDOWID=%u",
743 (unsigned int)R->TermWin.parent[0]); 736 (unsigned int)R->TermWin.parent[0]);
744 737
745/* add entries to the environment: 738/* add entries to the environment:
746 * @ DISPLAY: in case we started with -display 739 * @ DISPLAY: in case we started with -display
747 * @ WINDOWID: X window id number of the window 740 * @ WINDOWID: X window id number of the window
748 * @ COLORTERM: terminal sub-name and also indicates its color 741 * @ COLORTERM: terminal sub-name and also indicates its color
749 * @ TERM: terminal name 742 * @ TERM: terminal name
750 * @ TERMINFO: path to terminfo directory 743 * @ TERMINFO: path to terminfo directory
751 */ 744 */
752 putenv(R->h->env_display); 745 putenv(R->env_display);
753 putenv(R->h->env_windowid); 746 putenv(R->env_windowid);
754#ifdef RXVT_TERMINFO 747#ifdef RXVT_TERMINFO
755 putenv("TERMINFO=" RXVT_TERMINFO); 748 putenv("TERMINFO=" RXVT_TERMINFO);
756#endif 749#endif
757 if (XDEPTH <= 2) 750 if (XDEPTH <= 2)
758 putenv("COLORTERM=" COLORTERMENV "-mono"); 751 putenv("COLORTERM=" COLORTERMENV "-mono");
759 else 752 else
760 putenv("COLORTERM=" COLORTERMENVFULL); 753 putenv("COLORTERM=" COLORTERMENVFULL);
761 if (R->h->rs[Rs_term_name] != NULL) { 754 if (R->rs[Rs_term_name] != NULL) {
762 R->h->env_term = (char *)rxvt_malloc((STRLEN(R->h->rs[Rs_term_name]) + 6) * sizeof(char)); 755 R->env_term = (char *)rxvt_malloc((STRLEN(R->rs[Rs_term_name]) + 6) * sizeof(char));
763 sprintf(R->h->env_term, "TERM=%s", R->h->rs[Rs_term_name]); 756 sprintf(R->env_term, "TERM=%s", R->rs[Rs_term_name]);
764 putenv(R->h->env_term); 757 putenv(R->env_term);
765 } else 758 } else
766 putenv("TERM=" TERMENV); 759 putenv("TERM=" TERMENV);
767 760
768#ifdef HAVE_UNSETENV 761#ifdef HAVE_UNSETENV
769/* avoid passing old settings and confusing term size */ 762/* avoid passing old settings and confusing term size */
781/* EXTPROTO */ 774/* EXTPROTO */
782void 775void
783rxvt_init_xlocale(pR) 776rxvt_init_xlocale(pR)
784{ 777{
785#ifdef USE_XIM 778#ifdef USE_XIM
786 if (R->h->locale == NULL) 779 if (R->locale == NULL)
787 rxvt_print_error("Setting locale failed."); 780 rxvt_print_error("Setting locale failed.");
788 else { 781 else {
789 Atom wmlocale; 782 Atom wmlocale;
790 783
791 wmlocale = XInternAtom(R->Xdisplay, "WM_LOCALE_NAME", False); 784 wmlocale = XInternAtom(R->Xdisplay, "WM_LOCALE_NAME", False);
792 XChangeProperty(R->Xdisplay, R->TermWin.parent[0], wmlocale, 785 XChangeProperty(R->Xdisplay, R->TermWin.parent[0], wmlocale,
793 XA_STRING, 8, PropModeReplace, 786 XA_STRING, 8, PropModeReplace,
794 (unsigned char *)R->h->locale, STRLEN(R->h->locale)); 787 (unsigned char *)R->locale, STRLEN(R->locale));
795 788
796 if (XSupportsLocale() != True) { 789 if (XSupportsLocale() != True) {
797 rxvt_print_error("The locale is not supported by Xlib"); 790 rxvt_print_error("The locale is not supported by Xlib");
798 return; 791 return;
799 } 792 }
801 794
802 /* see if we can connect yet */ 795 /* see if we can connect yet */
803 rxvt_IMInstantiateCallback(R->Xdisplay, NULL, NULL); 796 rxvt_IMInstantiateCallback(R->Xdisplay, NULL, NULL);
804 797
805 /* To avoid Segmentation Fault in C locale: Solaris only? */ 798 /* To avoid Segmentation Fault in C locale: Solaris only? */
806 if (STRCMP(R->h->locale, "C")) 799 if (STRCMP(R->locale, "C"))
807 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, 800 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL,
808 rxvt_IMInstantiateCallback, NULL); 801 rxvt_IMInstantiateCallback, NULL);
809 } 802 }
810#endif 803#endif
811} 804}
820 * This should be called after the X server connection is established. 813 * This should be called after the X server connection is established.
821 */ 814 */
822 int i; 815 int i;
823 816
824 for (i = 0; i < NUM_XA; i++) 817 for (i = 0; i < NUM_XA; i++)
825 R->h->xa[i] = XInternAtom(R->Xdisplay, xa_names[i], False); 818 R->xa[i] = XInternAtom(R->Xdisplay, xa_names[i], False);
826 819
827/* Enable delete window protocol */ 820/* Enable delete window protocol */
828 XSetWMProtocols(R->Xdisplay, R->TermWin.parent[0], 821 XSetWMProtocols(R->Xdisplay, R->TermWin.parent[0],
829 &(R->h->xa[XA_WMDELETEWINDOW]), 1); 822 &(R->xa[XA_WMDELETEWINDOW]), 1);
830 823
831#ifdef USING_W11LIB 824#ifdef USING_W11LIB
832/* enable W11 callbacks */ 825/* enable W11 callbacks */
833 W11AddEventHandler(R->Xdisplay, rxvt_W11_process_x_event); 826 W11AddEventHandler(R->Xdisplay, rxvt_W11_process_x_event);
834#endif 827#endif
835 828
836#ifdef META8_OPTION 829#ifdef META8_OPTION
837 R->h->meta_char = (R->Options & Opt_meta8 ? 0x80 : C0_ESC); 830 R->meta_char = (R->Options & Opt_meta8 ? 0x80 : C0_ESC);
838#endif 831#endif
839 rxvt_get_ourmods(aR); 832 rxvt_get_ourmods(aR);
840 if (!(R->Options & Opt_scrollTtyOutput)) 833 if (!(R->Options & Opt_scrollTtyOutput))
841 R->h->PrivateModes |= PrivMode_TtyOutputInh; 834 R->PrivateModes |= PrivMode_TtyOutputInh;
842 if (R->Options & Opt_scrollTtyKeypress) 835 if (R->Options & Opt_scrollTtyKeypress)
843 R->h->PrivateModes |= PrivMode_Keypress; 836 R->PrivateModes |= PrivMode_Keypress;
844 if (!(R->Options & Opt_jumpScroll)) 837 if (!(R->Options & Opt_jumpScroll))
845 R->h->PrivateModes |= PrivMode_smoothScroll; 838 R->PrivateModes |= PrivMode_smoothScroll;
846#ifndef NO_BACKSPACE_KEY 839#ifndef NO_BACKSPACE_KEY
847 if (STRCMP(R->h->key_backspace, "DEC") == 0) 840 if (STRCMP(R->key_backspace, "DEC") == 0)
848 R->h->PrivateModes |= PrivMode_HaveBackSpace; 841 R->PrivateModes |= PrivMode_HaveBackSpace;
849#endif 842#endif
850/* add value for scrollBar */ 843/* add value for scrollBar */
851 if (scrollbar_visible(R)) { 844 if (scrollbar_visible(R)) {
852 R->h->PrivateModes |= PrivMode_scrollBar; 845 R->PrivateModes |= PrivMode_scrollBar;
853 R->h->SavedModes |= PrivMode_scrollBar; 846 R->SavedModes |= PrivMode_scrollBar;
854 } 847 }
855 if (menubar_visible(R)) { 848 if (menubar_visible(R)) {
856 R->h->PrivateModes |= PrivMode_menuBar; 849 R->PrivateModes |= PrivMode_menuBar;
857 R->h->SavedModes |= PrivMode_menuBar; 850 R->SavedModes |= PrivMode_menuBar;
858 } 851 }
859#ifdef GREEK_SUPPORT 852#ifdef GREEK_SUPPORT
860 greek_init(); 853 greek_init();
861#endif 854#endif
862 855
863 R->Xfd = XConnectionNumber(R->Xdisplay); 856 R->Xfd = XConnectionNumber(R->Xdisplay);
864 857
865#ifdef CURSOR_BLINK 858#ifdef CURSOR_BLINK
866 if (R->Options & Opt_cursorBlink) 859 if (R->Options & Opt_cursorBlink)
867 (void)gettimeofday(&R->h->lastcursorchange, NULL); 860 (void)gettimeofday(&R->lastcursorchange, NULL);
868#endif 861#endif
869 862
870 if ((R->cmd_fd = rxvt_run_command(aR_ argv)) < 0) { 863 if ((R->cmd_fd = rxvt_run_command(aR_ argv)) < 0) {
871 rxvt_print_error("aborting"); 864 rxvt_print_error("aborting");
872 exit(EXIT_FAILURE); 865 exit(EXIT_FAILURE);
881 int i; 874 int i;
882 875
883 for (i = 0; i < (XDEPTH <= 2 ? 2 : NRS_COLORS); i++) { 876 for (i = 0; i < (XDEPTH <= 2 ? 2 : NRS_COLORS); i++) {
884 rxvt_color xcol; 877 rxvt_color xcol;
885 878
886 if (!R->h->rs[Rs_color + i]) 879 if (!R->rs[Rs_color + i])
887 continue; 880 continue;
888 881
889 if (!rxvt_rXParseAllocColor(aR_ &xcol, R->h->rs[Rs_color + i])) { 882 if (!rxvt_rXParseAllocColor(aR_ &xcol, R->rs[Rs_color + i])) {
890#ifndef XTERM_REVERSE_VIDEO 883#ifndef XTERM_REVERSE_VIDEO
891 if (i < 2 && (R->Options & Opt_reverseVideo)) { 884 if (i < 2 && (R->Options & Opt_reverseVideo)) {
892 R->h->rs[Rs_color + i] = def_colorName[!i]; 885 R->rs[Rs_color + i] = def_colorName[!i];
893 } else 886 } else
894#endif 887#endif
895 R->h->rs[Rs_color + i] = def_colorName[i]; 888 R->rs[Rs_color + i] = def_colorName[i];
896 if (!R->h->rs[Rs_color + i]) 889 if (!R->rs[Rs_color + i])
897 continue; 890 continue;
898 if (!rxvt_rXParseAllocColor(aR_ &xcol, R->h->rs[Rs_color + i])) { 891 if (!rxvt_rXParseAllocColor(aR_ &xcol, R->rs[Rs_color + i])) {
899 switch (i) { 892 switch (i) {
900 case Color_fg: 893 case Color_fg:
901 case Color_bg: 894 case Color_bg:
902 /* fatal: need bg/fg color */ 895 /* fatal: need bg/fg color */
903 rxvt_print_error("aborting"); 896 rxvt_print_error("aborting");
917 break; 910 break;
918 } 911 }
919 } 912 }
920 } 913 }
921 R->PixColors[i] = xcol; 914 R->PixColors[i] = xcol;
922 SET_PIXCOLOR(R->h, i); 915 SET_PIXCOLOR(R, i);
923 } 916 }
924 917
925 if (XDEPTH <= 2 || !R->h->rs[Rs_color + Color_pointer]) 918 if (XDEPTH <= 2 || !R->rs[Rs_color + Color_pointer])
926 R->PixColors[Color_pointer] = R->PixColors[Color_fg]; 919 R->PixColors[Color_pointer] = R->PixColors[Color_fg];
927 if (XDEPTH <= 2 || !R->h->rs[Rs_color + Color_border]) 920 if (XDEPTH <= 2 || !R->rs[Rs_color + Color_border])
928 R->PixColors[Color_border] = R->PixColors[Color_fg]; 921 R->PixColors[Color_border] = R->PixColors[Color_fg];
929 922
930/* 923/*
931 * get scrollBar/menuBar shadow colors 924 * get scrollBar/menuBar shadow colors
932 * 925 *
979/* color aliases, fg/bg bright-bold */ 972/* color aliases, fg/bg bright-bold */
980/* INTPROTO */ 973/* INTPROTO */
981void 974void
982rxvt_color_aliases(pR_ int idx) 975rxvt_color_aliases(pR_ int idx)
983{ 976{
984 if (R->h->rs[Rs_color + idx] && isdigit(*(R->h->rs[Rs_color + idx]))) { 977 if (R->rs[Rs_color + idx] && isdigit(*(R->rs[Rs_color + idx]))) {
985 int i = atoi(R->h->rs[Rs_color + idx]); 978 int i = atoi(R->rs[Rs_color + idx]);
986 979
987 if (i >= 8 && i <= 15) { /* bright colors */ 980 if (i >= 8 && i <= 15) { /* bright colors */
988 i -= 8; 981 i -= 8;
989#ifndef NO_BRIGHTCOLOR 982#ifndef NO_BRIGHTCOLOR
990 R->h->rs[Rs_color + idx] = R->h->rs[Rs_color + minBrightCOLOR + i]; 983 R->rs[Rs_color + idx] = R->rs[Rs_color + minBrightCOLOR + i];
991 return; 984 return;
992#endif 985#endif
993 } 986 }
994 if (i >= 0 && i <= 7) /* normal colors */ 987 if (i >= 0 && i <= 7) /* normal colors */
995 R->h->rs[Rs_color + idx] = R->h->rs[Rs_color + minCOLOR + i]; 988 R->rs[Rs_color + idx] = R->rs[Rs_color + minCOLOR + i];
996 } 989 }
997} 990}
998 991
999/*----------------------------------------------------------------------*/ 992/*----------------------------------------------------------------------*/
1000/* 993/*
1012 KeyCode *kc; 1005 KeyCode *kc;
1013 const unsigned int modmasks[] = 1006 const unsigned int modmasks[] =
1014 { Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; 1007 { Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask };
1015 1008
1016 requestedmeta = realmeta = realalt = 0; 1009 requestedmeta = realmeta = realalt = 0;
1017 rsmod = R->h->rs[Rs_modifier]; 1010 rsmod = R->rs[Rs_modifier];
1018 if (rsmod 1011 if (rsmod
1019 && STRCASECMP(rsmod, "mod1") >= 0 && STRCASECMP(rsmod, "mod5") <= 0) 1012 && STRCASECMP(rsmod, "mod1") >= 0 && STRCASECMP(rsmod, "mod5") <= 0)
1020 requestedmeta = rsmod[3] - '0'; 1013 requestedmeta = rsmod[3] - '0';
1021 1014
1022 map = XGetModifierMapping(R->Xdisplay); 1015 map = XGetModifierMapping(R->Xdisplay);
1026 for (j = map->max_keypermod; j--; k++) { 1019 for (j = map->max_keypermod; j--; k++) {
1027 if (kc[k] == 0) 1020 if (kc[k] == 0)
1028 break; 1021 break;
1029 switch (XKeycodeToKeysym(R->Xdisplay, kc[k], 0)) { 1022 switch (XKeycodeToKeysym(R->Xdisplay, kc[k], 0)) {
1030 case XK_Num_Lock: 1023 case XK_Num_Lock:
1031 R->h->ModNumLockMask = modmasks[i - 1]; 1024 R->ModNumLockMask = modmasks[i - 1];
1032 /* FALLTHROUGH */ 1025 /* FALLTHROUGH */
1033 default: 1026 default:
1034 continue; /* for(;;) */ 1027 continue; /* for(;;) */
1035 case XK_Meta_L: 1028 case XK_Meta_L:
1036 case XK_Meta_R: 1029 case XK_Meta_R:
1058 XFreeModifiermap(map); 1051 XFreeModifiermap(map);
1059 i = (requestedmeta ? requestedmeta 1052 i = (requestedmeta ? requestedmeta
1060 : (realmeta ? realmeta 1053 : (realmeta ? realmeta
1061 : (realalt ? realalt : 0))); 1054 : (realalt ? realalt : 0)));
1062 if (i) 1055 if (i)
1063 R->h->ModMetaMask = modmasks[i - 1]; 1056 R->ModMetaMask = modmasks[i - 1];
1064} 1057}
1065 1058
1066/*----------------------------------------------------------------------*/ 1059/*----------------------------------------------------------------------*/
1067/* rxvt_Create_Windows() - Open and map the window */ 1060/* rxvt_Create_Windows() - Open and map the window */
1068/* EXTPROTO */ 1061/* EXTPROTO */
1111/* grab colors before netscape does */ 1104/* grab colors before netscape does */
1112 rxvt_Get_Colours(aR); 1105 rxvt_Get_Colours(aR);
1113 1106
1114 rxvt_change_font(aR_ 1, NULL); 1107 rxvt_change_font(aR_ 1, NULL);
1115 rxvt_window_calc(aR_ 0, 0); 1108 rxvt_window_calc(aR_ 0, 0);
1116 R->h->old_width = R->szHint.width; 1109 R->old_width = R->szHint.width;
1117 R->h->old_height = R->szHint.height; 1110 R->old_height = R->szHint.height;
1118 1111
1119/* parent window - reverse video so we can see placement errors 1112/* parent window - reverse video so we can see placement errors
1120 * sub-window placement & size in rxvt_resize_subwindows() 1113 * sub-window placement & size in rxvt_resize_subwindows()
1121 */ 1114 */
1122 1115
1139 R->szHint.height, 1132 R->szHint.height,
1140 R->TermWin.ext_bwidth, 1133 R->TermWin.ext_bwidth,
1141 R->PixColors[Color_border], 1134 R->PixColors[Color_border],
1142 R->PixColors[Color_fg]); 1135 R->PixColors[Color_fg]);
1143#endif 1136#endif
1144 rxvt_xterm_seq(aR_ XTerm_title, R->h->rs[Rs_title], CHAR_ST); 1137 rxvt_xterm_seq(aR_ XTerm_title, R->rs[Rs_title], CHAR_ST);
1145 rxvt_xterm_seq(aR_ XTerm_iconName, R->h->rs[Rs_iconName], CHAR_ST); 1138 rxvt_xterm_seq(aR_ XTerm_iconName, R->rs[Rs_iconName], CHAR_ST);
1146 1139
1147 classHint.res_name = (char *)R->h->rs[Rs_name]; 1140 classHint.res_name = (char *)R->rs[Rs_name];
1148 classHint.res_class = (char *)APL_CLASS; 1141 classHint.res_class = (char *)APL_CLASS;
1149 1142
1150 wmHint.flags = (InputHint | StateHint | WindowGroupHint); 1143 wmHint.flags = (InputHint | StateHint | WindowGroupHint);
1151 wmHint.input = True; 1144 wmHint.input = True;
1152 wmHint.initial_state = (R->Options & Opt_iconic ? IconicState 1145 wmHint.initial_state = (R->Options & Opt_iconic ? IconicState
1166/* vt cursor: Black-on-White is standard, but this is more popular */ 1159/* vt cursor: Black-on-White is standard, but this is more popular */
1167 R->TermWin_cursor = XCreateFontCursor(R->Xdisplay, XC_xterm); 1160 R->TermWin_cursor = XCreateFontCursor(R->Xdisplay, XC_xterm);
1168 1161
1169#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 1162#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
1170/* cursor (menuBar/scrollBar): Black-on-White */ 1163/* cursor (menuBar/scrollBar): Black-on-White */
1171 R->h->pointer_leftptr = XCreateFontCursor(R->Xdisplay, XC_left_ptr); 1164 R->pointer_leftptr = XCreateFontCursor(R->Xdisplay, XC_left_ptr);
1172#endif 1165#endif
1173 1166
1174#ifdef POINTER_BLANK 1167#ifdef POINTER_BLANK
1175 R->h->pointer_blank = XCreateGlyphCursor(R->Xdisplay, R->TermWin.font->fid, 1168 R->pointer_blank = XCreateGlyphCursor(R->Xdisplay, R->TermWin.font->fid,
1176 R->TermWin.font->fid, ' ', ' ', 1169 R->TermWin.font->fid, ' ', ' ',
1177 &blackcolour, &blackcolour); 1170 &blackcolour, &blackcolour);
1178#endif 1171#endif
1179 1172
1180/* the vt window */ 1173/* the vt window */
1181 R->TermWin.vt = XCreateSimpleWindow(R->Xdisplay, R->TermWin.parent[0], 1174 R->TermWin.vt = XCreateSimpleWindow(R->Xdisplay, R->TermWin.parent[0],
1182 R->h->window_vt_x, R->h->window_vt_y, 1175 R->window_vt_x, R->window_vt_y,
1183 TermWin_TotalWidth(), 1176 TermWin_TotalWidth(),
1184 TermWin_TotalHeight(), 1177 TermWin_TotalHeight(),
1185 0, 1178 0,
1186 R->PixColors[Color_fg], 1179 R->PixColors[Color_fg],
1187 R->PixColors[Color_bg]); 1180 R->PixColors[Color_bg]);
1200 XSelectInput(R->Xdisplay, R->TermWin.vt, vt_emask); 1193 XSelectInput(R->Xdisplay, R->TermWin.vt, vt_emask);
1201 1194
1202#if defined(MENUBAR) && (MENUBAR_MAX > 1) 1195#if defined(MENUBAR) && (MENUBAR_MAX > 1)
1203 if (menuBar_height()) { 1196 if (menuBar_height()) {
1204 R->menuBar.win = XCreateSimpleWindow(R->Xdisplay, R->TermWin.parent[0], 1197 R->menuBar.win = XCreateSimpleWindow(R->Xdisplay, R->TermWin.parent[0],
1205 R->h->window_vt_x, 0, 1198 R->window_vt_x, 0,
1206 TermWin_TotalWidth(), 1199 TermWin_TotalWidth(),
1207 menuBar_TotalHeight(), 1200 menuBar_TotalHeight(),
1208 0, 1201 0,
1209 R->PixColors[Color_fg], 1202 R->PixColors[Color_fg],
1210 R->PixColors[Color_scroll]); 1203 R->PixColors[Color_scroll]);
1211#ifdef DEBUG_X 1204#ifdef DEBUG_X
1212 XStoreName(R->Xdisplay, R->menuBar.win, "menubar"); 1205 XStoreName(R->Xdisplay, R->menuBar.win, "menubar");
1213#endif 1206#endif
1214 XDefineCursor(R->Xdisplay, R->menuBar.win, R->h->pointer_leftptr); 1207 XDefineCursor(R->Xdisplay, R->menuBar.win, R->pointer_leftptr);
1215 XSelectInput(R->Xdisplay, R->menuBar.win, 1208 XSelectInput(R->Xdisplay, R->menuBar.win,
1216 (ExposureMask | ButtonPressMask | ButtonReleaseMask 1209 (ExposureMask | ButtonPressMask | ButtonReleaseMask
1217 | Button1MotionMask)); 1210 | Button1MotionMask));
1218 } 1211 }
1219#endif 1212#endif
1220#ifdef XPM_BACKGROUND 1213#ifdef XPM_BACKGROUND
1221 if (R->h->rs[Rs_backgroundPixmap] != NULL 1214 if (R->rs[Rs_backgroundPixmap] != NULL
1222 && !(R->Options & Opt_transparent)) { 1215 && !(R->Options & Opt_transparent)) {
1223 const char *p = R->h->rs[Rs_backgroundPixmap]; 1216 const char *p = R->rs[Rs_backgroundPixmap];
1224 1217
1225 if ((p = STRCHR(p, ';')) != NULL) { 1218 if ((p = STRCHR(p, ';')) != NULL) {
1226 p++; 1219 p++;
1227 rxvt_scale_pixmap(aR_ p); 1220 rxvt_scale_pixmap(aR_ p);
1228 } 1221 }
1229 rxvt_set_bgPixmap(aR_ R->h->rs[Rs_backgroundPixmap]); 1222 rxvt_set_bgPixmap(aR_ R->rs[Rs_backgroundPixmap]);
1230 rxvt_scr_touch(aR_ True); 1223 rxvt_scr_touch(aR_ True);
1231 } 1224 }
1232#endif 1225#endif
1233 1226
1234/* graphics context for the vt window */ 1227/* graphics context for the vt window */
1239 GCForeground | GCBackground 1232 GCForeground | GCBackground
1240 | GCGraphicsExposures, &gcvalue); 1233 | GCGraphicsExposures, &gcvalue);
1241 1234
1242#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 1235#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
1243 gcvalue.foreground = R->PixColors[Color_topShadow]; 1236 gcvalue.foreground = R->PixColors[Color_topShadow];
1244 R->h->topShadowGC = XCreateGC(R->Xdisplay, R->TermWin.vt, 1237 R->topShadowGC = XCreateGC(R->Xdisplay, R->TermWin.vt,
1245 GCForeground, &gcvalue); 1238 GCForeground, &gcvalue);
1246 gcvalue.foreground = R->PixColors[Color_bottomShadow]; 1239 gcvalue.foreground = R->PixColors[Color_bottomShadow];
1247 R->h->botShadowGC = XCreateGC(R->Xdisplay, R->TermWin.vt, 1240 R->botShadowGC = XCreateGC(R->Xdisplay, R->TermWin.vt,
1248 GCForeground, &gcvalue); 1241 GCForeground, &gcvalue);
1249 gcvalue.foreground = R->PixColors[(XDEPTH <= 2 ? Color_fg 1242 gcvalue.foreground = R->PixColors[(XDEPTH <= 2 ? Color_fg
1250 : Color_scroll)]; 1243 : Color_scroll)];
1251 R->h->scrollbarGC = XCreateGC(R->Xdisplay, R->TermWin.vt, 1244 R->scrollbarGC = XCreateGC(R->Xdisplay, R->TermWin.vt,
1252 GCForeground, &gcvalue); 1245 GCForeground, &gcvalue);
1253#endif 1246#endif
1254} 1247}
1255 1248
1256/*----------------------------------------------------------------------*/ 1249/*----------------------------------------------------------------------*/
1264rxvt_run_command(pR_ const char *const *argv) 1257rxvt_run_command(pR_ const char *const *argv)
1265{ 1258{
1266 int cfd, er; 1259 int cfd, er;
1267 1260
1268/* get master (pty) */ 1261/* get master (pty) */
1269 if ((cfd = rxvt_get_pty(&(R->tty_fd), &(R->h->ttydev))) < 0) { 1262 if ((cfd = rxvt_get_pty(&(R->tty_fd), &(R->ttydev))) < 0) {
1270 rxvt_print_error("can't open pseudo-tty"); 1263 rxvt_print_error("can't open pseudo-tty");
1271 return -1; 1264 return -1;
1272 } 1265 }
1273#ifdef FD_SETSIZE 1266#ifdef FD_SETSIZE
1274 if (R->Xfd > FD_SETSIZE || cfd > FD_SETSIZE) { 1267 if (R->Xfd > FD_SETSIZE || cfd > FD_SETSIZE) {
1282/* get slave (tty) */ 1275/* get slave (tty) */
1283 if (R->tty_fd < 0) { 1276 if (R->tty_fd < 0) {
1284#ifndef NO_SETOWNER_TTYDEV 1277#ifndef NO_SETOWNER_TTYDEV
1285 rxvt_privileged_ttydev(aR_ SAVE); 1278 rxvt_privileged_ttydev(aR_ SAVE);
1286#endif 1279#endif
1287 if ((R->tty_fd = rxvt_get_tty(R->h->ttydev)) < 0) { 1280 if ((R->tty_fd = rxvt_get_tty(R->ttydev)) < 0) {
1288 close(cfd); 1281 close(cfd);
1289 rxvt_print_error("can't open slave tty %s", R->h->ttydev); 1282 rxvt_print_error("can't open slave tty %s", R->ttydev);
1290 return -1; 1283 return -1;
1291 } 1284 }
1292 } 1285 }
1293#ifndef NO_BACKSPACE_KEY 1286#ifndef NO_BACKSPACE_KEY
1294 if (R->h->key_backspace[0] && !R->h->key_backspace[1]) 1287 if (R->key_backspace[0] && !R->key_backspace[1])
1295 er = R->h->key_backspace[0]; 1288 er = R->key_backspace[0];
1296 else if (STRCMP(R->h->key_backspace, "DEC") == 0) 1289 else if (STRCMP(R->key_backspace, "DEC") == 0)
1297 er = '\177'; /* the initial state anyway */ 1290 er = '\177'; /* the initial state anyway */
1298 else 1291 else
1299#endif 1292#endif
1300 er = -1; 1293 er = -1;
1301 rxvt_get_ttymode(&(R->h->tio), er); 1294 rxvt_get_ttymode(&(R->tio), er);
1302 1295
1303/* install exit handler for cleanup */ 1296/* install exit handler for cleanup */
1304#ifdef HAVE_ATEXIT 1297#ifdef HAVE_ATEXIT
1305 atexit(rxvt_clean_exit); 1298 atexit(rxvt_clean_exit);
1306#else 1299#else
1320/* need to trap SIGURG for SVR4 (Unixware) rlogin */ 1313/* need to trap SIGURG for SVR4 (Unixware) rlogin */
1321/* signal (SIGURG, SIG_DFL); */ 1314/* signal (SIGURG, SIG_DFL); */
1322 1315
1323#ifndef __QNX__ 1316#ifndef __QNX__
1324/* spin off the command interpreter */ 1317/* spin off the command interpreter */
1325 switch (R->h->cmd_pid = fork()) { 1318 switch (R->cmd_pid = fork()) {
1326 case -1: 1319 case -1:
1327 rxvt_print_error("can't fork"); 1320 rxvt_print_error("can't fork");
1328 return -1; 1321 return -1;
1329 case 0: 1322 case 0:
1330 close(cfd); /* only keep R->tty_fd and STDERR open */ 1323 close(cfd); /* only keep R->tty_fd and STDERR open */
1331 close(R->Xfd); 1324 close(R->Xfd);
1332 if (rxvt_control_tty(R->tty_fd, R->h->ttydev) < 0) 1325 if (rxvt_control_tty(R->tty_fd, R->ttydev) < 0)
1333 rxvt_print_error("could not obtain control of tty"); 1326 rxvt_print_error("could not obtain control of tty");
1334 else { 1327 else {
1335 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1328 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1336 dup2(R->tty_fd, STDIN_FILENO); 1329 dup2(R->tty_fd, STDIN_FILENO);
1337 dup2(R->tty_fd, STDOUT_FILENO); 1330 dup2(R->tty_fd, STDOUT_FILENO);
1391int 1384int
1392rxvt_run_child(pR_ const char *const *argv) 1385rxvt_run_child(pR_ const char *const *argv)
1393{ 1386{
1394 char *login; 1387 char *login;
1395 1388
1396 SET_TTYMODE(STDIN_FILENO, &(R->h->tio)); /* init terminal attributes */ 1389 SET_TTYMODE(STDIN_FILENO, &(R->tio)); /* init terminal attributes */
1397 1390
1398 if (R->Options & Opt_console) { /* be virtual console, fail silently */ 1391 if (R->Options & Opt_console) { /* be virtual console, fail silently */
1399#ifdef TIOCCONS 1392#ifdef TIOCCONS
1400 unsigned int on = 1; 1393 unsigned int on = 1;
1401 1394
1487 arg_a[0] = login; 1480 arg_a[0] = login;
1488 } 1481 }
1489 arg_v = arg_a; 1482 arg_v = arg_a;
1490 } 1483 }
1491 iov_a[0] = iov_a[1] = iov_a[2] = R->tty_fd; 1484 iov_a[0] = iov_a[1] = iov_a[2] = R->tty_fd;
1492 R->h->cmd_pid = qnx_spawn(0, 0, 0, -1, -1, 1485 R->cmd_pid = qnx_spawn(0, 0, 0, -1, -1,
1493 _SPAWN_SETSID | _SPAWN_TCSETPGRP, 1486 _SPAWN_SETSID | _SPAWN_TCSETPGRP,
1494 command, arg_v, environ, iov_a, 0); 1487 command, arg_v, environ, iov_a, 0);
1495 if (login) 1488 if (login)
1496 free(login); 1489 free(login);
1497 close(R->tty_fd); 1490 close(R->tty_fd);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines