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