1 |
ayin |
1.195 |
/*----------------------------------------------------------------------* |
2 |
pcg |
1.50 |
* File: init.C |
3 |
pcg |
1.1 |
*----------------------------------------------------------------------* |
4 |
|
|
* |
5 |
|
|
* All portions of code are copyright by their respective author/s. |
6 |
|
|
* Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 |
pcg |
1.4 |
* - original version |
8 |
pcg |
1.1 |
* Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 |
pcg |
1.4 |
* - extensive modifications |
10 |
ayin |
1.214 |
* Copyright (c) 1996 Chuck Blake <cblake@BBN.COM> |
11 |
|
|
* Copyright (c) 1997 mj olesen <olesen@me.queensu.ca> |
12 |
|
|
* Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
13 |
pcg |
1.1 |
* Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
14 |
pcg |
1.4 |
* - extensive modifications |
15 |
pcg |
1.1 |
* Copyright (c) 1999 D J Hawkey Jr <hawkeyd@visi.com> |
16 |
pcg |
1.4 |
* - QNX support |
17 |
root |
1.134 |
* Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
18 |
pcg |
1.1 |
* |
19 |
|
|
* This program is free software; you can redistribute it and/or modify |
20 |
|
|
* it under the terms of the GNU General Public License as published by |
21 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
22 |
|
|
* (at your option) any later version. |
23 |
|
|
* |
24 |
|
|
* This program is distributed in the hope that it will be useful, |
25 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 |
|
|
* GNU General Public License for more details. |
28 |
|
|
* |
29 |
|
|
* You should have received a copy of the GNU General Public License |
30 |
|
|
* along with this program; if not, write to the Free Software |
31 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
32 |
|
|
*---------------------------------------------------------------------*/ |
33 |
|
|
/* |
34 |
|
|
* Initialisation routines. |
35 |
|
|
*/ |
36 |
|
|
|
37 |
pcg |
1.4 |
#include "../config.h" /* NECESSARY */ |
38 |
|
|
#include "rxvt.h" /* NECESSARY */ |
39 |
root |
1.105 |
#include "rxvtutil.h" |
40 |
pcg |
1.1 |
#include "init.h" |
41 |
|
|
|
42 |
root |
1.125 |
#include <limits> |
43 |
|
|
|
44 |
root |
1.99 |
#include <csignal> |
45 |
pcg |
1.1 |
|
46 |
ayin |
1.226 |
#include <fcntl.h> |
47 |
|
|
|
48 |
ayin |
1.218 |
#ifdef HAVE_XSETLOCALE |
49 |
|
|
# define X_LOCALE |
50 |
|
|
# include <X11/Xlocale.h> |
51 |
|
|
#else |
52 |
|
|
# ifdef HAVE_SETLOCALE |
53 |
|
|
# include <clocale> |
54 |
|
|
# endif |
55 |
|
|
#endif |
56 |
|
|
|
57 |
|
|
#ifdef HAVE_NL_LANGINFO |
58 |
|
|
# include <langinfo.h> |
59 |
|
|
#endif |
60 |
|
|
|
61 |
ayin |
1.214 |
#ifdef DISPLAY_IS_IP |
62 |
|
|
/* On Solaris link with -lsocket and -lnsl */ |
63 |
|
|
#include <sys/types.h> |
64 |
|
|
#include <sys/socket.h> |
65 |
|
|
|
66 |
|
|
/* these next two are probably only on Sun (not Solaris) */ |
67 |
|
|
#ifdef HAVE_SYS_SOCKIO_H |
68 |
|
|
#include <sys/sockio.h> |
69 |
|
|
#endif |
70 |
|
|
#ifdef HAVE_SYS_BYTEORDER_H |
71 |
|
|
#include <sys/byteorder.h> |
72 |
|
|
#endif |
73 |
|
|
|
74 |
|
|
#include <netinet/in.h> |
75 |
|
|
#include <arpa/inet.h> |
76 |
|
|
#include <net/if.h> |
77 |
|
|
#include <net/if_arp.h> |
78 |
|
|
|
79 |
|
|
static char * |
80 |
|
|
rxvt_network_display (const char *display) |
81 |
|
|
{ |
82 |
|
|
char buffer[1024], *rval = NULL; |
83 |
|
|
struct ifconf ifc; |
84 |
|
|
struct ifreq *ifr; |
85 |
|
|
int i, skfd; |
86 |
|
|
|
87 |
|
|
if (display[0] != ':' && strncmp (display, "unix:", 5)) |
88 |
|
|
return (char *) display; /* nothing to do */ |
89 |
|
|
|
90 |
|
|
ifc.ifc_len = sizeof (buffer); /* Get names of all ifaces */ |
91 |
|
|
ifc.ifc_buf = buffer; |
92 |
|
|
|
93 |
|
|
if ((skfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) |
94 |
|
|
{ |
95 |
|
|
perror ("socket"); |
96 |
|
|
return NULL; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
if (ioctl (skfd, SIOCGIFCONF, &ifc) < 0) |
100 |
|
|
{ |
101 |
|
|
perror ("SIOCGIFCONF"); |
102 |
|
|
close (skfd); |
103 |
|
|
return NULL; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
for (i = 0, ifr = ifc.ifc_req; |
107 |
|
|
i < (ifc.ifc_len / sizeof (struct ifreq)); |
108 |
|
|
i++, ifr++) |
109 |
|
|
{ |
110 |
|
|
struct ifreq ifr2; |
111 |
|
|
|
112 |
|
|
strcpy (ifr2.ifr_name, ifr->ifr_name); |
113 |
|
|
|
114 |
|
|
if (ioctl (skfd, SIOCGIFADDR, &ifr2) >= 0) |
115 |
|
|
{ |
116 |
|
|
unsigned long addr; |
117 |
|
|
struct sockaddr_in *p_addr; |
118 |
|
|
|
119 |
|
|
p_addr = (struct sockaddr_in *) &ifr2.ifr_addr; |
120 |
|
|
addr = htonl ((unsigned long)p_addr->sin_addr.s_addr); |
121 |
|
|
|
122 |
|
|
/* |
123 |
|
|
* not "0.0.0.0" or "127.0.0.1" - so format the address |
124 |
|
|
*/ |
125 |
|
|
if (addr && addr != 0x7F000001) |
126 |
|
|
{ |
127 |
|
|
char *colon = strchr (display, ':'); |
128 |
|
|
|
129 |
|
|
if (colon == NULL) |
130 |
|
|
colon = ":0.0"; |
131 |
|
|
|
132 |
|
|
rval = rxvt_malloc (strlen (colon) + 16); |
133 |
|
|
sprintf (rval, "%d.%d.%d.%d%s", |
134 |
|
|
(int) ((addr >> 030) & 0xFF), |
135 |
|
|
(int) ((addr >> 020) & 0xFF), |
136 |
|
|
(int) ((addr >> 010) & 0xFF), |
137 |
|
|
(int) (addr & 0xFF), colon); |
138 |
|
|
break; |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
close (skfd); |
144 |
|
|
|
145 |
|
|
return rval; |
146 |
|
|
} |
147 |
|
|
#endif |
148 |
|
|
|
149 |
pcg |
1.9 |
const char *const def_colorName[] = |
150 |
|
|
{ |
151 |
pcg |
1.1 |
COLOR_FOREGROUND, |
152 |
|
|
COLOR_BACKGROUND, |
153 |
pcg |
1.9 |
/* low-intensity colors */ |
154 |
root |
1.159 |
"rgb:00/00/00", // 0: black (Black) |
155 |
|
|
"rgb:cd/00/00", // 1: red (Red3) |
156 |
|
|
"rgb:00/cd/00", // 2: green (Green3) |
157 |
root |
1.183 |
"rgb:cd/cd/00", // 3: yellow (Yellow3) |
158 |
root |
1.159 |
"rgb:00/00/cd", // 4: blue (Blue3) |
159 |
|
|
"rgb:cd/00/cd", // 5: magenta (Magenta3) |
160 |
|
|
"rgb:00/cd/cd", // 6: cyan (Cyan3) |
161 |
ayin |
1.221 |
# ifdef XTERM_COLORS |
162 |
root |
1.159 |
"rgb:e5/e5/e5", // 7: white (Grey90) |
163 |
ayin |
1.221 |
# else |
164 |
root |
1.159 |
"rgb:fa/eb/d7", // 7: white (AntiqueWhite) |
165 |
pcg |
1.1 |
# endif |
166 |
pcg |
1.9 |
/* high-intensity colors */ |
167 |
pcg |
1.1 |
# ifdef XTERM_COLORS |
168 |
root |
1.159 |
"rgb:4d/4d/4d", // 8: bright black (Grey30) |
169 |
pcg |
1.1 |
# else |
170 |
root |
1.159 |
"rgb:40/40/40", // 8: bright black (Grey25) |
171 |
pcg |
1.1 |
# endif |
172 |
root |
1.159 |
"rgb:ff/00/00", // 1/9: bright red (Reed) |
173 |
|
|
"rgb:00/ff/00", // 2/10: bright green (Green) |
174 |
|
|
"rgb:ff/ff/00", // 3/11: bright yellow (Yellow) |
175 |
|
|
"rgb:00/00/ff", // 4/12: bright blue (Blue) |
176 |
|
|
"rgb:ff/00/ff", // 5/13: bright magenta (Magenta) |
177 |
|
|
"rgb:00/ff/ff", // 6/14: bright cyan (Cyan) |
178 |
|
|
"rgb:ff/ff/ff", // 7/15: bright white (White) |
179 |
root |
1.90 |
|
180 |
|
|
// 88 xterm colours |
181 |
|
|
"rgb:00/00/00", |
182 |
|
|
"rgb:00/00/8b", |
183 |
|
|
"rgb:00/00/cd", |
184 |
|
|
"rgb:00/00/ff", |
185 |
|
|
"rgb:00/8b/00", |
186 |
|
|
"rgb:00/8b/8b", |
187 |
|
|
"rgb:00/8b/cd", |
188 |
|
|
"rgb:00/8b/ff", |
189 |
|
|
"rgb:00/cd/00", |
190 |
|
|
"rgb:00/cd/8b", |
191 |
|
|
"rgb:00/cd/cd", |
192 |
|
|
"rgb:00/cd/ff", |
193 |
|
|
"rgb:00/ff/00", |
194 |
|
|
"rgb:00/ff/8b", |
195 |
|
|
"rgb:00/ff/cd", |
196 |
|
|
"rgb:00/ff/ff", |
197 |
|
|
"rgb:8b/00/00", |
198 |
|
|
"rgb:8b/00/8b", |
199 |
|
|
"rgb:8b/00/cd", |
200 |
|
|
"rgb:8b/00/ff", |
201 |
|
|
"rgb:8b/8b/00", |
202 |
|
|
"rgb:8b/8b/8b", |
203 |
|
|
"rgb:8b/8b/cd", |
204 |
|
|
"rgb:8b/8b/ff", |
205 |
|
|
"rgb:8b/cd/00", |
206 |
|
|
"rgb:8b/cd/8b", |
207 |
|
|
"rgb:8b/cd/cd", |
208 |
|
|
"rgb:8b/cd/ff", |
209 |
|
|
"rgb:8b/ff/00", |
210 |
|
|
"rgb:8b/ff/8b", |
211 |
|
|
"rgb:8b/ff/cd", |
212 |
|
|
"rgb:8b/ff/ff", |
213 |
|
|
"rgb:cd/00/00", |
214 |
|
|
"rgb:cd/00/8b", |
215 |
|
|
"rgb:cd/00/cd", |
216 |
|
|
"rgb:cd/00/ff", |
217 |
|
|
"rgb:cd/8b/00", |
218 |
|
|
"rgb:cd/8b/8b", |
219 |
|
|
"rgb:cd/8b/cd", |
220 |
|
|
"rgb:cd/8b/ff", |
221 |
|
|
"rgb:cd/cd/00", |
222 |
|
|
"rgb:cd/cd/8b", |
223 |
|
|
"rgb:cd/cd/cd", |
224 |
|
|
"rgb:cd/cd/ff", |
225 |
|
|
"rgb:cd/ff/00", |
226 |
|
|
"rgb:cd/ff/8b", |
227 |
|
|
"rgb:cd/ff/cd", |
228 |
|
|
"rgb:cd/ff/ff", |
229 |
|
|
"rgb:ff/00/00", |
230 |
|
|
"rgb:ff/00/8b", |
231 |
|
|
"rgb:ff/00/cd", |
232 |
|
|
"rgb:ff/00/ff", |
233 |
|
|
"rgb:ff/8b/00", |
234 |
|
|
"rgb:ff/8b/8b", |
235 |
|
|
"rgb:ff/8b/cd", |
236 |
|
|
"rgb:ff/8b/ff", |
237 |
|
|
"rgb:ff/cd/00", |
238 |
|
|
"rgb:ff/cd/8b", |
239 |
|
|
"rgb:ff/cd/cd", |
240 |
|
|
"rgb:ff/cd/ff", |
241 |
|
|
"rgb:ff/ff/00", |
242 |
|
|
"rgb:ff/ff/8b", |
243 |
|
|
"rgb:ff/ff/cd", |
244 |
|
|
"rgb:ff/ff/ff", |
245 |
|
|
"rgb:2e/2e/2e", |
246 |
|
|
"rgb:5c/5c/5c", |
247 |
|
|
"rgb:73/73/73", |
248 |
|
|
"rgb:8b/8b/8b", |
249 |
|
|
"rgb:a2/a2/a2", |
250 |
|
|
"rgb:b9/b9/b9", |
251 |
pcg |
1.1 |
"rgb:d0/d0/d0", |
252 |
root |
1.90 |
"rgb:e7/e7/e7", |
253 |
|
|
|
254 |
pcg |
1.1 |
#ifndef NO_CURSORCOLOR |
255 |
|
|
COLOR_CURSOR_BACKGROUND, |
256 |
|
|
COLOR_CURSOR_FOREGROUND, |
257 |
ayin |
1.222 |
#endif /* ! NO_CURSORCOLOR */ |
258 |
pcg |
1.49 |
NULL, /* Color_pointer_fg */ |
259 |
|
|
NULL, /* Color_pointer_bg */ |
260 |
pcg |
1.4 |
NULL, /* Color_border */ |
261 |
pcg |
1.1 |
#ifndef NO_BOLD_UNDERLINE_REVERSE |
262 |
pcg |
1.4 |
NULL, /* Color_BD */ |
263 |
root |
1.90 |
NULL, /* Color_IT */ |
264 |
pcg |
1.4 |
NULL, /* Color_UL */ |
265 |
|
|
NULL, /* Color_RV */ |
266 |
ayin |
1.222 |
#endif /* ! NO_BOLD_UNDERLINE_REVERSE */ |
267 |
root |
1.98 |
#if ENABLE_FRILLS |
268 |
|
|
NULL, // Color_underline |
269 |
|
|
#endif |
270 |
pcg |
1.1 |
#ifdef OPTION_HC |
271 |
|
|
NULL, |
272 |
|
|
#endif |
273 |
|
|
#ifdef KEEP_SCROLLCOLOR |
274 |
|
|
COLOR_SCROLLBAR, |
275 |
|
|
COLOR_SCROLLTROUGH, |
276 |
ayin |
1.222 |
#endif /* KEEP_SCROLLCOLOR */ |
277 |
ayin |
1.201 |
#if ENABLE_TRANSPARENCY |
278 |
root |
1.57 |
NULL, |
279 |
|
|
#endif |
280 |
root |
1.119 |
#if OFF_FOCUS_FADING |
281 |
root |
1.159 |
"rgb:00/00/00", |
282 |
root |
1.119 |
#endif |
283 |
pcg |
1.9 |
}; |
284 |
pcg |
1.1 |
|
285 |
pcg |
1.4 |
bool |
286 |
pcg |
1.14 |
rxvt_term::init_vars () |
287 |
pcg |
1.1 |
{ |
288 |
root |
1.154 |
pix_colors = // |
289 |
|
|
pix_colors_focused = new rxvt_color [TOTAL_COLORS]; |
290 |
root |
1.65 |
#ifdef OFF_FOCUS_FADING |
291 |
root |
1.79 |
pix_colors_unfocused = new rxvt_color [TOTAL_COLORS]; |
292 |
root |
1.65 |
#endif |
293 |
pcg |
1.1 |
|
294 |
pcg |
1.9 |
|
295 |
|
|
MEvent.time = CurrentTime; |
296 |
|
|
MEvent.button = AnyButton; |
297 |
|
|
want_refresh = 1; |
298 |
root |
1.79 |
priv_modes = SavedModes = PrivMode_Default; |
299 |
root |
1.122 |
ncol = 80; |
300 |
|
|
nrow = 24; |
301 |
|
|
int_bwidth = INTERNALBORDERWIDTH; |
302 |
|
|
ext_bwidth = EXTERNALBORDERWIDTH; |
303 |
|
|
lineSpace = LINESPACE; |
304 |
|
|
saveLines = SAVELINES; |
305 |
root |
1.79 |
numpix_colors = TOTAL_COLORS; |
306 |
pcg |
1.14 |
|
307 |
pcg |
1.9 |
refresh_type = SLOW_REFRESH; |
308 |
|
|
|
309 |
|
|
oldcursor.row = oldcursor.col = -1; |
310 |
|
|
last_bot = last_state = -1; |
311 |
pcg |
1.14 |
|
312 |
root |
1.182 |
set_option (Opt_scrollBar); |
313 |
|
|
set_option (Opt_scrollTtyOutput); |
314 |
|
|
set_option (Opt_jumpScroll); |
315 |
root |
1.188 |
set_option (Opt_skipScroll); |
316 |
root |
1.182 |
set_option (Opt_secondaryScreen); |
317 |
|
|
set_option (Opt_secondaryScroll); |
318 |
|
|
set_option (Opt_pastableTabs); |
319 |
|
|
set_option (Opt_intensityStyles); |
320 |
ayin |
1.186 |
set_option (Opt_iso14755_52); |
321 |
ayin |
1.181 |
|
322 |
pcg |
1.9 |
return true; |
323 |
pcg |
1.1 |
} |
324 |
|
|
|
325 |
|
|
void |
326 |
pcg |
1.14 |
rxvt_term::init_secondary () |
327 |
pcg |
1.1 |
{ |
328 |
pcg |
1.14 |
int i; |
329 |
pcg |
1.9 |
|
330 |
|
|
/* |
331 |
|
|
* Close all unused file descriptors |
332 |
|
|
* We don't want them, we don't need them. |
333 |
|
|
*/ |
334 |
|
|
if ((i = open ("/dev/null", O_RDONLY)) < 0) |
335 |
|
|
{ |
336 |
|
|
/* TODO: BOO HISS */ |
337 |
|
|
dup2 (STDERR_FILENO, STDIN_FILENO); |
338 |
|
|
} |
339 |
root |
1.215 |
else if (i != STDIN_FILENO) |
340 |
pcg |
1.9 |
{ |
341 |
|
|
dup2 (i, STDIN_FILENO); |
342 |
|
|
close (i); |
343 |
|
|
} |
344 |
pcg |
1.1 |
|
345 |
pcg |
1.9 |
dup2 (STDERR_FILENO, STDOUT_FILENO); |
346 |
pcg |
1.14 |
|
347 |
pcg |
1.7 |
#if 0 // schmorp sayz closing filies is murder |
348 |
pcg |
1.14 |
for (i = STDERR_FILENO + 1; i < num_fds; i++) |
349 |
pcg |
1.9 |
{ |
350 |
pcg |
1.4 |
#ifdef __sgi /* Alex Coventry says we need 4 & 7 too */ |
351 |
pcg |
1.9 |
if (i == 4 || i == 7) |
352 |
|
|
continue; |
353 |
pcg |
1.1 |
#endif |
354 |
pcg |
1.26 |
close (i); |
355 |
pcg |
1.1 |
} |
356 |
pcg |
1.7 |
#endif |
357 |
pcg |
1.1 |
} |
358 |
|
|
|
359 |
|
|
/*----------------------------------------------------------------------*/ |
360 |
pcg |
1.14 |
const char ** |
361 |
|
|
rxvt_term::init_resources (int argc, const char *const *argv) |
362 |
pcg |
1.1 |
{ |
363 |
pcg |
1.9 |
int i, r_argc; |
364 |
|
|
const char **cmd_argv, **r_argv; |
365 |
|
|
|
366 |
|
|
/* |
367 |
root |
1.171 |
* Look for -e option. Find => split and make cmd_argv[] of command args |
368 |
pcg |
1.9 |
*/ |
369 |
|
|
for (r_argc = 0; r_argc < argc; r_argc++) |
370 |
root |
1.171 |
if (!strcmp (argv[r_argc], "-e")) |
371 |
pcg |
1.9 |
break; |
372 |
pcg |
1.14 |
|
373 |
pcg |
1.9 |
if (r_argc == argc) |
374 |
|
|
cmd_argv = NULL; |
375 |
ayin |
1.216 |
else if (!argv[r_argc + 1]) |
376 |
ayin |
1.219 |
rxvt_fatal ("option '-e' requires an argument, aborting.\n"); |
377 |
pcg |
1.9 |
else |
378 |
|
|
{ |
379 |
pcg |
1.26 |
cmd_argv = (const char **)rxvt_malloc (sizeof (char *) * (argc - r_argc)); |
380 |
pcg |
1.1 |
|
381 |
pcg |
1.9 |
for (i = 0; i < argc - r_argc - 1; i++) |
382 |
|
|
cmd_argv[i] = (const char *)argv[i + r_argc + 1]; |
383 |
pcg |
1.14 |
|
384 |
pcg |
1.9 |
cmd_argv[i] = NULL; |
385 |
|
|
} |
386 |
pcg |
1.1 |
|
387 |
ayin |
1.216 |
r_argv = (const char **)rxvt_malloc (sizeof (char *) * (r_argc + 1)); |
388 |
|
|
|
389 |
|
|
for (i = 0; i < r_argc; i++) |
390 |
|
|
r_argv[i] = (const char *)argv[i]; |
391 |
|
|
|
392 |
|
|
r_argv[i] = NULL; |
393 |
|
|
|
394 |
ayin |
1.210 |
rs[Rs_name] = rxvt_basename (argv[0]); |
395 |
pcg |
1.14 |
|
396 |
pcg |
1.9 |
/* |
397 |
|
|
* Open display, get options/resources and create the window |
398 |
|
|
*/ |
399 |
pcg |
1.1 |
|
400 |
root |
1.140 |
if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) |
401 |
|
|
rs[Rs_display_name] = ":0"; |
402 |
pcg |
1.1 |
|
403 |
root |
1.140 |
get_options (r_argc, r_argv); |
404 |
root |
1.137 |
|
405 |
root |
1.140 |
if (!(display = displays.get (rs[Rs_display_name]))) |
406 |
root |
1.217 |
{ |
407 |
|
|
free (r_argv); |
408 |
|
|
rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); |
409 |
|
|
} |
410 |
root |
1.139 |
|
411 |
root |
1.166 |
// using a local pointer decreases code size a lot |
412 |
root |
1.157 |
xa = display->xa; |
413 |
|
|
|
414 |
root |
1.173 |
set (display); |
415 |
|
|
extract_resources (); |
416 |
|
|
|
417 |
root |
1.161 |
#if XFT |
418 |
root |
1.157 |
if (rs[Rs_depth]) |
419 |
root |
1.173 |
select_visual (strtol (rs[Rs_depth], 0, 0)); |
420 |
root |
1.157 |
#endif |
421 |
pcg |
1.1 |
|
422 |
sasha |
1.190 |
#ifdef HAVE_AFTERIMAGE |
423 |
sasha |
1.194 |
asv = create_asvisual_for_id (dpy, display->screen, depth, XVisualIDFromVisual (visual), cmap, NULL); |
424 |
sasha |
1.190 |
#endif |
425 |
root |
1.167 |
free (r_argv); |
426 |
|
|
|
427 |
root |
1.166 |
for (int i = NUM_RESOURCES; i--; ) |
428 |
|
|
if (rs [i] == resval_undef) |
429 |
|
|
rs [i] = 0; |
430 |
|
|
|
431 |
root |
1.151 |
#if ENABLE_PERL |
432 |
|
|
if (!rs[Rs_perl_ext_1]) |
433 |
|
|
rs[Rs_perl_ext_1] = "default"; |
434 |
|
|
|
435 |
|
|
if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
436 |
|
|
|| (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
437 |
|
|
|| (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
438 |
|
|
{ |
439 |
|
|
rxvt_perl.init (this); |
440 |
|
|
HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
441 |
|
|
} |
442 |
|
|
#endif |
443 |
|
|
|
444 |
pcg |
1.9 |
/* |
445 |
|
|
* set any defaults not already set |
446 |
|
|
*/ |
447 |
|
|
if (cmd_argv && cmd_argv[0]) |
448 |
|
|
{ |
449 |
|
|
if (!rs[Rs_title]) |
450 |
ayin |
1.210 |
rs[Rs_title] = rxvt_basename (cmd_argv[0]); |
451 |
pcg |
1.9 |
if (!rs[Rs_iconName]) |
452 |
|
|
rs[Rs_iconName] = rs[Rs_title]; |
453 |
|
|
} |
454 |
|
|
else |
455 |
|
|
{ |
456 |
|
|
if (!rs[Rs_title]) |
457 |
|
|
rs[Rs_title] = rs[Rs_name]; |
458 |
|
|
if (!rs[Rs_iconName]) |
459 |
|
|
rs[Rs_iconName] = rs[Rs_name]; |
460 |
pcg |
1.1 |
} |
461 |
pcg |
1.14 |
|
462 |
pcg |
1.26 |
if (rs[Rs_saveLines] && (i = atoi (rs[Rs_saveLines])) >= 0) |
463 |
root |
1.126 |
saveLines = min (i, MAX_SAVELINES); |
464 |
pcg |
1.14 |
|
465 |
root |
1.79 |
#if ENABLE_FRILLS |
466 |
pcg |
1.26 |
if (rs[Rs_int_bwidth] && (i = atoi (rs[Rs_int_bwidth])) >= 0) |
467 |
root |
1.125 |
int_bwidth = min (i, std::numeric_limits<int16_t>::max ()); |
468 |
root |
1.124 |
|
469 |
pcg |
1.26 |
if (rs[Rs_ext_bwidth] && (i = atoi (rs[Rs_ext_bwidth])) >= 0) |
470 |
root |
1.125 |
ext_bwidth = min (i, std::numeric_limits<int16_t>::max ()); |
471 |
root |
1.124 |
|
472 |
pcg |
1.26 |
if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0) |
473 |
root |
1.125 |
lineSpace = min (i, std::numeric_limits<int16_t>::max ()); |
474 |
pcg |
1.1 |
#endif |
475 |
|
|
|
476 |
|
|
#ifdef POINTER_BLANK |
477 |
pcg |
1.26 |
if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) |
478 |
pcg |
1.14 |
pointerBlankDelay = i; |
479 |
pcg |
1.9 |
else |
480 |
pcg |
1.14 |
pointerBlankDelay = 2; |
481 |
pcg |
1.1 |
#endif |
482 |
|
|
|
483 |
pcg |
1.9 |
/* no point having a scrollbar without having any scrollback! */ |
484 |
root |
1.122 |
if (!saveLines) |
485 |
root |
1.136 |
set_option (Opt_scrollBar, 0); |
486 |
pcg |
1.1 |
|
487 |
|
|
#ifdef PRINTPIPE |
488 |
pcg |
1.9 |
if (!rs[Rs_print_pipe]) |
489 |
|
|
rs[Rs_print_pipe] = PRINTPIPE; |
490 |
pcg |
1.1 |
#endif |
491 |
pcg |
1.9 |
|
492 |
|
|
if (!rs[Rs_cutchars]) |
493 |
|
|
rs[Rs_cutchars] = CUTCHARS; |
494 |
pcg |
1.14 |
|
495 |
pcg |
1.1 |
#ifndef NO_BACKSPACE_KEY |
496 |
pcg |
1.9 |
if (!rs[Rs_backspace_key]) |
497 |
pcg |
1.1 |
# ifdef DEFAULT_BACKSPACE |
498 |
ayin |
1.211 |
rs[Rs_backspace_key] = DEFAULT_BACKSPACE; |
499 |
pcg |
1.1 |
# else |
500 |
ayin |
1.211 |
rs[Rs_backspace_key] = "DEC"; /* can toggle between \010 or \177 */ |
501 |
pcg |
1.1 |
# endif |
502 |
|
|
#endif |
503 |
pcg |
1.14 |
|
504 |
pcg |
1.1 |
#ifndef NO_DELETE_KEY |
505 |
pcg |
1.9 |
if (!rs[Rs_delete_key]) |
506 |
pcg |
1.1 |
# ifdef DEFAULT_DELETE |
507 |
ayin |
1.211 |
rs[Rs_delete_key] = DEFAULT_DELETE; |
508 |
pcg |
1.1 |
# else |
509 |
ayin |
1.211 |
rs[Rs_delete_key] = "\033[3~"; |
510 |
pcg |
1.1 |
# endif |
511 |
|
|
#endif |
512 |
|
|
|
513 |
|
|
#ifdef HAVE_SCROLLBARS |
514 |
root |
1.90 |
setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]); |
515 |
pcg |
1.1 |
#endif |
516 |
|
|
|
517 |
|
|
#ifdef XTERM_REVERSE_VIDEO |
518 |
pcg |
1.9 |
/* this is how xterm implements reverseVideo */ |
519 |
root |
1.182 |
if (option (Opt_reverseVideo)) |
520 |
pcg |
1.9 |
{ |
521 |
|
|
if (!rs[Rs_color + Color_fg]) |
522 |
|
|
rs[Rs_color + Color_fg] = def_colorName[Color_bg]; |
523 |
root |
1.165 |
|
524 |
pcg |
1.9 |
if (!rs[Rs_color + Color_bg]) |
525 |
|
|
rs[Rs_color + Color_bg] = def_colorName[Color_fg]; |
526 |
pcg |
1.1 |
} |
527 |
|
|
#endif |
528 |
|
|
|
529 |
pcg |
1.9 |
for (i = 0; i < NRS_COLORS; i++) |
530 |
|
|
if (!rs[Rs_color + i]) |
531 |
|
|
rs[Rs_color + i] = def_colorName[i]; |
532 |
pcg |
1.1 |
|
533 |
|
|
#ifndef XTERM_REVERSE_VIDEO |
534 |
pcg |
1.9 |
/* this is how we implement reverseVideo */ |
535 |
root |
1.182 |
if (option (Opt_reverseVideo)) |
536 |
root |
1.123 |
::swap (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg]); |
537 |
pcg |
1.1 |
#endif |
538 |
|
|
|
539 |
pcg |
1.9 |
/* convenient aliases for setting fg/bg to colors */ |
540 |
pcg |
1.14 |
color_aliases (Color_fg); |
541 |
|
|
color_aliases (Color_bg); |
542 |
pcg |
1.1 |
#ifndef NO_CURSORCOLOR |
543 |
pcg |
1.14 |
color_aliases (Color_cursor); |
544 |
|
|
color_aliases (Color_cursor2); |
545 |
ayin |
1.222 |
#endif /* NO_CURSORCOLOR */ |
546 |
pcg |
1.49 |
color_aliases (Color_pointer_fg); |
547 |
|
|
color_aliases (Color_pointer_bg); |
548 |
pcg |
1.14 |
color_aliases (Color_border); |
549 |
pcg |
1.1 |
#ifndef NO_BOLD_UNDERLINE_REVERSE |
550 |
pcg |
1.14 |
color_aliases (Color_BD); |
551 |
|
|
color_aliases (Color_UL); |
552 |
|
|
color_aliases (Color_RV); |
553 |
ayin |
1.222 |
#endif /* ! NO_BOLD_UNDERLINE_REVERSE */ |
554 |
pcg |
1.1 |
|
555 |
root |
1.90 |
if (!rs[Rs_color + Color_border]) |
556 |
|
|
rs[Rs_color + Color_border] = rs[Rs_color + Color_bg]; |
557 |
|
|
|
558 |
pcg |
1.9 |
return cmd_argv; |
559 |
pcg |
1.1 |
} |
560 |
|
|
|
561 |
|
|
/*----------------------------------------------------------------------*/ |
562 |
|
|
void |
563 |
pcg |
1.14 |
rxvt_term::init_env () |
564 |
pcg |
1.1 |
{ |
565 |
pcg |
1.14 |
int i; |
566 |
|
|
char *val; |
567 |
pcg |
1.1 |
|
568 |
|
|
#ifdef DISPLAY_IS_IP |
569 |
pcg |
1.9 |
/* Fixup display_name for export over pty to any interested terminal |
570 |
|
|
* clients via "ESC[7n" (e.g. shells). Note we use the pure IP number |
571 |
|
|
* (for the first non-loopback interface) that we get from |
572 |
pcg |
1.26 |
* rxvt_network_display (). This is more "name-resolution-portable", if you |
573 |
pcg |
1.9 |
* will, and probably allows for faster x-client startup if your name |
574 |
|
|
* server is beyond a slow link or overloaded at client startup. Of |
575 |
|
|
* course that only helps the shell's child processes, not us. |
576 |
|
|
* |
577 |
|
|
* Giving out the display_name also affords a potential security hole |
578 |
|
|
*/ |
579 |
pcg |
1.14 |
val = rxvt_network_display (rs[Rs_display_name]); |
580 |
|
|
rs[Rs_display_name] = (const char *)val; |
581 |
|
|
|
582 |
pcg |
1.9 |
if (val == NULL) |
583 |
ayin |
1.222 |
#endif /* DISPLAY_IS_IP */ |
584 |
root |
1.169 |
val = XDisplayString (dpy); |
585 |
pcg |
1.9 |
|
586 |
pcg |
1.14 |
if (rs[Rs_display_name] == NULL) |
587 |
|
|
rs[Rs_display_name] = val; /* use broken `:0' value */ |
588 |
pcg |
1.9 |
|
589 |
root |
1.79 |
i = strlen (val); |
590 |
ayin |
1.208 |
env_display = (char *)rxvt_malloc (i + 9); |
591 |
pcg |
1.9 |
|
592 |
pcg |
1.14 |
sprintf (env_display, "DISPLAY=%s", val); |
593 |
pcg |
1.9 |
|
594 |
root |
1.155 |
sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent[0]); |
595 |
pcg |
1.9 |
|
596 |
|
|
/* add entries to the environment: |
597 |
|
|
* @ DISPLAY: in case we started with -display |
598 |
|
|
* @ WINDOWID: X window id number of the window |
599 |
|
|
* @ COLORTERM: terminal sub-name and also indicates its color |
600 |
|
|
* @ TERM: terminal name |
601 |
|
|
* @ TERMINFO: path to terminfo directory |
602 |
pcg |
1.27 |
* @ COLORFGBG: fg;bg color codes |
603 |
pcg |
1.9 |
*/ |
604 |
pcg |
1.14 |
putenv (env_display); |
605 |
|
|
putenv (env_windowid); |
606 |
root |
1.155 |
|
607 |
pcg |
1.27 |
if (env_colorfgbg) |
608 |
|
|
putenv (env_colorfgbg); |
609 |
pcg |
1.14 |
|
610 |
pcg |
1.1 |
#ifdef RXVT_TERMINFO |
611 |
pcg |
1.14 |
putenv ("TERMINFO=" RXVT_TERMINFO); |
612 |
pcg |
1.1 |
#endif |
613 |
pcg |
1.9 |
|
614 |
root |
1.156 |
if (depth <= 2) |
615 |
pcg |
1.14 |
putenv ("COLORTERM=" COLORTERMENV "-mono"); |
616 |
pcg |
1.9 |
else |
617 |
pcg |
1.14 |
putenv ("COLORTERM=" COLORTERMENVFULL); |
618 |
|
|
|
619 |
|
|
if (rs[Rs_term_name] != NULL) |
620 |
pcg |
1.9 |
{ |
621 |
ayin |
1.208 |
env_term = (char *)rxvt_malloc (strlen (rs[Rs_term_name]) + 6); |
622 |
pcg |
1.14 |
sprintf (env_term, "TERM=%s", rs[Rs_term_name]); |
623 |
|
|
putenv (env_term); |
624 |
pcg |
1.9 |
} |
625 |
|
|
else |
626 |
pcg |
1.14 |
putenv ("TERM=" TERMENV); |
627 |
pcg |
1.1 |
|
628 |
|
|
#ifdef HAVE_UNSETENV |
629 |
pcg |
1.9 |
/* avoid passing old settings and confusing term size */ |
630 |
pcg |
1.14 |
unsetenv ("LINES"); |
631 |
|
|
unsetenv ("COLUMNS"); |
632 |
|
|
unsetenv ("TERMCAP"); /* terminfo should be okay */ |
633 |
ayin |
1.222 |
#endif /* HAVE_UNSETENV */ |
634 |
pcg |
1.1 |
} |
635 |
|
|
|
636 |
|
|
/*----------------------------------------------------------------------*/ |
637 |
|
|
/* |
638 |
|
|
* This is more or less stolen straight from XFree86 xterm. |
639 |
|
|
* This should support all European type languages. |
640 |
|
|
*/ |
641 |
|
|
void |
642 |
pcg |
1.15 |
rxvt_term::set_locale (const char *locale) |
643 |
|
|
{ |
644 |
root |
1.140 |
set_environ (envv); |
645 |
root |
1.137 |
|
646 |
pcg |
1.15 |
#if HAVE_XSETLOCALE || HAVE_SETLOCALE |
647 |
|
|
free (this->locale); |
648 |
root |
1.57 |
this->locale = setlocale (LC_CTYPE, locale); |
649 |
|
|
|
650 |
|
|
if (!this->locale) |
651 |
|
|
{ |
652 |
root |
1.79 |
if (*locale) |
653 |
|
|
{ |
654 |
root |
1.137 |
rxvt_warn ("unable to set locale \"%s\", using C locale instead.\n", locale); |
655 |
|
|
setlocale (LC_CTYPE, "C"); |
656 |
root |
1.79 |
} |
657 |
|
|
else |
658 |
|
|
rxvt_warn ("default locale unavailable, check LC_* and LANG variables. Continuing.\n"); |
659 |
|
|
|
660 |
root |
1.137 |
this->locale = "C"; |
661 |
root |
1.57 |
} |
662 |
|
|
|
663 |
root |
1.79 |
|
664 |
ayin |
1.220 |
this->locale = strdup (this->locale); |
665 |
pcg |
1.29 |
SET_LOCALE (this->locale); |
666 |
pcg |
1.28 |
mbstate.reset (); |
667 |
pcg |
1.15 |
#endif |
668 |
root |
1.96 |
|
669 |
pcg |
1.15 |
#if HAVE_NL_LANGINFO |
670 |
root |
1.96 |
char *codeset = strdup (nl_langinfo (CODESET)); |
671 |
root |
1.105 |
// /^UTF.?8/i |
672 |
|
|
enc_utf8 = (codeset[0] == 'U' || codeset[0] == 'u') |
673 |
|
|
&& (codeset[1] == 'T' || codeset[1] == 't') |
674 |
|
|
&& (codeset[2] == 'F' || codeset[2] == 'f') |
675 |
|
|
&& (codeset[3] == '8' || codeset[4] == '8'); |
676 |
root |
1.96 |
free (codeset); |
677 |
pcg |
1.15 |
#else |
678 |
root |
1.96 |
enc_utf8 = 0; |
679 |
pcg |
1.15 |
#endif |
680 |
|
|
} |
681 |
|
|
|
682 |
|
|
void |
683 |
pcg |
1.14 |
rxvt_term::init_xlocale () |
684 |
pcg |
1.1 |
{ |
685 |
root |
1.140 |
set_environ (envv); |
686 |
root |
1.137 |
|
687 |
pcg |
1.1 |
#ifdef USE_XIM |
688 |
pcg |
1.14 |
if (!locale) |
689 |
pcg |
1.45 |
rxvt_warn ("setting locale failed, working without locale support.\n"); |
690 |
pcg |
1.9 |
else |
691 |
|
|
{ |
692 |
root |
1.97 |
set_string_property (xa[XA_WM_LOCALE_NAME], locale); |
693 |
pcg |
1.9 |
|
694 |
pcg |
1.14 |
if (!XSupportsLocale ()) |
695 |
pcg |
1.9 |
{ |
696 |
root |
1.92 |
rxvt_warn ("the locale is not supported by Xlib, working without locale support.\n"); |
697 |
pcg |
1.9 |
return; |
698 |
pcg |
1.4 |
} |
699 |
pcg |
1.10 |
|
700 |
pcg |
1.25 |
im_ev.start (display); |
701 |
pcg |
1.4 |
|
702 |
pcg |
1.25 |
/* see if we can connect already */ |
703 |
|
|
im_cb (); |
704 |
pcg |
1.1 |
} |
705 |
|
|
#endif |
706 |
|
|
} |
707 |
|
|
|
708 |
|
|
/*----------------------------------------------------------------------*/ |
709 |
|
|
void |
710 |
pcg |
1.26 |
rxvt_term::init_command (const char *const *argv) |
711 |
pcg |
1.1 |
{ |
712 |
pcg |
1.4 |
/* |
713 |
|
|
* Initialize the command connection. |
714 |
|
|
* This should be called after the X server connection is established. |
715 |
|
|
*/ |
716 |
pcg |
1.1 |
|
717 |
|
|
#ifdef META8_OPTION |
718 |
root |
1.182 |
meta_char = option (Opt_meta8) ? 0x80 : C0_ESC; |
719 |
pcg |
1.14 |
#endif |
720 |
pcg |
1.9 |
|
721 |
pcg |
1.20 |
get_ourmods (); |
722 |
pcg |
1.4 |
|
723 |
root |
1.182 |
if (!option (Opt_scrollTtyOutput)) |
724 |
root |
1.79 |
priv_modes |= PrivMode_TtyOutputInh; |
725 |
root |
1.182 |
if (option (Opt_scrollTtyKeypress)) |
726 |
root |
1.79 |
priv_modes |= PrivMode_Keypress; |
727 |
root |
1.182 |
if (!option (Opt_jumpScroll)) |
728 |
root |
1.79 |
priv_modes |= PrivMode_smoothScroll; |
729 |
pcg |
1.4 |
|
730 |
pcg |
1.1 |
#ifndef NO_BACKSPACE_KEY |
731 |
ayin |
1.211 |
if (strcmp (rs[Rs_backspace_key], "DEC") == 0) |
732 |
root |
1.79 |
priv_modes |= PrivMode_HaveBackSpace; |
733 |
pcg |
1.14 |
#endif |
734 |
pcg |
1.9 |
|
735 |
|
|
/* add value for scrollBar */ |
736 |
root |
1.143 |
if (scrollBar.state) |
737 |
pcg |
1.4 |
{ |
738 |
root |
1.79 |
priv_modes |= PrivMode_scrollBar; |
739 |
pcg |
1.14 |
SavedModes |= PrivMode_scrollBar; |
740 |
pcg |
1.4 |
} |
741 |
root |
1.110 |
|
742 |
root |
1.70 |
run_command (argv); |
743 |
pcg |
1.1 |
} |
744 |
|
|
|
745 |
|
|
/*----------------------------------------------------------------------*/ |
746 |
|
|
void |
747 |
pcg |
1.20 |
rxvt_term::Get_Colours () |
748 |
pcg |
1.1 |
{ |
749 |
pcg |
1.14 |
int i; |
750 |
pcg |
1.1 |
|
751 |
root |
1.65 |
#ifdef OFF_FOCUS_FADING |
752 |
root |
1.79 |
pix_colors = pix_colors_focused; |
753 |
root |
1.65 |
#endif |
754 |
ayin |
1.221 |
|
755 |
root |
1.156 |
for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) |
756 |
pcg |
1.9 |
{ |
757 |
root |
1.164 |
const char *name = rs[Rs_color + i]; |
758 |
pcg |
1.1 |
|
759 |
root |
1.164 |
if (!name) |
760 |
pcg |
1.9 |
continue; |
761 |
pcg |
1.1 |
|
762 |
root |
1.164 |
rxvt_color xcol; |
763 |
|
|
|
764 |
|
|
if (!set_color (xcol, name)) |
765 |
pcg |
1.9 |
{ |
766 |
pcg |
1.1 |
#ifndef XTERM_REVERSE_VIDEO |
767 |
root |
1.182 |
if (i < 2 && option (Opt_reverseVideo)) |
768 |
root |
1.164 |
name = def_colorName [1 - i]; |
769 |
pcg |
1.9 |
else |
770 |
|
|
#endif |
771 |
root |
1.164 |
name = def_colorName [i]; |
772 |
pcg |
1.9 |
|
773 |
root |
1.164 |
if (!name) |
774 |
pcg |
1.9 |
continue; |
775 |
pcg |
1.14 |
|
776 |
root |
1.164 |
if (!set_color (xcol, name)) |
777 |
pcg |
1.9 |
{ |
778 |
|
|
switch (i) |
779 |
|
|
{ |
780 |
pcg |
1.23 |
case Color_fg: |
781 |
|
|
case Color_bg: |
782 |
root |
1.160 |
rxvt_warn ("unable to get foreground/background colour, continuing.\n"); |
783 |
root |
1.164 |
name = ""; |
784 |
pcg |
1.23 |
break; |
785 |
pcg |
1.1 |
#ifndef NO_CURSORCOLOR |
786 |
pcg |
1.23 |
case Color_cursor2: |
787 |
root |
1.164 |
#endif |
788 |
pcg |
1.49 |
case Color_pointer_fg: |
789 |
root |
1.164 |
name = rs[Rs_color + Color_fg]; |
790 |
root |
1.168 |
xcol.set (this, name); |
791 |
pcg |
1.23 |
break; |
792 |
|
|
default: |
793 |
root |
1.164 |
name = rs[Rs_color + Color_bg]; |
794 |
root |
1.168 |
xcol.set (this, name); |
795 |
pcg |
1.23 |
break; |
796 |
pcg |
1.4 |
} |
797 |
|
|
} |
798 |
|
|
} |
799 |
pcg |
1.14 |
|
800 |
root |
1.79 |
pix_colors[i] = xcol; |
801 |
root |
1.164 |
rs[Rs_color + i] = name; |
802 |
root |
1.119 |
} |
803 |
|
|
|
804 |
root |
1.156 |
if (depth <= 2) |
805 |
pcg |
1.49 |
{ |
806 |
root |
1.168 |
if (!rs[Rs_color + Color_pointer_fg]) alias_color (Color_pointer_fg, Color_fg); |
807 |
|
|
if (!rs[Rs_color + Color_pointer_bg]) alias_color (Color_pointer_bg, Color_bg); |
808 |
|
|
if (!rs[Rs_color + Color_border] ) alias_color (Color_border, Color_fg); |
809 |
pcg |
1.49 |
} |
810 |
pcg |
1.1 |
|
811 |
pcg |
1.9 |
/* |
812 |
root |
1.143 |
* get scrollBar shadow colors |
813 |
pcg |
1.9 |
* |
814 |
|
|
* The calculations of topShadow/bottomShadow values are adapted |
815 |
|
|
* from the fvwm window manager. |
816 |
|
|
*/ |
817 |
pcg |
1.1 |
#ifdef KEEP_SCROLLCOLOR |
818 |
root |
1.156 |
if (depth <= 2) |
819 |
root |
1.118 |
{ |
820 |
|
|
/* Monochrome */ |
821 |
root |
1.168 |
alias_color (Color_scroll, Color_fg); |
822 |
|
|
alias_color (Color_topShadow, Color_bg); |
823 |
|
|
alias_color (Color_bottomShadow, Color_bg); |
824 |
pcg |
1.9 |
} |
825 |
|
|
else |
826 |
|
|
{ |
827 |
root |
1.168 |
pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]); |
828 |
pcg |
1.1 |
|
829 |
root |
1.168 |
rgba cscroll; |
830 |
|
|
pix_colors [Color_scroll].get (cscroll); |
831 |
pcg |
1.1 |
|
832 |
pcg |
1.9 |
/* topShadowColor */ |
833 |
root |
1.168 |
if (!pix_colors[Color_topShadow].set (this, |
834 |
|
|
rgba ( |
835 |
|
|
min ((int)rgba::MAX_CC, max (cscroll.r / 5, cscroll.r) * 7 / 5), |
836 |
|
|
min ((int)rgba::MAX_CC, max (cscroll.g / 5, cscroll.g) * 7 / 5), |
837 |
|
|
min ((int)rgba::MAX_CC, max (cscroll.b / 5, cscroll.b) * 7 / 5), |
838 |
|
|
cscroll.a) |
839 |
|
|
)) |
840 |
|
|
alias_color (Color_topShadow, Color_White); |
841 |
pcg |
1.1 |
} |
842 |
ayin |
1.222 |
#endif /* KEEP_SCROLLCOLOR */ |
843 |
root |
1.168 |
|
844 |
|
|
#ifdef OFF_FOCUS_FADING |
845 |
root |
1.174 |
for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) |
846 |
|
|
update_fade_color (i); |
847 |
root |
1.168 |
#endif |
848 |
pcg |
1.1 |
} |
849 |
|
|
|
850 |
|
|
/*----------------------------------------------------------------------*/ |
851 |
|
|
/* color aliases, fg/bg bright-bold */ |
852 |
|
|
void |
853 |
pcg |
1.26 |
rxvt_term::color_aliases (int idx) |
854 |
pcg |
1.1 |
{ |
855 |
pcg |
1.26 |
if (rs[Rs_color + idx] && isdigit (* (rs[Rs_color + idx]))) |
856 |
pcg |
1.9 |
{ |
857 |
pcg |
1.14 |
int i = atoi (rs[Rs_color + idx]); |
858 |
pcg |
1.1 |
|
859 |
pcg |
1.9 |
if (i >= 8 && i <= 15) |
860 |
ayin |
1.223 |
/* bright colors */ |
861 |
|
|
rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i - 8]; |
862 |
|
|
else if (i >= 0 && i <= 7) |
863 |
|
|
/* normal colors */ |
864 |
pcg |
1.14 |
rs[Rs_color + idx] = rs[Rs_color + minCOLOR + i]; |
865 |
pcg |
1.1 |
} |
866 |
|
|
} |
867 |
|
|
|
868 |
|
|
/*----------------------------------------------------------------------*/ |
869 |
|
|
/* |
870 |
|
|
* Probe the modifier keymap to get the Meta (Alt) and Num_Lock settings |
871 |
|
|
* Use resource ``modifier'' to override the Meta modifier |
872 |
|
|
*/ |
873 |
|
|
void |
874 |
pcg |
1.20 |
rxvt_term::get_ourmods () |
875 |
pcg |
1.1 |
{ |
876 |
root |
1.108 |
int i, j, k; |
877 |
|
|
int requestedmeta, realmeta, realalt; |
878 |
|
|
const char *cm, *rsmod; |
879 |
pcg |
1.9 |
XModifierKeymap *map; |
880 |
root |
1.108 |
KeyCode *kc; |
881 |
pcg |
1.9 |
const unsigned int modmasks[] = |
882 |
|
|
{ |
883 |
|
|
Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask |
884 |
|
|
}; |
885 |
|
|
|
886 |
|
|
requestedmeta = realmeta = realalt = 0; |
887 |
pcg |
1.20 |
rsmod = rs[Rs_modifier]; |
888 |
root |
1.105 |
|
889 |
pcg |
1.9 |
if (rsmod |
890 |
root |
1.79 |
&& strcasecmp (rsmod, "mod1") >= 0 && strcasecmp (rsmod, "mod5") <= 0) |
891 |
pcg |
1.9 |
requestedmeta = rsmod[3] - '0'; |
892 |
|
|
|
893 |
root |
1.169 |
map = XGetModifierMapping (dpy); |
894 |
pcg |
1.9 |
kc = map->modifiermap; |
895 |
root |
1.105 |
|
896 |
pcg |
1.9 |
for (i = 1; i < 6; i++) |
897 |
|
|
{ |
898 |
|
|
k = (i + 2) * map->max_keypermod; /* skip shift/lock/control */ |
899 |
root |
1.105 |
|
900 |
pcg |
1.9 |
for (j = map->max_keypermod; j--; k++) |
901 |
|
|
{ |
902 |
|
|
if (kc[k] == 0) |
903 |
|
|
break; |
904 |
root |
1.105 |
|
905 |
root |
1.169 |
switch (XKeycodeToKeysym (dpy, kc[k], 0)) |
906 |
pcg |
1.9 |
{ |
907 |
pcg |
1.23 |
case XK_Num_Lock: |
908 |
|
|
ModNumLockMask = modmasks[i - 1]; |
909 |
root |
1.105 |
continue; |
910 |
|
|
|
911 |
|
|
case XK_ISO_Level3_Shift: |
912 |
|
|
ModLevel3Mask = modmasks[i - 1]; |
913 |
|
|
continue; |
914 |
|
|
|
915 |
pcg |
1.23 |
case XK_Meta_L: |
916 |
|
|
case XK_Meta_R: |
917 |
|
|
cm = "meta"; |
918 |
|
|
realmeta = i; |
919 |
|
|
break; |
920 |
root |
1.105 |
|
921 |
pcg |
1.23 |
case XK_Alt_L: |
922 |
|
|
case XK_Alt_R: |
923 |
|
|
cm = "alt"; |
924 |
|
|
realalt = i; |
925 |
|
|
break; |
926 |
root |
1.105 |
|
927 |
pcg |
1.23 |
case XK_Super_L: |
928 |
|
|
case XK_Super_R: |
929 |
|
|
cm = "super"; |
930 |
|
|
break; |
931 |
root |
1.105 |
|
932 |
pcg |
1.23 |
case XK_Hyper_L: |
933 |
|
|
case XK_Hyper_R: |
934 |
|
|
cm = "hyper"; |
935 |
|
|
break; |
936 |
root |
1.105 |
|
937 |
|
|
default: |
938 |
|
|
continue; |
939 |
pcg |
1.4 |
} |
940 |
root |
1.105 |
|
941 |
root |
1.79 |
if (rsmod && strncasecmp (rsmod, cm, strlen (cm)) == 0) |
942 |
pcg |
1.9 |
requestedmeta = i; |
943 |
pcg |
1.4 |
} |
944 |
pcg |
1.1 |
} |
945 |
root |
1.105 |
|
946 |
pcg |
1.26 |
XFreeModifiermap (map); |
947 |
root |
1.105 |
|
948 |
|
|
i = requestedmeta ? requestedmeta |
949 |
|
|
: realmeta ? realmeta |
950 |
|
|
: realalt ? realalt |
951 |
|
|
: 0; |
952 |
|
|
|
953 |
pcg |
1.9 |
if (i) |
954 |
pcg |
1.20 |
ModMetaMask = modmasks[i - 1]; |
955 |
pcg |
1.1 |
} |
956 |
|
|
|
957 |
|
|
/*----------------------------------------------------------------------*/ |
958 |
pcg |
1.26 |
/* rxvt_Create_Windows () - Open and map the window */ |
959 |
pcg |
1.1 |
void |
960 |
pcg |
1.16 |
rxvt_term::create_windows (int argc, const char *const *argv) |
961 |
pcg |
1.1 |
{ |
962 |
pcg |
1.51 |
XClassHint classHint; |
963 |
|
|
XWMHints wmHint; |
964 |
root |
1.79 |
#if ENABLE_FRILLS |
965 |
root |
1.196 |
MWMHints mwmhints = { }; |
966 |
root |
1.67 |
#endif |
967 |
pcg |
1.51 |
XGCValues gcvalue; |
968 |
|
|
XSetWindowAttributes attributes; |
969 |
root |
1.114 |
Window top, parent; |
970 |
pcg |
1.1 |
|
971 |
root |
1.169 |
dLocal (Display *, dpy); |
972 |
pcg |
1.1 |
|
973 |
root |
1.148 |
/* grab colors before netscape does */ |
974 |
|
|
Get_Colours (); |
975 |
|
|
|
976 |
|
|
if (!set_fonts ()) |
977 |
|
|
rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); |
978 |
|
|
|
979 |
root |
1.153 |
parent = display->root; |
980 |
root |
1.148 |
|
981 |
root |
1.182 |
attributes.override_redirect = !!option (Opt_override_redirect); |
982 |
root |
1.148 |
|
983 |
root |
1.79 |
#if ENABLE_FRILLS |
984 |
root |
1.182 |
if (option (Opt_borderLess)) |
985 |
root |
1.67 |
{ |
986 |
root |
1.169 |
if (XInternAtom (dpy, "_MOTIF_WM_INFO", True) == None) |
987 |
root |
1.67 |
{ |
988 |
ayin |
1.206 |
// rxvt_warn("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n"); |
989 |
root |
1.158 |
attributes.override_redirect = true; |
990 |
root |
1.67 |
} |
991 |
|
|
else |
992 |
|
|
{ |
993 |
|
|
mwmhints.flags = MWM_HINTS_DECORATIONS; |
994 |
|
|
} |
995 |
|
|
} |
996 |
|
|
#endif |
997 |
|
|
|
998 |
root |
1.112 |
#if ENABLE_XEMBED |
999 |
root |
1.109 |
if (rs[Rs_embed]) |
1000 |
|
|
{ |
1001 |
root |
1.111 |
XWindowAttributes wattr; |
1002 |
|
|
|
1003 |
root |
1.114 |
parent = strtol (rs[Rs_embed], 0, 0); |
1004 |
root |
1.109 |
|
1005 |
root |
1.169 |
if (!XGetWindowAttributes (dpy, parent, &wattr)) |
1006 |
root |
1.111 |
rxvt_fatal ("invalid window-id specified with -embed, aborting.\n"); |
1007 |
pcg |
1.1 |
|
1008 |
root |
1.109 |
window_calc (wattr.width, wattr.height); |
1009 |
root |
1.114 |
} |
1010 |
root |
1.122 |
#endif |
1011 |
pcg |
1.1 |
|
1012 |
root |
1.114 |
window_calc (0, 0); |
1013 |
root |
1.109 |
|
1014 |
root |
1.114 |
/* sub-window placement & size in rxvt_resize_subwindows () */ |
1015 |
root |
1.156 |
attributes.background_pixel = pix_colors_focused [Color_border]; |
1016 |
|
|
attributes.border_pixel = pix_colors_focused [Color_border]; |
1017 |
|
|
attributes.colormap = cmap; |
1018 |
root |
1.153 |
|
1019 |
root |
1.169 |
top = XCreateWindow (dpy, parent, |
1020 |
root |
1.114 |
szHint.x, szHint.y, |
1021 |
|
|
szHint.width, szHint.height, |
1022 |
root |
1.122 |
ext_bwidth, |
1023 |
root |
1.156 |
depth, InputOutput, visual, |
1024 |
root |
1.148 |
CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, |
1025 |
|
|
&attributes); |
1026 |
root |
1.109 |
|
1027 |
root |
1.122 |
this->parent[0] = top; |
1028 |
root |
1.109 |
|
1029 |
|
|
old_width = szHint.width; |
1030 |
|
|
old_height = szHint.height; |
1031 |
pcg |
1.9 |
|
1032 |
root |
1.153 |
process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); |
1033 |
pcg |
1.49 |
process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); |
1034 |
pcg |
1.9 |
|
1035 |
root |
1.153 |
classHint.res_name = (char *)rs[Rs_name]; |
1036 |
pcg |
1.38 |
classHint.res_class = (char *)RESCLASS; |
1037 |
pcg |
1.9 |
|
1038 |
root |
1.153 |
wmHint.flags = InputHint | StateHint | WindowGroupHint; |
1039 |
|
|
wmHint.input = True; |
1040 |
root |
1.182 |
wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; |
1041 |
root |
1.153 |
wmHint.window_group = top; |
1042 |
pcg |
1.9 |
|
1043 |
root |
1.169 |
XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, |
1044 |
root |
1.115 |
&szHint, &wmHint, &classHint); |
1045 |
pcg |
1.49 |
|
1046 |
root |
1.153 |
#if ENABLE_FRILLS |
1047 |
|
|
if (mwmhints.flags) |
1048 |
root |
1.169 |
XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, |
1049 |
root |
1.153 |
PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS); |
1050 |
|
|
#endif |
1051 |
|
|
|
1052 |
root |
1.116 |
Atom protocols[] = { |
1053 |
|
|
xa[XA_WM_DELETE_WINDOW], |
1054 |
|
|
#if ENABLE_EWMH |
1055 |
|
|
xa[XA_NET_WM_PING], |
1056 |
|
|
#endif |
1057 |
|
|
}; |
1058 |
|
|
|
1059 |
root |
1.169 |
XSetWMProtocols (dpy, top, protocols, sizeof (protocols) / sizeof (protocols[0])); |
1060 |
root |
1.96 |
|
1061 |
root |
1.133 |
#if ENABLE_FRILLS |
1062 |
|
|
if (rs[Rs_transient_for]) |
1063 |
root |
1.169 |
XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); |
1064 |
root |
1.133 |
#endif |
1065 |
|
|
|
1066 |
root |
1.116 |
#if ENABLE_EWMH |
1067 |
pcg |
1.49 |
long pid = getpid (); |
1068 |
root |
1.93 |
|
1069 |
root |
1.169 |
XChangeProperty (dpy, top, |
1070 |
root |
1.97 |
xa[XA_NET_WM_PID], XA_CARDINAL, 32, |
1071 |
pcg |
1.49 |
PropModeReplace, (unsigned char *)&pid, 1); |
1072 |
root |
1.116 |
|
1073 |
|
|
// _NET_WM_WINDOW_TYPE is NORMAL, which is the default |
1074 |
pcg |
1.49 |
#endif |
1075 |
pcg |
1.24 |
|
1076 |
root |
1.169 |
XSelectInput (dpy, top, |
1077 |
root |
1.65 |
KeyPressMask |
1078 |
root |
1.90 |
#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755 |
1079 |
root |
1.65 |
| KeyReleaseMask |
1080 |
pcg |
1.1 |
#endif |
1081 |
root |
1.65 |
| FocusChangeMask | VisibilityChangeMask |
1082 |
root |
1.112 |
| ExposureMask | StructureNotifyMask); |
1083 |
|
|
|
1084 |
root |
1.109 |
termwin_ev.start (display, top); |
1085 |
pcg |
1.1 |
|
1086 |
pcg |
1.9 |
/* vt cursor: Black-on-White is standard, but this is more popular */ |
1087 |
root |
1.169 |
TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); |
1088 |
pcg |
1.1 |
|
1089 |
root |
1.143 |
#ifdef HAVE_SCROLLBARS |
1090 |
|
|
/* cursor scrollBar: Black-on-White */ |
1091 |
root |
1.169 |
leftptr_cursor = XCreateFontCursor (dpy, XC_left_ptr); |
1092 |
pcg |
1.1 |
#endif |
1093 |
|
|
|
1094 |
pcg |
1.9 |
/* the vt window */ |
1095 |
root |
1.169 |
vt = XCreateSimpleWindow (dpy, top, |
1096 |
root |
1.153 |
window_vt_x, window_vt_y, |
1097 |
|
|
width, height, |
1098 |
|
|
0, |
1099 |
|
|
pix_colors_focused[Color_fg], |
1100 |
|
|
pix_colors_focused[Color_bg]); |
1101 |
pcg |
1.6 |
|
1102 |
pcg |
1.51 |
attributes.bit_gravity = NorthWestGravity; |
1103 |
root |
1.169 |
XChangeWindowAttributes (dpy, vt, CWBitGravity, &attributes); |
1104 |
pcg |
1.51 |
|
1105 |
|
|
vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; |
1106 |
pcg |
1.17 |
|
1107 |
root |
1.182 |
if (option (Opt_pointerBlank)) |
1108 |
pcg |
1.9 |
vt_emask |= PointerMotionMask; |
1109 |
|
|
else |
1110 |
pcg |
1.51 |
vt_emask |= Button1MotionMask | Button3MotionMask; |
1111 |
pcg |
1.9 |
|
1112 |
root |
1.142 |
vt_select_input (); |
1113 |
|
|
|
1114 |
root |
1.122 |
vt_ev.start (display, vt); |
1115 |
pcg |
1.1 |
|
1116 |
pcg |
1.9 |
/* graphics context for the vt window */ |
1117 |
root |
1.153 |
gcvalue.foreground = pix_colors[Color_fg]; |
1118 |
|
|
gcvalue.background = pix_colors[Color_bg]; |
1119 |
root |
1.170 |
gcvalue.graphics_exposures = 0; |
1120 |
root |
1.153 |
|
1121 |
root |
1.169 |
gc = XCreateGC (dpy, vt, |
1122 |
root |
1.153 |
GCForeground | GCBackground | GCGraphicsExposures, |
1123 |
|
|
&gcvalue); |
1124 |
pcg |
1.1 |
|
1125 |
root |
1.156 |
drawable = new rxvt_drawable (this, vt); |
1126 |
pcg |
1.35 |
|
1127 |
root |
1.143 |
#ifdef RXVT_SCROLLBAR |
1128 |
root |
1.79 |
gcvalue.foreground = pix_colors[Color_topShadow]; |
1129 |
root |
1.169 |
topShadowGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
1130 |
root |
1.79 |
gcvalue.foreground = pix_colors[Color_bottomShadow]; |
1131 |
root |
1.169 |
botShadowGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
1132 |
root |
1.156 |
gcvalue.foreground = pix_colors[ (depth <= 2 ? Color_fg : Color_scroll)]; |
1133 |
root |
1.169 |
scrollbarGC = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
1134 |
pcg |
1.1 |
#endif |
1135 |
root |
1.65 |
|
1136 |
|
|
#ifdef OFF_FOCUS_FADING |
1137 |
|
|
// initially we are in unfocused state |
1138 |
|
|
if (rs[Rs_fade]) |
1139 |
root |
1.79 |
pix_colors = pix_colors_unfocused; |
1140 |
pcg |
1.1 |
#endif |
1141 |
root |
1.90 |
|
1142 |
root |
1.113 |
pointer_unblank (); |
1143 |
root |
1.90 |
scr_recolour (); |
1144 |
pcg |
1.1 |
} |
1145 |
|
|
|
1146 |
|
|
/* ------------------------------------------------------------------------- * |
1147 |
|
|
* GET TTY CURRENT STATE * |
1148 |
|
|
* ------------------------------------------------------------------------- */ |
1149 |
|
|
void |
1150 |
pcg |
1.26 |
rxvt_get_ttymode (ttymode_t *tio, int erase) |
1151 |
pcg |
1.1 |
{ |
1152 |
pcg |
1.9 |
/* |
1153 |
|
|
* standard System V termios interface |
1154 |
|
|
*/ |
1155 |
pcg |
1.26 |
if (GET_TERMIOS (STDIN_FILENO, tio) < 0) |
1156 |
pcg |
1.9 |
{ |
1157 |
root |
1.126 |
// return error - use system defaults, |
1158 |
|
|
// where possible, and zero elsewhere |
1159 |
|
|
memset (tio, 0, sizeof (ttymode_t)); |
1160 |
|
|
|
1161 |
pcg |
1.9 |
tio->c_cc[VINTR] = CINTR; |
1162 |
|
|
tio->c_cc[VQUIT] = CQUIT; |
1163 |
|
|
tio->c_cc[VERASE] = CERASE; |
1164 |
root |
1.126 |
#ifdef VERASE2 |
1165 |
|
|
tio->c_cc[VERASE2] = CERASE2; |
1166 |
|
|
#endif |
1167 |
pcg |
1.9 |
tio->c_cc[VKILL] = CKILL; |
1168 |
|
|
tio->c_cc[VSTART] = CSTART; |
1169 |
|
|
tio->c_cc[VSTOP] = CSTOP; |
1170 |
|
|
tio->c_cc[VSUSP] = CSUSP; |
1171 |
pcg |
1.1 |
# ifdef VDSUSP |
1172 |
pcg |
1.9 |
tio->c_cc[VDSUSP] = CDSUSP; |
1173 |
pcg |
1.1 |
# endif |
1174 |
|
|
# ifdef VREPRINT |
1175 |
pcg |
1.9 |
tio->c_cc[VREPRINT] = CRPRNT; |
1176 |
pcg |
1.1 |
# endif |
1177 |
|
|
# ifdef VDISCRD |
1178 |
pcg |
1.9 |
tio->c_cc[VDISCRD] = CFLUSH; |
1179 |
pcg |
1.1 |
# endif |
1180 |
|
|
# ifdef VWERSE |
1181 |
pcg |
1.9 |
tio->c_cc[VWERSE] = CWERASE; |
1182 |
pcg |
1.1 |
# endif |
1183 |
|
|
# ifdef VLNEXT |
1184 |
pcg |
1.9 |
tio->c_cc[VLNEXT] = CLNEXT; |
1185 |
pcg |
1.1 |
# endif |
1186 |
root |
1.120 |
} |
1187 |
pcg |
1.9 |
|
1188 |
|
|
tio->c_cc[VEOF] = CEOF; |
1189 |
|
|
tio->c_cc[VEOL] = VDISABLE; |
1190 |
pcg |
1.1 |
# ifdef VEOL2 |
1191 |
pcg |
1.9 |
tio->c_cc[VEOL2] = VDISABLE; |
1192 |
pcg |
1.1 |
# endif |
1193 |
|
|
# ifdef VSWTC |
1194 |
pcg |
1.9 |
tio->c_cc[VSWTC] = VDISABLE; |
1195 |
pcg |
1.1 |
# endif |
1196 |
|
|
# ifdef VSWTCH |
1197 |
pcg |
1.9 |
tio->c_cc[VSWTCH] = VDISABLE; |
1198 |
pcg |
1.1 |
# endif |
1199 |
|
|
# if VMIN != VEOF |
1200 |
pcg |
1.9 |
tio->c_cc[VMIN] = 1; |
1201 |
pcg |
1.1 |
# endif |
1202 |
|
|
# if VTIME != VEOL |
1203 |
pcg |
1.9 |
tio->c_cc[VTIME] = 0; |
1204 |
pcg |
1.1 |
# endif |
1205 |
|
|
|
1206 |
pcg |
1.9 |
if (erase != -1) |
1207 |
|
|
tio->c_cc[VERASE] = (char)erase; |
1208 |
|
|
|
1209 |
|
|
/* input modes */ |
1210 |
|
|
tio->c_iflag = (BRKINT | IGNPAR | ICRNL |
1211 |
pcg |
1.1 |
# ifdef IMAXBEL |
1212 |
pcg |
1.9 |
| IMAXBEL |
1213 |
pcg |
1.1 |
# endif |
1214 |
pcg |
1.9 |
| IXON); |
1215 |
pcg |
1.1 |
|
1216 |
pcg |
1.9 |
/* output modes */ |
1217 |
|
|
tio->c_oflag = (OPOST | ONLCR); |
1218 |
pcg |
1.1 |
|
1219 |
pcg |
1.9 |
/* control modes */ |
1220 |
|
|
tio->c_cflag = (CS8 | CREAD); |
1221 |
pcg |
1.1 |
|
1222 |
pcg |
1.9 |
/* line discipline modes */ |
1223 |
|
|
tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO |
1224 |
pcg |
1.1 |
# if defined (ECHOCTL) && defined (ECHOKE) |
1225 |
pcg |
1.9 |
| ECHOCTL | ECHOKE |
1226 |
pcg |
1.1 |
# endif |
1227 |
pcg |
1.9 |
| ECHOE | ECHOK); |
1228 |
pcg |
1.1 |
|
1229 |
pcg |
1.9 |
/* |
1230 |
|
|
* Debugging |
1231 |
|
|
*/ |
1232 |
pcg |
1.1 |
#ifdef DEBUG_TTYMODE |
1233 |
pcg |
1.9 |
/* c_iflag bits */ |
1234 |
pcg |
1.26 |
fprintf (stderr, "Input flags\n"); |
1235 |
pcg |
1.1 |
|
1236 |
pcg |
1.9 |
/* cpp token stringize doesn't work on all machines <sigh> */ |
1237 |
pcg |
1.4 |
# define FOO(flag,name) \ |
1238 |
|
|
if ((tio->c_iflag) & flag) \ |
1239 |
|
|
fprintf (stderr, "%s ", name) |
1240 |
pcg |
1.1 |
|
1241 |
pcg |
1.9 |
/* c_iflag bits */ |
1242 |
pcg |
1.26 |
FOO (IGNBRK, "IGNBRK"); |
1243 |
|
|
FOO (BRKINT, "BRKINT"); |
1244 |
|
|
FOO (IGNPAR, "IGNPAR"); |
1245 |
|
|
FOO (PARMRK, "PARMRK"); |
1246 |
|
|
FOO (INPCK, "INPCK"); |
1247 |
|
|
FOO (ISTRIP, "ISTRIP"); |
1248 |
|
|
FOO (INLCR, "INLCR"); |
1249 |
|
|
FOO (IGNCR, "IGNCR"); |
1250 |
|
|
FOO (ICRNL, "ICRNL"); |
1251 |
|
|
FOO (IXON, "IXON"); |
1252 |
|
|
FOO (IXOFF, "IXOFF"); |
1253 |
pcg |
1.1 |
# ifdef IUCLC |
1254 |
pcg |
1.26 |
FOO (IUCLC, "IUCLC"); |
1255 |
pcg |
1.1 |
# endif |
1256 |
|
|
# ifdef IXANY |
1257 |
pcg |
1.26 |
FOO (IXANY, "IXANY"); |
1258 |
pcg |
1.1 |
# endif |
1259 |
|
|
# ifdef IMAXBEL |
1260 |
pcg |
1.26 |
FOO (IMAXBEL, "IMAXBEL"); |
1261 |
pcg |
1.1 |
# endif |
1262 |
pcg |
1.9 |
|
1263 |
pcg |
1.26 |
fprintf (stderr, "\n"); |
1264 |
pcg |
1.1 |
|
1265 |
|
|
# undef FOO |
1266 |
pcg |
1.4 |
# define FOO(entry, name) \ |
1267 |
pcg |
1.26 |
fprintf (stderr, "%-8s = %#04o\n", name, tio->c_cc [entry]) |
1268 |
pcg |
1.1 |
|
1269 |
pcg |
1.26 |
FOO (VINTR, "VINTR"); |
1270 |
|
|
FOO (VQUIT, "VQUIT"); |
1271 |
|
|
FOO (VERASE, "VERASE"); |
1272 |
|
|
FOO (VKILL, "VKILL"); |
1273 |
|
|
FOO (VEOF, "VEOF"); |
1274 |
|
|
FOO (VEOL, "VEOL"); |
1275 |
pcg |
1.1 |
# ifdef VEOL2 |
1276 |
pcg |
1.26 |
FOO (VEOL2, "VEOL2"); |
1277 |
pcg |
1.1 |
# endif |
1278 |
|
|
# ifdef VSWTC |
1279 |
pcg |
1.26 |
FOO (VSWTC, "VSWTC"); |
1280 |
pcg |
1.1 |
# endif |
1281 |
|
|
# ifdef VSWTCH |
1282 |
pcg |
1.26 |
FOO (VSWTCH, "VSWTCH"); |
1283 |
pcg |
1.1 |
# endif |
1284 |
pcg |
1.26 |
FOO (VSTART, "VSTART"); |
1285 |
|
|
FOO (VSTOP, "VSTOP"); |
1286 |
|
|
FOO (VSUSP, "VSUSP"); |
1287 |
pcg |
1.1 |
# ifdef VDSUSP |
1288 |
pcg |
1.26 |
FOO (VDSUSP, "VDSUSP"); |
1289 |
pcg |
1.1 |
# endif |
1290 |
|
|
# ifdef VREPRINT |
1291 |
pcg |
1.26 |
FOO (VREPRINT, "VREPRINT"); |
1292 |
pcg |
1.1 |
# endif |
1293 |
|
|
# ifdef VDISCRD |
1294 |
pcg |
1.26 |
FOO (VDISCRD, "VDISCRD"); |
1295 |
pcg |
1.1 |
# endif |
1296 |
|
|
# ifdef VWERSE |
1297 |
pcg |
1.26 |
FOO (VWERSE, "VWERSE"); |
1298 |
pcg |
1.1 |
# endif |
1299 |
|
|
# ifdef VLNEXT |
1300 |
pcg |
1.26 |
FOO (VLNEXT, "VLNEXT"); |
1301 |
pcg |
1.1 |
# endif |
1302 |
pcg |
1.9 |
|
1303 |
pcg |
1.26 |
fprintf (stderr, "\n"); |
1304 |
pcg |
1.1 |
# undef FOO |
1305 |
ayin |
1.222 |
#endif /* DEBUG_TTYMODE */ |
1306 |
pcg |
1.1 |
} |
1307 |
|
|
|
1308 |
root |
1.79 |
/*----------------------------------------------------------------------*/ |
1309 |
|
|
/* |
1310 |
|
|
* Run the command in a subprocess and return a file descriptor for the |
1311 |
|
|
* master end of the pseudo-teletype pair with the command talking to |
1312 |
|
|
* the slave. |
1313 |
|
|
*/ |
1314 |
|
|
void |
1315 |
|
|
rxvt_term::run_command (const char *const *argv) |
1316 |
|
|
{ |
1317 |
root |
1.110 |
#if ENABLE_FRILLS |
1318 |
|
|
if (rs[Rs_pty_fd]) |
1319 |
|
|
{ |
1320 |
root |
1.145 |
pty->pty = atoi (rs[Rs_pty_fd]); |
1321 |
root |
1.127 |
|
1322 |
root |
1.145 |
if (pty->pty >= 0) |
1323 |
root |
1.132 |
{ |
1324 |
|
|
if (getfd_hook) |
1325 |
root |
1.145 |
pty->pty = (*getfd_hook) (pty->pty); |
1326 |
root |
1.127 |
|
1327 |
root |
1.145 |
if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK)) |
1328 |
root |
1.132 |
rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); |
1329 |
|
|
} |
1330 |
root |
1.110 |
} |
1331 |
|
|
else |
1332 |
|
|
#endif |
1333 |
root |
1.145 |
if (!pty->get ()) |
1334 |
root |
1.110 |
rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); |
1335 |
root |
1.79 |
|
1336 |
root |
1.105 |
int er; |
1337 |
|
|
|
1338 |
root |
1.79 |
#ifndef NO_BACKSPACE_KEY |
1339 |
ayin |
1.211 |
if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) |
1340 |
|
|
er = rs[Rs_backspace_key][0]; |
1341 |
|
|
else if (strcmp (rs[Rs_backspace_key], "DEC") == 0) |
1342 |
root |
1.79 |
er = '\177'; /* the initial state anyway */ |
1343 |
|
|
else |
1344 |
|
|
#endif |
1345 |
|
|
er = -1; |
1346 |
|
|
|
1347 |
|
|
rxvt_get_ttymode (&tio, er); |
1348 |
root |
1.179 |
SET_TERMIOS (pty->tty, &tio); /* init terminal attributes */ |
1349 |
root |
1.175 |
pty->set_utf8_mode (enc_utf8); |
1350 |
|
|
|
1351 |
|
|
/* set initial window size */ |
1352 |
|
|
tt_winch (); |
1353 |
root |
1.79 |
|
1354 |
root |
1.110 |
#if ENABLE_FRILLS |
1355 |
|
|
if (rs[Rs_pty_fd]) |
1356 |
|
|
return; |
1357 |
|
|
#endif |
1358 |
|
|
|
1359 |
root |
1.79 |
/* spin off the command interpreter */ |
1360 |
|
|
switch (cmd_pid = fork ()) |
1361 |
|
|
{ |
1362 |
|
|
case -1: |
1363 |
root |
1.110 |
{ |
1364 |
|
|
cmd_pid = 0; |
1365 |
|
|
rxvt_fatal ("can't fork, aborting.\n"); |
1366 |
|
|
} |
1367 |
root |
1.79 |
case 0: |
1368 |
|
|
init_env (); |
1369 |
|
|
|
1370 |
root |
1.145 |
if (!pty->make_controlling_tty ()) |
1371 |
root |
1.79 |
fprintf (stderr, "%s: could not obtain control of tty.", RESNAME); |
1372 |
|
|
else |
1373 |
|
|
{ |
1374 |
|
|
/* Reopen stdin, stdout and stderr over the tty file descriptor */ |
1375 |
root |
1.145 |
dup2 (pty->tty, STDIN_FILENO); |
1376 |
|
|
dup2 (pty->tty, STDOUT_FILENO); |
1377 |
|
|
dup2 (pty->tty, STDERR_FILENO); |
1378 |
root |
1.79 |
|
1379 |
|
|
// close all our file handles that we do no longer need |
1380 |
|
|
for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
1381 |
|
|
{ |
1382 |
root |
1.145 |
if ((*t)->pty->pty > 2) close ((*t)->pty->pty); |
1383 |
|
|
if ((*t)->pty->tty > 2) close ((*t)->pty->tty); |
1384 |
root |
1.79 |
} |
1385 |
|
|
|
1386 |
|
|
run_child (argv); |
1387 |
|
|
fprintf (stderr, "%s: unable to exec child.", RESNAME); |
1388 |
|
|
} |
1389 |
|
|
|
1390 |
|
|
_exit (EXIT_FAILURE); |
1391 |
|
|
|
1392 |
|
|
default: |
1393 |
root |
1.182 |
if (!option (Opt_utmpInhibit)) |
1394 |
|
|
pty->login (cmd_pid, option (Opt_loginShell), rs[Rs_display_name]); |
1395 |
root |
1.79 |
|
1396 |
root |
1.145 |
pty->close_tty (); |
1397 |
root |
1.149 |
|
1398 |
|
|
child_ev.start (cmd_pid); |
1399 |
|
|
|
1400 |
|
|
HOOK_INVOKE ((this, HOOK_CHILD_START, DT_INT, cmd_pid, DT_END)); |
1401 |
root |
1.79 |
break; |
1402 |
|
|
} |
1403 |
|
|
} |
1404 |
|
|
|
1405 |
|
|
/* ------------------------------------------------------------------------- * |
1406 |
|
|
* CHILD PROCESS OPERATIONS * |
1407 |
|
|
* ------------------------------------------------------------------------- */ |
1408 |
|
|
/* |
1409 |
|
|
* The only open file descriptor is the slave tty - so no error messages. |
1410 |
|
|
* returns are fatal |
1411 |
|
|
*/ |
1412 |
|
|
int |
1413 |
|
|
rxvt_term::run_child (const char *const *argv) |
1414 |
|
|
{ |
1415 |
|
|
char *login; |
1416 |
|
|
|
1417 |
root |
1.182 |
if (option (Opt_console)) |
1418 |
ayin |
1.224 |
{ |
1419 |
|
|
/* be virtual console, fail silently */ |
1420 |
root |
1.79 |
#ifdef TIOCCONS |
1421 |
|
|
unsigned int on = 1; |
1422 |
|
|
|
1423 |
|
|
ioctl (STDIN_FILENO, TIOCCONS, &on); |
1424 |
|
|
#elif defined (SRIOCSREDIR) |
1425 |
|
|
int fd; |
1426 |
|
|
|
1427 |
|
|
fd = open (CONSOLE, O_WRONLY, 0); |
1428 |
|
|
if (fd >= 0) |
1429 |
|
|
if (ioctl (fd, SRIOCSREDIR, NULL) < 0) |
1430 |
|
|
close (fd); |
1431 |
ayin |
1.222 |
#endif /* SRIOCSREDIR */ |
1432 |
root |
1.79 |
} |
1433 |
|
|
|
1434 |
|
|
/* reset signals and spin off the command interpreter */ |
1435 |
|
|
signal (SIGINT, SIG_DFL); |
1436 |
|
|
signal (SIGQUIT, SIG_DFL); |
1437 |
|
|
signal (SIGCHLD, SIG_DFL); |
1438 |
|
|
signal (SIGHUP, SIG_DFL); |
1439 |
|
|
signal (SIGPIPE, SIG_DFL); |
1440 |
|
|
/* |
1441 |
|
|
* mimick login's behavior by disabling the job control signals |
1442 |
|
|
* a shell that wants them can turn them back on |
1443 |
|
|
*/ |
1444 |
|
|
#ifdef SIGTSTP |
1445 |
|
|
signal (SIGTSTP, SIG_IGN); |
1446 |
|
|
signal (SIGTTIN, SIG_IGN); |
1447 |
|
|
signal (SIGTTOU, SIG_IGN); |
1448 |
ayin |
1.222 |
#endif /* SIGTSTP */ |
1449 |
root |
1.79 |
|
1450 |
|
|
// unblock signals (signals are blocked by iom.C |
1451 |
|
|
sigset_t ss; |
1452 |
|
|
sigemptyset (&ss); |
1453 |
|
|
sigprocmask (SIG_SETMASK, &ss, 0); |
1454 |
|
|
|
1455 |
|
|
/* command interpreter path */ |
1456 |
root |
1.213 |
if (argv) |
1457 |
root |
1.79 |
{ |
1458 |
|
|
# ifdef DEBUG_CMD |
1459 |
|
|
int i; |
1460 |
|
|
|
1461 |
|
|
for (i = 0; argv[i]; i++) |
1462 |
|
|
fprintf (stderr, "argv [%d] = \"%s\"\n", i, argv[i]); |
1463 |
|
|
# endif |
1464 |
|
|
|
1465 |
|
|
execvp (argv[0], (char *const *)argv); |
1466 |
|
|
/* no error message: STDERR is closed! */ |
1467 |
|
|
} |
1468 |
|
|
else |
1469 |
|
|
{ |
1470 |
root |
1.137 |
const char *argv0, *shell; |
1471 |
root |
1.79 |
|
1472 |
|
|
if ((shell = getenv ("SHELL")) == NULL || *shell == '\0') |
1473 |
|
|
shell = "/bin/sh"; |
1474 |
|
|
|
1475 |
ayin |
1.210 |
argv0 = (const char *)rxvt_basename (shell); |
1476 |
root |
1.79 |
|
1477 |
root |
1.182 |
if (option (Opt_loginShell)) |
1478 |
root |
1.79 |
{ |
1479 |
ayin |
1.208 |
login = (char *)rxvt_malloc (strlen (argv0) + 2); |
1480 |
root |
1.79 |
|
1481 |
|
|
login[0] = '-'; |
1482 |
|
|
strcpy (&login[1], argv0); |
1483 |
|
|
argv0 = login; |
1484 |
|
|
} |
1485 |
root |
1.137 |
|
1486 |
root |
1.213 |
execlp (shell, argv0, (char *)0); |
1487 |
root |
1.79 |
/* no error message: STDERR is closed! */ |
1488 |
|
|
} |
1489 |
|
|
|
1490 |
|
|
return -1; |
1491 |
|
|
} |
1492 |
|
|
|
1493 |
pcg |
1.1 |
/*----------------------- end-of-file (C source) -----------------------*/ |