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.9 by pcg, Tue Dec 2 21:49:46 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.9 2003/12/02 21:49:46 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
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),
72 check_ev (this, &rxvt_term::check_cb) 86 check_ev (this, &rxvt_term::check_cb),
87 incr_ev (this, &rxvt_term::incr_cb)
73{ 88{
74 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 89 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
75} 90}
76 91
77rxvt_term::~rxvt_term () 92rxvt_term::~rxvt_term ()
78{ 93{
79 rxvt_scr_release (this); 94 scr_release ();
95
96 free (locale);
97 free (codeset);
80 98
81#ifndef NO_SETOWNER_TTYDEV 99#ifndef NO_SETOWNER_TTYDEV
82 rxvt_privileged_ttydev (this, RESTORE); 100 rxvt_privileged_ttydev (this, RESTORE);
83#endif 101#endif
84#ifdef UTMP_SUPPORT 102#ifdef UTMP_SUPPORT
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 check_ev.start (); 260 check_ev.start ();
261
262 process_x_events ();
243 263
244 return true; 264 return true;
245} 265}
246 266
247/* ------------------------------------------------------------------------- * 267/* ------------------------------------------------------------------------- *
755 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, 775 XSetWindowBackground(R->Xdisplay, R->TermWin.vt,
756 R->PixColors[Color_bg]); 776 R->PixColors[Color_bg]);
757 777
758/* handle Color_BD, scrollbar background, etc. */ 778/* handle Color_BD, scrollbar background, etc. */
759 779
760 rxvt_set_colorfgbg(aR); 780 rxvt_set_colorfgbg (aR);
761 rxvt_recolour_cursor(aR); 781 R->recolour_cursor ();
762/* the only reasonable way to enforce a clean update */ 782/* the only reasonable way to enforce a clean update */
763 rxvt_scr_poweron(aR); 783 rxvt_scr_poweron (aR);
764} 784}
765 785
766#else 786#else
767# define rxvt_set_window_color(aR_ idx,color) ((void)0) 787# define rxvt_set_window_color(aR_ idx,color) ((void)0)
768#endif /* XTERM_COLOR_CHANGE */ 788#endif /* XTERM_COLOR_CHANGE */
769 789
770/* EXTPROTO */
771void 790void
772rxvt_recolour_cursor(pR) 791rxvt_term::recolour_cursor ()
773{ 792{
774 rxvt_color xcol[2];
775
776#if TODO 793#if TODO
794 rxvt_color xcol[2];
795
777 xcol[0] = R->PixColors[Color_pointer]; 796 xcol[0] = PixColors[Color_pointer];
778 xcol[1] = R->PixColors[Color_bg]; 797 xcol[1] = PixColors[Color_bg];
779 XQueryColors(R->Xdisplay, XCMAP, xcol, 2); 798 XQueryColors (Xdisplay, XCMAP, xcol, 2);
780 XRecolorCursor(R->Xdisplay, R->TermWin_cursor, &(xcol[0]), &(xcol[1])); 799 XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1]));
781#endif 800#endif
782} 801}
783 802
784/*----------------------------------------------------------------------*/ 803/*----------------------------------------------------------------------*/
785/* 804/*
937 uint16_t old_ncol = R->prev_ncol; 956 uint16_t old_ncol = R->prev_ncol;
938 957
939 /* scr_reset only works on the primary screen */ 958 /* scr_reset only works on the primary screen */
940 if (R->old_height) /* this is not the first time through */ 959 if (R->old_height) /* this is not the first time through */
941 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY); 960 curr_screen = rxvt_scr_change_screen(aR_ PRIMARY);
961
942 rxvt_scr_reset(aR); 962 R->scr_reset();
963
943 if (curr_screen >= 0) { /* this is not the first time through */ 964 if (curr_screen >= 0) { /* this is not the first time through */
944 rxvt_scr_change_screen(aR_ curr_screen); 965 rxvt_scr_change_screen(aR_ curr_screen);
945 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0)); 966 rxvt_selection_check(aR_(old_ncol != R->TermWin.ncol ? 4 : 0));
946 } 967 }
947 } 968 }
1047 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1068 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
1048 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1069 XSetICValues(R->Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1049 XFree(preedit_attr); 1070 XFree(preedit_attr);
1050} 1071}
1051 1072
1052/* EXTPROTO */
1053void
1054rxvt_setTermFontSet(pR_ int idx)
1055{
1056 char *string;
1057 long length;
1058 int success = 0;
1059
1060 if (idx < 0 || idx >= MAX_NFONTS)
1061 return;
1062}
1063
1064/* INTPROTO */ 1073/* INTPROTO */
1065void 1074void
1066rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect, 1075rxvt_setPreeditArea (pR_ XRectangle * preedit_rect, XRectangle * status_rect,
1067 XRectangle * needed_rect) 1076 XRectangle * needed_rect)
1068{ 1077{
1103 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL, 1112 XRegisterIMInstantiateCallback(R->Xdisplay, NULL, NULL, NULL,
1104 rxvt_IMInstantiateCallback, NULL); 1113 rxvt_IMInstantiateCallback, NULL);
1105} 1114}
1106 1115
1107/* 1116/*
1108 * X manual pages and include files don't match on some systems:
1109 * some think this is an XIDProc and others an XIMProc so we can't
1110 * use the first argument - need to update this to be nice for
1111 * both types via some sort of configure detection
1112 */
1113/* ARGSUSED */
1114/* EXTPROTO */
1115void
1116rxvt_IMInstantiateCallback(Display * unused
1117 __attribute__ ((unused)), XPointer client_data
1118 __attribute__ ((unused)), XPointer call_data
1119 __attribute__ ((unused)))
1120{
1121 dR;
1122 int i, found, had_im;
1123 const char *p;
1124 char **s;
1125 char buf[IMBUFSIZ];
1126
1127 D_MAIN((stderr, "rxvt_IMInstantiateCallback()"));
1128 if (R->Input_Context)
1129 return;
1130
1131 found = had_im = 0;
1132 p = R->rs[Rs_inputMethod];
1133 if (p && *p) {
1134 had_im = 1;
1135 s = rxvt_splitcommastring(p);
1136 for (i = 0; s[i]; i++) {
1137 if (*s[i]) {
1138 STRCPY(buf, "@im=");
1139 STRNCAT(buf, s[i], IMBUFSIZ - 5);
1140 if ((p = XSetLocaleModifiers(buf)) != NULL && *p
1141 && (rxvt_IM_get_IC(aR) == True)) {
1142 found = 1;
1143 break;
1144 }
1145 }
1146 }
1147 for (i = 0; s[i]; i++)
1148 free(s[i]);
1149 free(s);
1150 }
1151 if (found)
1152 return;
1153
1154/* try with XMODIFIERS env. var. */
1155 if ((p = XSetLocaleModifiers("")) != NULL && *p) {
1156 rxvt_IM_get_IC(aR);
1157 return;
1158 }
1159
1160/* try with no modifiers base IF the user didn't specify an IM */
1161 if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p
1162 && rxvt_IM_get_IC(aR) == True)
1163 return;
1164}
1165
1166/*
1167 * 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
1168 * open a suitable preedit type 1118 * open a suitable preedit type
1169 */ 1119 */
1170/* INTPROTO */ 1120static Bool
1171Bool
1172rxvt_IM_get_IC(pR) 1121rxvt_IM_get_IC (pR)
1173{ 1122{
1174 int i, j, found; 1123 int i, j, found;
1175 XIM xim; 1124 XIM xim;
1176 XPoint spot; 1125 XPoint spot;
1177 XRectangle rect, status_rect, needed_rect; 1126 XRectangle rect, status_rect, needed_rect;
1181 XIMStyles *xim_styles; 1130 XIMStyles *xim_styles;
1182 XVaNestedList preedit_attr, status_attr; 1131 XVaNestedList preedit_attr, status_attr;
1183 XIMCallback ximcallback; 1132 XIMCallback ximcallback;
1184 1133
1185 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1134 D_MAIN((stderr, "rxvt_IM_get_IC()"));
1186 xim = XOpenIM(R->Xdisplay, NULL, NULL, NULL); 1135 xim = XOpenIM (R->Xdisplay, NULL, NULL, NULL);
1187 if (xim == NULL) 1136 if (xim == NULL)
1188 return False; 1137 return False;
1189 1138
1190 xim_styles = NULL; 1139 xim_styles = NULL;
1191 if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) 1140 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1192 || !xim_styles || !xim_styles->count_styles) { 1141 || !xim_styles || !xim_styles->count_styles) {
1193 XCloseIM(xim); 1142 XCloseIM(xim);
1194 return False; 1143 return False;
1195 } 1144 }
1196 1145
1221 return False; 1170 return False;
1222 } 1171 }
1223 1172
1224 ximcallback.callback = rxvt_IMDestroyCallback; 1173 ximcallback.callback = rxvt_IMDestroyCallback;
1225 1174
1226/* 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) */
1227 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); 1176 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1228 1177
1229 preedit_attr = status_attr = NULL; 1178 preedit_attr = status_attr = NULL;
1230 1179
1231 if (R->input_style & XIMPreeditPosition) { 1180 if (R->input_style & XIMPreeditPosition) {
1279 rxvt_IMSetStatusPosition(aR); 1228 rxvt_IMSetStatusPosition(aR);
1280 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1229 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection"));
1281 return True; 1230 return True;
1282} 1231}
1283 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
1284/* EXTPROTO */ 1307/* EXTPROTO */
1285void 1308void
1286rxvt_IMSetStatusPosition(pR) 1309rxvt_IMSetStatusPosition(pR)
1287{ 1310{
1288 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