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.8 by pcg, Thu Nov 27 10:12:10 2003 UTC vs.
Revision 1.16 by pcg, Thu Dec 18 07:31:19 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.8 2003/11/27 10:12:10 pcg Exp $ 4 * $Id: main.C,v 1.16 2003/12/18 07:31:19 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
42 42
43#ifdef HAVE_TERMIOS_H 43#ifdef HAVE_TERMIOS_H
44# include <termios.h> 44# include <termios.h>
45#endif 45#endif
46 46
47#include <cstring>
48
49static char curlocale[128];
50
51void
52rxvt_set_locale (const char *locale)
53{
54 if (locale && STRNCMP (locale, curlocale, 128))
55 {
56 STRNCPY (curlocale, locale, 128);
57 setlocale (LC_CTYPE, curlocale);
58 }
59}
60
47void * 61void *
48rxvt_term::operator new (size_t s) 62rxvt_term::operator new (size_t s)
49{ 63{
50 void *p = malloc (s); 64 void *p = malloc (s);
51 65
66#endif 80#endif
67#ifdef POINTER_BLANK 81#ifdef POINTER_BLANK
68 pointer_ev (this, &rxvt_term::pointer_cb), 82 pointer_ev (this, &rxvt_term::pointer_cb),
69#endif 83#endif
70 x_ev (this, &rxvt_term::x_cb), 84 x_ev (this, &rxvt_term::x_cb),
71 destroy_ev (this, &rxvt_term::destroy_cb) 85 destroy_ev (this, &rxvt_term::destroy_cb),
86 check_ev (this, &rxvt_term::check_cb),
87 incr_ev (this, &rxvt_term::incr_cb)
72{ 88{
73 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 89 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
74} 90}
75 91
76rxvt_term::~rxvt_term () 92rxvt_term::~rxvt_term ()
77{ 93{
78 rxvt_scr_release (this); 94 scr_release ();
95
96 free (locale);
97 free (codeset);
79 98
80#ifndef NO_SETOWNER_TTYDEV 99#ifndef NO_SETOWNER_TTYDEV
81 rxvt_privileged_ttydev (this, RESTORE); 100 rxvt_privileged_ttydev (this, RESTORE);
82#endif 101#endif
83#ifdef UTMP_SUPPORT 102#ifdef UTMP_SUPPORT
101} 120}
102 121
103void 122void
104rxvt_term::destroy () 123rxvt_term::destroy ()
105{ 124{
125 check_ev.stop ();
106 pty_ev.stop (); 126 pty_ev.stop ();
107 x_ev.stop (); 127 x_ev.stop ();
108#ifdef CURSOR_BLINK 128#ifdef CURSOR_BLINK
109 blink_ev.stop (); 129 blink_ev.stop ();
110#endif 130#endif
125 145
126/*----------------------------------------------------------------------*/ 146/*----------------------------------------------------------------------*/
127/* rxvt_init() */ 147/* rxvt_init() */
128/* LIBPROTO */ 148/* LIBPROTO */
129rxvt_t 149rxvt_t
130rxvt_init(int argc, const char *const *argv) 150rxvt_init (int argc, const char *const *argv)
131{ 151{
132 SET_R(new rxvt_term); 152 SET_R (new rxvt_term);
133 dR; 153 dR;
134 154
135 if (!R->init_vars () || !R->init (argc, argv)) 155 if (!R->init_vars () || !R->init (argc, argv))
136 { 156 {
137 delete R; 157 delete R;
148/* install exit handler for cleanup */ 168/* install exit handler for cleanup */
149#if 0 169#if 0
150#ifdef HAVE_ATEXIT 170#ifdef HAVE_ATEXIT
151 atexit(rxvt_clean_exit); 171 atexit(rxvt_clean_exit);
152#else 172#else
153# ifdef HAVE_ON_EXIT
154 on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */
155# endif
156#endif 173#endif
157#endif 174#endif
158 175
159 struct sigaction sa; 176 struct sigaction sa;
160 177
161 sigfillset (&sa.sa_mask); 178 sigfillset (&sa.sa_mask);
162 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; 179 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
163 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGHUP , &sa, 0); //TODO, also: SIGPIPE 180 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
181 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
164 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); 182 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
165 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); 183 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
166 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); 184 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
167 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); 185 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
168 186
174} 192}
175 193
176bool 194bool
177rxvt_term::init (int argc, const char *const *argv) 195rxvt_term::init (int argc, const char *const *argv)
178{ 196{
179 dR;//TODO (scrollbar, setidle)
180
181 /* 197 /*
182 * Save and then give up any super-user privileges 198 * Save and then give up any super-user privileges
183 * If we need privileges in any area then we must specifically request it. 199 * If we need privileges in any area then we must specifically request it.
184 * We should only need to be root in these cases: 200 * We should only need to be root in these cases:
185 * 1. write utmp entries on some systems 201 * 1. write utmp entries on some systems
186 * 2. chown tty on some systems 202 * 2. chown tty on some systems
187 */ 203 */
188 rxvt_privileges (this, SAVE); 204 rxvt_privileges (this, SAVE);
189 rxvt_privileges (this, IGNORE); 205 rxvt_privileges (this, IGNORE);
190 206
191 rxvt_init_secondary (this); 207 init_secondary ();
192 208
193 const char **cmd_argv = rxvt_init_resources (this, argc, argv); 209 const char **cmd_argv = init_resources (argc, argv);
210
211 set_locale ("");
194 212
195#if (MENUBAR_MAX) 213#if (MENUBAR_MAX)
196 rxvt_menubar_read (this, rs[Rs_menu]); 214 rxvt_menubar_read (this, rs[Rs_menu]);
197#endif 215#endif
198#ifdef HAVE_SCROLLBARS 216#ifdef HAVE_SCROLLBARS
199 if (Options & Opt_scrollBar) 217 if (Options & Opt_scrollBar)
200 scrollbar_setIdle (); /* set existence for size calculations */ 218 scrollBar.setIdle (); /* set existence for size calculations */
201#endif 219#endif
202 220
203 rxvt_Create_Windows (this, argc, argv); 221 rxvt_Create_Windows (this, argc, argv);
204 222
205 rxvt_init_xlocale (this); 223 init_xlocale ();
206 224
207 rxvt_scr_reset (this); /* initialize screen */ 225 scr_reset (); /* initialize screen */
208#ifdef RXVT_GRAPHICS 226#ifdef RXVT_GRAPHICS
209 rxvt_Gr_reset (this); /* reset graphics */ 227 rxvt_Gr_reset (this); /* reset graphics */
210#endif 228#endif
211 229
212#if 0 230#if 0
231 } 249 }
232#endif 250#endif
233 XMapWindow (Xdisplay, TermWin.vt); 251 XMapWindow (Xdisplay, TermWin.vt);
234 XMapWindow (Xdisplay, TermWin.parent[0]); 252 XMapWindow (Xdisplay, TermWin.parent[0]);
235 253
236 rxvt_init_env (this); 254 init_env ();
237 rxvt_init_command (this, cmd_argv); 255 init_command (cmd_argv);
238 256
239 x_ev.start (Xfd, EVENT_READ); 257 x_ev.start (Xfd, EVENT_READ);
240 pty_ev.start (cmd_fd, EVENT_READ); 258 pty_ev.start (cmd_fd, EVENT_READ);
241 259
242 flush (); 260 check_ev.start ();
261
262 process_x_events ();
243 263
244 return true; 264 return true;
245} 265}
246 266
247/* ------------------------------------------------------------------------- * 267/* ------------------------------------------------------------------------- *
614/*----------------------------------------------------------------------*/ 634/*----------------------------------------------------------------------*/
615/* 635/*
616 * Tell the teletype handler what size the window is. 636 * Tell the teletype handler what size the window is.
617 * Called after a window size change. 637 * Called after a window size change.
618 */ 638 */
619/* EXTPROTO */
620void 639void
621rxvt_tt_winsize(int fd, unsigned short col, unsigned short row, int pid) 640rxvt_term::tt_winch ()
622{ 641{
623 struct winsize ws; 642 struct winsize ws;
624 643
625 if (fd < 0) 644 if (cmd_fd < 0)
626 return; 645 return;
646
627 ws.ws_col = col; 647 ws.ws_col = TermWin.ncol;
628 ws.ws_row = row; 648 ws.ws_row = TermWin.nrow;
629 ws.ws_xpixel = ws.ws_ypixel = 0; 649 ws.ws_xpixel = ws.ws_ypixel = 0;
630#ifndef DEBUG_SIZE 650#ifndef DEBUG_SIZE
631 (void)ioctl(fd, TIOCSWINSZ, &ws); 651 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
632#else 652#else
633 if (ioctl(fd, TIOCSWINSZ, &ws) < 0) { 653 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
634 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 654 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
635 }
636# ifdef SIGWINCH 655# ifdef SIGWINCH
637 else if (pid) /* force through to the command */ 656 else if (cmd_pid) /* force through to the command */
638 kill(pid, SIGWINCH); 657 kill (cmd_pid, SIGWINCH);
639# endif 658# endif
640#endif 659#endif
641} 660}
642 661
643/*----------------------------------------------------------------------*/ 662/*----------------------------------------------------------------------*/
756 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, 775 XSetWindowBackground(R->Xdisplay, R->TermWin.vt,
757 R->PixColors[Color_bg]); 776 R->PixColors[Color_bg]);
758 777
759/* handle Color_BD, scrollbar background, etc. */ 778/* handle Color_BD, scrollbar background, etc. */
760 779
761 rxvt_set_colorfgbg(aR); 780 rxvt_set_colorfgbg (aR);
762 rxvt_recolour_cursor(aR); 781 R->recolour_cursor ();
763/* the only reasonable way to enforce a clean update */ 782/* the only reasonable way to enforce a clean update */
764 rxvt_scr_poweron(aR); 783 rxvt_scr_poweron (aR);
765} 784}
766 785
767#else 786#else
768# define rxvt_set_window_color(aR_ idx,color) ((void)0) 787# define rxvt_set_window_color(aR_ idx,color) ((void)0)
769#endif /* XTERM_COLOR_CHANGE */ 788#endif /* XTERM_COLOR_CHANGE */
770 789
771/* EXTPROTO */
772void 790void
773rxvt_recolour_cursor(pR) 791rxvt_term::recolour_cursor ()
774{ 792{
775 rxvt_color xcol[2];
776
777#if TODO 793#if TODO
794 rxvt_color xcol[2];
795
778 xcol[0] = R->PixColors[Color_pointer]; 796 xcol[0] = PixColors[Color_pointer];
779 xcol[1] = R->PixColors[Color_bg]; 797 xcol[1] = PixColors[Color_bg];
780 XQueryColors(R->Xdisplay, XCMAP, xcol, 2); 798 XQueryColors (Xdisplay, XCMAP, xcol, 2);
781 XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); 799 XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1]));
782#endif 800#endif
783} 801}
784 802
785/*----------------------------------------------------------------------*/ 803/*----------------------------------------------------------------------*/
786/* 804/*
938 uint16_t old_ncol = R->prev_ncol; 956 uint16_t old_ncol = R->prev_ncol;
939 957
940 /* scr_reset only works on the primary screen */ 958 /* scr_reset only works on the primary screen */
941 if (R->old_height) /* this is not the first time through */ 959 if (R->old_height) /* this is not the first time through */
942 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); 960 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY);
961
943 rxvt_scr_reset(aR); 962 R->scr_reset();
963
944 if (curr_screen >= 0) { /* this is not the first time through */ 964 if (curr_screen >= 0) { /* this is not the first time through */
945 rxvt_scr_change_screen(aR_ curr_screen); 965 rxvt_scr_change_screen(aR_ curr_screen);
946 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); 966 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0));
947 } 967 }
948 } 968 }
1048 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1068 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
1049 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1069 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1050 XFree(preedit_attr); 1070 XFree(preedit_attr);
1051} 1071}
1052 1072
1053/* EXTPROTO */
1054void
1055rxvt_setTermFontSet(pR_ int idx)
1056{
1057 char *string;
1058 long length;
1059 int success = 0;
1060
1061 if (idx < 0 || idx >= MAX_NFONTS)
1062 return;
1063}
1064
1065/* INTPROTO */ 1073/* INTPROTO */
1066void 1074void
1067rxvt_setPreeditArea(pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1075rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1068 XRectangle * needed_rect) 1076 XRectangle * needed_rect)
1069{ 1077{
1070 int mbh, vtx = 0; 1078 int mbh, vtx = 0;
1071 1079
1072 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right)) 1080 if (scrollbar_visible(R) && !(R->Options & Opt_scrollBar_right))
1073 vtx = scrollbar_TotalWidth(); 1081 vtx = scrollbar_TotalWidth();
1104 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, 1112 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL,
1105 rxvt_IMInstantiateCallback, NULL); 1113 rxvt_IMInstantiateCallback, NULL);
1106} 1114}
1107 1115
1108/* 1116/*
1109 * X manual pages and include files don't match on some systems:
1110 * some think this is an XIDProc and others an XIMProc so we can't
1111 * use the first argument - need to update this to be nice for
1112 * both types via some sort of configure detection
1113 */
1114/* ARGSUSED */
1115/* EXTPROTO */
1116void
1117rxvt_IMInstantiateCallback(Display * unused
1118 __attribute__ ((unused)), XPointer client_data
1119 __attribute__ ((unused)), XPointer call_data
1120 __attribute__ ((unused)))
1121{
1122 dR;
1123 int i, found, had_im;
1124 const char *p;
1125 char **s;
1126 char buf[IMBUFSIZ];
1127
1128 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1129 if (R->Input_Context)
1130 return;
1131
1132 found = had_im = 0;
1133 p = R->rs[Rs_inputMethod];
1134 if (p && *p) {
1135 had_im = 1;
1136 s = rxvt_splitcommastring(p);
1137 for (i = 0; s[i]; i++) {
1138 if (*s[i]) {
1139 STRCPY(buf, "@im=");
1140 STRNCAT(buf, s[i], IMBUFSIZ - 5);
1141 if ((p = XSetLocaleModifiers(buf)) != NULL && *p
1142 && (rxvt_IM_get_IC(aR) == True)) {
1143 found = 1;
1144 break;
1145 }
1146 }
1147 }
1148 for (i = 0; s[i]; i++)
1149 free(s[i]);
1150 free(s);
1151 }
1152 if (found)
1153 return;
1154
1155/* try with XMODIFIERS env. var. */
1156 if ((p = XSetLocaleModifiers("")) != NULL && *p) {
1157 rxvt_IM_get_IC(aR);
1158 return;
1159 }
1160
1161/* try with no modifiers base IF the user didn't specify an IM */
1162 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p
1163 && rxvt_IM_get_IC(aR) == True)
1164 return;
1165}
1166
1167/*
1168 * Try to open a XIM with the current modifiers, then see if we can 1117 * Try to open a XIM with the current modifiers, then see if we can
1169 * open a suitable preedit type 1118 * open a suitable preedit type
1170 */ 1119 */
1171/* INTPROTO */ 1120static Bool
1172Bool
1173rxvt_IM_get_IC(pR) 1121rxvt_IM_get_IC (pR)
1174{ 1122{
1175 int i, j, found; 1123 int i, j, found;
1176 XIM xim; 1124 XIM xim;
1177 XPoint spot; 1125 XPoint spot;
1178 XRectangle rect, status_rect, needed_rect; 1126 XRectangle rect, status_rect, needed_rect;
1182 XIMStyles *xim_styles; 1130 XIMStyles *xim_styles;
1183 XVaNestedList preedit_attr, status_attr; 1131 XVaNestedList preedit_attr, status_attr;
1184 XIMCallback ximcallback; 1132 XIMCallback ximcallback;
1185 1133
1186 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1134 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1187 xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); 1135 xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL);
1188 if (xim == NULL) 1136 if (xim == NULL)
1189 return False; 1137 return False;
1190 1138
1191 xim_styles = NULL; 1139 xim_styles = NULL;
1192 if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) 1140 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1193 || !xim_styles || !xim_styles->count_styles) { 1141 || !xim_styles || !xim_styles->count_styles) {
1194 XCloseIM(xim); 1142 XCloseIM(xim);
1195 return False; 1143 return False;
1196 } 1144 }
1197 1145
1222 return False; 1170 return False;
1223 } 1171 }
1224 1172
1225 ximcallback.callback = rxvt_IMDestroyCallback; 1173 ximcallback.callback = rxvt_IMDestroyCallback;
1226 1174
1227/* XXX: not sure why we need this (as well as IC one below) */ 1175 /* XXX: not sure why we need this (as well as IC one below) */
1228 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); 1176 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1229 1177
1230 preedit_attr = status_attr = NULL; 1178 preedit_attr = status_attr = NULL;
1231 1179
1232 if (R->input_style & XIMPreeditPosition) { 1180 if (R->input_style & XIMPreeditPosition) {
1280 rxvt_IMSetStatusPosition(aR); 1228 rxvt_IMSetStatusPosition(aR);
1281 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1229 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1282 return True; 1230 return True;
1283} 1231}
1284 1232
1233/*
1234 * X manual pages and include files don't match on some systems:
1235 * some think this is an XIDProc and others an XIMProc so we can't
1236 * use the first argument - need to update this to be nice for
1237 * both types via some sort of configure detection
1238 */
1239/* ARGSUSED */
1240/* EXTPROTO */
1241void
1242rxvt_IMInstantiateCallback(Display * unused
1243 __attribute__ ((unused)), XPointer client_data
1244 __attribute__ ((unused)), XPointer call_data
1245 __attribute__ ((unused)))
1246{
1247 dR;
1248 int i, found, had_im;
1249 const char *p;
1250 char **s;
1251 char buf[IMBUFSIZ];
1252
1253 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1254 if (R->Input_Context)
1255 return;
1256
1257#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1258 if (R->rs[Rs_imLocale])
1259 setlocale (LC_CTYPE, R->rs[Rs_imLocale]);
1260#endif
1261
1262 p = R->rs[Rs_inputMethod];
1263 if (p && *p)
1264 {
1265 bool found = false;
1266
1267 s = rxvt_splitcommastring (p);
1268 for (i = 0; s[i]; i++)
1269 {
1270 if (*s[i])
1271 {
1272 STRCPY (buf, "@im=");
1273 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1274 if ((p = XSetLocaleModifiers (buf)) && *p
1275 && rxvt_IM_get_IC (aR))
1276 {
1277 found = true;
1278 break;
1279 }
1280 }
1281 }
1282 for (i = 0; s[i]; i++)
1283 free(s[i]);
1284 free(s);
1285
1286 if (found)
1287 goto done;
1288 }
1289
1290/* try with XMODIFIERS env. var. */
1291 if ((p = XSetLocaleModifiers ("")) && *p
1292 && rxvt_IM_get_IC (aR))
1293 goto done;
1294
1295/* try with no modifiers base IF the user didn't specify an IM */
1296 if ((p = XSetLocaleModifiers ("@im=none")) && *p
1297 && rxvt_IM_get_IC (aR) == True)
1298 goto done;
1299
1300done:
1301#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1302 if (R->rs[Rs_imLocale])
1303 setlocale (LC_CTYPE, R->locale);
1304#endif
1305}
1306
1285/* EXTPROTO */ 1307/* EXTPROTO */
1286void 1308void
1287rxvt_IMSetStatusPosition(pR) 1309rxvt_IMSetStatusPosition(pR)
1288{ 1310{
1289 XRectangle preedit_rect, status_rect, *needed_rect; 1311 XRectangle preedit_rect, status_rect, *needed_rect;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines