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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines