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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines