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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines