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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines