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.70 by root, Mon Jul 26 18:01:19 2004 UTC vs.
Revision 1.94 by root, Sun Aug 15 22:09:24 2004 UTC

51static char curlocale[128]; 51static char curlocale[128];
52 52
53bool 53bool
54rxvt_set_locale (const char *locale) 54rxvt_set_locale (const char *locale)
55{ 55{
56 if (!locale || !STRNCMP (locale, curlocale, 128)) 56 if (!locale || !strncmp (locale, curlocale, 128))
57 return false; 57 return false;
58 58
59 STRNCPY (curlocale, locale, 128); 59 strncpy (curlocale, locale, 128);
60 setlocale (LC_CTYPE, curlocale); 60 setlocale (LC_CTYPE, curlocale);
61 return true; 61 return true;
62} 62}
63 63
64#if ENABLE_COMBINING 64#if ENABLE_COMBINING
128void * 128void *
129rxvt_term::operator new (size_t s) 129rxvt_term::operator new (size_t s)
130{ 130{
131 void *p = malloc (s); 131 void *p = malloc (s);
132 132
133 MEMSET (p, 0, s); 133 memset (p, 0, s);
134 return p; 134 return p;
135} 135}
136 136
137void 137void
138rxvt_term::operator delete (void *p, size_t s) 138rxvt_term::operator delete (void *p, size_t s)
140 free (p); 140 free (p);
141} 141}
142 142
143rxvt_term::rxvt_term () 143rxvt_term::rxvt_term ()
144 : 144 :
145#if TRANSPARENT
145 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
146 termwin_ev (this, &rxvt_term::x_cb), 175 termwin_ev (this, &rxvt_term::x_cb),
147 vt_ev (this, &rxvt_term::x_cb), 176 vt_ev (this, &rxvt_term::x_cb),
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
175 check_ev (this, &rxvt_term::check_cb), 177 check_ev (this, &rxvt_term::check_cb),
178 flush_ev (this, &rxvt_term::flush_cb),
176 destroy_ev (this, &rxvt_term::destroy_cb), 179 destroy_ev (this, &rxvt_term::destroy_cb),
177 pty_ev (this, &rxvt_term::pty_cb), 180 pty_ev (this, &rxvt_term::pty_cb),
178 incr_ev (this, &rxvt_term::incr_cb) 181 incr_ev (this, &rxvt_term::incr_cb)
179{ 182{
180 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 183 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
184 187
185rxvt_term::~rxvt_term () 188rxvt_term::~rxvt_term ()
186{ 189{
187 termlist.erase (find (termlist.begin (), termlist.end(), this)); 190 termlist.erase (find (termlist.begin (), termlist.end(), this));
188 191
189 if (cmd_fd >= 0) 192 if (cmd_pid)
190 close (cmd_fd); 193 kill (-cmd_pid, SIGHUP);
191 194
192#ifndef NO_SETOWNER_TTYDEV 195 pty.put ();
193 privileged_ttydev (RESTORE); 196
194#endif
195#ifdef UTMP_SUPPORT 197#ifdef UTMP_SUPPORT
196 privileged_utmp (RESTORE); 198 privileged_utmp (RESTORE);
197#endif 199#endif
198 200
199 delete TermWin.fontset; 201 delete TermWin.fontset;
200 202
201 if (display) 203 if (display)
202 { 204 {
203 selection_clear (); 205 selection_clear ();
204 206
207#ifdef USE_XIM
208 im_destroy ();
209#endif
205#ifdef MENUBAR 210#ifdef MENUBAR
206 if (menubarGC) XFreeGC (display->display, menubarGC); 211 if (menubarGC) XFreeGC (display->display, menubarGC);
207#endif 212#endif
208#ifdef XTERM_SCROLLBAR 213#ifdef XTERM_SCROLLBAR
209 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); 214 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
210 if (ShadowGC) XFreeGC (display->display, ShadowGC); 215 if (ShadowGC) XFreeGC (display->display, ShadowGC);
211#endif 216#endif
242 XDestroyWindow (display->display, TermWin.parent[0]); 247 XDestroyWindow (display->display, TermWin.parent[0]);
243 } 248 }
244 249
245 // TODO: free pixcolours, colours should become part of rxvt_display 250 // TODO: free pixcolours, colours should become part of rxvt_display
246 251
247 delete PixColors; 252 delete pix_colors_focused;
253#ifdef OFF_FOCUS_FADING
254 delete pix_colors_unfocused;
255#endif
248 256
249 displays.put (display); 257 displays.put (display);
250 258
251 scr_release (); 259 scr_release ();
252 260
270} 278}
271 279
272void 280void
273rxvt_term::destroy () 281rxvt_term::destroy ()
274{ 282{
283 if (destroy_ev.active)
284 return;
285
286#if ENABLE_OVERLAY
287 scr_overlay_off ();
288#endif
289
275 if (display) 290 if (display)
276 { 291 {
292#if USE_XIM
293 im_ev.stop (display);
294#endif
295#if HAVE_SCROLLBARS
296 scrollbar_ev.stop (display);
297#endif
298#if MENUBAR
299 menubar_ev.stop (display);
300#endif
301#if TRANSPARENT
277 rootwin_ev.stop (display); 302 rootwin_ev.stop (display);
303#endif
304 incr_ev.stop ();
278 termwin_ev.stop (display); 305 termwin_ev.stop (display);
279 vt_ev.stop (display); 306 vt_ev.stop (display);
280#ifdef USE_XIM
281 im_destroy ();
282 im_ev.stop (display);
283#endif
284#ifdef HAVE_SCROLLBARS
285 scrollbar_ev.stop (display);
286#endif
287#ifdef MENUBAR
288 menubar_ev.stop (display);
289#endif
290 } 307 }
291 308
292 check_ev.stop (); 309 check_ev.stop ();
293 pty_ev.stop (); 310 pty_ev.stop ();
294#ifdef CURSOR_BLINK 311#ifdef CURSOR_BLINK
326 SET_R (this); 343 SET_R (this);
327 344
328 if (!init_vars ()) 345 if (!init_vars ())
329 return false; 346 return false;
330 347
348 init_secondary ();
349
350 const char **cmd_argv = init_resources (argc, argv);
351
352 set_locale ("");
353
354#if MENUBAR_MAX
355 menubar_read (rs[Rs_menu]);
356#endif
357#ifdef HAVE_SCROLLBARS
358 if (options & Opt_scrollBar)
359 scrollBar.setIdle (); /* set existence for size calculations */
360#endif
361
362 create_windows (argc, argv);
363
364 init_xlocale ();
365
366 scr_reset (); /* initialize screen */
367
368#if 0
369 XSynchronize (display->display, True);
370#endif
371
372#ifdef HAVE_SCROLLBARS
373 if (options & Opt_scrollBar)
374 resize_scrollbar (); /* create and map scrollbar */
375#endif
376#if (MENUBAR_MAX)
377 if (menubar_visible ())
378 XMapWindow (display->display, menuBar.win);
379#endif
380#ifdef TRANSPARENT
381 if (options & Opt_transparent)
382 {
383 XSelectInput (display->display, display->root, PropertyChangeMask);
384 check_our_parents ();
385 rootwin_ev.start (display, display->root);
386 }
387#endif
388
389 XMapWindow (display->display, TermWin.vt);
390 XMapWindow (display->display, TermWin.parent[0]);
391
392 init_command (cmd_argv);
393
394 pty_ev.start (pty.pty, EVENT_READ);
395
396 check_ev.start ();
397
398 return true;
399}
400
401static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
402
403void
404rxvt_init ()
405{
406 /* install exit handler for cleanup */
407#if 0
408#ifdef HAVE_ATEXIT
409 atexit (rxvt_clean_exit);
410#else
411#endif
412#endif
331 /* 413 /*
332 * Save and then give up any super-user privileges 414 * Save and then give up any super-user privileges
333 * If we need privileges in any area then we must specifically request it. 415 * If we need privileges in any area then we must specifically request it.
334 * We should only need to be root in these cases: 416 * We should only need to be root in these cases:
335 * 1. write utmp entries on some systems 417 * 1. write utmp entries on some systems
336 * 2. chown tty on some systems 418 * 2. chown tty on some systems
337 */ 419 */
338 privileges (SAVE); 420 rxvt_privileges (SAVE);
339 privileges (IGNORE); 421 rxvt_privileges (IGNORE);
340
341 init_secondary ();
342
343 const char **cmd_argv = init_resources (argc, argv);
344
345 set_locale ("");
346
347#if MENUBAR_MAX
348 menubar_read (rs[Rs_menu]);
349#endif
350#ifdef HAVE_SCROLLBARS
351 if (Options & Opt_scrollBar)
352 scrollBar.setIdle (); /* set existence for size calculations */
353#endif
354
355 create_windows (argc, argv);
356
357 init_xlocale ();
358
359 scr_reset (); /* initialize screen */
360
361#if 0
362 XSynchronize (display->display, True);
363#endif
364
365#ifdef HAVE_SCROLLBARS
366 if (Options & Opt_scrollBar)
367 resize_scrollbar (); /* create and map scrollbar */
368#endif
369#if (MENUBAR_MAX)
370 if (menubar_visible ())
371 XMapWindow (display->display, menuBar.win);
372#endif
373#ifdef TRANSPARENT
374 if (Options & Opt_transparent)
375 {
376 XSelectInput (display->display, display->root, PropertyChangeMask);
377 check_our_parents ();
378 }
379#endif
380
381 rootwin_ev.start (display, display->root);
382
383 XMapWindow (display->display, TermWin.vt);
384 XMapWindow (display->display, TermWin.parent[0]);
385
386 init_command (cmd_argv);
387
388 pty_ev.start (cmd_fd, EVENT_READ);
389
390 check_ev.start ();
391
392 return true;
393}
394
395static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
396
397void
398rxvt_init_signals ()
399{
400 /* install exit handler for cleanup */
401#if 0
402#ifdef HAVE_ATEXIT
403 atexit (rxvt_clean_exit);
404#else
405#endif
406#endif
407 422
408 struct sigaction sa; 423 struct sigaction sa;
409 424
410 sigfillset (&sa.sa_mask); 425 sigfillset (&sa.sa_mask);
411 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; 426 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
439 break; 454 break;
440 } 455 }
441} 456}
442 457
443/* ARGSUSED */ 458/* ARGSUSED */
444/* EXTPROTO */ 459/* INTPROTO */
445RETSIGTYPE 460RETSIGTYPE
446rxvt_Child_signal (int sig __attribute__ ((unused))) 461rxvt_Child_signal (int sig __attribute__ ((unused)))
447{ 462{
448 int pid, save_errno = errno; 463 int pid, save_errno = errno;
449 464
454} 469}
455 470
456/* 471/*
457 * Catch a fatal signal and tidy up before quitting 472 * Catch a fatal signal and tidy up before quitting
458 */ 473 */
459/* EXTPROTO */ 474/* INTPROTO */
460RETSIGTYPE 475RETSIGTYPE
461rxvt_Exit_signal (int sig) 476rxvt_Exit_signal (int sig)
462{ 477{
463 signal (sig, SIG_DFL); 478 signal (sig, SIG_DFL);
464#ifdef DEBUG_CMD 479#ifdef DEBUG_CMD
486/*----------------------------------------------------------------------*/ 501/*----------------------------------------------------------------------*/
487/* 502/*
488 * Exit gracefully, clearing the utmp entry and restoring tty attributes 503 * Exit gracefully, clearing the utmp entry and restoring tty attributes
489 * TODO: if debugging, this should free up any known resources if we can 504 * TODO: if debugging, this should free up any known resources if we can
490 */ 505 */
491/* EXTPROTO */ 506/* INTPROTO */
492void 507void
493rxvt_clean_exit () 508rxvt_clean_exit ()
494{ 509{
495 // TODO: rxvtd should clean up all ressources 510 // TODO: rxvtd should clean up all ressources
496 if (GET_R) 511 if (GET_R)
498} 513}
499 514
500/* ------------------------------------------------------------------------- * 515/* ------------------------------------------------------------------------- *
501 * MEMORY ALLOCATION WRAPPERS * 516 * MEMORY ALLOCATION WRAPPERS *
502 * ------------------------------------------------------------------------- */ 517 * ------------------------------------------------------------------------- */
503/* EXTPROTO */ 518/* INTPROTO */
504void * 519void *
505rxvt_malloc (size_t size) 520rxvt_malloc (size_t size)
506{ 521{
507 void *p; 522 void *p;
508 523
509 p = malloc (size); 524 p = malloc (size);
510 if (p) 525 if (p)
511 return p; 526 return p;
512 527
513 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 528 rxvt_fatal ("memory allocation failure. aborting.\n");
514 rxvt_clean_exit ();
515 exit (EXIT_FAILURE);
516 /* NOTREACHED */ 529 /* NOTREACHED */
517} 530}
518 531
519/* EXTPROTO */ 532/* INTPROTO */
520void * 533void *
521rxvt_calloc (size_t number, size_t size) 534rxvt_calloc (size_t number, size_t size)
522{ 535{
523 void *p; 536 void *p;
524 537
525 p = calloc (number, size); 538 p = calloc (number, size);
526 if (p) 539 if (p)
527 return p; 540 return p;
528 541
529 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 542 rxvt_fatal ("memory allocation failure. aborting.\n");
530 rxvt_clean_exit ();
531 exit (EXIT_FAILURE);
532 /* NOTREACHED */ 543 /* NOTREACHED */
533} 544}
534 545
535/* EXTPROTO */ 546/* INTPROTO */
536void * 547void *
537rxvt_realloc (void *ptr, size_t size) 548rxvt_realloc (void *ptr, size_t size)
538{ 549{
539 void *p; 550 void *p;
540 551
541 if (ptr) 552 if (ptr)
542 p = realloc (ptr, size); 553 p = realloc (ptr, size);
543 else 554 else
544 p = malloc (size); 555 p = malloc (size);
556
545 if (p) 557 if (p)
546 return p; 558 return p;
547 559
548 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 560 rxvt_fatal ("memory allocation failure. aborting.\n");
549 rxvt_clean_exit ();
550 exit (EXIT_FAILURE);
551 /* NOTREACHED */ 561 /* NOTREACHED */
552} 562}
553 563
554/* ------------------------------------------------------------------------- * 564/* ------------------------------------------------------------------------- *
555 * PRIVILEGED OPERATIONS * 565 * PRIVILEGED OPERATIONS *
556 * ------------------------------------------------------------------------- */ 566 * ------------------------------------------------------------------------- */
557/* take care of suid/sgid super-user (root) privileges */ 567/* take care of suid/sgid super-user (root) privileges */
558void 568void
559rxvt_term::privileges (int mode) 569rxvt_privileges (rxvt_privaction action)
560{ 570{
571#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
572 static uid_t euid;
573 static gid_t egid;
574#endif
575
561#if ! defined(__CYGWIN32__) 576#if ! defined(__CYGWIN32__)
562# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 577# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
563 /* setreuid () is the poor man's setuid (), seteuid () */ 578 /* setreuid () is the poor man's setuid (), seteuid () */
564# define seteuid(a) setreuid(-1, (a)) 579# define seteuid(a) setreuid(-1, (a))
565# define setegid(a) setregid(-1, (a)) 580# define setegid(a) setregid(-1, (a))
566# define HAVE_SETEUID 581# define HAVE_SETEUID
567# endif 582# endif
568# ifdef HAVE_SETEUID 583# ifdef HAVE_SETEUID
569 switch (mode) 584 switch (action)
570 { 585 {
571 case IGNORE: 586 case IGNORE:
572 /* 587 /*
573 * change effective uid/gid - not real uid/gid - so we can switch 588 * change effective uid/gid - not real uid/gid - so we can switch
574 * back to root later, as required 589 * back to root later, as required
584 seteuid (euid); 599 seteuid (euid);
585 setegid (egid); 600 setegid (egid);
586 break; 601 break;
587 } 602 }
588# else 603# else
589 switch (mode) 604 switch (action)
590 { 605 {
591 case IGNORE: 606 case IGNORE:
592 setuid (getuid ()); 607 setuid (getuid ());
593 setgid (getgid ()); 608 setgid (getgid ());
594 /* FALLTHROUGH */ 609 /* FALLTHROUGH */
601#endif 616#endif
602} 617}
603 618
604#ifdef UTMP_SUPPORT 619#ifdef UTMP_SUPPORT
605void 620void
606rxvt_term::privileged_utmp (char action) 621rxvt_term::privileged_utmp (rxvt_privaction action)
607{ 622{
608 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
609 action, next_utmp_action, getpid ()));
610 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
611 || (Options & Opt_utmpInhibit) 623 if ((options & Opt_utmpInhibit)
612 || ttydev == NULL || *ttydev == '\0') 624 || !pty.name || !*pty.name)
613 return; 625 return;
614 626
615 privileges (RESTORE); 627 rxvt_privileges (RESTORE);
628
616 if (action == SAVE) 629 if (action == SAVE)
617 {
618 next_utmp_action = RESTORE;
619 makeutent (ttydev, rs[Rs_display_name]); 630 makeutent (pty.name, rs[Rs_display_name]);
620 }
621 else 631 else
622 { /* action == RESTORE */
623 next_utmp_action = IGNORE;
624 cleanutent (); 632 cleanutent ();
625 } 633
626 privileges (IGNORE); 634 rxvt_privileges (IGNORE);
627}
628#endif
629
630#ifndef NO_SETOWNER_TTYDEV
631void
632rxvt_term::privileged_ttydev (char action)
633{
634 D_MAIN ((stderr,
635 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
636 action, next_tty_action, getpid ()));
637 if (next_tty_action != action || (action != SAVE && action != RESTORE)
638 || ttydev == NULL || *ttydev == '\0')
639 return;
640
641 privileges (RESTORE);
642
643 if (action == SAVE)
644 {
645 next_tty_action = RESTORE;
646# ifndef RESET_TTY_TO_COMMON_DEFAULTS
647 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
648 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
649 next_tty_action = IGNORE;
650 else
651# endif
652
653 {
654 chown (ttydev, getuid (), ttygid); /* fail silently */
655 chmod (ttydev, ttymode);
656# ifdef HAVE_REVOKE
657 revoke (ttydev);
658# endif
659
660 }
661 }
662 else
663 { /* action == RESTORE */
664 next_tty_action = IGNORE;
665# ifndef RESET_TTY_TO_COMMON_DEFAULTS
666 chmod (ttydev, ttyfd_stat.st_mode);
667 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
668# else
669 chmod (ttydev,
670 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
671 chown (ttydev, 0, 0);
672# endif
673
674 }
675
676 privileges (IGNORE);
677
678# ifndef RESET_TTY_TO_COMMON_DEFAULTS
679 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
680 action == RESTORE ? "Restoring" : (action ==
681 SAVE ? "Saving" :
682 "UNKNOWN ERROR for"), ttydev,
683 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
684 ttyfd_stat.st_gid));
685# endif
686} 635}
687#endif 636#endif
688 637
689/*----------------------------------------------------------------------*/ 638/*----------------------------------------------------------------------*/
690/* 639/*
761 710
762 if (scrollbar_visible ()) 711 if (scrollbar_visible ())
763 { 712 {
764 sb_w = scrollbar_TotalWidth (); 713 sb_w = scrollbar_TotalWidth ();
765 szHint.base_width += sb_w; 714 szHint.base_width += sb_w;
766 if (!(Options & Opt_scrollBar_right)) 715 if (!(options & Opt_scrollBar_right))
767 window_vt_x += sb_w; 716 window_vt_x += sb_w;
768 } 717 }
769 718
770 if (menubar_visible ()) 719 if (menubar_visible ())
771 { 720 {
799 { 748 {
800 MIN_IT (TermWin.height, max_height); 749 MIN_IT (TermWin.height, max_height);
801 szHint.height = szHint.base_height + TermWin.height; 750 szHint.height = szHint.base_height + TermWin.height;
802 } 751 }
803 752
804 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 753 if (scrollbar_visible () && (options & Opt_scrollBar_right))
805 window_sb_x = szHint.width - sb_w; 754 window_sb_x = szHint.width - sb_w;
806 755
807 if (recalc_x) 756 if (recalc_x)
808 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 757 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
809 - szHint.width - 2 * TermWin.ext_bwidth); 758 - szHint.width - 2 * TermWin.ext_bwidth);
825 * Called after a window size change. 774 * Called after a window size change.
826 */ 775 */
827void 776void
828rxvt_term::tt_winch () 777rxvt_term::tt_winch ()
829{ 778{
779 if (pty.pty < 0)
780 return;
781
830 struct winsize ws; 782 struct winsize ws;
831
832 if (cmd_fd < 0)
833 return;
834 783
835 ws.ws_col = TermWin.ncol; 784 ws.ws_col = TermWin.ncol;
836 ws.ws_row = TermWin.nrow; 785 ws.ws_row = TermWin.nrow;
837 ws.ws_xpixel = ws.ws_ypixel = 0; 786 ws.ws_xpixel = TermWin.width;
838#ifndef DEBUG_SIZE 787 ws.ws_ypixel = TermWin.height;
839 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 788 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
840#else 789
841 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 790#if 0
842 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 791 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
843# ifdef SIGWINCH
844 else if (cmd_pid) /* force through to the command */ 792 if (cmd_pid) /* force through to the command */
845 kill (cmd_pid, SIGWINCH); 793 kill (cmd_pid, SIGWINCH);
846# endif
847#endif 794#endif
848} 795}
849 796
850/*----------------------------------------------------------------------*/ 797/*----------------------------------------------------------------------*/
851/* rxvt_change_font () - Switch to a new font */ 798/* rxvt_change_font () - Switch to a new font */
883 resize_all_windows (0, 0, 0); 830 resize_all_windows (0, 0, 0);
884 scr_remap_chars (); 831 scr_remap_chars ();
885 scr_touch (true); 832 scr_touch (true);
886 } 833 }
887 834
835 for (unicode_t ch = 0x20; ch <= 0x7f; ch++)
836 TermWin.ascii_map [ch - 0x20] = fs->find_font (ch);
837
888 return true; 838 return true;
889 } 839 }
890 } 840 }
891 841
892 return false; 842 return false;
908 char *name; 858 char *name;
909 859
910 if (!XFetchName (display->display, TermWin.parent[0], &name)) 860 if (!XFetchName (display->display, TermWin.parent[0], &name))
911 name = NULL; 861 name = NULL;
912 862
913 if (name == NULL || STRCMP (name, str)) 863 if (name == NULL || strcmp (name, str))
914#endif 864#endif
915 XStoreName (display->display, TermWin.parent[0], str); 865 XStoreName (display->display, TermWin.parent[0], str);
916 866
917#ifdef SMART_WINDOW_TITLE 867#ifdef SMART_WINDOW_TITLE
918 if (name) 868 if (name)
927 char *name; 877 char *name;
928 878
929 if (!XGetIconName (display->display, TermWin.parent[0], &name)) 879 if (!XGetIconName (display->display, TermWin.parent[0], &name))
930 name = NULL; 880 name = NULL;
931 881
932 if (name == NULL || STRCMP (name, str)) 882 if (name == NULL || strcmp (name, str))
933#endif 883#endif
934 XSetIconName (display->display, TermWin.parent[0], str); 884 XSetIconName (display->display, TermWin.parent[0], str);
935 885
936#ifdef SMART_WINDOW_TITLE 886#ifdef SMART_WINDOW_TITLE
937 if (name) 887 if (name)
955 i = atoi (color); 905 i = atoi (color);
956 if (i >= 8 && i <= 15) 906 if (i >= 8 && i <= 15)
957 { /* bright colors */ 907 { /* bright colors */
958 i -= 8; 908 i -= 8;
959# ifndef NO_BRIGHTCOLOR 909# ifndef NO_BRIGHTCOLOR
960 PixColors[idx] = PixColors[minBrightCOLOR + i]; 910 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
961 SET_PIXCOLOR (idx); 911 SET_PIXCOLOR (idx);
962 goto Done; 912 goto Done;
963# endif 913# endif
964 914
965 } 915 }
966 if (i >= 0 && i <= 7) 916 if (i >= 0 && i <= 7)
967 { /* normal colors */ 917 { /* normal colors */
968 PixColors[idx] = PixColors[minCOLOR + i]; 918 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
969 SET_PIXCOLOR (idx); 919 SET_PIXCOLOR (idx);
970 goto Done; 920 goto Done;
971 } 921 }
972 } 922 }
973 923
974 if (!rXParseAllocColor (& xcol, color)) 924 if (!rXParseAllocColor (& xcol, color))
975 return; 925 return;
976 926
977 /* XStoreColor (display->display, XCMAP, XColor*); */ 927 /* XStoreColor (display->display, display->cmap, XColor*); */
978 928
979 /* 929 /*
980 * FIXME: should free colors here, but no idea how to do it so instead, 930 * FIXME: should free colors here, but no idea how to do it so instead,
981 * so just keep gobbling up the colormap 931 * so just keep gobbling up the colormap
982 */ 932 */
983# if 0 933# if 0
984 for (i = Color_Black; i <= Color_White; i++) 934 for (i = Color_Black; i <= Color_White; i++)
985 if (PixColors[idx] == PixColors[i]) 935 if (pix_colors[idx] == pix_colors[i])
986 break; 936 break;
987 if (i > Color_White) 937 if (i > Color_White)
988 { 938 {
989 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 939 /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
990 XFreeColors (display->display, XCMAP, (PixColors + idx), 1, 940 XFreeColors (display->display, display->cmap, (pix_colors + idx), 1,
991 DisplayPlanes (display->display, display->screen)); 941 DisplayPlanes (display->display, display->screen));
992 } 942 }
993# endif 943# endif
994 944
995 PixColors[idx] = xcol; 945 pix_colors_focused[idx] = xcol;
996 SET_PIXCOLOR (idx); 946 SET_PIXCOLOR (idx);
997 947
998 /* XSetWindowAttributes attr; */ 948 /* XSetWindowAttributes attr; */
999 /* Cursor cursor; */ 949 /* Cursor cursor; */
1000Done: 950Done:
951#ifdef OFF_FOCUS_FADING
952 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
953#endif
1001 if (idx == Color_bg && ! (Options & Opt_transparent)) 954 if (idx == Color_bg && ! (options & Opt_transparent))
1002 XSetWindowBackground (display->display, TermWin.vt, 955 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
1003 PixColors[Color_bg]);
1004 956
1005 /* handle Color_BD, scrollbar background, etc. */ 957 /* handle Color_BD, scrollbar background, etc. */
1006 958
1007 set_colorfgbg (); 959 set_colorfgbg ();
1008 recolour_cursor (); 960 recolour_cursor ();
1016void 968void
1017rxvt_term::recolour_cursor () 969rxvt_term::recolour_cursor ()
1018{ 970{
1019 XColor xcol[2]; 971 XColor xcol[2];
1020 972
1021 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg]; 973 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg];
1022 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg]; 974 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg];
1023 XQueryColors (display->display, XCMAP, xcol, 2); 975 XQueryColors (display->display, display->cmap, xcol, 2);
1024 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); 976 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
1025} 977}
1026 978
1027/*----------------------------------------------------------------------*/ 979/*----------------------------------------------------------------------*/
1028/* 980/*
1035 const char *xpmb = "\0"; 987 const char *xpmb = "\0";
1036 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 988 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
1037 989
1038 env_colorfgbg = 990 env_colorfgbg =
1039 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 991 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
1040 STRCPY (fstr, "default"); 992 strcpy (fstr, "default");
1041 STRCPY (bstr, "default"); 993 strcpy (bstr, "default");
1042 for (i = Color_Black; i <= Color_White; i++) 994 for (i = Color_Black; i <= Color_White; i++)
1043 if (PixColors[Color_fg] == PixColors[i]) 995 if (pix_colors[Color_fg] == pix_colors[i])
1044 { 996 {
1045 sprintf (fstr, "%d", (i - Color_Black)); 997 sprintf (fstr, "%d", (i - Color_Black));
1046 break; 998 break;
1047 } 999 }
1048 for (i = Color_Black; i <= Color_White; i++) 1000 for (i = Color_Black; i <= Color_White; i++)
1049 if (PixColors[Color_bg] == PixColors[i]) 1001 if (pix_colors[Color_bg] == pix_colors[i])
1050 { 1002 {
1051 sprintf (bstr, "%d", (i - Color_Black)); 1003 sprintf (bstr, "%d", (i - Color_Black));
1052#ifdef XPM_BACKGROUND 1004#ifdef XPM_BACKGROUND
1053 xpmb = "default;"; 1005 xpmb = "default;";
1054#endif 1006#endif
1059 1011
1060#ifndef NO_BRIGHTCOLOR 1012#ifndef NO_BRIGHTCOLOR
1061 colorfgbg = DEFAULT_RSTYLE; 1013 colorfgbg = DEFAULT_RSTYLE;
1062 for (i = minCOLOR; i <= maxCOLOR; i++) 1014 for (i = minCOLOR; i <= maxCOLOR; i++)
1063 { 1015 {
1064 if (PixColors[Color_fg] == PixColors[i]) 1016 if (pix_colors[Color_fg] == pix_colors[i])
1065 colorfgbg = SET_FGCOLOR (colorfgbg, i); 1017 colorfgbg = SET_FGCOLOR (colorfgbg, i);
1066 if (PixColors[Color_bg] == PixColors[i]) 1018 if (pix_colors[Color_bg] == pix_colors[i])
1067 colorfgbg = SET_BGCOLOR (colorfgbg, i); 1019 colorfgbg = SET_BGCOLOR (colorfgbg, i);
1068 } 1020 }
1069#endif 1021#endif
1070} 1022}
1071 1023
1222 if (width == 0) 1174 if (width == 0)
1223 width = wattr.width - szHint.base_width; 1175 width = wattr.width - szHint.base_width;
1224 if (height == 0) 1176 if (height == 0)
1225 height = wattr.height - szHint.base_height; 1177 height = wattr.height - szHint.base_height;
1226 } 1178 }
1179
1227 if (width != TermWin.width || height != TermWin.height) 1180 if (width != TermWin.width || height != TermWin.height)
1228 { 1181 {
1229 width += szHint.base_width; 1182 width += szHint.base_width;
1230 height += szHint.base_height; 1183 height += szHint.base_height;
1231 resize_all_windows (width, height, 0); 1184 resize_all_windows (width, height, 0);
1236 * - X INPUT METHOD ROUTINES - * 1189 * - X INPUT METHOD ROUTINES - *
1237 * -------------------------------------------------------------------- */ 1190 * -------------------------------------------------------------------- */
1238#ifdef USE_XIM 1191#ifdef USE_XIM
1239 1192
1240void 1193void
1194rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1195{
1196 fg = pix_colors[Color_fg];
1197 bg = pix_colors[Color_bg];
1198}
1199
1200void
1241rxvt_term::im_set_size (XRectangle *size) 1201rxvt_term::im_set_size (XRectangle &size)
1242{ 1202{
1203 // the int_bwidth terms make no sense to me
1243 size->x = TermWin.int_bwidth; 1204 size.x = TermWin.int_bwidth;
1244 size->y = TermWin.int_bwidth; 1205 size.y = TermWin.int_bwidth;
1245 size->width = Width2Pixel (TermWin.ncol); 1206 size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth;
1246 size->height = Height2Pixel (TermWin.nrow); 1207 size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth;
1247} 1208}
1248 1209
1249void 1210void
1250rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) 1211rxvt_term::im_set_preedit_area (XRectangle &preedit_rect,
1212 XRectangle &status_rect,
1213 const XRectangle &needed_rect)
1251{ 1214{
1252 *fg = PixColors[Color_fg]; 1215 preedit_rect.x = needed_rect.width;
1253 *bg = PixColors[Color_bg]; 1216 preedit_rect.y = 0;
1217 preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1;
1218 preedit_rect.height = TermWin.fheight;
1219
1220 status_rect.x = 0;
1221 status_rect.y = 0;
1222 status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1;
1223 status_rect.height = TermWin.fheight;
1254} 1224}
1255 1225
1256/* Checking whether input method is running. */ 1226/* Checking whether input method is running. */
1257bool 1227bool
1258rxvt_term::IMisRunning () 1228rxvt_term::IMisRunning ()
1259{ 1229{
1260 char *p; 1230 char *p;
1261 Atom atom; 1231 Atom atom;
1262 Window win; 1232 Window win;
1263 char server[IMBUFSIZ]; 1233 char server[IMBUFSIZ];
1264 1234
1265 /* get current locale modifier */ 1235 /* get current locale modifier */
1266 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1236 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1267 { 1237 {
1268 STRCPY (server, "@server="); 1238 strcpy (server, "@server=");
1269 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1239 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1240
1270 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ 1241 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */
1271 *p = '\0'; 1242 *p = '\0';
1272 1243
1273 atom = XInternAtom (display->display, server, False); 1244 atom = XInternAtom (display->display, server, False);
1274 win = XGetSelectionOwner (display->display, atom); 1245 win = XGetSelectionOwner (display->display, atom);
1246
1275 if (win != None) 1247 if (win != None)
1276 return True; 1248 return True;
1277 } 1249 }
1250
1278 return False; 1251 return False;
1279} 1252}
1280 1253
1281void 1254void
1282rxvt_term::IMSendSpot () 1255rxvt_term::IMSendSpot ()
1283{ 1256{
1284 XPoint spot; 1257 XPoint spot;
1285 XVaNestedList preedit_attr; 1258 XVaNestedList preedit_attr;
1286 1259
1287 if (Input_Context == NULL 1260 if (!Input_Context
1261 || !TermWin.focus
1288 || !TermWin.focus || ! (input_style & XIMPreeditPosition) 1262 || !(input_style & XIMPreeditPosition)
1263#if 0
1289 || ! (event_type == KeyPress 1264 || !(event_type == KeyPress
1290 || event_type == Expose 1265 || event_type == Expose
1291 || event_type == NoExpose 1266 || event_type == NoExpose
1292 || event_type == SelectionNotify 1267 || event_type == SelectionNotify
1293 || event_type == ButtonRelease || event_type == FocusIn) 1268 || event_type == ButtonRelease || event_type == FocusIn)
1269#endif
1294 || !IMisRunning ()) 1270 || !IMisRunning ())
1295 return; 1271 return;
1296 1272
1297 im_set_position (&spot); 1273 im_set_position (spot);
1298 1274
1299 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1275 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1300 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1276 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1301 XFree (preedit_attr); 1277 XFree (preedit_attr);
1302} 1278}
1303 1279
1304void 1280void
1305rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1306 XRectangle * needed_rect)
1307{
1308 int mbh, vtx = 0;
1309
1310 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1311 vtx = scrollbar_TotalWidth ();
1312
1313 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1314 mbh -= TermWin.lineSpace;
1315
1316 preedit_rect->x = needed_rect->width + vtx;
1317 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1318
1319 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1320 preedit_rect->height = Height2Pixel (1);
1321
1322 status_rect->x = vtx;
1323 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1324
1325 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1326 status_rect->height = Height2Pixel (1);
1327}
1328
1329void
1330rxvt_term::im_destroy () 1281rxvt_term::im_destroy ()
1331{ 1282{
1332 if (Input_Context) 1283 if (Input_Context)
1333 { 1284 {
1334 XDestroyIC (Input_Context); 1285 XDestroyIC (Input_Context);
1335 Input_Context = NULL; 1286 Input_Context = 0;
1336 } 1287 }
1337 1288
1338 if (input_method) 1289 if (input_method)
1339 { 1290 {
1340 display->put_xim (input_method); 1291 display->put_xim (input_method);
1347 * open a suitable preedit type 1298 * open a suitable preedit type
1348 */ 1299 */
1349bool 1300bool
1350rxvt_term::IM_get_IC (const char *modifiers) 1301rxvt_term::IM_get_IC (const char *modifiers)
1351{ 1302{
1352 int i, j, found; 1303 int i, j, found;
1353 XIM xim; 1304 XIM xim;
1354 XPoint spot; 1305 XPoint spot;
1355 XRectangle rect, status_rect, needed_rect; 1306 XRectangle rect, status_rect, needed_rect;
1356 unsigned long fg, bg; 1307 unsigned long fg, bg;
1357 const char *p; 1308 const char *p;
1358 char **s; 1309 char **s;
1359 XIMStyles *xim_styles; 1310 XIMStyles *xim_styles;
1360 XVaNestedList preedit_attr, status_attr;
1361 1311
1362 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1312 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1363 return false; 1313 return false;
1364 1314
1365 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1315 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1371 1321
1372 xim_styles = NULL; 1322 xim_styles = NULL;
1373 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1323 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1374 || !xim_styles || !xim_styles->count_styles) 1324 || !xim_styles || !xim_styles->count_styles)
1375 { 1325 {
1376 display->put_xim (input_method); 1326 im_destroy ();
1377 return false; 1327 return false;
1378 } 1328 }
1379 1329
1380 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1330 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1381 s = rxvt_splitcommastring (p); 1331 s = rxvt_splitcommastring (p);
1332
1382 for (i = found = 0; !found && s[i]; i++) 1333 for (i = found = 0; !found && s[i]; i++)
1383 { 1334 {
1384 if (!STRCMP (s[i], "OverTheSpot")) 1335 if (!strcmp (s[i], "OverTheSpot"))
1385 input_style = (XIMPreeditPosition | XIMStatusNothing); 1336 input_style = (XIMPreeditPosition | XIMStatusNothing);
1386 else if (!STRCMP (s[i], "OffTheSpot")) 1337 else if (!strcmp (s[i], "OffTheSpot"))
1387 input_style = (XIMPreeditArea | XIMStatusArea); 1338 input_style = (XIMPreeditArea | XIMStatusArea);
1388 else if (!STRCMP (s[i], "Root")) 1339 else if (!strcmp (s[i], "Root"))
1389 input_style = (XIMPreeditNothing | XIMStatusNothing); 1340 input_style = (XIMPreeditNothing | XIMStatusNothing);
1390 1341
1391 for (j = 0; j < xim_styles->count_styles; j++) 1342 for (j = 0; j < xim_styles->count_styles; j++)
1392 if (input_style == xim_styles->supported_styles[j]) 1343 if (input_style == xim_styles->supported_styles[j])
1393 { 1344 {
1402 free (s); 1353 free (s);
1403 XFree (xim_styles); 1354 XFree (xim_styles);
1404 1355
1405 if (!found) 1356 if (!found)
1406 { 1357 {
1407 display->put_xim (input_method); 1358 im_destroy ();
1408 return false; 1359 return false;
1409 } 1360 }
1410 1361
1411 preedit_attr = status_attr = NULL; 1362 XFontSet fs = 0;
1363 XVaNestedList preedit_attr = 0, status_attr = 0;
1364
1365 if (input_style & (XIMPreeditPosition | XIMPreeditArea))
1366 {
1367 // fake us a font-set, please
1368 char **missing_charset_list;
1369 int missing_charset_count;
1370 char *def_string;
1371 char pat[512];
1372
1373 sprintf (pat,
1374 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1375 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1376 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1377 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1378 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1379 "*",
1380 TermWin.fheight,
1381 TermWin.fheight + 1, TermWin.fheight - 1,
1382 TermWin.fheight - 2, TermWin.fheight + 2);
1383
1384 fs = XCreateFontSet (display->display, pat,
1385 &missing_charset_list, &missing_charset_count, &def_string);
1386
1387 if (missing_charset_list)
1388 XFreeStringList (missing_charset_list);
1389
1390 if (!fs)
1391 {
1392 input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
1393 rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
1394 }
1395 }
1412 1396
1413 if (input_style & XIMPreeditPosition) 1397 if (input_style & XIMPreeditPosition)
1414 { 1398 {
1415 im_set_size (&rect); 1399 im_set_size (rect);
1416 im_set_position (&spot); 1400 im_set_position (spot);
1417 im_set_color (&fg, &bg); 1401 im_set_color (fg, bg);
1418 1402
1419 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1403 preedit_attr = XVaCreateNestedList (0,
1404 XNForeground, fg,
1405 XNBackground, bg,
1406 XNArea, &rect,
1420 XNSpotLocation, &spot, 1407 XNSpotLocation, &spot,
1421 XNForeground, fg, XNBackground, bg,
1422 //XNFontSet, TermWin.fontset, 1408 XNFontSet, fs,
1423 NULL); 1409 NULL);
1424 } 1410 }
1425 else if (input_style & XIMPreeditArea) 1411 else if (input_style & XIMPreeditArea)
1426 { 1412 {
1427 im_set_color (&fg, &bg); 1413 im_set_color (fg, bg);
1428 1414
1429 /* 1415 /*
1430 * The necessary width of preedit area is unknown 1416 * The necessary width of preedit area is unknown
1431 * until create input context. 1417 * until create input context.
1432 */ 1418 */
1433 needed_rect.width = 0; 1419 needed_rect.width = 0;
1434
1435 im_set_preedit_area (&rect, &status_rect, &needed_rect); 1420 im_set_preedit_area (rect, status_rect, needed_rect);
1436 1421
1437 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1422 preedit_attr = XVaCreateNestedList (0,
1423 XNForeground, fg,
1438 XNForeground, fg, XNBackground, bg, 1424 XNBackground, bg,
1425 XNArea, &rect,
1426 XNFontSet, fs,
1427 NULL);
1428 status_attr = XVaCreateNestedList (0,
1429 XNForeground, fg,
1430 XNBackground, bg,
1431 XNArea, &status_rect,
1439 //XNFontSet, TermWin.fontset, 1432 XNFontSet, fs,
1440 NULL); 1433 NULL);
1441 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1442 XNForeground, fg, XNBackground, bg,
1443 //XNFontSet, TermWin.fontset,
1444 NULL);
1445 } 1434 }
1446 1435
1447 Input_Context = XCreateIC (xim, XNInputStyle, input_style, 1436 Input_Context = XCreateIC (xim,
1437 XNInputStyle, input_style,
1448 XNClientWindow, TermWin.parent[0], 1438 XNClientWindow, TermWin.vt,
1449 XNFocusWindow, TermWin.parent[0], 1439 XNFocusWindow, TermWin.parent[0],
1450 preedit_attr ? XNPreeditAttributes : NULL, 1440 preedit_attr ? XNPreeditAttributes : NULL,
1451 preedit_attr, 1441 preedit_attr,
1452 status_attr ? XNStatusAttributes : NULL, 1442 status_attr ? XNStatusAttributes : NULL,
1453 status_attr, NULL); 1443 status_attr, NULL);
1444
1454 if (preedit_attr) XFree (preedit_attr); 1445 if (preedit_attr) XFree (preedit_attr);
1455 if (status_attr) XFree (status_attr); 1446 if (status_attr) XFree (status_attr);
1447 if (fs) XFreeFontSet (display->display, fs);
1456 1448
1457 if (Input_Context == NULL) 1449 if (Input_Context == NULL)
1458 { 1450 {
1459 rxvt_warn ("failed to create input context, continuing without XIM.\n"); 1451 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1460 display->put_xim (input_method); 1452 im_destroy ();
1461 return false; 1453 return false;
1462 } 1454 }
1463 1455
1464 if (input_style & XIMPreeditArea) 1456 if (input_style & XIMPreeditArea)
1465 IMSetStatusPosition (); 1457 IMSetStatusPosition ();
1495 s = rxvt_splitcommastring (p); 1487 s = rxvt_splitcommastring (p);
1496 for (i = 0; s[i]; i++) 1488 for (i = 0; s[i]; i++)
1497 { 1489 {
1498 if (*s[i]) 1490 if (*s[i])
1499 { 1491 {
1500 STRCPY (buf, "@im="); 1492 strcpy (buf, "@im=");
1501 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1493 strncat (buf, s[i], IMBUFSIZ - 5);
1502 if (IM_get_IC (buf)) 1494 if (IM_get_IC (buf))
1503 { 1495 {
1504 found = true; 1496 found = true;
1505 break; 1497 break;
1506 } 1498 }
1530} 1522}
1531 1523
1532void 1524void
1533rxvt_term::IMSetStatusPosition () 1525rxvt_term::IMSetStatusPosition ()
1534{ 1526{
1535 XRectangle preedit_rect, status_rect, *needed_rect; 1527 XRectangle preedit_rect, status_rect, *needed_rect;
1536 XVaNestedList preedit_attr, status_attr; 1528 XVaNestedList preedit_attr, status_attr;
1537 1529
1538 if (Input_Context == NULL 1530 if (!Input_Context
1531 || !TermWin.focus
1539 || !TermWin.focus || ! (input_style & XIMPreeditArea) 1532 || !(input_style & XIMPreeditArea)
1540 || !IMisRunning ()) 1533 || !IMisRunning ())
1541 return; 1534 return;
1542 1535
1543 /* Getting the necessary width of preedit area */ 1536 /* Getting the necessary width of preedit area */
1544 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); 1537 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1545 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); 1538 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1546 XFree (status_attr); 1539 XFree (status_attr);
1547 1540
1548 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); 1541 im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
1542 XFree (needed_rect);
1549 1543
1550 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); 1544 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1551 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); 1545 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1552 1546
1553 XSetICValues (Input_Context, 1547 XSetICValues (Input_Context,
1554 XNPreeditAttributes, preedit_attr, 1548 XNPreeditAttributes, preedit_attr,
1555 XNStatusAttributes, status_attr, NULL); 1549 XNStatusAttributes, status_attr, NULL);
1556 1550
1557 XFree (preedit_attr); 1551 XFree (preedit_attr);
1558 XFree (status_attr); 1552 XFree (status_attr);
1559} 1553}
1560#endif /* USE_XIM */ 1554#endif /* USE_XIM */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines