1 |
/*--------------------------------*-C-*---------------------------------* |
2 |
* File: command.C |
3 |
*----------------------------------------------------------------------* |
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 |
* - original version |
8 |
* Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 |
* - extensive modifications |
10 |
* Copyright (c) 1995 Garrett D'Amore <garrett@netcom.com> |
11 |
* - vt100 printing |
12 |
* Copyright (c) 1995 Steven Hirsch <hirsch@emba.uvm.edu> |
13 |
* - X11 mouse report mode and support for |
14 |
* DEC "private mode" save/restore functions. |
15 |
* Copyright (c) 1995 Jakub Jelinek <jj@gnu.ai.mit.edu> |
16 |
* - key-related changes to handle Shift+function |
17 |
* keys properly. |
18 |
* Copyright (c) 1997 MJ Olesen <olesen@me.queensu.ca> |
19 |
* - extensive modifications |
20 |
* Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es> |
21 |
* - modification and cleanups for Solaris 2.x |
22 |
* and Linux 1.2.x |
23 |
* Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
24 |
* Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
25 |
* - extensive modifications |
26 |
* Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> |
27 |
* Copyright (c) 2001 Marius Gedminas |
28 |
* - Ctrl/Mod4+Tab works like Meta+Tab (options) |
29 |
* Copyright (c) 2003 Rob McMullen <robm@flipturn.org> |
30 |
* Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
31 |
* |
32 |
* This program is free software; you can redistribute it and/or modify |
33 |
* it under the terms of the GNU General Public License as published by |
34 |
* the Free Software Foundation; either version 2 of the License, or |
35 |
* (at your option) any later version. |
36 |
* |
37 |
* This program is distributed in the hope that it will be useful, |
38 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
39 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
40 |
* GNU General Public License for more details. |
41 |
* |
42 |
* You should have received a copy of the GNU General Public License |
43 |
* along with this program; if not, write to the Free Software |
44 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
45 |
*----------------------------------------------------------------------*/ |
46 |
|
47 |
/*{{{ includes: */ |
48 |
#include "../config.h" |
49 |
#include "rxvt.h" |
50 |
#include "rxvtperl.h" |
51 |
#include "version.h" |
52 |
#include "command.h" |
53 |
|
54 |
#if HAVE_SCHED_YIELD |
55 |
#undef HAVE_SCHED_YIELD // disabled for the time being |
56 |
//# include <sched.h> |
57 |
#endif |
58 |
|
59 |
#ifdef KEYSYM_RESOURCE |
60 |
# include "keyboard.h" |
61 |
#endif |
62 |
|
63 |
#include <csignal> |
64 |
|
65 |
/*----------------------------------------------------------------------*/ |
66 |
|
67 |
#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) |
68 |
|
69 |
#if ENABLE_FRILLS || ISO_14755 |
70 |
|
71 |
#define ISO_14755_STARTED 0x80000000UL |
72 |
#define ISO_14755_51 0x40000000UL // basic (section 5.1) |
73 |
#define ISO_14755_52 0x20000000UL // keycap (section 5.2) |
74 |
#define ISO_14755_54 0x10000000UL // code feedback (section 5.4) |
75 |
#define ISO_14755_MASK 0x0fffffffUL |
76 |
|
77 |
#if ISO_14755 |
78 |
static unsigned short iso14755_symtab[] = { |
79 |
// keysym, unicode |
80 |
XK_Left, 0x2190, |
81 |
XK_KP_Left, 0x2190, |
82 |
XK_Up, 0x2191, |
83 |
XK_KP_Up, 0x2191, |
84 |
XK_Right, 0x2192, |
85 |
XK_KP_Right, 0x2192, |
86 |
XK_Down, 0x2193, |
87 |
XK_KP_Down, 0x2193, |
88 |
XK_Linefeed, 0x21b4, |
89 |
XK_Return, 0x21b5, |
90 |
XK_KP_Enter, 0x21b5, |
91 |
|
92 |
XK_Prior, 0x21de, |
93 |
XK_Next, 0x21df, |
94 |
XK_Tab, 0x21e5, |
95 |
XK_ISO_Left_Tab, 0x21e6, |
96 |
XK_Shift_L, 0x21e7, |
97 |
XK_Shift_R, 0x21e7, |
98 |
|
99 |
XK_Shift_Lock, 0x21eb, |
100 |
XK_ISO_Lock, 0x21eb, |
101 |
XK_ISO_Lock, 0x21eb, |
102 |
XK_Caps_Lock, 0x21ec, |
103 |
XK_Num_Lock, 0x21ed, |
104 |
XK_ISO_Level3_Shift, 0x21ee, |
105 |
XK_ISO_Level3_Lock, 0x21ef, |
106 |
XK_ISO_Group_Lock, 0x21f0, |
107 |
XK_Home, 0x21f1, |
108 |
XK_End, 0x21f2, |
109 |
|
110 |
XK_Execute, 0x2318, |
111 |
XK_Begin, 0x2320, |
112 |
XK_Delete, 0x2326, |
113 |
XK_Clear, 0x2327, |
114 |
XK_BackSpace, 0x232b, |
115 |
XK_Insert, 0x2380, |
116 |
XK_Control_L, 0x2388, |
117 |
XK_Control_R, 0x2388, |
118 |
XK_Pause, 0x2389, |
119 |
XK_Break, 0x238a, |
120 |
XK_Escape, 0x238b, |
121 |
XK_Undo, 0x238c, |
122 |
XK_Print, 0x2399, |
123 |
|
124 |
XK_space, 0x2423, |
125 |
|
126 |
#ifdef XK_KP_Begin |
127 |
XK_KP_Prior, 0x21de, |
128 |
XK_KP_Next, 0x21df, |
129 |
XK_KP_Begin, 0x2320, |
130 |
XK_KP_Insert, 0x2380, |
131 |
XK_KP_Delete, 0x2326, |
132 |
XK_KP_Space, 0x2422, |
133 |
#endif |
134 |
0, |
135 |
}; |
136 |
|
137 |
void |
138 |
rxvt_term::iso14755_54 (int x, int y) |
139 |
{ |
140 |
x = Pixel2Col (x); |
141 |
y = Pixel2Row (y); |
142 |
|
143 |
if (!IN_RANGE_EXC (x, 0, ncol) |
144 |
|| !IN_RANGE_EXC (y, 0, nrow)) |
145 |
return; |
146 |
|
147 |
for (;;) |
148 |
{ |
149 |
const line_t &l = ROW(y + view_start); |
150 |
|
151 |
text_t t = l.t[x]; |
152 |
|
153 |
if (t != NOCHAR || !x) |
154 |
{ |
155 |
iso14755_51 (l.t[x], l.r[x], x, y); |
156 |
iso14755buf = ISO_14755_54; |
157 |
break; |
158 |
} |
159 |
|
160 |
x--; |
161 |
} |
162 |
} |
163 |
|
164 |
void |
165 |
rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) |
166 |
{ |
167 |
rxvt_fontset *fs = FONTSET (r); |
168 |
rxvt_font *f = (*fs)[fs->find_font (ch)]; |
169 |
wchar_t *chr, *alloc, ch2, *fname; |
170 |
int len; |
171 |
|
172 |
fname = rxvt_utf8towcs (f->name); |
173 |
|
174 |
# if ENABLE_COMBINING |
175 |
if (IS_COMPOSE (ch)) |
176 |
{ |
177 |
len = rxvt_composite.expand (ch, 0); |
178 |
alloc = chr = new wchar_t[len]; |
179 |
rxvt_composite.expand (ch, chr); |
180 |
} |
181 |
else |
182 |
# endif |
183 |
{ |
184 |
ch2 = ch; |
185 |
|
186 |
alloc = 0; |
187 |
chr = &ch2; |
188 |
len = 1; |
189 |
} |
190 |
|
191 |
char attr[80]; // plenty |
192 |
|
193 |
sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", |
194 |
(int)r, |
195 |
fgcolor_of (r), bgcolor_of (r), |
196 |
r & RS_Bold ? " bold" : "", |
197 |
r & RS_Italic ? " italic" : "", |
198 |
r & RS_Blink ? " blink" : "", |
199 |
r & RS_RVid ? " rvid" : "", |
200 |
r & RS_Uline ? " uline" : "", |
201 |
r & RS_Careful ? " careful" : ""); |
202 |
|
203 |
int width = wcswidth (fname, wcslen (fname)); |
204 |
|
205 |
max_it (width, 8+5); // for char + hey |
206 |
max_it (width, strlen (attr)); |
207 |
|
208 |
if (y >= 0) |
209 |
{ |
210 |
y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; |
211 |
x = 0; |
212 |
} |
213 |
|
214 |
scr_overlay_new (x, y, width, len + 2); |
215 |
|
216 |
r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); |
217 |
|
218 |
for (int y = 0; y < len; y++) |
219 |
{ |
220 |
char buf[9]; |
221 |
|
222 |
ch = *chr++; |
223 |
|
224 |
sprintf (buf, "%8x", ch); |
225 |
scr_overlay_set (0, y, buf); |
226 |
scr_overlay_set (9, y, '='); |
227 |
# if !UNICODE3 |
228 |
if (ch >= 0x10000) |
229 |
ch = 0xfffd; |
230 |
# endif |
231 |
scr_overlay_set (11, y, ch, r); |
232 |
scr_overlay_set (12, y, NOCHAR, r); |
233 |
} |
234 |
|
235 |
scr_overlay_set (0, len , attr); |
236 |
scr_overlay_set (0, len + 1, fname); |
237 |
|
238 |
free (fname); |
239 |
|
240 |
# if ENABLE_COMBINING |
241 |
if (alloc) |
242 |
delete [] alloc; |
243 |
# endif |
244 |
} |
245 |
#endif |
246 |
|
247 |
void |
248 |
rxvt_term::commit_iso14755 () |
249 |
{ |
250 |
wchar_t ch[2]; |
251 |
|
252 |
ch[0] = iso14755buf & ISO_14755_MASK; |
253 |
ch[1] = 0; |
254 |
|
255 |
if (iso14755buf & ISO_14755_51) |
256 |
{ |
257 |
char mb[16]; |
258 |
int len; |
259 |
|
260 |
// allow verbatim 0-bytes and control-bytes to be entered |
261 |
if (ch[0] >= 0x20) |
262 |
len = wcstombs (mb, ch, 16); |
263 |
else |
264 |
{ |
265 |
mb[0] = ch[0]; |
266 |
len = 1; |
267 |
} |
268 |
|
269 |
if (len > 0) |
270 |
tt_write (mb, len); |
271 |
else |
272 |
scr_bell (); |
273 |
} |
274 |
|
275 |
iso14755buf = 0; |
276 |
} |
277 |
|
278 |
int |
279 |
rxvt_term::hex_keyval (XKeyEvent &ev) |
280 |
{ |
281 |
// check wether this event corresponds to a hex digit |
282 |
// if the modifiers had not been pressed. |
283 |
for (int index = 0; index < 8; index++) |
284 |
{ |
285 |
KeySym k = XLookupKeysym (&ev, index); |
286 |
|
287 |
if (k >= XK_KP_0 && k <= XK_KP_9) return k - XK_KP_0; |
288 |
else if (k >= XK_0 && k <= XK_9) return k - XK_0; |
289 |
else if (k >= XK_a && k <= XK_f) return k - XK_a + 10; |
290 |
else if (k >= XK_A && k <= XK_F) return k - XK_A + 10; |
291 |
} |
292 |
|
293 |
return -1; |
294 |
} |
295 |
#endif |
296 |
|
297 |
/*{{{ Convert the keypress event into a string */ |
298 |
void |
299 |
rxvt_term::lookup_key (XKeyEvent &ev) |
300 |
{ |
301 |
int ctrl, meta, shft, len; |
302 |
unsigned int newlen; |
303 |
KeySym keysym; |
304 |
int valid_keysym; |
305 |
char kbuf[KBUFSZ]; |
306 |
|
307 |
/* |
308 |
* use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an |
309 |
* escape sequence to toggle the Keypad. |
310 |
* |
311 |
* Always permit `shift' to override the current setting |
312 |
*/ |
313 |
shft = ev.state & ShiftMask; |
314 |
ctrl = ev.state & ControlMask; |
315 |
meta = ev.state & ModMetaMask; |
316 |
|
317 |
if (numlock_state || (ev.state & ModNumLockMask)) |
318 |
{ |
319 |
numlock_state = (ev.state & ModNumLockMask); |
320 |
PrivMode ((!numlock_state), PrivMode_aplKP); |
321 |
} |
322 |
|
323 |
kbuf[0] = 0; |
324 |
|
325 |
#ifdef USE_XIM |
326 |
if (Input_Context) |
327 |
{ |
328 |
Status status_return; |
329 |
|
330 |
#if 0 |
331 |
#ifdef X_HAVE_UTF8_STRING |
332 |
if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful |
333 |
len = Xutf8LookupString (Input_Context, &ev, kbuf, |
334 |
KBUFSZ, &keysym, &status_return); |
335 |
else |
336 |
#endif |
337 |
#endif |
338 |
{ |
339 |
wchar_t wkbuf[KBUFSZ + 1]; |
340 |
|
341 |
// the XOpenIM manpage lies about hardcoding the locale |
342 |
// at the point of XOpenIM, so temporarily switch locales |
343 |
if (rs[Rs_imLocale]) |
344 |
SET_LOCALE (rs[Rs_imLocale]); |
345 |
|
346 |
// assume wchar_t == unicode or better |
347 |
len = XwcLookupString (Input_Context, &ev, wkbuf, |
348 |
KBUFSZ, &keysym, &status_return); |
349 |
|
350 |
if (rs[Rs_imLocale]) |
351 |
SET_LOCALE (locale); |
352 |
|
353 |
if (status_return == XLookupChars |
354 |
|| status_return == XLookupBoth) |
355 |
{ |
356 |
/* make sure the user can type ctrl-@, i.e. NUL */ |
357 |
if (len == 1 && *wkbuf == 0) |
358 |
{ |
359 |
kbuf[0] = 0; |
360 |
len = 1; |
361 |
} |
362 |
else |
363 |
{ |
364 |
wkbuf[len] = 0; |
365 |
len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); |
366 |
if (len < 0) |
367 |
len = 0; |
368 |
} |
369 |
} |
370 |
else |
371 |
len = 0; |
372 |
} |
373 |
|
374 |
valid_keysym = status_return == XLookupKeySym |
375 |
|| status_return == XLookupBoth; |
376 |
} |
377 |
else |
378 |
#endif |
379 |
{ |
380 |
len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose); |
381 |
valid_keysym = keysym != NoSymbol; |
382 |
} |
383 |
|
384 |
if (valid_keysym) |
385 |
{ |
386 |
#ifdef KEYSYM_RESOURCE |
387 |
if (keyboard->dispatch (this, keysym, ev.state)) |
388 |
return; |
389 |
#endif |
390 |
|
391 |
if (saveLines) |
392 |
{ |
393 |
#ifdef UNSHIFTED_SCROLLKEYS |
394 |
if (!ctrl && !meta) |
395 |
#else |
396 |
if (IS_SCROLL_MOD) |
397 |
#endif |
398 |
{ |
399 |
int lnsppg; |
400 |
|
401 |
#ifdef PAGING_CONTEXT_LINES |
402 |
lnsppg = nrow - PAGING_CONTEXT_LINES; |
403 |
#else |
404 |
lnsppg = nrow * 4 / 5; |
405 |
#endif |
406 |
if (keysym == XK_Prior) |
407 |
{ |
408 |
scr_page (UP, lnsppg); |
409 |
return; |
410 |
} |
411 |
else if (keysym == XK_Next) |
412 |
{ |
413 |
scr_page (DN, lnsppg); |
414 |
return; |
415 |
} |
416 |
} |
417 |
#ifdef SCROLL_ON_UPDOWN_KEYS |
418 |
if (IS_SCROLL_MOD) |
419 |
{ |
420 |
if (keysym == XK_Up) |
421 |
{ |
422 |
scr_page (UP, 1); |
423 |
return; |
424 |
} |
425 |
else if (keysym == XK_Down) |
426 |
{ |
427 |
scr_page (DN, 1); |
428 |
return; |
429 |
} |
430 |
} |
431 |
#endif |
432 |
#ifdef SCROLL_ON_HOMEEND_KEYS |
433 |
if (IS_SCROLL_MOD) |
434 |
{ |
435 |
if (keysym == XK_Home) |
436 |
{ |
437 |
scr_move_to (0, 1); |
438 |
return; |
439 |
} |
440 |
else if (keysym == XK_End) |
441 |
{ |
442 |
scr_move_to (1, 1); |
443 |
return; |
444 |
} |
445 |
} |
446 |
#endif |
447 |
} |
448 |
|
449 |
if (shft) |
450 |
{ |
451 |
/* Shift + F1 - F10 generates F11 - F20 */ |
452 |
if (keysym >= XK_F1 && keysym <= XK_F10) |
453 |
{ |
454 |
keysym += (XK_F11 - XK_F1); |
455 |
shft = 0; /* turn off Shift */ |
456 |
} |
457 |
else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys)) |
458 |
{ |
459 |
switch (keysym) |
460 |
{ |
461 |
/* normal XTerm key bindings */ |
462 |
case XK_Insert: /* Shift+Insert = paste mouse selection */ |
463 |
selection_request (ev.time); |
464 |
return; |
465 |
#if TODO |
466 |
/* rxvt extras */ |
467 |
case XK_KP_Add: /* Shift+KP_Add = bigger font */ |
468 |
change_font (FONT_UP); |
469 |
return; |
470 |
case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ |
471 |
change_font (FONT_DN); |
472 |
return; |
473 |
#endif |
474 |
} |
475 |
} |
476 |
} |
477 |
|
478 |
#if ENABLE_FRILLS || ISO_14755 |
479 |
// ISO 14755 support |
480 |
if (shft && ctrl) |
481 |
{ |
482 |
int hv; |
483 |
|
484 |
if (iso14755buf & ISO_14755_51 |
485 |
&& (keysym == XK_space || keysym == XK_KP_Space |
486 |
|| keysym == XK_Return || keysym == XK_KP_Enter)) |
487 |
{ |
488 |
commit_iso14755 (); |
489 |
iso14755buf = ISO_14755_51; |
490 |
# if ISO_14755 |
491 |
iso14755_51 (0); |
492 |
# endif |
493 |
return; |
494 |
} |
495 |
else if ((hv = hex_keyval (ev)) >= 0) |
496 |
{ |
497 |
iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK) |
498 |
| hv | ISO_14755_51; |
499 |
# if ISO_14755 |
500 |
iso14755_51 (iso14755buf & ISO_14755_MASK); |
501 |
# endif |
502 |
return; |
503 |
} |
504 |
else |
505 |
{ |
506 |
# if ENABLE_OVERLAY |
507 |
scr_overlay_off (); |
508 |
# endif |
509 |
iso14755buf = 0; |
510 |
} |
511 |
} |
512 |
else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) |
513 |
|| (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) |
514 |
if (!(iso14755buf & ISO_14755_STARTED)) |
515 |
{ |
516 |
iso14755buf |= ISO_14755_STARTED; |
517 |
# if ENABLE_OVERLAY |
518 |
scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); |
519 |
scr_overlay_set (0, 0, "ISO 14755 mode"); |
520 |
# endif |
521 |
} |
522 |
#endif |
523 |
|
524 |
#ifdef PRINTPIPE |
525 |
if (keysym == XK_Print) |
526 |
{ |
527 |
scr_printscreen (ctrl | shft); |
528 |
return; |
529 |
} |
530 |
#endif |
531 |
|
532 |
if (keysym >= 0xFF00 && keysym <= 0xFFFF) |
533 |
{ |
534 |
{ |
535 |
newlen = 1; |
536 |
switch (keysym) |
537 |
{ |
538 |
#ifndef NO_BACKSPACE_KEY |
539 |
case XK_BackSpace: |
540 |
if (priv_modes & PrivMode_HaveBackSpace) |
541 |
{ |
542 |
kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) |
543 |
^ !!ctrl) ? '\b' : '\177'; |
544 |
kbuf[1] = '\0'; |
545 |
} |
546 |
else |
547 |
strcpy (kbuf, key_backspace); |
548 |
break; |
549 |
#endif |
550 |
#ifndef NO_DELETE_KEY |
551 |
# ifdef XK_KP_Prior |
552 |
case XK_KP_Delete: |
553 |
/* allow shift to override */ |
554 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
555 |
{ |
556 |
strcpy (kbuf, "\033On"); |
557 |
break; |
558 |
} |
559 |
/* FALLTHROUGH */ |
560 |
# endif |
561 |
case XK_Delete: |
562 |
strcpy (kbuf, key_delete); |
563 |
break; |
564 |
#endif |
565 |
case XK_Tab: |
566 |
if (shft) |
567 |
strcpy (kbuf, "\033[Z"); |
568 |
else |
569 |
{ |
570 |
#ifdef CTRL_TAB_MAKES_META |
571 |
if (ctrl) |
572 |
meta = 1; |
573 |
#endif |
574 |
#ifdef MOD4_TAB_MAKES_META |
575 |
if (ev.state & Mod4Mask) |
576 |
meta = 1; |
577 |
#endif |
578 |
newlen = 0; |
579 |
} |
580 |
break; |
581 |
|
582 |
#ifdef XK_KP_Left |
583 |
case XK_KP_Up: /* \033Ox or standard */ |
584 |
case XK_KP_Down: /* \033Or or standard */ |
585 |
case XK_KP_Right: /* \033Ov or standard */ |
586 |
case XK_KP_Left: /* \033Ot or standard */ |
587 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
588 |
{ |
589 |
strcpy (kbuf, "\033OZ"); |
590 |
kbuf[2] = "txvr"[keysym - XK_KP_Left]; |
591 |
break; |
592 |
} |
593 |
else |
594 |
/* translate to std. cursor key */ |
595 |
keysym = XK_Left + (keysym - XK_KP_Left); |
596 |
/* FALLTHROUGH */ |
597 |
#endif |
598 |
case XK_Up: /* "\033[A" */ |
599 |
case XK_Down: /* "\033[B" */ |
600 |
case XK_Right: /* "\033[C" */ |
601 |
case XK_Left: /* "\033[D" */ |
602 |
strcpy (kbuf, "\033[Z"); |
603 |
kbuf[2] = "DACB"[keysym - XK_Left]; |
604 |
/* do Shift first */ |
605 |
if (shft) |
606 |
kbuf[2] = "dacb"[keysym - XK_Left]; |
607 |
else if (ctrl) |
608 |
{ |
609 |
kbuf[1] = 'O'; |
610 |
kbuf[2] = "dacb"[keysym - XK_Left]; |
611 |
} |
612 |
else if (priv_modes & PrivMode_aplCUR) |
613 |
kbuf[1] = 'O'; |
614 |
break; |
615 |
|
616 |
#ifndef UNSHIFTED_SCROLLKEYS |
617 |
# ifdef XK_KP_Prior |
618 |
case XK_KP_Prior: |
619 |
/* allow shift to override */ |
620 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
621 |
{ |
622 |
strcpy (kbuf, "\033Oy"); |
623 |
break; |
624 |
} |
625 |
/* FALLTHROUGH */ |
626 |
# endif |
627 |
case XK_Prior: |
628 |
strcpy (kbuf, "\033[5~"); |
629 |
break; |
630 |
# ifdef XK_KP_Next |
631 |
case XK_KP_Next: |
632 |
/* allow shift to override */ |
633 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
634 |
{ |
635 |
strcpy (kbuf, "\033Os"); |
636 |
break; |
637 |
} |
638 |
/* FALLTHROUGH */ |
639 |
# endif |
640 |
case XK_Next: |
641 |
strcpy (kbuf, "\033[6~"); |
642 |
break; |
643 |
#endif |
644 |
case XK_KP_Enter: |
645 |
/* allow shift to override */ |
646 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
647 |
{ |
648 |
strcpy (kbuf, "\033OM"); |
649 |
break; |
650 |
} |
651 |
|
652 |
/* FALLTHROUGH */ |
653 |
|
654 |
case XK_Return: |
655 |
if (priv_modes & PrivMode_LFNL) |
656 |
{ |
657 |
kbuf[0] = '\015'; |
658 |
kbuf[1] = '\012'; |
659 |
kbuf[2] = '\0'; |
660 |
} |
661 |
else |
662 |
{ |
663 |
kbuf[0] = '\015'; |
664 |
kbuf[1] = '\0'; |
665 |
} |
666 |
break; |
667 |
|
668 |
#ifdef XK_KP_Begin |
669 |
case XK_KP_Begin: |
670 |
strcpy (kbuf, "\033Ou"); |
671 |
break; |
672 |
|
673 |
#endif |
674 |
case XK_KP_F1: /* "\033OP" */ |
675 |
case XK_KP_F2: /* "\033OQ" */ |
676 |
case XK_KP_F3: /* "\033OR" */ |
677 |
case XK_KP_F4: /* "\033OS" */ |
678 |
strcpy (kbuf, "\033OP"); |
679 |
kbuf[2] += (keysym - XK_KP_F1); |
680 |
break; |
681 |
|
682 |
case XK_KP_Multiply: /* "\033Oj" : "*" */ |
683 |
case XK_KP_Add: /* "\033Ok" : "+" */ |
684 |
case XK_KP_Separator: /* "\033Ol" : "," */ |
685 |
case XK_KP_Subtract: /* "\033Om" : "-" */ |
686 |
case XK_KP_Decimal: /* "\033On" : "." */ |
687 |
case XK_KP_Divide: /* "\033Oo" : "/" */ |
688 |
case XK_KP_0: /* "\033Op" : "0" */ |
689 |
case XK_KP_1: /* "\033Oq" : "1" */ |
690 |
case XK_KP_2: /* "\033Or" : "2" */ |
691 |
case XK_KP_3: /* "\033Os" : "3" */ |
692 |
case XK_KP_4: /* "\033Ot" : "4" */ |
693 |
case XK_KP_5: /* "\033Ou" : "5" */ |
694 |
case XK_KP_6: /* "\033Ov" : "6" */ |
695 |
case XK_KP_7: /* "\033Ow" : "7" */ |
696 |
case XK_KP_8: /* "\033Ox" : "8" */ |
697 |
case XK_KP_9: /* "\033Oy" : "9" */ |
698 |
/* allow shift to override */ |
699 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
700 |
{ |
701 |
strcpy (kbuf, "\033Oj"); |
702 |
kbuf[2] += (keysym - XK_KP_Multiply); |
703 |
} |
704 |
else |
705 |
{ |
706 |
kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); |
707 |
kbuf[1] = '\0'; |
708 |
} |
709 |
break; |
710 |
|
711 |
case XK_Find: |
712 |
strcpy (kbuf, "\033[1~"); |
713 |
break; |
714 |
|
715 |
#ifdef XK_KP_End |
716 |
case XK_KP_Insert: |
717 |
/* allow shift to override */ |
718 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
719 |
{ |
720 |
strcpy (kbuf, "\033Op"); |
721 |
break; |
722 |
} |
723 |
/* FALLTHROUGH */ |
724 |
#endif |
725 |
case XK_Insert: |
726 |
strcpy (kbuf, "\033[2~"); |
727 |
break; |
728 |
#ifdef DXK_Remove /* support for DEC remove like key */ |
729 |
case DXK_Remove: |
730 |
/* FALLTHROUGH */ |
731 |
#endif |
732 |
case XK_Execute: |
733 |
strcpy (kbuf, "\033[3~"); |
734 |
break; |
735 |
case XK_Select: |
736 |
strcpy (kbuf, "\033[4~"); |
737 |
break; |
738 |
#ifdef XK_KP_End |
739 |
case XK_KP_End: |
740 |
/* allow shift to override */ |
741 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
742 |
{ |
743 |
strcpy (kbuf, "\033Oq"); |
744 |
break; |
745 |
} |
746 |
/* FALLTHROUGH */ |
747 |
#endif |
748 |
case XK_End: |
749 |
strcpy (kbuf, KS_END); |
750 |
break; |
751 |
#ifdef XK_KP_Home |
752 |
case XK_KP_Home: |
753 |
/* allow shift to override */ |
754 |
if ((priv_modes & PrivMode_aplKP) ? !shft : shft) |
755 |
{ |
756 |
strcpy (kbuf, "\033Ow"); |
757 |
break; |
758 |
} |
759 |
/* FALLTHROUGH */ |
760 |
#endif |
761 |
case XK_Home: |
762 |
strcpy (kbuf, KS_HOME); |
763 |
break; |
764 |
|
765 |
#define FKEY(n, fkey) \ |
766 |
sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey))) |
767 |
|
768 |
case XK_F1: /* "\033[11~" */ |
769 |
case XK_F2: /* "\033[12~" */ |
770 |
case XK_F3: /* "\033[13~" */ |
771 |
case XK_F4: /* "\033[14~" */ |
772 |
case XK_F5: /* "\033[15~" */ |
773 |
FKEY (11, XK_F1); |
774 |
break; |
775 |
case XK_F6: /* "\033[17~" */ |
776 |
case XK_F7: /* "\033[18~" */ |
777 |
case XK_F8: /* "\033[19~" */ |
778 |
case XK_F9: /* "\033[20~" */ |
779 |
case XK_F10: /* "\033[21~" */ |
780 |
FKEY (17, XK_F6); |
781 |
break; |
782 |
case XK_F11: /* "\033[23~" */ |
783 |
case XK_F12: /* "\033[24~" */ |
784 |
case XK_F13: /* "\033[25~" */ |
785 |
case XK_F14: /* "\033[26~" */ |
786 |
FKEY (23, XK_F11); |
787 |
break; |
788 |
case XK_F15: /* "\033[28~" */ |
789 |
case XK_F16: /* "\033[29~" */ |
790 |
FKEY (28, XK_F15); |
791 |
break; |
792 |
case XK_Help: /* "\033[28~" */ |
793 |
FKEY (28, XK_Help); |
794 |
break; |
795 |
case XK_Menu: /* "\033[29~" */ |
796 |
FKEY (29, XK_Menu); |
797 |
break; |
798 |
case XK_F17: /* "\033[31~" */ |
799 |
case XK_F18: /* "\033[32~" */ |
800 |
case XK_F19: /* "\033[33~" */ |
801 |
case XK_F20: /* "\033[34~" */ |
802 |
case XK_F21: /* "\033[35~" */ |
803 |
case XK_F22: /* "\033[36~" */ |
804 |
case XK_F23: /* "\033[37~" */ |
805 |
case XK_F24: /* "\033[38~" */ |
806 |
case XK_F25: /* "\033[39~" */ |
807 |
case XK_F26: /* "\033[40~" */ |
808 |
case XK_F27: /* "\033[41~" */ |
809 |
case XK_F28: /* "\033[42~" */ |
810 |
case XK_F29: /* "\033[43~" */ |
811 |
case XK_F30: /* "\033[44~" */ |
812 |
case XK_F31: /* "\033[45~" */ |
813 |
case XK_F32: /* "\033[46~" */ |
814 |
case XK_F33: /* "\033[47~" */ |
815 |
case XK_F34: /* "\033[48~" */ |
816 |
case XK_F35: /* "\033[49~" */ |
817 |
FKEY (31, XK_F17); |
818 |
break; |
819 |
#undef FKEY |
820 |
default: |
821 |
newlen = 0; |
822 |
break; |
823 |
} |
824 |
|
825 |
if (newlen) |
826 |
len = strlen (kbuf); |
827 |
} |
828 |
|
829 |
/* |
830 |
* Pass meta for all function keys, if 'meta' option set |
831 |
*/ |
832 |
#ifdef META8_OPTION |
833 |
if (meta && (meta_char == 0x80) && len > 0) |
834 |
kbuf[len - 1] |= 0x80; |
835 |
#endif |
836 |
|
837 |
} |
838 |
else if (ctrl && keysym == XK_minus) |
839 |
{ |
840 |
len = 1; |
841 |
kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ |
842 |
} |
843 |
else if (keysym == XK_ISO_Left_Tab) |
844 |
{ |
845 |
strcpy (kbuf, "\033[Z"); |
846 |
len = 3; |
847 |
} |
848 |
else |
849 |
{ |
850 |
#ifdef META8_OPTION |
851 |
/* set 8-bit on */ |
852 |
if (meta && (meta_char == 0x80)) |
853 |
{ |
854 |
char *ch; |
855 |
|
856 |
for (ch = kbuf; ch < kbuf + len; ch++) |
857 |
*ch |= 0x80; |
858 |
|
859 |
meta = 0; |
860 |
} |
861 |
#endif |
862 |
/* nil */ ; |
863 |
} |
864 |
} |
865 |
|
866 |
if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) |
867 |
return; |
868 |
|
869 |
if (len <= 0) |
870 |
return; /* not mapped */ |
871 |
|
872 |
if (OPTION (Opt_scrollTtyKeypress)) |
873 |
if (view_start) |
874 |
{ |
875 |
view_start = 0; |
876 |
want_refresh = 1; |
877 |
} |
878 |
|
879 |
/* |
880 |
* these modifications only affect the static keybuffer |
881 |
* pass Shift/Control indicators for function keys ending with `~' |
882 |
* |
883 |
* eg, |
884 |
* Prior = "ESC[5~" |
885 |
* Shift+Prior = "ESC[5$" |
886 |
* Ctrl+Prior = "ESC[5^" |
887 |
* Ctrl+Shift+Prior = "ESC[5@" |
888 |
* Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>). |
889 |
*/ |
890 |
if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') |
891 |
kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); |
892 |
|
893 |
/* escape prefix */ |
894 |
if (meta |
895 |
#ifdef META8_OPTION |
896 |
&& meta_char == C0_ESC |
897 |
#endif |
898 |
) |
899 |
{ |
900 |
const char ch = C0_ESC; |
901 |
tt_write (&ch, 1); |
902 |
} |
903 |
|
904 |
tt_write (kbuf, (unsigned int)len); |
905 |
} |
906 |
/*}}} */ |
907 |
|
908 |
#if defined (KEYSYM_RESOURCE) |
909 |
unsigned int |
910 |
rxvt_term::cmd_write (const char *str, unsigned int count) |
911 |
{ |
912 |
unsigned int n, s; |
913 |
|
914 |
n = cmdbuf_ptr - cmdbuf_base; |
915 |
s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; |
916 |
|
917 |
if (n > 0 && s < count) |
918 |
{ |
919 |
memmove (cmdbuf_base, cmdbuf_ptr, |
920 |
(unsigned int) (cmdbuf_endp - cmdbuf_ptr)); |
921 |
cmdbuf_ptr = cmdbuf_base; |
922 |
cmdbuf_endp -= n; |
923 |
s += n; |
924 |
} |
925 |
|
926 |
if (count > s) |
927 |
{ |
928 |
rxvt_warn ("data loss: cmd_write too large, continuing.\n"); |
929 |
count = s; |
930 |
} |
931 |
|
932 |
for (; count--;) |
933 |
*cmdbuf_endp++ = *str++; |
934 |
|
935 |
cmd_parse (); |
936 |
|
937 |
return 0; |
938 |
} |
939 |
#endif |
940 |
|
941 |
void |
942 |
rxvt_term::flush () |
943 |
{ |
944 |
flush_ev.stop (); |
945 |
|
946 |
#ifdef TRANSPARENT |
947 |
if (want_full_refresh) |
948 |
{ |
949 |
want_full_refresh = 0; |
950 |
scr_clear (); |
951 |
scr_touch (false); |
952 |
} |
953 |
#endif |
954 |
|
955 |
if (want_refresh) |
956 |
{ |
957 |
if (SHOULD_INVOKE (HOOK_LINE_UPDATE)) |
958 |
{ |
959 |
int row = view_start; |
960 |
int end_row = row + nrow; |
961 |
|
962 |
while (row > top_row && ROW (row - 1).is_longer ()) |
963 |
--row; |
964 |
|
965 |
do |
966 |
{ |
967 |
int start_row = row; |
968 |
line_t *l; |
969 |
|
970 |
do |
971 |
{ |
972 |
l = &ROW (row++); |
973 |
|
974 |
if (!(l->f & LINE_FILTERED)) |
975 |
{ |
976 |
// line not filtered, mark it as filtered |
977 |
l->f |= LINE_FILTERED; |
978 |
while (l->is_longer ()) |
979 |
{ |
980 |
l = &ROW (row++); |
981 |
l->f |= LINE_FILTERED; |
982 |
} |
983 |
|
984 |
// and filter it |
985 |
HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END)); |
986 |
|
987 |
break; |
988 |
} |
989 |
} |
990 |
while (l->is_longer () && row < end_row); |
991 |
} |
992 |
while (row < end_row); |
993 |
} |
994 |
|
995 |
scr_refresh (); |
996 |
scrollbar_show (1); |
997 |
#ifdef USE_XIM |
998 |
IMSendSpot (); |
999 |
#endif |
1000 |
} |
1001 |
|
1002 |
display->flush (); |
1003 |
} |
1004 |
|
1005 |
void |
1006 |
rxvt_term::check_cb (check_watcher &w) |
1007 |
{ |
1008 |
make_current (); |
1009 |
|
1010 |
display->flush (); |
1011 |
|
1012 |
if (want_refresh && !flush_ev.active) |
1013 |
flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally |
1014 |
} |
1015 |
|
1016 |
void |
1017 |
rxvt_term::flush_cb (time_watcher &w) |
1018 |
{ |
1019 |
make_current (); |
1020 |
|
1021 |
refresh_limit = 1; |
1022 |
refresh_count = 0; |
1023 |
flush (); |
1024 |
} |
1025 |
|
1026 |
#ifdef CURSOR_BLINK |
1027 |
void |
1028 |
rxvt_term::cursor_blink_cb (time_watcher &w) |
1029 |
{ |
1030 |
hidden_cursor = !hidden_cursor; |
1031 |
want_refresh = 1; |
1032 |
|
1033 |
w.start (w.at + CURSOR_BLINK_INTERVAL); |
1034 |
} |
1035 |
#endif |
1036 |
|
1037 |
#ifdef TEXT_BLINK |
1038 |
void |
1039 |
rxvt_term::text_blink_cb (time_watcher &w) |
1040 |
{ |
1041 |
if (scr_refresh_rend (RS_Blink, RS_Blink)) |
1042 |
{ |
1043 |
hidden_text = !hidden_text; |
1044 |
want_refresh = 1; |
1045 |
w.start (w.at + TEXT_BLINK_INTERVAL); |
1046 |
} |
1047 |
} |
1048 |
#endif |
1049 |
|
1050 |
#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
1051 |
void |
1052 |
rxvt_term::cont_scroll_cb (time_watcher &w) |
1053 |
{ |
1054 |
if ((scrollbar_isUp() || scrollbar_isDn()) && |
1055 |
scr_page (scrollbar_isUp() ? UP : DN, 1)) |
1056 |
{ |
1057 |
want_refresh = 1; |
1058 |
w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); |
1059 |
} |
1060 |
} |
1061 |
#endif |
1062 |
|
1063 |
#ifdef SELECTION_SCROLLING |
1064 |
void |
1065 |
rxvt_term::sel_scroll_cb (time_watcher &w) |
1066 |
{ |
1067 |
if (scr_page (scroll_selection_dir, scroll_selection_lines)) |
1068 |
{ |
1069 |
selection_extend (selection_save_x, selection_save_y, selection_save_state); |
1070 |
want_refresh = 1; |
1071 |
w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); |
1072 |
} |
1073 |
} |
1074 |
#endif |
1075 |
|
1076 |
#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
1077 |
void |
1078 |
rxvt_term::slip_wheel_cb (time_watcher &w) |
1079 |
{ |
1080 |
if (mouse_slip_wheel_speed == 0 |
1081 |
|| mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) |
1082 |
: scr_page (UP, mouse_slip_wheel_speed)) |
1083 |
{ |
1084 |
if (view_start == top_row || view_start == 0) |
1085 |
mouse_slip_wheel_speed = 0; |
1086 |
|
1087 |
want_refresh = 1; |
1088 |
w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); |
1089 |
} |
1090 |
} |
1091 |
#endif |
1092 |
|
1093 |
#if HAVE_SCHED_YIELD |
1094 |
static struct event_handler |
1095 |
{ |
1096 |
check_watcher cw_yield; |
1097 |
|
1098 |
void yield (check_watcher &w) |
1099 |
{ |
1100 |
sched_yield (); |
1101 |
w.stop (); |
1102 |
} |
1103 |
|
1104 |
event_handler () |
1105 |
: cw_yield (this, &event_handler::yield) |
1106 |
{ |
1107 |
} |
1108 |
} event_handler; |
1109 |
#endif |
1110 |
|
1111 |
bool |
1112 |
rxvt_term::pty_fill () |
1113 |
{ |
1114 |
ssize_t n = cmdbuf_endp - cmdbuf_ptr; |
1115 |
|
1116 |
if (CBUFSIZ == n) |
1117 |
{ |
1118 |
rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n"); |
1119 |
n = 0; |
1120 |
} |
1121 |
|
1122 |
memmove (cmdbuf_base, cmdbuf_ptr, n); |
1123 |
cmdbuf_ptr = cmdbuf_base; |
1124 |
cmdbuf_endp = cmdbuf_ptr + n; |
1125 |
|
1126 |
ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n); |
1127 |
|
1128 |
if (r > 0) |
1129 |
{ |
1130 |
cmdbuf_endp += r; |
1131 |
return true; |
1132 |
} |
1133 |
else if (r < 0 && (errno == EAGAIN || errno == EINTR)) |
1134 |
{ |
1135 |
#if HAVE_SCHED_YIELD |
1136 |
if (display->is_local) |
1137 |
event_handler.cw_yield.start (); |
1138 |
#endif |
1139 |
} |
1140 |
else |
1141 |
{ |
1142 |
pty_ev.stop (); |
1143 |
|
1144 |
if (!OPTION (Opt_hold)) |
1145 |
destroy (); |
1146 |
} |
1147 |
|
1148 |
return false; |
1149 |
} |
1150 |
|
1151 |
void |
1152 |
rxvt_term::pty_cb (io_watcher &w, short revents) |
1153 |
{ |
1154 |
make_current (); |
1155 |
|
1156 |
if (revents & EVENT_READ) |
1157 |
// loop, but don't allow a single term to monopolize us |
1158 |
while (pty_fill ()) |
1159 |
if (cmd_parse ()) |
1160 |
break; |
1161 |
|
1162 |
if (revents & EVENT_WRITE) |
1163 |
pty_write (); |
1164 |
} |
1165 |
|
1166 |
void |
1167 |
rxvt_term::pointer_unblank () |
1168 |
{ |
1169 |
XDefineCursor (xdisp, vt, TermWin_cursor); |
1170 |
recolour_cursor (); |
1171 |
|
1172 |
#ifdef POINTER_BLANK |
1173 |
hidden_pointer = 0; |
1174 |
|
1175 |
if (OPTION (Opt_pointerBlank)) |
1176 |
pointer_ev.start (NOW + pointerBlankDelay); |
1177 |
#endif |
1178 |
} |
1179 |
|
1180 |
#ifdef POINTER_BLANK |
1181 |
void |
1182 |
rxvt_term::pointer_blank () |
1183 |
{ |
1184 |
if (!OPTION (Opt_pointerBlank)) |
1185 |
return; |
1186 |
|
1187 |
XDefineCursor (xdisp, vt, display->blank_cursor); |
1188 |
XFlush (xdisp); |
1189 |
|
1190 |
hidden_pointer = 1; |
1191 |
} |
1192 |
|
1193 |
void |
1194 |
rxvt_term::pointer_cb (time_watcher &w) |
1195 |
{ |
1196 |
make_current (); |
1197 |
|
1198 |
pointer_blank (); |
1199 |
} |
1200 |
#endif |
1201 |
|
1202 |
void |
1203 |
rxvt_term::mouse_report (XButtonEvent &ev) |
1204 |
{ |
1205 |
int button_number, key_state = 0; |
1206 |
int x, y; |
1207 |
|
1208 |
x = ev.x; |
1209 |
y = ev.y; |
1210 |
pixel_position (&x, &y); |
1211 |
|
1212 |
if (MEvent.button == AnyButton) |
1213 |
button_number = 3; |
1214 |
else |
1215 |
{ |
1216 |
button_number = MEvent.button - Button1; |
1217 |
/* add 0x3D for wheel events, like xterm does */ |
1218 |
if (button_number >= 3) |
1219 |
button_number += (64 - 3); |
1220 |
} |
1221 |
|
1222 |
if (priv_modes & PrivMode_MouseX10) |
1223 |
{ |
1224 |
/* |
1225 |
* do not report ButtonRelease |
1226 |
* no state info allowed |
1227 |
*/ |
1228 |
key_state = 0; |
1229 |
if (button_number == 3) |
1230 |
return; |
1231 |
} |
1232 |
else |
1233 |
{ |
1234 |
/* XTerm mouse reporting needs these values: |
1235 |
* 4 = Shift |
1236 |
* 8 = Meta |
1237 |
* 16 = Control |
1238 |
* plus will add in our own Double-Click reporting |
1239 |
* 32 = Double Click |
1240 |
*/ |
1241 |
key_state = ((MEvent.state & ShiftMask) ? 4 : 0) |
1242 |
+ ((MEvent.state & ModMetaMask) ? 8 : 0) |
1243 |
+ ((MEvent.state & ControlMask) ? 16 : 0); |
1244 |
#ifdef MOUSE_REPORT_DOUBLECLICK |
1245 |
key_state += ((MEvent.clicks > 1) ? 32 : 0); |
1246 |
#endif |
1247 |
} |
1248 |
|
1249 |
#if DEBUG_MOUSEREPORT |
1250 |
fprintf (stderr, "Mouse ["); |
1251 |
if (key_state & 16) |
1252 |
fputc ('C', stderr); |
1253 |
if (key_state & 4) |
1254 |
fputc ('S', stderr); |
1255 |
if (key_state & 8) |
1256 |
fputc ('A', stderr); |
1257 |
if (key_state & 32) |
1258 |
fputc ('2', stderr); |
1259 |
fprintf (stderr, "]: <%d>, %d/%d\n", |
1260 |
button_number, |
1261 |
x + 1, |
1262 |
y + 1); |
1263 |
#endif |
1264 |
|
1265 |
tt_printf ("\033[M%c%c%c", |
1266 |
(32 + button_number + key_state), |
1267 |
(32 + x + 1), |
1268 |
(32 + y + 1)); |
1269 |
} |
1270 |
|
1271 |
/*{{{ process an X event */ |
1272 |
void |
1273 |
rxvt_term::x_cb (XEvent &ev) |
1274 |
{ |
1275 |
make_current (); |
1276 |
|
1277 |
dLocal (Display *, xdisp); |
1278 |
|
1279 |
if (ev.xany.window == vt |
1280 |
&& SHOULD_INVOKE (HOOK_X_EVENT) |
1281 |
&& HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) |
1282 |
return; |
1283 |
|
1284 |
// for XQueryPointer |
1285 |
Window unused_root, unused_child; |
1286 |
int unused_root_x, unused_root_y; |
1287 |
unsigned int unused_mask; |
1288 |
|
1289 |
switch (ev.type) |
1290 |
{ |
1291 |
case KeyPress: |
1292 |
#if ISO_14755 |
1293 |
if (!(iso14755buf & ISO_14755_52)) |
1294 |
#endif |
1295 |
lookup_key (ev.xkey); |
1296 |
|
1297 |
break; |
1298 |
|
1299 |
case KeyRelease: |
1300 |
{ |
1301 |
#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL |
1302 |
KeySym keysym; |
1303 |
|
1304 |
keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ |
1305 |
#endif |
1306 |
|
1307 |
#if ENABLE_FRILLS || ISO_14755 |
1308 |
// ISO 14755 support |
1309 |
if (iso14755buf) |
1310 |
if (iso14755buf & ISO_14755_52) |
1311 |
{ |
1312 |
# if ENABLE_OVERLAY |
1313 |
scr_overlay_off (); |
1314 |
# endif |
1315 |
# if ISO_14755 |
1316 |
// iso14755 part 5.2 handling: release time |
1317 |
// first: controls |
1318 |
if ((ev.xkey.state & ControlMask) |
1319 |
&& ((keysym >= 0x40 && keysym <= 0x5f) |
1320 |
|| (keysym >= 0x61 && keysym <= 0x7f))) |
1321 |
{ |
1322 |
iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f); |
1323 |
commit_iso14755 (); |
1324 |
goto skip_switch; |
1325 |
} |
1326 |
|
1327 |
for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) |
1328 |
if (i[0] == keysym) |
1329 |
{ |
1330 |
iso14755buf = ISO_14755_51 | i[1]; |
1331 |
commit_iso14755 (); |
1332 |
goto skip_switch; |
1333 |
} |
1334 |
|
1335 |
scr_bell (); |
1336 |
# endif |
1337 |
iso14755buf = 0; |
1338 |
break; |
1339 |
} |
1340 |
else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask)) |
1341 |
{ |
1342 |
# if ENABLE_OVERLAY |
1343 |
scr_overlay_off (); |
1344 |
# endif |
1345 |
if (iso14755buf & ISO_14755_51) |
1346 |
commit_iso14755 (); |
1347 |
#if ISO_14755 |
1348 |
else if (iso14755buf & ISO_14755_STARTED) |
1349 |
{ |
1350 |
iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair |
1351 |
|
1352 |
scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1); |
1353 |
scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE"); |
1354 |
} |
1355 |
# endif |
1356 |
else |
1357 |
iso14755buf = 0; |
1358 |
} |
1359 |
#endif |
1360 |
|
1361 |
if (ev.xany.window == vt |
1362 |
&& HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END))) |
1363 |
break; |
1364 |
|
1365 |
#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
1366 |
if (!(ev.xkey.state & ControlMask)) |
1367 |
slip_wheel_ev.stop (); |
1368 |
else if (keysym == XK_Control_L || keysym == XK_Control_R) |
1369 |
mouse_slip_wheel_speed = 0; |
1370 |
#endif |
1371 |
break; |
1372 |
} |
1373 |
|
1374 |
case ButtonPress: |
1375 |
button_press (ev.xbutton); |
1376 |
break; |
1377 |
|
1378 |
case ButtonRelease: |
1379 |
button_release (ev.xbutton); |
1380 |
break; |
1381 |
|
1382 |
case ClientMessage: |
1383 |
if (ev.xclient.format == 32 |
1384 |
&& !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END))) |
1385 |
{ |
1386 |
if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) |
1387 |
{ |
1388 |
if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END))) |
1389 |
{ |
1390 |
if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) |
1391 |
{ |
1392 |
if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) |
1393 |
destroy (); |
1394 |
} |
1395 |
#if ENABLE_EWMH |
1396 |
else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) |
1397 |
XSendEvent (xdisp, ev.xclient.window = display->root, |
1398 |
False, SubstructureRedirectMask | SubstructureNotifyMask, |
1399 |
&ev); |
1400 |
#endif |
1401 |
} |
1402 |
} |
1403 |
#if ENABLE_XEMBED |
1404 |
else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED]) |
1405 |
{ |
1406 |
if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) |
1407 |
focus_in (); |
1408 |
else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) |
1409 |
focus_out (); |
1410 |
} |
1411 |
#endif |
1412 |
} |
1413 |
break; |
1414 |
|
1415 |
case MappingNotify: |
1416 |
XRefreshKeyboardMapping (&ev.xmapping); |
1417 |
break; |
1418 |
|
1419 |
/* |
1420 |
* XXX: this is not the _current_ arrangement |
1421 |
* Here's my conclusion: |
1422 |
* If the window is completely unobscured, use bitblt's |
1423 |
* to scroll. Even then, they're only used when doing partial |
1424 |
* screen scrolling. When partially obscured, we have to fill |
1425 |
* in the GraphicsExpose parts, which means that after each refresh, |
1426 |
* we need to wait for the graphics expose or Noexpose events, |
1427 |
* which ought to make things real slow! |
1428 |
*/ |
1429 |
case VisibilityNotify: |
1430 |
switch (ev.xvisibility.state) |
1431 |
{ |
1432 |
case VisibilityUnobscured: |
1433 |
refresh_type = FAST_REFRESH; |
1434 |
break; |
1435 |
case VisibilityPartiallyObscured: |
1436 |
refresh_type = SLOW_REFRESH; |
1437 |
break; |
1438 |
default: |
1439 |
refresh_type = NO_REFRESH; |
1440 |
break; |
1441 |
} |
1442 |
break; |
1443 |
|
1444 |
case FocusIn: |
1445 |
focus_in (); |
1446 |
break; |
1447 |
|
1448 |
case FocusOut: |
1449 |
focus_out (); |
1450 |
break; |
1451 |
|
1452 |
case ConfigureNotify: |
1453 |
if (ev.xconfigure.window == parent[0]) |
1454 |
{ |
1455 |
while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) |
1456 |
; |
1457 |
|
1458 |
if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) |
1459 |
{ |
1460 |
seen_resize = 1; |
1461 |
resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); |
1462 |
} |
1463 |
|
1464 |
HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); |
1465 |
|
1466 |
#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ |
1467 |
if (OPTION (Opt_transparent)) |
1468 |
check_our_parents (); |
1469 |
#endif |
1470 |
} |
1471 |
break; |
1472 |
|
1473 |
case PropertyNotify: |
1474 |
if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) |
1475 |
if (ev.xproperty.atom == xa[XA_VT_SELECTION] |
1476 |
&& ev.xproperty.state == PropertyNewValue) |
1477 |
selection_property (ev.xproperty.window, ev.xproperty.atom); |
1478 |
|
1479 |
break; |
1480 |
|
1481 |
case SelectionClear: |
1482 |
selection_clear (); |
1483 |
break; |
1484 |
|
1485 |
case SelectionNotify: |
1486 |
if (selection_wait == Sel_normal) |
1487 |
selection_paste (ev.xselection.requestor, ev.xselection.property, true); |
1488 |
break; |
1489 |
|
1490 |
case SelectionRequest: |
1491 |
selection_send (ev.xselectionrequest); |
1492 |
break; |
1493 |
|
1494 |
case MapNotify: |
1495 |
mapped = 1; |
1496 |
#ifdef TEXT_BLINK |
1497 |
text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); |
1498 |
#endif |
1499 |
HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); |
1500 |
break; |
1501 |
|
1502 |
case UnmapNotify: |
1503 |
mapped = 0; |
1504 |
#ifdef TEXT_BLINK |
1505 |
text_blink_ev.stop (); |
1506 |
#endif |
1507 |
HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); |
1508 |
break; |
1509 |
|
1510 |
#ifdef TRANSPARENT |
1511 |
case ReparentNotify: |
1512 |
rootwin_cb (ev); |
1513 |
break; |
1514 |
#endif /* TRANSPARENT */ |
1515 |
|
1516 |
case GraphicsExpose: |
1517 |
case Expose: |
1518 |
if (ev.xany.window == vt) |
1519 |
{ |
1520 |
do |
1521 |
scr_expose (ev.xexpose.x, ev.xexpose.y, |
1522 |
ev.xexpose.width, ev.xexpose.height, False); |
1523 |
while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); |
1524 |
|
1525 |
ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; |
1526 |
|
1527 |
while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) |
1528 |
scr_expose (ev.xexpose.x, ev.xexpose.y, |
1529 |
ev.xexpose.width, ev.xexpose.height, False); |
1530 |
|
1531 |
want_refresh = 1; |
1532 |
} |
1533 |
else |
1534 |
{ |
1535 |
XEvent unused_event; |
1536 |
|
1537 |
while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) |
1538 |
; |
1539 |
while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) |
1540 |
; |
1541 |
|
1542 |
if (isScrollbarWindow (ev.xany.window)) |
1543 |
{ |
1544 |
scrollBar.setIdle (); |
1545 |
scrollbar_show (0); |
1546 |
} |
1547 |
|
1548 |
#ifdef TRANSPARENT |
1549 |
if (am_transparent && ev.xany.window == parent[0]) |
1550 |
XClearWindow (xdisp, ev.xany.window); |
1551 |
#endif |
1552 |
} |
1553 |
break; |
1554 |
|
1555 |
case MotionNotify: |
1556 |
#ifdef POINTER_BLANK |
1557 |
if (hidden_pointer) |
1558 |
pointer_unblank (); |
1559 |
#endif |
1560 |
if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) |
1561 |
break; |
1562 |
|
1563 |
if (ev.xany.window == vt) |
1564 |
{ |
1565 |
if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) |
1566 |
&& HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) |
1567 |
; // nop |
1568 |
else if (ev.xbutton.state & (Button1Mask | Button3Mask)) |
1569 |
{ |
1570 |
while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) |
1571 |
; |
1572 |
|
1573 |
XQueryPointer (xdisp, vt, |
1574 |
&unused_root, &unused_child, |
1575 |
&unused_root_x, &unused_root_y, |
1576 |
&ev.xbutton.x, &ev.xbutton.y, |
1577 |
&ev.xbutton.state); |
1578 |
#ifdef MOUSE_THRESHOLD |
1579 |
/* deal with a `jumpy' mouse */ |
1580 |
if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) |
1581 |
{ |
1582 |
#endif |
1583 |
#if ISO_14755 |
1584 |
// 5.4 |
1585 |
if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) |
1586 |
{ |
1587 |
iso14755_54 (ev.xbutton.x, ev.xbutton.y); |
1588 |
break; |
1589 |
} |
1590 |
#endif |
1591 |
selection_extend (ev.xbutton.x, ev.xbutton.y, |
1592 |
ev.xbutton.state & Button3Mask ? 2 : 0); |
1593 |
|
1594 |
#ifdef SELECTION_SCROLLING |
1595 |
if (ev.xbutton.y < int_bwidth |
1596 |
|| Pixel2Row (ev.xbutton.y) > (nrow-1)) |
1597 |
{ |
1598 |
int dist; |
1599 |
|
1600 |
/* don't clobber the current delay if we are |
1601 |
* already in the middle of scrolling. |
1602 |
*/ |
1603 |
if (!sel_scroll_ev.active) |
1604 |
sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); |
1605 |
|
1606 |
/* save the event params so we can highlight |
1607 |
* the selection in the pending-scroll loop |
1608 |
*/ |
1609 |
selection_save_x = ev.xbutton.x; |
1610 |
selection_save_y = ev.xbutton.y; |
1611 |
selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; |
1612 |
|
1613 |
/* calc number of lines to scroll */ |
1614 |
if (ev.xbutton.y < int_bwidth) |
1615 |
{ |
1616 |
scroll_selection_dir = UP; |
1617 |
dist = int_bwidth - ev.xbutton.y; |
1618 |
} |
1619 |
else |
1620 |
{ |
1621 |
scroll_selection_dir = DN; |
1622 |
dist = ev.xbutton.y - (int_bwidth + height); |
1623 |
} |
1624 |
|
1625 |
scroll_selection_lines = Pixel2Height (dist) |
1626 |
/ SELECTION_SCROLL_LINE_SPEEDUP |
1627 |
+ 1; |
1628 |
min_it (scroll_selection_lines, |
1629 |
SELECTION_SCROLL_MAX_LINES); |
1630 |
} |
1631 |
else |
1632 |
{ |
1633 |
/* we are within the text window, so we |
1634 |
* shouldn't be scrolling |
1635 |
*/ |
1636 |
if (sel_scroll_ev.active) |
1637 |
sel_scroll_ev.stop(); |
1638 |
} |
1639 |
#endif |
1640 |
#ifdef MOUSE_THRESHOLD |
1641 |
} |
1642 |
#endif |
1643 |
} |
1644 |
} |
1645 |
else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) |
1646 |
{ |
1647 |
while (XCheckTypedWindowEvent (xdisp, scrollBar.win, |
1648 |
MotionNotify, &ev)) |
1649 |
; |
1650 |
|
1651 |
XQueryPointer (xdisp, scrollBar.win, |
1652 |
&unused_root, &unused_child, |
1653 |
&unused_root_x, &unused_root_y, |
1654 |
&ev.xbutton.x, &ev.xbutton.y, |
1655 |
&unused_mask); |
1656 |
scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, |
1657 |
scrollbar_size ()); |
1658 |
want_refresh = 1; |
1659 |
refresh_limit = 0; |
1660 |
scrollbar_show (1); |
1661 |
} |
1662 |
break; |
1663 |
} |
1664 |
|
1665 |
skip_switch: ; |
1666 |
|
1667 |
#if defined(CURSOR_BLINK) |
1668 |
if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) |
1669 |
{ |
1670 |
if (hidden_cursor) |
1671 |
{ |
1672 |
hidden_cursor = 0; |
1673 |
want_refresh = 1; |
1674 |
} |
1675 |
|
1676 |
cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); |
1677 |
} |
1678 |
#endif |
1679 |
|
1680 |
#if defined(POINTER_BLANK) |
1681 |
if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) |
1682 |
{ |
1683 |
if (ev.type == MotionNotify |
1684 |
|| ev.type == ButtonPress |
1685 |
|| ev.type == ButtonRelease) |
1686 |
if (hidden_pointer) |
1687 |
pointer_unblank (); |
1688 |
|
1689 |
if (ev.type == KeyPress && hidden_pointer == 0) |
1690 |
pointer_blank (); |
1691 |
} |
1692 |
#endif |
1693 |
} |
1694 |
|
1695 |
void |
1696 |
rxvt_term::focus_in () |
1697 |
{ |
1698 |
if (!focus) |
1699 |
{ |
1700 |
focus = 1; |
1701 |
want_refresh = 1; |
1702 |
|
1703 |
HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); |
1704 |
|
1705 |
#if USE_XIM |
1706 |
if (Input_Context != NULL) |
1707 |
{ |
1708 |
IMSetStatusPosition (); |
1709 |
XSetICFocus (Input_Context); |
1710 |
} |
1711 |
#endif |
1712 |
#if CURSOR_BLINK |
1713 |
if (OPTION (Opt_cursorBlink)) |
1714 |
cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); |
1715 |
#endif |
1716 |
#if OFF_FOCUS_FADING |
1717 |
if (rs[Rs_fade]) |
1718 |
{ |
1719 |
pix_colors = pix_colors_focused; |
1720 |
scr_recolour (); |
1721 |
} |
1722 |
#endif |
1723 |
} |
1724 |
} |
1725 |
|
1726 |
void |
1727 |
rxvt_term::focus_out () |
1728 |
{ |
1729 |
if (focus) |
1730 |
{ |
1731 |
focus = 0; |
1732 |
want_refresh = 1; |
1733 |
|
1734 |
HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); |
1735 |
|
1736 |
#if ENABLE_FRILLS || ISO_14755 |
1737 |
if (iso14755buf) |
1738 |
{ |
1739 |
iso14755buf = 0; |
1740 |
# if ENABLE_OVERLAY |
1741 |
scr_overlay_off (); |
1742 |
# endif |
1743 |
} |
1744 |
#endif |
1745 |
#if USE_XIM |
1746 |
if (Input_Context != NULL) |
1747 |
XUnsetICFocus (Input_Context); |
1748 |
#endif |
1749 |
#if CURSOR_BLINK |
1750 |
if (OPTION (Opt_cursorBlink)) |
1751 |
cursor_blink_ev.stop (); |
1752 |
hidden_cursor = 0; |
1753 |
#endif |
1754 |
#if OFF_FOCUS_FADING |
1755 |
if (rs[Rs_fade]) |
1756 |
{ |
1757 |
pix_colors = pix_colors_unfocused; |
1758 |
scr_recolour (); |
1759 |
} |
1760 |
#endif |
1761 |
} |
1762 |
} |
1763 |
|
1764 |
#if TRANSPARENT |
1765 |
void |
1766 |
rxvt_term::rootwin_cb (XEvent &ev) |
1767 |
{ |
1768 |
make_current (); |
1769 |
|
1770 |
switch (ev.type) |
1771 |
{ |
1772 |
case PropertyNotify: |
1773 |
/* |
1774 |
* if user used some Esetroot compatible prog to set the root bg, |
1775 |
* use the property to determine the pixmap. We use it later on. |
1776 |
*/ |
1777 |
if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] |
1778 |
&& ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) |
1779 |
return; |
1780 |
|
1781 |
/* FALLTHROUGH */ |
1782 |
case ReparentNotify: |
1783 |
if (OPTION (Opt_transparent) && check_our_parents () && am_transparent) |
1784 |
want_refresh = want_full_refresh = 1; |
1785 |
break; |
1786 |
} |
1787 |
} |
1788 |
#endif |
1789 |
|
1790 |
void |
1791 |
rxvt_term::button_press (XButtonEvent &ev) |
1792 |
{ |
1793 |
int reportmode = 0, clickintime; |
1794 |
|
1795 |
bypass_keystate = ev.state & (ModMetaMask | ShiftMask); |
1796 |
|
1797 |
if (!bypass_keystate) |
1798 |
reportmode = !! (priv_modes & PrivMode_mouse_report); |
1799 |
|
1800 |
/* |
1801 |
* VT window processing of button press |
1802 |
*/ |
1803 |
if (ev.window == vt) |
1804 |
{ |
1805 |
if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END))) |
1806 |
return; |
1807 |
|
1808 |
#if ISO_14755 |
1809 |
// 5.4 |
1810 |
if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) |
1811 |
{ |
1812 |
iso14755_54 (ev.x, ev.y); |
1813 |
return; |
1814 |
} |
1815 |
#endif |
1816 |
|
1817 |
clickintime = ev.time - MEvent.time < MULTICLICK_TIME; |
1818 |
|
1819 |
if (reportmode) |
1820 |
{ |
1821 |
/* mouse report from vt window */ |
1822 |
/* save the xbutton state (for ButtonRelease) */ |
1823 |
MEvent.state = ev.state; |
1824 |
#ifdef MOUSE_REPORT_DOUBLECLICK |
1825 |
if (ev.button == MEvent.button && clickintime) |
1826 |
{ |
1827 |
/* same button, within alloted time */ |
1828 |
MEvent.clicks++; |
1829 |
|
1830 |
if (MEvent.clicks > 1) |
1831 |
{ |
1832 |
/* only report double clicks */ |
1833 |
MEvent.clicks = 2; |
1834 |
mouse_report (ev); |
1835 |
|
1836 |
/* don't report the release */ |
1837 |
MEvent.clicks = 0; |
1838 |
MEvent.button = AnyButton; |
1839 |
} |
1840 |
} |
1841 |
else |
1842 |
{ |
1843 |
/* different button, or time expired */ |
1844 |
MEvent.clicks = 1; |
1845 |
MEvent.button = ev.button; |
1846 |
mouse_report (ev); |
1847 |
} |
1848 |
#else |
1849 |
MEvent.button = ev.button; |
1850 |
mouse_report (ev); |
1851 |
#endif /* MOUSE_REPORT_DOUBLECLICK */ |
1852 |
|
1853 |
} |
1854 |
else |
1855 |
{ |
1856 |
if (ev.button != MEvent.button) |
1857 |
MEvent.clicks = 0; |
1858 |
|
1859 |
switch (ev.button) |
1860 |
{ |
1861 |
case Button1: |
1862 |
/* allow meta + click to select rectangular areas */ |
1863 |
/* should be done in screen.C */ |
1864 |
#if ENABLE_FRILLS |
1865 |
selection.rect = !!(ev.state & ModMetaMask); |
1866 |
#else |
1867 |
selection.rect = false; |
1868 |
#endif |
1869 |
|
1870 |
/* allow shift+left click to extend selection */ |
1871 |
if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report)) |
1872 |
{ |
1873 |
if (MEvent.button == Button1 && clickintime) |
1874 |
selection_rotate (ev.x, ev.y); |
1875 |
else |
1876 |
selection_extend (ev.x, ev.y, 1); |
1877 |
} |
1878 |
else |
1879 |
{ |
1880 |
if (MEvent.button == Button1 && clickintime) |
1881 |
MEvent.clicks++; |
1882 |
else |
1883 |
MEvent.clicks = 1; |
1884 |
|
1885 |
selection_click (MEvent.clicks, ev.x, ev.y); |
1886 |
} |
1887 |
|
1888 |
MEvent.button = Button1; |
1889 |
break; |
1890 |
|
1891 |
case Button3: |
1892 |
if (MEvent.button == Button3 && clickintime) |
1893 |
selection_rotate (ev.x, ev.y); |
1894 |
else |
1895 |
selection_extend (ev.x, ev.y, 1); |
1896 |
|
1897 |
MEvent.button = Button3; |
1898 |
break; |
1899 |
} |
1900 |
} |
1901 |
|
1902 |
MEvent.time = ev.time; |
1903 |
return; |
1904 |
} |
1905 |
|
1906 |
/* |
1907 |
* Scrollbar window processing of button press |
1908 |
*/ |
1909 |
if (isScrollbarWindow (ev.window)) |
1910 |
{ |
1911 |
scrollBar.setIdle (); |
1912 |
/* |
1913 |
* Rxvt-style scrollbar: |
1914 |
* move up if mouse is above slider |
1915 |
* move dn if mouse is below slider |
1916 |
* |
1917 |
* XTerm-style scrollbar: |
1918 |
* Move display proportional to pointer location |
1919 |
* pointer near top -> scroll one line |
1920 |
* pointer near bot -> scroll full page |
1921 |
*/ |
1922 |
#ifndef NO_SCROLLBAR_REPORT |
1923 |
if (reportmode) |
1924 |
{ |
1925 |
/* |
1926 |
* Mouse report disabled scrollbar: |
1927 |
* arrow buttons - send up/down |
1928 |
* click on scrollbar - send pageup/down |
1929 |
*/ |
1930 |
if ((scrollBar.style == R_SB_NEXT |
1931 |
&& scrollbarnext_upButton (ev.y)) |
1932 |
|| (scrollBar.style == R_SB_RXVT |
1933 |
&& scrollbarrxvt_upButton (ev.y))) |
1934 |
tt_printf ("\033[A"); |
1935 |
else if ((scrollBar.style == R_SB_NEXT |
1936 |
&& scrollbarnext_dnButton (ev.y)) |
1937 |
|| (scrollBar.style == R_SB_RXVT |
1938 |
&& scrollbarrxvt_dnButton (ev.y))) |
1939 |
tt_printf ("\033[B"); |
1940 |
else |
1941 |
switch (ev.button) |
1942 |
{ |
1943 |
case Button2: |
1944 |
tt_printf ("\014"); |
1945 |
break; |
1946 |
case Button1: |
1947 |
tt_printf ("\033[6~"); |
1948 |
break; |
1949 |
case Button3: |
1950 |
tt_printf ("\033[5~"); |
1951 |
break; |
1952 |
} |
1953 |
} |
1954 |
else |
1955 |
#endif /* NO_SCROLLBAR_REPORT */ |
1956 |
|
1957 |
{ |
1958 |
char upordown = 0; |
1959 |
|
1960 |
if (scrollBar.style == R_SB_NEXT) |
1961 |
{ |
1962 |
if (scrollbarnext_upButton (ev.y)) |
1963 |
upordown = -1; /* up */ |
1964 |
else if (scrollbarnext_dnButton (ev.y)) |
1965 |
upordown = 1; /* down */ |
1966 |
} |
1967 |
else if (scrollBar.style == R_SB_RXVT) |
1968 |
{ |
1969 |
if (scrollbarrxvt_upButton (ev.y)) |
1970 |
upordown = -1; /* up */ |
1971 |
else if (scrollbarrxvt_dnButton (ev.y)) |
1972 |
upordown = 1; /* down */ |
1973 |
} |
1974 |
if (upordown) |
1975 |
{ |
1976 |
#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
1977 |
cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); |
1978 |
#endif |
1979 |
if (scr_page (upordown < 0 ? UP : DN, 1)) |
1980 |
{ |
1981 |
if (upordown < 0) |
1982 |
scrollBar.setUp (); |
1983 |
else |
1984 |
scrollBar.setDn (); |
1985 |
} |
1986 |
} |
1987 |
else |
1988 |
switch (ev.button) |
1989 |
{ |
1990 |
case Button2: |
1991 |
switch (scrollbar_align) |
1992 |
{ |
1993 |
case R_SB_ALIGN_TOP: |
1994 |
csrO = 0; |
1995 |
break; |
1996 |
case R_SB_ALIGN_CENTRE: |
1997 |
csrO = (scrollBar.bot - scrollBar.top) / 2; |
1998 |
break; |
1999 |
case R_SB_ALIGN_BOTTOM: |
2000 |
csrO = scrollBar.bot - scrollBar.top; |
2001 |
break; |
2002 |
} |
2003 |
|
2004 |
if (scrollBar.style == R_SB_XTERM |
2005 |
|| scrollbar_above_slider (ev.y) |
2006 |
|| scrollbar_below_slider (ev.y)) |
2007 |
scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); |
2008 |
|
2009 |
scrollBar.setMotion (); |
2010 |
break; |
2011 |
|
2012 |
case Button1: |
2013 |
if (scrollbar_align == R_SB_ALIGN_CENTRE) |
2014 |
csrO = ev.y - scrollBar.top; |
2015 |
/* FALLTHROUGH */ |
2016 |
|
2017 |
case Button3: |
2018 |
if (scrollBar.style != R_SB_XTERM) |
2019 |
{ |
2020 |
if (scrollbar_above_slider (ev.y)) |
2021 |
# ifdef RXVT_SCROLL_FULL |
2022 |
scr_page (UP, nrow - 1); |
2023 |
# else |
2024 |
scr_page (UP, nrow / 4); |
2025 |
# endif |
2026 |
else if (scrollbar_below_slider (ev.y)) |
2027 |
# ifdef RXVT_SCROLL_FULL |
2028 |
scr_page (DN, nrow - 1); |
2029 |
# else |
2030 |
scr_page (DN, nrow / 4); |
2031 |
# endif |
2032 |
else |
2033 |
scrollBar.setMotion (); |
2034 |
} |
2035 |
else |
2036 |
{ |
2037 |
scr_page ((ev.button == Button1 ? DN : UP), |
2038 |
(nrow |
2039 |
* scrollbar_position (ev.y) |
2040 |
/ scrollbar_size ())); |
2041 |
} |
2042 |
|
2043 |
break; |
2044 |
} |
2045 |
} |
2046 |
|
2047 |
return; |
2048 |
} |
2049 |
} |
2050 |
|
2051 |
void |
2052 |
rxvt_term::button_release (XButtonEvent &ev) |
2053 |
{ |
2054 |
int reportmode = 0; |
2055 |
|
2056 |
csrO = 0; /* reset csr Offset */ |
2057 |
if (!bypass_keystate) |
2058 |
reportmode = !! (priv_modes & PrivMode_mouse_report); |
2059 |
|
2060 |
if (scrollbar_isUpDn ()) |
2061 |
{ |
2062 |
scrollBar.setIdle (); |
2063 |
scrollbar_show (0); |
2064 |
} |
2065 |
|
2066 |
#ifdef SELECTION_SCROLLING |
2067 |
if (sel_scroll_ev.active) |
2068 |
sel_scroll_ev.stop(); |
2069 |
#endif |
2070 |
|
2071 |
if (ev.window == vt) |
2072 |
{ |
2073 |
if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) |
2074 |
return; |
2075 |
|
2076 |
#if ISO_14755 |
2077 |
// 5.4 |
2078 |
if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) |
2079 |
return; |
2080 |
#endif |
2081 |
|
2082 |
if (reportmode) |
2083 |
{ |
2084 |
/* mouse report from vt window */ |
2085 |
/* don't report release of wheel "buttons" */ |
2086 |
if (ev.button >= 4) |
2087 |
return; |
2088 |
#ifdef MOUSE_REPORT_DOUBLECLICK |
2089 |
/* only report the release of 'slow' single clicks */ |
2090 |
if (MEvent.button != AnyButton |
2091 |
&& (ev.button != MEvent.button |
2092 |
|| (ev.time - MEvent.time |
2093 |
> MULTICLICK_TIME / 2))) |
2094 |
{ |
2095 |
MEvent.clicks = 0; |
2096 |
MEvent.button = AnyButton; |
2097 |
mouse_report (ev); |
2098 |
} |
2099 |
#else /* MOUSE_REPORT_DOUBLECLICK */ |
2100 |
MEvent.button = AnyButton; |
2101 |
mouse_report (ev); |
2102 |
#endif /* MOUSE_REPORT_DOUBLECLICK */ |
2103 |
return; |
2104 |
} |
2105 |
|
2106 |
/* |
2107 |
* dumb hack to compensate for the failure of click-and-drag |
2108 |
* when overriding mouse reporting |
2109 |
*/ |
2110 |
if (priv_modes & PrivMode_mouse_report |
2111 |
&& bypass_keystate |
2112 |
&& ev.button == Button1 && MEvent.clicks <= 1) |
2113 |
selection_extend (ev.x, ev.y, 0); |
2114 |
|
2115 |
switch (ev.button) |
2116 |
{ |
2117 |
case Button1: |
2118 |
case Button3: |
2119 |
selection_make (ev.time); |
2120 |
break; |
2121 |
|
2122 |
case Button2: |
2123 |
if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? |
2124 |
selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary); |
2125 |
break; |
2126 |
|
2127 |
#ifdef MOUSE_WHEEL |
2128 |
case Button4: |
2129 |
case Button5: |
2130 |
{ |
2131 |
int i; |
2132 |
page_dirn v; |
2133 |
|
2134 |
v = ev.button == Button4 ? UP : DN; |
2135 |
|
2136 |
if (ev.state & ShiftMask) |
2137 |
i = 1; |
2138 |
else if (OPTION (Opt_mouseWheelScrollPage)) |
2139 |
i = nrow - 1; |
2140 |
else |
2141 |
i = 5; |
2142 |
|
2143 |
# ifdef MOUSE_SLIP_WHEELING |
2144 |
if (ev.state & ControlMask) |
2145 |
{ |
2146 |
mouse_slip_wheel_speed += v ? -1 : 1; |
2147 |
if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; |
2148 |
if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; |
2149 |
|
2150 |
if (slip_wheel_ev.at < NOW) |
2151 |
slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; |
2152 |
|
2153 |
slip_wheel_ev.start (); |
2154 |
} |
2155 |
else |
2156 |
{ |
2157 |
# endif |
2158 |
scr_page (v, i); |
2159 |
scrollbar_show (1); |
2160 |
# ifdef MOUSE_SLIP_WHEELING |
2161 |
} |
2162 |
# endif |
2163 |
} |
2164 |
break; |
2165 |
#endif |
2166 |
} |
2167 |
} |
2168 |
} |
2169 |
|
2170 |
#ifdef TRANSPARENT |
2171 |
#if TINTING |
2172 |
/* taken from aterm-0.4.2 */ |
2173 |
|
2174 |
typedef uint32_t RUINT32T; |
2175 |
|
2176 |
void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
2177 |
{ |
2178 |
int sh_r, sh_g, sh_b; |
2179 |
RUINT32T mask_r, mask_g, mask_b; |
2180 |
RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
2181 |
unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
2182 |
unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
2183 |
int i; |
2184 |
|
2185 |
Visual *visual = term->visual; |
2186 |
|
2187 |
if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; |
2188 |
|
2189 |
/* for convenience */ |
2190 |
mask_r = visual->red_mask; |
2191 |
mask_g = visual->green_mask; |
2192 |
mask_b = visual->blue_mask; |
2193 |
|
2194 |
/* boring lookup table pre-initialization */ |
2195 |
switch (srcImage->bits_per_pixel) { |
2196 |
case 15: |
2197 |
if ((mask_r != 0x7c00) || |
2198 |
(mask_g != 0x03e0) || |
2199 |
(mask_b != 0x001f)) |
2200 |
return; |
2201 |
lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
2202 |
lookup_r = lookup; |
2203 |
lookup_g = lookup+32; |
2204 |
lookup_b = lookup+32+32; |
2205 |
sh_r = 10; |
2206 |
sh_g = 5; |
2207 |
sh_b = 0; |
2208 |
break; |
2209 |
case 16: |
2210 |
if ((mask_r != 0xf800) || |
2211 |
(mask_g != 0x07e0) || |
2212 |
(mask_b != 0x001f)) |
2213 |
return; |
2214 |
lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
2215 |
lookup_r = lookup; |
2216 |
lookup_g = lookup+32; |
2217 |
lookup_b = lookup+32+64; |
2218 |
sh_r = 11; |
2219 |
sh_g = 5; |
2220 |
sh_b = 0; |
2221 |
break; |
2222 |
case 24: |
2223 |
if ((mask_r != 0xff0000) || |
2224 |
(mask_g != 0x00ff00) || |
2225 |
(mask_b != 0x0000ff)) |
2226 |
return; |
2227 |
lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
2228 |
lookup_r = lookup; |
2229 |
lookup_g = lookup+256; |
2230 |
lookup_b = lookup+256+256; |
2231 |
sh_r = 16; |
2232 |
sh_g = 8; |
2233 |
sh_b = 0; |
2234 |
break; |
2235 |
case 32: |
2236 |
if ((mask_r != 0xff0000) || |
2237 |
(mask_g != 0x00ff00) || |
2238 |
(mask_b != 0x0000ff)) |
2239 |
return; |
2240 |
lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
2241 |
lookup_r = lookup; |
2242 |
lookup_g = lookup+256; |
2243 |
lookup_b = lookup+256+256; |
2244 |
sh_r = 16; |
2245 |
sh_g = 8; |
2246 |
sh_b = 0; |
2247 |
break; |
2248 |
default: |
2249 |
return; /* we do not support this color depth */ |
2250 |
} |
2251 |
|
2252 |
/* prepare limits for color transformation (each channel is handled separately) */ |
2253 |
if (shade < 0) { |
2254 |
shade = -shade; |
2255 |
if (shade < 0) shade = 0; |
2256 |
if (shade > 100) shade = 100; |
2257 |
|
2258 |
lower_lim_r = 65535-rm; |
2259 |
lower_lim_g = 65535-gm; |
2260 |
lower_lim_b = 65535-bm; |
2261 |
|
2262 |
lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
2263 |
lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
2264 |
lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
2265 |
|
2266 |
upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
2267 |
} else { |
2268 |
if (shade < 0) shade = 0; |
2269 |
if (shade > 100) shade = 100; |
2270 |
|
2271 |
lower_lim_r = lower_lim_g = lower_lim_b = 0; |
2272 |
|
2273 |
upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
2274 |
upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
2275 |
upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
2276 |
} |
2277 |
|
2278 |
/* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
2279 |
if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) |
2280 |
{ |
2281 |
unsigned int tmp; |
2282 |
|
2283 |
tmp = lower_lim_r; |
2284 |
lower_lim_r = lower_lim_b; |
2285 |
lower_lim_b = tmp; |
2286 |
|
2287 |
tmp = upper_lim_r; |
2288 |
upper_lim_r = upper_lim_b; |
2289 |
upper_lim_b = tmp; |
2290 |
} |
2291 |
|
2292 |
/* fill our lookup tables */ |
2293 |
for (i = 0; i <= mask_r>>sh_r; i++) |
2294 |
{ |
2295 |
RUINT32T tmp; |
2296 |
tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
2297 |
tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
2298 |
lookup_r[i] = (tmp/65535)<<sh_r; |
2299 |
} |
2300 |
for (i = 0; i <= mask_g>>sh_g; i++) |
2301 |
{ |
2302 |
RUINT32T tmp; |
2303 |
tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
2304 |
tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
2305 |
lookup_g[i] = (tmp/65535)<<sh_g; |
2306 |
} |
2307 |
for (i = 0; i <= mask_b>>sh_b; i++) |
2308 |
{ |
2309 |
RUINT32T tmp; |
2310 |
tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
2311 |
tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
2312 |
lookup_b[i] = (tmp/65535)<<sh_b; |
2313 |
} |
2314 |
|
2315 |
/* apply table to input image (replacing colors by newly calculated ones) */ |
2316 |
switch (srcImage->bits_per_pixel) |
2317 |
{ |
2318 |
case 15: |
2319 |
{ |
2320 |
unsigned short *p1, *pf, *p, *pl; |
2321 |
p1 = (unsigned short *) srcImage->data; |
2322 |
pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
2323 |
while (p1 < pf) |
2324 |
{ |
2325 |
p = p1; |
2326 |
pl = p1 + srcImage->width; |
2327 |
for (; p < pl; p++) |
2328 |
{ |
2329 |
*p = lookup_r[(*p & 0x7c00)>>10] | |
2330 |
lookup_g[(*p & 0x03e0)>> 5] | |
2331 |
lookup_b[(*p & 0x001f)]; |
2332 |
} |
2333 |
p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
2334 |
} |
2335 |
break; |
2336 |
} |
2337 |
case 16: |
2338 |
{ |
2339 |
unsigned short *p1, *pf, *p, *pl; |
2340 |
p1 = (unsigned short *) srcImage->data; |
2341 |
pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
2342 |
while (p1 < pf) |
2343 |
{ |
2344 |
p = p1; |
2345 |
pl = p1 + srcImage->width; |
2346 |
for (; p < pl; p++) |
2347 |
{ |
2348 |
*p = lookup_r[(*p & 0xf800)>>11] | |
2349 |
lookup_g[(*p & 0x07e0)>> 5] | |
2350 |
lookup_b[(*p & 0x001f)]; |
2351 |
} |
2352 |
p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
2353 |
} |
2354 |
break; |
2355 |
} |
2356 |
case 24: |
2357 |
{ |
2358 |
unsigned char *p1, *pf, *p, *pl; |
2359 |
p1 = (unsigned char *) srcImage->data; |
2360 |
pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
2361 |
while (p1 < pf) |
2362 |
{ |
2363 |
p = p1; |
2364 |
pl = p1 + srcImage->width * 3; |
2365 |
for (; p < pl; p += 3) |
2366 |
{ |
2367 |
p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
2368 |
p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
2369 |
p[2] = lookup_r[(p[2] & 0x0000ff)]; |
2370 |
} |
2371 |
p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
2372 |
} |
2373 |
break; |
2374 |
} |
2375 |
case 32: |
2376 |
{ |
2377 |
RUINT32T *p1, *pf, *p, *pl; |
2378 |
p1 = (RUINT32T *) srcImage->data; |
2379 |
pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
2380 |
|
2381 |
while (p1 < pf) |
2382 |
{ |
2383 |
p = p1; |
2384 |
pl = p1 + srcImage->width; |
2385 |
for (; p < pl; p++) |
2386 |
{ |
2387 |
*p = lookup_r[(*p & 0xff0000)>>16] | |
2388 |
lookup_g[(*p & 0x00ff00)>> 8] | |
2389 |
lookup_b[(*p & 0x0000ff)] | |
2390 |
(*p & ~0xffffff); |
2391 |
} |
2392 |
p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
2393 |
} |
2394 |
break; |
2395 |
} |
2396 |
} |
2397 |
|
2398 |
free (lookup); |
2399 |
} |
2400 |
#endif |
2401 |
|
2402 |
/* |
2403 |
* Check our parents are still who we think they are. |
2404 |
* Do transparency updates if required |
2405 |
*/ |
2406 |
int |
2407 |
rxvt_term::check_our_parents () |
2408 |
{ |
2409 |
int i, pchanged, aformat, have_pixmap, rootdepth; |
2410 |
unsigned long nitems, bytes_after; |
2411 |
Atom atype; |
2412 |
unsigned char *prop = NULL; |
2413 |
Window root, oldp, *list; |
2414 |
Pixmap rootpixmap = None; |
2415 |
XWindowAttributes wattr, wrootattr; |
2416 |
|
2417 |
pchanged = 0; |
2418 |
|
2419 |
if (!OPTION (Opt_transparent)) |
2420 |
return pchanged; /* Don't try any more */ |
2421 |
|
2422 |
XGetWindowAttributes (xdisp, display->root, &wrootattr); |
2423 |
rootdepth = wrootattr.depth; |
2424 |
|
2425 |
XGetWindowAttributes (xdisp, parent[0], &wattr); |
2426 |
|
2427 |
if (rootdepth != wattr.depth) |
2428 |
{ |
2429 |
if (am_transparent) |
2430 |
{ |
2431 |
pchanged = 1; |
2432 |
XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]); |
2433 |
am_transparent = am_pixmap_trans = 0; |
2434 |
} |
2435 |
|
2436 |
return pchanged; /* Don't try any more */ |
2437 |
} |
2438 |
|
2439 |
/* Get all X ops out of the queue so that our information is up-to-date. */ |
2440 |
XSync (xdisp, False); |
2441 |
|
2442 |
/* |
2443 |
* Make the frame window set by the window manager have |
2444 |
* the root background. Some window managers put multiple nested frame |
2445 |
* windows for each client, so we have to take care about that. |
2446 |
*/ |
2447 |
i = (xa[XA_XROOTPMAP_ID] |
2448 |
&& XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID], |
2449 |
0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2450 |
&nitems, &bytes_after, &prop) == Success); |
2451 |
|
2452 |
if (!i || prop == NULL) |
2453 |
i = (xa[XA_ESETROOT_PMAP_ID] |
2454 |
&& XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID], |
2455 |
0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2456 |
&nitems, &bytes_after, &prop) == Success); |
2457 |
|
2458 |
if (!i || prop == NULL |
2459 |
#if TINTING |
2460 |
|| !rs[Rs_color + Color_tint] |
2461 |
#endif |
2462 |
) |
2463 |
have_pixmap = 0; |
2464 |
else |
2465 |
{ |
2466 |
have_pixmap = 1; |
2467 |
rootpixmap = *(Pixmap *)prop; |
2468 |
XFree (prop); |
2469 |
} |
2470 |
|
2471 |
if (have_pixmap) |
2472 |
{ |
2473 |
/* |
2474 |
* Copy display->root pixmap transparency |
2475 |
*/ |
2476 |
int sx, sy, nx, ny; |
2477 |
unsigned int nw, nh; |
2478 |
Window cr; |
2479 |
XImage *image; |
2480 |
GC gc; |
2481 |
XGCValues gcvalue; |
2482 |
|
2483 |
XTranslateCoordinates (xdisp, parent[0], display->root, |
2484 |
0, 0, &sx, &sy, &cr); |
2485 |
nw = (unsigned int)szHint.width; |
2486 |
nh = (unsigned int)szHint.height; |
2487 |
nx = ny = 0; |
2488 |
|
2489 |
if (sx < 0) |
2490 |
{ |
2491 |
nw += sx; |
2492 |
nx = -sx; |
2493 |
sx = 0; |
2494 |
} |
2495 |
|
2496 |
if (sy < 0) |
2497 |
{ |
2498 |
nh += sy; |
2499 |
ny = -sy; |
2500 |
sy = 0; |
2501 |
} |
2502 |
|
2503 |
min_it (nw, (unsigned int) (wrootattr.width - sx)); |
2504 |
min_it (nh, (unsigned int) (wrootattr.height - sy)); |
2505 |
|
2506 |
XSync (xdisp, False); |
2507 |
allowedxerror = -1; |
2508 |
image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); |
2509 |
|
2510 |
/* XXX: handle BadMatch - usually because we're outside the pixmap */ |
2511 |
/* XXX: may need a delay here? */ |
2512 |
allowedxerror = 0; |
2513 |
|
2514 |
if (image == NULL) |
2515 |
{ |
2516 |
if (am_transparent && am_pixmap_trans) |
2517 |
{ |
2518 |
pchanged = 1; |
2519 |
if (pixmap != None) |
2520 |
{ |
2521 |
XFreePixmap (xdisp, pixmap); |
2522 |
pixmap = None; |
2523 |
} |
2524 |
} |
2525 |
|
2526 |
am_pixmap_trans = 0; |
2527 |
} |
2528 |
else |
2529 |
{ |
2530 |
if (pixmap != None) |
2531 |
XFreePixmap (xdisp, pixmap); |
2532 |
|
2533 |
#if TINTING |
2534 |
if (ISSET_PIXCOLOR (Color_tint)) |
2535 |
{ |
2536 |
unsigned short rm, gm, bm; |
2537 |
int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; |
2538 |
|
2539 |
pix_colors_focused[Color_tint].get (this, rm, gm, bm); |
2540 |
|
2541 |
ShadeXImage (this, image, shade, rm, gm, bm); |
2542 |
} |
2543 |
#endif |
2544 |
|
2545 |
pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth); |
2546 |
gc = XCreateGC (xdisp, vt, 0UL, &gcvalue); |
2547 |
XPutImage (xdisp, pixmap, gc, image, 0, 0, |
2548 |
nx, ny, image->width, image->height); |
2549 |
XFreeGC (xdisp, gc); |
2550 |
XDestroyImage (image); |
2551 |
XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap); |
2552 |
XClearWindow (xdisp, parent[0]); |
2553 |
|
2554 |
if (!am_transparent || !am_pixmap_trans) |
2555 |
pchanged = 1; |
2556 |
|
2557 |
am_transparent = am_pixmap_trans = 1; |
2558 |
} |
2559 |
} |
2560 |
|
2561 |
if (am_pixmap_trans) |
2562 |
XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); |
2563 |
else |
2564 |
{ |
2565 |
unsigned int n; |
2566 |
/* |
2567 |
* InheritPixmap transparency |
2568 |
*/ |
2569 |
for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
2570 |
{ |
2571 |
oldp = parent[i]; |
2572 |
XQueryTree (xdisp, parent[i - 1], &root, |
2573 |
&parent[i], &list, &n); |
2574 |
XFree (list); |
2575 |
|
2576 |
if (parent[i] == display->root) |
2577 |
{ |
2578 |
if (oldp != None) |
2579 |
pchanged = 1; |
2580 |
|
2581 |
break; |
2582 |
} |
2583 |
|
2584 |
if (oldp != parent[i]) |
2585 |
pchanged = 1; |
2586 |
} |
2587 |
|
2588 |
n = 0; |
2589 |
|
2590 |
if (pchanged) |
2591 |
{ |
2592 |
for (; n < (unsigned int)i; n++) |
2593 |
{ |
2594 |
XGetWindowAttributes (xdisp, parent[n], &wattr); |
2595 |
if (wattr.depth != rootdepth || wattr.c_class == InputOnly) |
2596 |
{ |
2597 |
n = (int) (sizeof (parent) / sizeof (Window)) + 1; |
2598 |
break; |
2599 |
} |
2600 |
} |
2601 |
} |
2602 |
|
2603 |
if (n > (int) (sizeof (parent) / sizeof (parent[0]))) |
2604 |
{ |
2605 |
XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]); |
2606 |
XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]); |
2607 |
am_transparent = 0; |
2608 |
/* XXX: also turn off Opt_transparent? */ |
2609 |
} |
2610 |
else |
2611 |
{ |
2612 |
for (n = 0; n < (unsigned int)i; n++) |
2613 |
{ |
2614 |
XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative); |
2615 |
XClearWindow (xdisp, parent[n]); |
2616 |
} |
2617 |
|
2618 |
XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); |
2619 |
am_transparent = 1; |
2620 |
} |
2621 |
|
2622 |
for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
2623 |
parent[i] = None; |
2624 |
} |
2625 |
|
2626 |
if (scrollBar.win) |
2627 |
{ |
2628 |
XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative); |
2629 |
scrollBar.setIdle (); |
2630 |
scrollbar_show (0); |
2631 |
} |
2632 |
|
2633 |
if (am_transparent) |
2634 |
{ |
2635 |
want_refresh = want_full_refresh = 1; |
2636 |
if (am_pixmap_trans) |
2637 |
flush (); |
2638 |
} |
2639 |
|
2640 |
return pchanged; |
2641 |
} |
2642 |
#endif |
2643 |
|
2644 |
/*}}} */ |
2645 |
|
2646 |
bool |
2647 |
rxvt_term::cmd_parse () |
2648 |
{ |
2649 |
bool flag = false; |
2650 |
wchar_t ch = NOCHAR; |
2651 |
char *seq_begin; // remember start of esc-sequence here |
2652 |
|
2653 |
for (;;) |
2654 |
{ |
2655 |
if (ch == NOCHAR) |
2656 |
{ |
2657 |
seq_begin = cmdbuf_ptr; |
2658 |
ch = next_char (); |
2659 |
|
2660 |
if (ch == NOCHAR) |
2661 |
break; |
2662 |
} |
2663 |
|
2664 |
if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) |
2665 |
{ |
2666 |
if (!seen_input) |
2667 |
{ |
2668 |
seen_input = 1; |
2669 |
// many badly-written programs (e.g. jed) contain a race condition: |
2670 |
// they first read the screensize and then install a SIGWINCH handler. |
2671 |
// some window managers resize the window early, and these programs |
2672 |
// then sometimes get the size wrong. |
2673 |
// unfortunately other programs are even more buggy and dislike |
2674 |
// being sent SIGWINCH, so only do it when we were in fact being |
2675 |
// resized. |
2676 |
if (seen_resize && cmd_pid) |
2677 |
kill (-cmd_pid, SIGWINCH); |
2678 |
} |
2679 |
|
2680 |
/* Read a text string from the input buffer */ |
2681 |
wchar_t buf[UBUFSIZ]; |
2682 |
bool refreshnow = false; |
2683 |
int nlines = 0; |
2684 |
wchar_t *str = buf; |
2685 |
wchar_t *eol = str + min (ncol, UBUFSIZ); |
2686 |
|
2687 |
for (;;) |
2688 |
{ |
2689 |
if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) |
2690 |
break; |
2691 |
|
2692 |
*str++ = ch; |
2693 |
|
2694 |
if (ch == C0_LF || str >= eol) |
2695 |
{ |
2696 |
if (ch == C0_LF) |
2697 |
nlines++; |
2698 |
|
2699 |
refresh_count++; |
2700 |
|
2701 |
if (!OPTION (Opt_jumpScroll) |
2702 |
|| (refresh_count >= refresh_limit * (nrow - 1))) |
2703 |
{ |
2704 |
refreshnow = true; |
2705 |
refresh_count = 0; |
2706 |
ch = NOCHAR; |
2707 |
break; |
2708 |
} |
2709 |
|
2710 |
// scr_add_lines only works for nlines <= nrow - 1. |
2711 |
if (nlines >= nrow - 1) |
2712 |
{ |
2713 |
if (!(SHOULD_INVOKE (HOOK_ADD_LINES) |
2714 |
&& HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) |
2715 |
scr_add_lines (buf, str - buf, nlines); |
2716 |
|
2717 |
nlines = 0; |
2718 |
str = buf; |
2719 |
eol = str + min (ncol, UBUFSIZ); |
2720 |
} |
2721 |
|
2722 |
if (str >= eol) |
2723 |
{ |
2724 |
if (eol >= buf + UBUFSIZ) |
2725 |
{ |
2726 |
ch = NOCHAR; |
2727 |
break; |
2728 |
} |
2729 |
else |
2730 |
eol = min (eol + ncol, buf + UBUFSIZ); |
2731 |
} |
2732 |
|
2733 |
} |
2734 |
|
2735 |
seq_begin = cmdbuf_ptr; |
2736 |
ch = next_char (); |
2737 |
} |
2738 |
|
2739 |
if (!(SHOULD_INVOKE (HOOK_ADD_LINES) |
2740 |
&& HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) |
2741 |
scr_add_lines (buf, str - buf, nlines); |
2742 |
|
2743 |
/* |
2744 |
* If there have been a lot of new lines, then update the screen |
2745 |
* What the heck I'll cheat and only refresh less than every page-full. |
2746 |
* the number of pages between refreshes is refresh_limit, which |
2747 |
* is incremented here because we must be doing flat-out scrolling. |
2748 |
*/ |
2749 |
if (refreshnow) |
2750 |
{ |
2751 |
if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) |
2752 |
refresh_limit++; |
2753 |
else |
2754 |
{ |
2755 |
flag = true; |
2756 |
scr_refresh (); |
2757 |
want_refresh = 1; |
2758 |
} |
2759 |
} |
2760 |
|
2761 |
} |
2762 |
else |
2763 |
{ |
2764 |
try |
2765 |
{ |
2766 |
process_nonprinting (ch); |
2767 |
} |
2768 |
catch (const class out_of_input &o) |
2769 |
{ |
2770 |
// we ran out of input, retry later |
2771 |
cmdbuf_ptr = seq_begin; |
2772 |
break; |
2773 |
} |
2774 |
|
2775 |
ch = NOCHAR; |
2776 |
} |
2777 |
} |
2778 |
|
2779 |
return flag; |
2780 |
} |
2781 |
|
2782 |
// read the next character |
2783 |
wchar_t |
2784 |
rxvt_term::next_char () NOTHROW |
2785 |
{ |
2786 |
while (cmdbuf_ptr < cmdbuf_endp) |
2787 |
{ |
2788 |
// assume 7-bit to be ascii ALWAYS |
2789 |
if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) |
2790 |
return *cmdbuf_ptr++; |
2791 |
|
2792 |
wchar_t wc; |
2793 |
size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); |
2794 |
|
2795 |
if (len == (size_t)-2) |
2796 |
{ |
2797 |
// the mbstate stores incomplete sequences. didn't know this :/ |
2798 |
cmdbuf_ptr = cmdbuf_endp; |
2799 |
break; |
2800 |
} |
2801 |
|
2802 |
if (len == (size_t)-1) |
2803 |
return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through |
2804 |
|
2805 |
// assume wchar == unicode |
2806 |
cmdbuf_ptr += len; |
2807 |
return wc & UNICODE_MASK; |
2808 |
} |
2809 |
|
2810 |
return NOCHAR; |
2811 |
} |
2812 |
|
2813 |
// read the next octet |
2814 |
uint32_t |
2815 |
rxvt_term::next_octet () NOTHROW |
2816 |
{ |
2817 |
return cmdbuf_ptr < cmdbuf_endp |
2818 |
? (unsigned char)*cmdbuf_ptr++ |
2819 |
: NOCHAR; |
2820 |
} |
2821 |
|
2822 |
static class out_of_input out_of_input; |
2823 |
|
2824 |
/* rxvt_cmd_getc () - Return next input character */ |
2825 |
/* |
2826 |
* Return the next input character after first passing any keyboard input |
2827 |
* to the command. |
2828 |
*/ |
2829 |
wchar_t |
2830 |
rxvt_term::cmd_getc () THROW ((class out_of_input)) |
2831 |
{ |
2832 |
wchar_t c = next_char (); |
2833 |
|
2834 |
if (c == NOCHAR) |
2835 |
throw out_of_input; |
2836 |
|
2837 |
return c; |
2838 |
} |
2839 |
|
2840 |
uint32_t |
2841 |
rxvt_term::cmd_get8 () THROW ((class out_of_input)) |
2842 |
{ |
2843 |
uint32_t c = next_octet (); |
2844 |
|
2845 |
if (c == NOCHAR) |
2846 |
throw out_of_input; |
2847 |
|
2848 |
return c; |
2849 |
} |
2850 |
|
2851 |
/*{{{ print pipe */ |
2852 |
/*----------------------------------------------------------------------*/ |
2853 |
#ifdef PRINTPIPE |
2854 |
FILE * |
2855 |
rxvt_term::popen_printer () |
2856 |
{ |
2857 |
FILE *stream = popen (rs[Rs_print_pipe], "w"); |
2858 |
|
2859 |
if (stream == NULL) |
2860 |
rxvt_warn ("can't open printer pipe, not printing.\n"); |
2861 |
|
2862 |
return stream; |
2863 |
} |
2864 |
|
2865 |
int |
2866 |
rxvt_term::pclose_printer (FILE *stream) |
2867 |
{ |
2868 |
fflush (stream); |
2869 |
return pclose (stream); |
2870 |
} |
2871 |
|
2872 |
/* |
2873 |
* simulate attached vt100 printer |
2874 |
*/ |
2875 |
void |
2876 |
rxvt_term::process_print_pipe () |
2877 |
{ |
2878 |
int done; |
2879 |
FILE *fd; |
2880 |
|
2881 |
if ((fd = popen_printer ()) == NULL) |
2882 |
return; |
2883 |
|
2884 |
/* |
2885 |
* Send all input to the printer until either ESC[4i or ESC[?4i |
2886 |
* is received. |
2887 |
*/ |
2888 |
for (done = 0; !done;) |
2889 |
{ |
2890 |
unsigned char buf[8]; |
2891 |
unicode_t ch; |
2892 |
unsigned int i, len; |
2893 |
|
2894 |
if ((ch = cmd_getc ()) != C0_ESC) |
2895 |
{ |
2896 |
if (putc (ch, fd) == EOF) |
2897 |
break; /* done = 1 */ |
2898 |
} |
2899 |
else |
2900 |
{ |
2901 |
len = 0; |
2902 |
buf[len++] = ch; |
2903 |
|
2904 |
if ((buf[len++] = cmd_getc ()) == '[') |
2905 |
{ |
2906 |
if ((ch = cmd_getc ()) == '?') |
2907 |
{ |
2908 |
buf[len++] = '?'; |
2909 |
ch = cmd_getc (); |
2910 |
} |
2911 |
if ((buf[len++] = ch) == '4') |
2912 |
{ |
2913 |
if ((buf[len++] = cmd_getc ()) == 'i') |
2914 |
break; /* done = 1 */ |
2915 |
} |
2916 |
} |
2917 |
|
2918 |
for (i = 0; i < len; i++) |
2919 |
if (putc (buf[i], fd) == EOF) |
2920 |
{ |
2921 |
done = 1; |
2922 |
break; |
2923 |
} |
2924 |
} |
2925 |
} |
2926 |
|
2927 |
pclose_printer (fd); |
2928 |
} |
2929 |
#endif /* PRINTPIPE */ |
2930 |
/*}}} */ |
2931 |
|
2932 |
/* *INDENT-OFF* */ |
2933 |
enum { |
2934 |
C1_40 = 0x40, |
2935 |
C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, |
2936 |
C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, |
2937 |
C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, |
2938 |
C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, |
2939 |
}; |
2940 |
/* *INDENT-ON* */ |
2941 |
|
2942 |
/*{{{ process non-printing single characters */ |
2943 |
void |
2944 |
rxvt_term::process_nonprinting (unicode_t ch) |
2945 |
{ |
2946 |
switch (ch) |
2947 |
{ |
2948 |
case C0_ESC: |
2949 |
process_escape_seq (); |
2950 |
break; |
2951 |
case C0_ENQ: /* terminal Status */ |
2952 |
if (rs[Rs_answerbackstring]) |
2953 |
tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring])); |
2954 |
else |
2955 |
tt_write (VT100_ANS, strlen (VT100_ANS)); |
2956 |
break; |
2957 |
case C0_BEL: /* bell */ |
2958 |
scr_bell (); |
2959 |
break; |
2960 |
case C0_BS: /* backspace */ |
2961 |
scr_backspace (); |
2962 |
break; |
2963 |
case C0_HT: /* tab */ |
2964 |
scr_tab (1); |
2965 |
break; |
2966 |
case C0_CR: /* carriage return */ |
2967 |
scr_gotorc (0, 0, R_RELATIVE); |
2968 |
break; |
2969 |
case C0_VT: /* vertical tab, form feed */ |
2970 |
case C0_FF: |
2971 |
case C0_LF: /* line feed */ |
2972 |
scr_index (UP); |
2973 |
break; |
2974 |
case C0_SO: /* shift out - acs */ |
2975 |
scr_charset_choose (1); |
2976 |
break; |
2977 |
case C0_SI: /* shift in - acs */ |
2978 |
scr_charset_choose (0); |
2979 |
break; |
2980 |
|
2981 |
#ifdef EIGHT_BIT_CONTROLS |
2982 |
// 8-bit controls |
2983 |
case 0x90: /* DCS */ |
2984 |
process_dcs_seq (); |
2985 |
break; |
2986 |
case 0x9b: /* CSI */ |
2987 |
process_csi_seq (); |
2988 |
break; |
2989 |
case 0x9d: /* CSI */ |
2990 |
process_osc_seq (); |
2991 |
break; |
2992 |
#endif |
2993 |
} |
2994 |
} |
2995 |
/*}}} */ |
2996 |
|
2997 |
|
2998 |
/*{{{ process VT52 escape sequences */ |
2999 |
void |
3000 |
rxvt_term::process_escape_vt52 (unicode_t ch) |
3001 |
{ |
3002 |
int row, col; |
3003 |
|
3004 |
switch (ch) |
3005 |
{ |
3006 |
case 'A': /* cursor up */ |
3007 |
scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE); |
3008 |
break; |
3009 |
case 'B': /* cursor down */ |
3010 |
scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE); |
3011 |
break; |
3012 |
case 'C': /* cursor right */ |
3013 |
scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); |
3014 |
break; |
3015 |
case 'D': /* cursor left */ |
3016 |
scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE); |
3017 |
break; |
3018 |
case 'H': /* cursor home */ |
3019 |
scr_gotorc (0, 0, 0); |
3020 |
break; |
3021 |
case 'I': /* cursor up and scroll down if needed */ |
3022 |
scr_index (DN); |
3023 |
break; |
3024 |
case 'J': /* erase to end of screen */ |
3025 |
scr_erase_screen (0); |
3026 |
break; |
3027 |
case 'K': /* erase to end of line */ |
3028 |
scr_erase_line (0); |
3029 |
break; |
3030 |
case 'Y': /* move to specified row and col */ |
3031 |
/* full command is 'ESC Y row col' where row and col |
3032 |
* are encoded by adding 32 and sending the ascii |
3033 |
* character. eg. SPACE = 0, '+' = 13, '0' = 18, |
3034 |
* etc. */ |
3035 |
row = cmd_getc () - ' '; |
3036 |
col = cmd_getc () - ' '; |
3037 |
scr_gotorc (row, col, 0); |
3038 |
break; |
3039 |
case 'Z': /* identify the terminal type */ |
3040 |
tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ |
3041 |
break; |
3042 |
case '<': /* turn off VT52 mode */ |
3043 |
PrivMode (0, PrivMode_vt52); |
3044 |
break; |
3045 |
case 'F': /* use special graphics character set */ |
3046 |
case 'G': /* use regular character set */ |
3047 |
/* unimplemented */ |
3048 |
break; |
3049 |
case '=': /* use alternate keypad mode */ |
3050 |
case '>': /* use regular keypad mode */ |
3051 |
/* unimplemented */ |
3052 |
break; |
3053 |
} |
3054 |
} |
3055 |
/*}}} */ |
3056 |
|
3057 |
|
3058 |
/*{{{ process escape sequences */ |
3059 |
void |
3060 |
rxvt_term::process_escape_seq () |
3061 |
{ |
3062 |
unicode_t ch = cmd_getc (); |
3063 |
|
3064 |
if (priv_modes & PrivMode_vt52) |
3065 |
{ |
3066 |
process_escape_vt52 (ch); |
3067 |
return; |
3068 |
} |
3069 |
|
3070 |
switch (ch) |
3071 |
{ |
3072 |
/* case 1: do_tek_mode (); break; */ |
3073 |
case '#': |
3074 |
if (cmd_getc () == '8') |
3075 |
scr_E (); |
3076 |
break; |
3077 |
case '(': |
3078 |
scr_charset_set (0, (unsigned int)cmd_getc ()); |
3079 |
break; |
3080 |
case ')': |
3081 |
scr_charset_set (1, (unsigned int)cmd_getc ()); |
3082 |
break; |
3083 |
case '*': |
3084 |
scr_charset_set (2, (unsigned int)cmd_getc ()); |
3085 |
break; |
3086 |
case '+': |
3087 |
scr_charset_set (3, (unsigned int)cmd_getc ()); |
3088 |
break; |
3089 |
#if ENABLE_FRILLS |
3090 |
case '6': |
3091 |
scr_backindex (); |
3092 |
break; |
3093 |
#endif |
3094 |
case '7': |
3095 |
scr_cursor (SAVE); |
3096 |
break; |
3097 |
case '8': |
3098 |
scr_cursor (RESTORE); |
3099 |
break; |
3100 |
#if ENABLE_FRILLS |
3101 |
case '9': |
3102 |
scr_forwardindex (); |
3103 |
break; |
3104 |
#endif |
3105 |
case '=': |
3106 |
case '>': |
3107 |
PrivMode ((ch == '='), PrivMode_aplKP); |
3108 |
break; |
3109 |
|
3110 |
case C1_40: |
3111 |
cmd_getc (); |
3112 |
break; |
3113 |
case C1_44: |
3114 |
scr_index (UP); |
3115 |
break; |
3116 |
|
3117 |
/* 8.3.87: NEXT LINE */ |
3118 |
case C1_NEL: /* ESC E */ |
3119 |
{ |
3120 |
wchar_t nlcr[] = { C0_LF, C0_CR }; |
3121 |
scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1); |
3122 |
} |
3123 |
break; |
3124 |
|
3125 |
/* kidnapped escape sequence: Should be 8.3.48 */ |
3126 |
case C1_ESA: /* ESC G */ |
3127 |
process_graphics (); |
3128 |
break; |
3129 |
|
3130 |
/* 8.3.63: CHARACTER TABULATION SET */ |
3131 |
case C1_HTS: /* ESC H */ |
3132 |
scr_set_tab (1); |
3133 |
break; |
3134 |
|
3135 |
/* 8.3.105: REVERSE LINE FEED */ |
3136 |
case C1_RI: /* ESC M */ |
3137 |
scr_index (DN); |
3138 |
break; |
3139 |
|
3140 |
/* 8.3.142: SINGLE-SHIFT TWO */ |
3141 |
/*case C1_SS2: scr_single_shift (2); break; */ |
3142 |
|
3143 |
/* 8.3.143: SINGLE-SHIFT THREE */ |
3144 |
/*case C1_SS3: scr_single_shift (3); break; */ |
3145 |
|
3146 |
/* 8.3.27: DEVICE CONTROL STRING */ |
3147 |
case C1_DCS: /* ESC P */ |
3148 |
process_dcs_seq (); |
3149 |
break; |
3150 |
|
3151 |
/* 8.3.110: SINGLE CHARACTER INTRODUCER */ |
3152 |
case C1_SCI: /* ESC Z */ |
3153 |
tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); |
3154 |
break; /* steal obsolete ESC [ c */ |
3155 |
|
3156 |
/* 8.3.16: CONTROL SEQUENCE INTRODUCER */ |
3157 |
case C1_CSI: /* ESC [ */ |
3158 |
process_csi_seq (); |
3159 |
break; |
3160 |
|
3161 |
/* 8.3.90: OPERATING SYSTEM COMMAND */ |
3162 |
case C1_OSC: /* ESC ] */ |
3163 |
process_osc_seq (); |
3164 |
break; |
3165 |
|
3166 |
/* 8.3.106: RESET TO INITIAL STATE */ |
3167 |
case 'c': |
3168 |
mbstate.reset (); |
3169 |
scr_poweron (); |
3170 |
scrollbar_show (1); |
3171 |
break; |
3172 |
|
3173 |
/* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ |
3174 |
case 'n': |
3175 |
scr_charset_choose (2); |
3176 |
break; |
3177 |
|
3178 |
/* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */ |
3179 |
case 'o': |
3180 |
scr_charset_choose (3); |
3181 |
break; |
3182 |
} |
3183 |
} |
3184 |
/*}}} */ |
3185 |
|
3186 |
/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ |
3187 |
/* *INDENT-OFF* */ |
3188 |
enum { |
3189 |
CSI_ICH = 0x40, |
3190 |
CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, |
3191 |
CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , |
3192 |
CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, |
3193 |
CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F, |
3194 |
CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC, |
3195 |
CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ, |
3196 |
CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 , |
3197 |
CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F |
3198 |
}; |
3199 |
|
3200 |
#define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \ |
3201 |
(((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \ |
3202 |
| ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0)) |
3203 |
#define get_byte_array_bit(array, bit) \ |
3204 |
(!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7)))) |
3205 |
|
3206 |
const unsigned char csi_defaults[] = |
3207 |
{ |
3208 |
make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */ |
3209 |
make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */ |
3210 |
make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */ |
3211 |
make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */ |
3212 |
make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ |
3213 |
make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ |
3214 |
make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ |
3215 |
make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ |
3216 |
}; |
3217 |
/* *INDENT-ON* */ |
3218 |
|
3219 |
void |
3220 |
rxvt_term::process_csi_seq () |
3221 |
{ |
3222 |
unicode_t ch, priv, i; |
3223 |
unsigned int nargs, p; |
3224 |
int n, ndef; |
3225 |
int arg[ESC_ARGS]; |
3226 |
|
3227 |
for (nargs = ESC_ARGS; nargs > 0;) |
3228 |
arg[--nargs] = 0; |
3229 |
|
3230 |
priv = 0; |
3231 |
ch = cmd_getc (); |
3232 |
if (ch >= '<' && ch <= '?') |
3233 |
{ /* '<' '=' '>' '?' */ |
3234 |
priv = ch; |
3235 |
ch = cmd_getc (); |
3236 |
} |
3237 |
|
3238 |
/* read any numerical arguments */ |
3239 |
for (n = -1; ch < CSI_ICH; ) |
3240 |
{ |
3241 |
if (isdigit (ch)) |
3242 |
{ |
3243 |
if (n < 0) |
3244 |
n = ch - '0'; |
3245 |
else |
3246 |
n = n * 10 + ch - '0'; |
3247 |
} |
3248 |
else if (ch == ';') |
3249 |
{ |
3250 |
if (nargs < ESC_ARGS) |
3251 |
arg[nargs++] = n; |
3252 |
n = -1; |
3253 |
} |
3254 |
else if (IS_CONTROL (ch)) |
3255 |
process_nonprinting (ch); |
3256 |
|
3257 |
ch = cmd_getc (); |
3258 |
} |
3259 |
|
3260 |
if (ch > CSI_7F) |
3261 |
return; |
3262 |
|
3263 |
if (nargs < ESC_ARGS) |
3264 |
arg[nargs++] = n; |
3265 |
|
3266 |
i = ch - CSI_ICH; |
3267 |
ndef = get_byte_array_bit (csi_defaults, i); |
3268 |
for (p = 0; p < nargs; p++) |
3269 |
if (arg[p] == -1) |
3270 |
arg[p] = ndef; |
3271 |
|
3272 |
/* |
3273 |
* private mode handling |
3274 |
*/ |
3275 |
if (priv) |
3276 |
{ |
3277 |
switch (priv) |
3278 |
{ |
3279 |
case '>': |
3280 |
if (ch == CSI_DA) /* secondary device attributes */ |
3281 |
{ |
3282 |
// first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, |
3283 |
// 'U' for rxvt-unicode != 7.[34] (where it was broken). |
3284 |
// |
3285 |
// second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt |
3286 |
// and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify |
3287 |
// that we do not support xterm mouse reporting (should be 95 when we do). |
3288 |
// |
3289 |
tt_printf ("\033[>%d;94;0c", 'U'); |
3290 |
} |
3291 |
break; |
3292 |
case '?': |
3293 |
if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') |
3294 |
process_terminal_mode (ch, priv, nargs, arg); |
3295 |
break; |
3296 |
} |
3297 |
return; |
3298 |
} |
3299 |
|
3300 |
switch (ch) |
3301 |
{ |
3302 |
/* |
3303 |
* ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses) |
3304 |
*/ |
3305 |
#ifdef PRINTPIPE |
3306 |
case CSI_MC: /* 8.3.83: (0) MEDIA COPY */ |
3307 |
switch (arg[0]) |
3308 |
{ |
3309 |
case 0: /* initiate transfer to primary aux device */ |
3310 |
scr_printscreen (0); |
3311 |
break; |
3312 |
case 5: /* start relay to primary aux device */ |
3313 |
process_print_pipe (); |
3314 |
break; |
3315 |
} |
3316 |
break; |
3317 |
#endif |
3318 |
|
3319 |
case CSI_CUU: /* 8.3.22: (1) CURSOR UP */ |
3320 |
case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ |
3321 |
arg[0] = -arg[0]; |
3322 |
/* FALLTHROUGH */ |
3323 |
case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */ |
3324 |
case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ |
3325 |
scr_gotorc (arg[0], 0, RELATIVE); |
3326 |
break; |
3327 |
|
3328 |
case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */ |
3329 |
case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ |
3330 |
#ifdef ISO6429 |
3331 |
arg[0] = -arg[0]; |
3332 |
#else /* emulate common DEC VTs */ |
3333 |
arg[0] = arg[0] ? -arg[0] : -1; |
3334 |
#endif |
3335 |
/* FALLTHROUGH */ |
3336 |
case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */ |
3337 |
case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */ |
3338 |
#ifdef ISO6429 |
3339 |
scr_gotorc (0, arg[0], RELATIVE); |
3340 |
#else /* emulate common DEC VTs */ |
3341 |
scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE); |
3342 |
#endif |
3343 |
break; |
3344 |
|
3345 |
case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */ |
3346 |
arg[0] = -arg[0]; |
3347 |
/* FALLTHROUGH */ |
3348 |
case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */ |
3349 |
scr_gotorc (arg[0], 0, R_RELATIVE); |
3350 |
break; |
3351 |
|
3352 |
case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */ |
3353 |
case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */ |
3354 |
scr_gotorc (0, arg[0] - 1, R_RELATIVE); |
3355 |
break; |
3356 |
|
3357 |
case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */ |
3358 |
scr_gotorc (arg[0] - 1, 0, C_RELATIVE); |
3359 |
break; |
3360 |
|
3361 |
case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */ |
3362 |
case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */ |
3363 |
scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0); |
3364 |
break; |
3365 |
|
3366 |
case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */ |
3367 |
arg[0] = -arg[0]; |
3368 |
/* FALLTHROUGH */ |
3369 |
case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */ |
3370 |
scr_tab (arg[0]); |
3371 |
break; |
3372 |
|
3373 |
case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */ |
3374 |
scr_erase_screen (arg[0]); |
3375 |
break; |
3376 |
|
3377 |
case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */ |
3378 |
scr_erase_line (arg[0]); |
3379 |
break; |
3380 |
|
3381 |
case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */ |
3382 |
scr_insdel_chars (arg[0], INSERT); |
3383 |
break; |
3384 |
|
3385 |
case CSI_IL: /* 8.3.68: (1) INSERT LINE */ |
3386 |
scr_insdel_lines (arg[0], INSERT); |
3387 |
break; |
3388 |
|
3389 |
case CSI_DL: /* 8.3.33: (1) DELETE LINE */ |
3390 |
scr_insdel_lines (arg[0], DELETE); |
3391 |
break; |
3392 |
|
3393 |
case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */ |
3394 |
scr_insdel_chars (arg[0], ERASE); |
3395 |
break; |
3396 |
|
3397 |
case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */ |
3398 |
scr_insdel_chars (arg[0], DELETE); |
3399 |
break; |
3400 |
|
3401 |
case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ |
3402 |
arg[0] = -arg[0]; |
3403 |
/* FALLTHROUGH */ |
3404 |
case CSI_SU: /* 8.3.148: (1) SCROLL UP */ |
3405 |
scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); |
3406 |
break; |
3407 |
|
3408 |
case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ |
3409 |
tt_write (VT100_ANS, sizeof (VT100_ANS) - 1); |
3410 |
break; |
3411 |
|
3412 |
case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ |
3413 |
process_sgr_mode (nargs, arg); |
3414 |
break; |
3415 |
|
3416 |
case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */ |
3417 |
switch (arg[0]) |
3418 |
{ |
3419 |
case 5: /* DSR requested */ |
3420 |
tt_printf ("\033[0n"); |
3421 |
break; |
3422 |
case 6: /* CPR requested */ |
3423 |
scr_report_position (); |
3424 |
break; |
3425 |
case 7: /* unofficial extension */ |
3426 |
if (OPTION (Opt_insecure)) |
3427 |
tt_printf ("%-.250s\012", rs[Rs_display_name]); |
3428 |
break; |
3429 |
case 8: /* unofficial extension */ |
3430 |
process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); |
3431 |
break; |
3432 |
} |
3433 |
break; |
3434 |
|
3435 |
case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */ |
3436 |
switch (arg[0]) |
3437 |
{ |
3438 |
case 0: /* char tab stop cleared at active position */ |
3439 |
scr_set_tab (0); |
3440 |
break; |
3441 |
/* case 1: */ /* line tab stop cleared in active line */ |
3442 |
/* case 2: */ /* char tab stops cleared in active line */ |
3443 |
case 3: /* all char tab stops are cleared */ |
3444 |
/* case 4: */ /* all line tab stops are cleared */ |
3445 |
case 5: /* all tab stops are cleared */ |
3446 |
scr_set_tab (-1); |
3447 |
break; |
3448 |
} |
3449 |
break; |
3450 |
|
3451 |
case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */ |
3452 |
switch (arg[0]) |
3453 |
{ |
3454 |
case 0: /* char tab stop set at active position */ |
3455 |
scr_set_tab (1); |
3456 |
break; /* = ESC H */ |
3457 |
/* case 1: */ /* line tab stop set at active line */ |
3458 |
case 2: /* char tab stop cleared at active position */ |
3459 |
scr_set_tab (0); |
3460 |
break; /* = ESC [ 0 g */ |
3461 |
/* case 3: */ /* line tab stop cleared at active line */ |
3462 |
/* case 4: */ /* char tab stops cleared at active line */ |
3463 |
case 5: /* all char tab stops are cleared */ |
3464 |
scr_set_tab (-1); |
3465 |
break; /* = ESC [ 3 g */ |
3466 |
/* case 6: */ /* all line tab stops are cleared */ |
3467 |
} |
3468 |
break; |
3469 |
|
3470 |
case CSI_RM: /* 8.3.107: RESET MODE */ |
3471 |
if (arg[0] == 4) |
3472 |
scr_insert_mode (0); |
3473 |
else if (arg[0] == 20) |
3474 |
priv_modes &= ~PrivMode_LFNL; |
3475 |
break; |
3476 |
|
3477 |
case CSI_SM: /* 8.3.126: SET MODE */ |
3478 |
if (arg[0] == 4) |
3479 |
scr_insert_mode (1); |
3480 |
else if (arg[0] == 20) |
3481 |
priv_modes |= PrivMode_LFNL; |
3482 |
break; |
3483 |
|
3484 |
/* |
3485 |
* PRIVATE USE beyond this point. All CSI_7? sequences here |
3486 |
*/ |
3487 |
case CSI_72: /* DECSTBM: set top and bottom margins */ |
3488 |
if (nargs == 1) |
3489 |
scr_scroll_region (arg[0] - 1, MAX_ROWS - 1); |
3490 |
else if (nargs == 0 || arg[0] >= arg[1]) |
3491 |
scr_scroll_region (0, MAX_ROWS - 1); |
3492 |
else |
3493 |
scr_scroll_region (arg[0] - 1, arg[1] - 1); |
3494 |
break; |
3495 |
|
3496 |
case CSI_73: |
3497 |
scr_cursor (SAVE); |
3498 |
break; |
3499 |
case CSI_75: |
3500 |
scr_cursor (RESTORE); |
3501 |
break; |
3502 |
|
3503 |
#if ENABLE_FRILLS |
3504 |
case CSI_74: |
3505 |
process_window_ops (arg, nargs); |
3506 |
break; |
3507 |
#endif |
3508 |
|
3509 |
case CSI_78: /* DECREQTPARM */ |
3510 |
if (arg[0] == 0 || arg[0] == 1) |
3511 |
tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2); |
3512 |
break; |
3513 |
|
3514 |
default: |
3515 |
break; |
3516 |
} |
3517 |
} |
3518 |
/*}}} */ |
3519 |
|
3520 |
#if ENABLE_FRILLS |
3521 |
/* ARGSUSED */ |
3522 |
void |
3523 |
rxvt_term::process_window_ops (const int *args, unsigned int nargs) |
3524 |
{ |
3525 |
int x, y; |
3526 |
XWindowAttributes wattr; |
3527 |
Window wdummy; |
3528 |
|
3529 |
dLocal (Display *, xdisp); |
3530 |
|
3531 |
if (nargs == 0) |
3532 |
return; |
3533 |
|
3534 |
switch (args[0]) |
3535 |
{ |
3536 |
/* |
3537 |
* commands |
3538 |
*/ |
3539 |
case 1: /* deiconify window */ |
3540 |
XMapWindow (xdisp, parent[0]); |
3541 |
break; |
3542 |
case 2: /* iconify window */ |
3543 |
XIconifyWindow (xdisp, parent[0], display->screen); |
3544 |
break; |
3545 |
case 3: /* set position (pixels) */ |
3546 |
XMoveWindow (xdisp, parent[0], args[1], args[2]); |
3547 |
break; |
3548 |
case 4: /* set size (pixels) */ |
3549 |
set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); |
3550 |
break; |
3551 |
case 5: /* raise window */ |
3552 |
XRaiseWindow (xdisp, parent[0]); |
3553 |
break; |
3554 |
case 6: /* lower window */ |
3555 |
XLowerWindow (xdisp, parent[0]); |
3556 |
break; |
3557 |
case 7: /* refresh window */ |
3558 |
scr_touch (true); |
3559 |
break; |
3560 |
case 8: /* set size (chars) */ |
3561 |
set_widthheight ((unsigned int) (args[2] * fwidth), |
3562 |
(unsigned int) (args[1] * fheight)); |
3563 |
break; |
3564 |
|
3565 |
//case 9: NYI, TODO, restore maximized window or maximize window |
3566 |
default: |
3567 |
if (args[0] >= 24) /* set height (chars) */ |
3568 |
set_widthheight ((unsigned int)width, |
3569 |
(unsigned int) (args[1] * fheight)); |
3570 |
break; |
3571 |
|
3572 |
|
3573 |
/* |
3574 |
* reports - some output format copied from XTerm |
3575 |
*/ |
3576 |
case 11: /* report window state */ |
3577 |
XGetWindowAttributes (xdisp, parent[0], &wattr); |
3578 |
tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); |
3579 |
break; |
3580 |
case 13: /* report window position */ |
3581 |
XGetWindowAttributes (xdisp, parent[0], &wattr); |
3582 |
XTranslateCoordinates (xdisp, parent[0], wattr.root, |
3583 |
-wattr.border_width, -wattr.border_width, |
3584 |
&x, &y, &wdummy); |
3585 |
tt_printf ("\033[3;%d;%dt", x, y); |
3586 |
break; |
3587 |
case 14: /* report window size (pixels) */ |
3588 |
XGetWindowAttributes (xdisp, parent[0], &wattr); |
3589 |
tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); |
3590 |
break; |
3591 |
case 18: /* report text area size (chars) */ |
3592 |
tt_printf ("\033[8;%d;%dt", nrow, ncol); |
3593 |
break; |
3594 |
case 19: /* report window size (chars) */ |
3595 |
tt_printf ("\033[9;%d;%dt", nrow, ncol); |
3596 |
break; |
3597 |
case 20: /* report icon label */ |
3598 |
{ |
3599 |
char *s; |
3600 |
XGetIconName (xdisp, parent[0], &s); |
3601 |
tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ |
3602 |
XFree (s); |
3603 |
} |
3604 |
break; |
3605 |
case 21: /* report window title */ |
3606 |
{ |
3607 |
char *s; |
3608 |
XFetchName (xdisp, parent[0], &s); |
3609 |
tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ |
3610 |
XFree (s); |
3611 |
} |
3612 |
break; |
3613 |
} |
3614 |
} |
3615 |
#endif |
3616 |
|
3617 |
/*----------------------------------------------------------------------*/ |
3618 |
/* |
3619 |
* get input up until STRING TERMINATOR (or BEL) |
3620 |
* ends_how is terminator used. returned input must be free()'d |
3621 |
*/ |
3622 |
char * |
3623 |
rxvt_term::get_to_st (unicode_t &ends_how) |
3624 |
{ |
3625 |
unicode_t ch; |
3626 |
bool seen_esc = false; |
3627 |
unsigned int n = 0; |
3628 |
wchar_t string[STRING_MAX]; |
3629 |
|
3630 |
while ((ch = cmd_getc ()) != NOCHAR) |
3631 |
{ |
3632 |
if (seen_esc) |
3633 |
{ |
3634 |
if (ch == 0x5c) /* 7bit ST */ |
3635 |
break; |
3636 |
else |
3637 |
return NULL; |
3638 |
} |
3639 |
else if (ch == C0_ESC) |
3640 |
{ |
3641 |
seen_esc = true; |
3642 |
continue; |
3643 |
} |
3644 |
else if (ch == C0_BEL || ch == CHAR_ST) |
3645 |
break; |
3646 |
else if (ch < 0x20) |
3647 |
return NULL; /* other control character - exit */ |
3648 |
|
3649 |
seen_esc = false; |
3650 |
|
3651 |
if (n >= STRING_MAX - 1) |
3652 |
// stop at some sane length |
3653 |
return NULL; |
3654 |
|
3655 |
if (ch == C0_SYN) |
3656 |
string[n++] = cmd_get8 (); |
3657 |
else |
3658 |
string[n++] = ch; |
3659 |
} |
3660 |
|
3661 |
string[n++] = '\0'; |
3662 |
|
3663 |
ends_how = (ch == 0x5c ? C0_ESC : ch); |
3664 |
|
3665 |
return rxvt_wcstombs (string); |
3666 |
} |
3667 |
|
3668 |
/*----------------------------------------------------------------------*/ |
3669 |
/* |
3670 |
* process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' |
3671 |
*/ |
3672 |
void |
3673 |
rxvt_term::process_dcs_seq () |
3674 |
{ |
3675 |
char *s; |
3676 |
unicode_t eh; |
3677 |
|
3678 |
/* |
3679 |
* Not handled yet |
3680 |
*/ |
3681 |
s = get_to_st (eh); |
3682 |
if (s) |
3683 |
free (s); |
3684 |
|
3685 |
return; |
3686 |
} |
3687 |
|
3688 |
/*----------------------------------------------------------------------*/ |
3689 |
/* |
3690 |
* process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' |
3691 |
*/ |
3692 |
void |
3693 |
rxvt_term::process_osc_seq () |
3694 |
{ |
3695 |
unicode_t ch, eh; |
3696 |
int arg; |
3697 |
|
3698 |
ch = cmd_getc (); |
3699 |
for (arg = 0; isdigit (ch); ch = cmd_getc ()) |
3700 |
arg = arg * 10 + (ch - '0'); |
3701 |
|
3702 |
if (ch == ';') |
3703 |
{ |
3704 |
char *s = get_to_st (eh); |
3705 |
|
3706 |
if (s) |
3707 |
{ |
3708 |
process_xterm_seq (arg, s, eh); |
3709 |
free (s); |
3710 |
} |
3711 |
} |
3712 |
} |
3713 |
|
3714 |
void |
3715 |
rxvt_term::process_color_seq (int report, int color, const char *str, char resp) |
3716 |
{ |
3717 |
if (str[0] == '?' && !str[1]) |
3718 |
{ |
3719 |
unsigned short r, g, b; |
3720 |
pix_colors_focused[color].get (this, r, g, b); |
3721 |
tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); |
3722 |
} |
3723 |
else |
3724 |
set_window_color (color, str); |
3725 |
} |
3726 |
|
3727 |
/* |
3728 |
* XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) |
3729 |
*/ |
3730 |
void |
3731 |
rxvt_term::process_xterm_seq (int op, const char *str, char resp) |
3732 |
{ |
3733 |
int color; |
3734 |
char *buf, *name; |
3735 |
bool query = str[0] == '?' && !str[1]; |
3736 |
int saveop = op; |
3737 |
|
3738 |
dLocal (Display *, xdisp); |
3739 |
|
3740 |
assert (str != NULL); |
3741 |
switch (op) |
3742 |
{ |
3743 |
case XTerm_name: |
3744 |
set_title (str); |
3745 |
/* FALLTHROUGH */ |
3746 |
case XTerm_iconName: |
3747 |
set_icon_name (str); |
3748 |
break; |
3749 |
case XTerm_title: |
3750 |
set_title (str); |
3751 |
break; |
3752 |
case XTerm_property: |
3753 |
if (str[0] == '?') |
3754 |
{ |
3755 |
Atom prop = display->atom (str + 1); |
3756 |
Atom actual_type; |
3757 |
int actual_format; |
3758 |
unsigned long nitems; |
3759 |
unsigned long bytes_after; |
3760 |
unsigned char *value = 0; |
3761 |
const char *str = ""; |
3762 |
|
3763 |
if (prop |
3764 |
&& XGetWindowProperty (xdisp, parent[0], |
3765 |
prop, 0, 1<<16, 0, AnyPropertyType, |
3766 |
&actual_type, &actual_format, |
3767 |
&nitems, &bytes_after, &value) == Success |
3768 |
&& actual_type != None |
3769 |
&& actual_format == 8) |
3770 |
str = (const char *)(value); |
3771 |
|
3772 |
tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); |
3773 |
|
3774 |
XFree (value); |
3775 |
} |
3776 |
else |
3777 |
{ |
3778 |
char *eq = strchr (str, '='); // constness lost, but verified to be ok |
3779 |
|
3780 |
if (eq) |
3781 |
{ |
3782 |
*eq = 0; |
3783 |
set_utf8_property (display->atom (str), eq + 1); |
3784 |
} |
3785 |
else |
3786 |
XDeleteProperty (xdisp, parent[0], |
3787 |
display->atom (str)); |
3788 |
} |
3789 |
break; |
3790 |
|
3791 |
case XTerm_Color: |
3792 |
for (buf = (char *)str; buf && *buf;) |
3793 |
{ |
3794 |
if ((name = strchr (buf, ';')) == NULL) |
3795 |
break; |
3796 |
|
3797 |
*name++ = '\0'; |
3798 |
color = atoi (buf) + minCOLOR; |
3799 |
|
3800 |
if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) |
3801 |
break; |
3802 |
|
3803 |
if ((buf = strchr (name, ';')) != NULL) |
3804 |
*buf++ = '\0'; |
3805 |
|
3806 |
if (name[0] == '?' && !name[1]) |
3807 |
{ |
3808 |
unsigned short r, g, b; |
3809 |
pix_colors_focused[color].get (this, r, g, b); |
3810 |
tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); |
3811 |
} |
3812 |
else |
3813 |
set_window_color (color, name); |
3814 |
} |
3815 |
break; |
3816 |
case XTerm_Color00: |
3817 |
process_color_seq (XTerm_Color00, Color_fg, str, resp); |
3818 |
break; |
3819 |
case XTerm_Color01: |
3820 |
process_color_seq (XTerm_Color01, Color_bg, str, resp); |
3821 |
break; |
3822 |
#ifndef NO_CURSORCOLOR |
3823 |
case XTerm_Color_cursor: |
3824 |
process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); |
3825 |
break; |
3826 |
#endif |
3827 |
case XTerm_Color_pointer_fg: |
3828 |
process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); |
3829 |
break; |
3830 |
case XTerm_Color_pointer_bg: |
3831 |
process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); |
3832 |
break; |
3833 |
#ifndef NO_BOLD_UNDERLINE_REVERSE |
3834 |
case XTerm_Color_RV: |
3835 |
process_color_seq (XTerm_Color_RV, Color_RV, str, resp); |
3836 |
break; |
3837 |
case Rxvt_Color_BD: |
3838 |
case URxvt_Color_BD: |
3839 |
process_color_seq (op, Color_BD, str, resp); |
3840 |
break; |
3841 |
case Rxvt_Color_UL: |
3842 |
case URxvt_Color_UL: |
3843 |
process_color_seq (op, Color_UL, str, resp); |
3844 |
break; |
3845 |
case URxvt_Color_IT: |
3846 |
process_color_seq (URxvt_Color_IT, Color_IT, str, resp); |
3847 |
break; |
3848 |
#endif |
3849 |
#if TRANSPARENT && TINTING |
3850 |
case URxvt_Color_tint: |
3851 |
process_color_seq (URxvt_Color_tint, Color_tint, str, resp); |
3852 |
check_our_parents (); |
3853 |
if (am_transparent) |
3854 |
want_full_refresh = want_refresh = 1; |
3855 |
break; |
3856 |
#endif |
3857 |
|
3858 |
case Rxvt_Pixmap: |
3859 |
{ |
3860 |
if (*str != ';') |
3861 |
{ |
3862 |
#if XPM_BACKGROUND |
3863 |
scale_pixmap (""); /* reset to default scaling */ |
3864 |
set_bgPixmap (str); /* change pixmap */ |
3865 |
scr_touch (true); |
3866 |
#endif |
3867 |
} |
3868 |
|
3869 |
int changed = 0; |
3870 |
|
3871 |
while ((str = strchr (str, ';')) != NULL) |
3872 |
{ |
3873 |
str++; |
3874 |
#if XPM_BACKGROUND |
3875 |
changed += scale_pixmap (str); |
3876 |
#endif |
3877 |
} |
3878 |
|
3879 |
if (changed) |
3880 |
{ |
3881 |
#ifdef XPM_BACKGROUND |
3882 |
resize_pixmap (); |
3883 |
scr_touch (true); |
3884 |
#endif |
3885 |
} |
3886 |
} |
3887 |
break; |
3888 |
|
3889 |
case Rxvt_restoreFG: |
3890 |
set_window_color (Color_fg, str); |
3891 |
break; |
3892 |
case Rxvt_restoreBG: |
3893 |
set_window_color (Color_bg, str); |
3894 |
break; |
3895 |
|
3896 |
case XTerm_logfile: |
3897 |
// TODO, when secure mode? |
3898 |
break; |
3899 |
|
3900 |
#if 0 |
3901 |
case Rxvt_dumpscreen: /* no error notices */ |
3902 |
{ |
3903 |
int fd; |
3904 |
if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) |
3905 |
{ |
3906 |
scr_dump (fd); |
3907 |
close (fd); |
3908 |
} |
3909 |
} |
3910 |
break; |
3911 |
#endif |
3912 |
case XTerm_font: |
3913 |
op = URxvt_font; |
3914 |
case URxvt_font: |
3915 |
#if ENABLE_STYLES |
3916 |
case URxvt_boldFont: |
3917 |
case URxvt_italicFont: |
3918 |
case URxvt_boldItalicFont: |
3919 |
#endif |
3920 |
if (query) |
3921 |
tt_printf ("\33]%d;%-.250s%c", saveop, |
3922 |
OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc |
3923 |
? fontset[op - URxvt_font]->fontdesc : "", |
3924 |
resp); |
3925 |
else |
3926 |
{ |
3927 |
const char *&res = rs[Rs_font + (op - URxvt_font)]; |
3928 |
|
3929 |
res = strdup (str); |
3930 |
allocated.push_back ((void *)res); |
3931 |
set_fonts (); |
3932 |
} |
3933 |
break; |
3934 |
|
3935 |
case URxvt_version: |
3936 |
if (query) |
3937 |
tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", |
3938 |
URxvt_version, |
3939 |
rs[Rs_name], |
3940 |
VERSION[0], VERSION[2], |
3941 |
resp); |
3942 |
break; |
3943 |
|
3944 |
#if ENABLE_FRILLS |
3945 |
case URxvt_locale: |
3946 |
if (query) |
3947 |
tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp); |
3948 |
else |
3949 |
{ |
3950 |
set_locale (str); |
3951 |
pty->set_utf8_mode (enc_utf8); |
3952 |
init_xlocale (); |
3953 |
} |
3954 |
break; |
3955 |
|
3956 |
case URxvt_view_up: |
3957 |
case URxvt_view_down: |
3958 |
{ |
3959 |
int lines = atoi (str); |
3960 |
|
3961 |
if (lines) |
3962 |
scr_page (op == URxvt_view_up ? UP : DN, lines); |
3963 |
else |
3964 |
scr_erase_savelines (); |
3965 |
} |
3966 |
|
3967 |
break; |
3968 |
#endif |
3969 |
|
3970 |
#if ENABLE_PERL |
3971 |
case URxvt_perl: |
3972 |
if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END))) |
3973 |
; // no responses yet |
3974 |
break; |
3975 |
#endif |
3976 |
} |
3977 |
} |
3978 |
/*----------------------------------------------------------------------*/ |
3979 |
|
3980 |
/*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */ |
3981 |
/* |
3982 |
* mode can only have the following values: |
3983 |
* 'l' = low |
3984 |
* 'h' = high |
3985 |
* 's' = save |
3986 |
* 'r' = restore |
3987 |
* 't' = toggle |
3988 |
* so no need for fancy checking |
3989 |
*/ |
3990 |
int |
3991 |
rxvt_term::privcases (int mode, unsigned long bit) |
3992 |
{ |
3993 |
int state; |
3994 |
|
3995 |
if (mode == 's') |
3996 |
{ |
3997 |
SavedModes |= (priv_modes & bit); |
3998 |
return -1; |
3999 |
} |
4000 |
else |
4001 |
{ |
4002 |
if (mode == 'r') |
4003 |
state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ |
4004 |
else |
4005 |
state = (mode == 't') ? ! (priv_modes & bit) : mode; |
4006 |
PrivMode (state, bit); |
4007 |
} |
4008 |
|
4009 |
return state; |
4010 |
} |
4011 |
|
4012 |
/* we're not using priv _yet_ */ |
4013 |
void |
4014 |
rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg) |
4015 |
{ |
4016 |
unsigned int i, j; |
4017 |
int state; |
4018 |
|
4019 |
static const struct |
4020 |
{ |
4021 |
const int argval; |
4022 |
const unsigned long bit; |
4023 |
} |
4024 |
|
4025 |
argtopriv[] = { |
4026 |
{ 1, PrivMode_aplCUR }, |
4027 |
{ 2, PrivMode_vt52 }, |
4028 |
{ 3, PrivMode_132 }, |
4029 |
{ 4, PrivMode_smoothScroll }, |
4030 |
{ 5, PrivMode_rVideo }, |
4031 |
{ 6, PrivMode_relOrigin }, |
4032 |
{ 7, PrivMode_Autowrap }, |
4033 |
// 8, bi-directional support mode |
4034 |
{ 9, PrivMode_MouseX10 }, |
4035 |
// 18, 19 printing-related |
4036 |
{ 25, PrivMode_VisibleCursor }, |
4037 |
#ifdef scrollBar_esc |
4038 |
{ scrollBar_esc, PrivMode_scrollBar }, |
4039 |
#endif |
4040 |
{ 35, PrivMode_ShiftKeys }, // rxvt extension |
4041 |
{ 40, PrivMode_132OK }, |
4042 |
// 41 xterm more fixes NYI |
4043 |
// 45 margin bell NYI |
4044 |
// 46 start logging |
4045 |
{ 47, PrivMode_Screen }, |
4046 |
{ 66, PrivMode_aplKP }, |
4047 |
#ifndef NO_BACKSPACE_KEY |
4048 |
{ 67, PrivMode_BackSpace }, |
4049 |
#endif |
4050 |
{ 1000, PrivMode_MouseX11 }, |
4051 |
// 1001 Use Hilite Mouse Tracking. NYI, TODO |
4052 |
// 1002 Use Cell Motion Mouse Tracking. NYI, TODO |
4053 |
// 1003 Use All Motion Mouse Tracking. NYI, TODO |
4054 |
{ 1010, PrivMode_TtyOutputInh }, // rxvt extension |
4055 |
{ 1011, PrivMode_Keypress }, // rxvt extension |
4056 |
// 1035 enable modifiers for alt, numlock NYI |
4057 |
// 1036 send ESC for meta keys NYI |
4058 |
// 1037 send DEL for keypad delete NYI |
4059 |
{ 1047, PrivMode_Screen }, |
4060 |
// 1048 save and restore cursor |
4061 |
{ 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ |
4062 |
// 1051, 1052, 1060, 1061 keyboard emulation NYI |
4063 |
}; |
4064 |
|
4065 |
if (nargs == 0) |
4066 |
return; |
4067 |
|
4068 |
/* make lo/hi boolean */ |
4069 |
if (mode == 'l') |
4070 |
mode = 0; /* reset */ |
4071 |
else if (mode == 'h') |
4072 |
mode = 1; /* set */ |
4073 |
|
4074 |
for (i = 0; i < nargs; i++) |
4075 |
{ |
4076 |
state = -1; |
4077 |
|
4078 |
/* basic handling */ |
4079 |
for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++) |
4080 |
if (argtopriv[j].argval == arg[i]) |
4081 |
{ |
4082 |
state = privcases (mode, argtopriv[j].bit); |
4083 |
break; |
4084 |
} |
4085 |
|
4086 |
/* extra handling for values with state unkept */ |
4087 |
switch (arg[i]) |
4088 |
{ |
4089 |
#if ENABLE_STYLES |
4090 |
case 1021: |
4091 |
set_option (Opt_intensityStyles, mode); |
4092 |
|
4093 |
scr_touch (true); |
4094 |
break; |
4095 |
#endif |
4096 |
case 1048: /* alternative cursor save */ |
4097 |
case 1049: |
4098 |
if (OPTION (Opt_secondaryScreen)) |
4099 |
if (mode == 0) |
4100 |
scr_cursor (RESTORE); |
4101 |
else if (mode == 1) |
4102 |
scr_cursor (SAVE); |
4103 |
break; |
4104 |
} |
4105 |
|
4106 |
if (state >= 0) |
4107 |
/* extra handling for values with valid 0 or 1 state */ |
4108 |
switch (arg[i]) |
4109 |
{ |
4110 |
/* case 1: - application cursor keys */ |
4111 |
case 2: /* VT52 mode */ |
4112 |
/* oddball mode. should be set regardless of set/reset |
4113 |
* parameter. Return from VT52 mode with an ESC < from |
4114 |
* within VT52 mode |
4115 |
*/ |
4116 |
PrivMode (1, PrivMode_vt52); |
4117 |
break; |
4118 |
case 3: /* 80/132 */ |
4119 |
if (priv_modes & PrivMode_132OK) |
4120 |
set_widthheight (((state ? 132 : 80) * fwidth), height); |
4121 |
break; |
4122 |
case 4: /* smooth scrolling */ |
4123 |
set_option (Opt_jumpScroll, !state); |
4124 |
break; |
4125 |
case 5: /* reverse video */ |
4126 |
scr_rvideo_mode (state); |
4127 |
break; |
4128 |
case 6: /* relative/absolute origins */ |
4129 |
scr_relative_origin (state); |
4130 |
break; |
4131 |
case 7: /* autowrap */ |
4132 |
scr_autowrap (state); |
4133 |
break; |
4134 |
/* case 8: - auto repeat, can't do on a per window basis */ |
4135 |
case 9: /* X10 mouse reporting */ |
4136 |
if (state) /* orthogonal */ |
4137 |
priv_modes &= ~PrivMode_MouseX11; |
4138 |
break; |
4139 |
#ifdef scrollBar_esc |
4140 |
case scrollBar_esc: |
4141 |
if (scrollbar_mapping (state)) |
4142 |
{ |
4143 |
resize_all_windows (0, 0, 0); |
4144 |
scr_touch (true); |
4145 |
} |
4146 |
break; |
4147 |
#endif |
4148 |
case 25: /* visible/invisible cursor */ |
4149 |
scr_cursor_visible (state); |
4150 |
break; |
4151 |
/* case 35: - shift keys */ |
4152 |
/* case 40: - 80 <--> 132 mode */ |
4153 |
case 47: /* secondary screen */ |
4154 |
scr_change_screen (state); |
4155 |
break; |
4156 |
/* case 66: - application key pad */ |
4157 |
/* case 67: - backspace key */ |
4158 |
case 1000: /* X11 mouse reporting */ |
4159 |
if (state) /* orthogonal */ |
4160 |
priv_modes &= ~PrivMode_MouseX10; |
4161 |
break; |
4162 |
#if 0 |
4163 |
case 1001: |
4164 |
break; /* X11 mouse highlighting */ |
4165 |
#endif |
4166 |
case 1010: /* scroll to bottom on TTY output inhibit */ |
4167 |
set_option (Opt_scrollTtyOutput, !state); |
4168 |
break; |
4169 |
case 1011: /* scroll to bottom on key press */ |
4170 |
set_option (Opt_scrollTtyKeypress, state); |
4171 |
break; |
4172 |
case 1047: /* secondary screen w/ clearing last */ |
4173 |
if (OPTION (Opt_secondaryScreen)) |
4174 |
if (current_screen != PRIMARY) |
4175 |
scr_erase_screen (2); |
4176 |
scr_change_screen (state); |
4177 |
break; |
4178 |
case 1049: /* secondary screen w/ clearing first */ |
4179 |
scr_change_screen (state); |
4180 |
if (OPTION (Opt_secondaryScreen)) |
4181 |
if (current_screen != PRIMARY) |
4182 |
scr_erase_screen (2); |
4183 |
break; |
4184 |
default: |
4185 |
break; |
4186 |
} |
4187 |
} |
4188 |
} |
4189 |
/*}}} */ |
4190 |
|
4191 |
/*{{{ process sgr sequences */ |
4192 |
void |
4193 |
rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) |
4194 |
{ |
4195 |
unsigned int i; |
4196 |
short rendset; |
4197 |
int rendstyle; |
4198 |
|
4199 |
if (nargs == 0) |
4200 |
{ |
4201 |
scr_rendition (0, ~RS_None); |
4202 |
return; |
4203 |
} |
4204 |
|
4205 |
for (i = 0; i < nargs; i++) |
4206 |
{ |
4207 |
rendset = -1; |
4208 |
switch (arg[i]) |
4209 |
{ |
4210 |
case 0: |
4211 |
rendset = 0, rendstyle = ~RS_None; |
4212 |
break; |
4213 |
case 1: |
4214 |
rendset = 1, rendstyle = RS_Bold; |
4215 |
break; |
4216 |
//case 2: // low intensity |
4217 |
case 3: |
4218 |
rendset = 1, rendstyle = RS_Italic; |
4219 |
break; |
4220 |
case 4: |
4221 |
rendset = 1, rendstyle = RS_Uline; |
4222 |
break; |
4223 |
case 5: // slowly blinking |
4224 |
case 6: // rapidly blinking |
4225 |
rendset = 1, rendstyle = RS_Blink; |
4226 |
break; |
4227 |
//case 6: // scoansi light background |
4228 |
case 7: |
4229 |
rendset = 1, rendstyle = RS_RVid; |
4230 |
break; |
4231 |
case 8: |
4232 |
// invisible. NYI |
4233 |
break; |
4234 |
//case 9: // crossed out |
4235 |
//case 10: // scoansi acs off, primary font |
4236 |
//case 11: // scoansi acs on, first alt font |
4237 |
//case 12: // scoansi acs on, |0x80, second alt font |
4238 |
//... |
4239 |
//case 19: // ninth alt font |
4240 |
//case 20: // gothic |
4241 |
case 21: // disable bold, faint, sometimes doubly underlined (iso 8613) |
4242 |
rendset = 0, rendstyle = RS_Bold; |
4243 |
break; |
4244 |
case 22: // normal intensity |
4245 |
rendset = 0, rendstyle = RS_Bold; |
4246 |
break; |
4247 |
case 23: // disable italic |
4248 |
rendset = 0, rendstyle = RS_Italic; |
4249 |
break; |
4250 |
case 24: |
4251 |
rendset = 0, rendstyle = RS_Uline; |
4252 |
break; |
4253 |
case 25: |
4254 |
rendset = 0, rendstyle = RS_Blink; |
4255 |
break; |
4256 |
case 26: // variable spacing (iso 8613) |
4257 |
rendset = 0, rendstyle = RS_Blink; |
4258 |
break; |
4259 |
case 27: |
4260 |
rendset = 0, rendstyle = RS_RVid; |
4261 |
break; |
4262 |
//case 28: // visible. NYI |
4263 |
//case 29: // not crossed-out |
4264 |
} |
4265 |
|
4266 |
if (rendset != -1) |
4267 |
{ |
4268 |
scr_rendition (rendset, rendstyle); |
4269 |
continue; /* for (;i;) */ |
4270 |
} |
4271 |
|
4272 |
switch (arg[i]) |
4273 |
{ |
4274 |
case 30: |
4275 |
case 31: /* set fg color */ |
4276 |
case 32: |
4277 |
case 33: |
4278 |
case 34: |
4279 |
case 35: |
4280 |
case 36: |
4281 |
case 37: |
4282 |
scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); |
4283 |
break; |
4284 |
case 38: // set fg color, ISO 8613-6 |
4285 |
if (nargs > i + 2 && arg[i + 1] == 5) |
4286 |
{ |
4287 |
scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); |
4288 |
i += 2; |
4289 |
} |
4290 |
break; |
4291 |
case 39: /* default fg */ |
4292 |
scr_color (Color_fg, Color_fg); |
4293 |
break; |
4294 |
|
4295 |
case 40: |
4296 |
case 41: /* set bg color */ |
4297 |
case 42: |
4298 |
case 43: |
4299 |
case 44: |
4300 |
case 45: |
4301 |
case 46: |
4302 |
case 47: |
4303 |
scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); |
4304 |
break; |
4305 |
case 48: // set bg color, ISO 8613-6 |
4306 |
if (nargs > i + 2 && arg[i + 1] == 5) |
4307 |
{ |
4308 |
scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); |
4309 |
i += 2; |
4310 |
} |
4311 |
break; |
4312 |
case 49: /* default bg */ |
4313 |
scr_color (Color_bg, Color_bg); |
4314 |
break; |
4315 |
|
4316 |
//case 50: // not variable spacing |
4317 |
|
4318 |
#if ENABLE_FRILLS |
4319 |
case 90: |
4320 |
case 91: /* set bright fg color */ |
4321 |
case 92: |
4322 |
case 93: |
4323 |
case 94: |
4324 |
case 95: |
4325 |
case 96: |
4326 |
case 97: |
4327 |
scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg); |
4328 |
break; |
4329 |
case 100: |
4330 |
case 101: /* set bright bg color */ |
4331 |
case 102: |
4332 |
case 103: |
4333 |
case 104: |
4334 |
case 105: |
4335 |
case 106: |
4336 |
case 107: |
4337 |
scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); |
4338 |
break; |
4339 |
#endif |
4340 |
} |
4341 |
} |
4342 |
} |
4343 |
/*}}} */ |
4344 |
|
4345 |
/*{{{ (do not) process Rob Nation's own graphics mode sequences */ |
4346 |
void |
4347 |
rxvt_term::process_graphics () |
4348 |
{ |
4349 |
unicode_t ch, cmd = cmd_getc (); |
4350 |
|
4351 |
if (cmd == 'Q') |
4352 |
{ /* query graphics */ |
4353 |
tt_printf ("\033G0\012"); /* no graphics */ |
4354 |
return; |
4355 |
} |
4356 |
/* swallow other graphics sequences until terminating ':' */ |
4357 |
do |
4358 |
ch = cmd_getc (); |
4359 |
while (ch != ':'); |
4360 |
} |
4361 |
/*}}} */ |
4362 |
|
4363 |
/* ------------------------------------------------------------------------- */ |
4364 |
|
4365 |
/* |
4366 |
* Send printf () formatted output to the command. |
4367 |
* Only use for small amounts of data. |
4368 |
*/ |
4369 |
void |
4370 |
rxvt_term::tt_printf (const char *fmt,...) |
4371 |
{ |
4372 |
va_list arg_ptr; |
4373 |
char buf[256]; |
4374 |
|
4375 |
va_start (arg_ptr, fmt); |
4376 |
vsnprintf ((char *)buf, 256, fmt, arg_ptr); |
4377 |
va_end (arg_ptr); |
4378 |
tt_write (buf, strlen (buf)); |
4379 |
} |
4380 |
|
4381 |
/* ---------------------------------------------------------------------- */ |
4382 |
/* Write data to the pty as typed by the user, pasted with the mouse, |
4383 |
* or generated by us in response to a query ESC sequence. |
4384 |
*/ |
4385 |
const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT |
4386 |
|
4387 |
void |
4388 |
rxvt_term::tt_write (const char *data, unsigned int len) |
4389 |
{ |
4390 |
if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) |
4391 |
return; |
4392 |
|
4393 |
if (pty->pty < 0) |
4394 |
return; |
4395 |
|
4396 |
if (v_buflen == 0) |
4397 |
{ |
4398 |
ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE)); |
4399 |
|
4400 |
if ((unsigned int)written == len) |
4401 |
return; |
4402 |
|
4403 |
data += written; |
4404 |
len -= written; |
4405 |
} |
4406 |
|
4407 |
v_buffer = (char *)realloc (v_buffer, v_buflen + len); |
4408 |
|
4409 |
memcpy (v_buffer + v_buflen, data, len); |
4410 |
v_buflen += len; |
4411 |
|
4412 |
pty_ev.set (EVENT_READ | EVENT_WRITE); |
4413 |
} |
4414 |
|
4415 |
void rxvt_term::pty_write () |
4416 |
{ |
4417 |
int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); |
4418 |
|
4419 |
if (written > 0) |
4420 |
{ |
4421 |
v_buflen -= written; |
4422 |
|
4423 |
if (v_buflen == 0) |
4424 |
{ |
4425 |
free (v_buffer); |
4426 |
v_buffer = 0; |
4427 |
v_buflen = 0; |
4428 |
|
4429 |
pty_ev.set (EVENT_READ); |
4430 |
return; |
4431 |
} |
4432 |
|
4433 |
memmove (v_buffer, v_buffer + written, v_buflen); |
4434 |
} |
4435 |
else if (written != -1 || (errno != EAGAIN && errno != EINTR)) |
4436 |
pty_ev.set (EVENT_READ); |
4437 |
} |
4438 |
|
4439 |
/*----------------------- end-of-file (C source) -----------------------*/ |
4440 |
|