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.108 by root, Wed Aug 25 05:03:33 2004 UTC vs.
Revision 1.147 by root, Mon Nov 28 19:35:04 2005 UTC

30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "main.intpro" /* PROTOS for internal routines */
36 35
37#include <signal.h> 36#include <csignal>
37#include <cstring>
38 38
39#ifdef TTY_GID_SUPPORT 39#ifdef TTY_GID_SUPPORT
40# include <grp.h> 40# include <grp.h>
41#endif 41#endif
42 42
43#ifdef HAVE_TERMIOS_H 43#ifdef HAVE_TERMIOS_H
44# include <termios.h> 44# include <termios.h>
45#endif 45#endif
46 46
47#include <cstring> 47#ifdef KEYSYM_RESOURCE
48# include "keyboard.h"
49#endif
48 50
49vector<rxvt_term *> rxvt_term::termlist; 51vector<rxvt_term *> rxvt_term::termlist;
50 52
51static char curlocale[128]; 53static char curlocale[128];
52 54
155 pointer_ev (this, &rxvt_term::pointer_cb), 157 pointer_ev (this, &rxvt_term::pointer_cb),
156#endif 158#endif
157#ifdef USE_XIM 159#ifdef USE_XIM
158 im_ev (this, &rxvt_term::im_cb), 160 im_ev (this, &rxvt_term::im_cb),
159#endif 161#endif
162 sw_term (this, &rxvt_term::sig_term),
163 sw_int (this, &rxvt_term::sig_term),
164 sw_chld (this, &rxvt_term::sig_chld),
160 termwin_ev (this, &rxvt_term::x_cb), 165 termwin_ev (this, &rxvt_term::x_cb),
161 vt_ev (this, &rxvt_term::x_cb), 166 vt_ev (this, &rxvt_term::x_cb),
162 check_ev (this, &rxvt_term::check_cb), 167 check_ev (this, &rxvt_term::check_cb),
163 flush_ev (this, &rxvt_term::flush_cb), 168 flush_ev (this, &rxvt_term::flush_cb),
164 destroy_ev (this, &rxvt_term::destroy_cb), 169 destroy_ev (this, &rxvt_term::destroy_cb),
166 incr_ev (this, &rxvt_term::incr_cb) 171 incr_ev (this, &rxvt_term::incr_cb)
167{ 172{
168 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 173 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
169 174
170 termlist.push_back (this); 175 termlist.push_back (this);
171}
172 176
173rxvt_term::~rxvt_term () 177#ifdef KEYSYM_RESOURCE
174{ 178 keyboard = new keyboard_manager;
175 termlist.erase (find (termlist.begin (), termlist.end(), this));
176 179
180 if (!keyboard)
181 rxvt_fatal ("out of memory, aborting.\n");
182#endif
183}
184
185// clean up the most important stuff, do *not* call x or free mem etc.
186// for use before an emergency exit
187void rxvt_term::emergency_cleanup ()
188{
177 if (cmd_pid) 189 if (cmd_pid)
178 kill (-cmd_pid, SIGHUP); 190 kill (-cmd_pid, SIGHUP);
179 191
180 pty.put ();
181
182#ifdef UTMP_SUPPORT 192#ifdef UTMP_SUPPORT
183 privileged_utmp (RESTORE); 193 privileged_utmp (RESTORE);
184#endif 194#endif
195
196 pty.put ();
197}
198
199rxvt_term::~rxvt_term ()
200{
201 termlist.erase (find (termlist.begin (), termlist.end(), this));
202
203 emergency_cleanup ();
185 204
186#if ENABLE_STYLES 205#if ENABLE_STYLES
187 for (int i = RS_styleCount; --i; ) 206 for (int i = RS_styleCount; --i; )
188 if (TermWin.fontset[i] != TermWin.fontset[0]) 207 if (TermWin.fontset[i] != TermWin.fontset[0])
189 delete TermWin.fontset[i]; 208 delete TermWin.fontset[i];
190#endif 209#endif
191 delete TermWin.fontset[0]; 210 delete TermWin.fontset[0];
192 211
193 if (display) 212 if (display)
194 { 213 {
214 dDisp;
215
195 selection_clear (); 216 selection_clear ();
196 217
197#ifdef USE_XIM 218#ifdef USE_XIM
198 im_destroy (); 219 im_destroy ();
199#endif 220#endif
200#ifdef MENUBAR 221#ifdef MENUBAR
201 if (menubarGC) XFreeGC (display->display, menubarGC); 222 if (menubarGC) XFreeGC (disp, menubarGC);
202#endif 223#endif
203#ifdef XTERM_SCROLLBAR 224#ifdef XTERM_SCROLLBAR
204 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); 225 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC);
205 if (ShadowGC) XFreeGC (display->display, ShadowGC); 226 if (ShadowGC) XFreeGC (disp, ShadowGC);
206#endif 227#endif
207#ifdef PLAIN_SCROLLBAR 228#ifdef PLAIN_SCROLLBAR
208 if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); 229 if (pscrollbarGC) XFreeGC (disp, pscrollbarGC);
209#endif 230#endif
210#ifdef NEXT_SCROLLBAR 231#ifdef NEXT_SCROLLBAR
211 if (blackGC) XFreeGC (display->display, blackGC); 232 if (blackGC) XFreeGC (disp, blackGC);
212 if (whiteGC) XFreeGC (display->display, whiteGC); 233 if (whiteGC) XFreeGC (disp, whiteGC);
213 if (grayGC) XFreeGC (display->display, grayGC); 234 if (grayGC) XFreeGC (disp, grayGC);
214 if (darkGC) XFreeGC (display->display, darkGC); 235 if (darkGC) XFreeGC (disp, darkGC);
215 if (stippleGC) XFreeGC (display->display, stippleGC); 236 if (stippleGC) XFreeGC (disp, stippleGC);
216 if (dimple) XFreePixmap (display->display, dimple); 237 if (dimple) XFreePixmap (disp, dimple);
217 if (upArrow) XFreePixmap (display->display, upArrow); 238 if (upArrow) XFreePixmap (disp, upArrow);
218 if (downArrow) XFreePixmap (display->display, downArrow); 239 if (downArrow) XFreePixmap (disp, downArrow);
219 if (upArrowHi) XFreePixmap (display->display, upArrowHi); 240 if (upArrowHi) XFreePixmap (disp, upArrowHi);
220 if (downArrowHi) XFreePixmap (display->display, downArrowHi); 241 if (downArrowHi) XFreePixmap (disp, downArrowHi);
221#endif 242#endif
222#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 243#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
223 if (topShadowGC) XFreeGC (display->display, topShadowGC); 244 if (topShadowGC) XFreeGC (disp, topShadowGC);
224 if (botShadowGC) XFreeGC (display->display, botShadowGC); 245 if (botShadowGC) XFreeGC (disp, botShadowGC);
225 if (scrollbarGC) XFreeGC (display->display, scrollbarGC); 246 if (scrollbarGC) XFreeGC (disp, scrollbarGC);
226#endif 247#endif
227 if (TermWin.gc) XFreeGC (display->display, TermWin.gc); 248 if (TermWin.gc) XFreeGC (disp, TermWin.gc);
228 249
229#if defined(MENUBAR) && (MENUBAR_MAX > 1) 250#if defined(MENUBAR) && (MENUBAR_MAX > 1)
230 delete menuBar.drawable; 251 delete menuBar.drawable;
231 //if (menuBar.win) 252 //if (menuBar.win)
232 // XDestroyWindow (display->display, menuBar.win); 253 // XDestroyWindow (disp, menuBar.win);
233#endif 254#endif
234 delete TermWin.drawable; 255 delete TermWin.drawable;
235 // destroy all windows 256 // destroy all windows
236 if (TermWin.parent[0]) 257 if (TermWin.parent[0])
237 XDestroyWindow (display->display, TermWin.parent[0]); 258 XDestroyWindow (disp, TermWin.parent[0]);
238 } 259 }
239 260
240 // TODO: free pixcolours, colours should become part of rxvt_display 261 // TODO: free pixcolours, colours should become part of rxvt_display
241 262
242 delete pix_colors_focused; 263 delete pix_colors_focused;
243#ifdef OFF_FOCUS_FADING 264#if OFF_FOCUS_FADING
244 delete pix_colors_unfocused; 265 delete pix_colors_unfocused;
245#endif 266#endif
246 267
247 displays.put (display); 268 displays.put (display);
248 269
249 scr_release (); 270 scr_release ();
250 271
251 /* clear all resources */ 272 /* clear all resources */
252 for (int i = 0; i < allocated.size (); i++) 273 for (int i = 0; i < allocated.size (); i++)
253 free (allocated[i]); 274 free (allocated [i]);
254 275
255 free (selection.text); 276 free (selection.text);
256 // TODO: manage env vars in child only(!) 277 // TODO: manage env vars in child only(!)
257 free (env_windowid); 278 free (env_windowid);
258 free (env_display); 279 free (env_display);
259 free (env_term); 280 free (env_term);
260 free (env_colorfgbg); 281 free (env_colorfgbg);
261 free (locale); 282 free (locale);
262#if 0 283 free (v_buffer);
263 free (codeset); 284 free (incr_buf);
264#endif
265 285
266 delete envv; 286 delete envv;
267 delete argv; 287 delete argv;
288
289#ifdef KEYSYM_RESOURCE
290 delete keyboard;
291#endif
268} 292}
269 293
270void 294void
271rxvt_term::destroy () 295rxvt_term::destroy ()
272{ 296{
324 348
325 delete this; 349 delete this;
326} 350}
327 351
328/*----------------------------------------------------------------------*/ 352/*----------------------------------------------------------------------*/
353/*
354 * Exit gracefully, clearing the utmp entry and restoring tty attributes
355 * TODO: if debugging, this should free up any known resources if we can
356 */
357static XErrorHandler old_xerror_handler;
358
359static void
360rxvt_emergency_cleanup ()
361{
362 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
363 (*t)->emergency_cleanup ();
364}
365
366#if ENABLE_FRILLS
367static void
368print_x_error (Display *dpy, XErrorEvent *event)
369{
370 char buffer[BUFSIZ];
371 char mesg[BUFSIZ];
372 char number[32];
373 char *mtype = "XlibMessage";
374 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
375 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
376 rxvt_warn ("An X Error occured, trying to continue after report.\n");
377 rxvt_warn ("%s: %s\n", mesg, buffer);
378 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
379 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
380 sprintf(number, "%d", event->request_code);
381 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
382 rxvt_warn ("(which is %s)\n", buffer);
383 if (event->request_code >= 128) {
384 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
385 mesg, BUFSIZ);
386 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
387 }
388 if ((event->error_code == BadWindow) ||
389 (event->error_code == BadPixmap) ||
390 (event->error_code == BadCursor) ||
391 (event->error_code == BadFont) ||
392 (event->error_code == BadDrawable) ||
393 (event->error_code == BadColor) ||
394 (event->error_code == BadGC) ||
395 (event->error_code == BadIDChoice) ||
396 (event->error_code == BadValue) ||
397 (event->error_code == BadAtom)) {
398 if (event->error_code == BadValue)
399 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
400 mesg, BUFSIZ);
401 else if (event->error_code == BadAtom)
402 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
403 mesg, BUFSIZ);
404 else
405 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
406 mesg, BUFSIZ);
407 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
408 }
409 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
410 mesg, BUFSIZ);
411 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
412}
413#endif
414
415int
416rxvt_xerror_handler (Display *display, XErrorEvent *event)
417{
418 if (GET_R->allowedxerror == -1)
419 GET_R->allowedxerror = event->error_code;
420 else
421 {
422 // GET_R is most likely not the terminal which caused the error,
423 // so just output the error and continue
424#if ENABLE_FRILLS
425 print_x_error (display, event);
426#else
427 old_xerror_handler (display, event);
428#endif
429 }
430
431 return 0;
432}
433
434int
435rxvt_xioerror_handler (Display *display)
436{
437 rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n",
438 DisplayString (display));
439 rxvt_emergency_cleanup ();
440 _exit (EXIT_FAILURE);
441}
442
443/*
444 * Catch a fatal signal and tidy up before quitting
445 */
446void
447rxvt_term::sig_term (sig_watcher &w)
448{
449#ifdef DEBUG_CMD
450 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
451#endif
452 rxvt_emergency_cleanup ();
453 signal (w.signum, SIG_DFL);
454 kill (getpid (), w.signum);
455}
456
457/*----------------------------------------------------------------------*/
329/* rxvt_init () */ 458/* rxvt_init () */
330bool 459bool
331rxvt_term::init (int argc, const char *const *argv) 460rxvt_term::init (int argc, const char *const *argv)
332{ 461{
333 SET_R (this); 462 SET_R (this);
334 463
464 set_locale ("");
465
335 if (!init_vars ()) 466 if (!init_vars ())
336 return false; 467 return false;
337 468
338 init_secondary (); 469 init_secondary ();
339 470
340 const char **cmd_argv = init_resources (argc, argv); 471 const char **cmd_argv = init_resources (argc, argv);
341 472
342 set_locale (""); 473#ifdef KEYSYM_RESOURCE
474 keyboard->register_done ();
475#endif
343 476
344#if MENUBAR_MAX 477#if MENUBAR_MAX
345 menubar_read (rs[Rs_menu]); 478 menubar_read (rs[Rs_menu]);
346#endif 479#endif
347#ifdef HAVE_SCROLLBARS 480#ifdef HAVE_SCROLLBARS
349 scrollBar.setIdle (); /* set existence for size calculations */ 482 scrollBar.setIdle (); /* set existence for size calculations */
350#endif 483#endif
351 484
352 create_windows (argc, argv); 485 create_windows (argc, argv);
353 486
487 dDisp;
488
354 init_xlocale (); 489 init_xlocale ();
355 490
356 scr_reset (); /* initialize screen */ 491 scr_reset (); /* initialize screen */
357 492
358#if 0 493#if 0
359 XSynchronize (display->display, True); 494 XSynchronize (disp, True);
360#endif 495#endif
361 496
362#ifdef HAVE_SCROLLBARS 497#ifdef HAVE_SCROLLBARS
363 if (options & Opt_scrollBar) 498 if (options & Opt_scrollBar)
364 resize_scrollbar (); /* create and map scrollbar */ 499 resize_scrollbar (); /* create and map scrollbar */
365#endif 500#endif
366#if (MENUBAR_MAX) 501#if (MENUBAR_MAX)
367 if (menubar_visible ()) 502 if (menubar_visible ())
368 XMapWindow (display->display, menuBar.win); 503 XMapWindow (disp, menuBar.win);
369#endif 504#endif
370#ifdef TRANSPARENT 505#ifdef TRANSPARENT
371 if (options & Opt_transparent) 506 if (options & Opt_transparent)
372 { 507 {
373 XSelectInput (display->display, display->root, PropertyChangeMask); 508 XSelectInput (disp, display->root, PropertyChangeMask);
374 check_our_parents (); 509 check_our_parents ();
375 rootwin_ev.start (display, display->root); 510 rootwin_ev.start (display, display->root);
376 } 511 }
377#endif 512#endif
378 513
379 XMapWindow (display->display, TermWin.vt); 514 XMapWindow (disp, TermWin.vt);
380 XMapWindow (display->display, TermWin.parent[0]); 515 XMapWindow (disp, TermWin.parent[0]);
381 516
382 set_colorfgbg (); 517 set_colorfgbg ();
383 518
384 init_command (cmd_argv); 519 init_command (cmd_argv);
385 520
521 free (cmd_argv);
522
386 pty_ev.start (pty.pty, EVENT_READ); 523 pty_ev.start (pty.pty, EVENT_READ);
387 524
388 check_ev.start (); 525 check_ev.start ();
389 526
390 return true; 527 return true;
391} 528}
392 529
393static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
394
395void 530void
396rxvt_init () 531rxvt_init ()
397{ 532{
398 /* install exit handler for cleanup */
399#if 0
400#ifdef HAVE_ATEXIT
401 atexit (rxvt_clean_exit);
402#else
403#endif
404#endif
405 /* 533 /*
406 * Save and then give up any super-user privileges 534 * Save and then give up any super-user privileges
407 * If we need privileges in any area then we must specifically request it. 535 * If we need privileges in any area then we must specifically request it.
408 * We should only need to be root in these cases: 536 * We should only need to be root in these cases:
409 * 1. write utmp entries on some systems 537 * 1. write utmp entries on some systems
410 * 2. chown tty on some systems 538 * 2. chown tty on some systems
411 */ 539 */
412 rxvt_privileges (SAVE); 540 rxvt_privileges (SAVE);
413 rxvt_privileges (IGNORE); 541 rxvt_privileges (IGNORE);
414 542
415 struct sigaction sa; 543 signal (SIGHUP, SIG_IGN);
416 544 signal (SIGPIPE, SIG_IGN);
417 sigfillset (&sa.sa_mask);
418 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
419 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
420 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
421 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
422 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
423 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
424 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
425 545
426 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 546 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
427 /* signal (SIGURG, SIG_DFL); */ 547 /* signal (SIGURG, SIG_DFL); */
428 548
429 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 549 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
550 // TODO: handle this with exceptions and tolerate the memory loss
430 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 551 XSetIOErrorHandler (rxvt_xioerror_handler);
431} 552}
432 553
433/* ------------------------------------------------------------------------- * 554/* ------------------------------------------------------------------------- *
434 * SIGNAL HANDLING & EXIT HANDLER * 555 * SIGNAL HANDLING & EXIT HANDLER *
435 * ------------------------------------------------------------------------- */ 556 * ------------------------------------------------------------------------- */
436/* 557/*
437 * Catch a SIGCHLD signal and exit if the direct child has died 558 * Catch a SIGCHLD signal and exit if the direct child has died
438 */ 559 */
439 560
440void rxvt_term::child_exited (int pid) 561void
562rxvt_term::sig_chld (sig_watcher &w)
441{ 563{
442 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 564 // we are being called for every SIGCHLD, not just ours
443 if (pid == (*t)->cmd_pid) 565 int pid;
444 {
445 (*t)->destroy ();
446 break;
447 }
448}
449
450/* ARGSUSED */
451/* INTPROTO */
452RETSIGTYPE
453rxvt_Child_signal (int sig __attribute__ ((unused)))
454{
455 int pid, save_errno = errno;
456 566
457 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 567 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
458 rxvt_term::child_exited (pid); 568 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
459 569 if (pid == (*t)->cmd_pid)
460 errno = save_errno; 570 {
461} 571 (*t)->destroy ();
462 572 break;
463/* 573 }
464 * Catch a fatal signal and tidy up before quitting
465 */
466/* INTPROTO */
467RETSIGTYPE
468rxvt_Exit_signal (int sig)
469{
470 signal (sig, SIG_DFL);
471#ifdef DEBUG_CMD
472 rxvt_warn ("caught signal %d, exiting.\n", sig);
473#endif
474 rxvt_clean_exit ();
475 kill (getpid (), sig);
476}
477
478/* INTPROTO */
479int
480rxvt_xerror_handler (Display *display, XErrorEvent *event)
481{
482 if (GET_R->allowedxerror == -1)
483 GET_R->allowedxerror = event->error_code;
484 else
485 {
486 old_xerror_handler (display, event);
487 GET_R->destroy ();
488 }
489
490 return 0;
491}
492
493/*----------------------------------------------------------------------*/
494/*
495 * Exit gracefully, clearing the utmp entry and restoring tty attributes
496 * TODO: if debugging, this should free up any known resources if we can
497 */
498/* INTPROTO */
499void
500rxvt_clean_exit ()
501{
502 // TODO: rxvtd should clean up all ressources
503 if (GET_R)
504 GET_R->destroy ();
505} 574}
506 575
507/* ------------------------------------------------------------------------- * 576/* ------------------------------------------------------------------------- *
508 * MEMORY ALLOCATION WRAPPERS * 577 * MEMORY ALLOCATION WRAPPERS *
509 * ------------------------------------------------------------------------- */ 578 * ------------------------------------------------------------------------- */
510/* INTPROTO */ 579void *
511void *
512rxvt_malloc (size_t size) 580rxvt_malloc (size_t size)
513{ 581{
514 void *p;
515
516 p = malloc (size); 582 void *p = malloc (size);
583
517 if (p) 584 if (!p)
518 return p;
519
520 rxvt_fatal ("memory allocation failure. aborting.\n"); 585 rxvt_fatal ("memory allocation failure. aborting.\n");
521 /* NOTREACHED */
522}
523 586
524/* INTPROTO */ 587 return p;
588}
589
525void * 590void *
526rxvt_calloc (size_t number, size_t size) 591rxvt_calloc (size_t number, size_t size)
527{ 592{
528 void *p;
529
530 p = calloc (number, size); 593 void *p = calloc (number, size);
594
531 if (p) 595 if (!p)
532 return p;
533
534 rxvt_fatal ("memory allocation failure. aborting.\n"); 596 rxvt_fatal ("memory allocation failure. aborting.\n");
535 /* NOTREACHED */
536}
537 597
538/* INTPROTO */ 598 return p;
599}
600
539void * 601void *
540rxvt_realloc (void *ptr, size_t size) 602rxvt_realloc (void *ptr, size_t size)
541{ 603{
542 void *p;
543
544 if (ptr)
545 p = realloc (ptr, size); 604 void *p = realloc (ptr, size);
546 else
547 p = malloc (size);
548 605
549 if (p) 606 if (!p)
550 return p;
551
552 rxvt_fatal ("memory allocation failure. aborting.\n"); 607 rxvt_fatal ("memory allocation failure. aborting.\n");
553 /* NOTREACHED */ 608
609 return p;
554} 610}
555 611
556/* ------------------------------------------------------------------------- * 612/* ------------------------------------------------------------------------- *
557 * PRIVILEGED OPERATIONS * 613 * PRIVILEGED OPERATIONS *
558 * ------------------------------------------------------------------------- */ 614 * ------------------------------------------------------------------------- */
633 * if width/height are non-zero then override calculated width/height 689 * if width/height are non-zero then override calculated width/height
634 */ 690 */
635void 691void
636rxvt_term::window_calc (unsigned int width, unsigned int height) 692rxvt_term::window_calc (unsigned int width, unsigned int height)
637{ 693{
638 short recalc_x, recalc_y; 694 short recalc_x, recalc_y;
639 int x, y, sb_w, mb_h, flags; 695 int x, y, sb_w, mb_h, flags;
640 unsigned int w, h; 696 unsigned int w, h;
641 unsigned int max_width, max_height; 697 unsigned int max_width, max_height;
698 dDisp;
642 699
643 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 700 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
644 TermWin.ncol, TermWin.nrow, szHint.width, 701 TermWin.ncol, TermWin.nrow, szHint.width,
645 szHint.height)); 702 szHint.height));
646 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 703 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
652 if (!parsed_geometry) 709 if (!parsed_geometry)
653 { 710 {
654 parsed_geometry = 1; 711 parsed_geometry = 1;
655 if (rs[Rs_geometry]) 712 if (rs[Rs_geometry])
656 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 713 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
714
657 if (flags & WidthValue) 715 if (flags & WidthValue)
658 { 716 {
659 TermWin.ncol = BOUND_POSITIVE_INT16 (w); 717 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
660 szHint.flags |= USSize; 718 szHint.flags |= USSize;
661 } 719 }
720
662 if (flags & HeightValue) 721 if (flags & HeightValue)
663 { 722 {
664 TermWin.nrow = BOUND_POSITIVE_INT16 (h); 723 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
665 szHint.flags |= USSize; 724 szHint.flags |= USSize;
666 } 725 }
726
667 if (flags & XValue) 727 if (flags & XValue)
668 { 728 {
669 szHint.x = x; 729 szHint.x = x;
670 szHint.flags |= USPosition; 730 szHint.flags |= USPosition;
671 if (flags & XNegative) 731 if (flags & XNegative)
672 { 732 {
673 recalc_x = 1; 733 recalc_x = 1;
674 szHint.win_gravity = NorthEastGravity; 734 szHint.win_gravity = NorthEastGravity;
675 } 735 }
676 } 736 }
737
677 if (flags & YValue) 738 if (flags & YValue)
678 { 739 {
679 szHint.y = y; 740 szHint.y = y;
680 szHint.flags |= USPosition; 741 szHint.flags |= USPosition;
681 if (flags & YNegative) 742 if (flags & YNegative)
744 805
745 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 806 if (scrollbar_visible () && (options & Opt_scrollBar_right))
746 window_sb_x = szHint.width - sb_w; 807 window_sb_x = szHint.width - sb_w;
747 808
748 if (recalc_x) 809 if (recalc_x)
749 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 810 szHint.x += (DisplayWidth (disp, display->screen)
750 - szHint.width - 2 * TermWin.ext_bwidth); 811 - szHint.width - 2 * TermWin.ext_bwidth);
751 if (recalc_y) 812 if (recalc_y)
752 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) 813 szHint.y += (DisplayHeight (disp, display->screen)
753 - szHint.height - 2 * TermWin.ext_bwidth); 814 - szHint.height - 2 * TermWin.ext_bwidth);
754 815
755 TermWin.ncol = TermWin.width / TermWin.fwidth; 816 TermWin.ncol = TermWin.width / TermWin.fwidth;
756 TermWin.nrow = TermWin.height / TermWin.fheight; 817 TermWin.nrow = TermWin.height / TermWin.fheight;
757 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 818 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
780 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 841 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
781 842
782#if 0 843#if 0
783 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 844 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
784 if (cmd_pid) /* force through to the command */ 845 if (cmd_pid) /* force through to the command */
785 kill (cmd_pid, SIGWINCH); 846 kill (-cmd_pid, SIGWINCH);
786#endif 847#endif
787} 848}
788 849
789/*----------------------------------------------------------------------*/ 850/*----------------------------------------------------------------------*/
790/* set_fonts () - load and set the various fonts 851/* set_fonts () - load and set the various fonts
791/* 852 *
792 * init = 1 - initialize 853 * init = 1 - initialize
793 * 854 *
794 * fontname == FONT_UP - switch to bigger font 855 * fontname == FONT_UP - switch to bigger font
795 * fontname == FONT_DN - switch to smaller font 856 * fontname == FONT_DN - switch to smaller font
796 */ 857 */
798rxvt_term::set_fonts () 859rxvt_term::set_fonts ()
799{ 860{
800 rxvt_fontset *fs = new rxvt_fontset (this); 861 rxvt_fontset *fs = new rxvt_fontset (this);
801 rxvt_fontprop prop; 862 rxvt_fontprop prop;
802 863
803 prop.width = prop.height = prop.weight = prop.slant
804 = rxvt_fontprop::unset;
805
806 if (!fs 864 if (!fs
807 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed", prop) 865 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed")
808 || !fs->realize_font (1)) 866 || !fs->realize_font (1))
809 { 867 {
810 delete fs; 868 delete fs;
811 return false; 869 return false;
812 } 870 }
818#endif 876#endif
819 877
820 delete TermWin.fontset[0]; 878 delete TermWin.fontset[0];
821 TermWin.fontset[0] = fs; 879 TermWin.fontset[0] = fs;
822 880
823 fs->prop = prop = (*fs)[1]->properties (); 881 prop = (*fs)[1]->properties ();
882 prop.height += TermWin.lineSpace;
883 fs->set_prop (prop);
824 884
825 TermWin.fwidth = prop.width; 885 TermWin.fwidth = prop.width;
826 TermWin.fheight = prop.height; 886 TermWin.fheight = prop.height;
827 TermWin.fweight = prop.weight; 887 TermWin.fweight = prop.weight;
828 TermWin.fslant = prop.slant; 888 TermWin.fslant = prop.slant;
848 908
849 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; 909 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
850 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; 910 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
851 } 911 }
852 912
853 fs->populate (res, prop2); 913 fs->populate (res);
914 fs->set_prop (prop2);
854 } 915 }
855#else 916#else
856 TermWin.fontset[style] = TermWin.fontset[0]; 917 TermWin.fontset[style] = TermWin.fontset[0];
857#endif 918#endif
858 } 919 }
865 } 926 }
866 927
867 return true; 928 return true;
868} 929}
869 930
931void rxvt_term::set_string_property (Atom prop, const char *str, int len)
932{
933 // TODO: SMART_WINDOW_TITLE
934 XChangeProperty (display->display, TermWin.parent[0],
935 prop, XA_STRING, 8, PropModeReplace,
936 (const unsigned char *)str, len >= 0 ? len : strlen (str));
937}
938
939void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
940{
941 // TODO: SMART_WINDOW_TITLE
942 wchar_t *ws = rxvt_mbstowcs (str, len);
943 char *s = rxvt_wcstoutf8 (ws);
944
945 XChangeProperty (display->display, TermWin.parent[0],
946 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
947 (const unsigned char *)s, strlen (s));
948
949 free (s);
950 free (ws);
951}
952
870/*----------------------------------------------------------------------*/ 953/*----------------------------------------------------------------------*/
871/*----------------------------------------------------------------------*/ 954/*----------------------------------------------------------------------*/
872/* xterm sequences - title, iconName, color (exptl) */ 955/* xterm sequences - title, iconName, color (exptl) */
873void 956void
874rxvt_term::set_title (const char *str) 957rxvt_term::set_title (const char *str)
875{ 958{
876#ifdef SMART_WINDOW_TITLE 959 set_string_property (XA_WM_NAME, str);
877 char *name; 960#if ENABLE_EWMH
878 961 set_utf8_property (xa[XA_NET_WM_NAME], str);
879 if (!XFetchName (display->display, TermWin.parent[0], &name))
880 name = NULL;
881
882 if (name == NULL || strcmp (name, str))
883#endif
884 XStoreName (display->display, TermWin.parent[0], str);
885
886#ifdef SMART_WINDOW_TITLE
887 if (name)
888 XFree (name);
889#endif 962#endif
890} 963}
891 964
892void 965void
893rxvt_term::set_icon_name (const char *str) 966rxvt_term::set_icon_name (const char *str)
894{ 967{
895#ifdef SMART_WINDOW_TITLE 968 set_string_property (XA_WM_ICON_NAME, str);
896 char *name; 969#if ENABLE_EWMH
897 970 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
898 if (!XGetIconName (display->display, TermWin.parent[0], &name))
899 name = NULL;
900
901 if (name == NULL || strcmp (name, str))
902#endif
903 XSetIconName (display->display, TermWin.parent[0], str);
904
905#ifdef SMART_WINDOW_TITLE
906 if (name)
907 XFree (name);
908#endif 971#endif
909} 972}
910 973
911#ifdef XTERM_COLOR_CHANGE 974#ifdef XTERM_COLOR_CHANGE
912void 975void
920 983
921 /* handle color aliases */ 984 /* handle color aliases */
922 if (isdigit (*color)) 985 if (isdigit (*color))
923 { 986 {
924 i = atoi (color); 987 i = atoi (color);
988
925 if (i >= 8 && i <= 15) 989 if (i >= 8 && i <= 15)
926 { /* bright colors */ 990 { /* bright colors */
927 i -= 8; 991 i -= 8;
928# ifndef NO_BRIGHTCOLOR 992# ifndef NO_BRIGHTCOLOR
929 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 993 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
930 SET_PIXCOLOR (idx); 994 SET_PIXCOLOR (idx);
931 goto Done; 995 goto done;
932# endif 996# endif
933
934 } 997 }
998
935 if (i >= 0 && i <= 7) 999 if (i >= 0 && i <= 7)
936 { /* normal colors */ 1000 { /* normal colors */
937 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1001 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
938 SET_PIXCOLOR (idx); 1002 SET_PIXCOLOR (idx);
939 goto Done; 1003 goto done;
940 } 1004 }
941 } 1005 }
942 1006
943 if (!rXParseAllocColor (& xcol, color)) 1007 if (!rXParseAllocColor (&xcol, color))
944 return; 1008 return;
945 1009
946 /* XStoreColor (display->display, display->cmap, XColor*); */ 1010 /* XStoreColor (display->display, display->cmap, XColor*); */
947 1011
948 /* 1012 /*
964 pix_colors_focused[idx] = xcol; 1028 pix_colors_focused[idx] = xcol;
965 SET_PIXCOLOR (idx); 1029 SET_PIXCOLOR (idx);
966 1030
967 /* XSetWindowAttributes attr; */ 1031 /* XSetWindowAttributes attr; */
968 /* Cursor cursor; */ 1032 /* Cursor cursor; */
969Done: 1033done:
1034
970#ifdef OFF_FOCUS_FADING 1035#if OFF_FOCUS_FADING
971 if (rs[Rs_fade]) 1036 if (rs[Rs_fade])
972 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); 1037 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]);
973#endif 1038#endif
974 1039
975 /*TODO: handle Color_BD, scrollbar background, etc. */ 1040 /*TODO: handle Color_BD, scrollbar background, etc. */
976 1041
977 recolour_cursor (); 1042 recolour_cursor ();
1031 1096
1032 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1097 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1033} 1098}
1034 1099
1035/*----------------------------------------------------------------------*/ 1100/*----------------------------------------------------------------------*/
1036/*
1037 * Colour determination for low colour displays, routine from
1038 * Hans de Goede <hans@highrise.nl>
1039 */
1040 1101
1041int 1102int
1042rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1103rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1043{ 1104{
1044 if (!screen_in_out->set (display, colour)) 1105 if (!screen_in_out->set (display, colour))
1055 * -------------------------------------------------------------------- */ 1116 * -------------------------------------------------------------------- */
1056void 1117void
1057rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) 1118rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent)
1058{ 1119{
1059 int fix_screen; 1120 int fix_screen;
1060
1061#ifdef SMART_RESIZE 1121#ifdef SMART_RESIZE
1062 int old_width = szHint.width, old_height = szHint.height; 1122 int old_width = szHint.width, old_height = szHint.height;
1063#endif 1123#endif
1124 dDisp;
1064 1125
1065 window_calc (width, height); 1126 window_calc (width, height);
1066 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1127 XSetWMNormalHints (disp, TermWin.parent[0], &szHint);
1067 1128
1068 if (!ignoreparent) 1129 if (!ignoreparent)
1069 { 1130 {
1070#ifdef SMART_RESIZE 1131#ifdef SMART_RESIZE
1071 /* 1132 /*
1075 int x, y, x1, y1; 1136 int x, y, x1, y1;
1076 int dx, dy; 1137 int dx, dy;
1077 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1138 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1078 Window unused_cr; 1139 Window unused_cr;
1079 1140
1080 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1141 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
1081 0, 0, &x, &y, &unused_cr); 1142 0, 0, &x, &y, &unused_cr);
1082 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, 1143 XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1,
1083 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1144 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1084 /* 1145 /*
1085 * if display->root isn't the parent window, a WM will probably have offset 1146 * if display->root isn't the parent window, a WM will probably have offset
1086 * our position for handles and decorations. Counter it 1147 * our position for handles and decorations. Counter it
1087 */ 1148 */
1089 { 1150 {
1090 x -= x1; 1151 x -= x1;
1091 y -= y1; 1152 y -= y1;
1092 } 1153 }
1093 1154
1094 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; 1155 x1 = (DisplayWidth (disp, display->screen) - old_width) / 2;
1095 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; 1156 y1 = (DisplayHeight (disp, display->screen) - old_height) / 2;
1096 dx = old_width - szHint.width; 1157 dx = old_width - szHint.width;
1097 dy = old_height - szHint.height; 1158 dy = old_height - szHint.height;
1098 1159
1099 /* Check position of the center of the window */ 1160 /* Check position of the center of the window */
1100 if (x < x1) /* left half */ 1161 if (x < x1) /* left half */
1104 if (y < y1) /* top half */ 1165 if (y < y1) /* top half */
1105 dy = 0; 1166 dy = 0;
1106 else if (y == y1) /* exact center */ 1167 else if (y == y1) /* exact center */
1107 dy /= 2; 1168 dy /= 2;
1108 1169
1109 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1170 XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy,
1110 szHint.width, szHint.height); 1171 szHint.width, szHint.height);
1111#else 1172#else
1112 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); 1173 XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height);
1113#endif 1174#endif
1114 } 1175 }
1115 1176
1116 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; 1177 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1117 1178
1118 if (fix_screen || width != old_width || height != old_height) 1179 if (fix_screen || width != old_width || height != old_height)
1119 { 1180 {
1120 if (scrollbar_visible ()) 1181 if (scrollbar_visible ())
1121 { 1182 {
1122 XMoveResizeWindow (display->display, scrollBar.win, 1183 XMoveResizeWindow (disp, scrollBar.win,
1123 window_sb_x, 0, 1184 window_sb_x, 0,
1124 scrollbar_TotalWidth (), szHint.height); 1185 scrollbar_TotalWidth (), szHint.height);
1125 resize_scrollbar (); 1186 resize_scrollbar ();
1126 } 1187 }
1127 1188
1128 if (menubar_visible ()) 1189 if (menubar_visible ())
1129 XMoveResizeWindow (display->display, menuBar.win, 1190 XMoveResizeWindow (disp, menuBar.win,
1130 window_vt_x, 0, 1191 window_vt_x, 0,
1131 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1192 TermWin_TotalWidth (), menuBar_TotalHeight ());
1132 1193
1133 XMoveResizeWindow (display->display, TermWin.vt, 1194 XMoveResizeWindow (disp, TermWin.vt,
1134 window_vt_x, window_vt_y, 1195 window_vt_x, window_vt_y,
1135 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1196 TermWin_TotalWidth (), TermWin_TotalHeight ());
1197
1136 scr_clear (); 1198 scr_clear ();
1137#ifdef XPM_BACKGROUND 1199#ifdef XPM_BACKGROUND
1138 resize_pixmap (); 1200 resize_pixmap ();
1139#endif 1201#endif
1140 } 1202 }
1163 } 1225 }
1164 1226
1165 old_width = szHint.width; 1227 old_width = szHint.width;
1166 old_height = szHint.height; 1228 old_height = szHint.height;
1167 1229
1230#ifdef XPM_BACKGROUND
1231 if (TermWin.pixmap)
1232 scr_touch (false);
1233#endif
1234
1168#ifdef USE_XIM 1235#ifdef USE_XIM
1169 IMSetStatusPosition (); 1236 IMSetStatusPosition ();
1170#endif 1237#endif
1171} 1238}
1172 1239
1180 XWindowAttributes wattr; 1247 XWindowAttributes wattr;
1181 1248
1182 if (width == 0 || height == 0) 1249 if (width == 0 || height == 0)
1183 { 1250 {
1184 XGetWindowAttributes (display->display, display->root, &wattr); 1251 XGetWindowAttributes (display->display, display->root, &wattr);
1252
1185 if (width == 0) 1253 if (width == 0)
1186 width = wattr.width - szHint.base_width; 1254 width = wattr.width - szHint.base_width;
1187 if (height == 0) 1255 if (height == 0)
1188 height = wattr.height - szHint.base_height; 1256 height = wattr.height - szHint.base_height;
1189 } 1257 }
1263} 1331}
1264 1332
1265void 1333void
1266rxvt_term::IMSendSpot () 1334rxvt_term::IMSendSpot ()
1267{ 1335{
1268 XPoint spot; 1336 XPoint nspot;
1269 XVaNestedList preedit_attr; 1337 XVaNestedList preedit_attr;
1270 1338
1271 if (!Input_Context 1339 if (!Input_Context
1272 || !TermWin.focus 1340 || !TermWin.focus
1273 || !(input_style & XIMPreeditPosition) 1341 || !(input_style & XIMPreeditPosition))
1274#if 0
1275 || !(event_type == KeyPress
1276 || event_type == Expose
1277 || event_type == NoExpose
1278 || event_type == SelectionNotify
1279 || event_type == ButtonRelease || event_type == FocusIn)
1280#endif
1281 || !IMisRunning ())
1282 return; 1342 return;
1283 1343
1284 im_set_position (spot); 1344 im_set_position (nspot);
1345
1346 if (nspot.x == spot.x && nspot.y == spot.y)
1347 return;
1348
1349 spot = nspot;
1285 1350
1286 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1351 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1287 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1352 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1288 XFree (preedit_attr); 1353 XFree (preedit_attr);
1289} 1354}
1290 1355
1291void 1356void
1292rxvt_term::im_destroy () 1357rxvt_term::im_destroy ()
1293{ 1358{
1294 if (Input_Context)
1295 {
1296 XDestroyIC (Input_Context);
1297 Input_Context = 0;
1298 }
1299
1300 if (input_method) 1359 if (input_method)
1301 { 1360 {
1361 if (Input_Context && input_method->xim)
1362 XDestroyIC (Input_Context);
1363
1302 display->put_xim (input_method); 1364 display->put_xim (input_method);
1303 input_method = 0; 1365 input_method = 0;
1304 } 1366 }
1367
1368 Input_Context = 0;
1305} 1369}
1306 1370
1307/* 1371/*
1308 * Try to open a XIM with the current modifiers, then see if we can 1372 * Try to open a XIM with the current modifiers, then see if we can
1309 * open a suitable preedit type 1373 * open a suitable preedit type
1327 input_method = display->get_xim (locale, modifiers); 1391 input_method = display->get_xim (locale, modifiers);
1328 if (input_method == NULL) 1392 if (input_method == NULL)
1329 return false; 1393 return false;
1330 1394
1331 xim = input_method->xim; 1395 xim = input_method->xim;
1396 spot.x = spot.y = -1;
1332 1397
1333 xim_styles = NULL; 1398 xim_styles = NULL;
1334 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1399 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1335 || !xim_styles || !xim_styles->count_styles) 1400 || !xim_styles || !xim_styles->count_styles)
1336 { 1401 {
1337 im_destroy (); 1402 im_destroy ();
1338 return false; 1403 return false;
1339 } 1404 }
1340 1405
1341 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1406 const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };
1407
1408 for (int pi = 0; pi < 2; pi++)
1409 {
1410 p = pet[pi];
1411
1412 if (!p)
1413 continue;
1414
1342 s = rxvt_splitcommastring (p); 1415 s = rxvt_splitcommastring (p);
1343 1416
1344 for (i = found = 0; !found && s[i]; i++) 1417 for (i = found = 0; !found && s[i]; i++)
1345 { 1418 {
1346 if (!strcmp (s[i], "OverTheSpot")) 1419 if (!strcmp (s[i], "OverTheSpot"))
1347 input_style = (XIMPreeditPosition | XIMStatusNothing); 1420 input_style = (XIMPreeditPosition | XIMStatusNothing);
1348 else if (!strcmp (s[i], "OffTheSpot")) 1421 else if (!strcmp (s[i], "OffTheSpot"))
1349 input_style = (XIMPreeditArea | XIMStatusArea); 1422 input_style = (XIMPreeditArea | XIMStatusArea);
1350 else if (!strcmp (s[i], "Root")) 1423 else if (!strcmp (s[i], "Root"))
1351 input_style = (XIMPreeditNothing | XIMStatusNothing); 1424 input_style = (XIMPreeditNothing | XIMStatusNothing);
1425 else if (!strcmp (s[i], "None"))
1426 input_style = (XIMPreeditNone | XIMStatusNone);
1352 1427
1353 for (j = 0; j < xim_styles->count_styles; j++) 1428 for (j = 0; j < xim_styles->count_styles; j++)
1354 if (input_style == xim_styles->supported_styles[j]) 1429 if (input_style == xim_styles->supported_styles[j])
1355 { 1430 {
1431 rxvt_freecommastring (s);
1432
1356 found = 1; 1433 found = 1;
1357 break; 1434 goto foundpet;
1435 }
1436
1358 } 1437 }
1359 }
1360 1438
1361 for (i = 0; s[i]; i++) 1439 rxvt_freecommastring (s);
1362 free (s[i]); 1440 }
1363 1441
1364 free (s); 1442foundpet:
1443
1365 XFree (xim_styles); 1444 XFree (xim_styles);
1366 1445
1367 if (!found) 1446 if (!found)
1368 { 1447 {
1369 im_destroy (); 1448 im_destroy ();
1390 "*", 1469 "*",
1391 TermWin.fheight, 1470 TermWin.fheight,
1392 TermWin.fheight + 1, TermWin.fheight - 1, 1471 TermWin.fheight + 1, TermWin.fheight - 1,
1393 TermWin.fheight - 2, TermWin.fheight + 2); 1472 TermWin.fheight - 2, TermWin.fheight + 2);
1394 1473
1395 fs = XCreateFontSet (display->display, pat, 1474 fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
1396 &missing_charset_list, &missing_charset_count, &def_string); 1475 &missing_charset_list, &missing_charset_count, &def_string);
1397 1476
1398 if (missing_charset_list) 1477 if (missing_charset_list)
1399 XFreeStringList (missing_charset_list); 1478 XFreeStringList (missing_charset_list);
1400 1479
1472} 1551}
1473 1552
1474void 1553void
1475rxvt_term::im_cb () 1554rxvt_term::im_cb ()
1476{ 1555{
1477 int i, found, had_im; 1556 int i;
1478 const char *p; 1557 const char *p;
1479 char **s; 1558 char **s;
1480 char buf[IMBUFSIZ]; 1559 char buf[IMBUFSIZ];
1481 1560
1561 SET_R (this);
1562
1482 im_destroy (); 1563 im_destroy ();
1483 1564
1484 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1565 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1485 if (Input_Context) 1566 if (Input_Context)
1486 return; 1567 return;
1494 if (p && *p) 1575 if (p && *p)
1495 { 1576 {
1496 bool found = false; 1577 bool found = false;
1497 1578
1498 s = rxvt_splitcommastring (p); 1579 s = rxvt_splitcommastring (p);
1580
1499 for (i = 0; s[i]; i++) 1581 for (i = 0; s[i]; i++)
1500 { 1582 {
1501 if (*s[i]) 1583 if (*s[i])
1502 { 1584 {
1503 strcpy (buf, "@im="); 1585 strcpy (buf, "@im=");
1507 found = true; 1589 found = true;
1508 break; 1590 break;
1509 } 1591 }
1510 } 1592 }
1511 } 1593 }
1512 for (i = 0; s[i]; i++) 1594
1513 free (s[i]); 1595 rxvt_freecommastring (s);
1514 free (s);
1515 1596
1516 if (found) 1597 if (found)
1517 goto done; 1598 goto done;
1518 } 1599 }
1519 1600

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines