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.94 by root, Sun Aug 15 22:09:24 2004 UTC vs.
Revision 1.121 by root, Wed Dec 15 00:12:58 2004 UTC

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),
196 183
197#ifdef UTMP_SUPPORT 184#ifdef UTMP_SUPPORT
198 privileged_utmp (RESTORE); 185 privileged_utmp (RESTORE);
199#endif 186#endif
200 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
201 delete TermWin.fontset; 193 delete TermWin.fontset[0];
202 194
203 if (display) 195 if (display)
204 { 196 {
205 selection_clear (); 197 selection_clear ();
206 198
267 free (env_windowid); 259 free (env_windowid);
268 free (env_display); 260 free (env_display);
269 free (env_term); 261 free (env_term);
270 free (env_colorfgbg); 262 free (env_colorfgbg);
271 free (locale); 263 free (locale);
272#if 0 264 free (v_buffer);
273 free (codeset); 265 free (incr_buf);
274#endif
275 266
276 delete envv; 267 delete envv;
277 delete argv; 268 delete argv;
278} 269}
279 270
387#endif 378#endif
388 379
389 XMapWindow (display->display, TermWin.vt); 380 XMapWindow (display->display, TermWin.vt);
390 XMapWindow (display->display, TermWin.parent[0]); 381 XMapWindow (display->display, TermWin.parent[0]);
391 382
383 set_colorfgbg ();
384
392 init_command (cmd_argv); 385 init_command (cmd_argv);
393 386
394 pty_ev.start (pty.pty, EVENT_READ); 387 pty_ev.start (pty.pty, EVENT_READ);
395 388
396 check_ev.start (); 389 check_ev.start ();
401static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); 394static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
402 395
403void 396void
404rxvt_init () 397rxvt_init ()
405{ 398{
406 /* install exit handler for cleanup */
407#if 0
408#ifdef HAVE_ATEXIT
409 atexit (rxvt_clean_exit);
410#else
411#endif
412#endif
413 /* 399 /*
414 * Save and then give up any super-user privileges 400 * Save and then give up any super-user privileges
415 * If we need privileges in any area then we must specifically request it. 401 * If we need privileges in any area then we must specifically request it.
416 * We should only need to be root in these cases: 402 * We should only need to be root in these cases:
417 * 1. write utmp entries on some systems 403 * 1. write utmp entries on some systems
418 * 2. chown tty on some systems 404 * 2. chown tty on some systems
419 */ 405 */
420 rxvt_privileges (SAVE); 406 rxvt_privileges (SAVE);
421 rxvt_privileges (IGNORE); 407 rxvt_privileges (IGNORE);
422 408
423 struct sigaction sa; 409 signal (SIGHUP, SIG_IGN);
424 410 signal (SIGPIPE, SIG_IGN);
425 sigfillset (&sa.sa_mask);
426 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
427 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
428 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
429 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
430 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
431 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
432 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
433 411
434 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 412 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
435 /* signal (SIGURG, SIG_DFL); */ 413 /* signal (SIGURG, SIG_DFL); */
436 414
437 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 415 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
416 // TODO: handle this with exceptions and tolerate the memory loss
438 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 417 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
439} 418}
440 419
441/* ------------------------------------------------------------------------- * 420/* ------------------------------------------------------------------------- *
442 * SIGNAL HANDLING & EXIT HANDLER * 421 * SIGNAL HANDLING & EXIT HANDLER *
443 * ------------------------------------------------------------------------- */ 422 * ------------------------------------------------------------------------- */
444/* 423/*
445 * Catch a SIGCHLD signal and exit if the direct child has died 424 * Catch a SIGCHLD signal and exit if the direct child has died
446 */ 425 */
447 426
448void rxvt_term::child_exited (int pid) 427void
428rxvt_term::sig_chld (sig_watcher &w)
449{ 429{
450 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 430 // we are being called for every SIGCHLD, not just ours
451 if (pid == (*t)->cmd_pid) 431 int pid;
452 {
453 (*t)->destroy ();
454 break;
455 }
456}
457
458/* ARGSUSED */
459/* INTPROTO */
460RETSIGTYPE
461rxvt_Child_signal (int sig __attribute__ ((unused)))
462{
463 int pid, save_errno = errno;
464 432
465 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 433 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
466 rxvt_term::child_exited (pid); 434 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
467 435 if (pid == (*t)->cmd_pid)
468 errno = save_errno; 436 {
469} 437 (*t)->destroy ();
470 438 break;
471/* 439 }
472 * Catch a fatal signal and tidy up before quitting
473 */
474/* INTPROTO */
475RETSIGTYPE
476rxvt_Exit_signal (int sig)
477{
478 signal (sig, SIG_DFL);
479#ifdef DEBUG_CMD
480 rxvt_warn ("caught signal %d, exiting.\n", sig);
481#endif
482 rxvt_clean_exit ();
483 kill (getpid (), sig);
484}
485
486/* INTPROTO */
487int
488rxvt_xerror_handler (Display *display, XErrorEvent *event)
489{
490 if (GET_R->allowedxerror == -1)
491 GET_R->allowedxerror = event->error_code;
492 else
493 {
494 old_xerror_handler (display, event);
495 GET_R->destroy ();
496 }
497
498 return 0;
499} 440}
500 441
501/*----------------------------------------------------------------------*/ 442/*----------------------------------------------------------------------*/
502/* 443/*
503 * Exit gracefully, clearing the utmp entry and restoring tty attributes 444 * Exit gracefully, clearing the utmp entry and restoring tty attributes
504 * TODO: if debugging, this should free up any known resources if we can 445 * TODO: if debugging, this should free up any known resources if we can
505 */ 446 */
447void
448rxvt_destroy_all ()
449{
450 // TODO: rxvtd should clean up all ressources
451 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
452 (*t)->destroy ();
453}
454
455/*
456 * Catch a fatal signal and tidy up before quitting
457 */
458void
459rxvt_term::sig_term (sig_watcher &w)
460{
461#ifdef DEBUG_CMD
462 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
463#endif
464 rxvt_destroy_all ();
465 signal (w.signum, SIG_DFL);
466 kill (getpid (), w.signum);
467}
468
506/* INTPROTO */ 469/* INTPROTO */
507void 470int
508rxvt_clean_exit () 471rxvt_xerror_handler (Display *display, XErrorEvent *event)
509{ 472{
510 // TODO: rxvtd should clean up all ressources 473 if (GET_R->allowedxerror == -1)
511 if (GET_R) 474 GET_R->allowedxerror = event->error_code;
475 else
476 {
477 old_xerror_handler (display, event);
512 GET_R->destroy (); 478 GET_R->destroy ();
479 }
480
481 return 0;
513} 482}
514 483
515/* ------------------------------------------------------------------------- * 484/* ------------------------------------------------------------------------- *
516 * MEMORY ALLOCATION WRAPPERS * 485 * MEMORY ALLOCATION WRAPPERS *
517 * ------------------------------------------------------------------------- */ 486 * ------------------------------------------------------------------------- */
518/* INTPROTO */ 487void *
519void *
520rxvt_malloc (size_t size) 488rxvt_malloc (size_t size)
521{ 489{
522 void *p;
523
524 p = malloc (size); 490 void *p = malloc (size);
491
525 if (p) 492 if (!p)
526 return p;
527
528 rxvt_fatal ("memory allocation failure. aborting.\n"); 493 rxvt_fatal ("memory allocation failure. aborting.\n");
529 /* NOTREACHED */ 494
495 return p;
530} 496}
531 497
532/* INTPROTO */ 498/* INTPROTO */
533void * 499void *
534rxvt_calloc (size_t number, size_t size) 500rxvt_calloc (size_t number, size_t size)
535{ 501{
536 void *p;
537
538 p = calloc (number, size); 502 void *p = calloc (number, size);
503
539 if (p) 504 if (!p)
540 return p;
541
542 rxvt_fatal ("memory allocation failure. aborting.\n"); 505 rxvt_fatal ("memory allocation failure. aborting.\n");
543 /* NOTREACHED */ 506
507 return p;
544} 508}
545 509
546/* INTPROTO */ 510/* INTPROTO */
547void * 511void *
548rxvt_realloc (void *ptr, size_t size) 512rxvt_realloc (void *ptr, size_t size)
549{ 513{
550 void *p;
551
552 if (ptr)
553 p = realloc (ptr, size); 514 void *p = realloc (ptr, size);
554 else
555 p = malloc (size);
556 515
557 if (p) 516 if (!p)
558 return p;
559
560 rxvt_fatal ("memory allocation failure. aborting.\n"); 517 rxvt_fatal ("memory allocation failure. aborting.\n");
561 /* NOTREACHED */ 518
519 return p;
562} 520}
563 521
564/* ------------------------------------------------------------------------- * 522/* ------------------------------------------------------------------------- *
565 * PRIVILEGED OPERATIONS * 523 * PRIVILEGED OPERATIONS *
566 * ------------------------------------------------------------------------- */ 524 * ------------------------------------------------------------------------- */
793 kill (cmd_pid, SIGWINCH); 751 kill (cmd_pid, SIGWINCH);
794#endif 752#endif
795} 753}
796 754
797/*----------------------------------------------------------------------*/ 755/*----------------------------------------------------------------------*/
798/* rxvt_change_font () - Switch to a new font */ 756/* set_fonts () - load and set the various fonts
799/* 757/*
800 * init = 1 - initialize 758 * init = 1 - initialize
801 * 759 *
802 * fontname == FONT_UP - switch to bigger font 760 * fontname == FONT_UP - switch to bigger font
803 * fontname == FONT_DN - switch to smaller font 761 * fontname == FONT_DN - switch to smaller font
804 */ 762 */
805bool 763bool
806rxvt_term::change_font (const char *fontname) 764rxvt_term::set_fonts ()
807{ 765{
808 if (fontname == FONT_UP)
809 {
810 // TODO
811 }
812 else if (fontname == FONT_DN)
813 {
814 // TODO
815 }
816 else
817 {
818 rxvt_fontset *fs = new rxvt_fontset (this); 766 rxvt_fontset *fs = new rxvt_fontset (this);
767 rxvt_fontprop prop;
819 768
820 if (fs && fs->populate (fontname ? fontname : "fixed")) 769 if (!fs
770 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed")
771 || !fs->realize_font (1))
772 {
773 delete fs;
774 return false;
775 }
776
777#if ENABLE_STYLES
778 for (int i = RS_styleCount; --i; )
779 if (TermWin.fontset[i] != TermWin.fontset[0])
780 delete TermWin.fontset[i];
781#endif
782
783 delete TermWin.fontset[0];
784 TermWin.fontset[0] = fs;
785
786 prop = (*fs)[1]->properties ();
787 fs->set_prop (prop);
788
789 TermWin.fwidth = prop.width;
790 TermWin.fheight = prop.height;
791 TermWin.fweight = prop.weight;
792 TermWin.fslant = prop.slant;
793 TermWin.fbase = (*fs)[1]->ascent;
794
795 for (int style = 1; style < 4; style++)
796 {
797#if ENABLE_STYLES
798 const char *res = rs[Rs_font + style];
799
800 if (res && !*res)
801 TermWin.fontset[style] = TermWin.fontset[0];
802 else
821 { 803 {
822 delete TermWin.fontset; 804 TermWin.fontset[style] = fs = new rxvt_fontset (this);
823 TermWin.fontset = fs; 805 rxvt_fontprop prop2 = prop;
824 TermWin.fwidth = fs->base_font ()->width;
825 TermWin.fheight = fs->base_font ()->height;
826 TermWin.fbase = fs->base_font ()->ascent;
827 806
828 if (TermWin.parent[0]) 807 if (res)
808 prop2.weight = prop2.slant = rxvt_fontprop::unset;
809 else
829 { 810 {
830 resize_all_windows (0, 0, 0); 811 res = TermWin.fontset[0]->fontdesc;
831 scr_remap_chars (); 812
832 scr_touch (true); 813 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
814 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
833 } 815 }
834 816
835 for (unicode_t ch = 0x20; ch <= 0x7f; ch++) 817 fs->populate (res);
836 TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); 818 fs->set_prop (prop2);
837
838 return true;
839 } 819 }
820#else
821 TermWin.fontset[style] = TermWin.fontset[0];
822#endif
823 }
824
825 if (TermWin.parent[0])
840 } 826 {
827 resize_all_windows (0, 0, 0);
828 scr_remap_chars ();
829 scr_touch (true);
830 }
841 831
842 return false; 832 return true;
843} 833}
844 834
845bool 835void rxvt_term::set_string_property (Atom prop, const char *str, int len)
846rxvt_term::font_up_down (int n, int direction)
847{ 836{
848 return false; 837 // TODO: SMART_WINDOW_TITLE
838 XChangeProperty (display->display, TermWin.parent[0],
839 prop, XA_STRING, 8, PropModeReplace,
840 (const unsigned char *)str, len >= 0 ? len : strlen (str));
841}
842
843void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
844{
845 // TODO: SMART_WINDOW_TITLE
846 wchar_t *ws = rxvt_mbstowcs (str, len);
847 char *s = rxvt_wcstoutf8 (ws);
848
849 XChangeProperty (display->display, TermWin.parent[0],
850 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
851 (const unsigned char *)s, strlen (s));
852
853 free (s);
854 free (ws);
849} 855}
850 856
851/*----------------------------------------------------------------------*/ 857/*----------------------------------------------------------------------*/
852/*----------------------------------------------------------------------*/ 858/*----------------------------------------------------------------------*/
853/* xterm sequences - title, iconName, color (exptl) */ 859/* xterm sequences - title, iconName, color (exptl) */
854void 860void
855rxvt_term::set_title (const char *str) 861rxvt_term::set_title (const char *str)
856{ 862{
857#ifdef SMART_WINDOW_TITLE 863 set_string_property (XA_WM_NAME, str);
858 char *name; 864#if ENABLE_FRILLS
859 865 set_utf8_property (xa[XA_NET_WM_NAME], str);
860 if (!XFetchName (display->display, TermWin.parent[0], &name))
861 name = NULL;
862
863 if (name == NULL || strcmp (name, str))
864#endif
865 XStoreName (display->display, TermWin.parent[0], str);
866
867#ifdef SMART_WINDOW_TITLE
868 if (name)
869 XFree (name);
870#endif 866#endif
871} 867}
872 868
873void 869void
874rxvt_term::set_icon_name (const char *str) 870rxvt_term::set_icon_name (const char *str)
875{ 871{
876#ifdef SMART_WINDOW_TITLE 872 set_string_property (XA_WM_ICON_NAME, str);
877 char *name; 873#if ENABLE_FRILLS
878 874 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
879 if (!XGetIconName (display->display, TermWin.parent[0], &name))
880 name = NULL;
881
882 if (name == NULL || strcmp (name, str))
883#endif
884 XSetIconName (display->display, TermWin.parent[0], str);
885
886#ifdef SMART_WINDOW_TITLE
887 if (name)
888 XFree (name);
889#endif 875#endif
890} 876}
891 877
892#ifdef XTERM_COLOR_CHANGE 878#ifdef XTERM_COLOR_CHANGE
893void 879void
947 933
948 /* XSetWindowAttributes attr; */ 934 /* XSetWindowAttributes attr; */
949 /* Cursor cursor; */ 935 /* Cursor cursor; */
950Done: 936Done:
951#ifdef OFF_FOCUS_FADING 937#ifdef OFF_FOCUS_FADING
938 if (rs[Rs_fade])
952 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); 939 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
953#endif 940#endif
954 if (idx == Color_bg && ! (options & Opt_transparent))
955 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
956 941
957 /* handle Color_BD, scrollbar background, etc. */ 942 /*TODO: handle Color_BD, scrollbar background, etc. */
958 943
959 set_colorfgbg ();
960 recolour_cursor (); 944 recolour_cursor ();
961 scr_touch (true); 945 scr_recolour ();
962} 946}
963 947
964#else 948#else
965# define set_window_color (idx,color) ((void)0) 949# define set_window_color (idx,color) ((void)0)
966#endif /* XTERM_COLOR_CHANGE */ 950#endif /* XTERM_COLOR_CHANGE */
968void 952void
969rxvt_term::recolour_cursor () 953rxvt_term::recolour_cursor ()
970{ 954{
971 XColor xcol[2]; 955 XColor xcol[2];
972 956
973 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; 957 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg)
974 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg]; 958 ? pix_colors_focused[Color_pointer_fg]
959 : pix_colors_focused[Color_fg];
960 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
961 ? pix_colors_focused[Color_pointer_bg]
962 : pix_colors_focused[Color_bg];
963
975 XQueryColors (display->display, display->cmap, xcol, 2); 964 XQueryColors (display->display, display->cmap, xcol, 2);
976 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); 965 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
977} 966}
978 967
979/*----------------------------------------------------------------------*/ 968/*----------------------------------------------------------------------*/
981 * find if fg/bg matches any of the normal (low-intensity) colors 970 * find if fg/bg matches any of the normal (low-intensity) colors
982 */ 971 */
983void 972void
984rxvt_term::set_colorfgbg () 973rxvt_term::set_colorfgbg ()
985{ 974{
986 unsigned int i; 975 unsigned int i;
987 const char *xpmb = "\0"; 976 const char *xpmb = "\0";
988 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 977 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
989 978
990 env_colorfgbg =
991 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 979 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
992 strcpy (fstr, "default"); 980 strcpy (fstr, "default");
993 strcpy (bstr, "default"); 981 strcpy (bstr, "default");
994 for (i = Color_Black; i <= Color_White; i++) 982 for (i = Color_Black; i <= Color_White; i++)
995 if (pix_colors[Color_fg] == pix_colors[i]) 983 if (pix_colors[Color_fg] == pix_colors[i])
996 { 984 {
997 sprintf (fstr, "%d", (i - Color_Black)); 985 sprintf (fstr, "%d", (i - Color_Black));
998 break; 986 break;
999 } 987 }
988
1000 for (i = Color_Black; i <= Color_White; i++) 989 for (i = Color_Black; i <= Color_White; i++)
1001 if (pix_colors[Color_bg] == pix_colors[i]) 990 if (pix_colors[Color_bg] == pix_colors[i])
1002 { 991 {
1003 sprintf (bstr, "%d", (i - Color_Black)); 992 sprintf (bstr, "%d", (i - Color_Black));
1004#ifdef XPM_BACKGROUND 993#ifdef XPM_BACKGROUND
1006#endif 995#endif
1007 break; 996 break;
1008 } 997 }
1009 998
1010 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 999 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1011
1012#ifndef NO_BRIGHTCOLOR
1013 colorfgbg = DEFAULT_RSTYLE;
1014 for (i = minCOLOR; i <= maxCOLOR; i++)
1015 {
1016 if (pix_colors[Color_fg] == pix_colors[i])
1017 colorfgbg = SET_FGCOLOR (colorfgbg, i);
1018 if (pix_colors[Color_bg] == pix_colors[i])
1019 colorfgbg = SET_BGCOLOR (colorfgbg, i);
1020 }
1021#endif
1022} 1000}
1023 1001
1024/*----------------------------------------------------------------------*/ 1002/*----------------------------------------------------------------------*/
1025/* 1003/*
1026 * Colour determination for low colour displays, routine from 1004 * Colour determination for low colour displays, routine from
1252} 1230}
1253 1231
1254void 1232void
1255rxvt_term::IMSendSpot () 1233rxvt_term::IMSendSpot ()
1256{ 1234{
1257 XPoint spot; 1235 XPoint nspot;
1258 XVaNestedList preedit_attr; 1236 XVaNestedList preedit_attr;
1259 1237
1260 if (!Input_Context 1238 if (!Input_Context
1261 || !TermWin.focus 1239 || !TermWin.focus
1262 || !(input_style & XIMPreeditPosition) 1240 || !(input_style & XIMPreeditPosition))
1263#if 0
1264 || !(event_type == KeyPress
1265 || event_type == Expose
1266 || event_type == NoExpose
1267 || event_type == SelectionNotify
1268 || event_type == ButtonRelease || event_type == FocusIn)
1269#endif
1270 || !IMisRunning ())
1271 return; 1241 return;
1272 1242
1273 im_set_position (spot); 1243 im_set_position (nspot);
1244
1245 if (nspot.x == spot.x && nspot.y == spot.y)
1246 return;
1247
1248 spot = nspot;
1274 1249
1275 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1250 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1276 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1251 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1277 XFree (preedit_attr); 1252 XFree (preedit_attr);
1278} 1253}
1279 1254
1280void 1255void
1281rxvt_term::im_destroy () 1256rxvt_term::im_destroy ()
1282{ 1257{
1283 if (Input_Context)
1284 {
1285 XDestroyIC (Input_Context);
1286 Input_Context = 0;
1287 }
1288
1289 if (input_method) 1258 if (input_method)
1290 { 1259 {
1260 if (Input_Context && input_method->xim)
1261 XDestroyIC (Input_Context);
1262
1291 display->put_xim (input_method); 1263 display->put_xim (input_method);
1292 input_method = 0; 1264 input_method = 0;
1293 } 1265 }
1266
1267 Input_Context = 0;
1294} 1268}
1295 1269
1296/* 1270/*
1297 * Try to open a XIM with the current modifiers, then see if we can 1271 * Try to open a XIM with the current modifiers, then see if we can
1298 * open a suitable preedit type 1272 * open a suitable preedit type
1316 input_method = display->get_xim (locale, modifiers); 1290 input_method = display->get_xim (locale, modifiers);
1317 if (input_method == NULL) 1291 if (input_method == NULL)
1318 return false; 1292 return false;
1319 1293
1320 xim = input_method->xim; 1294 xim = input_method->xim;
1295 spot.x = spot.y = -1;
1321 1296
1322 xim_styles = NULL; 1297 xim_styles = NULL;
1323 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1298 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1324 || !xim_styles || !xim_styles->count_styles) 1299 || !xim_styles || !xim_styles->count_styles)
1325 { 1300 {
1326 im_destroy (); 1301 im_destroy ();
1327 return false; 1302 return false;
1328 } 1303 }
1329 1304
1330 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1305 const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };
1306
1307 for (int pi = 0; pi < 2; pi++)
1308 {
1309 p = pet[pi];
1310
1311 if (!p)
1312 continue;
1313
1331 s = rxvt_splitcommastring (p); 1314 s = rxvt_splitcommastring (p);
1332 1315
1333 for (i = found = 0; !found && s[i]; i++) 1316 for (i = found = 0; !found && s[i]; i++)
1334 { 1317 {
1335 if (!strcmp (s[i], "OverTheSpot")) 1318 if (!strcmp (s[i], "OverTheSpot"))
1336 input_style = (XIMPreeditPosition | XIMStatusNothing); 1319 input_style = (XIMPreeditPosition | XIMStatusNothing);
1337 else if (!strcmp (s[i], "OffTheSpot")) 1320 else if (!strcmp (s[i], "OffTheSpot"))
1338 input_style = (XIMPreeditArea | XIMStatusArea); 1321 input_style = (XIMPreeditArea | XIMStatusArea);
1339 else if (!strcmp (s[i], "Root")) 1322 else if (!strcmp (s[i], "Root"))
1340 input_style = (XIMPreeditNothing | XIMStatusNothing); 1323 input_style = (XIMPreeditNothing | XIMStatusNothing);
1324 else if (!strcmp (s[i], "None"))
1325 input_style = (XIMPreeditNone | XIMStatusNone);
1341 1326
1342 for (j = 0; j < xim_styles->count_styles; j++) 1327 for (j = 0; j < xim_styles->count_styles; j++)
1343 if (input_style == xim_styles->supported_styles[j]) 1328 if (input_style == xim_styles->supported_styles[j])
1344 { 1329 {
1330 rxvt_freecommastring (s);
1331
1345 found = 1; 1332 found = 1;
1346 break; 1333 goto foundpet;
1334 }
1335
1347 } 1336 }
1348 }
1349 1337
1350 for (i = 0; s[i]; i++) 1338 rxvt_freecommastring (s);
1351 free (s[i]); 1339 }
1352 1340
1353 free (s); 1341foundpet:
1342
1354 XFree (xim_styles); 1343 XFree (xim_styles);
1355 1344
1356 if (!found) 1345 if (!found)
1357 { 1346 {
1358 im_destroy (); 1347 im_destroy ();
1483 if (p && *p) 1472 if (p && *p)
1484 { 1473 {
1485 bool found = false; 1474 bool found = false;
1486 1475
1487 s = rxvt_splitcommastring (p); 1476 s = rxvt_splitcommastring (p);
1477
1488 for (i = 0; s[i]; i++) 1478 for (i = 0; s[i]; i++)
1489 { 1479 {
1490 if (*s[i]) 1480 if (*s[i])
1491 { 1481 {
1492 strcpy (buf, "@im="); 1482 strcpy (buf, "@im=");
1496 found = true; 1486 found = true;
1497 break; 1487 break;
1498 } 1488 }
1499 } 1489 }
1500 } 1490 }
1501 for (i = 0; s[i]; i++) 1491
1502 free (s[i]); 1492 rxvt_freecommastring (s);
1503 free (s);
1504 1493
1505 if (found) 1494 if (found)
1506 goto done; 1495 goto done;
1507 } 1496 }
1508 1497

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines