ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
Revision: 1.222
Committed: Sat Dec 31 19:35:56 2005 UTC (18 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.221: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

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