ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
Revision: 1.224
Committed: Sun Jan 1 06:18:20 2006 UTC (18 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.223: +4 -5 lines
Log Message:
*** empty log message ***

File Contents

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