… | |
… | |
14 | * - extensive modifications |
14 | * - extensive modifications |
15 | * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de> |
15 | * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de> |
16 | * |
16 | * |
17 | * This program is free software; you can redistribute it and/or modify |
17 | * This program is free software; you can redistribute it and/or modify |
18 | * it under the terms of the GNU General Public License as published by |
18 | * it under the terms of the GNU General Public License as published by |
19 | * the Free Software Foundation; either version 2 of the License, or |
19 | * the Free Software Foundation; either version 3 of the License, or |
20 | * (at your option) any later version. |
20 | * (at your option) any later version. |
21 | * |
21 | * |
22 | * This program is distributed in the hope that it will be useful, |
22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
38 | #include "init.h" |
38 | #include "init.h" |
39 | #include "keyboard.h" |
39 | #include "keyboard.h" |
40 | |
40 | |
41 | #include <limits> |
41 | #include <limits> |
42 | |
42 | |
43 | #include <csignal> |
43 | #include <signal.h> |
44 | |
44 | |
45 | #include <fcntl.h> |
45 | #include <fcntl.h> |
46 | |
46 | |
47 | #ifdef HAVE_XSETLOCALE |
47 | #ifdef HAVE_XSETLOCALE |
48 | # define X_LOCALE |
48 | # define X_LOCALE |
49 | # include <X11/Xlocale.h> |
49 | # include <X11/Xlocale.h> |
50 | #else |
50 | #else |
51 | # ifdef HAVE_SETLOCALE |
|
|
52 | # include <clocale> |
51 | # include <locale.h> |
53 | # endif |
|
|
54 | #endif |
52 | #endif |
55 | |
53 | |
56 | #ifdef HAVE_NL_LANGINFO |
54 | #ifdef HAVE_NL_LANGINFO |
57 | # include <langinfo.h> |
55 | # include <langinfo.h> |
|
|
56 | #endif |
|
|
57 | |
|
|
58 | #ifdef HAVE_STARTUP_NOTIFICATION |
|
|
59 | # define SN_API_NOT_YET_FROZEN |
|
|
60 | # include <libsn/sn-launchee.h> |
58 | #endif |
61 | #endif |
59 | |
62 | |
60 | #ifdef DISPLAY_IS_IP |
63 | #ifdef DISPLAY_IS_IP |
61 | /* On Solaris link with -lsocket and -lnsl */ |
64 | /* On Solaris link with -lsocket and -lnsl */ |
62 | #include <sys/types.h> |
65 | #include <sys/types.h> |
… | |
… | |
73 | #include <netinet/in.h> |
76 | #include <netinet/in.h> |
74 | #include <arpa/inet.h> |
77 | #include <arpa/inet.h> |
75 | #include <net/if.h> |
78 | #include <net/if.h> |
76 | #include <net/if_arp.h> |
79 | #include <net/if_arp.h> |
77 | |
80 | |
78 | static char * |
81 | static char * ecb_cold |
79 | rxvt_network_display (const char *display) |
82 | rxvt_network_display (const char *display) |
80 | { |
83 | { |
81 | char buffer[1024], *rval = NULL; |
84 | char buffer[1024], *rval = NULL; |
82 | struct ifconf ifc; |
85 | struct ifconf ifc; |
83 | struct ifreq *ifr; |
86 | struct ifreq *ifr; |
… | |
… | |
516 | #endif |
519 | #endif |
517 | COLOR_SCROLLBAR, |
520 | COLOR_SCROLLBAR, |
518 | #ifdef RXVT_SCROLLBAR |
521 | #ifdef RXVT_SCROLLBAR |
519 | COLOR_SCROLLTROUGH, |
522 | COLOR_SCROLLTROUGH, |
520 | #endif |
523 | #endif |
521 | #if ENABLE_TRANSPARENCY |
524 | #if BG_IMAGE_FROM_ROOT |
522 | NULL, |
525 | NULL, |
523 | #endif |
526 | #endif |
524 | #if OFF_FOCUS_FADING |
527 | #if OFF_FOCUS_FADING |
525 | "rgb:00/00/00", |
528 | "rgb:00/00/00", |
526 | #endif |
529 | #endif |
… | |
… | |
562 | |
565 | |
563 | /*----------------------------------------------------------------------*/ |
566 | /*----------------------------------------------------------------------*/ |
564 | const char ** |
567 | const char ** |
565 | rxvt_term::init_resources (int argc, const char *const *argv) |
568 | rxvt_term::init_resources (int argc, const char *const *argv) |
566 | { |
569 | { |
567 | int i, r_argc; |
570 | int i; |
568 | const char **cmd_argv, **r_argv; |
571 | const char **cmd_argv; |
569 | |
|
|
570 | /* |
|
|
571 | * Look for -e option. Find => split and make cmd_argv[] of command args |
|
|
572 | */ |
|
|
573 | for (r_argc = 0; r_argc < argc; r_argc++) |
|
|
574 | if (!strcmp (argv[r_argc], "-e")) |
|
|
575 | break; |
|
|
576 | |
|
|
577 | if (r_argc == argc) |
|
|
578 | cmd_argv = NULL; |
|
|
579 | else if (!argv[r_argc + 1]) |
|
|
580 | rxvt_fatal ("option '-e' requires an argument, aborting.\n"); |
|
|
581 | else |
|
|
582 | { |
|
|
583 | cmd_argv = (const char **)rxvt_malloc (sizeof (char *) * (argc - r_argc)); |
|
|
584 | |
|
|
585 | for (i = 0; i < argc - r_argc - 1; i++) |
|
|
586 | cmd_argv[i] = (const char *)argv[i + r_argc + 1]; |
|
|
587 | |
|
|
588 | cmd_argv[i] = NULL; |
|
|
589 | } |
|
|
590 | |
|
|
591 | r_argv = (const char **)rxvt_malloc (sizeof (char *) * (r_argc + 1)); |
|
|
592 | |
|
|
593 | for (i = 0; i < r_argc; i++) |
|
|
594 | r_argv[i] = (const char *)argv[i]; |
|
|
595 | |
|
|
596 | r_argv[i] = NULL; |
|
|
597 | |
572 | |
598 | rs[Rs_name] = rxvt_basename (argv[0]); |
573 | rs[Rs_name] = rxvt_basename (argv[0]); |
599 | |
574 | |
600 | /* |
575 | /* |
601 | * Open display, get options/resources and create the window |
576 | * Open display, get options/resources and create the window |
602 | */ |
577 | */ |
603 | |
578 | |
604 | if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) |
579 | if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) |
605 | rs[Rs_display_name] = ":0"; |
580 | rs[Rs_display_name] = ":0"; |
606 | |
581 | |
607 | get_options (r_argc, r_argv); |
582 | cmd_argv = get_options (argc, argv); |
608 | |
583 | |
609 | if (!(display = displays.get (rs[Rs_display_name]))) |
584 | if (!(display = displays.get (rs[Rs_display_name]))) |
610 | { |
|
|
611 | free (r_argv); |
|
|
612 | rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); |
585 | rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); |
613 | } |
|
|
614 | |
586 | |
615 | // using a local pointer decreases code size a lot |
587 | // using a local pointer decreases code size a lot |
616 | xa = display->xa; |
588 | xa = display->xa; |
617 | |
589 | |
618 | set (display); |
590 | set (display); |
619 | extract_resources (); |
591 | extract_resources (); |
620 | |
592 | |
621 | #if XFT |
593 | #if ENABLE_FRILLS |
622 | if (rs[Rs_depth]) |
594 | if (rs[Rs_visual]) |
623 | select_visual (strtol (rs[Rs_depth], 0, 0)); |
595 | select_visual (strtol (rs[Rs_visual], 0, 0)); |
|
|
596 | else if (rs[Rs_depth]) |
|
|
597 | select_depth (strtol (rs[Rs_depth], 0, 0)); |
624 | #endif |
598 | #endif |
625 | |
|
|
626 | free (r_argv); |
|
|
627 | |
599 | |
628 | for (int i = NUM_RESOURCES; i--; ) |
600 | for (int i = NUM_RESOURCES; i--; ) |
629 | if (rs [i] == resval_undef) |
601 | if (rs [i] == resval_undef) |
630 | rs [i] = 0; |
602 | rs [i] = 0; |
631 | |
603 | |
… | |
… | |
639 | { |
611 | { |
640 | rxvt_perl.init (this); |
612 | rxvt_perl.init (this); |
641 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
613 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
642 | } |
614 | } |
643 | #endif |
615 | #endif |
|
|
616 | |
|
|
617 | extract_keysym_resources (); |
644 | |
618 | |
645 | /* |
619 | /* |
646 | * set any defaults not already set |
620 | * set any defaults not already set |
647 | */ |
621 | */ |
648 | if (cmd_argv && cmd_argv[0]) |
622 | if (cmd_argv && cmd_argv[0]) |
… | |
… | |
683 | if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) |
657 | if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) |
684 | pointerBlankDelay = i; |
658 | pointerBlankDelay = i; |
685 | else |
659 | else |
686 | pointerBlankDelay = 2; |
660 | pointerBlankDelay = 2; |
687 | #endif |
661 | #endif |
|
|
662 | |
|
|
663 | if (rs[Rs_multiClickTime] && (i = atoi (rs[Rs_multiClickTime])) >= 0) |
|
|
664 | multiClickTime = i; |
|
|
665 | else |
|
|
666 | multiClickTime = 500; |
|
|
667 | |
|
|
668 | cursor_type = option (Opt_cursorUnderline) ? 1 : 0; |
688 | |
669 | |
689 | /* no point having a scrollbar without having any scrollback! */ |
670 | /* no point having a scrollbar without having any scrollback! */ |
690 | if (!saveLines) |
671 | if (!saveLines) |
691 | set_option (Opt_scrollBar, 0); |
672 | set_option (Opt_scrollBar, 0); |
692 | |
673 | |
… | |
… | |
757 | return cmd_argv; |
738 | return cmd_argv; |
758 | } |
739 | } |
759 | |
740 | |
760 | /*----------------------------------------------------------------------*/ |
741 | /*----------------------------------------------------------------------*/ |
761 | void |
742 | void |
762 | rxvt_term::init (int argc, const char *const *argv, stringvec *envv) |
743 | rxvt_term::init (stringvec *argv, stringvec *envv) |
763 | { |
744 | { |
|
|
745 | argv->push_back (0); |
|
|
746 | envv->push_back (0); |
|
|
747 | |
|
|
748 | this->argv = argv; |
764 | this->envv = envv; |
749 | this->envv = envv; |
765 | |
750 | |
|
|
751 | env = new char *[this->envv->size ()]; |
|
|
752 | for (int i = 0; i < this->envv->size (); i++) |
|
|
753 | env[i] = this->envv->at (i); |
|
|
754 | |
|
|
755 | init2 (argv->size () - 1, argv->begin ()); |
|
|
756 | } |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::init (int argc, const char *const *argv, const char *const *envv) |
|
|
760 | { |
|
|
761 | #if ENABLE_PERL |
|
|
762 | // perl might want to access the stringvecs later, so we need to copy them |
|
|
763 | stringvec *args = new stringvec; |
|
|
764 | for (int i = 0; i < argc; i++) |
|
|
765 | args->push_back (strdup (argv [i])); |
|
|
766 | |
|
|
767 | stringvec *envs = new stringvec; |
|
|
768 | for (const char *const *var = envv; *var; var++) |
|
|
769 | envs->push_back (strdup (*var)); |
|
|
770 | |
|
|
771 | init (args, envs); |
|
|
772 | #else |
|
|
773 | init2 (argc, argv); |
|
|
774 | #endif |
|
|
775 | } |
|
|
776 | |
|
|
777 | void |
|
|
778 | rxvt_term::init2 (int argc, const char *const *argv) |
|
|
779 | { |
766 | SET_R (this); |
780 | SET_R (this); |
767 | set_locale (""); |
781 | set_locale (""); |
768 | set_environ (envv); // a few things in X do not call setlocale :( |
782 | set_environ (env); // a few things in X do not call setlocale :( |
769 | |
783 | |
770 | init_vars (); |
784 | init_vars (); |
771 | |
785 | |
772 | const char **cmd_argv = init_resources (argc, argv); |
786 | const char **cmd_argv = init_resources (argc, argv); |
773 | |
787 | |
… | |
… | |
784 | if (chdir (path)) |
798 | if (chdir (path)) |
785 | rxvt_fatal ("unable to change into specified shell working directory, aborting.\n"); |
799 | rxvt_fatal ("unable to change into specified shell working directory, aborting.\n"); |
786 | } |
800 | } |
787 | |
801 | |
788 | if (option (Opt_scrollBar)) |
802 | if (option (Opt_scrollBar)) |
789 | scrollBar.state = STATE_IDLE; /* set existence for size calculations */ |
803 | scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */ |
790 | |
804 | |
791 | pty = ptytty::create (); |
805 | pty = ptytty::create (); |
792 | |
806 | |
793 | create_windows (argc, argv); |
807 | create_windows (argc, argv); |
794 | |
808 | |
… | |
… | |
800 | XSynchronize (dpy, True); |
814 | XSynchronize (dpy, True); |
801 | #endif |
815 | #endif |
802 | |
816 | |
803 | if (option (Opt_scrollBar)) |
817 | if (option (Opt_scrollBar)) |
804 | scrollBar.resize (); /* create and map scrollbar */ |
818 | scrollBar.resize (); /* create and map scrollbar */ |
|
|
819 | |
805 | #ifdef HAVE_BG_PIXMAP |
820 | #ifdef HAVE_BG_PIXMAP |
806 | { |
|
|
807 | bg_init (); |
821 | bg_init (); |
808 | |
|
|
809 | #ifdef ENABLE_TRANSPARENCY |
|
|
810 | if (option (Opt_transparent)) |
|
|
811 | { |
|
|
812 | bg_set_transparent (); |
|
|
813 | |
|
|
814 | if (rs [Rs_blurradius]) |
|
|
815 | bg_set_blur (rs [Rs_blurradius]); |
|
|
816 | |
|
|
817 | if (ISSET_PIXCOLOR (Color_tint)) |
|
|
818 | bg_set_tint (pix_colors_focused [Color_tint]); |
|
|
819 | |
|
|
820 | if (rs [Rs_shade]) |
|
|
821 | bg_set_shade (rs [Rs_shade]); |
|
|
822 | |
|
|
823 | bg_set_root_pixmap (); |
|
|
824 | XSelectInput (dpy, display->root, PropertyChangeMask); |
|
|
825 | rootwin_ev.start (display, display->root); |
|
|
826 | } |
|
|
827 | #endif |
|
|
828 | |
|
|
829 | #ifdef BG_IMAGE_FROM_FILE |
|
|
830 | if (rs[Rs_backgroundPixmap]) |
|
|
831 | { |
|
|
832 | if (bg_set_file (rs[Rs_backgroundPixmap])) |
|
|
833 | if (!bg_window_position_sensitive ()) |
|
|
834 | update_background (); |
|
|
835 | } |
|
|
836 | #endif |
|
|
837 | } |
|
|
838 | #endif |
822 | #endif |
839 | |
823 | |
840 | #if ENABLE_PERL |
824 | #if ENABLE_PERL |
841 | rootwin_ev.start (display, display->root); |
825 | rootwin_ev.start (display, display->root); |
842 | #endif |
826 | #endif |
843 | |
827 | |
844 | set_colorfgbg (); |
828 | init_done = 1; |
845 | |
829 | |
846 | init_command (cmd_argv); |
830 | init_command (cmd_argv); |
847 | |
|
|
848 | free (cmd_argv); |
|
|
849 | |
831 | |
850 | if (pty->pty >= 0) |
832 | if (pty->pty >= 0) |
851 | pty_ev.start (pty->pty, ev::READ); |
833 | pty_ev.start (pty->pty, ev::READ); |
852 | |
834 | |
853 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
835 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
… | |
… | |
860 | XChangeProperty (dpy, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], |
842 | XChangeProperty (dpy, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], |
861 | 32, PropModeReplace, (unsigned char *)&info, 2); |
843 | 32, PropModeReplace, (unsigned char *)&info, 2); |
862 | } |
844 | } |
863 | #endif |
845 | #endif |
864 | |
846 | |
|
|
847 | #if HAVE_STARTUP_NOTIFICATION |
|
|
848 | SnDisplay *snDisplay; |
|
|
849 | SnLauncheeContext *snContext; |
|
|
850 | |
|
|
851 | snDisplay = sn_display_new (dpy, NULL, NULL); |
|
|
852 | snContext = sn_launchee_context_new_from_environment (snDisplay, DefaultScreen (dpy)); |
|
|
853 | |
|
|
854 | /* Tell the window manager that this window is part of the startup context */ |
|
|
855 | if (snContext) |
|
|
856 | sn_launchee_context_setup_window (snContext, parent); |
|
|
857 | #endif |
|
|
858 | |
865 | XMapWindow (dpy, vt); |
859 | XMapWindow (dpy, vt); |
866 | XMapWindow (dpy, parent); |
860 | XMapWindow (dpy, parent); |
|
|
861 | |
|
|
862 | #if HAVE_STARTUP_NOTIFICATION |
|
|
863 | if (snContext) |
|
|
864 | { |
|
|
865 | /* Mark the startup process as complete */ |
|
|
866 | sn_launchee_context_complete (snContext); |
|
|
867 | |
|
|
868 | sn_launchee_context_unref (snContext); |
|
|
869 | } |
|
|
870 | |
|
|
871 | sn_display_unref (snDisplay); |
|
|
872 | #endif |
867 | |
873 | |
868 | refresh_check (); |
874 | refresh_check (); |
869 | } |
875 | } |
870 | |
876 | |
871 | /*----------------------------------------------------------------------*/ |
877 | /*----------------------------------------------------------------------*/ |
872 | void |
878 | void |
873 | rxvt_term::init_env () |
879 | rxvt_term::init_env () |
874 | { |
880 | { |
875 | char *val; |
881 | char *val; |
|
|
882 | char *env_display; |
|
|
883 | char *env_windowid; |
|
|
884 | char *env_colorfgbg; |
|
|
885 | char *env_term; |
876 | |
886 | |
877 | #ifdef DISPLAY_IS_IP |
887 | #ifdef DISPLAY_IS_IP |
878 | /* Fixup display_name for export over pty to any interested terminal |
888 | /* Fixup display_name for export over pty to any interested terminal |
879 | * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number |
889 | * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number |
880 | * (for the first non-loopback interface) that we get from |
890 | * (for the first non-loopback interface) that we get from |
… | |
… | |
897 | |
907 | |
898 | env_display = (char *)rxvt_malloc (strlen (val) + 9); |
908 | env_display = (char *)rxvt_malloc (strlen (val) + 9); |
899 | |
909 | |
900 | sprintf (env_display, "DISPLAY=%s", val); |
910 | sprintf (env_display, "DISPLAY=%s", val); |
901 | |
911 | |
|
|
912 | env_windowid = (char *)rxvt_malloc (21); |
902 | sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent); |
913 | sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent); |
903 | |
914 | |
904 | /* add entries to the environment: |
915 | /* add entries to the environment: |
905 | * @ DISPLAY: in case we started with -display |
916 | * @ DISPLAY: in case we started with -display |
906 | * @ WINDOWID: X window id number of the window |
917 | * @ WINDOWID: X window id number of the window |
… | |
… | |
910 | * @ COLORFGBG: fg;bg color codes |
921 | * @ COLORFGBG: fg;bg color codes |
911 | */ |
922 | */ |
912 | putenv (env_display); |
923 | putenv (env_display); |
913 | putenv (env_windowid); |
924 | putenv (env_windowid); |
914 | |
925 | |
915 | if (env_colorfgbg) |
926 | env_colorfgbg = get_colorfgbg (); |
916 | putenv (env_colorfgbg); |
927 | putenv (env_colorfgbg); |
917 | |
928 | |
918 | #ifdef RXVT_TERMINFO |
929 | #ifdef RXVT_TERMINFO |
919 | putenv ("TERMINFO=" RXVT_TERMINFO); |
930 | putenv ("TERMINFO=" RXVT_TERMINFO); |
920 | #endif |
931 | #endif |
921 | |
932 | |
… | |
… | |
940 | unsetenv ("TERMCAP"); /* terminfo should be okay */ |
951 | unsetenv ("TERMCAP"); /* terminfo should be okay */ |
941 | #endif /* HAVE_UNSETENV */ |
952 | #endif /* HAVE_UNSETENV */ |
942 | } |
953 | } |
943 | |
954 | |
944 | /*----------------------------------------------------------------------*/ |
955 | /*----------------------------------------------------------------------*/ |
945 | /* |
|
|
946 | * This is more or less stolen straight from XFree86 xterm. |
|
|
947 | * This should support all European type languages. |
|
|
948 | */ |
|
|
949 | void |
956 | void |
950 | rxvt_term::set_locale (const char *locale) |
957 | rxvt_term::set_locale (const char *locale) |
951 | { |
958 | { |
952 | set_environ (envv); |
959 | set_environ (env); |
953 | |
960 | |
954 | #if HAVE_XSETLOCALE || HAVE_SETLOCALE |
|
|
955 | free (this->locale); |
961 | free (this->locale); |
956 | this->locale = setlocale (LC_CTYPE, locale); |
962 | this->locale = setlocale (LC_CTYPE, locale); |
957 | |
963 | |
958 | if (!this->locale) |
964 | if (!this->locale) |
959 | { |
965 | { |
… | |
… | |
970 | |
976 | |
971 | |
977 | |
972 | this->locale = strdup (this->locale); |
978 | this->locale = strdup (this->locale); |
973 | SET_LOCALE (this->locale); |
979 | SET_LOCALE (this->locale); |
974 | mbstate.reset (); |
980 | mbstate.reset (); |
975 | #endif |
|
|
976 | |
981 | |
977 | #if HAVE_NL_LANGINFO |
982 | #if HAVE_NL_LANGINFO |
978 | char *codeset = strdup (nl_langinfo (CODESET)); |
983 | char *codeset = nl_langinfo (CODESET); |
979 | // /^UTF.?8/i |
984 | // /^UTF.?8/i |
980 | enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u') |
985 | enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u') |
981 | && (codeset[1] == 'T' || codeset[1] == 't') |
986 | && (codeset[1] == 'T' || codeset[1] == 't') |
982 | && (codeset[2] == 'F' || codeset[2] == 'f') |
987 | && (codeset[2] == 'F' || codeset[2] == 'f') |
983 | && (codeset[3] == '8' || codeset[4] == '8'); |
988 | && (codeset[3] == '8' || codeset[4] == '8'); |
984 | free (codeset); |
|
|
985 | #else |
989 | #else |
986 | enc_utf8 = 0; |
990 | enc_utf8 = 0; |
987 | #endif |
991 | #endif |
988 | } |
992 | } |
989 | |
993 | |
990 | void |
994 | void |
991 | rxvt_term::init_xlocale () |
995 | rxvt_term::init_xlocale () |
992 | { |
996 | { |
993 | set_environ (envv); |
997 | set_environ (env); |
994 | |
998 | |
995 | #ifdef USE_XIM |
999 | #if USE_XIM |
996 | if (!locale) |
1000 | if (!locale) |
997 | rxvt_warn ("setting locale failed, working without locale support.\n"); |
1001 | rxvt_warn ("setting locale failed, continuing without locale support.\n"); |
998 | else |
1002 | else |
999 | { |
1003 | { |
1000 | set_string_property (xa[XA_WM_LOCALE_NAME], locale); |
1004 | set_string_property (xa[XA_WM_LOCALE_NAME], locale); |
1001 | |
1005 | |
1002 | if (!XSupportsLocale ()) |
1006 | if (!XSupportsLocale ()) |
1003 | { |
1007 | { |
1004 | rxvt_warn ("the locale is not supported by Xlib, working without locale support.\n"); |
1008 | rxvt_warn ("the locale is not supported by Xlib, continuing without locale support.\n"); |
1005 | return; |
1009 | return; |
1006 | } |
1010 | } |
1007 | |
1011 | |
1008 | im_ev.start (display); |
1012 | im_ev.start (display); |
1009 | |
1013 | |
… | |
… | |
1158 | /*----------------------------------------------------------------------*/ |
1162 | /*----------------------------------------------------------------------*/ |
1159 | /* color aliases, fg/bg bright-bold */ |
1163 | /* color aliases, fg/bg bright-bold */ |
1160 | void |
1164 | void |
1161 | rxvt_term::color_aliases (int idx) |
1165 | rxvt_term::color_aliases (int idx) |
1162 | { |
1166 | { |
1163 | if (rs[Rs_color + idx] && isdigit (* (rs[Rs_color + idx]))) |
1167 | if (rs[Rs_color + idx] && isdigit (*rs[Rs_color + idx])) |
1164 | { |
1168 | { |
1165 | int i = atoi (rs[Rs_color + idx]); |
1169 | int i = atoi (rs[Rs_color + idx]); |
1166 | |
1170 | |
1167 | if (i >= 8 && i <= 15) |
1171 | if (i >= 8 && i <= 15) |
1168 | /* bright colors */ |
1172 | /* bright colors */ |
… | |
… | |
1208 | for (j = map->max_keypermod; j--; k++) |
1212 | for (j = map->max_keypermod; j--; k++) |
1209 | { |
1213 | { |
1210 | if (kc[k] == 0) |
1214 | if (kc[k] == 0) |
1211 | break; |
1215 | break; |
1212 | |
1216 | |
1213 | switch (XKeycodeToKeysym (dpy, kc[k], 0)) |
1217 | switch (rxvt_XKeycodeToKeysym (dpy, kc[k], 0)) |
1214 | { |
1218 | { |
1215 | case XK_Num_Lock: |
1219 | case XK_Num_Lock: |
1216 | ModNumLockMask = modmasks[i - 1]; |
1220 | ModNumLockMask = modmasks[i - 1]; |
1217 | continue; |
1221 | continue; |
1218 | |
1222 | |
… | |
… | |
1263 | } |
1267 | } |
1264 | |
1268 | |
1265 | void |
1269 | void |
1266 | rxvt_term::set_icon (const char *file) |
1270 | rxvt_term::set_icon (const char *file) |
1267 | { |
1271 | { |
1268 | #ifdef HAVE_AFTERIMAGE |
|
|
1269 | init_asv (); |
|
|
1270 | |
|
|
1271 | ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); |
|
|
1272 | if (!im) |
|
|
1273 | { |
|
|
1274 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
|
|
1275 | return; |
|
|
1276 | } |
|
|
1277 | |
|
|
1278 | unsigned int w = im->width; |
|
|
1279 | unsigned int h = im->height; |
|
|
1280 | |
|
|
1281 | if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) |
|
|
1282 | { |
|
|
1283 | rxvt_warn ("Icon image too big, continuing without.\n"); |
|
|
1284 | destroy_asimage (&im); |
|
|
1285 | return; |
|
|
1286 | } |
|
|
1287 | |
|
|
1288 | ASImage *result = scale_asimage (asv, im, |
|
|
1289 | w, h, ASA_ARGB32, |
|
|
1290 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1291 | destroy_asimage (&im); |
|
|
1292 | |
|
|
1293 | if (!result) |
|
|
1294 | { |
|
|
1295 | rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); |
|
|
1296 | return; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); |
|
|
1300 | if (buffer) |
|
|
1301 | { |
|
|
1302 | ARGB32 *asbuf = result->alt.argb32; |
|
|
1303 | buffer [0] = w; |
|
|
1304 | buffer [1] = h; |
|
|
1305 | |
|
|
1306 | for (unsigned int i = 0; i < w * h; ++i) |
|
|
1307 | buffer [i + 2] = asbuf [i]; |
|
|
1308 | |
|
|
1309 | XChangeProperty (dpy, parent, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, |
|
|
1310 | PropModeReplace, (const unsigned char *) buffer, 2 + w * h); |
|
|
1311 | free (buffer); |
|
|
1312 | } |
|
|
1313 | else |
|
|
1314 | rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); |
|
|
1315 | |
|
|
1316 | destroy_asimage (&result); |
|
|
1317 | #endif |
|
|
1318 | |
|
|
1319 | #ifdef HAVE_PIXBUF |
1272 | #if HAVE_PIXBUF |
1320 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
1273 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
1321 | if (!pixbuf) |
1274 | if (!pixbuf) |
1322 | { |
1275 | { |
1323 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
1276 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
1324 | return; |
1277 | return; |
… | |
… | |
1444 | CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, |
1397 | CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, |
1445 | &attributes); |
1398 | &attributes); |
1446 | |
1399 | |
1447 | this->parent = top; |
1400 | this->parent = top; |
1448 | |
1401 | |
1449 | old_width = szHint.width; |
|
|
1450 | old_height = szHint.height; |
|
|
1451 | |
|
|
1452 | set_title (rs [Rs_title]); |
1402 | set_title (rs [Rs_title]); |
1453 | set_icon_name (rs [Rs_iconName]); |
1403 | set_icon_name (rs [Rs_iconName]); |
1454 | |
1404 | |
1455 | classHint.res_name = (char *)rs[Rs_name]; |
1405 | classHint.res_name = (char *)rs[Rs_name]; |
1456 | classHint.res_class = (char *)RESCLASS; |
1406 | classHint.res_class = (char *)RESCLASS; |
1457 | |
1407 | |
1458 | wmHint.flags = InputHint | StateHint | WindowGroupHint; |
1408 | wmHint.flags = InputHint | StateHint | WindowGroupHint; |
1459 | wmHint.input = True; |
1409 | wmHint.input = True; |
1460 | wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; |
1410 | wmHint.initial_state = option (Opt_iconic) ? IconicState |
|
|
1411 | : option (Opt_dockapp) ? WithdrawnState |
|
|
1412 | : NormalState; |
1461 | wmHint.window_group = top; |
1413 | wmHint.window_group = top; |
1462 | |
1414 | |
1463 | XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, |
1415 | XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, |
1464 | &szHint, &wmHint, &classHint); |
1416 | &szHint, &wmHint, &classHint); |
1465 | #if ENABLE_EWMH |
1417 | #if ENABLE_EWMH |
… | |
… | |
1467 | * set up icon hint |
1419 | * set up icon hint |
1468 | * rs [Rs_iconfile] is path to icon |
1420 | * rs [Rs_iconfile] is path to icon |
1469 | */ |
1421 | */ |
1470 | |
1422 | |
1471 | if (rs [Rs_iconfile]) |
1423 | if (rs [Rs_iconfile]) |
1472 | { |
|
|
1473 | set_icon (rs [Rs_iconfile]); |
1424 | set_icon (rs [Rs_iconfile]); |
1474 | } |
|
|
1475 | #endif |
1425 | #endif |
1476 | |
1426 | |
1477 | #if ENABLE_FRILLS |
1427 | #if ENABLE_FRILLS |
1478 | if (mwmhints.flags) |
1428 | if (mwmhints.flags) |
1479 | XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, |
1429 | XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, |
… | |
… | |
1518 | TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); |
1468 | TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); |
1519 | |
1469 | |
1520 | /* the vt window */ |
1470 | /* the vt window */ |
1521 | vt = XCreateSimpleWindow (dpy, top, |
1471 | vt = XCreateSimpleWindow (dpy, top, |
1522 | window_vt_x, window_vt_y, |
1472 | window_vt_x, window_vt_y, |
1523 | width, height, |
1473 | vt_width, vt_height, |
1524 | 0, |
1474 | 0, |
1525 | pix_colors_focused[Color_fg], |
1475 | pix_colors_focused[Color_fg], |
1526 | pix_colors_focused[Color_bg]); |
1476 | pix_colors_focused[Color_bg]); |
1527 | |
1477 | |
1528 | attributes.bit_gravity = NorthWestGravity; |
1478 | attributes.bit_gravity = NorthWestGravity; |
… | |
… | |
1577 | if (pty->pty >= 0) |
1527 | if (pty->pty >= 0) |
1578 | { |
1528 | { |
1579 | if (getfd_hook) |
1529 | if (getfd_hook) |
1580 | pty->pty = (*getfd_hook) (pty->pty); |
1530 | pty->pty = (*getfd_hook) (pty->pty); |
1581 | |
1531 | |
1582 | if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK)) |
1532 | if (pty->pty < 0) |
1583 | rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); |
1533 | rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); |
1584 | } |
1534 | } |
1585 | } |
1535 | } |
1586 | else |
1536 | else |
1587 | #endif |
1537 | #endif |
1588 | if (!pty->get ()) |
1538 | if (!pty->get ()) |
1589 | rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); |
1539 | rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); |
|
|
1540 | |
|
|
1541 | fcntl (pty->pty, F_SETFL, O_NONBLOCK); |
1590 | |
1542 | |
1591 | struct termios tio = def_tio; |
1543 | struct termios tio = def_tio; |
1592 | |
1544 | |
1593 | #ifndef NO_BACKSPACE_KEY |
1545 | #ifndef NO_BACKSPACE_KEY |
1594 | if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) |
1546 | if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) |
… | |
… | |
1644 | |
1596 | |
1645 | _exit (EXIT_FAILURE); |
1597 | _exit (EXIT_FAILURE); |
1646 | |
1598 | |
1647 | default: |
1599 | default: |
1648 | if (!option (Opt_utmpInhibit)) |
1600 | if (!option (Opt_utmpInhibit)) |
|
|
1601 | { |
|
|
1602 | #ifdef LOG_ONLY_ON_LOGIN |
|
|
1603 | bool login_shell = option (Opt_loginShell); |
|
|
1604 | #else |
|
|
1605 | bool login_shell = true; |
|
|
1606 | #endif |
1649 | pty->login (cmd_pid, option (Opt_loginShell), rs[Rs_display_name]); |
1607 | pty->login (cmd_pid, login_shell, rs[Rs_display_name]); |
|
|
1608 | } |
1650 | |
1609 | |
1651 | pty->close_tty (); |
1610 | pty->close_tty (); |
1652 | |
1611 | |
1653 | child_ev.start (cmd_pid); |
1612 | child_ev.start (cmd_pid); |
1654 | |
1613 | |
… | |
… | |
1679 | #elif defined (SRIOCSREDIR) |
1638 | #elif defined (SRIOCSREDIR) |
1680 | int fd; |
1639 | int fd; |
1681 | |
1640 | |
1682 | fd = open (CONSOLE, O_WRONLY, 0); |
1641 | fd = open (CONSOLE, O_WRONLY, 0); |
1683 | if (fd >= 0) |
1642 | if (fd >= 0) |
1684 | if (ioctl (fd, SRIOCSREDIR, NULL) < 0) |
1643 | { |
|
|
1644 | ioctl (fd, SRIOCSREDIR, STDIN_FILENO); |
1685 | close (fd); |
1645 | close (fd); |
|
|
1646 | } |
1686 | #endif /* SRIOCSREDIR */ |
1647 | #endif /* SRIOCSREDIR */ |
1687 | } |
1648 | } |
1688 | |
1649 | |
1689 | /* reset signals and spin off the command interpreter */ |
1650 | /* reset signals and spin off the command interpreter */ |
1690 | signal (SIGINT, SIG_DFL); |
1651 | signal (SIGINT, SIG_DFL); |