1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.8 2003/11/27 10:12:10 pcg Exp $ |
4 | * $Id: main.C,v 1.14 2003/12/18 00:29:29 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> |
… | |
… | |
66 | #endif |
66 | #endif |
67 | #ifdef POINTER_BLANK |
67 | #ifdef POINTER_BLANK |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
69 | #endif |
69 | #endif |
70 | x_ev (this, &rxvt_term::x_cb), |
70 | x_ev (this, &rxvt_term::x_cb), |
71 | destroy_ev (this, &rxvt_term::destroy_cb) |
71 | destroy_ev (this, &rxvt_term::destroy_cb), |
|
|
72 | check_ev (this, &rxvt_term::check_cb), |
|
|
73 | incr_ev (this, &rxvt_term::incr_cb) |
72 | { |
74 | { |
73 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
75 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
74 | } |
76 | } |
75 | |
77 | |
76 | rxvt_term::~rxvt_term () |
78 | rxvt_term::~rxvt_term () |
77 | { |
79 | { |
78 | rxvt_scr_release (this); |
80 | scr_release (); |
79 | |
81 | |
|
|
82 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
83 | free (locale); |
|
|
84 | #endif |
80 | #ifndef NO_SETOWNER_TTYDEV |
85 | #ifndef NO_SETOWNER_TTYDEV |
81 | rxvt_privileged_ttydev (this, RESTORE); |
86 | rxvt_privileged_ttydev (this, RESTORE); |
82 | #endif |
87 | #endif |
83 | #ifdef UTMP_SUPPORT |
88 | #ifdef UTMP_SUPPORT |
84 | rxvt_privileged_utmp (this, RESTORE); |
89 | rxvt_privileged_utmp (this, RESTORE); |
… | |
… | |
101 | } |
106 | } |
102 | |
107 | |
103 | void |
108 | void |
104 | rxvt_term::destroy () |
109 | rxvt_term::destroy () |
105 | { |
110 | { |
|
|
111 | check_ev.stop (); |
106 | pty_ev.stop (); |
112 | pty_ev.stop (); |
107 | x_ev.stop (); |
113 | x_ev.stop (); |
108 | #ifdef CURSOR_BLINK |
114 | #ifdef CURSOR_BLINK |
109 | blink_ev.stop (); |
115 | blink_ev.stop (); |
110 | #endif |
116 | #endif |
… | |
… | |
125 | |
131 | |
126 | /*----------------------------------------------------------------------*/ |
132 | /*----------------------------------------------------------------------*/ |
127 | /* rxvt_init() */ |
133 | /* rxvt_init() */ |
128 | /* LIBPROTO */ |
134 | /* LIBPROTO */ |
129 | rxvt_t |
135 | rxvt_t |
130 | rxvt_init(int argc, const char *const *argv) |
136 | rxvt_init (int argc, const char *const *argv) |
131 | { |
137 | { |
132 | SET_R(new rxvt_term); |
138 | SET_R (new rxvt_term); |
133 | dR; |
139 | dR; |
134 | |
140 | |
135 | if (!R->init_vars () || !R->init (argc, argv)) |
141 | if (!R->init_vars () || !R->init (argc, argv)) |
136 | { |
142 | { |
137 | delete R; |
143 | delete R; |
… | |
… | |
148 | /* install exit handler for cleanup */ |
154 | /* install exit handler for cleanup */ |
149 | #if 0 |
155 | #if 0 |
150 | #ifdef HAVE_ATEXIT |
156 | #ifdef HAVE_ATEXIT |
151 | atexit(rxvt_clean_exit); |
157 | atexit(rxvt_clean_exit); |
152 | #else |
158 | #else |
153 | # ifdef HAVE_ON_EXIT |
|
|
154 | on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */ |
|
|
155 | # endif |
|
|
156 | #endif |
159 | #endif |
157 | #endif |
160 | #endif |
158 | |
161 | |
159 | struct sigaction sa; |
162 | struct sigaction sa; |
160 | |
163 | |
161 | sigfillset (&sa.sa_mask); |
164 | sigfillset (&sa.sa_mask); |
162 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
165 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
163 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGHUP , &sa, 0); //TODO, also: SIGPIPE |
166 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
167 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
164 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
168 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
165 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
169 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
166 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
170 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
167 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
171 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
168 | |
172 | |
… | |
… | |
202 | |
206 | |
203 | rxvt_Create_Windows (this, argc, argv); |
207 | rxvt_Create_Windows (this, argc, argv); |
204 | |
208 | |
205 | rxvt_init_xlocale (this); |
209 | rxvt_init_xlocale (this); |
206 | |
210 | |
207 | rxvt_scr_reset (this); /* initialize screen */ |
211 | scr_reset (); /* initialize screen */ |
208 | #ifdef RXVT_GRAPHICS |
212 | #ifdef RXVT_GRAPHICS |
209 | rxvt_Gr_reset (this); /* reset graphics */ |
213 | rxvt_Gr_reset (this); /* reset graphics */ |
210 | #endif |
214 | #endif |
211 | |
215 | |
212 | #if 0 |
216 | #if 0 |
… | |
… | |
237 | rxvt_init_command (this, cmd_argv); |
241 | rxvt_init_command (this, cmd_argv); |
238 | |
242 | |
239 | x_ev.start (Xfd, EVENT_READ); |
243 | x_ev.start (Xfd, EVENT_READ); |
240 | pty_ev.start (cmd_fd, EVENT_READ); |
244 | pty_ev.start (cmd_fd, EVENT_READ); |
241 | |
245 | |
242 | flush (); |
246 | check_ev.start (); |
|
|
247 | |
|
|
248 | process_x_events (); |
243 | |
249 | |
244 | return true; |
250 | return true; |
245 | } |
251 | } |
246 | |
252 | |
247 | /* ------------------------------------------------------------------------- * |
253 | /* ------------------------------------------------------------------------- * |
… | |
… | |
614 | /*----------------------------------------------------------------------*/ |
620 | /*----------------------------------------------------------------------*/ |
615 | /* |
621 | /* |
616 | * Tell the teletype handler what size the window is. |
622 | * Tell the teletype handler what size the window is. |
617 | * Called after a window size change. |
623 | * Called after a window size change. |
618 | */ |
624 | */ |
619 | /* EXTPROTO */ |
|
|
620 | void |
625 | void |
621 | rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) |
626 | rxvt_term::tt_winch () |
622 | { |
627 | { |
623 | struct winsize ws; |
628 | struct winsize ws; |
624 | |
629 | |
625 | if (fd < 0) |
630 | if (cmd_fd < 0) |
626 | return; |
631 | return; |
|
|
632 | |
627 | ws.ws_col = col; |
633 | ws.ws_col = TermWin.ncol; |
628 | ws.ws_row = row; |
634 | ws.ws_row = TermWin.nrow; |
629 | ws.ws_xpixel = ws.ws_ypixel = 0; |
635 | ws.ws_xpixel = ws.ws_ypixel = 0; |
630 | #ifndef DEBUG_SIZE |
636 | #ifndef DEBUG_SIZE |
631 | (void)ioctl(fd, TIOCSWINSZ, &ws); |
637 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
632 | #else |
638 | #else |
633 | if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { |
639 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
634 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
640 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
635 | } |
|
|
636 | # ifdef SIGWINCH |
641 | # ifdef SIGWINCH |
637 | else if (pid) /* force through to the command */ |
642 | else if (cmd_pid) /* force through to the command */ |
638 | kill(pid, SIGWINCH); |
643 | kill (cmd_pid, SIGWINCH); |
639 | # endif |
644 | # endif |
640 | #endif |
645 | #endif |
641 | } |
646 | } |
642 | |
647 | |
643 | /*----------------------------------------------------------------------*/ |
648 | /*----------------------------------------------------------------------*/ |
… | |
… | |
938 | uint16_t old_ncol = R->prev_ncol; |
943 | uint16_t old_ncol = R->prev_ncol; |
939 | |
944 | |
940 | /* scr_reset only works on the primary screen */ |
945 | /* scr_reset only works on the primary screen */ |
941 | if (R->old_height) /* this is not the first time through */ |
946 | if (R->old_height) /* this is not the first time through */ |
942 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
947 | curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); |
|
|
948 | |
943 | rxvt_scr_reset(aR); |
949 | R->scr_reset(); |
|
|
950 | |
944 | if (curr_screen >= 0) { /* this is not the first time through */ |
951 | if (curr_screen >= 0) { /* this is not the first time through */ |
945 | rxvt_scr_change_screen(aR_ curr_screen); |
952 | rxvt_scr_change_screen(aR_ curr_screen); |
946 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
953 | rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); |
947 | } |
954 | } |
948 | } |
955 | } |
… | |
… | |
1062 | return; |
1069 | return; |
1063 | } |
1070 | } |
1064 | |
1071 | |
1065 | /* INTPROTO */ |
1072 | /* INTPROTO */ |
1066 | void |
1073 | void |
1067 | rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1074 | rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, |
1068 | XRectangle * needed_rect) |
1075 | XRectangle * needed_rect) |
1069 | { |
1076 | { |
1070 | int mbh, vtx = 0; |
1077 | int mbh, vtx = 0; |
1071 | |
1078 | |
1072 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1079 | if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) |
1073 | vtx = scrollbar_TotalWidth(); |
1080 | vtx = scrollbar_TotalWidth(); |
… | |
… | |
1117 | rxvt_IMInstantiateCallback(Display * unused |
1124 | rxvt_IMInstantiateCallback(Display * unused |
1118 | __attribute__ ((unused)), XPointer client_data |
1125 | __attribute__ ((unused)), XPointer client_data |
1119 | __attribute__ ((unused)), XPointer call_data |
1126 | __attribute__ ((unused)), XPointer call_data |
1120 | __attribute__ ((unused))) |
1127 | __attribute__ ((unused))) |
1121 | { |
1128 | { |
1122 | dR; |
1129 | dR; |
1123 | int i, found, had_im; |
1130 | int i, found, had_im; |
1124 | const char *p; |
1131 | const char *p; |
1125 | char **s; |
1132 | char **s; |
1126 | char buf[IMBUFSIZ]; |
1133 | char buf[IMBUFSIZ]; |
1127 | |
1134 | |
1128 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1135 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1129 | if (R->Input_Context) |
1136 | if (R->Input_Context) |
1130 | return; |
1137 | return; |
1131 | |
1138 | |
1132 | found = had_im = 0; |
1139 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1140 | if (R->rs[Rs_imLocale]) |
|
|
1141 | setlocale (LC_CTYPE, R->rs[Rs_imLocale]); |
|
|
1142 | #endif |
|
|
1143 | |
1133 | p = R->rs[Rs_inputMethod]; |
1144 | p = R->rs[Rs_inputMethod]; |
1134 | if (p && *p) { |
1145 | if (p && *p) |
1135 | had_im = 1; |
1146 | { |
|
|
1147 | bool found = false; |
|
|
1148 | |
1136 | s = rxvt_splitcommastring(p); |
1149 | s = rxvt_splitcommastring (p); |
1137 | for (i = 0; s[i]; i++) { |
1150 | for (i = 0; s[i]; i++) |
|
|
1151 | { |
1138 | if (*s[i]) { |
1152 | if (*s[i]) |
|
|
1153 | { |
1139 | STRCPY(buf, "@im="); |
1154 | STRCPY (buf, "@im="); |
1140 | STRNCAT(buf, s[i], IMBUFSIZ - 5); |
1155 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1141 | if ((p = XSetLocaleModifiers(buf)) != NULL && *p |
1156 | if ((p = XSetLocaleModifiers (buf)) && *p |
1142 | && (rxvt_IM_get_IC(aR) == True)) { |
1157 | && rxvt_IM_get_IC (aR)) |
|
|
1158 | { |
1143 | found = 1; |
1159 | found = true; |
1144 | break; |
1160 | break; |
1145 | } |
1161 | } |
1146 | } |
1162 | } |
1147 | } |
1163 | } |
1148 | for (i = 0; s[i]; i++) |
1164 | for (i = 0; s[i]; i++) |
1149 | free(s[i]); |
1165 | free(s[i]); |
1150 | free(s); |
1166 | free(s); |
1151 | } |
1167 | |
1152 | if (found) |
1168 | if (found) |
1153 | return; |
1169 | goto done; |
|
|
1170 | } |
1154 | |
1171 | |
1155 | /* try with XMODIFIERS env. var. */ |
1172 | /* try with XMODIFIERS env. var. */ |
1156 | if ((p = XSetLocaleModifiers("")) != NULL && *p) { |
1173 | if ((p = XSetLocaleModifiers ("")) && *p |
1157 | rxvt_IM_get_IC(aR); |
1174 | && rxvt_IM_get_IC (aR)) |
1158 | return; |
1175 | goto done; |
1159 | } |
|
|
1160 | |
1176 | |
1161 | /* try with no modifiers base IF the user didn't specify an IM */ |
1177 | /* try with no modifiers base IF the user didn't specify an IM */ |
1162 | if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p |
1178 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1163 | && rxvt_IM_get_IC(aR) == True) |
1179 | && rxvt_IM_get_IC (aR) == True) |
1164 | return; |
1180 | goto done; |
|
|
1181 | |
|
|
1182 | done: |
|
|
1183 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1184 | if (R->rs[Rs_imLocale]) |
|
|
1185 | setlocale (LC_CTYPE, R->locale); |
|
|
1186 | #endif |
1165 | } |
1187 | } |
1166 | |
1188 | |
1167 | /* |
1189 | /* |
1168 | * Try to open a XIM with the current modifiers, then see if we can |
1190 | * Try to open a XIM with the current modifiers, then see if we can |
1169 | * open a suitable preedit type |
1191 | * open a suitable preedit type |