ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.32 by pcg, Fri Feb 13 12:16:21 2004 UTC vs.
Revision 1.120 by root, Mon Dec 13 19:16:36 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines