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