ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
Revision: 1.226
Committed: Sun Jan 1 15:03:49 2006 UTC (18 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-6_2
Changes since 1.225: +3 -1 lines
Log Message:
*** empty log message ***

File Contents

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