ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
Revision: 1.229
Committed: Tue Jan 3 17:34:44 2006 UTC (18 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.228: +36 -34 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 root 1.227 #include "../config.h"
49     #include "rxvt.h"
50     #include "rxvtperl.h"
51 pcg 1.1 #include "version.h"
52     #include "command.h"
53    
54 root 1.224 #if HAVE_SCHED_YIELD
55     # include <sched.h>
56     #endif
57    
58 root 1.190 #ifdef KEYSYM_RESOURCE
59     # include "keyboard.h"
60     #endif
61    
62 root 1.183 #include <csignal>
63 pcg 1.20
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.226 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
991 root 1.116 }
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 root 1.227 #if HAVE_SCHED_YIELD
1076     static struct event_handler
1077     {
1078     check_watcher cw_yield;
1079    
1080     void yield (check_watcher &w)
1081     {
1082     sched_yield ();
1083     w.stop ();
1084     }
1085    
1086     event_handler ()
1087     : cw_yield (this, &event_handler::yield)
1088     {
1089     }
1090     } event_handler;
1091     #endif
1092    
1093 pcg 1.4 bool
1094 pcg 1.8 rxvt_term::pty_fill ()
1095 pcg 1.4 {
1096     ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1097    
1098 pcg 1.93 if (CBUFSIZ == n)
1099     {
1100     rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n");
1101     n = 0;
1102     }
1103    
1104 pcg 1.4 memmove (cmdbuf_base, cmdbuf_ptr, n);
1105     cmdbuf_ptr = cmdbuf_base;
1106     cmdbuf_endp = cmdbuf_ptr + n;
1107 pcg 1.36
1108 root 1.223 ssize_t r = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1109 pcg 1.4
1110 root 1.223 if (r > 0)
1111 pcg 1.4 {
1112 root 1.223 cmdbuf_endp += r;
1113 pcg 1.4 return true;
1114     }
1115 root 1.223 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1116     {
1117     #if HAVE_SCHED_YIELD
1118 root 1.228 if (display->is_local)
1119     event_handler.cw_yield.start ();
1120 root 1.223 #endif
1121     }
1122     else
1123 root 1.215 {
1124     pty_ev.stop ();
1125    
1126 root 1.219 if (!OPTION (Opt_hold))
1127 root 1.215 destroy ();
1128     }
1129 pcg 1.57
1130 pcg 1.13 return false;
1131 pcg 1.4 }
1132    
1133 pcg 1.3 void
1134     rxvt_term::pty_cb (io_watcher &w, short revents)
1135     {
1136 pcg 1.9 SET_R (this);
1137 pcg 1.19 SET_LOCALE (locale);
1138 pcg 1.9
1139 root 1.177 if (revents & EVENT_READ)
1140 pcg 1.93 // loop, but don't allow a single term to monopolize us
1141     while (pty_fill ())
1142     if (cmd_parse ())
1143     break;
1144 root 1.177
1145     if (revents & EVENT_WRITE)
1146     pty_write ();
1147 pcg 1.57 }
1148    
1149 pcg 1.6 void
1150     rxvt_term::pointer_unblank ()
1151     {
1152 root 1.208 XDefineCursor (display->display, vt, TermWin_cursor);
1153 pcg 1.19 recolour_cursor ();
1154 pcg 1.7
1155 root 1.107 #ifdef POINTER_BLANK
1156 pcg 1.6 hidden_pointer = 0;
1157 pcg 1.1
1158 root 1.219 if (OPTION (Opt_pointerBlank))
1159 pcg 1.7 pointer_ev.start (NOW + pointerBlankDelay);
1160 root 1.107 #endif
1161 pcg 1.1 }
1162    
1163 root 1.107 #ifdef POINTER_BLANK
1164 pcg 1.1 void
1165 pcg 1.6 rxvt_term::pointer_blank ()
1166 pcg 1.1 {
1167 root 1.219 if (! OPTION (Opt_pointerBlank))
1168 pcg 1.6 return;
1169    
1170 root 1.208 XDefineCursor (display->display, vt, display->blank_cursor);
1171 pcg 1.38 XFlush (display->display);
1172 pcg 1.1
1173 pcg 1.6 hidden_pointer = 1;
1174 pcg 1.1 }
1175    
1176     void
1177 pcg 1.6 rxvt_term::pointer_cb (time_watcher &w)
1178 pcg 1.1 {
1179 pcg 1.9 SET_R (this);
1180 pcg 1.19 SET_LOCALE (locale);
1181 pcg 1.9
1182 pcg 1.6 pointer_blank ();
1183 pcg 1.1 }
1184     #endif
1185    
1186     void
1187 pcg 1.56 rxvt_term::mouse_report (XButtonEvent &ev)
1188 pcg 1.1 {
1189 pcg 1.56 int button_number, key_state = 0;
1190     int x, y;
1191 pcg 1.36
1192 pcg 1.38 x = ev.x;
1193     y = ev.y;
1194 pcg 1.36 pixel_position (&x, &y);
1195    
1196     if (MEvent.button == AnyButton)
1197 root 1.145 button_number = 3;
1198 pcg 1.36 else
1199     {
1200     button_number = MEvent.button - Button1;
1201     /* add 0x3D for wheel events, like xterm does */
1202     if (button_number >= 3)
1203     button_number += (64 - 3);
1204     }
1205 pcg 1.1
1206 root 1.145 if (priv_modes & PrivMode_MouseX10)
1207 pcg 1.36 {
1208     /*
1209     * do not report ButtonRelease
1210     * no state info allowed
1211     */
1212     key_state = 0;
1213     if (button_number == 3)
1214     return;
1215     }
1216     else
1217     {
1218     /* XTerm mouse reporting needs these values:
1219     * 4 = Shift
1220     * 8 = Meta
1221     * 16 = Control
1222     * plus will add in our own Double-Click reporting
1223     * 32 = Double Click
1224     */
1225     key_state = ((MEvent.state & ShiftMask) ? 4 : 0)
1226     + ((MEvent.state & ModMetaMask) ? 8 : 0)
1227     + ((MEvent.state & ControlMask) ? 16 : 0);
1228 pcg 1.1 #ifdef MOUSE_REPORT_DOUBLECLICK
1229 pcg 1.36 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1230 pcg 1.1 #endif
1231     }
1232    
1233 root 1.163 #if DEBUG_MOUSEREPORT
1234 pcg 1.43 fprintf (stderr, "Mouse [");
1235 pcg 1.36 if (key_state & 16)
1236 pcg 1.43 fputc ('C', stderr);
1237 pcg 1.36 if (key_state & 4)
1238 pcg 1.43 fputc ('S', stderr);
1239 pcg 1.36 if (key_state & 8)
1240 pcg 1.43 fputc ('A', stderr);
1241 pcg 1.36 if (key_state & 32)
1242 pcg 1.43 fputc ('2', stderr);
1243     fprintf (stderr, "]: <%d>, %d/%d\n",
1244 pcg 1.36 button_number,
1245     x + 1,
1246     y + 1);
1247 root 1.163 #endif
1248    
1249 pcg 1.43 tt_printf ("\033[M%c%c%c",
1250 pcg 1.36 (32 + button_number + key_state),
1251     (32 + x + 1),
1252     (32 + y + 1));
1253 pcg 1.1 }
1254    
1255     #ifdef USING_W11LIB
1256     void
1257 pcg 1.43 rxvt_W11_process_x_event (XEvent *ev)
1258 pcg 1.1 {
1259 pcg 1.43 rxvt_t *r = rxvt_get_r ();
1260 pcg 1.1
1261 pcg 1.38 x_cb (*ev);
1262 pcg 1.1 }
1263     #endif
1264    
1265     /*{{{ process an X event */
1266     void
1267 pcg 1.38 rxvt_term::x_cb (XEvent &ev)
1268 pcg 1.1 {
1269 root 1.192 dDisp;
1270    
1271 pcg 1.38 SET_R (this);
1272     SET_LOCALE (locale);
1273    
1274     #if defined(CURSOR_BLINK)
1275 root 1.219 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress)
1276 pcg 1.38 {
1277     if (hidden_cursor)
1278     {
1279     hidden_cursor = 0;
1280     want_refresh = 1;
1281     }
1282    
1283     cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1284     }
1285     #endif
1286    
1287     #if defined(POINTER_BLANK)
1288 root 1.219 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1289 pcg 1.38 {
1290     if (ev.type == MotionNotify
1291     || ev.type == ButtonPress
1292     || ev.type == ButtonRelease)
1293     if (hidden_pointer)
1294     pointer_unblank ();
1295    
1296     if (ev.type == KeyPress && hidden_pointer == 0)
1297     pointer_blank ();
1298     }
1299     #endif
1300    
1301 root 1.175 Window unused_root, unused_child;
1302     int unused_root_x, unused_root_y;
1303     unsigned int unused_mask;
1304 pcg 1.3
1305 pcg 1.38 switch (ev.type)
1306 pcg 1.36 {
1307     case KeyPress:
1308 root 1.145 #if ISO_14755
1309     if (!(iso14755buf & ISO_14755_52))
1310     #endif
1311 root 1.131 lookup_key (ev.xkey);
1312    
1313 pcg 1.36 break;
1314 pcg 1.1
1315 pcg 1.36 case KeyRelease:
1316     {
1317 root 1.163 #if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1318 root 1.131 KeySym ks;
1319    
1320     ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1321     #endif
1322    
1323 root 1.145 #if ENABLE_FRILLS || ISO_14755
1324 root 1.131 // ISO 14755 support
1325     if (iso14755buf)
1326 root 1.145 if (iso14755buf & ISO_14755_52)
1327 root 1.131 {
1328 root 1.145 # if ENABLE_OVERLAY
1329     scr_overlay_off ();
1330     # endif
1331     # if ISO_14755
1332 root 1.131 // iso14755 part 5.2 handling: release time
1333     // first: controls
1334     if ((ev.xkey.state & ControlMask)
1335     && ((ks >= 0x40 && ks <= 0x5f)
1336     || (ks >= 0x61 && ks <= 0x7f)))
1337     {
1338 root 1.145 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1339 root 1.131 commit_iso14755 ();
1340     return; // case-break;
1341     }
1342    
1343     for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1344     if (i[0] == ks)
1345     {
1346 root 1.145 iso14755buf = ISO_14755_51 | i[1];
1347 root 1.131 commit_iso14755 ();
1348     return; // case-break;
1349     }
1350    
1351 root 1.145 scr_bell ();
1352     # endif
1353 root 1.131 iso14755buf = 0;
1354     break;
1355     }
1356     else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1357     {
1358 root 1.145 # if ENABLE_OVERLAY
1359     scr_overlay_off ();
1360     # endif
1361     if (iso14755buf & ISO_14755_51)
1362 root 1.131 commit_iso14755 ();
1363 root 1.145 #if ISO_14755
1364     else if (iso14755buf & ISO_14755_STARTED)
1365     {
1366     iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1367    
1368     scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1369     scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1370     }
1371     # endif
1372     else
1373     iso14755buf = 0;
1374 root 1.131 }
1375     #endif
1376    
1377     #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1378 root 1.97 if (!(ev.xkey.state & ControlMask))
1379     slip_wheel_ev.stop ();
1380 root 1.131 else if (ks == XK_Control_L || ks == XK_Control_R)
1381     mouse_slip_wheel_speed = 0;
1382     #endif
1383 pcg 1.36 break;
1384     }
1385    
1386     case ButtonPress:
1387 pcg 1.38 button_press (ev.xbutton);
1388 pcg 1.36 break;
1389    
1390     case ButtonRelease:
1391 pcg 1.38 button_release (ev.xbutton);
1392 pcg 1.36 break;
1393    
1394     case ClientMessage:
1395 pcg 1.38 if (ev.xclient.format == 32
1396 root 1.200 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1397     {
1398     if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1399     destroy ();
1400     #if ENABLE_EWMH
1401     else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1402     XSendEvent (disp, ev.xclient.window = display->root,
1403     False, SubstructureRedirectMask | SubstructureNotifyMask,
1404     &ev);
1405     #endif
1406     }
1407 root 1.198 #if ENABLE_XEMBED
1408 root 1.200 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1409 root 1.198 {
1410     if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1411     focus_in ();
1412     else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1413     focus_out ();
1414     }
1415     #endif
1416 pcg 1.1 #ifdef OFFIX_DND
1417 pcg 1.36 /* OffiX Dnd (drag 'n' drop) protocol */
1418 root 1.198 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1419     && (ev.xclient.data.l[0] == DndFile
1420     || ev.xclient.data.l[0] == DndDir
1421     || ev.xclient.data.l[0] == DndLink))
1422 pcg 1.36 {
1423     /* Get Dnd data */
1424 pcg 1.93 Atom ActualType;
1425     int ActualFormat;
1426     unsigned char *data;
1427     unsigned long Size, RemainingBytes;
1428 pcg 1.36
1429 root 1.192 XGetWindowProperty (disp, display->root,
1430     xa[XA_DNDSELECTION],
1431     0L, 1000000L,
1432     False, AnyPropertyType,
1433     &ActualType, &ActualFormat,
1434     &Size, &RemainingBytes,
1435     &data);
1436 root 1.175 set_string_property (XA_CUT_BUFFER0, data);
1437 pcg 1.93 XFree (data);
1438 root 1.176 selection_paste (display->root, XA_CUT_BUFFER0, true);
1439 root 1.192 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1440 pcg 1.36 }
1441 pcg 1.1 #endif /* OFFIX_DND */
1442 pcg 1.36 break;
1443 pcg 1.1
1444 pcg 1.36 case MappingNotify:
1445 root 1.116 XRefreshKeyboardMapping (&ev.xmapping);
1446 pcg 1.36 break;
1447    
1448     /*
1449     * XXX: this is not the _current_ arrangement
1450     * Here's my conclusion:
1451     * If the window is completely unobscured, use bitblt's
1452     * to scroll. Even then, they're only used when doing partial
1453     * screen scrolling. When partially obscured, we have to fill
1454     * in the GraphicsExpose parts, which means that after each refresh,
1455     * we need to wait for the graphics expose or Noexpose events,
1456     * which ought to make things real slow!
1457     */
1458     case VisibilityNotify:
1459 pcg 1.38 switch (ev.xvisibility.state)
1460 pcg 1.8 {
1461     case VisibilityUnobscured:
1462 pcg 1.34 refresh_type = FAST_REFRESH;
1463 pcg 1.8 break;
1464     case VisibilityPartiallyObscured:
1465 pcg 1.34 refresh_type = SLOW_REFRESH;
1466 pcg 1.8 break;
1467     default:
1468 pcg 1.34 refresh_type = NO_REFRESH;
1469 pcg 1.8 break;
1470     }
1471 pcg 1.36 break;
1472 pcg 1.1
1473 pcg 1.36 case FocusIn:
1474 root 1.198 focus_in ();
1475 pcg 1.36 break;
1476    
1477     case FocusOut:
1478 root 1.198 focus_out ();
1479 pcg 1.36 break;
1480    
1481     case ConfigureNotify:
1482 root 1.208 if (ev.xconfigure.window == parent[0])
1483 pcg 1.36 {
1484 root 1.208 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev))
1485     ;
1486 pcg 1.38
1487 root 1.208 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1488 root 1.163 {
1489     seen_resize = 1;
1490 root 1.208 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1491 root 1.163 }
1492 root 1.116
1493 pcg 1.1 #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1494 root 1.219 if (OPTION (Opt_transparent))
1495 root 1.175 check_our_parents ();
1496 pcg 1.36 #endif
1497     }
1498     break;
1499    
1500 root 1.131 case PropertyNotify:
1501     if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1502     && ev.xproperty.state == PropertyNewValue)
1503     selection_property (ev.xproperty.window, ev.xproperty.atom);
1504    
1505     break;
1506    
1507 pcg 1.36 case SelectionClear:
1508 pcg 1.81 selection_clear ();
1509 pcg 1.36 break;
1510    
1511     case SelectionNotify:
1512     if (selection_wait == Sel_normal)
1513 root 1.176 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1514 pcg 1.36 break;
1515    
1516     case SelectionRequest:
1517 pcg 1.38 selection_send (ev.xselectionrequest);
1518 pcg 1.36 break;
1519 pcg 1.1
1520 pcg 1.36 case UnmapNotify:
1521 root 1.208 mapped = 0;
1522 pcg 1.31 #ifdef TEXT_BLINK
1523 pcg 1.34 text_blink_ev.stop ();
1524 pcg 1.31 #endif
1525 pcg 1.36 break;
1526 pcg 1.1
1527 pcg 1.36 case MapNotify:
1528 root 1.208 mapped = 1;
1529 pcg 1.31 #ifdef TEXT_BLINK
1530 pcg 1.34 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1531 pcg 1.31 #endif
1532 pcg 1.36 break;
1533 pcg 1.1
1534     #ifdef TRANSPARENT
1535 pcg 1.36 case ReparentNotify:
1536 pcg 1.38 rootwin_cb (ev);
1537     break;
1538 pcg 1.1 #endif /* TRANSPARENT */
1539    
1540 pcg 1.36 case GraphicsExpose:
1541     case Expose:
1542 root 1.208 if (ev.xany.window == vt)
1543 pcg 1.36 {
1544 root 1.116 do
1545     scr_expose (ev.xexpose.x, ev.xexpose.y,
1546     ev.xexpose.width, ev.xexpose.height, False);
1547 root 1.208 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev));
1548 root 1.116
1549     ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1550    
1551 root 1.208 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1552 root 1.116 scr_expose (ev.xexpose.x, ev.xexpose.y,
1553     ev.xexpose.width, ev.xexpose.height, False);
1554    
1555     scr_refresh (refresh_type);
1556 pcg 1.36 }
1557     else
1558     {
1559 pcg 1.38 XEvent unused_event;
1560 pcg 1.36
1561 root 1.192 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1562 pcg 1.95 ;
1563 root 1.192 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1564 pcg 1.95 ;
1565    
1566 pcg 1.43 if (isScrollbarWindow (ev.xany.window))
1567 pcg 1.36 {
1568 pcg 1.43 scrollBar.setIdle ();
1569 pcg 1.36 scrollbar_show (0);
1570     }
1571 pcg 1.1 #ifdef MENUBAR
1572 pcg 1.43 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1573 pcg 1.36 menubar_expose ();
1574 pcg 1.1 #endif
1575 root 1.116
1576     #ifdef TRANSPARENT
1577 root 1.208 if (am_transparent && ev.xany.window == parent[0])
1578 root 1.192 XClearWindow (disp, ev.xany.window);
1579 root 1.116 #endif
1580 pcg 1.36 }
1581     break;
1582    
1583     case MotionNotify:
1584 pcg 1.1 #ifdef POINTER_BLANK
1585 pcg 1.36 if (hidden_pointer)
1586     pointer_unblank ();
1587 pcg 1.1 #endif
1588     #if MENUBAR
1589 pcg 1.43 if (isMenuBarWindow (ev.xany.window))
1590 pcg 1.36 {
1591 pcg 1.56 menubar_control (ev.xbutton);
1592 pcg 1.36 break;
1593     }
1594     #endif
1595 root 1.168 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1596 pcg 1.36 break;
1597    
1598 root 1.208 if (ev.xany.window == vt)
1599 pcg 1.36 {
1600 root 1.145 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1601 pcg 1.36 {
1602 root 1.208 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1603 pcg 1.38 ;
1604    
1605 root 1.208 XQueryPointer (disp, vt,
1606 root 1.145 &unused_root, &unused_child,
1607     &unused_root_x, &unused_root_y,
1608 root 1.168 &ev.xbutton.x, &ev.xbutton.y,
1609     &ev.xbutton.state);
1610 pcg 1.1 #ifdef MOUSE_THRESHOLD
1611 pcg 1.36 /* deal with a `jumpy' mouse */
1612 pcg 1.38 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1613 pcg 1.36 {
1614 pcg 1.1 #endif
1615 root 1.145 #if ISO_14755
1616     // 5.4
1617     if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1618     {
1619     iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1620     break;
1621     }
1622     #endif
1623     selection_extend (ev.xbutton.x, ev.xbutton.y,
1624 root 1.168 ev.xbutton.state & Button3Mask ? 2 : 0);
1625    
1626 pcg 1.1 #ifdef SELECTION_SCROLLING
1627 root 1.208 if (ev.xbutton.y < int_bwidth
1628     || Pixel2Row (ev.xbutton.y) > (nrow-1))
1629 pcg 1.36 {
1630     int dist;
1631    
1632     /* don't clobber the current delay if we are
1633     * already in the middle of scrolling.
1634     */
1635 root 1.97 if (!sel_scroll_ev.active)
1636     sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1637 pcg 1.36
1638     /* save the event params so we can highlight
1639     * the selection in the pending-scroll loop
1640     */
1641 root 1.145 selection_save_x = ev.xbutton.x;
1642     selection_save_y = ev.xbutton.y;
1643     selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1644 pcg 1.36
1645     /* calc number of lines to scroll */
1646 root 1.208 if (ev.xbutton.y < int_bwidth)
1647 pcg 1.36 {
1648     scroll_selection_dir = UP;
1649 root 1.208 dist = int_bwidth - ev.xbutton.y;
1650 pcg 1.36 }
1651     else
1652     {
1653     scroll_selection_dir = DN;
1654 root 1.208 dist = ev.xbutton.y - (int_bwidth + height);
1655 pcg 1.36 }
1656 root 1.145
1657     scroll_selection_lines = Pixel2Height (dist)
1658     / SELECTION_SCROLL_LINE_SPEEDUP
1659     + 1;
1660 root 1.212 min_it (scroll_selection_lines,
1661 root 1.145 SELECTION_SCROLL_MAX_LINES);
1662 pcg 1.36 }
1663     else
1664     {
1665     /* we are within the text window, so we
1666     * shouldn't be scrolling
1667     */
1668 root 1.97 if (sel_scroll_ev.active)
1669     sel_scroll_ev.stop();
1670 pcg 1.36 }
1671 pcg 1.1 #endif
1672     #ifdef MOUSE_THRESHOLD
1673 pcg 1.36 }
1674 pcg 1.1 #endif
1675 pcg 1.36 }
1676     }
1677 pcg 1.43 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1678 pcg 1.36 {
1679 root 1.192 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1680 root 1.168 MotionNotify, &ev))
1681     ;
1682    
1683 root 1.192 XQueryPointer (disp, scrollBar.win,
1684 pcg 1.36 &unused_root, &unused_child,
1685     &unused_root_x, &unused_root_y,
1686 root 1.168 &ev.xbutton.x, &ev.xbutton.y,
1687 pcg 1.36 &unused_mask);
1688 pcg 1.43 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1689     scrollbar_size ());
1690 pcg 1.36 scr_refresh (refresh_type);
1691     refresh_limit = 0;
1692     scrollbar_show (1);
1693     }
1694     break;
1695     }
1696     }
1697 pcg 1.1
1698 root 1.198 void
1699     rxvt_term::focus_in ()
1700     {
1701 root 1.208 if (!focus)
1702 root 1.198 {
1703 root 1.208 focus = 1;
1704 root 1.198 want_refresh = 1;
1705 root 1.227
1706     PERL_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1707    
1708 root 1.206 #if USE_XIM
1709 root 1.198 if (Input_Context != NULL)
1710     {
1711     IMSetStatusPosition ();
1712     XSetICFocus (Input_Context);
1713     }
1714     #endif
1715 root 1.206 #if CURSOR_BLINK
1716 root 1.219 if (OPTION (Opt_cursorBlink))
1717 root 1.198 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1718     #endif
1719 root 1.206 #if OFF_FOCUS_FADING
1720 root 1.198 if (rs[Rs_fade])
1721     {
1722     pix_colors = pix_colors_focused;
1723     scr_recolour ();
1724     }
1725     #endif
1726     }
1727     }
1728    
1729     void
1730     rxvt_term::focus_out ()
1731     {
1732 root 1.208 if (focus)
1733 root 1.198 {
1734 root 1.208 focus = 0;
1735 root 1.198 want_refresh = 1;
1736    
1737 root 1.227 PERL_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1738    
1739 root 1.198 #if ENABLE_FRILLS || ISO_14755
1740 root 1.227 if (iso14755buf)
1741     {
1742     iso14755buf = 0;
1743     # if ENABLE_OVERLAY
1744     scr_overlay_off ();
1745     # endif
1746     }
1747 root 1.198 #endif
1748 root 1.206 #if USE_XIM
1749 root 1.198 if (Input_Context != NULL)
1750     XUnsetICFocus (Input_Context);
1751     #endif
1752 root 1.206 #if CURSOR_BLINK
1753 root 1.219 if (OPTION (Opt_cursorBlink))
1754 root 1.198 cursor_blink_ev.stop ();
1755     hidden_cursor = 0;
1756     #endif
1757 root 1.206 #if OFF_FOCUS_FADING
1758 root 1.198 if (rs[Rs_fade])
1759     {
1760     pix_colors = pix_colors_unfocused;
1761     scr_recolour ();
1762     }
1763     #endif
1764     }
1765     }
1766    
1767 root 1.131 #if TRANSPARENT
1768 pcg 1.1 void
1769 pcg 1.38 rxvt_term::rootwin_cb (XEvent &ev)
1770     {
1771     SET_R (this);
1772     SET_LOCALE (locale);
1773    
1774 pcg 1.40 switch (ev.type)
1775 pcg 1.38 {
1776 pcg 1.40 case PropertyNotify:
1777 root 1.131 /*
1778     * if user used some Esetroot compatible prog to set the root bg,
1779     * use the property to determine the pixmap. We use it later on.
1780     */
1781 root 1.179 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1782     && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1783 root 1.131 return;
1784 pcg 1.38
1785 pcg 1.40 /* FALLTHROUGH */
1786     case ReparentNotify:
1787 root 1.219 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1788 root 1.120 want_refresh = want_full_refresh = 1;
1789 pcg 1.40 break;
1790 pcg 1.38 }
1791     }
1792 root 1.131 #endif
1793 pcg 1.38
1794     void
1795 pcg 1.56 rxvt_term::button_press (XButtonEvent &ev)
1796 pcg 1.1 {
1797 pcg 1.36 int reportmode = 0, clickintime;
1798 pcg 1.1
1799 pcg 1.38 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1800 root 1.229
1801 pcg 1.36 if (!bypass_keystate)
1802 root 1.145 reportmode = !! (priv_modes & PrivMode_mouse_report);
1803    
1804 pcg 1.36 /*
1805     * VT window processing of button press
1806     */
1807 root 1.208 if (ev.window == vt)
1808 pcg 1.36 {
1809 root 1.145 #if ISO_14755
1810     // 5.4
1811     if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1812     {
1813     iso14755_54 (ev.x, ev.y);
1814     return;
1815     }
1816     #endif
1817    
1818 pcg 1.50 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1819 root 1.168
1820 pcg 1.50 if (reportmode)
1821 pcg 1.36 {
1822 pcg 1.50 /* mouse report from vt window */
1823     /* save the xbutton state (for ButtonRelease) */
1824     MEvent.state = ev.state;
1825     #ifdef MOUSE_REPORT_DOUBLECLICK
1826     if (ev.button == MEvent.button && clickintime)
1827 pcg 1.36 {
1828 pcg 1.50 /* same button, within alloted time */
1829     MEvent.clicks++;
1830     if (MEvent.clicks > 1)
1831 pcg 1.36 {
1832 pcg 1.50 /* only report double clicks */
1833     MEvent.clicks = 2;
1834 pcg 1.36 mouse_report (ev);
1835 pcg 1.50
1836     /* don't report the release */
1837     MEvent.clicks = 0;
1838     MEvent.button = AnyButton;
1839 pcg 1.36 }
1840 pcg 1.50 }
1841     else
1842     {
1843     /* different button, or time expired */
1844     MEvent.clicks = 1;
1845 pcg 1.38 MEvent.button = ev.button;
1846 pcg 1.36 mouse_report (ev);
1847 pcg 1.50 }
1848     #else
1849     MEvent.button = ev.button;
1850     mouse_report (ev);
1851 pcg 1.1 #endif /* MOUSE_REPORT_DOUBLECLICK */
1852 pcg 1.36
1853 pcg 1.50 }
1854     else
1855     {
1856     if (ev.button != MEvent.button)
1857     MEvent.clicks = 0;
1858 root 1.168
1859 root 1.229 if (!PERL_INVOKE ((this, HOOK_MOUSE_CLICK, DT_XEVENT, &ev, DT_END)))
1860     switch (ev.button)
1861     {
1862     case Button1:
1863     /* allow meta + click to select rectangular areas */
1864     /* should be done in screen.C */
1865 root 1.168 #if ENABLE_FRILLS
1866 root 1.229 selection.rect = !!(ev.state & ModMetaMask);
1867 root 1.168 #else
1868 root 1.229 selection.rect = false;
1869 root 1.168 #endif
1870    
1871 root 1.229 /* allow shift+left click to extend selection */
1872     if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1873     {
1874     if (MEvent.button == Button1 && clickintime)
1875     selection_rotate (ev.x, ev.y);
1876     else
1877     selection_extend (ev.x, ev.y, 1);
1878     }
1879     else
1880     {
1881     if (MEvent.button == Button1 && clickintime)
1882     MEvent.clicks++;
1883     else
1884     MEvent.clicks = 1;
1885 pcg 1.21
1886 root 1.229 selection_click (MEvent.clicks, ev.x, ev.y);
1887     }
1888 pcg 1.21
1889 root 1.229 MEvent.button = Button1;
1890     break;
1891 pcg 1.1
1892 root 1.229 case Button3:
1893     if (MEvent.button == Button3 && clickintime)
1894     selection_rotate (ev.x, ev.y);
1895     else
1896     selection_extend (ev.x, ev.y, 1);
1897 root 1.145
1898 root 1.229 MEvent.button = Button3;
1899     break;
1900     }
1901     }
1902 root 1.145
1903 pcg 1.50 MEvent.time = ev.time;
1904     return;
1905 pcg 1.36 }
1906 pcg 1.1
1907 pcg 1.36 /*
1908     * Scrollbar window processing of button press
1909     */
1910 pcg 1.43 if (isScrollbarWindow (ev.window))
1911 pcg 1.36 {
1912     scrollBar.setIdle ();
1913     /*
1914     * Rxvt-style scrollbar:
1915     * move up if mouse is above slider
1916     * move dn if mouse is below slider
1917     *
1918     * XTerm-style scrollbar:
1919     * Move display proportional to pointer location
1920     * pointer near top -> scroll one line
1921     * pointer near bot -> scroll full page
1922     */
1923 pcg 1.1 #ifndef NO_SCROLLBAR_REPORT
1924 pcg 1.36 if (reportmode)
1925     {
1926     /*
1927     * Mouse report disabled scrollbar:
1928     * arrow buttons - send up/down
1929     * click on scrollbar - send pageup/down
1930     */
1931     if ((scrollBar.style == R_SB_NEXT
1932 pcg 1.43 && scrollbarnext_upButton (ev.y))
1933 pcg 1.36 || (scrollBar.style == R_SB_RXVT
1934 pcg 1.43 && scrollbarrxvt_upButton (ev.y)))
1935     tt_printf ("\033[A");
1936 pcg 1.36 else if ((scrollBar.style == R_SB_NEXT
1937 pcg 1.43 && scrollbarnext_dnButton (ev.y))
1938 pcg 1.36 || (scrollBar.style == R_SB_RXVT
1939 pcg 1.43 && scrollbarrxvt_dnButton (ev.y)))
1940     tt_printf ("\033[B");
1941 pcg 1.36 else
1942 pcg 1.38 switch (ev.button)
1943 pcg 1.36 {
1944     case Button2:
1945 pcg 1.43 tt_printf ("\014");
1946 pcg 1.36 break;
1947     case Button1:
1948 pcg 1.43 tt_printf ("\033[6~");
1949 pcg 1.36 break;
1950     case Button3:
1951 pcg 1.43 tt_printf ("\033[5~");
1952 pcg 1.36 break;
1953     }
1954     }
1955     else
1956 pcg 1.1 #endif /* NO_SCROLLBAR_REPORT */
1957    
1958 pcg 1.36 {
1959     char upordown = 0;
1960    
1961     if (scrollBar.style == R_SB_NEXT)
1962     {
1963 pcg 1.43 if (scrollbarnext_upButton (ev.y))
1964 pcg 1.36 upordown = -1; /* up */
1965 pcg 1.43 else if (scrollbarnext_dnButton (ev.y))
1966 pcg 1.36 upordown = 1; /* down */
1967     }
1968     else if (scrollBar.style == R_SB_RXVT)
1969     {
1970 pcg 1.43 if (scrollbarrxvt_upButton (ev.y))
1971 pcg 1.36 upordown = -1; /* up */
1972 pcg 1.43 else if (scrollbarrxvt_dnButton (ev.y))
1973 pcg 1.36 upordown = 1; /* down */
1974     }
1975     if (upordown)
1976     {
1977 pcg 1.1 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1978 root 1.97 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY);
1979 pcg 1.1 #endif
1980 pcg 1.36 if (scr_page (upordown < 0 ? UP : DN, 1))
1981     {
1982     if (upordown < 0)
1983     scrollBar.setUp ();
1984     else
1985     scrollBar.setDn ();
1986     }
1987     }
1988     else
1989 pcg 1.38 switch (ev.button)
1990 pcg 1.36 {
1991     case Button2:
1992     switch (scrollbar_align)
1993     {
1994     case R_SB_ALIGN_TOP:
1995     csrO = 0;
1996     break;
1997     case R_SB_ALIGN_CENTRE:
1998     csrO = (scrollBar.bot - scrollBar.top) / 2;
1999     break;
2000     case R_SB_ALIGN_BOTTOM:
2001     csrO = scrollBar.bot - scrollBar.top;
2002     break;
2003     }
2004 root 1.120
2005 pcg 1.36 if (scrollBar.style == R_SB_XTERM
2006 pcg 1.43 || scrollbar_above_slider (ev.y)
2007     || scrollbar_below_slider (ev.y))
2008 root 1.120 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ());
2009    
2010 pcg 1.36 scrollBar.setMotion ();
2011     break;
2012    
2013     case Button1:
2014     if (scrollbar_align == R_SB_ALIGN_CENTRE)
2015 pcg 1.38 csrO = ev.y - scrollBar.top;
2016 pcg 1.36 /* FALLTHROUGH */
2017    
2018     case Button3:
2019     if (scrollBar.style != R_SB_XTERM)
2020     {
2021 pcg 1.43 if (scrollbar_above_slider (ev.y))
2022 pcg 1.1 # ifdef RXVT_SCROLL_FULL
2023 root 1.208 scr_page (UP, nrow - 1);
2024 pcg 1.1 # else
2025 root 1.208 scr_page (UP, nrow / 4);
2026 pcg 1.1 # endif
2027 pcg 1.43 else if (scrollbar_below_slider (ev.y))
2028 pcg 1.1 # ifdef RXVT_SCROLL_FULL
2029 root 1.208 scr_page (DN, nrow - 1);
2030 pcg 1.1 # else
2031 root 1.208 scr_page (DN, nrow / 4);
2032 pcg 1.1 # endif
2033 pcg 1.36 else
2034     scrollBar.setMotion ();
2035     }
2036     else
2037     {
2038 pcg 1.38 scr_page ((ev.button == Button1 ? DN : UP),
2039 root 1.208 (nrow
2040 pcg 1.43 * scrollbar_position (ev.y)
2041     / scrollbar_size ()));
2042 pcg 1.36 }
2043 root 1.120
2044 pcg 1.36 break;
2045     }
2046     }
2047     return;
2048 pcg 1.1 }
2049     #if MENUBAR
2050 pcg 1.36 /*
2051     * Menubar window processing of button press
2052     */
2053 pcg 1.43 if (isMenuBarWindow (ev.window))
2054 pcg 1.36 menubar_control (ev);
2055 pcg 1.1 #endif
2056     }
2057    
2058     void
2059 pcg 1.56 rxvt_term::button_release (XButtonEvent &ev)
2060 pcg 1.1 {
2061 pcg 1.38 int reportmode = 0;
2062 pcg 1.1
2063 pcg 1.36 csrO = 0; /* reset csr Offset */
2064     if (!bypass_keystate)
2065 root 1.145 reportmode = !! (priv_modes & PrivMode_mouse_report);
2066 pcg 1.36
2067 pcg 1.43 if (scrollbar_isUpDn ())
2068 pcg 1.36 {
2069     scrollBar.setIdle ();
2070     scrollbar_show (0);
2071 pcg 1.1 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2072 pcg 1.36 refresh_type &= ~SMOOTH_REFRESH;
2073 pcg 1.1 #endif
2074 root 1.145 }
2075 pcg 1.36
2076 pcg 1.1 #ifdef SELECTION_SCROLLING
2077 root 1.97 if (sel_scroll_ev.active)
2078     sel_scroll_ev.stop();
2079 pcg 1.1 #endif
2080 root 1.145
2081 root 1.208 if (ev.window == vt)
2082 pcg 1.36 {
2083 root 1.145 #if ISO_14755
2084     // 5.4
2085     if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2086     return;
2087     #endif
2088 pcg 1.50 if (reportmode)
2089 pcg 1.36 {
2090 pcg 1.50 /* mouse report from vt window */
2091     /* don't report release of wheel "buttons" */
2092     if (ev.button >= 4)
2093     return;
2094     #ifdef MOUSE_REPORT_DOUBLECLICK
2095     /* only report the release of 'slow' single clicks */
2096     if (MEvent.button != AnyButton
2097     && (ev.button != MEvent.button
2098     || (ev.time - MEvent.time
2099     > MULTICLICK_TIME / 2)))
2100 pcg 1.36 {
2101 pcg 1.50 MEvent.clicks = 0;
2102 pcg 1.36 MEvent.button = AnyButton;
2103     mouse_report (ev);
2104 pcg 1.50 }
2105     #else /* MOUSE_REPORT_DOUBLECLICK */
2106     MEvent.button = AnyButton;
2107     mouse_report (ev);
2108 pcg 1.1 #endif /* MOUSE_REPORT_DOUBLECLICK */
2109 pcg 1.50 return;
2110     }
2111 root 1.145
2112 pcg 1.50 /*
2113     * dumb hack to compensate for the failure of click-and-drag
2114     * when overriding mouse reporting
2115     */
2116 root 1.145 if (priv_modes & PrivMode_mouse_report
2117 pcg 1.50 && bypass_keystate
2118     && ev.button == Button1 && MEvent.clicks <= 1)
2119     selection_extend (ev.x, ev.y, 0);
2120    
2121     switch (ev.button)
2122     {
2123     case Button1:
2124     case Button3:
2125     selection_make (ev.time);
2126     break;
2127     case Button2:
2128     selection_request (ev.time, ev.x, ev.y);
2129     break;
2130     #ifdef MOUSE_WHEEL
2131     case Button4:
2132     case Button5:
2133 pcg 1.36 {
2134 pcg 1.50 int i;
2135     page_dirn v;
2136 pcg 1.36
2137 root 1.97 v = ev.button == Button4 ? UP : DN;
2138    
2139 pcg 1.50 if (ev.state & ShiftMask)
2140     i = 1;
2141 root 1.219 else if (OPTION (Opt_mouseWheelScrollPage))
2142 root 1.208 i = nrow - 1;
2143 pcg 1.50 else
2144     i = 5;
2145 root 1.97
2146 pcg 1.1 # ifdef MOUSE_SLIP_WHEELING
2147 pcg 1.50 if (ev.state & ControlMask)
2148     {
2149 root 1.97 mouse_slip_wheel_speed += v ? -1 : 1;
2150 root 1.208 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2151     if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2152 root 1.107
2153     if (slip_wheel_ev.at < NOW)
2154     slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2155    
2156     slip_wheel_ev.start ();
2157 pcg 1.50 }
2158 root 1.107 else
2159     {
2160 pcg 1.1 # endif
2161     # ifdef JUMP_MOUSE_WHEEL
2162 root 1.107 scr_page (v, i);
2163 pcg 1.36 scr_refresh (SMOOTH_REFRESH);
2164     scrollbar_show (1);
2165 root 1.107 # else
2166     while (i--)
2167     {
2168     scr_page (v, 1);
2169     scr_refresh (SMOOTH_REFRESH);
2170     scrollbar_show (1);
2171     }
2172     # endif
2173     # ifdef MOUSE_SLIP_WHEELING
2174 pcg 1.50 }
2175 root 1.107 #endif
2176 pcg 1.50 }
2177     break;
2178 pcg 1.1 #endif
2179 pcg 1.36 }
2180     }
2181 pcg 1.1 #ifdef MENUBAR
2182 pcg 1.43 else if (isMenuBarWindow (ev.window))
2183 pcg 1.36 menubar_control (ev);
2184 pcg 1.1 #endif
2185     }
2186    
2187 pcg 1.90 #ifdef TRANSPARENT
2188     #if TINTING
2189 root 1.116 /* taken from aterm-0.4.2 */
2190    
2191     typedef uint32_t RUINT32T;
2192 pcg 1.90
2193 root 1.116 void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2194 pcg 1.90 {
2195 root 1.116 int sh_r, sh_g, sh_b;
2196     RUINT32T mask_r, mask_g, mask_b;
2197     RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2198     unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2199     unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2200     int i;
2201    
2202 root 1.192 Visual *visual = display->visual;
2203 root 1.116
2204     if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2205    
2206     /* for convenience */
2207     mask_r = visual->red_mask;
2208     mask_g = visual->green_mask;
2209     mask_b = visual->blue_mask;
2210    
2211     /* boring lookup table pre-initialization */
2212     switch (srcImage->bits_per_pixel) {
2213     case 15:
2214     if ((mask_r != 0x7c00) ||
2215     (mask_g != 0x03e0) ||
2216     (mask_b != 0x001f))
2217     return;
2218     lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2219     lookup_r = lookup;
2220     lookup_g = lookup+32;
2221     lookup_b = lookup+32+32;
2222     sh_r = 10;
2223     sh_g = 5;
2224     sh_b = 0;
2225     break;
2226     case 16:
2227     if ((mask_r != 0xf800) ||
2228     (mask_g != 0x07e0) ||
2229     (mask_b != 0x001f))
2230     return;
2231     lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2232     lookup_r = lookup;
2233     lookup_g = lookup+32;
2234     lookup_b = lookup+32+64;
2235     sh_r = 11;
2236     sh_g = 5;
2237     sh_b = 0;
2238     break;
2239     case 24:
2240     if ((mask_r != 0xff0000) ||
2241     (mask_g != 0x00ff00) ||
2242     (mask_b != 0x0000ff))
2243     return;
2244     lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2245     lookup_r = lookup;
2246     lookup_g = lookup+256;
2247     lookup_b = lookup+256+256;
2248     sh_r = 16;
2249     sh_g = 8;
2250     sh_b = 0;
2251     break;
2252     case 32:
2253     if ((mask_r != 0xff0000) ||
2254     (mask_g != 0x00ff00) ||
2255     (mask_b != 0x0000ff))
2256     return;
2257     lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2258     lookup_r = lookup;
2259     lookup_g = lookup+256;
2260     lookup_b = lookup+256+256;
2261     sh_r = 16;
2262     sh_g = 8;
2263     sh_b = 0;
2264     break;
2265     default:
2266     return; /* we do not support this color depth */
2267     }
2268    
2269     /* prepare limits for color transformation (each channel is handled separately) */
2270     if (shade < 0) {
2271     shade = -shade;
2272     if (shade < 0) shade = 0;
2273     if (shade > 100) shade = 100;
2274    
2275     lower_lim_r = 65535-rm;
2276     lower_lim_g = 65535-gm;
2277     lower_lim_b = 65535-bm;
2278    
2279     lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2280     lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2281     lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2282    
2283     upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2284     } else {
2285     if (shade < 0) shade = 0;
2286     if (shade > 100) shade = 100;
2287    
2288     lower_lim_r = lower_lim_g = lower_lim_b = 0;
2289    
2290     upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2291     upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2292     upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2293     }
2294 pcg 1.90
2295 root 1.116 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2296     if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2297     {
2298     unsigned int tmp;
2299 pcg 1.90
2300 root 1.116 tmp = lower_lim_r;
2301     lower_lim_r = lower_lim_b;
2302     lower_lim_b = tmp;
2303    
2304     tmp = upper_lim_r;
2305     upper_lim_r = upper_lim_b;
2306     upper_lim_b = tmp;
2307     }
2308 pcg 1.90
2309 root 1.116 /* fill our lookup tables */
2310     for (i = 0; i <= mask_r>>sh_r; i++)
2311     {
2312     RUINT32T tmp;
2313     tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2314     tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2315     lookup_r[i] = (tmp/65535)<<sh_r;
2316     }
2317     for (i = 0; i <= mask_g>>sh_g; i++)
2318     {
2319     RUINT32T tmp;
2320     tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2321     tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2322     lookup_g[i] = (tmp/65535)<<sh_g;
2323     }
2324     for (i = 0; i <= mask_b>>sh_b; i++)
2325     {
2326     RUINT32T tmp;
2327     tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2328     tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2329     lookup_b[i] = (tmp/65535)<<sh_b;
2330     }
2331 pcg 1.90
2332 root 1.116 /* apply table to input image (replacing colors by newly calculated ones) */
2333     switch (srcImage->bits_per_pixel)
2334     {
2335     case 15:
2336     {
2337     unsigned short *p1, *pf, *p, *pl;
2338     p1 = (unsigned short *) srcImage->data;
2339     pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2340     while (p1 < pf)
2341     {
2342     p = p1;
2343     pl = p1 + srcImage->width;
2344     for (; p < pl; p++)
2345     {
2346     *p = lookup_r[(*p & 0x7c00)>>10] |
2347     lookup_g[(*p & 0x03e0)>> 5] |
2348     lookup_b[(*p & 0x001f)];
2349     }
2350     p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2351     }
2352     break;
2353     }
2354     case 16:
2355     {
2356     unsigned short *p1, *pf, *p, *pl;
2357     p1 = (unsigned short *) srcImage->data;
2358     pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2359     while (p1 < pf)
2360     {
2361     p = p1;
2362     pl = p1 + srcImage->width;
2363     for (; p < pl; p++)
2364     {
2365     *p = lookup_r[(*p & 0xf800)>>11] |
2366     lookup_g[(*p & 0x07e0)>> 5] |
2367     lookup_b[(*p & 0x001f)];
2368     }
2369     p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2370     }
2371     break;
2372     }
2373     case 24:
2374     {
2375     unsigned char *p1, *pf, *p, *pl;
2376     p1 = (unsigned char *) srcImage->data;
2377     pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2378     while (p1 < pf)
2379     {
2380     p = p1;
2381     pl = p1 + srcImage->width * 3;
2382     for (; p < pl; p += 3)
2383     {
2384     p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2385     p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2386     p[2] = lookup_r[(p[2] & 0x0000ff)];
2387     }
2388     p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2389     }
2390     break;
2391     }
2392     case 32:
2393     {
2394     RUINT32T *p1, *pf, *p, *pl;
2395     p1 = (RUINT32T *) srcImage->data;
2396     pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2397    
2398     while (p1 < pf)
2399     {
2400     p = p1;
2401     pl = p1 + srcImage->width;
2402     for (; p < pl; p++)
2403     {
2404     *p = lookup_r[(*p & 0xff0000)>>16] |
2405     lookup_g[(*p & 0x00ff00)>> 8] |
2406     lookup_b[(*p & 0x0000ff)] |
2407     (*p & ~0xffffff);
2408     }
2409     p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2410     }
2411     break;
2412 pcg 1.90 }
2413 root 1.116 }
2414    
2415     free (lookup);
2416 pcg 1.90 }
2417     #endif
2418 pcg 1.1
2419     /*
2420     * Check our parents are still who we think they are.
2421     * Do transparency updates if required
2422     */
2423     int
2424 pcg 1.34 rxvt_term::check_our_parents ()
2425 pcg 1.1 {
2426 pcg 1.90 int i, pchanged, aformat, have_pixmap, rootdepth;
2427     unsigned long nitems, bytes_after;
2428     Atom atype;
2429     unsigned char *prop = NULL;
2430     Window root, oldp, *list;
2431     Pixmap rootpixmap = None;
2432 pcg 1.36 XWindowAttributes wattr, wrootattr;
2433 root 1.192 dDisp;
2434 pcg 1.36
2435     pchanged = 0;
2436    
2437 root 1.219 if (!OPTION (Opt_transparent))
2438 pcg 1.36 return pchanged; /* Don't try any more */
2439    
2440 root 1.192 XGetWindowAttributes (disp, display->root, &wrootattr);
2441 pcg 1.36 rootdepth = wrootattr.depth;
2442    
2443 root 1.208 XGetWindowAttributes (disp, parent[0], &wattr);
2444 pcg 1.90
2445 pcg 1.36 if (rootdepth != wattr.depth)
2446     {
2447     if (am_transparent)
2448     {
2449     pchanged = 1;
2450 root 1.208 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2451 pcg 1.36 am_transparent = am_pixmap_trans = 0;
2452     }
2453 pcg 1.90
2454 pcg 1.36 return pchanged; /* Don't try any more */
2455 pcg 1.1 }
2456    
2457 pcg 1.36 /* Get all X ops out of the queue so that our information is up-to-date. */
2458 root 1.192 XSync (disp, False);
2459 pcg 1.1
2460 pcg 1.36 /*
2461     * Make the frame window set by the window manager have
2462     * the root background. Some window managers put multiple nested frame
2463     * windows for each client, so we have to take care about that.
2464     */
2465 root 1.178 i = (xa[XA_XROOTPMAP_ID]
2466 root 1.192 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2467 pcg 1.36 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2468 pcg 1.90 &nitems, &bytes_after, &prop) == Success);
2469    
2470     if (!i || prop == NULL)
2471 root 1.178 i = (xa[XA_ESETROOT_PMAP_ID]
2472 root 1.192 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2473 pcg 1.90 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2474     &nitems, &bytes_after, &prop) == Success);
2475    
2476 root 1.116 if (!i || prop == NULL
2477     #if TINTING
2478     || !rs[Rs_color + Color_tint]
2479     #endif
2480     )
2481 pcg 1.36 have_pixmap = 0;
2482     else
2483     {
2484     have_pixmap = 1;
2485 pcg 1.93 rootpixmap = *(Pixmap *)prop;
2486 pcg 1.43 XFree (prop);
2487 pcg 1.1 }
2488 pcg 1.90
2489 pcg 1.36 if (have_pixmap)
2490     {
2491     /*
2492 pcg 1.38 * Copy display->root pixmap transparency
2493 pcg 1.36 */
2494 pcg 1.67 int sx, sy, nx, ny;
2495     unsigned int nw, nh;
2496     Window cr;
2497     XImage *image;
2498     GC gc;
2499     XGCValues gcvalue;
2500 pcg 1.36
2501 root 1.208 XTranslateCoordinates (disp, parent[0], display->root,
2502 pcg 1.90 0, 0, &sx, &sy, &cr);
2503 pcg 1.36 nw = (unsigned int)szHint.width;
2504     nh = (unsigned int)szHint.height;
2505     nx = ny = 0;
2506 pcg 1.67
2507 pcg 1.36 if (sx < 0)
2508     {
2509     nw += sx;
2510     nx = -sx;
2511     sx = 0;
2512     }
2513 pcg 1.67
2514 pcg 1.36 if (sy < 0)
2515     {
2516     nh += sy;
2517     ny = -sy;
2518     sy = 0;
2519     }
2520 pcg 1.67
2521 root 1.212 min_it (nw, (unsigned int) (wrootattr.width - sx));
2522     min_it (nh, (unsigned int) (wrootattr.height - sy));
2523 root 1.175
2524 root 1.192 XSync (disp, False);
2525 pcg 1.36 allowedxerror = -1;
2526 root 1.192 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2527 pcg 1.90
2528 pcg 1.36 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2529     /* XXX: may need a delay here? */
2530     allowedxerror = 0;
2531 pcg 1.90
2532 pcg 1.36 if (image == NULL)
2533     {
2534     if (am_transparent && am_pixmap_trans)
2535     {
2536     pchanged = 1;
2537 root 1.208 if (pixmap != None)
2538 pcg 1.36 {
2539 root 1.208 XFreePixmap (disp, pixmap);
2540     pixmap = None;
2541 pcg 1.36 }
2542     }
2543 pcg 1.90
2544 pcg 1.36 am_pixmap_trans = 0;
2545     }
2546     else
2547     {
2548 root 1.208 if (pixmap != None)
2549     XFreePixmap (disp, pixmap);
2550 pcg 1.90
2551     #if TINTING
2552     if (ISSET_PIXCOLOR (Color_tint))
2553     {
2554 root 1.107 unsigned short rm, gm, bm;
2555 root 1.116 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2556 pcg 1.90
2557 root 1.145 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2558 pcg 1.90
2559 root 1.116 ShadeXImage (display, image, shade, rm, gm, bm);
2560 pcg 1.90 }
2561     #endif
2562    
2563 root 1.208 pixmap = XCreatePixmap (disp, vt,
2564 pcg 1.90 szHint.width, szHint.height, image->depth);
2565 root 1.208 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2566     XPutImage (disp, pixmap, gc, image, 0, 0,
2567 pcg 1.90 nx, ny, image->width, image->height);
2568 root 1.192 XFreeGC (disp, gc);
2569 pcg 1.43 XDestroyImage (image);
2570 root 1.208 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2571     XClearWindow (disp, parent[0]);
2572 pcg 1.90
2573 pcg 1.36 if (!am_transparent || !am_pixmap_trans)
2574     pchanged = 1;
2575 pcg 1.90
2576 pcg 1.36 am_transparent = am_pixmap_trans = 1;
2577     }
2578 pcg 1.1 }
2579 pcg 1.67
2580 root 1.175 if (am_pixmap_trans)
2581 root 1.208 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2582 root 1.175 else
2583 pcg 1.36 {
2584 pcg 1.90 unsigned int n;
2585 pcg 1.36 /*
2586     * InheritPixmap transparency
2587     */
2588 root 1.208 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2589 pcg 1.36 {
2590 root 1.208 oldp = parent[i];
2591     XQueryTree (disp, parent[i - 1], &root,
2592     &parent[i], &list, &n);
2593 pcg 1.43 XFree (list);
2594 pcg 1.90
2595 root 1.208 if (parent[i] == display->root)
2596 pcg 1.36 {
2597     if (oldp != None)
2598     pchanged = 1;
2599 pcg 1.90
2600 pcg 1.36 break;
2601     }
2602 pcg 1.90
2603 root 1.208 if (oldp != parent[i])
2604 pcg 1.36 pchanged = 1;
2605     }
2606 pcg 1.67
2607 pcg 1.36 n = 0;
2608 pcg 1.67
2609 pcg 1.36 if (pchanged)
2610     {
2611     for (; n < (unsigned int)i; n++)
2612     {
2613 root 1.208 XGetWindowAttributes (disp, parent[n], &wattr);
2614 pcg 1.36 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2615     {
2616 root 1.208 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2617 pcg 1.36 break;
2618     }
2619     }
2620     }
2621 pcg 1.67
2622 root 1.208 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2623 pcg 1.36 {
2624 root 1.208 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2625     XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2626 pcg 1.36 am_transparent = 0;
2627     /* XXX: also turn off Opt_transparent? */
2628     }
2629     else
2630     {
2631 pcg 1.90 #if WAIT_FOR_WM
2632 pcg 1.36 /* wait (an arbitrary period) for the WM to do its thing
2633     * needed for fvwm2.2.2 (and before?) */
2634 pcg 1.43 sleep (1);
2635 pcg 1.90 #endif
2636 pcg 1.36 for (n = 0; n < (unsigned int)i; n++)
2637 root 1.116 {
2638 root 1.208 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2639     XClearWindow (disp, parent[n]);
2640 root 1.116 }
2641 pcg 1.90
2642 root 1.208 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2643 pcg 1.36 am_transparent = 1;
2644     }
2645 pcg 1.67
2646 root 1.208 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2647     parent[i] = None;
2648 pcg 1.1 }
2649 pcg 1.90
2650 root 1.116 if (scrollBar.win)
2651     {
2652 root 1.192 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2653 root 1.116 scrollBar.setIdle ();
2654     scrollbar_show (0);
2655     }
2656    
2657 root 1.175 if (am_transparent)
2658     {
2659     want_refresh = want_full_refresh = 1;
2660     if (am_pixmap_trans)
2661     flush ();
2662     }
2663    
2664 pcg 1.36 return pchanged;
2665 pcg 1.1 }
2666     #endif
2667    
2668     /*}}} */
2669    
2670 pcg 1.81 bool
2671     rxvt_term::cmd_parse ()
2672     {
2673     bool flag = false;
2674     unicode_t ch = NOCHAR;
2675     unsigned char *seq_begin; // remember start of esc-sequence here
2676    
2677     for (;;)
2678     {
2679     if (ch == NOCHAR)
2680     {
2681     seq_begin = cmdbuf_ptr;
2682     ch = next_char ();
2683     }
2684    
2685     if (ch == NOCHAR) // TODO: improve
2686     break;
2687    
2688 pcg 1.93 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2689 pcg 1.81 {
2690 root 1.145 if (!seen_input)
2691     {
2692     seen_input = 1;
2693     // many badly-written programs (e.g. jed) contain a race condition:
2694     // they first read the screensize and then install a SIGWINCH handler.
2695     // some window managers resize the window early, and these programs
2696     // then sometimes get the size wrong.
2697 root 1.163 // unfortunately other programs are even more buggy and dislike
2698     // being sent SIGWINCH, so only do it when we were in fact being
2699     // resized.
2700 root 1.197 if (seen_resize && cmd_pid)
2701 root 1.163 kill (-cmd_pid, SIGWINCH);
2702 root 1.145 }
2703    
2704 pcg 1.81 /* Read a text string from the input buffer */
2705     unicode_t buf[UBUFSIZ];
2706     bool refreshnow = false;
2707     int nlines = 0;
2708     unicode_t *str = buf;
2709 root 1.208 unicode_t *eol = str + min (ncol, UBUFSIZ);
2710 pcg 1.81
2711     for (;;)
2712     {
2713 pcg 1.93 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2714 pcg 1.81 break;
2715    
2716     *str++ = ch;
2717    
2718 root 1.204 if (ch == C0_LF || str >= eol)
2719 pcg 1.81 {
2720 root 1.205 if (ch == C0_LF)
2721     nlines++;
2722    
2723 pcg 1.81 refresh_count++;
2724    
2725 root 1.219 if (!OPTION (Opt_jumpScroll)
2726 root 1.208 || (refresh_count >= refresh_limit * (nrow - 1)))
2727 pcg 1.81 {
2728     refreshnow = true;
2729 root 1.226 refresh_count = 0;
2730 pcg 1.81 ch = NOCHAR;
2731     break;
2732     }
2733    
2734 root 1.208 // scr_add_lines only works for nlines <= nrow - 1.
2735     if (nlines >= nrow - 1)
2736 pcg 1.81 {
2737     scr_add_lines (buf, nlines, str - buf);
2738     nlines = 0;
2739     str = buf;
2740 root 1.208 eol = str + min (ncol, UBUFSIZ);
2741 root 1.204 }
2742    
2743     if (str >= eol)
2744     {
2745     if (eol >= buf + UBUFSIZ)
2746     {
2747     ch = NOCHAR;
2748     break;
2749     }
2750     else
2751 root 1.208 eol = min (eol + ncol, buf + UBUFSIZ);
2752 pcg 1.81 }
2753    
2754     }
2755 root 1.120
2756     seq_begin = cmdbuf_ptr;
2757     ch = next_char ();
2758 pcg 1.81 }
2759    
2760     scr_add_lines (buf, nlines, str - buf);
2761    
2762     /*
2763     * If there have been a lot of new lines, then update the screen
2764     * What the heck I'll cheat and only refresh less than every page-full.
2765     * the number of pages between refreshes is refresh_limit, which
2766     * is incremented here because we must be doing flat-out scrolling.
2767     */
2768     if (refreshnow)
2769     {
2770 root 1.219 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2771 pcg 1.81 refresh_limit++;
2772 pcg 1.93 else
2773 root 1.116 {
2774     flag = true;
2775     scr_refresh (refresh_type);
2776 root 1.226 flush_ev.stop ();
2777 root 1.116 }
2778 pcg 1.81 }
2779    
2780     }
2781     else
2782     {
2783     try
2784     {
2785     process_nonprinting (ch);
2786     }
2787     catch (const class out_of_input &o)
2788     {
2789     // we ran out of input, retry later
2790     cmdbuf_ptr = seq_begin;
2791     break;
2792     }
2793    
2794     ch = NOCHAR;
2795     }
2796     }
2797    
2798     return flag;
2799     }
2800    
2801 root 1.97 // read the next octet
2802     unicode_t
2803     rxvt_term::next_octet ()
2804     {
2805     return cmdbuf_ptr < cmdbuf_endp
2806     ? *cmdbuf_ptr++
2807     : NOCHAR;
2808     }
2809    
2810 pcg 1.81 // read the next character
2811     unicode_t
2812     rxvt_term::next_char ()
2813     {
2814     while (cmdbuf_ptr < cmdbuf_endp)
2815     {
2816     // assume 7-bit to be ascii ALWAYS
2817     if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2818     return *cmdbuf_ptr++;
2819    
2820     wchar_t wc;
2821     size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2822    
2823     if (len == (size_t)-2)
2824     {
2825     // the mbstate stores incomplete sequences. didn't know this :/
2826     cmdbuf_ptr = cmdbuf_endp;
2827     break;
2828     }
2829    
2830     if (len == (size_t)-1)
2831     return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2832    
2833     // assume wchar == unicode
2834     cmdbuf_ptr += len;
2835 root 1.183 return wc & UNICODE_MASK;
2836 pcg 1.81 }
2837    
2838     return NOCHAR;
2839     }
2840    
2841     /* rxvt_cmd_getc () - Return next input character */
2842     /*
2843     * Return the next input character after first passing any keyboard input
2844     * to the command.
2845     */
2846     unicode_t
2847     rxvt_term::cmd_getc ()
2848     {
2849     unicode_t c = next_char ();
2850    
2851     if (c == NOCHAR)
2852     throw out_of_input;
2853    
2854     return c;
2855     }
2856    
2857 root 1.97 unicode_t
2858     rxvt_term::cmd_get8 ()
2859     {
2860     unicode_t c = next_octet ();
2861    
2862     if (c == NOCHAR)
2863     throw out_of_input;
2864    
2865     return c;
2866     }
2867    
2868 pcg 1.1 /*{{{ print pipe */
2869     /*----------------------------------------------------------------------*/
2870     #ifdef PRINTPIPE
2871 pcg 1.34 FILE *
2872     rxvt_term::popen_printer ()
2873 pcg 1.1 {
2874 pcg 1.67 FILE *stream = popen (rs[Rs_print_pipe], "w");
2875 pcg 1.1
2876 pcg 1.36 if (stream == NULL)
2877 pcg 1.81 rxvt_warn ("can't open printer pipe, not printing.\n");
2878    
2879 pcg 1.36 return stream;
2880 pcg 1.1 }
2881    
2882     int
2883 pcg 1.34 rxvt_term::pclose_printer (FILE *stream)
2884 pcg 1.1 {
2885 pcg 1.11 fflush (stream);
2886     return pclose (stream);
2887 pcg 1.1 }
2888    
2889     /*
2890     * simulate attached vt100 printer
2891     */
2892     void
2893 pcg 1.34 rxvt_term::process_print_pipe ()
2894 pcg 1.1 {
2895 pcg 1.81 int done;
2896     FILE *fd;
2897 pcg 1.36
2898     if ((fd = popen_printer ()) == NULL)
2899     return;
2900    
2901     /*
2902     * Send all input to the printer until either ESC[4i or ESC[?4i
2903     * is received.
2904     */
2905     for (done = 0; !done;)
2906     {
2907 pcg 1.81 unsigned char buf[8];
2908     unicode_t ch;
2909     unsigned int i, len;
2910 pcg 1.1
2911 pcg 1.36 if ((ch = cmd_getc ()) != C0_ESC)
2912     {
2913 pcg 1.43 if (putc (ch, fd) == EOF)
2914 pcg 1.36 break; /* done = 1 */
2915     }
2916     else
2917     {
2918     len = 0;
2919     buf[len++] = ch;
2920 pcg 1.1
2921 pcg 1.36 if ((buf[len++] = cmd_getc ()) == '[')
2922     {
2923     if ((ch = cmd_getc ()) == '?')
2924     {
2925     buf[len++] = '?';
2926     ch = cmd_getc ();
2927     }
2928     if ((buf[len++] = ch) == '4')
2929     {
2930     if ((buf[len++] = cmd_getc ()) == 'i')
2931     break; /* done = 1 */
2932     }
2933     }
2934 pcg 1.81
2935 pcg 1.36 for (i = 0; i < len; i++)
2936 pcg 1.43 if (putc (buf[i], fd) == EOF)
2937 pcg 1.36 {
2938     done = 1;
2939     break;
2940     }
2941     }
2942 pcg 1.1 }
2943 pcg 1.81
2944 pcg 1.36 pclose_printer (fd);
2945 pcg 1.1 }
2946     #endif /* PRINTPIPE */
2947     /*}}} */
2948    
2949     /* *INDENT-OFF* */
2950     enum {
2951 pcg 1.36 C1_40 = 0x40,
2952 pcg 1.90 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2953 pcg 1.36 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2954     C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2955 pcg 1.90 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2956 pcg 1.1 };
2957     /* *INDENT-ON* */
2958    
2959     /*{{{ process non-printing single characters */
2960     void
2961 pcg 1.81 rxvt_term::process_nonprinting (unicode_t ch)
2962 pcg 1.1 {
2963 pcg 1.36 switch (ch)
2964     {
2965 pcg 1.81 case C0_ESC:
2966     process_escape_seq ();
2967     break;
2968 pcg 1.36 case C0_ENQ: /* terminal Status */
2969     if (rs[Rs_answerbackstring])
2970 pcg 1.90 tt_write ((const unsigned char *)rs[Rs_answerbackstring],
2971 root 1.145 (unsigned int)strlen (rs[Rs_answerbackstring]));
2972 pcg 1.36 else
2973 pcg 1.43 tt_write ((unsigned char *)VT100_ANS,
2974 root 1.145 (unsigned int)strlen (VT100_ANS));
2975 pcg 1.36 break;
2976     case C0_BEL: /* bell */
2977     scr_bell ();
2978     break;
2979     case C0_BS: /* backspace */
2980     scr_backspace ();
2981     break;
2982     case C0_HT: /* tab */
2983     scr_tab (1);
2984     break;
2985     case C0_CR: /* carriage return */
2986     scr_gotorc (0, 0, R_RELATIVE);
2987     break;
2988     case C0_VT: /* vertical tab, form feed */
2989     case C0_FF:
2990     case C0_LF: /* line feed */
2991     scr_index (UP);
2992     break;
2993     case C0_SO: /* shift out - acs */
2994     scr_charset_choose (1);
2995     break;
2996     case C0_SI: /* shift in - acs */
2997     scr_charset_choose (0);
2998     break;
2999 pcg 1.81
3000 root 1.97 #ifdef EIGHT_BIT_CONTROLS
3001 pcg 1.81 // 8-bit controls
3002     case 0x90: /* DCS */
3003     process_dcs_seq ();
3004     break;
3005     case 0x9b: /* CSI */
3006     process_csi_seq ();
3007     break;
3008     case 0x9d: /* CSI */
3009     process_osc_seq ();
3010     break;
3011 root 1.97 #endif
3012 pcg 1.1 }
3013     }
3014     /*}}} */
3015    
3016    
3017     /*{{{ process VT52 escape sequences */
3018     void
3019 pcg 1.81 rxvt_term::process_escape_vt52 (unicode_t ch)
3020 pcg 1.1 {
3021 pcg 1.36 int row, col;
3022    
3023     switch (ch)
3024     {
3025     case 'A': /* cursor up */
3026     scr_gotorc (-1, 0, R_RELATIVE | C_RELATIVE);
3027     break;
3028     case 'B': /* cursor down */
3029     scr_gotorc (1, 0, R_RELATIVE | C_RELATIVE);
3030     break;
3031     case 'C': /* cursor right */
3032     scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
3033     break;
3034     case 'D': /* cursor left */
3035     scr_gotorc (0, -1, R_RELATIVE | C_RELATIVE);
3036     break;
3037     case 'H': /* cursor home */
3038     scr_gotorc (0, 0, 0);
3039     break;
3040     case 'I': /* cursor up and scroll down if needed */
3041     scr_index (DN);
3042     break;
3043     case 'J': /* erase to end of screen */
3044     scr_erase_screen (0);
3045     break;
3046     case 'K': /* erase to end of line */
3047     scr_erase_line (0);
3048     break;
3049     case 'Y': /* move to specified row and col */
3050     /* full command is 'ESC Y row col' where row and col
3051     * are encoded by adding 32 and sending the ascii
3052     * character. eg. SPACE = 0, '+' = 13, '0' = 18,
3053     * etc. */
3054     row = cmd_getc () - ' ';
3055     col = cmd_getc () - ' ';
3056     scr_gotorc (row, col, 0);
3057     break;
3058     case 'Z': /* identify the terminal type */
3059 pcg 1.43 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3060 pcg 1.1 break;
3061 pcg 1.36 case '<': /* turn off VT52 mode */
3062 pcg 1.43 PrivMode (0, PrivMode_vt52);
3063 pcg 1.36 break;
3064     case 'F': /* use special graphics character set */
3065     case 'G': /* use regular character set */
3066     /* unimplemented */
3067     break;
3068     case '=': /* use alternate keypad mode */
3069     case '>': /* use regular keypad mode */
3070     /* unimplemented */
3071     break;
3072 pcg 1.1 }
3073     }
3074     /*}}} */
3075    
3076    
3077     /*{{{ process escape sequences */
3078     void
3079 pcg 1.34 rxvt_term::process_escape_seq ()
3080 pcg 1.1 {
3081 pcg 1.81 unicode_t ch = cmd_getc ();
3082 pcg 1.36
3083 root 1.145 if (priv_modes & PrivMode_vt52)
3084 pcg 1.36 {
3085     process_escape_vt52 (ch);
3086     return;
3087     }
3088 pcg 1.1
3089 pcg 1.36 switch (ch)
3090     {
3091     /* case 1: do_tek_mode (); break; */
3092     case '#':
3093     if (cmd_getc () == '8')
3094     scr_E ();
3095     break;
3096 pcg 1.44 case '(':
3097 pcg 1.36 scr_charset_set (0, (unsigned int)cmd_getc ());
3098     break;
3099     case ')':
3100     scr_charset_set (1, (unsigned int)cmd_getc ());
3101     break;
3102     case '*':
3103     scr_charset_set (2, (unsigned int)cmd_getc ());
3104     break;
3105     case '+':
3106     scr_charset_set (3, (unsigned int)cmd_getc ());
3107     break;
3108 root 1.145 #if ENABLE_FRILLS
3109 pcg 1.36 case '6':
3110     scr_backindex ();
3111     break;
3112     #endif
3113     case '7':
3114     scr_cursor (SAVE);
3115     break;
3116     case '8':
3117     scr_cursor (RESTORE);
3118     break;
3119 root 1.145 #if ENABLE_FRILLS
3120 pcg 1.36 case '9':
3121     scr_forwardindex ();
3122     break;
3123     #endif
3124     case '=':
3125     case '>':
3126 pcg 1.43 PrivMode ((ch == '='), PrivMode_aplKP);
3127 pcg 1.36 break;
3128    
3129     case C1_40:
3130     cmd_getc ();
3131     break;
3132     case C1_44:
3133     scr_index (UP);
3134     break;
3135 pcg 1.1
3136 pcg 1.36 /* 8.3.87: NEXT LINE */
3137     case C1_NEL: /* ESC E */
3138 pcg 1.1 {
3139 pcg 1.93 unicode_t nlcr[] = { C0_LF, C0_CR };
3140 pcg 1.34 scr_add_lines (nlcr, 1, 2);
3141 pcg 1.1 }
3142 pcg 1.36 break;
3143    
3144     /* kidnapped escape sequence: Should be 8.3.48 */
3145     case C1_ESA: /* ESC G */
3146     process_graphics ();
3147     break;
3148    
3149     /* 8.3.63: CHARACTER TABULATION SET */
3150     case C1_HTS: /* ESC H */
3151     scr_set_tab (1);
3152     break;
3153    
3154     /* 8.3.105: REVERSE LINE FEED */
3155     case C1_RI: /* ESC M */
3156     scr_index (DN);
3157     break;
3158    
3159     /* 8.3.142: SINGLE-SHIFT TWO */
3160 pcg 1.90 /*case C1_SS2: scr_single_shift (2); break; */
3161 pcg 1.36
3162     /* 8.3.143: SINGLE-SHIFT THREE */
3163 pcg 1.90 /*case C1_SS3: scr_single_shift (3); break; */
3164 pcg 1.36
3165     /* 8.3.27: DEVICE CONTROL STRING */
3166     case C1_DCS: /* ESC P */
3167     process_dcs_seq ();
3168     break;
3169    
3170     /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3171     case C1_SCI: /* ESC Z */
3172 pcg 1.43 tt_write ((const unsigned char *)ESCZ_ANSWER,
3173     (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3174 pcg 1.36 break; /* steal obsolete ESC [ c */
3175    
3176     /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3177     case C1_CSI: /* ESC [ */
3178     process_csi_seq ();
3179     break;
3180 pcg 1.1
3181 pcg 1.36 /* 8.3.90: OPERATING SYSTEM COMMAND */
3182     case C1_OSC: /* ESC ] */
3183     process_osc_seq ();
3184     break;
3185    
3186     /* 8.3.106: RESET TO INITIAL STATE */
3187     case 'c':
3188 pcg 1.90 mbstate.reset ();
3189 pcg 1.36 scr_poweron ();
3190     scrollbar_show (1);
3191     break;
3192    
3193     /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3194     case 'n':
3195     scr_charset_choose (2);
3196     break;
3197    
3198     /* 8.3.81: LOCKING-SHIFT THREE (see ISO2022) */
3199     case 'o':
3200     scr_charset_choose (3);
3201     break;
3202 pcg 1.1 }
3203     }
3204     /*}}} */
3205    
3206     /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3207     /* *INDENT-OFF* */
3208     enum {
3209 pcg 1.36 CSI_ICH = 0x40,
3210 pcg 1.95 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3211 pcg 1.36 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3212     CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3213     CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
3214     CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
3215     CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3216     CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3217     CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3218 pcg 1.1 };
3219    
3220     #define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \
3221     (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3222     | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3223     #define get_byte_array_bit(array, bit) \
3224 pcg 1.43 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7))))
3225 pcg 1.1
3226 pcg 1.36 const unsigned char csi_defaults[] =
3227     {
3228 pcg 1.43 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3229     make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3230     make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3231     make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3232     make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3233     make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3234     make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3235 pcg 1.90 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3236 pcg 1.36 };
3237 pcg 1.1 /* *INDENT-ON* */
3238    
3239     void
3240 pcg 1.34 rxvt_term::process_csi_seq ()
3241 pcg 1.1 {
3242 pcg 1.81 unicode_t ch, priv, i;
3243     unsigned int nargs, p;
3244     int n, ndef;
3245     int arg[ESC_ARGS];
3246 pcg 1.36
3247     for (nargs = ESC_ARGS; nargs > 0;)
3248     arg[--nargs] = 0;
3249    
3250     priv = 0;
3251     ch = cmd_getc ();
3252     if (ch >= '<' && ch <= '?')
3253     { /* '<' '=' '>' '?' */
3254     priv = ch;
3255     ch = cmd_getc ();
3256     }
3257 pcg 1.81
3258 pcg 1.36 /* read any numerical arguments */
3259     for (n = -1; ch < CSI_ICH; )
3260     {
3261 pcg 1.43 if (isdigit (ch))
3262 pcg 1.36 {
3263     if (n < 0)
3264     n = ch - '0';
3265     else
3266     n = n * 10 + ch - '0';
3267     }
3268     else if (ch == ';')
3269     {
3270     if (nargs < ESC_ARGS)
3271     arg[nargs++] = n;
3272     n = -1;
3273     }
3274 pcg 1.81 else if (IS_CONTROL (ch))
3275     process_nonprinting (ch);
3276    
3277 pcg 1.36 ch = cmd_getc ();
3278     }
3279 pcg 1.1
3280 pcg 1.36 if (ch > CSI_7F)
3281     return;
3282 pcg 1.1
3283 pcg 1.36 if (nargs < ESC_ARGS)
3284     arg[nargs++] = n;
3285    
3286     i = ch - CSI_ICH;
3287 pcg 1.43 ndef = get_byte_array_bit (csi_defaults, i);
3288 pcg 1.36 for (p = 0; p < nargs; p++)
3289     if (arg[p] == -1)
3290     arg[p] = ndef;
3291 pcg 1.1
3292     #ifdef DEBUG_CMD
3293 pcg 1.43 fprintf (stderr, "CSI ");
3294 pcg 1.36 for (p = 0; p < nargs; p++)
3295 pcg 1.43 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3296     fprintf (stderr, "%c\n", ch);
3297 pcg 1.1 #endif
3298    
3299 pcg 1.36 /*
3300     * private mode handling
3301     */
3302     if (priv)
3303     {
3304     switch (priv)
3305     {
3306     case '>':
3307     if (ch == CSI_DA) /* secondary device attributes */
3308 root 1.194 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3309 pcg 1.36 break;
3310     case '?':
3311     if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3312     process_terminal_mode (ch, priv, nargs, arg);
3313     break;
3314     }
3315     return;
3316 pcg 1.1 }
3317    
3318 pcg 1.36 switch (ch)
3319     {
3320     /*
3321 pcg 1.43 * ISO/IEC 6429:1992 (E) CSI sequences (defaults in parentheses)
3322 pcg 1.36 */
3323 pcg 1.1 #ifdef PRINTPIPE
3324 pcg 1.36 case CSI_MC: /* 8.3.83: (0) MEDIA COPY */
3325     switch (arg[0])
3326     {
3327     case 0: /* initiate transfer to primary aux device */
3328     scr_printscreen (0);
3329     break;
3330     case 5: /* start relay to primary aux device */
3331     process_print_pipe ();
3332     break;
3333     }
3334     break;
3335     #endif
3336 pcg 1.1
3337 pcg 1.36 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3338     case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3339     arg[0] = -arg[0];
3340     /* FALLTHROUGH */
3341     case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3342     case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3343     scr_gotorc (arg[0], 0, RELATIVE);
3344     break;
3345    
3346     case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3347     case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3348 pcg 1.1 #ifdef ISO6429
3349 pcg 1.36 arg[0] = -arg[0];
3350 pcg 1.1 #else /* emulate common DEC VTs */
3351 pcg 1.36 arg[0] = arg[0] ? -arg[0] : -1;
3352 pcg 1.1 #endif
3353 pcg 1.36 /* FALLTHROUGH */
3354     case CSI_CUF: /* 8.3.20: (1) CURSOR RIGHT */
3355     case CSI_HPR: /* 8.3.60: (1) CHARACTER POSITION FORWARD */
3356 pcg 1.1 #ifdef ISO6429
3357 pcg 1.36 scr_gotorc (0, arg[0], RELATIVE);
3358 pcg 1.1 #else /* emulate common DEC VTs */
3359 pcg 1.36 scr_gotorc (0, arg[0] ? arg[0] : 1, RELATIVE);
3360 pcg 1.1 #endif
3361 pcg 1.36 break;
3362    
3363     case CSI_CPL: /* 8.3.13: (1) CURSOR PRECEDING LINE */
3364     arg[0] = -arg[0];
3365     /* FALLTHROUGH */
3366     case CSI_CNL: /* 8.3.12: (1) CURSOR NEXT LINE */
3367     scr_gotorc (arg[0], 0, R_RELATIVE);
3368     break;
3369    
3370     case CSI_CHA: /* 8.3.9: (1) CURSOR CHARACTER ABSOLUTE */
3371     case CSI_HPA: /* 8.3.58: (1) CURSOR POSITION ABSOLUTE */
3372     scr_gotorc (0, arg[0] - 1, R_RELATIVE);
3373     break;
3374    
3375     case CSI_VPA: /* 8.3.159: (1) LINE POSITION ABSOLUTE */
3376     scr_gotorc (arg[0] - 1, 0, C_RELATIVE);
3377     break;
3378    
3379     case CSI_CUP: /* 8.3.21: (1,1) CURSOR POSITION */
3380     case CSI_HVP: /* 8.3.64: (1,1) CHARACTER AND LINE POSITION */
3381     scr_gotorc (arg[0] - 1, nargs < 2 ? 0 : (arg[1] - 1), 0);
3382     break;
3383 pcg 1.1
3384 pcg 1.36 case CSI_CBT: /* 8.3.7: (1) CURSOR BACKWARD TABULATION */
3385     arg[0] = -arg[0];
3386     /* FALLTHROUGH */
3387     case CSI_CHT: /* 8.3.10: (1) CURSOR FORWARD TABULATION */
3388     scr_tab (arg[0]);
3389     break;
3390    
3391     case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */
3392     scr_erase_screen (arg[0]);
3393     break;
3394    
3395     case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */
3396     scr_erase_line (arg[0]);
3397     break;
3398    
3399     case CSI_ICH: /* 8.3.65: (1) INSERT CHARACTER */
3400     scr_insdel_chars (arg[0], INSERT);
3401     break;
3402    
3403     case CSI_IL: /* 8.3.68: (1) INSERT LINE */
3404     scr_insdel_lines (arg[0], INSERT);
3405     break;
3406    
3407     case CSI_DL: /* 8.3.33: (1) DELETE LINE */
3408     scr_insdel_lines (arg[0], DELETE);
3409     break;
3410    
3411     case CSI_ECH: /* 8.3.39: (1) ERASE CHARACTER */
3412     scr_insdel_chars (arg[0], ERASE);
3413     break;
3414    
3415     case CSI_DCH: /* 8.3.26: (1) DELETE CHARACTER */
3416     scr_insdel_chars (arg[0], DELETE);
3417     break;
3418    
3419     case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3420     arg[0] = -arg[0];
3421     /* FALLTHROUGH */
3422     case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3423 root 1.210 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3424 pcg 1.36 break;
3425    
3426     case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3427 pcg 1.43 tt_write ((const unsigned char *)VT100_ANS,
3428 root 1.145 (unsigned int) (sizeof (VT100_ANS) - 1));
3429 pcg 1.36 break;
3430    
3431     case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3432     process_sgr_mode (nargs, arg);
3433     break;
3434    
3435     case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */
3436     switch (arg[0])
3437     {
3438     case 5: /* DSR requested */
3439 pcg 1.43 tt_printf ("\033[0n");
3440 pcg 1.36 break;
3441     case 6: /* CPR requested */
3442     scr_report_position ();
3443     break;
3444     case 7: /* unofficial extension */
3445 root 1.219 if (OPTION (Opt_insecure))
3446 root 1.145 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3447 pcg 1.36 break;
3448     case 8: /* unofficial extension */
3449 pcg 1.90 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3450 pcg 1.36 break;
3451     }
3452     break;
3453 pcg 1.1
3454 pcg 1.36 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3455     switch (arg[0])
3456     {
3457     case 0: /* char tab stop cleared at active position */
3458     scr_set_tab (0);
3459     break;
3460     /* case 1: */ /* line tab stop cleared in active line */
3461     /* case 2: */ /* char tab stops cleared in active line */
3462     case 3: /* all char tab stops are cleared */
3463     /* case 4: */ /* all line tab stops are cleared */
3464     case 5: /* all tab stops are cleared */
3465     scr_set_tab (-1);
3466     break;
3467     }
3468     break;
3469    
3470     case CSI_CTC: /* 8.3.17: (0) CURSOR TABULATION CONTROL */
3471     switch (arg[0])
3472     {
3473     case 0: /* char tab stop set at active position */
3474     scr_set_tab (1);
3475     break; /* = ESC H */
3476     /* case 1: */ /* line tab stop set at active line */
3477     case 2: /* char tab stop cleared at active position */
3478     scr_set_tab (0);
3479     break; /* = ESC [ 0 g */
3480     /* case 3: */ /* line tab stop cleared at active line */
3481     /* case 4: */ /* char tab stops cleared at active line */
3482     case 5: /* all char tab stops are cleared */
3483     scr_set_tab (-1);
3484     break; /* = ESC [ 3 g */
3485     /* case 6: */ /* all line tab stops are cleared */
3486     }
3487     break;
3488    
3489     case CSI_RM: /* 8.3.107: RESET MODE */
3490     if (arg[0] == 4)
3491     scr_insert_mode (0);
3492 root 1.145 else if (arg[0] == 20)
3493     priv_modes &= ~PrivMode_LFNL;
3494 pcg 1.36 break;
3495    
3496     case CSI_SM: /* 8.3.126: SET MODE */
3497     if (arg[0] == 4)
3498     scr_insert_mode (1);
3499 root 1.145 else if (arg[0] == 20)
3500     priv_modes |= PrivMode_LFNL;
3501 pcg 1.36 break;
3502    
3503     /*
3504     * PRIVATE USE beyond this point. All CSI_7? sequences here
3505     */
3506     case CSI_72: /* DECSTBM: set top and bottom margins */
3507     if (nargs == 1)
3508     scr_scroll_region (arg[0] - 1, MAX_ROWS - 1);
3509     else if (nargs == 0 || arg[0] >= arg[1])
3510     scr_scroll_region (0, MAX_ROWS - 1);
3511     else
3512     scr_scroll_region (arg[0] - 1, arg[1] - 1);
3513     break;
3514    
3515     case CSI_73:
3516     scr_cursor (SAVE);
3517     break;
3518     case CSI_75:
3519     scr_cursor (RESTORE);
3520     break;
3521 pcg 1.1
3522 root 1.145 #if ENABLE_FRILLS
3523 pcg 1.36 case CSI_74:
3524     process_window_ops (arg, nargs);
3525     break;
3526 pcg 1.1 #endif
3527    
3528 pcg 1.36 case CSI_78: /* DECREQTPARM */
3529     if (arg[0] == 0 || arg[0] == 1)
3530 pcg 1.43 tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2);
3531 pcg 1.81 break;
3532 pcg 1.1
3533 pcg 1.36 default:
3534     break;
3535 pcg 1.1 }
3536     }
3537     /*}}} */
3538    
3539 root 1.145 #if ENABLE_FRILLS
3540 pcg 1.1 /* ARGSUSED */
3541     void
3542 pcg 1.34 rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3543 pcg 1.1 {
3544 pcg 1.81 int x, y;
3545 pcg 1.36 XWindowAttributes wattr;
3546 pcg 1.81 Window wdummy;
3547 root 1.192 dDisp;
3548 pcg 1.1
3549 pcg 1.36 if (nargs == 0)
3550     return;
3551 pcg 1.81
3552 pcg 1.36 switch (args[0])
3553     {
3554 pcg 1.81 /*
3555     * commands
3556     */
3557 pcg 1.36 case 1: /* deiconify window */
3558 root 1.208 XMapWindow (disp, parent[0]);
3559 pcg 1.36 break;
3560     case 2: /* iconify window */
3561 root 1.208 XIconifyWindow (disp, parent[0], display->screen);
3562 pcg 1.36 break;
3563     case 3: /* set position (pixels) */
3564 root 1.208 XMoveWindow (disp, parent[0], args[1], args[2]);
3565 pcg 1.36 break;
3566     case 4: /* set size (pixels) */
3567     set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3568     break;
3569     case 5: /* raise window */
3570 root 1.208 XRaiseWindow (disp, parent[0]);
3571 pcg 1.36 break;
3572     case 6: /* lower window */
3573 root 1.208 XLowerWindow (disp, parent[0]);
3574 pcg 1.36 break;
3575     case 7: /* refresh window */
3576     scr_touch (true);
3577     break;
3578     case 8: /* set size (chars) */
3579 root 1.208 set_widthheight ((unsigned int) (args[2] * fwidth),
3580     (unsigned int) (args[1] * fheight));
3581 pcg 1.36 break;
3582 pcg 1.81
3583     //case 9: NYI, TODO, restore maximized window or maximize window
3584 pcg 1.36 default:
3585     if (args[0] >= 24) /* set height (chars) */
3586 root 1.208 set_widthheight ((unsigned int)width,
3587     (unsigned int) (args[1] * fheight));
3588 pcg 1.36 break;
3589 pcg 1.81
3590    
3591     /*
3592     * reports - some output format copied from XTerm
3593     */
3594 pcg 1.36 case 11: /* report window state */
3595 root 1.208 XGetWindowAttributes (disp, parent[0], &wattr);
3596 pcg 1.43 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3597 pcg 1.36 break;
3598     case 13: /* report window position */
3599 root 1.208 XGetWindowAttributes (disp, parent[0], &wattr);
3600     XTranslateCoordinates (disp, parent[0], wattr.root,
3601 pcg 1.90 -wattr.border_width, -wattr.border_width,
3602     &x, &y, &wdummy);
3603 pcg 1.43 tt_printf ("\033[3;%d;%dt", x, y);
3604 pcg 1.36 break;
3605     case 14: /* report window size (pixels) */
3606 root 1.208 XGetWindowAttributes (disp, parent[0], &wattr);
3607 pcg 1.43 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3608 pcg 1.36 break;
3609 pcg 1.81 case 18: /* report text area size (chars) */
3610 root 1.208 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3611 pcg 1.36 break;
3612 pcg 1.81 case 19: /* report window size (chars) */
3613 root 1.208 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3614 pcg 1.81 break;
3615 pcg 1.36 case 20: /* report icon label */
3616 root 1.131 {
3617     char *s;
3618 root 1.208 XGetIconName (disp, parent[0], &s);
3619 root 1.219 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3620 root 1.131 XFree (s);
3621     }
3622 pcg 1.36 break;
3623     case 21: /* report window title */
3624 root 1.131 {
3625     char *s;
3626 root 1.208 XFetchName (disp, parent[0], &s);
3627 root 1.219 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3628 root 1.131 XFree (s);
3629     }
3630 pcg 1.36 break;
3631 pcg 1.1 }
3632     }
3633     #endif
3634    
3635     /*----------------------------------------------------------------------*/
3636     /*
3637     * get input up until STRING TERMINATOR (or BEL)
3638 pcg 1.93 * ends_how is terminator used. returned input must be free()'d
3639 pcg 1.1 */
3640 pcg 1.81 unsigned char *
3641     rxvt_term::get_to_st (unicode_t &ends_how)
3642 pcg 1.1 {
3643 root 1.175 unicode_t ch;
3644     bool seen_esc = false;
3645 pcg 1.81 unsigned int n = 0;
3646 root 1.175 wchar_t string[STRING_MAX];
3647 pcg 1.36
3648 root 1.97 while ((ch = cmd_getc ()) != NOCHAR)
3649 pcg 1.36 {
3650 root 1.163 if (seen_esc)
3651 pcg 1.36 {
3652 root 1.97 if (ch == 0x5c) /* 7bit ST */
3653     break;
3654     else
3655     return NULL;
3656 pcg 1.36 }
3657 root 1.163 else if (ch == C0_ESC)
3658     {
3659 root 1.175 seen_esc = true;
3660 root 1.163 continue;
3661     }
3662 root 1.97 else if (ch == C0_BEL || ch == CHAR_ST)
3663     break;
3664     else if (ch < 0x20)
3665 pcg 1.36 return NULL; /* other control character - exit */
3666 pcg 1.81
3667 root 1.175 seen_esc = false;
3668 root 1.163
3669 root 1.202 if (n >= STRING_MAX - 1)
3670 pcg 1.90 // stop at some sane length
3671     return NULL;
3672 pcg 1.81
3673 root 1.97 if (ch == C0_SYN)
3674 root 1.163 string[n++] = cmd_get8 ();
3675 root 1.97 else
3676 root 1.163 string[n++] = ch;
3677 pcg 1.36 }
3678 pcg 1.81
3679 pcg 1.36 string[n++] = '\0';
3680 pcg 1.81
3681 root 1.175 ends_how = (ch == 0x5c ? C0_ESC : ch);
3682 pcg 1.81
3683 root 1.175 return (unsigned char *)rxvt_wcstombs (string);
3684 pcg 1.1 }
3685    
3686     /*----------------------------------------------------------------------*/
3687     /*
3688     * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3689     */
3690     void
3691 pcg 1.34 rxvt_term::process_dcs_seq ()
3692 pcg 1.1 {
3693 pcg 1.81 unsigned char *s;
3694     unicode_t eh;
3695    
3696 pcg 1.36 /*
3697     * Not handled yet
3698     */
3699 pcg 1.81 s = get_to_st (eh);
3700 pcg 1.36 if (s)
3701 pcg 1.43 free (s);
3702 pcg 1.81
3703 pcg 1.36 return;
3704 pcg 1.1 }
3705    
3706     /*----------------------------------------------------------------------*/
3707     /*
3708     * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3709     */
3710     void
3711 pcg 1.34 rxvt_term::process_osc_seq ()
3712 pcg 1.1 {
3713 pcg 1.81 unicode_t ch, eh;
3714     int arg;
3715 pcg 1.1
3716 pcg 1.36 ch = cmd_getc ();
3717 pcg 1.43 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3718 pcg 1.36 arg = arg * 10 + (ch - '0');
3719 pcg 1.1
3720 pcg 1.36 if (ch == ';')
3721     {
3722 pcg 1.81 unsigned char *s = get_to_st (eh);
3723    
3724 pcg 1.36 if (s)
3725     {
3726 pcg 1.90 process_xterm_seq (arg, (char *)s, eh);
3727     free (s);
3728     }
3729     }
3730     }
3731 pcg 1.81
3732 pcg 1.90 void
3733     rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp)
3734     {
3735     if (str[0] == '?' && !str[1])
3736     {
3737 root 1.131 unsigned short r, g, b;
3738 root 1.145 pix_colors_focused[color].get (display, r, g, b);
3739 root 1.131 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp);
3740 pcg 1.1 }
3741 pcg 1.90 else
3742     set_window_color (color, str);
3743 pcg 1.1 }
3744 pcg 1.90
3745 pcg 1.1 /*
3746     * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3747     */
3748     void
3749 pcg 1.90 rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3750 pcg 1.1 {
3751 pcg 1.81 int changed = 0;
3752     int color;
3753     char *buf, *name;
3754 pcg 1.90 bool query = str[0] == '?' && !str[1];
3755 root 1.163 int saveop = op;
3756 root 1.192 dDisp;
3757 pcg 1.36
3758 pcg 1.43 assert (str != NULL);
3759 pcg 1.36 switch (op)
3760     {
3761     case XTerm_name:
3762     set_title (str);
3763     /* FALLTHROUGH */
3764     case XTerm_iconName:
3765 pcg 1.81 set_icon_name (str);
3766 pcg 1.36 break;
3767     case XTerm_title:
3768     set_title (str);
3769     break;
3770 pcg 1.90 case XTerm_property:
3771     if (str[0] == '?')
3772     {
3773 root 1.175 Atom prop = display->atom (str + 1);
3774 pcg 1.90 Atom actual_type;
3775     int actual_format;
3776     unsigned long nitems;
3777     unsigned long bytes_after;
3778     unsigned char *value = 0;
3779     const char *str = "";
3780    
3781     if (prop
3782 root 1.208 && XGetWindowProperty (disp, parent[0],
3783 pcg 1.90 prop, 0, 1<<16, 0, AnyPropertyType,
3784     &actual_type, &actual_format,
3785     &nitems, &bytes_after, &value) == Success
3786     && actual_type != None
3787     && actual_format == 8)
3788     str = (const char *)(value);
3789    
3790     tt_printf ("\033]%d;%s%c", XTerm_property, str, resp);
3791    
3792     XFree (value);
3793     }
3794     else
3795     {
3796     char *eq = strchr (str, '='); // constness lost, but verified to be ok
3797    
3798     if (eq)
3799     {
3800     *eq = 0;
3801 root 1.175 set_utf8_property (display->atom (str), eq + 1);
3802 pcg 1.90 }
3803     else
3804 root 1.208 XDeleteProperty (disp, parent[0],
3805 pcg 1.90 display->atom (str));
3806     }
3807     break;
3808    
3809 pcg 1.36 case XTerm_Color:
3810     for (buf = (char *)str; buf && *buf;)
3811     {
3812 root 1.145 if ((name = strchr (buf, ';')) == NULL)
3813 pcg 1.36 break;
3814 pcg 1.81
3815 pcg 1.36 *name++ = '\0';
3816 pcg 1.43 color = atoi (buf);
3817 pcg 1.81
3818 pcg 1.36 if (color < 0 || color >= TOTAL_COLORS)
3819     break;
3820 pcg 1.81
3821 root 1.145 if ((buf = strchr (name, ';')) != NULL)
3822 pcg 1.36 *buf++ = '\0';
3823 pcg 1.81
3824 pcg 1.90 if (name[0] == '?' && !name[1])
3825     {
3826 root 1.131 unsigned short r, g, b;
3827 root 1.145 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3828 root 1.131 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3829 pcg 1.90 }
3830     else
3831     set_window_color (color + minCOLOR, name);
3832 pcg 1.36 }
3833     break;
3834 pcg 1.90 case XTerm_Color00:
3835     process_color_seq (XTerm_Color00, Color_fg, str, resp);
3836     break;
3837     case XTerm_Color01:
3838     process_color_seq (XTerm_Color00, Color_bg, str, resp);
3839     break;
3840 pcg 1.1 #ifndef NO_CURSORCOLOR
3841 pcg 1.36 case XTerm_Color_cursor:
3842 pcg 1.90 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3843 pcg 1.36 break;
3844     #endif
3845 pcg 1.90 case XTerm_Color_pointer_fg:
3846     process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3847     break;
3848     case XTerm_Color_pointer_bg:
3849     process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3850 pcg 1.36 break;
3851 pcg 1.1 #ifndef NO_BOLD_UNDERLINE_REVERSE
3852 pcg 1.36 case XTerm_Color_BD:
3853 pcg 1.90 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3854 pcg 1.36 break;
3855     case XTerm_Color_UL:
3856 pcg 1.90 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3857 pcg 1.36 break;
3858     case XTerm_Color_RV:
3859 pcg 1.90 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3860 pcg 1.36 break;
3861 root 1.201 case URxvt_Color_IT:
3862     process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3863     break;
3864 pcg 1.1 #endif
3865 root 1.170 #if TRANSPARENT && TINTING
3866 root 1.201 case URxvt_Color_tint:
3867     process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3868 root 1.163 check_our_parents ();
3869     if (am_transparent)
3870     want_full_refresh = want_refresh = 1;
3871     break;
3872     #endif
3873 pcg 1.1
3874 pcg 1.36 case XTerm_Pixmap:
3875     if (*str != ';')
3876     {
3877 pcg 1.1 #if XPM_BACKGROUND
3878 pcg 1.36 scale_pixmap (""); /* reset to default scaling */
3879     set_bgPixmap (str); /* change pixmap */
3880 pcg 1.1 #endif
3881 pcg 1.36 scr_touch (true);
3882     }
3883 root 1.145 while ((str = strchr (str, ';')) != NULL)
3884 pcg 1.36 {
3885     str++;
3886 pcg 1.1 #if XPM_BACKGROUND
3887 pcg 1.36 changed += scale_pixmap (str);
3888 pcg 1.1 #endif
3889 root 1.191 }
3890 pcg 1.36
3891     if (changed)
3892     {
3893 pcg 1.1 #ifdef XPM_BACKGROUND
3894 pcg 1.36 resize_pixmap ();
3895 pcg 1.1 #endif
3896 pcg 1.36 scr_touch (true);
3897     }
3898     break;
3899    
3900     case XTerm_restoreFG:
3901     set_window_color (Color_fg, str);
3902     break;
3903     case XTerm_restoreBG:
3904     set_window_color (Color_bg, str);
3905     break;
3906 pcg 1.90
3907 pcg 1.36 case XTerm_logfile:
3908 pcg 1.81 // TODO, when secure mode?
3909 pcg 1.36 break;
3910 pcg 1.90
3911 root 1.201 #ifdef MENUBAR
3912     case URxvt_Menu:
3913 root 1.219 if (OPTION (Opt_insecure))
3914 root 1.201 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3915     break;
3916     #endif
3917     #if 0
3918     case XTerm_dumpscreen: /* no error notices */
3919     {
3920     int fd;
3921     if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3922     {
3923     scr_dump (fd);
3924     close (fd);
3925     }
3926     }
3927     break;
3928     #endif
3929 pcg 1.36 case XTerm_font:
3930 root 1.163 op = URxvt_font;
3931     case URxvt_font:
3932     #if ENABLE_STYLES
3933     case URxvt_boldFont:
3934     case URxvt_italicFont:
3935     case URxvt_boldItalicFont:
3936     #endif
3937 pcg 1.90 if (query)
3938 root 1.163 tt_printf ("\33]%d;%-.250s%c", saveop,
3939 root 1.219 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3940 root 1.208 ? fontset[op - URxvt_font]->fontdesc : "",
3941 root 1.131 resp);
3942 pcg 1.90 else
3943 root 1.163 {
3944     const char *&res = rs[Rs_font + (op - URxvt_font)];
3945    
3946     res = strdup (str);
3947     allocated.push_back ((void *)res);
3948     set_fonts ();
3949     }
3950 pcg 1.51 break;
3951 pcg 1.90
3952 root 1.145 #if ENABLE_FRILLS
3953 root 1.201 case URxvt_locale:
3954 pcg 1.90 if (query)
3955 root 1.219 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp);
3956 pcg 1.54 else
3957     {
3958     set_locale (str);
3959 root 1.190 pty.set_utf8_mode (enc_utf8);
3960 root 1.199 init_xlocale ();
3961 pcg 1.54 }
3962 pcg 1.36 break;
3963 pcg 1.90
3964 root 1.201 case URxvt_view_up:
3965     case URxvt_view_down:
3966     int lines = atoi (str);
3967    
3968     if (lines)
3969     scr_page (op == URxvt_view_up ? UP : DN, lines);
3970     else
3971     {
3972     scr_erase_savelines ();
3973     }
3974    
3975 pcg 1.36 break;
3976 pcg 1.1 #endif
3977     }
3978     }
3979     /*----------------------------------------------------------------------*/
3980    
3981     /*{{{ process DEC private mode sequences `ESC [ ? Ps mode' */
3982     /*
3983     * mode can only have the following values:
3984     * 'l' = low
3985     * 'h' = high
3986     * 's' = save
3987     * 'r' = restore
3988     * 't' = toggle
3989     * so no need for fancy checking
3990     */
3991     int
3992 pcg 1.34 rxvt_term::privcases (int mode, unsigned long bit)
3993 pcg 1.1 {
3994 pcg 1.81 int state;
3995 pcg 1.1
3996 pcg 1.36 if (mode == 's')
3997     {
3998 root 1.145 SavedModes |= (priv_modes & bit);
3999 pcg 1.36 return -1;
4000 pcg 1.1 }
4001 pcg 1.36 else
4002     {
4003     if (mode == 'r')
4004     state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
4005     else
4006 root 1.145 state = (mode == 't') ? ! (priv_modes & bit) : mode;
4007 pcg 1.43 PrivMode (state, bit);
4008 pcg 1.36 }
4009 pcg 1.81
4010 pcg 1.36 return state;
4011 pcg 1.1 }
4012    
4013     /* we're not using priv _yet_ */
4014     void
4015 pcg 1.43 rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg)
4016 pcg 1.1 {
4017 pcg 1.81 unsigned int i, j;
4018     int state;
4019    
4020 pcg 1.36 static const struct
4021     {
4022     const int argval;
4023     const unsigned long bit;
4024     }
4025 pcg 1.81
4026 pcg 1.36 argtopriv[] = {
4027     { 1, PrivMode_aplCUR },
4028     { 2, PrivMode_vt52 },
4029     { 3, PrivMode_132 },
4030     { 4, PrivMode_smoothScroll },
4031     { 5, PrivMode_rVideo },
4032     { 6, PrivMode_relOrigin },
4033     { 7, PrivMode_Autowrap },
4034 root 1.145 // 8, bi-directional support mode
4035 pcg 1.36 { 9, PrivMode_MouseX10 },
4036 pcg 1.1 #ifdef menuBar_esc
4037 pcg 1.36 { menuBar_esc, PrivMode_menuBar },
4038 pcg 1.1 #endif
4039 root 1.145 // 18, 19 printing-related
4040     { 25, PrivMode_VisibleCursor },
4041 pcg 1.1 #ifdef scrollBar_esc
4042 pcg 1.36 { scrollBar_esc, PrivMode_scrollBar },
4043 pcg 1.1 #endif
4044 pcg 1.73 { 35, PrivMode_ShiftKeys }, // rxvt extension
4045 pcg 1.36 { 40, PrivMode_132OK },
4046 pcg 1.73 // 41 xterm more fixes NYI
4047     // 45 margin bell NYI
4048     // 46 start logging
4049 pcg 1.36 { 47, PrivMode_Screen },
4050     { 66, PrivMode_aplKP },
4051 pcg 1.1 #ifndef NO_BACKSPACE_KEY
4052 pcg 1.36 { 67, PrivMode_BackSpace },
4053 pcg 1.1 #endif
4054 pcg 1.36 { 1000, PrivMode_MouseX11 },
4055 pcg 1.73 // 1001 Use Hilite Mouse Tracking. NYI, TODO
4056     // 1002 Use Cell Motion Mouse Tracking. NYI, TODO
4057     // 1003 Use All Motion Mouse Tracking. NYI, TODO
4058     { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4059     { 1011, PrivMode_Keypress }, // rxvt extension
4060     // 1035 enable modifiers for alt, numlock NYI
4061     // 1036 send ESC for meta keys NYI
4062     // 1037 send DEL for keypad delete NYI
4063 pcg 1.36 { 1047, PrivMode_Screen },
4064 pcg 1.73 // 1048 save and restore cursor
4065 pcg 1.90 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4066 pcg 1.73 // 1051, 1052, 1060, 1061 keyboard emulation NYI
4067 pcg 1.36 };
4068    
4069     if (nargs == 0)
4070     return;
4071    
4072     /* make lo/hi boolean */
4073     if (mode == 'l')
4074     mode = 0; /* reset */
4075     else if (mode == 'h')
4076     mode = 1; /* set */
4077    
4078     for (i = 0; i < nargs; i++)
4079     {
4080     state = -1;
4081    
4082     /* basic handling */
4083 pcg 1.43 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++)
4084 pcg 1.36 if (argtopriv[j].argval == arg[i])
4085     {
4086     state = privcases (mode, argtopriv[j].bit);
4087     break;
4088     }
4089 pcg 1.1
4090 pcg 1.36 /* extra handling for values with state unkept */
4091 pcg 1.73 switch (arg[i])
4092     {
4093 root 1.220 #if ENABLE_STYLES
4094     case 1021:
4095     if (mode)
4096     SET_OPTION (Opt_intensityStyles);
4097     else
4098     CLR_OPTION (Opt_intensityStyles);
4099 root 1.222
4100 root 1.225 scr_touch (true);
4101 root 1.222 break;
4102 root 1.220 #endif
4103 pcg 1.73 case 1048: /* alternative cursor save */
4104 root 1.163 case 1049:
4105 root 1.219 if (OPTION (Opt_secondaryScreen))
4106 pcg 1.90 if (mode == 0)
4107     scr_cursor (RESTORE);
4108     else if (mode == 1)
4109     scr_cursor (SAVE);
4110     break;
4111 pcg 1.73 }
4112    
4113     if (state >= 0)
4114     /* extra handling for values with valid 0 or 1 state */
4115 pcg 1.36 switch (arg[i])
4116     {
4117 pcg 1.73 /* case 1: - application cursor keys */
4118     case 2: /* VT52 mode */
4119     /* oddball mode. should be set regardless of set/reset
4120     * parameter. Return from VT52 mode with an ESC < from
4121     * within VT52 mode
4122     */
4123     PrivMode (1, PrivMode_vt52);
4124     break;
4125     case 3: /* 80/132 */
4126 root 1.145 if (priv_modes & PrivMode_132OK)
4127 root 1.208 set_widthheight (((state ? 132 : 80) * fwidth), height);
4128 pcg 1.73 break;
4129     case 4: /* smooth scrolling */
4130 root 1.219 if (!state)
4131     SET_OPTION (Opt_jumpScroll);
4132 pcg 1.73 else
4133 root 1.219 CLR_OPTION (Opt_jumpScroll);
4134 pcg 1.73 break;
4135     case 5: /* reverse video */
4136     scr_rvideo_mode (state);
4137     break;
4138     case 6: /* relative/absolute origins */
4139     scr_relative_origin (state);
4140     break;
4141     case 7: /* autowrap */
4142     scr_autowrap (state);
4143     break;
4144 pcg 1.90 /* case 8: - auto repeat, can't do on a per window basis */
4145 pcg 1.73 case 9: /* X10 mouse reporting */
4146     if (state) /* orthogonal */
4147 root 1.145 priv_modes &= ~PrivMode_MouseX11;
4148 pcg 1.73 break;
4149 pcg 1.1 #ifdef menuBar_esc
4150 pcg 1.73 case menuBar_esc:
4151 pcg 1.1 #ifdef MENUBAR
4152 pcg 1.73 map_menuBar (state);
4153 pcg 1.1 #endif
4154 pcg 1.73 break;
4155 pcg 1.1 #endif
4156     #ifdef scrollBar_esc
4157 pcg 1.73 case scrollBar_esc:
4158     if (scrollbar_mapping (state))
4159     {
4160     resize_all_windows (0, 0, 0);
4161     scr_touch (true);
4162     }
4163     break;
4164 pcg 1.1 #endif
4165 pcg 1.73 case 25: /* visible/invisible cursor */
4166     scr_cursor_visible (state);
4167     break;
4168 pcg 1.90 /* case 35: - shift keys */
4169     /* case 40: - 80 <--> 132 mode */
4170 pcg 1.73 case 47: /* secondary screen */
4171     scr_change_screen (state);
4172     break;
4173 pcg 1.90 /* case 66: - application key pad */
4174     /* case 67: - backspace key */
4175 pcg 1.73 case 1000: /* X11 mouse reporting */
4176     if (state) /* orthogonal */
4177 root 1.145 priv_modes &= ~PrivMode_MouseX10;
4178 pcg 1.73 break;
4179 pcg 1.1 #if 0
4180 pcg 1.73 case 1001:
4181     break; /* X11 mouse highlighting */
4182 pcg 1.1 #endif
4183 pcg 1.73 case 1010: /* scroll to bottom on TTY output inhibit */
4184 root 1.219 if (!state)
4185     SET_OPTION (Opt_scrollTtyOutput);
4186 pcg 1.73 else
4187 root 1.219 CLR_OPTION (Opt_scrollTtyOutput);
4188 pcg 1.73 break;
4189     case 1011: /* scroll to bottom on key press */
4190     if (state)
4191 root 1.219 SET_OPTION (Opt_scrollTtyKeypress);
4192 pcg 1.73 else
4193 root 1.219 CLR_OPTION (Opt_scrollTtyKeypress);
4194 pcg 1.73 break;
4195 pcg 1.90 case 1047: /* secondary screen w/ clearing last */
4196 root 1.219 if (OPTION (Opt_secondaryScreen))
4197 pcg 1.90 if (current_screen != PRIMARY)
4198     scr_erase_screen (2);
4199     scr_change_screen (state);
4200     break;
4201     case 1049: /* secondary screen w/ clearing first */
4202 pcg 1.73 scr_change_screen (state);
4203 root 1.219 if (OPTION (Opt_secondaryScreen))
4204 pcg 1.90 if (current_screen != PRIMARY)
4205     scr_erase_screen (2);
4206     break;
4207 pcg 1.73 default:
4208     break;
4209     }
4210 pcg 1.1 }
4211     }
4212     /*}}} */
4213    
4214     /*{{{ process sgr sequences */
4215     void
4216 pcg 1.34 rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4217 pcg 1.1 {
4218 pcg 1.81 unsigned int i;
4219     short rendset;
4220     int rendstyle;
4221 pcg 1.36
4222     if (nargs == 0)
4223     {
4224     scr_rendition (0, ~RS_None);
4225     return;
4226     }
4227 pcg 1.81
4228 pcg 1.36 for (i = 0; i < nargs; i++)
4229     {
4230     rendset = -1;
4231     switch (arg[i])
4232     {
4233     case 0:
4234     rendset = 0, rendstyle = ~RS_None;
4235     break;
4236     case 1:
4237     rendset = 1, rendstyle = RS_Bold;
4238     break;
4239 root 1.163 //case 2: // low intensity
4240     case 3:
4241     rendset = 1, rendstyle = RS_Italic;
4242     break;
4243 pcg 1.36 case 4:
4244     rendset = 1, rendstyle = RS_Uline;
4245     break;
4246 root 1.107 case 5: // slowly blinking
4247     case 6: // rapidly blinking
4248 pcg 1.36 rendset = 1, rendstyle = RS_Blink;
4249     break;
4250 pcg 1.93 //case 6: // scoansi light background
4251 pcg 1.36 case 7:
4252     rendset = 1, rendstyle = RS_RVid;
4253     break;
4254 pcg 1.73 case 8:
4255     // invisible. NYI
4256     break;
4257 root 1.107 //case 9: // crossed out
4258     //case 10: // scoansi acs off, primary font
4259     //case 11: // scoansi acs on, first alt font
4260     //case 12: // scoansi acs on, |0x80, second alt font
4261     //...
4262     //case 19: // ninth alt font
4263     //case 20: // gothic
4264 root 1.163 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4265 root 1.107 rendset = 0, rendstyle = RS_Bold;
4266 pcg 1.93 break;
4267 root 1.163 case 22: // normal intensity
4268 pcg 1.36 rendset = 0, rendstyle = RS_Bold;
4269     break;
4270 root 1.163 case 23: // disable italic
4271     rendset = 0, rendstyle = RS_Italic;
4272     break;
4273 pcg 1.36 case 24:
4274     rendset = 0, rendstyle = RS_Uline;
4275     break;
4276     case 25:
4277     rendset = 0, rendstyle = RS_Blink;
4278     break;
4279 root 1.163 case 26: // variable spacing (iso 8613)
4280 root 1.145 rendset = 0, rendstyle = RS_Blink;
4281     break;
4282 pcg 1.36 case 27:
4283     rendset = 0, rendstyle = RS_RVid;
4284     break;
4285 root 1.107 //case 28: // visible. NYI
4286     //case 29: // not crossed-out
4287 pcg 1.36 }
4288 pcg 1.73
4289 pcg 1.36 if (rendset != -1)
4290     {
4291     scr_rendition (rendset, rendstyle);
4292 pcg 1.43 continue; /* for (;i;) */
4293 pcg 1.36 }
4294    
4295     switch (arg[i])
4296     {
4297     case 30:
4298     case 31: /* set fg color */
4299     case 32:
4300     case 33:
4301     case 34:
4302     case 35:
4303     case 36:
4304     case 37:
4305 pcg 1.73 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4306 pcg 1.36 break;
4307 root 1.163 case 38: // set fg color, ISO 8613-6
4308 pcg 1.36 if (nargs > i + 2 && arg[i + 1] == 5)
4309     {
4310 pcg 1.73 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4311 pcg 1.36 i += 2;
4312     }
4313     break;
4314     case 39: /* default fg */
4315     scr_color (Color_fg, Color_fg);
4316     break;
4317    
4318     case 40:
4319     case 41: /* set bg color */
4320     case 42:
4321     case 43:
4322     case 44:
4323     case 45:
4324     case 46:
4325     case 47:
4326 pcg 1.73 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4327 pcg 1.36 break;
4328 root 1.163 case 48: // set bg color, ISO 8613-6
4329 pcg 1.36 if (nargs > i + 2 && arg[i + 1] == 5)
4330     {
4331 pcg 1.73 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4332 pcg 1.36 i += 2;
4333     }
4334     break;
4335     case 49: /* default bg */
4336     scr_color (Color_bg, Color_bg);
4337     break;
4338 pcg 1.1
4339 root 1.163 //case 50: // not variable spacing
4340    
4341 pcg 1.1 #ifndef NO_BRIGHTCOLOR
4342 pcg 1.36 case 90:
4343     case 91: /* set bright fg color */
4344     case 92:
4345     case 93:
4346     case 94:
4347     case 95:
4348     case 96:
4349     case 97:
4350 root 1.163 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4351 pcg 1.36 break;
4352     case 100:
4353     case 101: /* set bright bg color */
4354     case 102:
4355     case 103:
4356     case 104:
4357     case 105:
4358     case 106:
4359     case 107:
4360 root 1.163 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4361 pcg 1.36 break;
4362 pcg 1.1 #endif
4363 pcg 1.36 }
4364 pcg 1.1 }
4365     }
4366     /*}}} */
4367    
4368 pcg 1.93 /*{{{ (do not) process Rob Nation's own graphics mode sequences */
4369 pcg 1.1 void
4370 pcg 1.34 rxvt_term::process_graphics ()
4371 pcg 1.1 {
4372 pcg 1.81 unicode_t ch, cmd = cmd_getc ();
4373 pcg 1.1
4374 pcg 1.36 if (cmd == 'Q')
4375     { /* query graphics */
4376 root 1.145 tt_printf ("\033G0\012"); /* no graphics */
4377 pcg 1.36 return;
4378     }
4379     /* swallow other graphics sequences until terminating ':' */
4380     do
4381     ch = cmd_getc ();
4382     while (ch != ':');
4383 pcg 1.1 }
4384     /*}}} */
4385    
4386     /* ------------------------------------------------------------------------- */
4387    
4388     /*
4389 pcg 1.43 * Send printf () formatted output to the command.
4390 pcg 1.1 * Only use for small amounts of data.
4391     */
4392     void
4393 pcg 1.10 rxvt_term::tt_printf (const char *fmt,...)
4394 pcg 1.1 {
4395 pcg 1.10 va_list arg_ptr;
4396     unsigned char buf[256];
4397 pcg 1.1
4398 pcg 1.10 va_start (arg_ptr, fmt);
4399     vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4400     va_end (arg_ptr);
4401 root 1.145 tt_write (buf, strlen (buf));
4402 pcg 1.1 }
4403    
4404     /* ---------------------------------------------------------------------- */
4405 pcg 1.10 /* Write data to the pty as typed by the user, pasted with the mouse,
4406 pcg 1.1 * or generated by us in response to a query ESC sequence.
4407     */
4408 root 1.177 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4409    
4410 pcg 1.1 void
4411 pcg 1.10 rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4412 pcg 1.1 {
4413 root 1.177 if (v_buflen == 0)
4414     {
4415     ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4416 pcg 1.10
4417 root 1.177 if ((unsigned int)written == len)
4418     return;
4419 pcg 1.34
4420 root 1.177 data += written;
4421     len -= written;
4422     }
4423 pcg 1.10
4424 root 1.177 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4425 pcg 1.10
4426 root 1.177 memcpy (v_buffer + v_buflen, data, len);
4427     v_buflen += len;
4428 pcg 1.10
4429 root 1.177 pty_ev.set (EVENT_READ | EVENT_WRITE);
4430     }
4431 pcg 1.10
4432 root 1.177 void rxvt_term::pty_write ()
4433     {
4434     int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4435 pcg 1.1
4436 root 1.177 if (written > 0)
4437 pcg 1.10 {
4438 root 1.177 v_buflen -= written;
4439 pcg 1.10
4440 root 1.177 if (v_buflen == 0)
4441 pcg 1.10 {
4442 root 1.177 free (v_buffer);
4443     v_buffer = 0;
4444     v_buflen = 0;
4445 pcg 1.10
4446 root 1.177 pty_ev.set (EVENT_READ);
4447 pcg 1.10 return;
4448     }
4449 root 1.177
4450     memmove (v_buffer, v_buffer + written, v_buflen);
4451 pcg 1.1 }
4452 root 1.177 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4453 root 1.213 pty_ev.set (EVENT_READ);
4454 pcg 1.1 }
4455 pcg 1.10
4456 pcg 1.1 /*----------------------- end-of-file (C source) -----------------------*/
4457