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

File Contents

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