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.118 by root, Thu Dec 9 06:20:41 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
387#endif 379#endif
388 380
389 XMapWindow (display->display, TermWin.vt); 381 XMapWindow (display->display, TermWin.vt);
390 XMapWindow (display->display, TermWin.parent[0]); 382 XMapWindow (display->display, TermWin.parent[0]);
391 383
384 set_colorfgbg ();
385
392 init_command (cmd_argv); 386 init_command (cmd_argv);
393 387
394 pty_ev.start (pty.pty, EVENT_READ); 388 pty_ev.start (pty.pty, EVENT_READ);
395 389
396 check_ev.start (); 390 check_ev.start ();
401static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); 395static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
402 396
403void 397void
404rxvt_init () 398rxvt_init ()
405{ 399{
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 /* 400 /*
414 * Save and then give up any super-user privileges 401 * Save and then give up any super-user privileges
415 * 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.
416 * We should only need to be root in these cases: 403 * We should only need to be root in these cases:
417 * 1. write utmp entries on some systems 404 * 1. write utmp entries on some systems
418 * 2. chown tty on some systems 405 * 2. chown tty on some systems
419 */ 406 */
420 rxvt_privileges (SAVE); 407 rxvt_privileges (SAVE);
421 rxvt_privileges (IGNORE); 408 rxvt_privileges (IGNORE);
422 409
423 struct sigaction sa; 410 signal (SIGHUP, SIG_IGN);
424 411 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 412
434 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 413 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
435 /* signal (SIGURG, SIG_DFL); */ 414 /* signal (SIGURG, SIG_DFL); */
436 415
437 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
438 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 418 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
439} 419}
440 420
441/* ------------------------------------------------------------------------- * 421/* ------------------------------------------------------------------------- *
442 * SIGNAL HANDLING & EXIT HANDLER * 422 * SIGNAL HANDLING & EXIT HANDLER *
443 * ------------------------------------------------------------------------- */ 423 * ------------------------------------------------------------------------- */
444/* 424/*
445 * 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
446 */ 426 */
447 427
448void rxvt_term::child_exited (int pid) 428void
429rxvt_term::sig_chld (sig_watcher &w)
449{ 430{
450 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 431 // we are being called for every SIGCHLD, not just ours
451 if (pid == (*t)->cmd_pid) 432 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 433
465 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 434 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
466 rxvt_term::child_exited (pid); 435 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
467 436 if (pid == (*t)->cmd_pid)
468 errno = save_errno; 437 {
469} 438 (*t)->destroy ();
470 439 break;
471/* 440 }
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} 441}
500 442
501/*----------------------------------------------------------------------*/ 443/*----------------------------------------------------------------------*/
502/* 444/*
503 * Exit gracefully, clearing the utmp entry and restoring tty attributes 445 * Exit gracefully, clearing the utmp entry and restoring tty attributes
504 * 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
505 */ 447 */
448void
449rxvt_destroy_all ()
450{
451 // TODO: rxvtd should clean up all ressources
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
506/* INTPROTO */ 470/* INTPROTO */
507void 471int
508rxvt_clean_exit () 472rxvt_xerror_handler (Display *display, XErrorEvent *event)
509{ 473{
510 // TODO: rxvtd should clean up all ressources 474 if (GET_R->allowedxerror == -1)
511 if (GET_R) 475 GET_R->allowedxerror = event->error_code;
476 else
477 {
478 old_xerror_handler (display, event);
512 GET_R->destroy (); 479 GET_R->destroy ();
480 }
481
482 return 0;
513} 483}
514 484
515/* ------------------------------------------------------------------------- * 485/* ------------------------------------------------------------------------- *
516 * MEMORY ALLOCATION WRAPPERS * 486 * MEMORY ALLOCATION WRAPPERS *
517 * ------------------------------------------------------------------------- */ 487 * ------------------------------------------------------------------------- */
518/* INTPROTO */ 488void *
519void *
520rxvt_malloc (size_t size) 489rxvt_malloc (size_t size)
521{ 490{
522 void *p;
523
524 p = malloc (size); 491 void *p = malloc (size);
492
525 if (p) 493 if (!p)
526 return p;
527
528 rxvt_fatal ("memory allocation failure. aborting.\n"); 494 rxvt_fatal ("memory allocation failure. aborting.\n");
529 /* NOTREACHED */ 495
496 return p;
530} 497}
531 498
532/* INTPROTO */ 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)
540 return p;
541
542 rxvt_fatal ("memory allocation failure. aborting.\n"); 506 rxvt_fatal ("memory allocation failure. aborting.\n");
543 /* NOTREACHED */ 507
508 return p;
544} 509}
545 510
546/* INTPROTO */ 511/* INTPROTO */
547void * 512void *
548rxvt_realloc (void *ptr, size_t size) 513rxvt_realloc (void *ptr, size_t size)
549{ 514{
550 void *p;
551
552 if (ptr)
553 p = realloc (ptr, size); 515 void *p = realloc (ptr, size);
554 else
555 p = malloc (size);
556 516
557 if (p) 517 if (!p)
558 return p;
559
560 rxvt_fatal ("memory allocation failure. aborting.\n"); 518 rxvt_fatal ("memory allocation failure. aborting.\n");
561 /* NOTREACHED */ 519
520 return p;
562} 521}
563 522
564/* ------------------------------------------------------------------------- * 523/* ------------------------------------------------------------------------- *
565 * PRIVILEGED OPERATIONS * 524 * PRIVILEGED OPERATIONS *
566 * ------------------------------------------------------------------------- */ 525 * ------------------------------------------------------------------------- */
793 kill (cmd_pid, SIGWINCH); 752 kill (cmd_pid, SIGWINCH);
794#endif 753#endif
795} 754}
796 755
797/*----------------------------------------------------------------------*/ 756/*----------------------------------------------------------------------*/
798/* rxvt_change_font () - Switch to a new font */ 757/* set_fonts () - load and set the various fonts
799/* 758/*
800 * init = 1 - initialize 759 * init = 1 - initialize
801 * 760 *
802 * fontname == FONT_UP - switch to bigger font 761 * fontname == FONT_UP - switch to bigger font
803 * fontname == FONT_DN - switch to smaller font 762 * fontname == FONT_DN - switch to smaller font
804 */ 763 */
805bool 764bool
806rxvt_term::change_font (const char *fontname) 765rxvt_term::set_fonts ()
807{ 766{
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); 767 rxvt_fontset *fs = new rxvt_fontset (this);
768 rxvt_fontprop prop;
819 769
820 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
821 { 804 {
822 delete TermWin.fontset; 805 TermWin.fontset[style] = fs = new rxvt_fontset (this);
823 TermWin.fontset = fs; 806 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 807
828 if (TermWin.parent[0]) 808 if (res)
809 prop2.weight = prop2.slant = rxvt_fontprop::unset;
810 else
829 { 811 {
830 resize_all_windows (0, 0, 0); 812 res = TermWin.fontset[0]->fontdesc;
831 scr_remap_chars (); 813
832 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;
833 } 816 }
834 817
835 for (unicode_t ch = 0x20; ch <= 0x7f; ch++) 818 fs->populate (res);
836 TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); 819 fs->set_prop (prop2);
837
838 return true;
839 } 820 }
821#else
822 TermWin.fontset[style] = TermWin.fontset[0];
823#endif
824 }
825
826 if (TermWin.parent[0])
840 } 827 {
828 resize_all_windows (0, 0, 0);
829 scr_remap_chars ();
830 scr_touch (true);
831 }
841 832
842 return false; 833 return true;
843} 834}
844 835
845bool 836void rxvt_term::set_string_property (Atom prop, const char *str, int len)
846rxvt_term::font_up_down (int n, int direction)
847{ 837{
848 return false; 838 // TODO: SMART_WINDOW_TITLE
839 XChangeProperty (display->display, TermWin.parent[0],
840 prop, XA_STRING, 8, PropModeReplace,
841 (const unsigned char *)str, len >= 0 ? len : strlen (str));
842}
843
844void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
845{
846 // TODO: SMART_WINDOW_TITLE
847 wchar_t *ws = rxvt_mbstowcs (str, len);
848 char *s = rxvt_wcstoutf8 (ws);
849
850 XChangeProperty (display->display, TermWin.parent[0],
851 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
852 (const unsigned char *)s, strlen (s));
853
854 free (s);
855 free (ws);
849} 856}
850 857
851/*----------------------------------------------------------------------*/ 858/*----------------------------------------------------------------------*/
852/*----------------------------------------------------------------------*/ 859/*----------------------------------------------------------------------*/
853/* xterm sequences - title, iconName, color (exptl) */ 860/* xterm sequences - title, iconName, color (exptl) */
854void 861void
855rxvt_term::set_title (const char *str) 862rxvt_term::set_title (const char *str)
856{ 863{
857#ifdef SMART_WINDOW_TITLE 864 set_string_property (XA_WM_NAME, str);
858 char *name; 865#if ENABLE_FRILLS
859 866 set_utf8_property (display->atom ("_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 867#endif
871} 868}
872 869
873void 870void
874rxvt_term::set_icon_name (const char *str) 871rxvt_term::set_icon_name (const char *str)
875{ 872{
876#ifdef SMART_WINDOW_TITLE 873 set_string_property (XA_WM_ICON_NAME, str);
877 char *name; 874#if ENABLE_FRILLS
878 875 set_utf8_property (display->atom ("_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 876#endif
890} 877}
891 878
892#ifdef XTERM_COLOR_CHANGE 879#ifdef XTERM_COLOR_CHANGE
893void 880void
947 934
948 /* XSetWindowAttributes attr; */ 935 /* XSetWindowAttributes attr; */
949 /* Cursor cursor; */ 936 /* Cursor cursor; */
950Done: 937Done:
951#ifdef OFF_FOCUS_FADING 938#ifdef OFF_FOCUS_FADING
939 if (rs[Rs_fade])
952 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); 940 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
953#endif 941#endif
954 if (idx == Color_bg && ! (options & Opt_transparent))
955 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
956 942
957 /* handle Color_BD, scrollbar background, etc. */ 943 /*TODO: handle Color_BD, scrollbar background, etc. */
958 944
959 set_colorfgbg ();
960 recolour_cursor (); 945 recolour_cursor ();
961 scr_touch (true); 946 scr_recolour ();
962} 947}
963 948
964#else 949#else
965# define set_window_color (idx,color) ((void)0) 950# define set_window_color (idx,color) ((void)0)
966#endif /* XTERM_COLOR_CHANGE */ 951#endif /* XTERM_COLOR_CHANGE */
968void 953void
969rxvt_term::recolour_cursor () 954rxvt_term::recolour_cursor ()
970{ 955{
971 XColor xcol[2]; 956 XColor xcol[2];
972 957
973 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; 958 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]; 959 ? pix_colors_focused[Color_pointer_fg]
960 : pix_colors_focused[Color_fg];
961 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
962 ? pix_colors_focused[Color_pointer_bg]
963 : pix_colors_focused[Color_bg];
964
975 XQueryColors (display->display, display->cmap, xcol, 2); 965 XQueryColors (display->display, display->cmap, xcol, 2);
976 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); 966 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
977} 967}
978 968
979/*----------------------------------------------------------------------*/ 969/*----------------------------------------------------------------------*/
981 * find if fg/bg matches any of the normal (low-intensity) colors 971 * find if fg/bg matches any of the normal (low-intensity) colors
982 */ 972 */
983void 973void
984rxvt_term::set_colorfgbg () 974rxvt_term::set_colorfgbg ()
985{ 975{
986 unsigned int i; 976 unsigned int i;
987 const char *xpmb = "\0"; 977 const char *xpmb = "\0";
988 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 978 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
989 979
990 env_colorfgbg =
991 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 980 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
992 strcpy (fstr, "default"); 981 strcpy (fstr, "default");
993 strcpy (bstr, "default"); 982 strcpy (bstr, "default");
994 for (i = Color_Black; i <= Color_White; i++) 983 for (i = Color_Black; i <= Color_White; i++)
995 if (pix_colors[Color_fg] == pix_colors[i]) 984 if (pix_colors[Color_fg] == pix_colors[i])
996 { 985 {
997 sprintf (fstr, "%d", (i - Color_Black)); 986 sprintf (fstr, "%d", (i - Color_Black));
998 break; 987 break;
999 } 988 }
989
1000 for (i = Color_Black; i <= Color_White; i++) 990 for (i = Color_Black; i <= Color_White; i++)
1001 if (pix_colors[Color_bg] == pix_colors[i]) 991 if (pix_colors[Color_bg] == pix_colors[i])
1002 { 992 {
1003 sprintf (bstr, "%d", (i - Color_Black)); 993 sprintf (bstr, "%d", (i - Color_Black));
1004#ifdef XPM_BACKGROUND 994#ifdef XPM_BACKGROUND
1006#endif 996#endif
1007 break; 997 break;
1008 } 998 }
1009 999
1010 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1000 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} 1001}
1023 1002
1024/*----------------------------------------------------------------------*/ 1003/*----------------------------------------------------------------------*/
1025/* 1004/*
1026 * Colour determination for low colour displays, routine from 1005 * Colour determination for low colour displays, routine from
1252} 1231}
1253 1232
1254void 1233void
1255rxvt_term::IMSendSpot () 1234rxvt_term::IMSendSpot ()
1256{ 1235{
1257 XPoint spot; 1236 XPoint nspot;
1258 XVaNestedList preedit_attr; 1237 XVaNestedList preedit_attr;
1259 1238
1260 if (!Input_Context 1239 if (!Input_Context
1261 || !TermWin.focus 1240 || !TermWin.focus
1262 || !(input_style & XIMPreeditPosition) 1241 || !(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; 1242 return;
1272 1243
1273 im_set_position (spot); 1244 im_set_position (nspot);
1245
1246 if (nspot.x == spot.x && nspot.y == spot.y)
1247 return;
1248
1249 spot = nspot;
1274 1250
1275 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1251 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1276 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1252 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1277 XFree (preedit_attr); 1253 XFree (preedit_attr);
1278} 1254}
1279 1255
1280void 1256void
1281rxvt_term::im_destroy () 1257rxvt_term::im_destroy ()
1282{ 1258{
1283 if (Input_Context)
1284 {
1285 XDestroyIC (Input_Context);
1286 Input_Context = 0;
1287 }
1288
1289 if (input_method) 1259 if (input_method)
1290 { 1260 {
1261 if (Input_Context && input_method->xim)
1262 XDestroyIC (Input_Context);
1263
1291 display->put_xim (input_method); 1264 display->put_xim (input_method);
1292 input_method = 0; 1265 input_method = 0;
1293 } 1266 }
1267
1268 Input_Context = 0;
1294} 1269}
1295 1270
1296/* 1271/*
1297 * Try to open a XIM with the current modifiers, then see if we can 1272 * Try to open a XIM with the current modifiers, then see if we can
1298 * open a suitable preedit type 1273 * open a suitable preedit type
1316 input_method = display->get_xim (locale, modifiers); 1291 input_method = display->get_xim (locale, modifiers);
1317 if (input_method == NULL) 1292 if (input_method == NULL)
1318 return false; 1293 return false;
1319 1294
1320 xim = input_method->xim; 1295 xim = input_method->xim;
1296 spot.x = spot.y = -1;
1321 1297
1322 xim_styles = NULL; 1298 xim_styles = NULL;
1323 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1299 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1324 || !xim_styles || !xim_styles->count_styles) 1300 || !xim_styles || !xim_styles->count_styles)
1325 { 1301 {
1326 im_destroy (); 1302 im_destroy ();
1327 return false; 1303 return false;
1328 } 1304 }
1329 1305
1330 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1306 const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };
1307
1308 for (int pi = 0; pi < 2; pi++)
1309 {
1310 p = pet[pi];
1311
1312 if (!p)
1313 continue;
1314
1331 s = rxvt_splitcommastring (p); 1315 s = rxvt_splitcommastring (p);
1332 1316
1333 for (i = found = 0; !found && s[i]; i++) 1317 for (i = found = 0; !found && s[i]; i++)
1334 { 1318 {
1335 if (!strcmp (s[i], "OverTheSpot")) 1319 if (!strcmp (s[i], "OverTheSpot"))
1336 input_style = (XIMPreeditPosition | XIMStatusNothing); 1320 input_style = (XIMPreeditPosition | XIMStatusNothing);
1337 else if (!strcmp (s[i], "OffTheSpot")) 1321 else if (!strcmp (s[i], "OffTheSpot"))
1338 input_style = (XIMPreeditArea | XIMStatusArea); 1322 input_style = (XIMPreeditArea | XIMStatusArea);
1339 else if (!strcmp (s[i], "Root")) 1323 else if (!strcmp (s[i], "Root"))
1340 input_style = (XIMPreeditNothing | XIMStatusNothing); 1324 input_style = (XIMPreeditNothing | XIMStatusNothing);
1325 else if (!strcmp (s[i], "None"))
1326 input_style = (XIMPreeditNone | XIMStatusNone);
1341 1327
1342 for (j = 0; j < xim_styles->count_styles; j++) 1328 for (j = 0; j < xim_styles->count_styles; j++)
1343 if (input_style == xim_styles->supported_styles[j]) 1329 if (input_style == xim_styles->supported_styles[j])
1344 { 1330 {
1331 rxvt_freecommastring (s);
1332
1345 found = 1; 1333 found = 1;
1346 break; 1334 goto foundpet;
1335 }
1336
1347 } 1337 }
1348 }
1349 1338
1350 for (i = 0; s[i]; i++) 1339 rxvt_freecommastring (s);
1351 free (s[i]); 1340 }
1352 1341
1353 free (s); 1342foundpet:
1343
1354 XFree (xim_styles); 1344 XFree (xim_styles);
1355 1345
1356 if (!found) 1346 if (!found)
1357 { 1347 {
1358 im_destroy (); 1348 im_destroy ();
1483 if (p && *p) 1473 if (p && *p)
1484 { 1474 {
1485 bool found = false; 1475 bool found = false;
1486 1476
1487 s = rxvt_splitcommastring (p); 1477 s = rxvt_splitcommastring (p);
1478
1488 for (i = 0; s[i]; i++) 1479 for (i = 0; s[i]; i++)
1489 { 1480 {
1490 if (*s[i]) 1481 if (*s[i])
1491 { 1482 {
1492 strcpy (buf, "@im="); 1483 strcpy (buf, "@im=");
1496 found = true; 1487 found = true;
1497 break; 1488 break;
1498 } 1489 }
1499 } 1490 }
1500 } 1491 }
1501 for (i = 0; s[i]; i++) 1492
1502 free (s[i]); 1493 rxvt_freecommastring (s);
1503 free (s);
1504 1494
1505 if (found) 1495 if (found)
1506 goto done; 1496 goto done;
1507 } 1497 }
1508 1498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines