1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.11 2003/12/08 23:14:40 pcg Exp $ |
4 | * $Id: main.C,v 1.15 2003/12/18 05:45:11 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> |
… | |
… | |
42 | |
42 | |
43 | #ifdef HAVE_TERMIOS_H |
43 | #ifdef HAVE_TERMIOS_H |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
|
|
47 | #include <cstring> |
|
|
48 | |
|
|
49 | static char curlocale[128]; |
|
|
50 | |
|
|
51 | void |
|
|
52 | rxvt_set_locale (const char *locale) |
|
|
53 | { |
|
|
54 | if (locale && strncmp (locale, curlocale, 128)) |
|
|
55 | { |
|
|
56 | strncpy (curlocale, locale, 128); |
|
|
57 | setlocale (LC_CTYPE, curlocale); |
|
|
58 | } |
|
|
59 | } |
|
|
60 | |
47 | void * |
61 | void * |
48 | rxvt_term::operator new (size_t s) |
62 | rxvt_term::operator new (size_t s) |
49 | { |
63 | { |
50 | void *p = malloc (s); |
64 | void *p = malloc (s); |
51 | |
65 | |
… | |
… | |
67 | #ifdef POINTER_BLANK |
81 | #ifdef POINTER_BLANK |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
82 | pointer_ev (this, &rxvt_term::pointer_cb), |
69 | #endif |
83 | #endif |
70 | x_ev (this, &rxvt_term::x_cb), |
84 | x_ev (this, &rxvt_term::x_cb), |
71 | destroy_ev (this, &rxvt_term::destroy_cb), |
85 | destroy_ev (this, &rxvt_term::destroy_cb), |
72 | check_ev (this, &rxvt_term::check_cb) |
86 | check_ev (this, &rxvt_term::check_cb), |
|
|
87 | incr_ev (this, &rxvt_term::incr_cb) |
73 | { |
88 | { |
74 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
89 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
75 | } |
90 | } |
76 | |
91 | |
77 | rxvt_term::~rxvt_term () |
92 | rxvt_term::~rxvt_term () |
78 | { |
93 | { |
79 | rxvt_scr_release (this); |
94 | scr_release (); |
|
|
95 | |
|
|
96 | free (locale); |
|
|
97 | free (codeset); |
80 | |
98 | |
81 | #ifndef NO_SETOWNER_TTYDEV |
99 | #ifndef NO_SETOWNER_TTYDEV |
82 | rxvt_privileged_ttydev (this, RESTORE); |
100 | rxvt_privileged_ttydev (this, RESTORE); |
83 | #endif |
101 | #endif |
84 | #ifdef UTMP_SUPPORT |
102 | #ifdef UTMP_SUPPORT |
… | |
… | |
174 | } |
192 | } |
175 | |
193 | |
176 | bool |
194 | bool |
177 | rxvt_term::init (int argc, const char *const *argv) |
195 | rxvt_term::init (int argc, const char *const *argv) |
178 | { |
196 | { |
179 | dR;//TODO (scrollbar, setidle) |
|
|
180 | |
|
|
181 | /* |
197 | /* |
182 | * Save and then give up any super-user privileges |
198 | * Save and then give up any super-user privileges |
183 | * If we need privileges in any area then we must specifically request it. |
199 | * If we need privileges in any area then we must specifically request it. |
184 | * We should only need to be root in these cases: |
200 | * We should only need to be root in these cases: |
185 | * 1. write utmp entries on some systems |
201 | * 1. write utmp entries on some systems |
186 | * 2. chown tty on some systems |
202 | * 2. chown tty on some systems |
187 | */ |
203 | */ |
188 | rxvt_privileges (this, SAVE); |
204 | rxvt_privileges (this, SAVE); |
189 | rxvt_privileges (this, IGNORE); |
205 | rxvt_privileges (this, IGNORE); |
190 | |
206 | |
|
|
207 | #if HAVE_XSETLOCALE || HAVE_SETLOCALE |
|
|
208 | locale = strdup (setlocale (LC_CTYPE, "")); |
|
|
209 | #endif |
|
|
210 | #if HAVE_NL_LANGINFO |
|
|
211 | codeset = strdup (nl_langinfo (CODESET)); |
|
|
212 | #endif |
|
|
213 | |
191 | rxvt_init_secondary (this); |
214 | init_secondary (); |
192 | |
215 | |
193 | const char **cmd_argv = rxvt_init_resources (this, argc, argv); |
216 | const char **cmd_argv = init_resources (argc, argv); |
194 | |
217 | |
195 | #if (MENUBAR_MAX) |
218 | #if (MENUBAR_MAX) |
196 | rxvt_menubar_read (this, rs[Rs_menu]); |
219 | rxvt_menubar_read (this, rs[Rs_menu]); |
197 | #endif |
220 | #endif |
198 | #ifdef HAVE_SCROLLBARS |
221 | #ifdef HAVE_SCROLLBARS |
199 | if (Options & Opt_scrollBar) |
222 | if (Options & Opt_scrollBar) |
200 | scrollbar_setIdle (); /* set existence for size calculations */ |
223 | scrollBar.setIdle (); /* set existence for size calculations */ |
201 | #endif |
224 | #endif |
202 | |
225 | |
203 | rxvt_Create_Windows (this, argc, argv); |
226 | rxvt_Create_Windows (this, argc, argv); |
204 | |
227 | |
205 | rxvt_init_xlocale (this); |
228 | init_xlocale (); |
206 | |
229 | |
207 | rxvt_scr_reset (this); /* initialize screen */ |
230 | scr_reset (); /* initialize screen */ |
208 | #ifdef RXVT_GRAPHICS |
231 | #ifdef RXVT_GRAPHICS |
209 | rxvt_Gr_reset (this); /* reset graphics */ |
232 | rxvt_Gr_reset (this); /* reset graphics */ |
210 | #endif |
233 | #endif |
211 | |
234 | |
212 | #if 0 |
235 | #if 0 |
… | |
… | |
231 | } |
254 | } |
232 | #endif |
255 | #endif |
233 | XMapWindow (Xdisplay, TermWin.vt); |
256 | XMapWindow (Xdisplay, TermWin.vt); |
234 | XMapWindow (Xdisplay, TermWin.parent[0]); |
257 | XMapWindow (Xdisplay, TermWin.parent[0]); |
235 | |
258 | |
236 | rxvt_init_env (this); |
259 | init_env (); |
237 | rxvt_init_command (this, cmd_argv); |
260 | init_command (cmd_argv); |
238 | |
261 | |
239 | x_ev.start (Xfd, EVENT_READ); |
262 | x_ev.start (Xfd, EVENT_READ); |
240 | pty_ev.start (cmd_fd, EVENT_READ); |
263 | pty_ev.start (cmd_fd, EVENT_READ); |
241 | |
264 | |
242 | check_ev.start (); |
265 | check_ev.start (); |
… | |
… | |
757 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
780 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
758 | R->PixColors[Color_bg]); |
781 | R->PixColors[Color_bg]); |
759 | |
782 | |
760 | /* handle Color_BD, scrollbar background, etc. */ |
783 | /* handle Color_BD, scrollbar background, etc. */ |
761 | |
784 | |
762 | rxvt_set_colorfgbg(aR); |
785 | rxvt_set_colorfgbg (aR); |
763 | rxvt_recolour_cursor(aR); |
786 | R->recolour_cursor (); |
764 | /* the only reasonable way to enforce a clean update */ |
787 | /* the only reasonable way to enforce a clean update */ |
765 | rxvt_scr_poweron(aR); |
788 | rxvt_scr_poweron (aR); |
766 | } |
789 | } |
767 | |
790 | |
768 | #else |
791 | #else |
769 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
792 | # define rxvt_set_window_color(aR_ idx,color) ((void)0) |
770 | #endif /* XTERM_COLOR_CHANGE */ |
793 | #endif /* XTERM_COLOR_CHANGE */ |
771 | |
794 | |
772 | /* EXTPROTO */ |
|
|
773 | void |
795 | void |
774 | rxvt_recolour_cursor(pR) |
796 | rxvt_term::recolour_cursor () |
775 | { |
797 | { |
776 | rxvt_color xcol[2]; |
|
|
777 | |
|
|
778 | #if TODO |
798 | #if TODO |
|
|
799 | rxvt_color xcol[2]; |
|
|
800 | |
779 | xcol[0] = R->PixColors[Color_pointer]; |
801 | xcol[0] = PixColors[Color_pointer]; |
780 | xcol[1] = R->PixColors[Color_bg]; |
802 | xcol[1] = PixColors[Color_bg]; |
781 | XQueryColors(R->Xdisplay, XCMAP, xcol, 2); |
803 | XQueryColors (Xdisplay, XCMAP, xcol, 2); |
782 | XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); |
804 | XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); |
783 | #endif |
805 | #endif |
784 | } |
806 | } |
785 | |
807 | |
786 | /*----------------------------------------------------------------------*/ |
808 | /*----------------------------------------------------------------------*/ |
787 | /* |
809 | /* |
… | |
… | |
939 | uint16_t old_ncol = R->prev_ncol; |
961 | uint16_t old_ncol = R->prev_ncol; |
940 | |
962 | |
941 | /* scr_reset only works on the primary screen */ |
963 | /* scr_reset only works on the primary screen */ |
942 | if (R->old_height) /* this is not the first time through */ |
964 | if (R->old_height) /* this is not the first time through */ |
943 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
965 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
|
|
966 | |
944 | rxvt_scr_reset(aR); |
967 | R->scr_reset(); |
|
|
968 | |
945 | if (curr_screen >= 0) { /* this is not the first time through */ |
969 | if (curr_screen >= 0) { /* this is not the first time through */ |
946 | rxvt_scr_change_screen(aR_ curr_screen); |
970 | rxvt_scr_change_screen(aR_ curr_screen); |
947 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
971 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
948 | } |
972 | } |
949 | } |
973 | } |
… | |
… | |
1127 | char buf[IMBUFSIZ]; |
1151 | char buf[IMBUFSIZ]; |
1128 | |
1152 | |
1129 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1153 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1130 | if (R->Input_Context) |
1154 | if (R->Input_Context) |
1131 | return; |
1155 | return; |
|
|
1156 | |
|
|
1157 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1158 | if (R->rs[Rs_imLocale]) |
|
|
1159 | setlocale (LC_CTYPE, R->rs[Rs_imLocale]); |
|
|
1160 | #endif |
1132 | |
1161 | |
1133 | p = R->rs[Rs_inputMethod]; |
1162 | p = R->rs[Rs_inputMethod]; |
1134 | if (p && *p) |
1163 | if (p && *p) |
1135 | { |
1164 | { |
1136 | bool found = false; |
1165 | bool found = false; |
… | |
… | |
1153 | for (i = 0; s[i]; i++) |
1182 | for (i = 0; s[i]; i++) |
1154 | free(s[i]); |
1183 | free(s[i]); |
1155 | free(s); |
1184 | free(s); |
1156 | |
1185 | |
1157 | if (found) |
1186 | if (found) |
1158 | return; |
1187 | goto done; |
1159 | } |
1188 | } |
1160 | |
1189 | |
1161 | /* try with XMODIFIERS env. var. */ |
1190 | /* try with XMODIFIERS env. var. */ |
1162 | if ((p = XSetLocaleModifiers ("")) && *p |
1191 | if ((p = XSetLocaleModifiers ("")) && *p |
1163 | && rxvt_IM_get_IC (aR)) |
1192 | && rxvt_IM_get_IC (aR)) |
1164 | return; |
1193 | goto done; |
1165 | |
1194 | |
1166 | /* try with no modifiers base IF the user didn't specify an IM */ |
1195 | /* try with no modifiers base IF the user didn't specify an IM */ |
1167 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1196 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1168 | && rxvt_IM_get_IC (aR) == True) |
1197 | && rxvt_IM_get_IC (aR) == True) |
1169 | return; |
1198 | goto done; |
|
|
1199 | |
|
|
1200 | done: |
|
|
1201 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1202 | if (R->rs[Rs_imLocale]) |
|
|
1203 | setlocale (LC_CTYPE, R->locale); |
|
|
1204 | #endif |
1170 | } |
1205 | } |
1171 | |
1206 | |
1172 | /* |
1207 | /* |
1173 | * Try to open a XIM with the current modifiers, then see if we can |
1208 | * Try to open a XIM with the current modifiers, then see if we can |
1174 | * open a suitable preedit type |
1209 | * open a suitable preedit type |