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