1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.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 |
… | |
… | |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
12 | * - extensive modifications |
12 | * - extensive modifications |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
15 | * - extensive modifications |
15 | * - extensive modifications |
|
|
16 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
16 | * |
17 | * |
17 | * This program is free software; you can redistribute it and/or modify |
18 | * 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 |
19 | * 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 |
20 | * the Free Software Foundation; either version 2 of the License, or |
20 | * (at your option) any later version. |
21 | * (at your option) any later version. |
… | |
… | |
43 | # include <termios.h> |
44 | # include <termios.h> |
44 | #endif |
45 | #endif |
45 | |
46 | |
46 | #include <cstring> |
47 | #include <cstring> |
47 | |
48 | |
|
|
49 | vector<rxvt_term *> rxvt_term::termlist; |
|
|
50 | |
48 | static char curlocale[128]; |
51 | static char curlocale[128]; |
49 | |
52 | |
50 | void |
53 | bool |
51 | rxvt_set_locale (const char *locale) |
54 | rxvt_set_locale (const char *locale) |
52 | { |
55 | { |
53 | if (locale && STRNCMP (locale, curlocale, 128)) |
56 | if (!locale || !STRNCMP (locale, curlocale, 128)) |
54 | { |
57 | return false; |
|
|
58 | |
55 | STRNCPY (curlocale, locale, 128); |
59 | STRNCPY (curlocale, locale, 128); |
56 | setlocale (LC_CTYPE, curlocale); |
60 | setlocale (LC_CTYPE, curlocale); |
|
|
61 | return true; |
|
|
62 | } |
|
|
63 | |
|
|
64 | #if ENABLE_COMBINING |
|
|
65 | class rxvt_composite_vec rxvt_composite; |
|
|
66 | |
|
|
67 | text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2) |
|
|
68 | { |
|
|
69 | compose_char *cc; |
|
|
70 | |
|
|
71 | // break compose chains, as stupid readline really likes to duplicate |
|
|
72 | // composing characters for some reason near the end of a line. |
|
|
73 | cc = (*this)[c1]; |
|
|
74 | while (cc) |
57 | } |
75 | { |
|
|
76 | if (cc->c2 == c2) return c1; |
|
|
77 | cc = (*this)[cc->c1]; |
|
|
78 | } |
|
|
79 | |
|
|
80 | // check to see wether this combination already exists otherwise |
|
|
81 | for (cc = v.end (); cc-- > v.begin (); ) |
|
|
82 | { |
|
|
83 | if (cc->c1 == c1 && cc->c2 == c2) |
|
|
84 | return COMPOSE_LO + (cc - v.begin ()); |
|
|
85 | } |
|
|
86 | |
|
|
87 | // allocate a new combination |
|
|
88 | if (v.size () == COMPOSE_HI - COMPOSE_LO + 1) |
|
|
89 | { |
|
|
90 | static int seen; |
|
|
91 | |
|
|
92 | if (!seen++) |
|
|
93 | fprintf (stderr, "too many unrepresentable composite characters, try --enable-unicode3\n"); |
|
|
94 | |
|
|
95 | return REPLACEMENT_CHAR; |
|
|
96 | } |
|
|
97 | |
|
|
98 | v.push_back (compose_char (c1, c2)); |
|
|
99 | |
|
|
100 | return v.size () - 1 + COMPOSE_LO; |
58 | } |
101 | } |
|
|
102 | |
|
|
103 | int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) |
|
|
104 | { |
|
|
105 | compose_char *cc = (*this)[c]; |
|
|
106 | |
|
|
107 | if (!cc) |
|
|
108 | { |
|
|
109 | if (r) *r = c; |
|
|
110 | return 1; |
|
|
111 | } |
|
|
112 | |
|
|
113 | int len = expand (cc->c1, r); |
|
|
114 | |
|
|
115 | if (r) r += len; |
|
|
116 | |
|
|
117 | if (cc->c2 != NOCHAR) |
|
|
118 | { |
|
|
119 | len++; |
|
|
120 | if (r) *r++ = cc->c2; |
|
|
121 | } |
|
|
122 | |
|
|
123 | return len; |
|
|
124 | |
|
|
125 | } |
|
|
126 | #endif |
59 | |
127 | |
60 | void * |
128 | void * |
61 | rxvt_term::operator new (size_t s) |
129 | rxvt_term::operator new (size_t s) |
62 | { |
130 | { |
63 | void *p = malloc (s); |
131 | void *p = malloc (s); |
… | |
… | |
72 | free (p); |
140 | free (p); |
73 | } |
141 | } |
74 | |
142 | |
75 | rxvt_term::rxvt_term () |
143 | rxvt_term::rxvt_term () |
76 | : |
144 | : |
|
|
145 | #if TRANSPARENT |
77 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
|
|
147 | #endif |
|
|
148 | #ifdef HAVE_SCROLLBARS |
|
|
149 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
150 | #endif |
|
|
151 | #ifdef MENUBAR |
|
|
152 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef CURSOR_BLINK |
|
|
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
156 | #endif |
|
|
157 | #ifdef TEXT_BLINK |
|
|
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
159 | #endif |
|
|
160 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
161 | cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), |
|
|
162 | #endif |
|
|
163 | #ifdef SELECTION_SCROLLING |
|
|
164 | sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), |
|
|
165 | #endif |
|
|
166 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
|
|
167 | slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), |
|
|
168 | #endif |
|
|
169 | #ifdef POINTER_BLANK |
|
|
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
171 | #endif |
|
|
172 | #ifdef USE_XIM |
|
|
173 | im_ev (this, &rxvt_term::im_cb), |
|
|
174 | #endif |
78 | termwin_ev (this, &rxvt_term::x_cb), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
79 | vt_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
80 | #ifdef HAVE_SCROLLBARS |
|
|
81 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
82 | #endif |
|
|
83 | #ifdef MENUBAR |
|
|
84 | menubar_ev (this, &rxvt_term::x_cb), fixme |
|
|
85 | #endif |
|
|
86 | #ifdef CURSOR_BLINK |
|
|
87 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
88 | #endif |
|
|
89 | #ifdef TEXT_BLINK |
|
|
90 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
91 | #endif |
|
|
92 | #ifdef POINTER_BLANK |
|
|
93 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
94 | #endif |
|
|
95 | check_ev (this, &rxvt_term::check_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
|
|
178 | flush_ev (this, &rxvt_term::flush_cb), |
96 | destroy_ev (this, &rxvt_term::destroy_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
97 | pty_ev (this, &rxvt_term::pty_cb), |
180 | pty_ev (this, &rxvt_term::pty_cb), |
98 | incr_ev (this, &rxvt_term::incr_cb) |
181 | incr_ev (this, &rxvt_term::incr_cb) |
99 | { |
182 | { |
100 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
183 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
|
|
184 | |
|
|
185 | termlist.push_back (this); |
101 | } |
186 | } |
102 | |
187 | |
103 | rxvt_term::~rxvt_term () |
188 | rxvt_term::~rxvt_term () |
104 | { |
189 | { |
105 | scr_release (); |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
106 | |
191 | |
107 | free (locale); |
192 | if (cmd_fd >= 0) |
108 | free (codeset); |
193 | close (cmd_fd); |
109 | |
194 | |
110 | #ifndef NO_SETOWNER_TTYDEV |
195 | #ifndef NO_SETOWNER_TTYDEV |
111 | privileged_ttydev (RESTORE); |
196 | privileged_ttydev (RESTORE); |
112 | #endif |
197 | #endif |
113 | #ifdef UTMP_SUPPORT |
198 | #ifdef UTMP_SUPPORT |
114 | privileged_utmp (RESTORE); |
199 | privileged_utmp (RESTORE); |
115 | #endif |
200 | #endif |
|
|
201 | |
|
|
202 | delete TermWin.fontset; |
|
|
203 | |
|
|
204 | if (display) |
|
|
205 | { |
|
|
206 | selection_clear (); |
|
|
207 | |
116 | #ifdef USE_XIM |
208 | #ifdef USE_XIM |
117 | if (Input_Context) |
209 | im_destroy (); |
118 | { |
|
|
119 | XDestroyIC (Input_Context); |
|
|
120 | Input_Context = NULL; |
|
|
121 | } |
|
|
122 | #endif |
210 | #endif |
|
|
211 | #ifdef MENUBAR |
|
|
212 | if (menubarGC) XFreeGC (display->display, menubarGC); |
|
|
213 | #endif |
|
|
214 | #ifdef XTERM_SCROLLBAR |
|
|
215 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
|
|
216 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
|
|
217 | #endif |
|
|
218 | #ifdef PLAIN_SCROLLBAR |
|
|
219 | if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); |
|
|
220 | #endif |
|
|
221 | #ifdef NEXT_SCROLLBAR |
|
|
222 | if (blackGC) XFreeGC (display->display, blackGC); |
|
|
223 | if (whiteGC) XFreeGC (display->display, whiteGC); |
|
|
224 | if (grayGC) XFreeGC (display->display, grayGC); |
|
|
225 | if (darkGC) XFreeGC (display->display, darkGC); |
|
|
226 | if (stippleGC) XFreeGC (display->display, stippleGC); |
|
|
227 | if (dimple) XFreePixmap (display->display, dimple); |
|
|
228 | if (upArrow) XFreePixmap (display->display, upArrow); |
|
|
229 | if (downArrow) XFreePixmap (display->display, downArrow); |
|
|
230 | if (upArrowHi) XFreePixmap (display->display, upArrowHi); |
|
|
231 | if (downArrowHi) XFreePixmap (display->display, downArrowHi); |
|
|
232 | #endif |
|
|
233 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
|
|
234 | if (topShadowGC) XFreeGC (display->display, topShadowGC); |
|
|
235 | if (botShadowGC) XFreeGC (display->display, botShadowGC); |
|
|
236 | if (scrollbarGC) XFreeGC (display->display, scrollbarGC); |
|
|
237 | #endif |
|
|
238 | if (TermWin.gc) XFreeGC (display->display, TermWin.gc); |
123 | |
239 | |
|
|
240 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
|
|
241 | delete menuBar.drawable; |
|
|
242 | //if (menuBar.win) |
|
|
243 | // XDestroyWindow (display->display, menuBar.win); |
|
|
244 | #endif |
|
|
245 | delete TermWin.drawable; |
|
|
246 | // destroy all windows |
124 | if (TermWin.parent[0]) |
247 | if (TermWin.parent[0]) |
125 | XDestroyWindow (display->display, TermWin.parent[0]); |
248 | XDestroyWindow (display->display, TermWin.parent[0]); |
|
|
249 | } |
126 | |
250 | |
127 | // TODO: free pixcolours, colours should become part of rxvt_display |
251 | // TODO: free pixcolours, colours should become part of rxvt_display |
128 | |
252 | |
129 | delete PixColors; |
253 | delete PixColorsFocused; |
|
|
254 | #ifdef OFF_FOCUS_FADING |
|
|
255 | delete PixColorsUnFocused; |
|
|
256 | #endif |
130 | |
257 | |
131 | if (cmd_fd >= 0) |
258 | displays.put (display); |
132 | close (cmd_fd); |
259 | |
|
|
260 | scr_release (); |
|
|
261 | |
|
|
262 | /* clear all resources */ |
|
|
263 | for (int i = 0; i < allocated.size (); i++) |
|
|
264 | free (allocated[i]); |
|
|
265 | |
|
|
266 | free (selection.text); |
|
|
267 | // TODO: manage env vars in child only(!) |
|
|
268 | free (env_windowid); |
|
|
269 | free (env_display); |
|
|
270 | free (env_term); |
|
|
271 | free (env_colorfgbg); |
|
|
272 | free (locale); |
|
|
273 | #if 0 |
|
|
274 | free (codeset); |
|
|
275 | #endif |
|
|
276 | |
|
|
277 | delete envv; |
|
|
278 | delete argv; |
|
|
279 | } |
|
|
280 | |
|
|
281 | void |
|
|
282 | rxvt_term::destroy () |
|
|
283 | { |
|
|
284 | if (destroy_ev.active) |
|
|
285 | return; |
133 | |
286 | |
134 | if (display) |
287 | if (display) |
135 | displays.release (display); |
|
|
136 | } |
|
|
137 | |
|
|
138 | void |
|
|
139 | rxvt_term::destroy () |
|
|
140 | { |
|
|
141 | if (display) |
|
|
142 | { |
288 | { |
|
|
289 | #if USE_XIM |
|
|
290 | im_ev.stop (display); |
|
|
291 | #endif |
|
|
292 | #if HAVE_SCROLLBARS |
|
|
293 | scrollbar_ev.stop (display); |
|
|
294 | #endif |
|
|
295 | #if MENUBAR |
|
|
296 | menubar_ev.stop (display); |
|
|
297 | #endif |
|
|
298 | #if TRANSPARENT |
|
|
299 | rootwin_ev.stop (display); |
|
|
300 | #endif |
|
|
301 | incr_ev.stop (); |
143 | termwin_ev.stop (display); |
302 | termwin_ev.stop (display); |
144 | vt_ev.stop (display); |
303 | vt_ev.stop (display); |
145 | #ifdef HAVE_SCROLLBARS |
|
|
146 | scrollbar_ev.stop (display); |
|
|
147 | #endif |
|
|
148 | #ifdef MENUBAR |
|
|
149 | menubar_ev.stop (display); |
|
|
150 | #endif |
|
|
151 | } |
304 | } |
152 | |
305 | |
153 | check_ev.stop (); |
306 | check_ev.stop (); |
154 | pty_ev.stop (); |
307 | pty_ev.stop (); |
155 | #ifdef CURSOR_BLINK |
308 | #ifdef CURSOR_BLINK |
156 | cursor_blink_ev.stop (); |
309 | cursor_blink_ev.stop (); |
157 | #endif |
310 | #endif |
158 | #ifdef TEXT_BLINK |
311 | #ifdef TEXT_BLINK |
159 | text_blink_ev.stop (); |
312 | text_blink_ev.stop (); |
160 | #endif |
313 | #endif |
|
|
314 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
315 | cont_scroll_ev.stop (); |
|
|
316 | #endif |
|
|
317 | #ifdef SELECTION_SCROLLING |
|
|
318 | sel_scroll_ev.stop (); |
|
|
319 | #endif |
161 | #ifdef POINTER_BLANK |
320 | #ifdef POINTER_BLANK |
162 | pointer_ev.stop (); |
321 | pointer_ev.stop (); |
163 | #endif |
322 | #endif |
164 | |
323 | |
165 | destroy_ev.start (0); |
324 | destroy_ev.start (0); |
… | |
… | |
172 | |
331 | |
173 | delete this; |
332 | delete this; |
174 | } |
333 | } |
175 | |
334 | |
176 | /*----------------------------------------------------------------------*/ |
335 | /*----------------------------------------------------------------------*/ |
177 | /* rxvt_init() */ |
336 | /* rxvt_init () */ |
178 | /* LIBPROTO */ |
|
|
179 | rxvt_t |
|
|
180 | rxvt_init (int argc, const char *const *argv) |
|
|
181 | { |
|
|
182 | SET_R (new rxvt_term); |
|
|
183 | |
|
|
184 | if (!GET_R->init_vars () || !GET_R->init (argc, argv)) |
|
|
185 | { |
|
|
186 | delete GET_R; |
|
|
187 | SET_R (0); |
|
|
188 | } |
|
|
189 | |
|
|
190 | return GET_R; |
|
|
191 | } |
|
|
192 | |
|
|
193 | static int (*old_xerror_handler)(Display *dpy, XErrorEvent *event); |
|
|
194 | |
|
|
195 | void |
|
|
196 | rxvt_init_signals () |
|
|
197 | { |
|
|
198 | /* install exit handler for cleanup */ |
|
|
199 | #if 0 |
|
|
200 | #ifdef HAVE_ATEXIT |
|
|
201 | atexit(rxvt_clean_exit); |
|
|
202 | #else |
|
|
203 | #endif |
|
|
204 | #endif |
|
|
205 | |
|
|
206 | struct sigaction sa; |
|
|
207 | |
|
|
208 | sigfillset (&sa.sa_mask); |
|
|
209 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
210 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
211 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
212 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
213 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
214 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
215 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
216 | |
|
|
217 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
218 | /* signal (SIGURG, SIG_DFL); */ |
|
|
219 | |
|
|
220 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
221 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
|
|
222 | } |
|
|
223 | |
|
|
224 | bool |
337 | bool |
225 | rxvt_term::init (int argc, const char *const *argv) |
338 | rxvt_term::init (int argc, const char *const *argv) |
226 | { |
339 | { |
|
|
340 | SET_R (this); |
|
|
341 | |
|
|
342 | if (!init_vars ()) |
|
|
343 | return false; |
|
|
344 | |
227 | /* |
345 | /* |
228 | * Save and then give up any super-user privileges |
346 | * Save and then give up any super-user privileges |
229 | * If we need privileges in any area then we must specifically request it. |
347 | * If we need privileges in any area then we must specifically request it. |
230 | * We should only need to be root in these cases: |
348 | * We should only need to be root in these cases: |
231 | * 1. write utmp entries on some systems |
349 | * 1. write utmp entries on some systems |
… | |
… | |
238 | |
356 | |
239 | const char **cmd_argv = init_resources (argc, argv); |
357 | const char **cmd_argv = init_resources (argc, argv); |
240 | |
358 | |
241 | set_locale (""); |
359 | set_locale (""); |
242 | |
360 | |
243 | #if (MENUBAR_MAX) |
361 | #if MENUBAR_MAX |
244 | menubar_read (rs[Rs_menu]); |
362 | menubar_read (rs[Rs_menu]); |
245 | #endif |
363 | #endif |
246 | #ifdef HAVE_SCROLLBARS |
364 | #ifdef HAVE_SCROLLBARS |
247 | if (Options & Opt_scrollBar) |
365 | if (Options & Opt_scrollBar) |
248 | scrollBar.setIdle (); /* set existence for size calculations */ |
366 | scrollBar.setIdle (); /* set existence for size calculations */ |
… | |
… | |
251 | create_windows (argc, argv); |
369 | create_windows (argc, argv); |
252 | |
370 | |
253 | init_xlocale (); |
371 | init_xlocale (); |
254 | |
372 | |
255 | scr_reset (); /* initialize screen */ |
373 | scr_reset (); /* initialize screen */ |
256 | #ifdef RXVT_GRAPHICS |
|
|
257 | Gr_reset (); /* reset graphics */ |
|
|
258 | #endif |
|
|
259 | |
374 | |
260 | #if 0 |
375 | #if 0 |
261 | #ifdef DEBUG_X |
|
|
262 | XSynchronize(display->display, True); |
376 | XSynchronize (display->display, True); |
263 | #endif |
|
|
264 | #endif |
377 | #endif |
265 | |
378 | |
266 | #ifdef HAVE_SCROLLBARS |
379 | #ifdef HAVE_SCROLLBARS |
267 | if (Options & Opt_scrollBar) |
380 | if (Options & Opt_scrollBar) |
268 | resize_scrollbar (); /* create and map scrollbar */ |
381 | resize_scrollbar (); /* create and map scrollbar */ |
269 | #endif |
382 | #endif |
270 | #if (MENUBAR_MAX) |
383 | #if (MENUBAR_MAX) |
271 | if (menubar_visible(r)) |
384 | if (menubar_visible ()) |
272 | XMapWindow (display->display, menuBar.win); |
385 | XMapWindow (display->display, menuBar.win); |
273 | #endif |
386 | #endif |
274 | #ifdef TRANSPARENT |
387 | #ifdef TRANSPARENT |
275 | if (Options & Opt_transparent) |
388 | if (Options & Opt_transparent) |
276 | { |
389 | { |
277 | XSelectInput (display->display, display->root, PropertyChangeMask); |
390 | XSelectInput (display->display, display->root, PropertyChangeMask); |
278 | check_our_parents (); |
391 | check_our_parents (); |
279 | } |
|
|
280 | #endif |
|
|
281 | |
|
|
282 | rootwin_ev.start (display, display->root); |
392 | rootwin_ev.start (display, display->root); |
|
|
393 | } |
|
|
394 | #endif |
283 | |
395 | |
284 | XMapWindow (display->display, TermWin.vt); |
396 | XMapWindow (display->display, TermWin.vt); |
285 | XMapWindow (display->display, TermWin.parent[0]); |
397 | XMapWindow (display->display, TermWin.parent[0]); |
286 | |
398 | |
287 | init_env (); |
|
|
288 | init_command (cmd_argv); |
399 | init_command (cmd_argv); |
289 | |
400 | |
290 | pty_ev.start (cmd_fd, EVENT_READ); |
401 | pty_ev.start (cmd_fd, EVENT_READ); |
291 | |
402 | |
292 | check_ev.start (); |
403 | check_ev.start (); |
293 | |
404 | |
294 | return true; |
405 | return true; |
|
|
406 | } |
|
|
407 | |
|
|
408 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
409 | |
|
|
410 | void |
|
|
411 | rxvt_init_signals () |
|
|
412 | { |
|
|
413 | /* install exit handler for cleanup */ |
|
|
414 | #if 0 |
|
|
415 | #ifdef HAVE_ATEXIT |
|
|
416 | atexit (rxvt_clean_exit); |
|
|
417 | #else |
|
|
418 | #endif |
|
|
419 | #endif |
|
|
420 | |
|
|
421 | struct sigaction sa; |
|
|
422 | |
|
|
423 | sigfillset (&sa.sa_mask); |
|
|
424 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
425 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
426 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
427 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
428 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
429 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
430 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
431 | |
|
|
432 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
433 | /* signal (SIGURG, SIG_DFL); */ |
|
|
434 | |
|
|
435 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
436 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
295 | } |
437 | } |
296 | |
438 | |
297 | /* ------------------------------------------------------------------------- * |
439 | /* ------------------------------------------------------------------------- * |
298 | * SIGNAL HANDLING & EXIT HANDLER * |
440 | * SIGNAL HANDLING & EXIT HANDLER * |
299 | * ------------------------------------------------------------------------- */ |
441 | * ------------------------------------------------------------------------- */ |
300 | /* |
442 | /* |
301 | * Catch a SIGCHLD signal and exit if the direct child has died |
443 | * Catch a SIGCHLD signal and exit if the direct child has died |
302 | */ |
444 | */ |
|
|
445 | |
|
|
446 | void rxvt_term::child_exited (int pid) |
|
|
447 | { |
|
|
448 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
449 | if (pid == (*t)->cmd_pid) |
|
|
450 | { |
|
|
451 | (*t)->destroy (); |
|
|
452 | break; |
|
|
453 | } |
|
|
454 | } |
|
|
455 | |
303 | /* ARGSUSED */ |
456 | /* ARGSUSED */ |
304 | /* EXTPROTO */ |
457 | /* EXTPROTO */ |
305 | RETSIGTYPE |
458 | RETSIGTYPE |
306 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
459 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
307 | { |
460 | { |
308 | int pid, save_errno = errno; |
461 | int pid, save_errno = errno; |
|
|
462 | |
309 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
463 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
310 | ; |
464 | rxvt_term::child_exited (pid); |
|
|
465 | |
311 | errno = save_errno; |
466 | errno = save_errno; |
312 | |
|
|
313 | #if 0 |
|
|
314 | if (pid == cmd_pid) |
|
|
315 | exit (EXIT_SUCCESS); |
|
|
316 | #endif |
|
|
317 | } |
467 | } |
318 | |
468 | |
319 | /* |
469 | /* |
320 | * Catch a fatal signal and tidy up before quitting |
470 | * Catch a fatal signal and tidy up before quitting |
321 | */ |
471 | */ |
322 | /* EXTPROTO */ |
472 | /* EXTPROTO */ |
323 | RETSIGTYPE |
473 | RETSIGTYPE |
324 | rxvt_Exit_signal(int sig) |
474 | rxvt_Exit_signal (int sig) |
325 | { |
475 | { |
326 | signal(sig, SIG_DFL); |
476 | signal (sig, SIG_DFL); |
327 | #ifdef DEBUG_CMD |
477 | #ifdef DEBUG_CMD |
328 | rxvt_print_error("signal %d", sig); |
478 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
329 | #endif |
479 | #endif |
330 | rxvt_clean_exit(); |
480 | rxvt_clean_exit (); |
331 | kill(getpid(), sig); |
481 | kill (getpid (), sig); |
332 | } |
482 | } |
333 | |
483 | |
334 | /* INTPROTO */ |
484 | /* INTPROTO */ |
335 | int |
485 | int |
336 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
486 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
… | |
… | |
353 | */ |
503 | */ |
354 | /* EXTPROTO */ |
504 | /* EXTPROTO */ |
355 | void |
505 | void |
356 | rxvt_clean_exit () |
506 | rxvt_clean_exit () |
357 | { |
507 | { |
|
|
508 | // TODO: rxvtd should clean up all ressources |
|
|
509 | if (GET_R) |
358 | GET_R->destroy (); |
510 | GET_R->destroy (); |
359 | } |
511 | } |
360 | |
512 | |
361 | /* ------------------------------------------------------------------------- * |
513 | /* ------------------------------------------------------------------------- * |
362 | * MEMORY ALLOCATION WRAPPERS * |
514 | * MEMORY ALLOCATION WRAPPERS * |
363 | * ------------------------------------------------------------------------- */ |
515 | * ------------------------------------------------------------------------- */ |
364 | /* EXTPROTO */ |
516 | /* EXTPROTO */ |
365 | void * |
517 | void * |
366 | rxvt_malloc(size_t size) |
518 | rxvt_malloc (size_t size) |
367 | { |
519 | { |
368 | void *p; |
520 | void *p; |
369 | |
521 | |
370 | p = malloc(size); |
522 | p = malloc (size); |
371 | if (p) |
523 | if (p) |
372 | return p; |
524 | return p; |
373 | |
525 | |
374 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
526 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
375 | rxvt_clean_exit(); |
527 | rxvt_clean_exit (); |
376 | exit(EXIT_FAILURE); |
528 | exit (EXIT_FAILURE); |
377 | /* NOTREACHED */ |
529 | /* NOTREACHED */ |
378 | } |
530 | } |
379 | |
531 | |
380 | /* EXTPROTO */ |
532 | /* EXTPROTO */ |
381 | void * |
533 | void * |
382 | rxvt_calloc(size_t number, size_t size) |
534 | rxvt_calloc (size_t number, size_t size) |
383 | { |
535 | { |
384 | void *p; |
536 | void *p; |
385 | |
537 | |
386 | p = calloc(number, size); |
538 | p = calloc (number, size); |
387 | if (p) |
539 | if (p) |
388 | return p; |
540 | return p; |
389 | |
541 | |
390 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
542 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
391 | rxvt_clean_exit(); |
543 | rxvt_clean_exit (); |
392 | exit(EXIT_FAILURE); |
544 | exit (EXIT_FAILURE); |
393 | /* NOTREACHED */ |
545 | /* NOTREACHED */ |
394 | } |
546 | } |
395 | |
547 | |
396 | /* EXTPROTO */ |
548 | /* EXTPROTO */ |
397 | void * |
549 | void * |
398 | rxvt_realloc(void *ptr, size_t size) |
550 | rxvt_realloc (void *ptr, size_t size) |
399 | { |
551 | { |
400 | void *p; |
552 | void *p; |
401 | |
553 | |
402 | if (ptr) |
554 | if (ptr) |
403 | p = realloc(ptr, size); |
555 | p = realloc (ptr, size); |
404 | else |
556 | else |
405 | p = malloc(size); |
557 | p = malloc (size); |
406 | if (p) |
558 | if (p) |
407 | return p; |
559 | return p; |
408 | |
560 | |
409 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
561 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
410 | rxvt_clean_exit(); |
562 | rxvt_clean_exit (); |
411 | exit(EXIT_FAILURE); |
563 | exit (EXIT_FAILURE); |
412 | /* NOTREACHED */ |
564 | /* NOTREACHED */ |
413 | } |
565 | } |
414 | |
566 | |
415 | /* ------------------------------------------------------------------------- * |
567 | /* ------------------------------------------------------------------------- * |
416 | * PRIVILEGED OPERATIONS * |
568 | * PRIVILEGED OPERATIONS * |
… | |
… | |
419 | void |
571 | void |
420 | rxvt_term::privileges (int mode) |
572 | rxvt_term::privileges (int mode) |
421 | { |
573 | { |
422 | #if ! defined(__CYGWIN32__) |
574 | #if ! defined(__CYGWIN32__) |
423 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
575 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
424 | /* setreuid() is the poor man's setuid(), seteuid() */ |
576 | /* setreuid () is the poor man's setuid (), seteuid () */ |
425 | # define seteuid(a) setreuid(-1, (a)) |
577 | # define seteuid(a) setreuid(-1, (a)) |
426 | # define setegid(a) setregid(-1, (a)) |
578 | # define setegid(a) setregid(-1, (a)) |
427 | # define HAVE_SETEUID |
579 | # define HAVE_SETEUID |
428 | # endif |
580 | # endif |
429 | # ifdef HAVE_SETEUID |
581 | # ifdef HAVE_SETEUID |
… | |
… | |
432 | case IGNORE: |
584 | case IGNORE: |
433 | /* |
585 | /* |
434 | * change effective uid/gid - not real uid/gid - so we can switch |
586 | * change effective uid/gid - not real uid/gid - so we can switch |
435 | * back to root later, as required |
587 | * back to root later, as required |
436 | */ |
588 | */ |
437 | seteuid(getuid()); |
589 | seteuid (getuid ()); |
438 | setegid(getgid()); |
590 | setegid (getgid ()); |
439 | break; |
591 | break; |
440 | case SAVE: |
592 | case SAVE: |
441 | euid = geteuid(); |
593 | euid = geteuid (); |
442 | egid = getegid(); |
594 | egid = getegid (); |
443 | break; |
595 | break; |
444 | case RESTORE: |
596 | case RESTORE: |
445 | seteuid(euid); |
597 | seteuid (euid); |
446 | setegid(egid); |
598 | setegid (egid); |
447 | break; |
599 | break; |
448 | } |
600 | } |
449 | # else |
601 | # else |
450 | switch (mode) |
602 | switch (mode) |
451 | { |
603 | { |
452 | case IGNORE: |
604 | case IGNORE: |
453 | setuid(getuid()); |
605 | setuid (getuid ()); |
454 | setgid(getgid()); |
606 | setgid (getgid ()); |
455 | /* FALLTHROUGH */ |
607 | /* FALLTHROUGH */ |
456 | case SAVE: |
608 | case SAVE: |
457 | /* FALLTHROUGH */ |
609 | /* FALLTHROUGH */ |
458 | case RESTORE: |
610 | case RESTORE: |
459 | break; |
611 | break; |
… | |
… | |
464 | |
616 | |
465 | #ifdef UTMP_SUPPORT |
617 | #ifdef UTMP_SUPPORT |
466 | void |
618 | void |
467 | rxvt_term::privileged_utmp (char action) |
619 | rxvt_term::privileged_utmp (char action) |
468 | { |
620 | { |
469 | D_MAIN((stderr, "rxvt_privileged_utmp(%c); waiting for: %c (pid: %d)", |
621 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
470 | action, next_utmp_action, getpid())); |
622 | action, next_utmp_action, getpid ())); |
471 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
623 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
472 | || (Options & Opt_utmpInhibit) |
624 | || (Options & Opt_utmpInhibit) |
473 | || ttydev == NULL || *ttydev == '\0') |
625 | || ttydev == NULL || *ttydev == '\0') |
474 | return; |
626 | return; |
475 | |
627 | |
… | |
… | |
490 | |
642 | |
491 | #ifndef NO_SETOWNER_TTYDEV |
643 | #ifndef NO_SETOWNER_TTYDEV |
492 | void |
644 | void |
493 | rxvt_term::privileged_ttydev (char action) |
645 | rxvt_term::privileged_ttydev (char action) |
494 | { |
646 | { |
495 | D_MAIN((stderr, |
647 | D_MAIN ((stderr, |
496 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
648 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
497 | action, next_tty_action, getpid())); |
649 | action, next_tty_action, getpid ())); |
498 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
650 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
499 | || ttydev == NULL || *ttydev == '\0') |
651 | || ttydev == NULL || *ttydev == '\0') |
500 | return; |
652 | return; |
501 | |
653 | |
502 | privileges (RESTORE); |
654 | privileges (RESTORE); |
503 | |
655 | |
504 | if (action == SAVE) |
656 | if (action == SAVE) |
505 | { |
657 | { |
506 | next_tty_action = RESTORE; |
658 | next_tty_action = RESTORE; |
507 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
659 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
508 | /* store original tty status for restoration rxvt_clean_exit() -- rgg 04/12/95 */ |
660 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
509 | if (lstat(ttydev, &ttyfd_stat) < 0) /* you lose out */ |
661 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
510 | next_tty_action = IGNORE; |
662 | next_tty_action = IGNORE; |
511 | else |
663 | else |
512 | # endif |
664 | # endif |
513 | |
665 | |
514 | { |
666 | { |
515 | chown(ttydev, getuid(), ttygid); /* fail silently */ |
667 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
516 | chmod(ttydev, ttymode); |
668 | chmod (ttydev, ttymode); |
517 | # ifdef HAVE_REVOKE |
669 | # ifdef HAVE_REVOKE |
518 | revoke(ttydev); |
670 | revoke (ttydev); |
519 | # endif |
671 | # endif |
520 | |
672 | |
521 | } |
673 | } |
522 | } |
674 | } |
523 | else |
675 | else |
524 | { /* action == RESTORE */ |
676 | { /* action == RESTORE */ |
525 | next_tty_action = IGNORE; |
677 | next_tty_action = IGNORE; |
526 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
678 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
527 | chmod(ttydev, ttyfd_stat.st_mode); |
679 | chmod (ttydev, ttyfd_stat.st_mode); |
528 | chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
680 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
529 | # else |
681 | # else |
530 | chmod(ttydev, |
682 | chmod (ttydev, |
531 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
683 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
532 | chown(ttydev, 0, 0); |
684 | chown (ttydev, 0, 0); |
533 | # endif |
685 | # endif |
534 | |
686 | |
535 | } |
687 | } |
536 | |
688 | |
537 | privileges (IGNORE); |
689 | privileges (IGNORE); |
538 | |
690 | |
539 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
691 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
540 | D_MAIN((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
692 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
541 | action == RESTORE ? "Restoring" : (action == |
693 | action == RESTORE ? "Restoring" : (action == |
542 | SAVE ? "Saving" : |
694 | SAVE ? "Saving" : |
543 | "UNKNOWN ERROR for"), ttydev, |
695 | "UNKNOWN ERROR for"), ttydev, |
544 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
696 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
545 | ttyfd_stat.st_gid)); |
697 | ttyfd_stat.st_gid)); |
… | |
… | |
558 | short recalc_x, recalc_y; |
710 | short recalc_x, recalc_y; |
559 | int x, y, sb_w, mb_h, flags; |
711 | int x, y, sb_w, mb_h, flags; |
560 | unsigned int w, h; |
712 | unsigned int w, h; |
561 | unsigned int max_width, max_height; |
713 | unsigned int max_width, max_height; |
562 | |
714 | |
563 | D_SIZE((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
715 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
564 | TermWin.ncol, TermWin.nrow, szHint.width, |
716 | TermWin.ncol, TermWin.nrow, szHint.width, |
565 | szHint.height)); |
717 | szHint.height)); |
566 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
718 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
567 | szHint.win_gravity = NorthWestGravity; |
719 | szHint.win_gravity = NorthWestGravity; |
568 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
720 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
… | |
… | |
571 | flags = 0; |
723 | flags = 0; |
572 | if (!parsed_geometry) |
724 | if (!parsed_geometry) |
573 | { |
725 | { |
574 | parsed_geometry = 1; |
726 | parsed_geometry = 1; |
575 | if (rs[Rs_geometry]) |
727 | if (rs[Rs_geometry]) |
576 | flags = XParseGeometry(rs[Rs_geometry], &x, &y, &w, &h); |
728 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
577 | if (flags & WidthValue) |
729 | if (flags & WidthValue) |
578 | { |
730 | { |
579 | TermWin.ncol = BOUND_POSITIVE_INT16(w); |
731 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
580 | szHint.flags |= USSize; |
732 | szHint.flags |= USSize; |
581 | } |
733 | } |
582 | if (flags & HeightValue) |
734 | if (flags & HeightValue) |
583 | { |
735 | { |
584 | TermWin.nrow = BOUND_POSITIVE_INT16(h); |
736 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
585 | szHint.flags |= USSize; |
737 | szHint.flags |= USSize; |
586 | } |
738 | } |
587 | if (flags & XValue) |
739 | if (flags & XValue) |
588 | { |
740 | { |
589 | szHint.x = x; |
741 | szHint.x = x; |
… | |
… | |
606 | else |
758 | else |
607 | szHint.win_gravity = SouthWestGravity; |
759 | szHint.win_gravity = SouthWestGravity; |
608 | } |
760 | } |
609 | } |
761 | } |
610 | } |
762 | } |
|
|
763 | |
611 | /* TODO: BOUNDS */ |
764 | /* TODO: BOUNDS */ |
612 | TermWin.width = TermWin.ncol * TermWin.fwidth; |
765 | TermWin.width = TermWin.ncol * TermWin.fwidth; |
613 | TermWin.height = TermWin.nrow * TermWin.fheight; |
766 | TermWin.height = TermWin.nrow * TermWin.fheight; |
614 | max_width = MAX_COLS * TermWin.fwidth; |
767 | max_width = MAX_COLS * TermWin.fwidth; |
615 | max_height = MAX_ROWS * TermWin.fheight; |
768 | max_height = MAX_ROWS * TermWin.fheight; |
616 | |
769 | |
617 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
770 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
618 | |
771 | |
619 | sb_w = mb_h = 0; |
772 | sb_w = mb_h = 0; |
620 | window_vt_x = window_vt_y = 0; |
773 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
|
|
774 | |
621 | if (scrollbar_visible ()) |
775 | if (scrollbar_visible ()) |
622 | { |
776 | { |
623 | sb_w = scrollbar_TotalWidth(); |
777 | sb_w = scrollbar_TotalWidth (); |
624 | szHint.base_width += sb_w; |
778 | szHint.base_width += sb_w; |
625 | if (!(Options & Opt_scrollBar_right)) |
779 | if (!(Options & Opt_scrollBar_right)) |
626 | window_vt_x = sb_w; |
780 | window_vt_x += sb_w; |
627 | } |
781 | } |
|
|
782 | |
628 | if (menubar_visible ()) |
783 | if (menubar_visible ()) |
629 | { |
784 | { |
630 | mb_h = menuBar_TotalHeight(); |
785 | mb_h = menuBar_TotalHeight (); |
631 | szHint.base_height += mb_h; |
786 | szHint.base_height += mb_h; |
632 | window_vt_y = mb_h; |
787 | window_vt_y += mb_h; |
633 | } |
788 | } |
|
|
789 | |
634 | szHint.width_inc = TermWin.fwidth; |
790 | szHint.width_inc = TermWin.fwidth; |
635 | szHint.height_inc = TermWin.fheight; |
791 | szHint.height_inc = TermWin.fheight; |
636 | szHint.min_width = szHint.base_width + szHint.width_inc; |
792 | szHint.min_width = szHint.base_width + szHint.width_inc; |
637 | szHint.min_height = szHint.base_height + szHint.height_inc; |
793 | szHint.min_height = szHint.base_height + szHint.height_inc; |
638 | |
794 | |
… | |
… | |
641 | szHint.width = width; |
797 | szHint.width = width; |
642 | TermWin.width = width - szHint.base_width; |
798 | TermWin.width = width - szHint.base_width; |
643 | } |
799 | } |
644 | else |
800 | else |
645 | { |
801 | { |
646 | MIN_IT(TermWin.width, max_width); |
802 | MIN_IT (TermWin.width, max_width); |
647 | szHint.width = szHint.base_width + TermWin.width; |
803 | szHint.width = szHint.base_width + TermWin.width; |
648 | } |
804 | } |
|
|
805 | |
649 | if (height && height - szHint.base_height < max_height) |
806 | if (height && height - szHint.base_height < max_height) |
650 | { |
807 | { |
651 | szHint.height = height; |
808 | szHint.height = height; |
652 | TermWin.height = height - szHint.base_height; |
809 | TermWin.height = height - szHint.base_height; |
653 | } |
810 | } |
654 | else |
811 | else |
655 | { |
812 | { |
656 | MIN_IT(TermWin.height, max_height); |
813 | MIN_IT (TermWin.height, max_height); |
657 | szHint.height = szHint.base_height + TermWin.height; |
814 | szHint.height = szHint.base_height + TermWin.height; |
658 | } |
815 | } |
|
|
816 | |
659 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
817 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
660 | window_sb_x = szHint.width - sb_w; |
818 | window_sb_x = szHint.width - sb_w; |
661 | |
819 | |
662 | if (recalc_x) |
820 | if (recalc_x) |
663 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
821 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
… | |
… | |
666 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
824 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
667 | - szHint.height - 2 * TermWin.ext_bwidth); |
825 | - szHint.height - 2 * TermWin.ext_bwidth); |
668 | |
826 | |
669 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
827 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
670 | TermWin.nrow = TermWin.height / TermWin.fheight; |
828 | TermWin.nrow = TermWin.height / TermWin.fheight; |
671 | D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
829 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
672 | TermWin.ncol, TermWin.nrow, szHint.width, |
830 | TermWin.ncol, TermWin.nrow, szHint.width, |
673 | szHint.height)); |
831 | szHint.height)); |
674 | return; |
832 | return; |
675 | } |
833 | } |
676 | |
834 | |
… | |
… | |
692 | ws.ws_xpixel = ws.ws_ypixel = 0; |
850 | ws.ws_xpixel = ws.ws_ypixel = 0; |
693 | #ifndef DEBUG_SIZE |
851 | #ifndef DEBUG_SIZE |
694 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
852 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
695 | #else |
853 | #else |
696 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
854 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
697 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
855 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
698 | # ifdef SIGWINCH |
856 | # ifdef SIGWINCH |
699 | else if (cmd_pid) /* force through to the command */ |
857 | else if (cmd_pid) /* force through to the command */ |
700 | kill (cmd_pid, SIGWINCH); |
858 | kill (cmd_pid, SIGWINCH); |
701 | # endif |
859 | # endif |
702 | #endif |
860 | #endif |
703 | } |
861 | } |
704 | |
862 | |
705 | /*----------------------------------------------------------------------*/ |
863 | /*----------------------------------------------------------------------*/ |
706 | /* rxvt_change_font() - Switch to a new font */ |
864 | /* rxvt_change_font () - Switch to a new font */ |
707 | /* |
865 | /* |
708 | * init = 1 - initialize |
866 | * init = 1 - initialize |
709 | * |
867 | * |
710 | * fontname == FONT_UP - switch to bigger font |
868 | * fontname == FONT_UP - switch to bigger font |
711 | * fontname == FONT_DN - switch to smaller font |
869 | * fontname == FONT_DN - switch to smaller font |
712 | */ |
870 | */ |
713 | void |
871 | bool |
714 | rxvt_term::change_font (int init, const char *fontname) |
872 | rxvt_term::change_font (const char *fontname) |
715 | {} |
873 | { |
|
|
874 | if (fontname == FONT_UP) |
|
|
875 | { |
|
|
876 | // TODO |
|
|
877 | } |
|
|
878 | else if (fontname == FONT_DN) |
|
|
879 | { |
|
|
880 | // TODO |
|
|
881 | } |
|
|
882 | else |
|
|
883 | { |
|
|
884 | rxvt_fontset *fs = new rxvt_fontset (this); |
716 | |
885 | |
717 | void |
886 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
|
|
887 | { |
|
|
888 | delete TermWin.fontset; |
|
|
889 | TermWin.fontset = fs; |
|
|
890 | TermWin.fwidth = fs->base_font ()->width; |
|
|
891 | TermWin.fheight = fs->base_font ()->height; |
|
|
892 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
893 | |
|
|
894 | if (TermWin.parent[0]) |
|
|
895 | { |
|
|
896 | resize_all_windows (0, 0, 0); |
|
|
897 | scr_remap_chars (); |
|
|
898 | scr_touch (true); |
|
|
899 | } |
|
|
900 | |
|
|
901 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
|
|
902 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
|
|
903 | |
|
|
904 | return true; |
|
|
905 | } |
|
|
906 | } |
|
|
907 | |
|
|
908 | return false; |
|
|
909 | } |
|
|
910 | |
|
|
911 | bool |
718 | rxvt_term::font_up_down (int n, int direction) |
912 | rxvt_term::font_up_down (int n, int direction) |
719 | {} |
913 | { |
|
|
914 | return false; |
|
|
915 | } |
720 | |
916 | |
721 | /*----------------------------------------------------------------------*/ |
917 | /*----------------------------------------------------------------------*/ |
722 | /*----------------------------------------------------------------------*/ |
918 | /*----------------------------------------------------------------------*/ |
723 | /* xterm sequences - title, iconName, color (exptl) */ |
919 | /* xterm sequences - title, iconName, color (exptl) */ |
724 | void |
920 | void |
725 | rxvt_term::set_title (const char *str) |
921 | rxvt_term::set_title (const char *str) |
726 | { |
922 | { |
727 | #ifndef SMART_WINDOW_TITLE |
923 | #ifdef SMART_WINDOW_TITLE |
728 | XStoreName(display->display, TermWin.parent[0], str); |
924 | char *name; |
729 | #else |
|
|
730 | char *name; |
|
|
731 | |
925 | |
732 | if (XFetchName(display->display, TermWin.parent[0], &name) == 0) |
926 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
733 | name = NULL; |
927 | name = NULL; |
|
|
928 | |
734 | if (name == NULL || STRCMP(name, str)) |
929 | if (name == NULL || STRCMP (name, str)) |
|
|
930 | #endif |
735 | XStoreName(display->display, TermWin.parent[0], str); |
931 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
932 | |
|
|
933 | #ifdef SMART_WINDOW_TITLE |
736 | if (name) |
934 | if (name) |
737 | XFree(name); |
935 | XFree (name); |
738 | #endif |
936 | #endif |
739 | } |
937 | } |
740 | |
938 | |
741 | void |
939 | void |
742 | rxvt_term::set_iconName (const char *str) |
940 | rxvt_term::set_icon_name (const char *str) |
743 | { |
941 | { |
744 | #ifndef SMART_WINDOW_TITLE |
942 | #ifdef SMART_WINDOW_TITLE |
745 | XSetIconName(display->display, TermWin.parent[0], str); |
943 | char *name; |
746 | #else |
|
|
747 | char *name; |
|
|
748 | |
944 | |
749 | if (XGetIconName(display->display, TermWin.parent[0], &name)) |
945 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
750 | name = NULL; |
946 | name = NULL; |
|
|
947 | |
751 | if (name == NULL || STRCMP(name, str)) |
948 | if (name == NULL || STRCMP (name, str)) |
|
|
949 | #endif |
752 | XSetIconName(display->display, TermWin.parent[0], str); |
950 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
951 | |
|
|
952 | #ifdef SMART_WINDOW_TITLE |
753 | if (name) |
953 | if (name) |
754 | XFree(name); |
954 | XFree (name); |
755 | #endif |
955 | #endif |
756 | } |
956 | } |
757 | |
957 | |
758 | #ifdef XTERM_COLOR_CHANGE |
958 | #ifdef XTERM_COLOR_CHANGE |
759 | void |
959 | void |
760 | rxvt_term::set_window_color (int idx, const char *color) |
960 | rxvt_term::set_window_color (int idx, const char *color) |
761 | { |
961 | { |
762 | rxvt_color xcol; |
962 | rxvt_color xcol; |
763 | int i; |
963 | int i; |
764 | |
964 | |
765 | if (color == NULL || *color == '\0') |
965 | if (color == NULL || *color == '\0') |
766 | return; |
966 | return; |
767 | |
967 | |
768 | /* handle color aliases */ |
968 | /* handle color aliases */ |
769 | if (isdigit(*color)) |
969 | if (isdigit (*color)) |
770 | { |
970 | { |
771 | i = atoi(color); |
971 | i = atoi (color); |
772 | if (i >= 8 && i <= 15) |
972 | if (i >= 8 && i <= 15) |
773 | { /* bright colors */ |
973 | { /* bright colors */ |
774 | i -= 8; |
974 | i -= 8; |
775 | # ifndef NO_BRIGHTCOLOR |
975 | # ifndef NO_BRIGHTCOLOR |
776 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
976 | PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; |
777 | SET_PIXCOLOR(idx); |
977 | SET_PIXCOLOR (idx); |
778 | goto Done; |
978 | goto Done; |
779 | # endif |
979 | # endif |
780 | |
980 | |
781 | } |
981 | } |
782 | if (i >= 0 && i <= 7) |
982 | if (i >= 0 && i <= 7) |
783 | { /* normal colors */ |
983 | { /* normal colors */ |
784 | PixColors[idx] = PixColors[minCOLOR + i]; |
984 | PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; |
785 | SET_PIXCOLOR(idx); |
985 | SET_PIXCOLOR (idx); |
786 | goto Done; |
986 | goto Done; |
787 | } |
987 | } |
788 | } |
988 | } |
|
|
989 | |
789 | if (!rXParseAllocColor (& xcol, color)) |
990 | if (!rXParseAllocColor (& xcol, color)) |
790 | return; |
991 | return; |
|
|
992 | |
791 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
993 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
792 | |
994 | |
793 | /* |
995 | /* |
794 | * FIXME: should free colors here, but no idea how to do it so instead, |
996 | * FIXME: should free colors here, but no idea how to do it so instead, |
795 | * so just keep gobbling up the colormap |
997 | * so just keep gobbling up the colormap |
796 | */ |
998 | */ |
… | |
… | |
799 | if (PixColors[idx] == PixColors[i]) |
1001 | if (PixColors[idx] == PixColors[i]) |
800 | break; |
1002 | break; |
801 | if (i > Color_White) |
1003 | if (i > Color_White) |
802 | { |
1004 | { |
803 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
1005 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
804 | XFreeColors(display->display, XCMAP, (PixColors + idx), 1, |
1006 | XFreeColors (display->display, display->cmap, (PixColors + idx), 1, |
805 | DisplayPlanes(display->display, display->screen)); |
1007 | DisplayPlanes (display->display, display->screen)); |
806 | } |
1008 | } |
807 | # endif |
1009 | # endif |
808 | |
1010 | |
809 | PixColors[idx] = xcol; |
1011 | PixColorsFocused[idx] = xcol; |
810 | SET_PIXCOLOR(idx); |
1012 | SET_PIXCOLOR (idx); |
811 | |
1013 | |
812 | /* XSetWindowAttributes attr; */ |
1014 | /* XSetWindowAttributes attr; */ |
813 | /* Cursor cursor; */ |
1015 | /* Cursor cursor; */ |
814 | Done: |
1016 | Done: |
|
|
1017 | #ifdef OFF_FOCUS_FADING |
|
|
1018 | PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); |
|
|
1019 | #endif |
815 | if (idx == Color_bg && !(Options & Opt_transparent)) |
1020 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
816 | XSetWindowBackground(display->display, TermWin.vt, |
1021 | XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); |
817 | PixColors[Color_bg]); |
|
|
818 | |
1022 | |
819 | /* handle Color_BD, scrollbar background, etc. */ |
1023 | /* handle Color_BD, scrollbar background, etc. */ |
820 | |
1024 | |
821 | set_colorfgbg (); |
1025 | set_colorfgbg (); |
822 | recolour_cursor (); |
1026 | recolour_cursor (); |
823 | /* the only reasonable way to enforce a clean update */ |
1027 | scr_touch (true); |
824 | scr_poweron (); |
|
|
825 | } |
1028 | } |
826 | |
1029 | |
827 | #else |
1030 | #else |
828 | # define set_window_color (idx,color) ((void)0) |
1031 | # define set_window_color (idx,color) ((void)0) |
829 | #endif /* XTERM_COLOR_CHANGE */ |
1032 | #endif /* XTERM_COLOR_CHANGE */ |
830 | |
1033 | |
831 | void |
1034 | void |
832 | rxvt_term::recolour_cursor () |
1035 | rxvt_term::recolour_cursor () |
833 | { |
1036 | { |
834 | #if TODO |
|
|
835 | rxvt_color xcol[2]; |
1037 | XColor xcol[2]; |
836 | |
1038 | |
837 | xcol[0] = PixColors[Color_pointer]; |
1039 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; |
838 | xcol[1] = PixColors[Color_bg]; |
1040 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; |
839 | XQueryColors (display->display, XCMAP, xcol, 2); |
1041 | XQueryColors (display->display, display->cmap, xcol, 2); |
840 | XRecolorCursor (display->display, TermWin_cursor, &(xcol[0]), &(xcol[1])); |
1042 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
841 | #endif |
|
|
842 | } |
1043 | } |
843 | |
1044 | |
844 | /*----------------------------------------------------------------------*/ |
1045 | /*----------------------------------------------------------------------*/ |
845 | /* |
1046 | /* |
846 | * find if fg/bg matches any of the normal (low-intensity) colors |
1047 | * find if fg/bg matches any of the normal (low-intensity) colors |
… | |
… | |
848 | void |
1049 | void |
849 | rxvt_term::set_colorfgbg () |
1050 | rxvt_term::set_colorfgbg () |
850 | { |
1051 | { |
851 | unsigned int i; |
1052 | unsigned int i; |
852 | const char *xpmb = "\0"; |
1053 | const char *xpmb = "\0"; |
853 | char fstr[sizeof("default") + 1], bstr[sizeof("default") + 1]; |
1054 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
854 | |
1055 | |
855 | env_colorfgbg = |
1056 | env_colorfgbg = |
856 | (char *)rxvt_malloc(sizeof("COLORFGBG=default;default;bg") + 1); |
1057 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
857 | STRCPY(fstr, "default"); |
1058 | STRCPY (fstr, "default"); |
858 | STRCPY(bstr, "default"); |
1059 | STRCPY (bstr, "default"); |
859 | for (i = Color_Black; i <= Color_White; i++) |
1060 | for (i = Color_Black; i <= Color_White; i++) |
860 | if (PixColors[Color_fg] == PixColors[i]) |
1061 | if (PixColors[Color_fg] == PixColors[i]) |
861 | { |
1062 | { |
862 | sprintf(fstr, "%d", (i - Color_Black)); |
1063 | sprintf (fstr, "%d", (i - Color_Black)); |
863 | break; |
1064 | break; |
864 | } |
1065 | } |
865 | for (i = Color_Black; i <= Color_White; i++) |
1066 | for (i = Color_Black; i <= Color_White; i++) |
866 | if (PixColors[Color_bg] == PixColors[i]) |
1067 | if (PixColors[Color_bg] == PixColors[i]) |
867 | { |
1068 | { |
868 | sprintf(bstr, "%d", (i - Color_Black)); |
1069 | sprintf (bstr, "%d", (i - Color_Black)); |
869 | #ifdef XPM_BACKGROUND |
1070 | #ifdef XPM_BACKGROUND |
870 | xpmb = "default;"; |
1071 | xpmb = "default;"; |
871 | #endif |
1072 | #endif |
872 | break; |
1073 | break; |
873 | } |
1074 | } |
|
|
1075 | |
874 | sprintf(env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1076 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
875 | putenv(env_colorfgbg); |
|
|
876 | |
1077 | |
877 | #ifndef NO_BRIGHTCOLOR |
1078 | #ifndef NO_BRIGHTCOLOR |
878 | colorfgbg = DEFAULT_RSTYLE; |
1079 | colorfgbg = DEFAULT_RSTYLE; |
879 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1080 | for (i = minCOLOR; i <= maxCOLOR; i++) |
880 | { |
1081 | { |
881 | if (PixColors[Color_fg] == PixColors[i]) |
1082 | if (PixColors[Color_fg] == PixColors[i]) |
882 | colorfgbg = SET_FGCOLOR(colorfgbg, i); |
1083 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
883 | if (PixColors[Color_bg] == PixColors[i]) |
1084 | if (PixColors[Color_bg] == PixColors[i]) |
884 | colorfgbg = SET_BGCOLOR(colorfgbg, i); |
1085 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
885 | } |
1086 | } |
886 | #endif |
1087 | #endif |
887 | } |
1088 | } |
888 | |
1089 | |
889 | /*----------------------------------------------------------------------*/ |
1090 | /*----------------------------------------------------------------------*/ |
… | |
… | |
895 | int |
1096 | int |
896 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1097 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
897 | { |
1098 | { |
898 | if (!screen_in_out->set (display, colour)) |
1099 | if (!screen_in_out->set (display, colour)) |
899 | { |
1100 | { |
900 | rxvt_print_error("can't allocate colour: %s", colour); |
1101 | rxvt_warn ("can't get colour '%s', continuing without.\n", colour); |
901 | return false; |
1102 | return false; |
902 | } |
1103 | } |
903 | |
1104 | |
904 | return true; |
1105 | return true; |
905 | } |
1106 | } |
… | |
… | |
916 | int old_width = szHint.width, old_height = szHint.height; |
1117 | int old_width = szHint.width, old_height = szHint.height; |
917 | #endif |
1118 | #endif |
918 | |
1119 | |
919 | window_calc (width, height); |
1120 | window_calc (width, height); |
920 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1121 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
|
|
1122 | |
921 | if (!ignoreparent) |
1123 | if (!ignoreparent) |
922 | { |
1124 | { |
923 | #ifdef SMART_RESIZE |
1125 | #ifdef SMART_RESIZE |
924 | /* |
1126 | /* |
925 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
1127 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
… | |
… | |
960 | dy /= 2; |
1162 | dy /= 2; |
961 | |
1163 | |
962 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1164 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
963 | szHint.width, szHint.height); |
1165 | szHint.width, szHint.height); |
964 | #else |
1166 | #else |
965 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, |
1167 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
966 | szHint.height); |
|
|
967 | #endif |
1168 | #endif |
968 | |
|
|
969 | } |
1169 | } |
970 | |
1170 | |
971 | fix_screen = (TermWin.ncol != prev_ncol |
1171 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
972 | || TermWin.nrow != prev_nrow); |
|
|
973 | |
1172 | |
974 | if (fix_screen || width != old_width || height != old_height) |
1173 | if (fix_screen || width != old_width || height != old_height) |
975 | { |
1174 | { |
976 | if (scrollbar_visible ()) |
1175 | if (scrollbar_visible ()) |
977 | { |
1176 | { |
978 | XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, |
1177 | XMoveResizeWindow (display->display, scrollBar.win, |
|
|
1178 | window_sb_x, 0, |
979 | 0, scrollbar_TotalWidth (), szHint.height); |
1179 | scrollbar_TotalWidth (), szHint.height); |
980 | resize_scrollbar (); |
1180 | resize_scrollbar (); |
981 | } |
1181 | } |
982 | |
1182 | |
983 | if (menubar_visible ()) |
1183 | if (menubar_visible ()) |
984 | XMoveResizeWindow (display->display, menuBar.win, window_vt_x, |
1184 | XMoveResizeWindow (display->display, menuBar.win, |
|
|
1185 | window_vt_x, 0, |
985 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1186 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
986 | |
1187 | |
987 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1188 | XMoveResizeWindow (display->display, TermWin.vt, |
988 | window_vt_y, TermWin_TotalWidth (), |
1189 | window_vt_x, window_vt_y, |
989 | TermWin_TotalHeight ()); |
1190 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
990 | #ifdef RXVT_GRAPHICS |
|
|
991 | if (old_height) |
|
|
992 | Gr_Resize (old_width - szHint.base_width, |
|
|
993 | old_height - szHint.base_height); |
|
|
994 | #endif |
|
|
995 | scr_clear (); |
1191 | scr_clear (); |
996 | #ifdef XPM_BACKGROUND |
1192 | #ifdef XPM_BACKGROUND |
997 | resize_pixmap (); |
1193 | resize_pixmap (); |
998 | #endif |
1194 | #endif |
999 | |
|
|
1000 | } |
1195 | } |
1001 | |
1196 | |
1002 | if (fix_screen || old_height == 0) |
1197 | if (fix_screen || old_height == 0) |
1003 | { |
1198 | { |
1004 | int curr_screen = -1; |
1199 | int curr_screen = -1; |
… | |
… | |
1011 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1206 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1012 | curr_screen = scr_change_screen (PRIMARY); |
1207 | curr_screen = scr_change_screen (PRIMARY); |
1013 | TermWin.ncol = ncol; |
1208 | TermWin.ncol = ncol; |
1014 | } |
1209 | } |
1015 | |
1210 | |
1016 | scr_reset(); |
1211 | scr_reset (); |
1017 | |
1212 | |
1018 | if (curr_screen >= 0) /* this is not the first time through */ |
1213 | if (curr_screen >= 0) /* this is not the first time through */ |
1019 | { |
1214 | { |
1020 | scr_change_screen (curr_screen); |
1215 | scr_change_screen (curr_screen); |
1021 | selection_check (old_ncol != TermWin.ncol ? 4 : 0); |
1216 | selection_check (old_ncol != TermWin.ncol ? 4 : 0); |
… | |
… | |
1039 | { |
1234 | { |
1040 | XWindowAttributes wattr; |
1235 | XWindowAttributes wattr; |
1041 | |
1236 | |
1042 | if (width == 0 || height == 0) |
1237 | if (width == 0 || height == 0) |
1043 | { |
1238 | { |
1044 | XGetWindowAttributes(display->display, display->root, &wattr); |
1239 | XGetWindowAttributes (display->display, display->root, &wattr); |
1045 | if (width == 0) |
1240 | if (width == 0) |
1046 | width = wattr.width - szHint.base_width; |
1241 | width = wattr.width - szHint.base_width; |
1047 | if (height == 0) |
1242 | if (height == 0) |
1048 | height = wattr.height - szHint.base_height; |
1243 | height = wattr.height - szHint.base_height; |
1049 | } |
1244 | } |
|
|
1245 | |
1050 | if (width != TermWin.width || height != TermWin.height) |
1246 | if (width != TermWin.width || height != TermWin.height) |
1051 | { |
1247 | { |
1052 | width += szHint.base_width; |
1248 | width += szHint.base_width; |
1053 | height += szHint.base_height; |
1249 | height += szHint.base_height; |
1054 | resize_all_windows (width, height, 0); |
1250 | resize_all_windows (width, height, 0); |
… | |
… | |
1057 | |
1253 | |
1058 | /* -------------------------------------------------------------------- * |
1254 | /* -------------------------------------------------------------------- * |
1059 | * - X INPUT METHOD ROUTINES - * |
1255 | * - X INPUT METHOD ROUTINES - * |
1060 | * -------------------------------------------------------------------- */ |
1256 | * -------------------------------------------------------------------- */ |
1061 | #ifdef USE_XIM |
1257 | #ifdef USE_XIM |
|
|
1258 | |
1062 | void |
1259 | void |
1063 | rxvt_term::set_size (XRectangle *size) |
1260 | rxvt_term::im_set_size (XRectangle *size) |
1064 | { |
1261 | { |
1065 | size->x = TermWin.int_bwidth; |
1262 | size->x = TermWin.int_bwidth; |
1066 | size->y = TermWin.int_bwidth; |
1263 | size->y = TermWin.int_bwidth; |
1067 | size->width = Width2Pixel(TermWin.ncol); |
1264 | size->width = Width2Pixel (TermWin.ncol); |
1068 | size->height = Height2Pixel(TermWin.nrow); |
1265 | size->height = Height2Pixel (TermWin.nrow); |
1069 | } |
1266 | } |
1070 | |
1267 | |
1071 | void |
1268 | void |
1072 | rxvt_term::set_color (unsigned long *fg, unsigned long *bg) |
1269 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1073 | { |
1270 | { |
1074 | *fg = PixColors[Color_fg]; |
1271 | *fg = PixColors[Color_fg]; |
1075 | *bg = PixColors[Color_bg]; |
1272 | *bg = PixColors[Color_bg]; |
1076 | } |
1273 | } |
1077 | |
1274 | |
… | |
… | |
1083 | Atom atom; |
1280 | Atom atom; |
1084 | Window win; |
1281 | Window win; |
1085 | char server[IMBUFSIZ]; |
1282 | char server[IMBUFSIZ]; |
1086 | |
1283 | |
1087 | /* get current locale modifier */ |
1284 | /* get current locale modifier */ |
1088 | if ((p = XSetLocaleModifiers(NULL)) != NULL) |
1285 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1089 | { |
1286 | { |
1090 | STRCPY(server, "@server="); |
1287 | STRCPY (server, "@server="); |
1091 | STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1288 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1092 | if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ |
1289 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1093 | *p = '\0'; |
1290 | *p = '\0'; |
1094 | |
1291 | |
1095 | atom = XInternAtom(display->display, server, False); |
1292 | atom = XInternAtom (display->display, server, False); |
1096 | win = XGetSelectionOwner(display->display, atom); |
1293 | win = XGetSelectionOwner (display->display, atom); |
1097 | if (win != None) |
1294 | if (win != None) |
1098 | return True; |
1295 | return True; |
1099 | } |
1296 | } |
1100 | return False; |
1297 | return False; |
1101 | } |
1298 | } |
… | |
… | |
1105 | { |
1302 | { |
1106 | XPoint spot; |
1303 | XPoint spot; |
1107 | XVaNestedList preedit_attr; |
1304 | XVaNestedList preedit_attr; |
1108 | |
1305 | |
1109 | if (Input_Context == NULL |
1306 | if (Input_Context == NULL |
1110 | || !TermWin.focus || !(input_style & XIMPreeditPosition) |
1307 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1111 | || !(event_type == KeyPress |
1308 | || ! (event_type == KeyPress |
1112 | || event_type == Expose |
1309 | || event_type == Expose |
1113 | || event_type == NoExpose |
1310 | || event_type == NoExpose |
1114 | || event_type == SelectionNotify |
1311 | || event_type == SelectionNotify |
1115 | || event_type == ButtonRelease || event_type == FocusIn) |
1312 | || event_type == ButtonRelease || event_type == FocusIn) |
1116 | || !IMisRunning ()) |
1313 | || !IMisRunning ()) |
1117 | return; |
1314 | return; |
1118 | |
1315 | |
1119 | set_position (&spot); |
1316 | im_set_position (&spot); |
1120 | |
1317 | |
1121 | preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); |
1318 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1122 | XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1319 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1123 | XFree(preedit_attr); |
1320 | XFree (preedit_attr); |
1124 | } |
1321 | } |
1125 | |
1322 | |
1126 | void |
1323 | void |
1127 | rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
1324 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
1128 | XRectangle * needed_rect) |
1325 | XRectangle * needed_rect) |
1129 | { |
1326 | { |
1130 | int mbh, vtx = 0; |
1327 | int mbh, vtx = 0; |
1131 | |
1328 | |
1132 | if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) |
1329 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
1133 | vtx = scrollbar_TotalWidth(); |
1330 | vtx = scrollbar_TotalWidth (); |
1134 | |
1331 | |
1135 | mbh = menubar_visible () ? menuBar_TotalHeight() : 0; |
1332 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
1136 | mbh -= TermWin.lineSpace; |
1333 | mbh -= TermWin.lineSpace; |
1137 | |
1334 | |
1138 | preedit_rect->x = needed_rect->width + vtx; |
1335 | preedit_rect->x = needed_rect->width + vtx; |
1139 | preedit_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; |
1336 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
1140 | |
1337 | |
1141 | preedit_rect->width = Width2Pixel(TermWin.ncol + 1) - needed_rect->width + vtx; |
1338 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
1142 | preedit_rect->height = Height2Pixel(1); |
1339 | preedit_rect->height = Height2Pixel (1); |
1143 | |
1340 | |
1144 | status_rect->x = vtx; |
1341 | status_rect->x = vtx; |
1145 | status_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; |
1342 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
1146 | |
1343 | |
1147 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); |
1344 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
1148 | status_rect->height = Height2Pixel(1); |
1345 | status_rect->height = Height2Pixel (1); |
1149 | } |
1346 | } |
1150 | |
1347 | |
1151 | /* ARGSUSED */ |
|
|
1152 | /* EXTPROTO */ |
|
|
1153 | void |
1348 | void |
1154 | rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data |
1349 | rxvt_term::im_destroy () |
1155 | __attribute__ ((unused)), XPointer call_data |
|
|
1156 | __attribute__ ((unused))) |
|
|
1157 | { |
1350 | { |
|
|
1351 | if (Input_Context) |
|
|
1352 | { |
|
|
1353 | XDestroyIC (Input_Context); |
1158 | GET_R->Input_Context = NULL; |
1354 | Input_Context = NULL; |
1159 | /* To avoid Segmentation Fault in C locale: Solaris only? */ |
1355 | } |
1160 | if (STRCMP (GET_R->locale, "C")) |
1356 | |
1161 | XRegisterIMInstantiateCallback(GET_R->display->display, NULL, NULL, NULL, |
1357 | if (input_method) |
1162 | rxvt_IMInstantiateCallback, NULL); |
1358 | { |
|
|
1359 | display->put_xim (input_method); |
|
|
1360 | input_method = 0; |
|
|
1361 | } |
1163 | } |
1362 | } |
1164 | |
1363 | |
1165 | /* |
1364 | /* |
1166 | * Try to open a XIM with the current modifiers, then see if we can |
1365 | * Try to open a XIM with the current modifiers, then see if we can |
1167 | * open a suitable preedit type |
1366 | * open a suitable preedit type |
1168 | */ |
1367 | */ |
1169 | bool |
1368 | bool |
1170 | rxvt_term::IM_get_IC () |
1369 | rxvt_term::IM_get_IC (const char *modifiers) |
1171 | { |
1370 | { |
1172 | int i, j, found; |
1371 | int i, j, found; |
1173 | XIM xim; |
1372 | XIM xim; |
1174 | XPoint spot; |
1373 | XPoint spot; |
1175 | XRectangle rect, status_rect, needed_rect; |
1374 | XRectangle rect, status_rect, needed_rect; |
1176 | unsigned long fg, bg; |
1375 | unsigned long fg, bg; |
1177 | const char *p; |
1376 | const char *p; |
1178 | char **s; |
1377 | char **s; |
1179 | XIMStyles *xim_styles; |
1378 | XIMStyles *xim_styles; |
1180 | XVaNestedList preedit_attr, status_attr; |
1379 | XVaNestedList preedit_attr, status_attr; |
1181 | XIMCallback ximcallback; |
|
|
1182 | |
1380 | |
|
|
1381 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
|
|
1382 | return false; |
|
|
1383 | |
1183 | D_MAIN((stderr, "rxvt_IM_get_IC()")); |
1384 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1184 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
1385 | input_method = display->get_xim (locale, modifiers); |
1185 | if (xim == NULL) |
1386 | if (input_method == NULL) |
1186 | return False; |
1387 | return false; |
|
|
1388 | |
|
|
1389 | xim = input_method->xim; |
1187 | |
1390 | |
1188 | xim_styles = NULL; |
1391 | xim_styles = NULL; |
1189 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1392 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1190 | || !xim_styles || !xim_styles->count_styles) |
1393 | || !xim_styles || !xim_styles->count_styles) |
1191 | { |
1394 | { |
1192 | XCloseIM(xim); |
1395 | display->put_xim (input_method); |
1193 | return False; |
1396 | return false; |
1194 | } |
1397 | } |
1195 | |
1398 | |
1196 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] |
1399 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1197 | : "OverTheSpot,OffTheSpot,Root"; |
|
|
1198 | s = rxvt_splitcommastring(p); |
1400 | s = rxvt_splitcommastring (p); |
1199 | for (i = found = 0; !found && s[i]; i++) |
1401 | for (i = found = 0; !found && s[i]; i++) |
1200 | { |
1402 | { |
1201 | if (!STRCMP(s[i], "OverTheSpot")) |
1403 | if (!STRCMP (s[i], "OverTheSpot")) |
1202 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1404 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1203 | else if (!STRCMP(s[i], "OffTheSpot")) |
1405 | else if (!STRCMP (s[i], "OffTheSpot")) |
1204 | input_style = (XIMPreeditArea | XIMStatusArea); |
1406 | input_style = (XIMPreeditArea | XIMStatusArea); |
1205 | else if (!STRCMP(s[i], "Root")) |
1407 | else if (!STRCMP (s[i], "Root")) |
1206 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1408 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1207 | |
1409 | |
1208 | for (j = 0; j < xim_styles->count_styles; j++) |
1410 | for (j = 0; j < xim_styles->count_styles; j++) |
1209 | if (input_style == xim_styles->supported_styles[j]) |
1411 | if (input_style == xim_styles->supported_styles[j]) |
1210 | { |
1412 | { |
1211 | found = 1; |
1413 | found = 1; |
1212 | break; |
1414 | break; |
1213 | } |
1415 | } |
1214 | } |
1416 | } |
|
|
1417 | |
1215 | for (i = 0; s[i]; i++) |
1418 | for (i = 0; s[i]; i++) |
1216 | free(s[i]); |
1419 | free (s[i]); |
|
|
1420 | |
1217 | free(s); |
1421 | free (s); |
1218 | XFree(xim_styles); |
1422 | XFree (xim_styles); |
1219 | |
1423 | |
1220 | if (!found) |
1424 | if (!found) |
1221 | { |
1425 | { |
1222 | XCloseIM(xim); |
1426 | display->put_xim (input_method); |
1223 | return False; |
1427 | return false; |
1224 | } |
1428 | } |
1225 | |
|
|
1226 | ximcallback.callback = rxvt_IMDestroyCallback; |
|
|
1227 | |
|
|
1228 | /* XXX: not sure why we need this (as well as IC one below) */ |
|
|
1229 | XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); |
|
|
1230 | |
1429 | |
1231 | preedit_attr = status_attr = NULL; |
1430 | preedit_attr = status_attr = NULL; |
1232 | |
1431 | |
1233 | if (input_style & XIMPreeditPosition) |
1432 | if (input_style & XIMPreeditPosition) |
1234 | { |
1433 | { |
1235 | set_size (&rect); |
1434 | im_set_size (&rect); |
1236 | set_position (&spot); |
1435 | im_set_position (&spot); |
1237 | set_color (&fg, &bg); |
1436 | im_set_color (&fg, &bg); |
1238 | |
1437 | |
1239 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
1438 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1240 | XNSpotLocation, &spot, |
1439 | XNSpotLocation, &spot, |
1241 | XNForeground, fg, XNBackground, bg, |
1440 | XNForeground, fg, XNBackground, bg, |
1242 | //XNFontSet, TermWin.fontset, |
1441 | //XNFontSet, TermWin.fontset, |
1243 | NULL); |
1442 | NULL); |
1244 | } |
1443 | } |
1245 | else if (input_style & XIMPreeditArea) |
1444 | else if (input_style & XIMPreeditArea) |
1246 | { |
1445 | { |
1247 | set_color (&fg, &bg); |
1446 | im_set_color (&fg, &bg); |
1248 | |
1447 | |
1249 | /* |
1448 | /* |
1250 | * The necessary width of preedit area is unknown |
1449 | * The necessary width of preedit area is unknown |
1251 | * until create input context. |
1450 | * until create input context. |
1252 | */ |
1451 | */ |
1253 | needed_rect.width = 0; |
1452 | needed_rect.width = 0; |
1254 | |
1453 | |
1255 | set_preedit_area(&rect, &status_rect, &needed_rect); |
1454 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1256 | |
1455 | |
1257 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
1456 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1258 | XNForeground, fg, XNBackground, bg, |
1457 | XNForeground, fg, XNBackground, bg, |
1259 | //XNFontSet, TermWin.fontset, |
1458 | //XNFontSet, TermWin.fontset, |
1260 | NULL); |
1459 | NULL); |
1261 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, |
1460 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
1262 | XNForeground, fg, XNBackground, bg, |
1461 | XNForeground, fg, XNBackground, bg, |
1263 | //XNFontSet, TermWin.fontset, |
1462 | //XNFontSet, TermWin.fontset, |
1264 | NULL); |
1463 | NULL); |
1265 | } |
1464 | } |
|
|
1465 | |
1266 | Input_Context = XCreateIC(xim, XNInputStyle, input_style, |
1466 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1267 | XNClientWindow, TermWin.parent[0], |
1467 | XNClientWindow, TermWin.parent[0], |
1268 | XNFocusWindow, TermWin.parent[0], |
1468 | XNFocusWindow, TermWin.parent[0], |
1269 | XNDestroyCallback, &ximcallback, |
|
|
1270 | preedit_attr ? XNPreeditAttributes : NULL, |
1469 | preedit_attr ? XNPreeditAttributes : NULL, |
1271 | preedit_attr, |
1470 | preedit_attr, |
1272 | status_attr ? XNStatusAttributes : NULL, |
1471 | status_attr ? XNStatusAttributes : NULL, |
1273 | status_attr, NULL); |
1472 | status_attr, NULL); |
1274 | if (preedit_attr) |
1473 | if (preedit_attr) XFree (preedit_attr); |
1275 | XFree(preedit_attr); |
1474 | if (status_attr) XFree (status_attr); |
1276 | if (status_attr) |
1475 | |
1277 | XFree(status_attr); |
|
|
1278 | if (Input_Context == NULL) |
1476 | if (Input_Context == NULL) |
1279 | { |
1477 | { |
1280 | rxvt_print_error("failed to create input context"); |
1478 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1281 | XCloseIM(xim); |
1479 | display->put_xim (input_method); |
1282 | return False; |
1480 | return false; |
1283 | } |
1481 | } |
|
|
1482 | |
1284 | if (input_style & XIMPreeditArea) |
1483 | if (input_style & XIMPreeditArea) |
1285 | IMSetStatusPosition (); |
1484 | IMSetStatusPosition (); |
|
|
1485 | |
1286 | D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); |
1486 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
1287 | return True; |
1487 | return true; |
1288 | } |
1488 | } |
1289 | |
1489 | |
1290 | /* |
|
|
1291 | * X manual pages and include files don't match on some systems: |
|
|
1292 | * some think this is an XIDProc and others an XIMProc so we can't |
|
|
1293 | * use the first argument - need to update this to be nice for |
|
|
1294 | * both types via some sort of configure detection |
|
|
1295 | */ |
|
|
1296 | /* ARGSUSED */ |
|
|
1297 | /* EXTPROTO */ |
|
|
1298 | void |
1490 | void |
1299 | rxvt_IMInstantiateCallback(Display * unused |
1491 | rxvt_term::im_cb () |
1300 | __attribute__ ((unused)), XPointer client_data |
|
|
1301 | __attribute__ ((unused)), XPointer call_data |
|
|
1302 | __attribute__ ((unused))) |
|
|
1303 | { |
1492 | { |
1304 | int i, found, had_im; |
1493 | int i, found, had_im; |
1305 | const char *p; |
1494 | const char *p; |
1306 | char **s; |
1495 | char **s; |
1307 | char buf[IMBUFSIZ]; |
1496 | char buf[IMBUFSIZ]; |
1308 | |
1497 | |
|
|
1498 | im_destroy (); |
|
|
1499 | |
1309 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1500 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1310 | if (GET_R->Input_Context) |
1501 | if (Input_Context) |
1311 | return; |
1502 | return; |
1312 | |
1503 | |
1313 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1504 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1314 | if (GET_R->rs[Rs_imLocale]) |
1505 | if (rs[Rs_imLocale]) |
1315 | setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); |
1506 | SET_LOCALE (rs[Rs_imLocale]); |
1316 | #endif |
1507 | #endif |
1317 | |
1508 | |
1318 | p = GET_R->rs[Rs_inputMethod]; |
1509 | p = rs[Rs_inputMethod]; |
1319 | if (p && *p) |
1510 | if (p && *p) |
1320 | { |
1511 | { |
1321 | bool found = false; |
1512 | bool found = false; |
1322 | |
1513 | |
1323 | s = rxvt_splitcommastring (p); |
1514 | s = rxvt_splitcommastring (p); |
… | |
… | |
1325 | { |
1516 | { |
1326 | if (*s[i]) |
1517 | if (*s[i]) |
1327 | { |
1518 | { |
1328 | STRCPY (buf, "@im="); |
1519 | STRCPY (buf, "@im="); |
1329 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1520 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1330 | if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) |
1521 | if (IM_get_IC (buf)) |
1331 | { |
1522 | { |
1332 | found = true; |
1523 | found = true; |
1333 | break; |
1524 | break; |
1334 | } |
1525 | } |
1335 | } |
1526 | } |
1336 | } |
1527 | } |
1337 | for (i = 0; s[i]; i++) |
1528 | for (i = 0; s[i]; i++) |
1338 | free(s[i]); |
1529 | free (s[i]); |
1339 | free(s); |
1530 | free (s); |
1340 | |
1531 | |
1341 | if (found) |
1532 | if (found) |
1342 | goto done; |
1533 | goto done; |
1343 | } |
1534 | } |
1344 | |
1535 | |
1345 | /* try with XMODIFIERS env. var. */ |
1536 | /* try with XMODIFIERS env. var. */ |
1346 | if ((p = XSetLocaleModifiers ("")) && *p |
1537 | if (IM_get_IC ("")) |
1347 | && GET_R->IM_get_IC ()) |
|
|
1348 | goto done; |
1538 | goto done; |
1349 | |
1539 | |
1350 | /* try with no modifiers base IF the user didn't specify an IM */ |
1540 | /* try with no modifiers base IF the user didn't specify an IM */ |
1351 | if ((p = XSetLocaleModifiers ("@im=none")) && *p |
1541 | if (IM_get_IC ("@im=none")) |
1352 | && GET_R->IM_get_IC () == True) |
|
|
1353 | goto done; |
1542 | goto done; |
1354 | |
1543 | |
1355 | done: |
1544 | done: |
1356 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1545 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1357 | if (GET_R->rs[Rs_imLocale]) |
1546 | if (rs[Rs_imLocale]) |
1358 | setlocale (LC_CTYPE, GET_R->locale); |
1547 | SET_LOCALE (locale); |
1359 | #endif |
1548 | #endif |
1360 | } |
1549 | } |
1361 | |
1550 | |
1362 | void |
1551 | void |
1363 | rxvt_term::IMSetStatusPosition () |
1552 | rxvt_term::IMSetStatusPosition () |
1364 | { |
1553 | { |
1365 | XRectangle preedit_rect, status_rect, *needed_rect; |
1554 | XRectangle preedit_rect, status_rect, *needed_rect; |
1366 | XVaNestedList preedit_attr, status_attr; |
1555 | XVaNestedList preedit_attr, status_attr; |
1367 | |
1556 | |
1368 | if (Input_Context == NULL |
1557 | if (Input_Context == NULL |
1369 | || !TermWin.focus || !(input_style & XIMPreeditArea) |
1558 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1370 | || !IMisRunning ()) |
1559 | || !IMisRunning ()) |
1371 | return; |
1560 | return; |
1372 | |
1561 | |
1373 | /* Getting the necessary width of preedit area */ |
1562 | /* Getting the necessary width of preedit area */ |
1374 | status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); |
1563 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1375 | XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); |
1564 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1376 | XFree(status_attr); |
1565 | XFree (status_attr); |
1377 | |
1566 | |
1378 | set_preedit_area(&preedit_rect, &status_rect, needed_rect); |
1567 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1379 | |
1568 | |
1380 | preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); |
1569 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1381 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); |
1570 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1382 | |
1571 | |
1383 | XSetICValues(Input_Context, |
1572 | XSetICValues (Input_Context, |
1384 | XNPreeditAttributes, preedit_attr, |
1573 | XNPreeditAttributes, preedit_attr, |
1385 | XNStatusAttributes, status_attr, NULL); |
1574 | XNStatusAttributes, status_attr, NULL); |
1386 | |
1575 | |
1387 | XFree(preedit_attr); |
1576 | XFree (preedit_attr); |
1388 | XFree(status_attr); |
1577 | XFree (status_attr); |
1389 | } |
1578 | } |
1390 | #endif /* USE_XIM */ |
1579 | #endif /* USE_XIM */ |
1391 | |
1580 | |
1392 | /*----------------------------------------------------------------------*/ |
1581 | /*----------------------------------------------------------------------*/ |
1393 | rxvt_t rxvt_current_term; |
1582 | rxvt_t rxvt_current_term; |