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