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.26 by pcg, Sun Feb 1 01:34:41 2004 UTC vs.
Revision 1.29 by pcg, Wed Feb 11 08:13:45 2004 UTC

72 free (p); 72 free (p);
73} 73}
74 74
75rxvt_term::rxvt_term () 75rxvt_term::rxvt_term ()
76 : 76 :
77 rootwin_ev (this, &rxvt_term::rootwin_cb),
78 termwin_ev (this, &rxvt_term::x_cb),
79 vt_ev (this, &rxvt_term::x_cb),
80#ifdef HAVE_SCROLLBARS
81 scrollbar_ev (this, &rxvt_term::x_cb),
82#endif
83#ifdef MENUBAR
84 menubar_ev (this, &rxvt_term::x_cb), fixme
85#endif
77#ifdef CURSOR_BLINK 86#ifdef CURSOR_BLINK
78 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 87 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
79#endif 88#endif
80#ifdef TEXT_BLINK 89#ifdef TEXT_BLINK
81 text_blink_ev (this, &rxvt_term::text_blink_cb), 90 text_blink_ev (this, &rxvt_term::text_blink_cb),
84 pointer_ev (this, &rxvt_term::pointer_cb), 93 pointer_ev (this, &rxvt_term::pointer_cb),
85#endif 94#endif
86 check_ev (this, &rxvt_term::check_cb), 95 check_ev (this, &rxvt_term::check_cb),
87 destroy_ev (this, &rxvt_term::destroy_cb), 96 destroy_ev (this, &rxvt_term::destroy_cb),
88 pty_ev (this, &rxvt_term::pty_cb), 97 pty_ev (this, &rxvt_term::pty_cb),
89 x_ev (this, &rxvt_term::x_cb),
90 incr_ev (this, &rxvt_term::incr_cb) 98 incr_ev (this, &rxvt_term::incr_cb),
99#ifdef USE_XIM
100 im_ev (this, &rxvt_term::im_cb)
101#endif
91{ 102{
92 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 103 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
93} 104}
94 105
95rxvt_term::~rxvt_term () 106rxvt_term::~rxvt_term ()
96{ 107{
108 if (cmd_fd >= 0)
109 close (cmd_fd);
110
97 scr_release (); 111 scr_release ();
98 112
99 free (locale); 113 free (locale);
100 free (codeset); 114 free (codeset);
101 115
103 privileged_ttydev (RESTORE); 117 privileged_ttydev (RESTORE);
104#endif 118#endif
105#ifdef UTMP_SUPPORT 119#ifdef UTMP_SUPPORT
106 privileged_utmp (RESTORE); 120 privileged_utmp (RESTORE);
107#endif 121#endif
122
123 // TODO: free pixcolours, colours should become part of rxvt_display
124
125 delete PixColors;
126
127 displays.put (display);
128}
129
130void
131rxvt_term::destroy ()
132{
133 if (display)
134 {
135 if (TermWin.parent[0])
136 XDestroyWindow (display->display, TermWin.parent[0]);
137
138 termwin_ev.stop (display);
139 vt_ev.stop (display);
140
108#ifdef USE_XIM 141#ifdef USE_XIM
109 if (Input_Context != NULL) 142 im_destroy ();
143 im_ev.stop (display);
144#endif
145#ifdef HAVE_SCROLLBARS
146 scrollbar_ev.stop (display);
147#endif
148#ifdef MENUBAR
149 menubar_ev.stop (display);
150#endif
110 { 151 }
111 XDestroyIC (Input_Context);
112 Input_Context = NULL;
113 }
114#endif
115 152
116 if (cmd_fd >= 0)
117 close (cmd_fd);
118
119 if (Xfd >= 0)
120 XCloseDisplay (Xdisplay);
121
122 delete PixColors;
123}
124
125void
126rxvt_term::destroy ()
127{
128 check_ev.stop (); 153 check_ev.stop ();
129 pty_ev.stop (); 154 pty_ev.stop ();
130 x_ev.stop ();
131#ifdef CURSOR_BLINK 155#ifdef CURSOR_BLINK
132 cursor_blink_ev.stop (); 156 cursor_blink_ev.stop ();
133#endif 157#endif
134#ifdef TEXT_BLINK 158#ifdef TEXT_BLINK
135 text_blink_ev.stop (); 159 text_blink_ev.stop ();
163 SET_R (0); 187 SET_R (0);
164 } 188 }
165 189
166 return GET_R; 190 return GET_R;
167} 191}
192
193static int (*old_xerror_handler)(Display *dpy, XErrorEvent *event);
168 194
169void 195void
170rxvt_init_signals () 196rxvt_init_signals ()
171{ 197{
172 /* install exit handler for cleanup */ 198 /* install exit handler for cleanup */
189 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); 215 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
190 216
191 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 217 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
192 /* signal (SIGURG, SIG_DFL); */ 218 /* signal (SIGURG, SIG_DFL); */
193 219
194 XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 220 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
195 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 221 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
196} 222}
197 223
198bool 224bool
199rxvt_term::init (int argc, const char *const *argv) 225rxvt_term::init (int argc, const char *const *argv)
231 Gr_reset (); /* reset graphics */ 257 Gr_reset (); /* reset graphics */
232#endif 258#endif
233 259
234#if 0 260#if 0
235#ifdef DEBUG_X 261#ifdef DEBUG_X
236 XSynchronize(Xdisplay, True); 262 XSynchronize(display->display, True);
237#endif 263#endif
238#endif 264#endif
239 265
240#ifdef HAVE_SCROLLBARS 266#ifdef HAVE_SCROLLBARS
241 if (Options & Opt_scrollBar) 267 if (Options & Opt_scrollBar)
242 resize_scrollbar (); /* create and map scrollbar */ 268 resize_scrollbar (); /* create and map scrollbar */
243#endif 269#endif
244#if (MENUBAR_MAX) 270#if (MENUBAR_MAX)
245 if (menubar_visible(r)) 271 if (menubar_visible(r))
246 XMapWindow (Xdisplay, menuBar.win); 272 XMapWindow (display->display, menuBar.win);
247#endif 273#endif
248#ifdef TRANSPARENT 274#ifdef TRANSPARENT
249 if (Options & Opt_transparent) 275 if (Options & Opt_transparent)
250 { 276 {
251 XSelectInput (Xdisplay, Xroot, PropertyChangeMask); 277 XSelectInput (display->display, display->root, PropertyChangeMask);
252 check_our_parents (); 278 check_our_parents ();
253 } 279 }
254#endif 280#endif
281
282 rootwin_ev.start (display, display->root);
283
255 XMapWindow (Xdisplay, TermWin.vt); 284 XMapWindow (display->display, TermWin.vt);
256 XMapWindow (Xdisplay, TermWin.parent[0]); 285 XMapWindow (display->display, TermWin.parent[0]);
257 286
258 init_env (); 287 init_env ();
259 init_command (cmd_argv); 288 init_command (cmd_argv);
260 289
261 x_ev.start (Xfd, EVENT_READ);
262 pty_ev.start (cmd_fd, EVENT_READ); 290 pty_ev.start (cmd_fd, EVENT_READ);
263 291
264 check_ev.start (); 292 check_ev.start ();
265
266 process_x_events ();
267 293
268 return true; 294 return true;
269} 295}
270 296
271/* ------------------------------------------------------------------------- * 297/* ------------------------------------------------------------------------- *
303#endif 329#endif
304 rxvt_clean_exit(); 330 rxvt_clean_exit();
305 kill(getpid(), sig); 331 kill(getpid(), sig);
306} 332}
307 333
308/* ARGSUSED */
309/* EXTPROTO */ 334/* INTPROTO */
310int 335int
311rxvt_xerror_handler(const Display * display 336rxvt_xerror_handler (Display *display, XErrorEvent *event)
312 __attribute__ ((unused)), const XErrorEvent * event)
313{ 337{
314 if (GET_R->allowedxerror == -1) 338 if (GET_R->allowedxerror == -1)
315 GET_R->allowedxerror = event->error_code; 339 GET_R->allowedxerror = event->error_code;
316 else 340 else
317 { 341 {
318 rxvt_print_error("XError: Request: %d . %d, Error: %d", 342 old_xerror_handler (display, event);
319 event->request_code, event->minor_code,
320 event->error_code);
321
322 GET_R->destroy (); 343 GET_R->destroy ();
323 } 344 }
324 345
325 return 0; 346 return 0;
326} 347}
637 } 658 }
638 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 659 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
639 window_sb_x = szHint.width - sb_w; 660 window_sb_x = szHint.width - sb_w;
640 661
641 if (recalc_x) 662 if (recalc_x)
642 szHint.x += (DisplayWidth (Xdisplay, DefaultScreen (Xdisplay)) 663 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
643 - szHint.width - 2 * TermWin.ext_bwidth); 664 - szHint.width - 2 * TermWin.ext_bwidth);
644 if (recalc_y) 665 if (recalc_y)
645 szHint.y += (DisplayHeight (Xdisplay, DefaultScreen (Xdisplay)) 666 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display))
646 - szHint.height - 2 * TermWin.ext_bwidth); 667 - szHint.height - 2 * TermWin.ext_bwidth);
647 668
648 TermWin.ncol = TermWin.width / TermWin.fwidth; 669 TermWin.ncol = TermWin.width / TermWin.fwidth;
649 TermWin.nrow = TermWin.height / TermWin.fheight; 670 TermWin.nrow = TermWin.height / TermWin.fheight;
650 D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 671 D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
702/* xterm sequences - title, iconName, color (exptl) */ 723/* xterm sequences - title, iconName, color (exptl) */
703void 724void
704rxvt_term::set_title (const char *str) 725rxvt_term::set_title (const char *str)
705{ 726{
706#ifndef SMART_WINDOW_TITLE 727#ifndef SMART_WINDOW_TITLE
707 XStoreName(Xdisplay, TermWin.parent[0], str); 728 XStoreName(display->display, TermWin.parent[0], str);
708#else 729#else
709 char *name; 730 char *name;
710 731
711 if (XFetchName(Xdisplay, TermWin.parent[0], &name) == 0) 732 if (XFetchName(display->display, TermWin.parent[0], &name) == 0)
712 name = NULL; 733 name = NULL;
713 if (name == NULL || STRCMP(name, str)) 734 if (name == NULL || STRCMP(name, str))
714 XStoreName(Xdisplay, TermWin.parent[0], str); 735 XStoreName(display->display, TermWin.parent[0], str);
715 if (name) 736 if (name)
716 XFree(name); 737 XFree(name);
717#endif 738#endif
718} 739}
719 740
720void 741void
721rxvt_term::set_iconName (const char *str) 742rxvt_term::set_iconName (const char *str)
722{ 743{
723#ifndef SMART_WINDOW_TITLE 744#ifndef SMART_WINDOW_TITLE
724 XSetIconName(Xdisplay, TermWin.parent[0], str); 745 XSetIconName(display->display, TermWin.parent[0], str);
725#else 746#else
726 char *name; 747 char *name;
727 748
728 if (XGetIconName(Xdisplay, TermWin.parent[0], &name)) 749 if (XGetIconName(display->display, TermWin.parent[0], &name))
729 name = NULL; 750 name = NULL;
730 if (name == NULL || STRCMP(name, str)) 751 if (name == NULL || STRCMP(name, str))
731 XSetIconName(Xdisplay, TermWin.parent[0], str); 752 XSetIconName(display->display, TermWin.parent[0], str);
732 if (name) 753 if (name)
733 XFree(name); 754 XFree(name);
734#endif 755#endif
735} 756}
736 757
765 goto Done; 786 goto Done;
766 } 787 }
767 } 788 }
768 if (!rXParseAllocColor (& xcol, color)) 789 if (!rXParseAllocColor (& xcol, color))
769 return; 790 return;
770 /* XStoreColor (Xdisplay, XCMAP, XColor*); */ 791 /* XStoreColor (display->display, XCMAP, XColor*); */
771 792
772 /* 793 /*
773 * FIXME: should free colors here, but no idea how to do it so instead, 794 * FIXME: should free colors here, but no idea how to do it so instead,
774 * so just keep gobbling up the colormap 795 * so just keep gobbling up the colormap
775 */ 796 */
778 if (PixColors[idx] == PixColors[i]) 799 if (PixColors[idx] == PixColors[i])
779 break; 800 break;
780 if (i > Color_White) 801 if (i > Color_White)
781 { 802 {
782 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 803 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */
783 XFreeColors(Xdisplay, XCMAP, (PixColors + idx), 1, 804 XFreeColors(display->display, XCMAP, (PixColors + idx), 1,
784 DisplayPlanes(Xdisplay, Xscreen)); 805 DisplayPlanes(display->display, display->screen));
785 } 806 }
786# endif 807# endif
787 808
788 PixColors[idx] = xcol; 809 PixColors[idx] = xcol;
789 SET_PIXCOLOR(idx); 810 SET_PIXCOLOR(idx);
790 811
791 /* XSetWindowAttributes attr; */ 812 /* XSetWindowAttributes attr; */
792 /* Cursor cursor; */ 813 /* Cursor cursor; */
793Done: 814Done:
794 if (idx == Color_bg && !(Options & Opt_transparent)) 815 if (idx == Color_bg && !(Options & Opt_transparent))
795 XSetWindowBackground(Xdisplay, TermWin.vt, 816 XSetWindowBackground(display->display, TermWin.vt,
796 PixColors[Color_bg]); 817 PixColors[Color_bg]);
797 818
798 /* handle Color_BD, scrollbar background, etc. */ 819 /* handle Color_BD, scrollbar background, etc. */
799 820
800 set_colorfgbg (); 821 set_colorfgbg ();
813#if TODO 834#if TODO
814 rxvt_color xcol[2]; 835 rxvt_color xcol[2];
815 836
816 xcol[0] = PixColors[Color_pointer]; 837 xcol[0] = PixColors[Color_pointer];
817 xcol[1] = PixColors[Color_bg]; 838 xcol[1] = PixColors[Color_bg];
818 XQueryColors (Xdisplay, XCMAP, xcol, 2); 839 XQueryColors (display->display, XCMAP, xcol, 2);
819 XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); 840 XRecolorCursor (display->display, TermWin_cursor, &(xcol[0]), &(xcol[1]));
820#endif 841#endif
821} 842}
822 843
823/*----------------------------------------------------------------------*/ 844/*----------------------------------------------------------------------*/
824/* 845/*
872 */ 893 */
873 894
874int 895int
875rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 896rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
876{ 897{
877 if (!screen_in_out->set (this, colour)) 898 if (!screen_in_out->set (display, colour))
878 { 899 {
879 rxvt_print_error("can't allocate colour: %s", colour); 900 rxvt_print_error("can't allocate colour: %s", colour);
880 return false; 901 return false;
881 } 902 }
882 903
894#ifdef SMART_RESIZE 915#ifdef SMART_RESIZE
895 int old_width = szHint.width, old_height = szHint.height; 916 int old_width = szHint.width, old_height = szHint.height;
896#endif 917#endif
897 918
898 window_calc (width, height); 919 window_calc (width, height);
899 XSetWMNormalHints (Xdisplay, TermWin.parent[0], &szHint); 920 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
900 if (!ignoreparent) 921 if (!ignoreparent)
901 { 922 {
902#ifdef SMART_RESIZE 923#ifdef SMART_RESIZE
903 /* 924 /*
904 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 925 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
907 int x, y, x1, y1; 928 int x, y, x1, y1;
908 int dx, dy; 929 int dx, dy;
909 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 930 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
910 Window unused_cr; 931 Window unused_cr;
911 932
912 XTranslateCoordinates (Xdisplay, TermWin.parent[0], Xroot, 933 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
913 0, 0, &x, &y, &unused_cr); 934 0, 0, &x, &y, &unused_cr);
914 XGetGeometry (Xdisplay, TermWin.parent[0], &unused_cr, &x1, &y1, 935 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1,
915 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 936 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
916 /* 937 /*
917 * if Xroot isn't the parent window, a WM will probably have offset 938 * if display->root isn't the parent window, a WM will probably have offset
918 * our position for handles and decorations. Counter it 939 * our position for handles and decorations. Counter it
919 */ 940 */
920 if (x1 != x || y1 != y) 941 if (x1 != x || y1 != y)
921 { 942 {
922 x -= x1; 943 x -= x1;
923 y -= y1; 944 y -= y1;
924 } 945 }
925 946
926 x1 = (DisplayWidth (Xdisplay, Xscreen) - old_width) / 2; 947 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2;
927 y1 = (DisplayHeight (Xdisplay, Xscreen) - old_height) / 2; 948 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2;
928 dx = old_width - szHint.width; 949 dx = old_width - szHint.width;
929 dy = old_height - szHint.height; 950 dy = old_height - szHint.height;
930 951
931 /* Check position of the center of the window */ 952 /* Check position of the center of the window */
932 if (x < x1) /* left half */ 953 if (x < x1) /* left half */
936 if (y < y1) /* top half */ 957 if (y < y1) /* top half */
937 dy = 0; 958 dy = 0;
938 else if (y == y1) /* exact center */ 959 else if (y == y1) /* exact center */
939 dy /= 2; 960 dy /= 2;
940 961
941 XMoveResizeWindow (Xdisplay, TermWin.parent[0], x + dx, y + dy, 962 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
942 szHint.width, szHint.height); 963 szHint.width, szHint.height);
943#else 964#else
944 XResizeWindow (Xdisplay, TermWin.parent[0], szHint.width, 965 XResizeWindow (display->display, TermWin.parent[0], szHint.width,
945 szHint.height); 966 szHint.height);
946#endif 967#endif
947 968
948 } 969 }
949 970
952 973
953 if (fix_screen || width != old_width || height != old_height) 974 if (fix_screen || width != old_width || height != old_height)
954 { 975 {
955 if (scrollbar_visible ()) 976 if (scrollbar_visible ())
956 { 977 {
957 XMoveResizeWindow (Xdisplay, scrollBar.win, window_sb_x, 978 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x,
958 0, scrollbar_TotalWidth (), szHint.height); 979 0, scrollbar_TotalWidth (), szHint.height);
959 resize_scrollbar (); 980 resize_scrollbar ();
960 } 981 }
961 982
962 if (menubar_visible ()) 983 if (menubar_visible ())
963 XMoveResizeWindow (Xdisplay, menuBar.win, window_vt_x, 984 XMoveResizeWindow (display->display, menuBar.win, window_vt_x,
964 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 985 0, TermWin_TotalWidth (), menuBar_TotalHeight ());
965 986
966 XMoveResizeWindow (Xdisplay, TermWin.vt, window_vt_x, 987 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x,
967 window_vt_y, TermWin_TotalWidth (), 988 window_vt_y, TermWin_TotalWidth (),
968 TermWin_TotalHeight ()); 989 TermWin_TotalHeight ());
969#ifdef RXVT_GRAPHICS 990#ifdef RXVT_GRAPHICS
970 if (old_height) 991 if (old_height)
971 Gr_Resize (old_width - szHint.base_width, 992 Gr_Resize (old_width - szHint.base_width,
1018{ 1039{
1019 XWindowAttributes wattr; 1040 XWindowAttributes wattr;
1020 1041
1021 if (width == 0 || height == 0) 1042 if (width == 0 || height == 0)
1022 { 1043 {
1023 XGetWindowAttributes(Xdisplay, Xroot, &wattr); 1044 XGetWindowAttributes(display->display, display->root, &wattr);
1024 if (width == 0) 1045 if (width == 0)
1025 width = wattr.width - szHint.base_width; 1046 width = wattr.width - szHint.base_width;
1026 if (height == 0) 1047 if (height == 0)
1027 height = wattr.height - szHint.base_height; 1048 height = wattr.height - szHint.base_height;
1028 } 1049 }
1036 1057
1037/* -------------------------------------------------------------------- * 1058/* -------------------------------------------------------------------- *
1038 * - X INPUT METHOD ROUTINES - * 1059 * - X INPUT METHOD ROUTINES - *
1039 * -------------------------------------------------------------------- */ 1060 * -------------------------------------------------------------------- */
1040#ifdef USE_XIM 1061#ifdef USE_XIM
1062
1041void 1063void
1042rxvt_term::set_size (XRectangle *size) 1064rxvt_term::im_set_size (XRectangle *size)
1043{ 1065{
1044 size->x = TermWin.int_bwidth; 1066 size->x = TermWin.int_bwidth;
1045 size->y = TermWin.int_bwidth; 1067 size->y = TermWin.int_bwidth;
1046 size->width = Width2Pixel(TermWin.ncol); 1068 size->width = Width2Pixel(TermWin.ncol);
1047 size->height = Height2Pixel(TermWin.nrow); 1069 size->height = Height2Pixel(TermWin.nrow);
1048} 1070}
1049 1071
1050void 1072void
1051rxvt_term::set_color (unsigned long *fg, unsigned long *bg) 1073rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg)
1052{ 1074{
1053 *fg = PixColors[Color_fg]; 1075 *fg = PixColors[Color_fg];
1054 *bg = PixColors[Color_bg]; 1076 *bg = PixColors[Color_bg];
1055} 1077}
1056 1078
1069 STRCPY(server, "@server="); 1091 STRCPY(server, "@server=");
1070 STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1092 STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1071 if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ 1093 if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */
1072 *p = '\0'; 1094 *p = '\0';
1073 1095
1074 atom = XInternAtom(Xdisplay, server, False); 1096 atom = XInternAtom(display->display, server, False);
1075 win = XGetSelectionOwner(Xdisplay, atom); 1097 win = XGetSelectionOwner(display->display, atom);
1076 if (win != None) 1098 if (win != None)
1077 return True; 1099 return True;
1078 } 1100 }
1079 return False; 1101 return False;
1080} 1102}
1093 || event_type == SelectionNotify 1115 || event_type == SelectionNotify
1094 || event_type == ButtonRelease || event_type == FocusIn) 1116 || event_type == ButtonRelease || event_type == FocusIn)
1095 || !IMisRunning ()) 1117 || !IMisRunning ())
1096 return; 1118 return;
1097 1119
1098 set_position (&spot); 1120 im_set_position (&spot);
1099 1121
1100 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1122 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
1101 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1123 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1102 XFree(preedit_attr); 1124 XFree(preedit_attr);
1103} 1125}
1104 1126
1105void 1127void
1106rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, 1128rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1107 XRectangle * needed_rect) 1129 XRectangle * needed_rect)
1108{ 1130{
1109 int mbh, vtx = 0; 1131 int mbh, vtx = 0;
1110 1132
1111 if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) 1133 if (scrollbar_visible () && !(Options & Opt_scrollBar_right))
1112 vtx = scrollbar_TotalWidth(); 1134 vtx = scrollbar_TotalWidth();
1125 1147
1126 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); 1148 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1);
1127 status_rect->height = Height2Pixel(1); 1149 status_rect->height = Height2Pixel(1);
1128} 1150}
1129 1151
1130/* ARGSUSED */
1131/* EXTPROTO */
1132void 1152void
1133rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data 1153rxvt_term::im_destroy ()
1134 __attribute__ ((unused)), XPointer call_data
1135 __attribute__ ((unused)))
1136{ 1154{
1155 if (Input_Context)
1156 {
1157 XDestroyIC (Input_Context);
1137 GET_R->Input_Context = NULL; 1158 Input_Context = NULL;
1138 /* To avoid Segmentation Fault in C locale: Solaris only? */ 1159 }
1139 if (STRCMP (GET_R->locale, "C")) 1160
1140 XRegisterIMInstantiateCallback(GET_R->Xdisplay, NULL, NULL, NULL, 1161 if (input_method)
1141 rxvt_IMInstantiateCallback, NULL); 1162 {
1163 display->put_xim (input_method);
1164 input_method = 0;
1165 }
1142} 1166}
1143 1167
1144/* 1168/*
1145 * Try to open a XIM with the current modifiers, then see if we can 1169 * Try to open a XIM with the current modifiers, then see if we can
1146 * open a suitable preedit type 1170 * open a suitable preedit type
1147 */ 1171 */
1148bool 1172bool
1149rxvt_term::IM_get_IC () 1173rxvt_term::IM_get_IC (const char *modifiers)
1150{ 1174{
1151 int i, j, found; 1175 int i, j, found;
1152 XIM xim; 1176 XIM xim;
1153 XPoint spot; 1177 XPoint spot;
1154 XRectangle rect, status_rect, needed_rect; 1178 XRectangle rect, status_rect, needed_rect;
1155 unsigned long fg, bg; 1179 unsigned long fg, bg;
1156 const char *p; 1180 const char *p;
1157 char **s; 1181 char **s;
1158 XIMStyles *xim_styles; 1182 XIMStyles *xim_styles;
1159 XVaNestedList preedit_attr, status_attr; 1183 XVaNestedList preedit_attr, status_attr;
1160 XIMCallback ximcallback; 1184
1185 if (!((p = XSetLocaleModifiers (modifiers)) && *p))
1186 return false;
1161 1187
1162 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1188 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1163 xim = XOpenIM (Xdisplay, NULL, NULL, NULL); 1189 input_method = display->get_xim (locale, modifiers);
1164 if (xim == NULL) 1190 if (input_method == NULL)
1165 return False; 1191 return false;
1192
1193 xim = input_method->xim;
1166 1194
1167 xim_styles = NULL; 1195 xim_styles = NULL;
1168 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1196 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1169 || !xim_styles || !xim_styles->count_styles) 1197 || !xim_styles || !xim_styles->count_styles)
1170 { 1198 {
1171 XCloseIM(xim); 1199 display->put_xim (input_method);
1172 return False; 1200 return false;
1173 } 1201 }
1174 1202
1175 p = rs[Rs_preeditType] ? rs[Rs_preeditType] 1203 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1176 : "OverTheSpot,OffTheSpot,Root";
1177 s = rxvt_splitcommastring(p); 1204 s = rxvt_splitcommastring(p);
1178 for (i = found = 0; !found && s[i]; i++) 1205 for (i = found = 0; !found && s[i]; i++)
1179 { 1206 {
1180 if (!STRCMP(s[i], "OverTheSpot")) 1207 if (!STRCMP(s[i], "OverTheSpot"))
1181 input_style = (XIMPreeditPosition | XIMStatusNothing); 1208 input_style = (XIMPreeditPosition | XIMStatusNothing);
1189 { 1216 {
1190 found = 1; 1217 found = 1;
1191 break; 1218 break;
1192 } 1219 }
1193 } 1220 }
1221
1194 for (i = 0; s[i]; i++) 1222 for (i = 0; s[i]; i++)
1195 free(s[i]); 1223 free (s[i]);
1224
1196 free(s); 1225 free (s);
1197 XFree(xim_styles); 1226 XFree (xim_styles);
1198 1227
1199 if (!found) 1228 if (!found)
1200 { 1229 {
1201 XCloseIM(xim); 1230 display->put_xim (input_method);
1202 return False; 1231 return false;
1203 } 1232 }
1204
1205 ximcallback.callback = rxvt_IMDestroyCallback;
1206
1207 /* XXX: not sure why we need this (as well as IC one below) */
1208 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1209 1233
1210 preedit_attr = status_attr = NULL; 1234 preedit_attr = status_attr = NULL;
1211 1235
1212 if (input_style & XIMPreeditPosition) 1236 if (input_style & XIMPreeditPosition)
1213 { 1237 {
1214 set_size (&rect); 1238 im_set_size (&rect);
1215 set_position (&spot); 1239 im_set_position (&spot);
1216 set_color (&fg, &bg); 1240 im_set_color (&fg, &bg);
1217 1241
1218 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1242 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1219 XNSpotLocation, &spot, 1243 XNSpotLocation, &spot,
1220 XNForeground, fg, XNBackground, bg, 1244 XNForeground, fg, XNBackground, bg,
1221 //XNFontSet, TermWin.fontset, 1245 //XNFontSet, TermWin.fontset,
1222 NULL); 1246 NULL);
1223 } 1247 }
1224 else if (input_style & XIMPreeditArea) 1248 else if (input_style & XIMPreeditArea)
1225 { 1249 {
1226 set_color (&fg, &bg); 1250 im_set_color (&fg, &bg);
1227 1251
1228 /* 1252 /*
1229 * The necessary width of preedit area is unknown 1253 * The necessary width of preedit area is unknown
1230 * until create input context. 1254 * until create input context.
1231 */ 1255 */
1232 needed_rect.width = 0; 1256 needed_rect.width = 0;
1233 1257
1234 set_preedit_area(&rect, &status_rect, &needed_rect); 1258 im_set_preedit_area (&rect, &status_rect, &needed_rect);
1235 1259
1236 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1260 preedit_attr = XVaCreateNestedList(0, XNArea, &rect,
1237 XNForeground, fg, XNBackground, bg, 1261 XNForeground, fg, XNBackground, bg,
1238 //XNFontSet, TermWin.fontset, 1262 //XNFontSet, TermWin.fontset,
1239 NULL); 1263 NULL);
1240 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, 1264 status_attr = XVaCreateNestedList(0, XNArea, &status_rect,
1241 XNForeground, fg, XNBackground, bg, 1265 XNForeground, fg, XNBackground, bg,
1242 //XNFontSet, TermWin.fontset, 1266 //XNFontSet, TermWin.fontset,
1243 NULL); 1267 NULL);
1244 } 1268 }
1269
1245 Input_Context = XCreateIC(xim, XNInputStyle, input_style, 1270 Input_Context = XCreateIC(xim, XNInputStyle, input_style,
1246 XNClientWindow, TermWin.parent[0], 1271 XNClientWindow, TermWin.parent[0],
1247 XNFocusWindow, TermWin.parent[0], 1272 XNFocusWindow, TermWin.parent[0],
1248 XNDestroyCallback, &ximcallback,
1249 preedit_attr ? XNPreeditAttributes : NULL, 1273 preedit_attr ? XNPreeditAttributes : NULL,
1250 preedit_attr, 1274 preedit_attr,
1251 status_attr ? XNStatusAttributes : NULL, 1275 status_attr ? XNStatusAttributes : NULL,
1252 status_attr, NULL); 1276 status_attr, NULL);
1253 if (preedit_attr) 1277 if (preedit_attr) XFree(preedit_attr);
1254 XFree(preedit_attr); 1278 if (status_attr) XFree(status_attr);
1255 if (status_attr) 1279
1256 XFree(status_attr);
1257 if (Input_Context == NULL) 1280 if (Input_Context == NULL)
1258 { 1281 {
1259 rxvt_print_error("failed to create input context"); 1282 rxvt_print_error("failed to create input context");
1260 XCloseIM(xim); 1283 display->put_xim (input_method);
1261 return False; 1284 return false;
1262 } 1285 }
1286
1263 if (input_style & XIMPreeditArea) 1287 if (input_style & XIMPreeditArea)
1264 IMSetStatusPosition (); 1288 IMSetStatusPosition ();
1289
1265 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1290 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1266 return True; 1291 return true;
1267} 1292}
1268 1293
1269/*
1270 * X manual pages and include files don't match on some systems:
1271 * some think this is an XIDProc and others an XIMProc so we can't
1272 * use the first argument - need to update this to be nice for
1273 * both types via some sort of configure detection
1274 */
1275/* ARGSUSED */
1276/* EXTPROTO */
1277void 1294void
1278rxvt_IMInstantiateCallback(Display * unused 1295rxvt_term::im_cb ()
1279 __attribute__ ((unused)), XPointer client_data
1280 __attribute__ ((unused)), XPointer call_data
1281 __attribute__ ((unused)))
1282{ 1296{
1283 int i, found, had_im; 1297 int i, found, had_im;
1284 const char *p; 1298 const char *p;
1285 char **s; 1299 char **s;
1286 char buf[IMBUFSIZ]; 1300 char buf[IMBUFSIZ];
1287 1301
1302 im_destroy ();
1303
1288 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1304 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1289 if (GET_R->Input_Context) 1305 if (Input_Context)
1290 return; 1306 return;
1291 1307
1292#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1308#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1293 if (GET_R->rs[Rs_imLocale]) 1309 if (rs[Rs_imLocale])
1294 setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); 1310 setlocale (LC_CTYPE, rs[Rs_imLocale]);
1295#endif 1311#endif
1296 1312
1297 p = GET_R->rs[Rs_inputMethod]; 1313 p = rs[Rs_inputMethod];
1298 if (p && *p) 1314 if (p && *p)
1299 { 1315 {
1300 bool found = false; 1316 bool found = false;
1301 1317
1302 s = rxvt_splitcommastring (p); 1318 s = rxvt_splitcommastring (p);
1304 { 1320 {
1305 if (*s[i]) 1321 if (*s[i])
1306 { 1322 {
1307 STRCPY (buf, "@im="); 1323 STRCPY (buf, "@im=");
1308 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1324 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1309 if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) 1325 if (IM_get_IC (buf))
1310 { 1326 {
1311 found = true; 1327 found = true;
1312 break; 1328 break;
1313 } 1329 }
1314 } 1330 }
1320 if (found) 1336 if (found)
1321 goto done; 1337 goto done;
1322 } 1338 }
1323 1339
1324 /* try with XMODIFIERS env. var. */ 1340 /* try with XMODIFIERS env. var. */
1325 if ((p = XSetLocaleModifiers ("")) && *p 1341 if (IM_get_IC (""))
1326 && GET_R->IM_get_IC ())
1327 goto done; 1342 goto done;
1328 1343
1329 /* try with no modifiers base IF the user didn't specify an IM */ 1344 /* try with no modifiers base IF the user didn't specify an IM */
1330 if ((p = XSetLocaleModifiers ("@im=none")) && *p 1345 if (IM_get_IC ("@im=none"))
1331 && GET_R->IM_get_IC () == True)
1332 goto done; 1346 goto done;
1333 1347
1334done: 1348done:
1335#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1349#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1336 if (GET_R->rs[Rs_imLocale]) 1350 if (rs[Rs_imLocale])
1337 setlocale (LC_CTYPE, GET_R->locale); 1351 setlocale (LC_CTYPE, locale);
1338#endif 1352#endif
1339} 1353}
1340 1354
1341void 1355void
1342rxvt_term::IMSetStatusPosition () 1356rxvt_term::IMSetStatusPosition ()
1352 /* Getting the necessary width of preedit area */ 1366 /* Getting the necessary width of preedit area */
1353 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); 1367 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL);
1354 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); 1368 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL);
1355 XFree(status_attr); 1369 XFree(status_attr);
1356 1370
1357 set_preedit_area(&preedit_rect, &status_rect, needed_rect); 1371 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect);
1358 1372
1359 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); 1373 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL);
1360 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); 1374 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL);
1361 1375
1362 XSetICValues(Input_Context, 1376 XSetICValues(Input_Context,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines