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.80 by root, Fri Aug 13 19:31:23 2004 UTC vs.
Revision 1.114 by root, Tue Sep 7 06:19:45 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
123 return len; 123 return len;
124 124
125} 125}
126#endif 126#endif
127 127
128void *
129rxvt_term::operator new (size_t s)
130{
131 void *p = malloc (s);
132
133 MEMSET (p, 0, s);
134 return p;
135}
136
137void
138rxvt_term::operator delete (void *p, size_t s)
139{
140 free (p);
141}
142
143rxvt_term::rxvt_term () 128rxvt_term::rxvt_term ()
144 : 129 :
145#if TRANSPARENT 130#if TRANSPARENT
146 rootwin_ev (this, &rxvt_term::rootwin_cb), 131 rootwin_ev (this, &rxvt_term::rootwin_cb),
147#endif 132#endif
170 pointer_ev (this, &rxvt_term::pointer_cb), 155 pointer_ev (this, &rxvt_term::pointer_cb),
171#endif 156#endif
172#ifdef USE_XIM 157#ifdef USE_XIM
173 im_ev (this, &rxvt_term::im_cb), 158 im_ev (this, &rxvt_term::im_cb),
174#endif 159#endif
160 sw_term (this, &rxvt_term::sig_term),
161 sw_chld (this, &rxvt_term::sig_chld),
175 termwin_ev (this, &rxvt_term::x_cb), 162 termwin_ev (this, &rxvt_term::x_cb),
176 vt_ev (this, &rxvt_term::x_cb), 163 vt_ev (this, &rxvt_term::x_cb),
177 check_ev (this, &rxvt_term::check_cb), 164 check_ev (this, &rxvt_term::check_cb),
178 flush_ev (this, &rxvt_term::flush_cb), 165 flush_ev (this, &rxvt_term::flush_cb),
179 destroy_ev (this, &rxvt_term::destroy_cb), 166 destroy_ev (this, &rxvt_term::destroy_cb),
187 174
188rxvt_term::~rxvt_term () 175rxvt_term::~rxvt_term ()
189{ 176{
190 termlist.erase (find (termlist.begin (), termlist.end(), this)); 177 termlist.erase (find (termlist.begin (), termlist.end(), this));
191 178
192 if (cmd_fd >= 0) 179 if (cmd_pid)
193 close (cmd_fd); 180 kill (-cmd_pid, SIGHUP);
194 181
195#ifndef NO_SETOWNER_TTYDEV 182 pty.put ();
196 privileged_ttydev (RESTORE); 183
197#endif
198#ifdef UTMP_SUPPORT 184#ifdef UTMP_SUPPORT
199 privileged_utmp (RESTORE); 185 privileged_utmp (RESTORE);
200#endif 186#endif
201 187
188#if ENABLE_STYLES
189 for (int i = RS_styleCount; --i; )
190 if (TermWin.fontset[i] != TermWin.fontset[0])
191 delete TermWin.fontset[i];
192#endif
202 delete TermWin.fontset; 193 delete TermWin.fontset[0];
203 194
204 if (display) 195 if (display)
205 { 196 {
206 selection_clear (); 197 selection_clear ();
207 198
208#ifdef USE_XIM 199#ifdef USE_XIM
209 im_destroy (); 200 im_destroy ();
210#endif 201#endif
211#ifdef MENUBAR 202#ifdef MENUBAR
212 if (menubarGC) XFreeGC (display->display, menubarGC); 203 if (menubarGC) XFreeGC (display->display, menubarGC);
213#endif 204#endif
214#ifdef XTERM_SCROLLBAR 205#ifdef XTERM_SCROLLBAR
215 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); 206 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
216 if (ShadowGC) XFreeGC (display->display, ShadowGC); 207 if (ShadowGC) XFreeGC (display->display, ShadowGC);
217#endif 208#endif
248 XDestroyWindow (display->display, TermWin.parent[0]); 239 XDestroyWindow (display->display, TermWin.parent[0]);
249 } 240 }
250 241
251 // TODO: free pixcolours, colours should become part of rxvt_display 242 // TODO: free pixcolours, colours should become part of rxvt_display
252 243
253 delete PixColorsFocused; 244 delete pix_colors_focused;
254#ifdef OFF_FOCUS_FADING 245#ifdef OFF_FOCUS_FADING
255 delete PixColorsUnFocused; 246 delete pix_colors_unfocused;
256#endif 247#endif
257 248
258 displays.put (display); 249 displays.put (display);
259 250
260 scr_release (); 251 scr_release ();
282rxvt_term::destroy () 273rxvt_term::destroy ()
283{ 274{
284 if (destroy_ev.active) 275 if (destroy_ev.active)
285 return; 276 return;
286 277
278#if ENABLE_OVERLAY
279 scr_overlay_off ();
280#endif
281
287 if (display) 282 if (display)
288 { 283 {
289#if USE_XIM 284#if USE_XIM
290 im_ev.stop (display); 285 im_ev.stop (display);
291#endif 286#endif
340 SET_R (this); 335 SET_R (this);
341 336
342 if (!init_vars ()) 337 if (!init_vars ())
343 return false; 338 return false;
344 339
340 init_secondary ();
341
342 const char **cmd_argv = init_resources (argc, argv);
343
344 set_locale ("");
345
346#if MENUBAR_MAX
347 menubar_read (rs[Rs_menu]);
348#endif
349#ifdef HAVE_SCROLLBARS
350 if (options & Opt_scrollBar)
351 scrollBar.setIdle (); /* set existence for size calculations */
352#endif
353
354 create_windows (argc, argv);
355
356 init_xlocale ();
357
358 scr_reset (); /* initialize screen */
359
360#if 0
361 XSynchronize (display->display, True);
362#endif
363
364#ifdef HAVE_SCROLLBARS
365 if (options & Opt_scrollBar)
366 resize_scrollbar (); /* create and map scrollbar */
367#endif
368#if (MENUBAR_MAX)
369 if (menubar_visible ())
370 XMapWindow (display->display, menuBar.win);
371#endif
372#ifdef TRANSPARENT
373 if (options & Opt_transparent)
374 {
375 XSelectInput (display->display, display->root, PropertyChangeMask);
376 check_our_parents ();
377 rootwin_ev.start (display, display->root);
378 }
379#endif
380
381 XMapWindow (display->display, TermWin.vt);
382 XMapWindow (display->display, TermWin.parent[0]);
383
384 set_colorfgbg ();
385
386 init_command (cmd_argv);
387
388 pty_ev.start (pty.pty, EVENT_READ);
389
390 check_ev.start ();
391
392 return true;
393}
394
395static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
396
397void
398rxvt_init ()
399{
345 /* 400 /*
346 * Save and then give up any super-user privileges 401 * Save and then give up any super-user privileges
347 * If we need privileges in any area then we must specifically request it. 402 * If we need privileges in any area then we must specifically request it.
348 * We should only need to be root in these cases: 403 * We should only need to be root in these cases:
349 * 1. write utmp entries on some systems 404 * 1. write utmp entries on some systems
350 * 2. chown tty on some systems 405 * 2. chown tty on some systems
351 */ 406 */
352 privileges (SAVE); 407 rxvt_privileges (SAVE);
353 privileges (IGNORE); 408 rxvt_privileges (IGNORE);
354 409
355 init_secondary (); 410 signal (SIGHUP, SIG_IGN);
356 411 signal (SIGPIPE, SIG_IGN);
357 const char **cmd_argv = init_resources (argc, argv);
358
359 set_locale ("");
360
361#if MENUBAR_MAX
362 menubar_read (rs[Rs_menu]);
363#endif
364#ifdef HAVE_SCROLLBARS
365 if (Options & Opt_scrollBar)
366 scrollBar.setIdle (); /* set existence for size calculations */
367#endif
368
369 create_windows (argc, argv);
370
371 init_xlocale ();
372
373 scr_reset (); /* initialize screen */
374
375#if 0
376 XSynchronize (display->display, True);
377#endif
378
379#ifdef HAVE_SCROLLBARS
380 if (Options & Opt_scrollBar)
381 resize_scrollbar (); /* create and map scrollbar */
382#endif
383#if (MENUBAR_MAX)
384 if (menubar_visible ())
385 XMapWindow (display->display, menuBar.win);
386#endif
387#ifdef TRANSPARENT
388 if (Options & Opt_transparent)
389 {
390 XSelectInput (display->display, display->root, PropertyChangeMask);
391 check_our_parents ();
392 rootwin_ev.start (display, display->root);
393 }
394#endif
395
396 XMapWindow (display->display, TermWin.vt);
397 XMapWindow (display->display, TermWin.parent[0]);
398
399 init_command (cmd_argv);
400
401 pty_ev.start (cmd_fd, EVENT_READ);
402
403 check_ev.start ();
404
405 return true;
406}
407
408static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
409
410void
411rxvt_init_signals ()
412{
413 /* install exit handler for cleanup */
414#if 0
415#ifdef HAVE_ATEXIT
416 atexit (rxvt_clean_exit);
417#else
418#endif
419#endif
420
421 struct sigaction sa;
422
423 sigfillset (&sa.sa_mask);
424 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
425 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
426 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
427 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
428 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
429 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
430 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
431 412
432 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 413 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
433 /* signal (SIGURG, SIG_DFL); */ 414 /* signal (SIGURG, SIG_DFL); */
434 415
435 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 416 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
417 // TODO: handle this with exceptions and tolerate the memory loss
436 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 418 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
437} 419}
438 420
439/* ------------------------------------------------------------------------- * 421/* ------------------------------------------------------------------------- *
440 * SIGNAL HANDLING & EXIT HANDLER * 422 * SIGNAL HANDLING & EXIT HANDLER *
441 * ------------------------------------------------------------------------- */ 423 * ------------------------------------------------------------------------- */
442/* 424/*
443 * Catch a SIGCHLD signal and exit if the direct child has died 425 * Catch a SIGCHLD signal and exit if the direct child has died
444 */ 426 */
445 427
446void rxvt_term::child_exited (int pid) 428void
429rxvt_term::sig_chld (sig_watcher &w)
447{ 430{
448 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 431 // we are being called for every SIGCHLD, not just ours
449 if (pid == (*t)->cmd_pid) 432 int pid;
450 {
451 (*t)->destroy ();
452 break;
453 }
454}
455
456/* ARGSUSED */
457/* EXTPROTO */
458RETSIGTYPE
459rxvt_Child_signal (int sig __attribute__ ((unused)))
460{
461 int pid, save_errno = errno;
462 433
463 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 434 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
464 rxvt_term::child_exited (pid); 435 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
465 436 if (pid == (*t)->cmd_pid)
466 errno = save_errno; 437 {
467} 438 (*t)->destroy ();
468 439 break;
469/* 440 }
470 * Catch a fatal signal and tidy up before quitting
471 */
472/* EXTPROTO */
473RETSIGTYPE
474rxvt_Exit_signal (int sig)
475{
476 signal (sig, SIG_DFL);
477#ifdef DEBUG_CMD
478 rxvt_warn ("caught signal %d, exiting.\n", sig);
479#endif
480 rxvt_clean_exit ();
481 kill (getpid (), sig);
482}
483
484/* INTPROTO */
485int
486rxvt_xerror_handler (Display *display, XErrorEvent *event)
487{
488 if (GET_R->allowedxerror == -1)
489 GET_R->allowedxerror = event->error_code;
490 else
491 {
492 old_xerror_handler (display, event);
493 GET_R->destroy ();
494 }
495
496 return 0;
497} 441}
498 442
499/*----------------------------------------------------------------------*/ 443/*----------------------------------------------------------------------*/
500/* 444/*
501 * Exit gracefully, clearing the utmp entry and restoring tty attributes 445 * Exit gracefully, clearing the utmp entry and restoring tty attributes
502 * TODO: if debugging, this should free up any known resources if we can 446 * TODO: if debugging, this should free up any known resources if we can
503 */ 447 */
504/* EXTPROTO */
505void 448void
506rxvt_clean_exit () 449rxvt_destroy_all ()
507{ 450{
508 // TODO: rxvtd should clean up all ressources 451 // TODO: rxvtd should clean up all ressources
509 if (GET_R) 452 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
453 (*t)->destroy ();
454}
455
456/*
457 * Catch a fatal signal and tidy up before quitting
458 */
459void
460rxvt_term::sig_term (sig_watcher &w)
461{
462#ifdef DEBUG_CMD
463 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
464#endif
465 rxvt_destroy_all ();
466 signal (w.signum, SIG_DFL);
467 kill (getpid (), w.signum);
468}
469
470/* INTPROTO */
471int
472rxvt_xerror_handler (Display *display, XErrorEvent *event)
473{
474 if (GET_R->allowedxerror == -1)
475 GET_R->allowedxerror = event->error_code;
476 else
477 {
478 old_xerror_handler (display, event);
510 GET_R->destroy (); 479 GET_R->destroy ();
480 }
481
482 return 0;
511} 483}
512 484
513/* ------------------------------------------------------------------------- * 485/* ------------------------------------------------------------------------- *
514 * MEMORY ALLOCATION WRAPPERS * 486 * MEMORY ALLOCATION WRAPPERS *
515 * ------------------------------------------------------------------------- */ 487 * ------------------------------------------------------------------------- */
516/* EXTPROTO */ 488void *
517void *
518rxvt_malloc (size_t size) 489rxvt_malloc (size_t size)
519{ 490{
520 void *p;
521
522 p = malloc (size); 491 void *p = malloc (size);
492
523 if (p) 493 if (!p)
494 rxvt_fatal ("memory allocation failure. aborting.\n");
495
524 return p; 496 return p;
525
526 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
527 rxvt_clean_exit ();
528 exit (EXIT_FAILURE);
529 /* NOTREACHED */
530} 497}
531 498
532/* EXTPROTO */ 499/* INTPROTO */
533void * 500void *
534rxvt_calloc (size_t number, size_t size) 501rxvt_calloc (size_t number, size_t size)
535{ 502{
536 void *p;
537
538 p = calloc (number, size); 503 void *p = calloc (number, size);
504
539 if (p) 505 if (!p)
506 rxvt_fatal ("memory allocation failure. aborting.\n");
507
540 return p; 508 return p;
541
542 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
543 rxvt_clean_exit ();
544 exit (EXIT_FAILURE);
545 /* NOTREACHED */
546} 509}
547 510
548/* EXTPROTO */ 511/* INTPROTO */
549void * 512void *
550rxvt_realloc (void *ptr, size_t size) 513rxvt_realloc (void *ptr, size_t size)
551{ 514{
552 void *p;
553
554 if (ptr)
555 p = realloc (ptr, size); 515 void *p = realloc (ptr, size);
556 else 516
557 p = malloc (size);
558 if (p) 517 if (!p)
518 rxvt_fatal ("memory allocation failure. aborting.\n");
519
559 return p; 520 return p;
560
561 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
562 rxvt_clean_exit ();
563 exit (EXIT_FAILURE);
564 /* NOTREACHED */
565} 521}
566 522
567/* ------------------------------------------------------------------------- * 523/* ------------------------------------------------------------------------- *
568 * PRIVILEGED OPERATIONS * 524 * PRIVILEGED OPERATIONS *
569 * ------------------------------------------------------------------------- */ 525 * ------------------------------------------------------------------------- */
570/* take care of suid/sgid super-user (root) privileges */ 526/* take care of suid/sgid super-user (root) privileges */
571void 527void
572rxvt_term::privileges (int mode) 528rxvt_privileges (rxvt_privaction action)
573{ 529{
530#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
531 static uid_t euid;
532 static gid_t egid;
533#endif
534
574#if ! defined(__CYGWIN32__) 535#if ! defined(__CYGWIN32__)
575# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 536# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
576 /* setreuid () is the poor man's setuid (), seteuid () */ 537 /* setreuid () is the poor man's setuid (), seteuid () */
577# define seteuid(a) setreuid(-1, (a)) 538# define seteuid(a) setreuid(-1, (a))
578# define setegid(a) setregid(-1, (a)) 539# define setegid(a) setregid(-1, (a))
579# define HAVE_SETEUID 540# define HAVE_SETEUID
580# endif 541# endif
581# ifdef HAVE_SETEUID 542# ifdef HAVE_SETEUID
582 switch (mode) 543 switch (action)
583 { 544 {
584 case IGNORE: 545 case IGNORE:
585 /* 546 /*
586 * change effective uid/gid - not real uid/gid - so we can switch 547 * change effective uid/gid - not real uid/gid - so we can switch
587 * back to root later, as required 548 * back to root later, as required
597 seteuid (euid); 558 seteuid (euid);
598 setegid (egid); 559 setegid (egid);
599 break; 560 break;
600 } 561 }
601# else 562# else
602 switch (mode) 563 switch (action)
603 { 564 {
604 case IGNORE: 565 case IGNORE:
605 setuid (getuid ()); 566 setuid (getuid ());
606 setgid (getgid ()); 567 setgid (getgid ());
607 /* FALLTHROUGH */ 568 /* FALLTHROUGH */
614#endif 575#endif
615} 576}
616 577
617#ifdef UTMP_SUPPORT 578#ifdef UTMP_SUPPORT
618void 579void
619rxvt_term::privileged_utmp (char action) 580rxvt_term::privileged_utmp (rxvt_privaction action)
620{ 581{
621 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
622 action, next_utmp_action, getpid ()));
623 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
624 || (Options & Opt_utmpInhibit) 582 if ((options & Opt_utmpInhibit)
625 || ttydev == NULL || *ttydev == '\0') 583 || !pty.name || !*pty.name)
626 return; 584 return;
627 585
628 privileges (RESTORE); 586 rxvt_privileges (RESTORE);
587
629 if (action == SAVE) 588 if (action == SAVE)
630 {
631 next_utmp_action = RESTORE;
632 makeutent (ttydev, rs[Rs_display_name]); 589 makeutent (pty.name, rs[Rs_display_name]);
633 }
634 else 590 else
635 { /* action == RESTORE */
636 next_utmp_action = IGNORE;
637 cleanutent (); 591 cleanutent ();
638 } 592
639 privileges (IGNORE); 593 rxvt_privileges (IGNORE);
640}
641#endif
642
643#ifndef NO_SETOWNER_TTYDEV
644void
645rxvt_term::privileged_ttydev (char action)
646{
647 D_MAIN ((stderr,
648 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
649 action, next_tty_action, getpid ()));
650 if (next_tty_action != action || (action != SAVE && action != RESTORE)
651 || ttydev == NULL || *ttydev == '\0')
652 return;
653
654 privileges (RESTORE);
655
656 if (action == SAVE)
657 {
658 next_tty_action = RESTORE;
659# ifndef RESET_TTY_TO_COMMON_DEFAULTS
660 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
661 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
662 next_tty_action = IGNORE;
663 else
664# endif
665
666 {
667 chown (ttydev, getuid (), ttygid); /* fail silently */
668 chmod (ttydev, ttymode);
669# ifdef HAVE_REVOKE
670 revoke (ttydev);
671# endif
672
673 }
674 }
675 else
676 { /* action == RESTORE */
677 next_tty_action = IGNORE;
678# ifndef RESET_TTY_TO_COMMON_DEFAULTS
679 chmod (ttydev, ttyfd_stat.st_mode);
680 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
681# else
682 chmod (ttydev,
683 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
684 chown (ttydev, 0, 0);
685# endif
686
687 }
688
689 privileges (IGNORE);
690
691# ifndef RESET_TTY_TO_COMMON_DEFAULTS
692 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
693 action == RESTORE ? "Restoring" : (action ==
694 SAVE ? "Saving" :
695 "UNKNOWN ERROR for"), ttydev,
696 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
697 ttyfd_stat.st_gid));
698# endif
699} 594}
700#endif 595#endif
701 596
702/*----------------------------------------------------------------------*/ 597/*----------------------------------------------------------------------*/
703/* 598/*
774 669
775 if (scrollbar_visible ()) 670 if (scrollbar_visible ())
776 { 671 {
777 sb_w = scrollbar_TotalWidth (); 672 sb_w = scrollbar_TotalWidth ();
778 szHint.base_width += sb_w; 673 szHint.base_width += sb_w;
779 if (!(Options & Opt_scrollBar_right)) 674 if (!(options & Opt_scrollBar_right))
780 window_vt_x += sb_w; 675 window_vt_x += sb_w;
781 } 676 }
782 677
783 if (menubar_visible ()) 678 if (menubar_visible ())
784 { 679 {
812 { 707 {
813 MIN_IT (TermWin.height, max_height); 708 MIN_IT (TermWin.height, max_height);
814 szHint.height = szHint.base_height + TermWin.height; 709 szHint.height = szHint.base_height + TermWin.height;
815 } 710 }
816 711
817 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 712 if (scrollbar_visible () && (options & Opt_scrollBar_right))
818 window_sb_x = szHint.width - sb_w; 713 window_sb_x = szHint.width - sb_w;
819 714
820 if (recalc_x) 715 if (recalc_x)
821 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 716 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
822 - szHint.width - 2 * TermWin.ext_bwidth); 717 - szHint.width - 2 * TermWin.ext_bwidth);
838 * Called after a window size change. 733 * Called after a window size change.
839 */ 734 */
840void 735void
841rxvt_term::tt_winch () 736rxvt_term::tt_winch ()
842{ 737{
738 if (pty.pty < 0)
739 return;
740
843 struct winsize ws; 741 struct winsize ws;
844
845 if (cmd_fd < 0)
846 return;
847 742
848 ws.ws_col = TermWin.ncol; 743 ws.ws_col = TermWin.ncol;
849 ws.ws_row = TermWin.nrow; 744 ws.ws_row = TermWin.nrow;
850 ws.ws_xpixel = ws.ws_ypixel = 0; 745 ws.ws_xpixel = TermWin.width;
851#ifndef DEBUG_SIZE 746 ws.ws_ypixel = TermWin.height;
852 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 747 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
853#else 748
854 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 749#if 0
855 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 750 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
856# ifdef SIGWINCH
857 else if (cmd_pid) /* force through to the command */ 751 if (cmd_pid) /* force through to the command */
858 kill (cmd_pid, SIGWINCH); 752 kill (cmd_pid, SIGWINCH);
859# endif
860#endif 753#endif
861} 754}
862 755
863/*----------------------------------------------------------------------*/ 756/*----------------------------------------------------------------------*/
864/* rxvt_change_font () - Switch to a new font */ 757/* set_fonts () - load and set the various fonts
865/* 758/*
866 * init = 1 - initialize 759 * init = 1 - initialize
867 * 760 *
868 * fontname == FONT_UP - switch to bigger font 761 * fontname == FONT_UP - switch to bigger font
869 * fontname == FONT_DN - switch to smaller font 762 * fontname == FONT_DN - switch to smaller font
870 */ 763 */
871bool 764bool
872rxvt_term::change_font (const char *fontname) 765rxvt_term::set_fonts ()
873{ 766{
874 if (fontname == FONT_UP)
875 {
876 // TODO
877 }
878 else if (fontname == FONT_DN)
879 {
880 // TODO
881 }
882 else
883 {
884 rxvt_fontset *fs = new rxvt_fontset (this); 767 rxvt_fontset *fs = new rxvt_fontset (this);
768 rxvt_fontprop prop;
885 769
886 if (fs && fs->populate (fontname ? fontname : "fixed")) 770 if (!fs
771 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed")
772 || !fs->realize_font (1))
773 {
774 delete fs;
775 return false;
776 }
777
778#if ENABLE_STYLES
779 for (int i = RS_styleCount; --i; )
780 if (TermWin.fontset[i] != TermWin.fontset[0])
781 delete TermWin.fontset[i];
782#endif
783
784 delete TermWin.fontset[0];
785 TermWin.fontset[0] = fs;
786
787 prop = (*fs)[1]->properties ();
788 fs->set_prop (prop);
789
790 TermWin.fwidth = prop.width;
791 TermWin.fheight = prop.height;
792 TermWin.fweight = prop.weight;
793 TermWin.fslant = prop.slant;
794 TermWin.fbase = (*fs)[1]->ascent;
795
796 for (int style = 1; style < 4; style++)
797 {
798#if ENABLE_STYLES
799 const char *res = rs[Rs_font + style];
800
801 if (res && !*res)
802 TermWin.fontset[style] = TermWin.fontset[0];
803 else
887 { 804 {
888 delete TermWin.fontset; 805 TermWin.fontset[style] = fs = new rxvt_fontset (this);
889 TermWin.fontset = fs; 806 rxvt_fontprop prop2 = prop;
890 TermWin.fwidth = fs->base_font ()->width;
891 TermWin.fheight = fs->base_font ()->height;
892 TermWin.fbase = fs->base_font ()->ascent;
893 807
894 if (TermWin.parent[0]) 808 if (res)
809 prop2.weight = prop2.slant = rxvt_fontprop::unset;
810 else
895 { 811 {
896 resize_all_windows (0, 0, 0); 812 res = TermWin.fontset[0]->fontdesc;
897 scr_remap_chars (); 813
898 scr_touch (true); 814 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
815 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
899 } 816 }
900 817
901 for (unicode_t ch = 0x20; ch <= 0x7f; ch++) 818 fs->populate (res);
902 TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); 819 fs->set_prop (prop2);
903
904 return true;
905 } 820 }
821#else
822 TermWin.fontset[style] = TermWin.fontset[0];
823#endif
824 }
825
826 if (TermWin.parent[0])
906 } 827 {
828 resize_all_windows (0, 0, 0);
829 scr_remap_chars ();
830 scr_touch (true);
831 }
907 832
908 return false; 833 return true;
909}
910
911bool
912rxvt_term::font_up_down (int n, int direction)
913{
914 return false;
915} 834}
916 835
917/*----------------------------------------------------------------------*/ 836/*----------------------------------------------------------------------*/
918/*----------------------------------------------------------------------*/ 837/*----------------------------------------------------------------------*/
919/* xterm sequences - title, iconName, color (exptl) */ 838/* xterm sequences - title, iconName, color (exptl) */
924 char *name; 843 char *name;
925 844
926 if (!XFetchName (display->display, TermWin.parent[0], &name)) 845 if (!XFetchName (display->display, TermWin.parent[0], &name))
927 name = NULL; 846 name = NULL;
928 847
929 if (name == NULL || STRCMP (name, str)) 848 if (name == NULL || strcmp (name, str))
930#endif 849#endif
931 XStoreName (display->display, TermWin.parent[0], str); 850 XStoreName (display->display, TermWin.parent[0], str);
932 851
933#ifdef SMART_WINDOW_TITLE 852#ifdef SMART_WINDOW_TITLE
934 if (name) 853 if (name)
943 char *name; 862 char *name;
944 863
945 if (!XGetIconName (display->display, TermWin.parent[0], &name)) 864 if (!XGetIconName (display->display, TermWin.parent[0], &name))
946 name = NULL; 865 name = NULL;
947 866
948 if (name == NULL || STRCMP (name, str)) 867 if (name == NULL || strcmp (name, str))
949#endif 868#endif
950 XSetIconName (display->display, TermWin.parent[0], str); 869 XSetIconName (display->display, TermWin.parent[0], str);
951 870
952#ifdef SMART_WINDOW_TITLE 871#ifdef SMART_WINDOW_TITLE
953 if (name) 872 if (name)
971 i = atoi (color); 890 i = atoi (color);
972 if (i >= 8 && i <= 15) 891 if (i >= 8 && i <= 15)
973 { /* bright colors */ 892 { /* bright colors */
974 i -= 8; 893 i -= 8;
975# ifndef NO_BRIGHTCOLOR 894# ifndef NO_BRIGHTCOLOR
976 PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; 895 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
977 SET_PIXCOLOR (idx); 896 SET_PIXCOLOR (idx);
978 goto Done; 897 goto Done;
979# endif 898# endif
980 899
981 } 900 }
982 if (i >= 0 && i <= 7) 901 if (i >= 0 && i <= 7)
983 { /* normal colors */ 902 { /* normal colors */
984 PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; 903 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
985 SET_PIXCOLOR (idx); 904 SET_PIXCOLOR (idx);
986 goto Done; 905 goto Done;
987 } 906 }
988 } 907 }
989 908
996 * FIXME: should free colors here, but no idea how to do it so instead, 915 * FIXME: should free colors here, but no idea how to do it so instead,
997 * so just keep gobbling up the colormap 916 * so just keep gobbling up the colormap
998 */ 917 */
999# if 0 918# if 0
1000 for (i = Color_Black; i <= Color_White; i++) 919 for (i = Color_Black; i <= Color_White; i++)
1001 if (PixColors[idx] == PixColors[i]) 920 if (pix_colors[idx] == pix_colors[i])
1002 break; 921 break;
1003 if (i > Color_White) 922 if (i > Color_White)
1004 { 923 {
1005 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 924 /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
1006 XFreeColors (display->display, display->cmap, (PixColors + idx), 1, 925 XFreeColors (display->display, display->cmap, (pix_colors + idx), 1,
1007 DisplayPlanes (display->display, display->screen)); 926 DisplayPlanes (display->display, display->screen));
1008 } 927 }
1009# endif 928# endif
1010 929
1011 PixColorsFocused[idx] = xcol; 930 pix_colors_focused[idx] = xcol;
1012 SET_PIXCOLOR (idx); 931 SET_PIXCOLOR (idx);
1013 932
1014 /* XSetWindowAttributes attr; */ 933 /* XSetWindowAttributes attr; */
1015 /* Cursor cursor; */ 934 /* Cursor cursor; */
1016Done: 935Done:
1017#ifdef OFF_FOCUS_FADING 936#ifdef OFF_FOCUS_FADING
937 if (rs[Rs_fade])
1018 PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); 938 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
1019#endif 939#endif
1020 if (idx == Color_bg && ! (Options & Opt_transparent))
1021 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
1022 940
1023 /* handle Color_BD, scrollbar background, etc. */ 941 /*TODO: handle Color_BD, scrollbar background, etc. */
1024 942
1025 set_colorfgbg ();
1026 recolour_cursor (); 943 recolour_cursor ();
1027 scr_touch (true); 944 scr_recolour ();
1028} 945}
1029 946
1030#else 947#else
1031# define set_window_color (idx,color) ((void)0) 948# define set_window_color (idx,color) ((void)0)
1032#endif /* XTERM_COLOR_CHANGE */ 949#endif /* XTERM_COLOR_CHANGE */
1034void 951void
1035rxvt_term::recolour_cursor () 952rxvt_term::recolour_cursor ()
1036{ 953{
1037 XColor xcol[2]; 954 XColor xcol[2];
1038 955
1039 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; 956 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg)
1040 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; 957 ? pix_colors_focused[Color_pointer_fg]
958 : pix_colors_focused[Color_fg];
959 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
960 ? pix_colors_focused[Color_pointer_bg]
961 : pix_colors_focused[Color_bg];
962
1041 XQueryColors (display->display, display->cmap, xcol, 2); 963 XQueryColors (display->display, display->cmap, xcol, 2);
1042 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); 964 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
1043} 965}
1044 966
1045/*----------------------------------------------------------------------*/ 967/*----------------------------------------------------------------------*/
1047 * find if fg/bg matches any of the normal (low-intensity) colors 969 * find if fg/bg matches any of the normal (low-intensity) colors
1048 */ 970 */
1049void 971void
1050rxvt_term::set_colorfgbg () 972rxvt_term::set_colorfgbg ()
1051{ 973{
1052 unsigned int i; 974 unsigned int i;
1053 const char *xpmb = "\0"; 975 const char *xpmb = "\0";
1054 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 976 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
1055 977
1056 env_colorfgbg =
1057 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 978 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
1058 STRCPY (fstr, "default"); 979 strcpy (fstr, "default");
1059 STRCPY (bstr, "default"); 980 strcpy (bstr, "default");
1060 for (i = Color_Black; i <= Color_White; i++) 981 for (i = Color_Black; i <= Color_White; i++)
1061 if (PixColors[Color_fg] == PixColors[i]) 982 if (pix_colors[Color_fg] == pix_colors[i])
1062 { 983 {
1063 sprintf (fstr, "%d", (i - Color_Black)); 984 sprintf (fstr, "%d", (i - Color_Black));
1064 break; 985 break;
1065 } 986 }
987
1066 for (i = Color_Black; i <= Color_White; i++) 988 for (i = Color_Black; i <= Color_White; i++)
1067 if (PixColors[Color_bg] == PixColors[i]) 989 if (pix_colors[Color_bg] == pix_colors[i])
1068 { 990 {
1069 sprintf (bstr, "%d", (i - Color_Black)); 991 sprintf (bstr, "%d", (i - Color_Black));
1070#ifdef XPM_BACKGROUND 992#ifdef XPM_BACKGROUND
1071 xpmb = "default;"; 993 xpmb = "default;";
1072#endif 994#endif
1073 break; 995 break;
1074 } 996 }
1075 997
1076 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 998 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1077
1078#ifndef NO_BRIGHTCOLOR
1079 colorfgbg = DEFAULT_RSTYLE;
1080 for (i = minCOLOR; i <= maxCOLOR; i++)
1081 {
1082 if (PixColors[Color_fg] == PixColors[i])
1083 colorfgbg = SET_FGCOLOR (colorfgbg, i);
1084 if (PixColors[Color_bg] == PixColors[i])
1085 colorfgbg = SET_BGCOLOR (colorfgbg, i);
1086 }
1087#endif
1088} 999}
1089 1000
1090/*----------------------------------------------------------------------*/ 1001/*----------------------------------------------------------------------*/
1091/* 1002/*
1092 * Colour determination for low colour displays, routine from 1003 * Colour determination for low colour displays, routine from
1255 * - X INPUT METHOD ROUTINES - * 1166 * - X INPUT METHOD ROUTINES - *
1256 * -------------------------------------------------------------------- */ 1167 * -------------------------------------------------------------------- */
1257#ifdef USE_XIM 1168#ifdef USE_XIM
1258 1169
1259void 1170void
1171rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1172{
1173 fg = pix_colors[Color_fg];
1174 bg = pix_colors[Color_bg];
1175}
1176
1177void
1260rxvt_term::im_set_size (XRectangle *size) 1178rxvt_term::im_set_size (XRectangle &size)
1261{ 1179{
1180 // the int_bwidth terms make no sense to me
1262 size->x = TermWin.int_bwidth; 1181 size.x = TermWin.int_bwidth;
1263 size->y = TermWin.int_bwidth; 1182 size.y = TermWin.int_bwidth;
1264 size->width = Width2Pixel (TermWin.ncol); 1183 size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth;
1265 size->height = Height2Pixel (TermWin.nrow); 1184 size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth;
1266} 1185}
1267 1186
1268void 1187void
1269rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) 1188rxvt_term::im_set_preedit_area (XRectangle &preedit_rect,
1189 XRectangle &status_rect,
1190 const XRectangle &needed_rect)
1270{ 1191{
1271 *fg = PixColors[Color_fg]; 1192 preedit_rect.x = needed_rect.width;
1272 *bg = PixColors[Color_bg]; 1193 preedit_rect.y = 0;
1194 preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1;
1195 preedit_rect.height = TermWin.fheight;
1196
1197 status_rect.x = 0;
1198 status_rect.y = 0;
1199 status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1;
1200 status_rect.height = TermWin.fheight;
1273} 1201}
1274 1202
1275/* Checking whether input method is running. */ 1203/* Checking whether input method is running. */
1276bool 1204bool
1277rxvt_term::IMisRunning () 1205rxvt_term::IMisRunning ()
1278{ 1206{
1279 char *p; 1207 char *p;
1280 Atom atom; 1208 Atom atom;
1281 Window win; 1209 Window win;
1282 char server[IMBUFSIZ]; 1210 char server[IMBUFSIZ];
1283 1211
1284 /* get current locale modifier */ 1212 /* get current locale modifier */
1285 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1213 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1286 { 1214 {
1287 STRCPY (server, "@server="); 1215 strcpy (server, "@server=");
1288 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1216 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1217
1289 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ 1218 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */
1290 *p = '\0'; 1219 *p = '\0';
1291 1220
1292 atom = XInternAtom (display->display, server, False); 1221 atom = XInternAtom (display->display, server, False);
1293 win = XGetSelectionOwner (display->display, atom); 1222 win = XGetSelectionOwner (display->display, atom);
1223
1294 if (win != None) 1224 if (win != None)
1295 return True; 1225 return True;
1296 } 1226 }
1227
1297 return False; 1228 return False;
1298} 1229}
1299 1230
1300void 1231void
1301rxvt_term::IMSendSpot () 1232rxvt_term::IMSendSpot ()
1302{ 1233{
1303 XPoint spot; 1234 XPoint nspot;
1304 XVaNestedList preedit_attr; 1235 XVaNestedList preedit_attr;
1305 1236
1306 if (Input_Context == NULL 1237 if (!Input_Context
1238 || !TermWin.focus
1307 || !TermWin.focus || ! (input_style & XIMPreeditPosition) 1239 || !(input_style & XIMPreeditPosition))
1308 || ! (event_type == KeyPress
1309 || event_type == Expose
1310 || event_type == NoExpose
1311 || event_type == SelectionNotify
1312 || event_type == ButtonRelease || event_type == FocusIn)
1313 || !IMisRunning ())
1314 return; 1240 return;
1315 1241
1316 im_set_position (&spot); 1242 im_set_position (nspot);
1243
1244 if (nspot.x == spot.x && nspot.y == spot.y)
1245 return;
1246
1247 spot = nspot;
1317 1248
1318 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1249 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1319 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1250 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1320 XFree (preedit_attr); 1251 XFree (preedit_attr);
1321} 1252}
1322 1253
1323void 1254void
1324rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1325 XRectangle * needed_rect)
1326{
1327 int mbh, vtx = 0;
1328
1329 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1330 vtx = scrollbar_TotalWidth ();
1331
1332 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1333 mbh -= TermWin.lineSpace;
1334
1335 preedit_rect->x = needed_rect->width + vtx;
1336 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1337
1338 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1339 preedit_rect->height = Height2Pixel (1);
1340
1341 status_rect->x = vtx;
1342 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1343
1344 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1345 status_rect->height = Height2Pixel (1);
1346}
1347
1348void
1349rxvt_term::im_destroy () 1255rxvt_term::im_destroy ()
1350{ 1256{
1351 if (Input_Context)
1352 {
1353 XDestroyIC (Input_Context);
1354 Input_Context = NULL;
1355 }
1356
1357 if (input_method) 1257 if (input_method)
1358 { 1258 {
1259 if (Input_Context && input_method->xim)
1260 XDestroyIC (Input_Context);
1261
1359 display->put_xim (input_method); 1262 display->put_xim (input_method);
1360 input_method = 0; 1263 input_method = 0;
1361 } 1264 }
1265
1266 Input_Context = 0;
1362} 1267}
1363 1268
1364/* 1269/*
1365 * Try to open a XIM with the current modifiers, then see if we can 1270 * Try to open a XIM with the current modifiers, then see if we can
1366 * open a suitable preedit type 1271 * open a suitable preedit type
1367 */ 1272 */
1368bool 1273bool
1369rxvt_term::IM_get_IC (const char *modifiers) 1274rxvt_term::IM_get_IC (const char *modifiers)
1370{ 1275{
1371 int i, j, found; 1276 int i, j, found;
1372 XIM xim; 1277 XIM xim;
1373 XPoint spot; 1278 XPoint spot;
1374 XRectangle rect, status_rect, needed_rect; 1279 XRectangle rect, status_rect, needed_rect;
1375 unsigned long fg, bg; 1280 unsigned long fg, bg;
1376 const char *p; 1281 const char *p;
1377 char **s; 1282 char **s;
1378 XIMStyles *xim_styles; 1283 XIMStyles *xim_styles;
1379 XVaNestedList preedit_attr, status_attr;
1380 1284
1381 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1285 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1382 return false; 1286 return false;
1383 1287
1384 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1288 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1385 input_method = display->get_xim (locale, modifiers); 1289 input_method = display->get_xim (locale, modifiers);
1386 if (input_method == NULL) 1290 if (input_method == NULL)
1387 return false; 1291 return false;
1388 1292
1389 xim = input_method->xim; 1293 xim = input_method->xim;
1294 spot.x = spot.y = -1;
1390 1295
1391 xim_styles = NULL; 1296 xim_styles = NULL;
1392 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1297 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1393 || !xim_styles || !xim_styles->count_styles) 1298 || !xim_styles || !xim_styles->count_styles)
1394 { 1299 {
1395 display->put_xim (input_method); 1300 im_destroy ();
1396 return false; 1301 return false;
1397 } 1302 }
1398 1303
1399 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1304 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root,None";
1400 s = rxvt_splitcommastring (p); 1305 s = rxvt_splitcommastring (p);
1306
1401 for (i = found = 0; !found && s[i]; i++) 1307 for (i = found = 0; !found && s[i]; i++)
1402 { 1308 {
1403 if (!STRCMP (s[i], "OverTheSpot")) 1309 if (!strcmp (s[i], "OverTheSpot"))
1404 input_style = (XIMPreeditPosition | XIMStatusNothing); 1310 input_style = (XIMPreeditPosition | XIMStatusNothing);
1405 else if (!STRCMP (s[i], "OffTheSpot")) 1311 else if (!strcmp (s[i], "OffTheSpot"))
1406 input_style = (XIMPreeditArea | XIMStatusArea); 1312 input_style = (XIMPreeditArea | XIMStatusArea);
1407 else if (!STRCMP (s[i], "Root")) 1313 else if (!strcmp (s[i], "Root"))
1408 input_style = (XIMPreeditNothing | XIMStatusNothing); 1314 input_style = (XIMPreeditNothing | XIMStatusNothing);
1315 else if (!strcmp (s[i], "None"))
1316 input_style = (XIMPreeditNone | XIMStatusNone);
1409 1317
1410 for (j = 0; j < xim_styles->count_styles; j++) 1318 for (j = 0; j < xim_styles->count_styles; j++)
1411 if (input_style == xim_styles->supported_styles[j]) 1319 if (input_style == xim_styles->supported_styles[j])
1412 { 1320 {
1413 found = 1; 1321 found = 1;
1421 free (s); 1329 free (s);
1422 XFree (xim_styles); 1330 XFree (xim_styles);
1423 1331
1424 if (!found) 1332 if (!found)
1425 { 1333 {
1426 display->put_xim (input_method); 1334 im_destroy ();
1427 return false; 1335 return false;
1428 } 1336 }
1429 1337
1430 preedit_attr = status_attr = NULL; 1338 XFontSet fs = 0;
1339 XVaNestedList preedit_attr = 0, status_attr = 0;
1340
1341 if (input_style & (XIMPreeditPosition | XIMPreeditArea))
1342 {
1343 // fake us a font-set, please
1344 char **missing_charset_list;
1345 int missing_charset_count;
1346 char *def_string;
1347 char pat[512];
1348
1349 sprintf (pat,
1350 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1351 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1352 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1353 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1354 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1355 "*",
1356 TermWin.fheight,
1357 TermWin.fheight + 1, TermWin.fheight - 1,
1358 TermWin.fheight - 2, TermWin.fheight + 2);
1359
1360 fs = XCreateFontSet (display->display, pat,
1361 &missing_charset_list, &missing_charset_count, &def_string);
1362
1363 if (missing_charset_list)
1364 XFreeStringList (missing_charset_list);
1365
1366 if (!fs)
1367 {
1368 input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
1369 rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
1370 }
1371 }
1431 1372
1432 if (input_style & XIMPreeditPosition) 1373 if (input_style & XIMPreeditPosition)
1433 { 1374 {
1434 im_set_size (&rect); 1375 im_set_size (rect);
1435 im_set_position (&spot); 1376 im_set_position (spot);
1436 im_set_color (&fg, &bg); 1377 im_set_color (fg, bg);
1437 1378
1438 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1379 preedit_attr = XVaCreateNestedList (0,
1380 XNForeground, fg,
1381 XNBackground, bg,
1382 XNArea, &rect,
1439 XNSpotLocation, &spot, 1383 XNSpotLocation, &spot,
1440 XNForeground, fg, XNBackground, bg,
1441 //XNFontSet, TermWin.fontset, 1384 XNFontSet, fs,
1442 NULL); 1385 NULL);
1443 } 1386 }
1444 else if (input_style & XIMPreeditArea) 1387 else if (input_style & XIMPreeditArea)
1445 { 1388 {
1446 im_set_color (&fg, &bg); 1389 im_set_color (fg, bg);
1447 1390
1448 /* 1391 /*
1449 * The necessary width of preedit area is unknown 1392 * The necessary width of preedit area is unknown
1450 * until create input context. 1393 * until create input context.
1451 */ 1394 */
1452 needed_rect.width = 0; 1395 needed_rect.width = 0;
1453
1454 im_set_preedit_area (&rect, &status_rect, &needed_rect); 1396 im_set_preedit_area (rect, status_rect, needed_rect);
1455 1397
1456 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1398 preedit_attr = XVaCreateNestedList (0,
1399 XNForeground, fg,
1457 XNForeground, fg, XNBackground, bg, 1400 XNBackground, bg,
1401 XNArea, &rect,
1402 XNFontSet, fs,
1403 NULL);
1404 status_attr = XVaCreateNestedList (0,
1405 XNForeground, fg,
1406 XNBackground, bg,
1407 XNArea, &status_rect,
1458 //XNFontSet, TermWin.fontset, 1408 XNFontSet, fs,
1459 NULL); 1409 NULL);
1460 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1461 XNForeground, fg, XNBackground, bg,
1462 //XNFontSet, TermWin.fontset,
1463 NULL);
1464 } 1410 }
1465 1411
1466 Input_Context = XCreateIC (xim, XNInputStyle, input_style, 1412 Input_Context = XCreateIC (xim,
1413 XNInputStyle, input_style,
1467 XNClientWindow, TermWin.parent[0], 1414 XNClientWindow, TermWin.vt,
1468 XNFocusWindow, TermWin.parent[0], 1415 XNFocusWindow, TermWin.parent[0],
1469 preedit_attr ? XNPreeditAttributes : NULL, 1416 preedit_attr ? XNPreeditAttributes : NULL,
1470 preedit_attr, 1417 preedit_attr,
1471 status_attr ? XNStatusAttributes : NULL, 1418 status_attr ? XNStatusAttributes : NULL,
1472 status_attr, NULL); 1419 status_attr, NULL);
1420
1473 if (preedit_attr) XFree (preedit_attr); 1421 if (preedit_attr) XFree (preedit_attr);
1474 if (status_attr) XFree (status_attr); 1422 if (status_attr) XFree (status_attr);
1423 if (fs) XFreeFontSet (display->display, fs);
1475 1424
1476 if (Input_Context == NULL) 1425 if (Input_Context == NULL)
1477 { 1426 {
1478 rxvt_warn ("failed to create input context, continuing without XIM.\n"); 1427 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1479 display->put_xim (input_method); 1428 im_destroy ();
1480 return false; 1429 return false;
1481 } 1430 }
1482 1431
1483 if (input_style & XIMPreeditArea) 1432 if (input_style & XIMPreeditArea)
1484 IMSetStatusPosition (); 1433 IMSetStatusPosition ();
1514 s = rxvt_splitcommastring (p); 1463 s = rxvt_splitcommastring (p);
1515 for (i = 0; s[i]; i++) 1464 for (i = 0; s[i]; i++)
1516 { 1465 {
1517 if (*s[i]) 1466 if (*s[i])
1518 { 1467 {
1519 STRCPY (buf, "@im="); 1468 strcpy (buf, "@im=");
1520 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1469 strncat (buf, s[i], IMBUFSIZ - 5);
1521 if (IM_get_IC (buf)) 1470 if (IM_get_IC (buf))
1522 { 1471 {
1523 found = true; 1472 found = true;
1524 break; 1473 break;
1525 } 1474 }
1549} 1498}
1550 1499
1551void 1500void
1552rxvt_term::IMSetStatusPosition () 1501rxvt_term::IMSetStatusPosition ()
1553{ 1502{
1554 XRectangle preedit_rect, status_rect, *needed_rect; 1503 XRectangle preedit_rect, status_rect, *needed_rect;
1555 XVaNestedList preedit_attr, status_attr; 1504 XVaNestedList preedit_attr, status_attr;
1556 1505
1557 if (Input_Context == NULL 1506 if (!Input_Context
1507 || !TermWin.focus
1558 || !TermWin.focus || ! (input_style & XIMPreeditArea) 1508 || !(input_style & XIMPreeditArea)
1559 || !IMisRunning ()) 1509 || !IMisRunning ())
1560 return; 1510 return;
1561 1511
1562 /* Getting the necessary width of preedit area */ 1512 /* Getting the necessary width of preedit area */
1563 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); 1513 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1564 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); 1514 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1565 XFree (status_attr); 1515 XFree (status_attr);
1566 1516
1567 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); 1517 im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
1518 XFree (needed_rect);
1568 1519
1569 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); 1520 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1570 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); 1521 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1571 1522
1572 XSetICValues (Input_Context, 1523 XSetICValues (Input_Context,
1573 XNPreeditAttributes, preedit_attr, 1524 XNPreeditAttributes, preedit_attr,
1574 XNStatusAttributes, status_attr, NULL); 1525 XNStatusAttributes, status_attr, NULL);
1575 1526
1576 XFree (preedit_attr); 1527 XFree (preedit_attr);
1577 XFree (status_attr); 1528 XFree (status_attr);
1578} 1529}
1579#endif /* USE_XIM */ 1530#endif /* USE_XIM */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines