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