ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.208 by root, Sun Dec 18 00:59:42 2005 UTC vs.
Revision 1.385 by root, Mon Dec 24 06:51:37 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: command.C 2 * File: command.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 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> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2005 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com>
31 * 31 *
32 * This program is free software; you can redistribute it and/or modify 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 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 34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version. 35 * (at your option) any later version.
43 * along with this program; if not, write to the Free Software 43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/ 45 *----------------------------------------------------------------------*/
46 46
47/*{{{ includes: */ 47/*{{{ includes: */
48#include "../config.h" /* NECESSARY */ 48#include "../config.h"
49#include "rxvt.h" /* NECESSARY */ 49#include "rxvt.h"
50#include "rxvtperl.h"
50#include "version.h" 51#include "version.h"
51#include "command.h" 52#include "command.h"
52 53
53#ifdef KEYSYM_RESOURCE 54#ifdef KEYSYM_RESOURCE
54# include "keyboard.h" 55# include "keyboard.h"
55#endif 56#endif
56 57
57#include <csignal> 58#include <csignal>
58 59
60#if LINUX_YIELD_HACK
61# include <ctime>
62#endif
63
59/*----------------------------------------------------------------------*/ 64/*----------------------------------------------------------------------*/
60 65
61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 66#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
62
63// exception thrown when the command parser runs out of input data
64class out_of_input { } out_of_input;
65 67
66#if ENABLE_FRILLS || ISO_14755 68#if ENABLE_FRILLS || ISO_14755
67 69
68#define ISO_14755_STARTED 0x80000000UL 70#define ISO_14755_STARTED 0x80000000UL
69#define ISO_14755_51 0x40000000UL // basic (section 5.1) 71#define ISO_14755_51 0x40000000UL // basic (section 5.1)
93 XK_Shift_L, 0x21e7, 95 XK_Shift_L, 0x21e7,
94 XK_Shift_R, 0x21e7, 96 XK_Shift_R, 0x21e7,
95 97
96 XK_Shift_Lock, 0x21eb, 98 XK_Shift_Lock, 0x21eb,
97 XK_ISO_Lock, 0x21eb, 99 XK_ISO_Lock, 0x21eb,
98 XK_ISO_Lock, 0x21eb,
99 XK_Caps_Lock, 0x21ec, 100 XK_Caps_Lock, 0x21ec,
100 XK_Num_Lock, 0x21ed, 101 XK_Num_Lock, 0x21ed,
101 XK_ISO_Level3_Shift, 0x21ee, 102 XK_ISO_Level3_Shift, 0x21ee,
102 XK_ISO_Level3_Lock, 0x21ef, 103 XK_ISO_Level3_Lock, 0x21ef,
103 XK_ISO_Group_Lock, 0x21f0, 104 XK_ISO_Group_Lock, 0x21f0,
135rxvt_term::iso14755_54 (int x, int y) 136rxvt_term::iso14755_54 (int x, int y)
136{ 137{
137 x = Pixel2Col (x); 138 x = Pixel2Col (x);
138 y = Pixel2Row (y); 139 y = Pixel2Row (y);
139 140
140 if (x < 0 || x >= ncol 141 if (!IN_RANGE_EXC (x, 0, ncol)
141 || y < 0 || y >= nrow) 142 || !IN_RANGE_EXC (y, 0, nrow))
142 return; 143 return;
143 144
144 for (;;) 145 for (;;)
145 { 146 {
146 const line_t &l = save[y + saveLines - view_start]; 147 const line_t &l = ROW(y + view_start);
147 148
148 text_t t = l.t[x]; 149 text_t t = l.t[x];
149 150
150 if (t != NOCHAR || !x) 151 if (t != NOCHAR || !x)
151 { 152 {
152 iso14755_51 (l.t[x], l.r[x]); 153 iso14755_51 (l.t[x], l.r[x], x, y);
153 iso14755buf = ISO_14755_54; 154 iso14755buf = ISO_14755_54;
154 break; 155 break;
155 } 156 }
156 157
157 x--; 158 x--;
158 } 159 }
159
160} 160}
161#endif
162 161
163#if ENABLE_OVERLAY
164void 162void
165rxvt_term::iso14755_51 (unicode_t ch, rend_t r) 163rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
166{ 164{
167 rxvt_fontset *fs = FONTSET (r); 165 rxvt_fontset *fs = FONTSET (r);
168 rxvt_font *f = (*fs)[fs->find_font (ch)]; 166 rxvt_font *f = (*fs)[fs->find_font (ch)];
169 wchar_t *chr, *alloc, ch2, *fname; 167 wchar_t *chr, *alloc, ch2, *fname;
170 int len; 168 int len;
171 169
172 fname = rxvt_utf8towcs (f->name); 170 fname = rxvt_utf8towcs (f->name);
173 171
174#if ENABLE_COMBINING 172# if ENABLE_COMBINING
175 if (IS_COMPOSE (ch)) 173 if (IS_COMPOSE (ch))
176 { 174 {
177 len = rxvt_composite.expand (ch, 0); 175 len = rxvt_composite.expand (ch, 0);
178 alloc = chr = new wchar_t[len]; 176 alloc = chr = new wchar_t[len];
179 rxvt_composite.expand (ch, chr); 177 rxvt_composite.expand (ch, chr);
180 } 178 }
181 else 179 else
182#endif 180# endif
183 { 181 {
184 ch2 = ch; 182 ch2 = ch;
185 183
186 alloc = 0; 184 alloc = 0;
187 chr = &ch2; 185 chr = &ch2;
188 len = 1; 186 len = 1;
189 } 187 }
190 188
189 char attr[80]; // plenty
190
191 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
192 (int)r,
193 fgcolor_of (r), bgcolor_of (r),
194 r & RS_Bold ? " bold" : "",
195 r & RS_Italic ? " italic" : "",
196 r & RS_Blink ? " blink" : "",
197 r & RS_RVid ? " rvid" : "",
198 r & RS_Uline ? " uline" : "",
199 r & RS_Careful ? " careful" : "");
200
191 int width = wcswidth (fname, wcslen (fname)); 201 int width = wcswidth (fname, wcslen (fname));
192 202
193 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1); 203 max_it (width, 8+5); // for char + hex
204 max_it (width, strlen (attr));
205
206 if (y >= 0)
207 {
208 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
209 x = 0;
210 }
211
212 scr_overlay_new (x, y, width, len + 2);
194 213
195 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 214 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
196 215
197 for (int y = 0; y < len; y++) 216 for (int y = 0; y < len; y++)
198 { 217 {
201 ch = *chr++; 220 ch = *chr++;
202 221
203 sprintf (buf, "%8x", ch); 222 sprintf (buf, "%8x", ch);
204 scr_overlay_set (0, y, buf); 223 scr_overlay_set (0, y, buf);
205 scr_overlay_set (9, y, '='); 224 scr_overlay_set (9, y, '=');
206#if !UNICODE3 225# if !UNICODE3
207 if (ch >= 0x10000) 226 if (ch >= 0x10000)
208 ch = 0xfffd; 227 ch = 0xfffd;
209#endif 228# endif
210 scr_overlay_set (11, y, ch, r); 229 scr_overlay_set (11, y, ch, r);
230
231 if (WCWIDTH (ch) >= 2)
211 scr_overlay_set (12, y, NOCHAR, r); 232 scr_overlay_set (12, y, NOCHAR, r);
212 } 233 }
213 234
235// {
236// char buf[4+4+3+1];
237// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y);
238// scr_overlay_set (0, 0, buf);
239// }
240 scr_overlay_set (0, len , attr);
214 scr_overlay_set (0, len, fname); 241 scr_overlay_set (0, len + 1, fname);
215 242
216 free (fname); 243 free (fname);
217 244
218#if ENABLE_COMBINING 245# if ENABLE_COMBINING
219 if (alloc) 246 if (alloc)
220 delete [] alloc; 247 delete [] alloc;
221#endif 248# endif
222} 249}
223#endif 250#endif
224 251
225void 252void
226rxvt_term::commit_iso14755 () 253rxvt_term::commit_iso14755 ()
243 mb[0] = ch[0]; 270 mb[0] = ch[0];
244 len = 1; 271 len = 1;
245 } 272 }
246 273
247 if (len > 0) 274 if (len > 0)
248 tt_write ((unsigned char *)mb, len); 275 tt_write (mb, len);
249 else 276 else
250 scr_bell (); 277 scr_bell ();
251 } 278 }
252 279
253 iso14755buf = 0; 280 iso14755buf = 0;
270 297
271 return -1; 298 return -1;
272} 299}
273#endif 300#endif
274 301
275/*{{{ Convert the keypress event into a string */
276void 302void
277rxvt_term::lookup_key (XKeyEvent &ev) 303rxvt_term::key_press (XKeyEvent &ev)
278{ 304{
279 int ctrl, meta, shft, len; 305 int ctrl, meta, shft, len;
280 unsigned int newlen; 306 unsigned int newlen;
281 KeySym keysym; 307 KeySym keysym;
282#ifdef DEBUG_CMD
283 static int debug_key = 1; /* accessible by a debugger only */
284#endif
285 int valid_keysym; 308 int valid_keysym;
286 unsigned char kbuf[KBUFSZ]; 309 char kbuf[KBUFSZ];
310
311#if ISO_14755
312 if (iso14755buf & ISO_14755_52)
313 return;
314#endif
287 315
288 /* 316 /*
289 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 317 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
290 * escape sequence to toggle the Keypad. 318 * escape sequence to toggle the Keypad.
291 * 319 *
309 Status status_return; 337 Status status_return;
310 338
311#if 0 339#if 0
312#ifdef X_HAVE_UTF8_STRING 340#ifdef X_HAVE_UTF8_STRING
313 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 341 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
314 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 342 len = Xutf8LookupString (Input_Context, &ev, kbuf,
315 KBUFSZ, &keysym, &status_return); 343 KBUFSZ, &keysym, &status_return);
316 else 344 else
317#endif 345#endif
318#endif 346#endif
319 { 347 {
356 || status_return == XLookupBoth; 384 || status_return == XLookupBoth;
357 } 385 }
358 else 386 else
359#endif 387#endif
360 { 388 {
361 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 389 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
362 valid_keysym = keysym != NoSymbol; 390 valid_keysym = keysym != NoSymbol;
363 } 391 }
364 392
365 if (valid_keysym) 393 if (valid_keysym)
366 { 394 {
418 scr_move_to (0, 1); 446 scr_move_to (0, 1);
419 return; 447 return;
420 } 448 }
421 else if (keysym == XK_End) 449 else if (keysym == XK_End)
422 { 450 {
423 scr_move_to (1, 0); 451 scr_move_to (1, 1);
424 return; 452 return;
425 } 453 }
426 } 454 }
427#endif 455#endif
428 } 456 }
439 { 467 {
440 switch (keysym) 468 switch (keysym)
441 { 469 {
442 /* normal XTerm key bindings */ 470 /* normal XTerm key bindings */
443 case XK_Insert: /* Shift+Insert = paste mouse selection */ 471 case XK_Insert: /* Shift+Insert = paste mouse selection */
444 selection_request (ev.time, 0, 0); 472 selection_request (ev.time);
445 return; 473 return;
446#if TODO 474#if TODO
447 /* rxvt extras */ 475 /* rxvt extras */
448 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 476 case XK_KP_Add: /* Shift+KP_Add = bigger font */
449 change_font (FONT_UP); 477 change_font (FONT_UP);
468 { 496 {
469 commit_iso14755 (); 497 commit_iso14755 ();
470 iso14755buf = ISO_14755_51; 498 iso14755buf = ISO_14755_51;
471# if ISO_14755 499# if ISO_14755
472 iso14755_51 (0); 500 iso14755_51 (0);
501# endif
502 return;
503 }
504 else if (keysym == XK_BackSpace)
505 {
506 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
507# if ISO_14755
508 iso14755_51 (iso14755buf & ISO_14755_MASK);
473# endif 509# endif
474 return; 510 return;
475 } 511 }
476 else if ((hv = hex_keyval (ev)) >= 0) 512 else if ((hv = hex_keyval (ev)) >= 0)
477 { 513 {
482# endif 518# endif
483 return; 519 return;
484 } 520 }
485 else 521 else
486 { 522 {
487# if ENABLE_OVERLAY 523# if ISO_14755
488 scr_overlay_off (); 524 scr_overlay_off ();
489# endif 525# endif
490 iso14755buf = 0; 526 iso14755buf = 0;
491 } 527 }
492 } 528 }
493 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 529 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
494 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 530 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
495 if (!(iso14755buf & ISO_14755_STARTED)) 531 if (!(iso14755buf & ISO_14755_STARTED))
496 { 532 {
497 iso14755buf |= ISO_14755_STARTED; 533 iso14755buf |= ISO_14755_STARTED;
498# if ENABLE_OVERLAY 534# if ISO_14755
499 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 535 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
500 scr_overlay_set (0, 0, "ISO 14755 mode"); 536 scr_overlay_set (0, 0, "ISO 14755 mode");
501# endif 537# endif
502 } 538 }
503#endif 539#endif
504 540
505#ifdef PRINTPIPE 541#ifdef PRINTPIPE
506 if (keysym == XK_Print) 542 if (keysym == XK_Print)
507 { 543 {
508 scr_printscreen (ctrl | shft); 544 scr_printscreen (ctrl | shft);
509 return; 545 return;
511#endif 547#endif
512 548
513 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 549 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
514 { 550 {
515 { 551 {
552 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
516 newlen = 1; 553 newlen = 1;
554#ifdef XK_KP_Home
555 static const KeySym keypadtrans[] = {
556 XK_KP_7, // XK_KP_Home
557 XK_KP_4, // XK_KP_Left
558 XK_KP_8, // XK_KP_Up
559 XK_KP_6, // XK_KP_Right
560 XK_KP_2, // XK_KP_Down
561#ifndef UNSHIFTED_SCROLLKEYS
562 XK_KP_9, // XK_KP_Prior
563 XK_KP_3, // XK_KP_Next
564#else
565 XK_Prior,
566 XK_Next,
567#endif
568 XK_KP_1, // XK_KP_End
569 XK_KP_5, // XK_KP_Begin
570 };
571
572 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin))
573 {
574 unsigned int index = keysym - XK_KP_Home;
575 keysym = kp ? keypadtrans[index] : XK_Home + index;
576 }
577 else if (keysym == XK_KP_Insert)
578 keysym = kp ? XK_KP_0 : XK_Insert;
579#ifndef NO_DELETE_KEY
580 else if (keysym == XK_KP_Delete)
581 keysym = kp ? XK_KP_Decimal : XK_Delete;
582#endif
583#endif
517 switch (keysym) 584 switch (keysym)
518 { 585 {
519#ifndef NO_BACKSPACE_KEY 586#ifndef NO_BACKSPACE_KEY
520 case XK_BackSpace: 587 case XK_BackSpace:
521 if (priv_modes & PrivMode_HaveBackSpace) 588 if (priv_modes & PrivMode_HaveBackSpace)
523 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) 590 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
524 ^ !!ctrl) ? '\b' : '\177'; 591 ^ !!ctrl) ? '\b' : '\177';
525 kbuf[1] = '\0'; 592 kbuf[1] = '\0';
526 } 593 }
527 else 594 else
528 strcpy (kbuf, key_backspace); 595 strcpy (kbuf, rs[Rs_backspace_key]);
529 break; 596 break;
530#endif 597#endif
531#ifndef NO_DELETE_KEY 598#ifndef NO_DELETE_KEY
532# ifdef XK_KP_Prior
533 case XK_KP_Delete:
534 /* allow shift to override */
535 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
536 {
537 strcpy (kbuf, "\033On");
538 break;
539 }
540 /* FALLTHROUGH */
541# endif
542 case XK_Delete: 599 case XK_Delete:
543 strcpy (kbuf, key_delete); 600 strcpy (kbuf, rs[Rs_delete_key]);
544 break; 601 break;
545#endif 602#endif
546 case XK_Tab: 603 case XK_Tab:
547 if (shft) 604 if (shft)
548 strcpy (kbuf, "\033[Z"); 605 strcpy (kbuf, "\033[Z");
558#endif 615#endif
559 newlen = 0; 616 newlen = 0;
560 } 617 }
561 break; 618 break;
562 619
563#ifdef XK_KP_Left
564 case XK_KP_Up: /* \033Ox or standard */
565 case XK_KP_Down: /* \033Or or standard */
566 case XK_KP_Right: /* \033Ov or standard */
567 case XK_KP_Left: /* \033Ot or standard */
568 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
569 {
570 strcpy (kbuf, "\033OZ");
571 kbuf[2] = "txvr"[keysym - XK_KP_Left];
572 break;
573 }
574 else
575 /* translate to std. cursor key */
576 keysym = XK_Left + (keysym - XK_KP_Left);
577 /* FALLTHROUGH */
578#endif
579 case XK_Up: /* "\033[A" */ 620 case XK_Up: /* "\033[A" */
580 case XK_Down: /* "\033[B" */ 621 case XK_Down: /* "\033[B" */
581 case XK_Right: /* "\033[C" */ 622 case XK_Right: /* "\033[C" */
582 case XK_Left: /* "\033[D" */ 623 case XK_Left: /* "\033[D" */
583 strcpy (kbuf, "\033[Z"); 624 strcpy (kbuf, "\033[Z");
593 else if (priv_modes & PrivMode_aplCUR) 634 else if (priv_modes & PrivMode_aplCUR)
594 kbuf[1] = 'O'; 635 kbuf[1] = 'O';
595 break; 636 break;
596 637
597#ifndef UNSHIFTED_SCROLLKEYS 638#ifndef UNSHIFTED_SCROLLKEYS
598# ifdef XK_KP_Prior
599 case XK_KP_Prior:
600 /* allow shift to override */
601 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
602 {
603 strcpy (kbuf, "\033Oy");
604 break;
605 }
606 /* FALLTHROUGH */
607# endif
608 case XK_Prior: 639 case XK_Prior:
609 strcpy (kbuf, "\033[5~"); 640 strcpy (kbuf, "\033[5~");
610 break; 641 break;
611# ifdef XK_KP_Next
612 case XK_KP_Next:
613 /* allow shift to override */
614 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
615 {
616 strcpy (kbuf, "\033Os");
617 break;
618 }
619 /* FALLTHROUGH */
620# endif
621 case XK_Next: 642 case XK_Next:
622 strcpy (kbuf, "\033[6~"); 643 strcpy (kbuf, "\033[6~");
623 break; 644 break;
624#endif 645#endif
625 case XK_KP_Enter: 646 case XK_KP_Enter:
626 /* allow shift to override */ 647 /* allow shift to override */
627 if ((priv_modes & PrivMode_aplKP) ? !shft : shft) 648 if (kp)
628 { 649 {
629 strcpy (kbuf, "\033OM"); 650 strcpy (kbuf, "\033OM");
630 break; 651 break;
631 } 652 }
632 653
644 kbuf[0] = '\015'; 665 kbuf[0] = '\015';
645 kbuf[1] = '\0'; 666 kbuf[1] = '\0';
646 } 667 }
647 break; 668 break;
648 669
649#ifdef XK_KP_Begin
650 case XK_KP_Begin:
651 strcpy (kbuf, "\033Ou");
652 break;
653
654#endif
655 case XK_KP_F1: /* "\033OP" */ 670 case XK_KP_F1: /* "\033OP" */
656 case XK_KP_F2: /* "\033OQ" */ 671 case XK_KP_F2: /* "\033OQ" */
657 case XK_KP_F3: /* "\033OR" */ 672 case XK_KP_F3: /* "\033OR" */
658 case XK_KP_F4: /* "\033OS" */ 673 case XK_KP_F4: /* "\033OS" */
659 strcpy (kbuf, "\033OP"); 674 strcpy (kbuf, "\033OP");
675 case XK_KP_6: /* "\033Ov" : "6" */ 690 case XK_KP_6: /* "\033Ov" : "6" */
676 case XK_KP_7: /* "\033Ow" : "7" */ 691 case XK_KP_7: /* "\033Ow" : "7" */
677 case XK_KP_8: /* "\033Ox" : "8" */ 692 case XK_KP_8: /* "\033Ox" : "8" */
678 case XK_KP_9: /* "\033Oy" : "9" */ 693 case XK_KP_9: /* "\033Oy" : "9" */
679 /* allow shift to override */ 694 /* allow shift to override */
680 if ((priv_modes & PrivMode_aplKP) ? !shft : shft) 695 if (kp)
681 { 696 {
682 strcpy (kbuf, "\033Oj"); 697 strcpy (kbuf, "\033Oj");
683 kbuf[2] += (keysym - XK_KP_Multiply); 698 kbuf[2] += (keysym - XK_KP_Multiply);
684 } 699 }
685 else 700 else
691 706
692 case XK_Find: 707 case XK_Find:
693 strcpy (kbuf, "\033[1~"); 708 strcpy (kbuf, "\033[1~");
694 break; 709 break;
695 710
696#ifdef XK_KP_End
697 case XK_KP_Insert:
698 /* allow shift to override */
699 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
700 {
701 strcpy (kbuf, "\033Op");
702 break;
703 }
704 /* FALLTHROUGH */
705#endif
706 case XK_Insert: 711 case XK_Insert:
707 strcpy (kbuf, "\033[2~"); 712 strcpy (kbuf, "\033[2~");
708 break; 713 break;
709#ifdef DXK_Remove /* support for DEC remove like key */ 714#ifdef DXK_Remove /* support for DEC remove like key */
710 case DXK_Remove: 715 case DXK_Remove:
714 strcpy (kbuf, "\033[3~"); 719 strcpy (kbuf, "\033[3~");
715 break; 720 break;
716 case XK_Select: 721 case XK_Select:
717 strcpy (kbuf, "\033[4~"); 722 strcpy (kbuf, "\033[4~");
718 break; 723 break;
719#ifdef XK_KP_End
720 case XK_KP_End:
721 /* allow shift to override */
722 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
723 {
724 strcpy (kbuf, "\033Oq");
725 break;
726 }
727 /* FALLTHROUGH */
728#endif
729 case XK_End: 724 case XK_End:
730 strcpy (kbuf, KS_END); 725 strcpy (kbuf, KS_END);
731 break; 726 break;
732#ifdef XK_KP_Home
733 case XK_KP_Home:
734 /* allow shift to override */
735 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
736 {
737 strcpy (kbuf, "\033Ow");
738 break;
739 }
740 /* FALLTHROUGH */
741#endif
742 case XK_Home: 727 case XK_Home:
743 strcpy (kbuf, KS_HOME); 728 strcpy (kbuf, KS_HOME);
744 break; 729 break;
745 730
746#define FKEY(n, fkey) \ 731#define FKEY(n, fkey) \
830 { 815 {
831#ifdef META8_OPTION 816#ifdef META8_OPTION
832 /* set 8-bit on */ 817 /* set 8-bit on */
833 if (meta && (meta_char == 0x80)) 818 if (meta && (meta_char == 0x80))
834 { 819 {
835 unsigned char *ch; 820 char *ch;
836 821
837 for (ch = kbuf; ch < kbuf + len; ch++) 822 for (ch = kbuf; ch < kbuf + len; ch++)
838 *ch |= 0x80; 823 *ch |= 0x80;
839 824
840 meta = 0; 825 meta = 0;
842#endif 827#endif
843 /* nil */ ; 828 /* nil */ ;
844 } 829 }
845 } 830 }
846 831
832 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
833 return;
834
847 if (len <= 0) 835 if (len <= 0)
848 return; /* not mapped */ 836 return; /* not mapped */
849 837
850 if (options & Opt_scrollTtyKeypress) 838 if (option (Opt_scrollTtyKeypress))
851 if (view_start) 839 if (view_start)
852 { 840 {
853 view_start = 0; 841 view_start = 0;
854 want_refresh = 1; 842 want_refresh = 1;
855 } 843 }
873#ifdef META8_OPTION 861#ifdef META8_OPTION
874 && meta_char == C0_ESC 862 && meta_char == C0_ESC
875#endif 863#endif
876 ) 864 )
877 { 865 {
878 const unsigned char ch = C0_ESC; 866 const char ch = C0_ESC;
879 tt_write (&ch, 1); 867 tt_write (&ch, 1);
880 } 868 }
881 869
882#if defined(DEBUG_CMD)
883 /* Display keyboard buffer contents */
884 unsigned char *p;
885 int i;
886
887 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
888 for (i = 0, p = kbuf; i < len; i++, p++)
889 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
890 fprintf (stderr, "'\n");
891#endif /* DEBUG_CMD */
892 tt_write (kbuf, (unsigned int)len); 870 tt_write (kbuf, (unsigned int)len);
893} 871}
894/*}}} */
895 872
873void
874rxvt_term::key_release (XKeyEvent &ev)
875{
876#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
877 KeySym keysym;
878
879 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
880#endif
881
882#if ENABLE_FRILLS || ISO_14755
883 // ISO 14755 support
884 if (iso14755buf)
885 if (iso14755buf & ISO_14755_52)
886 {
887# if ISO_14755
888 scr_overlay_off ();
889# endif
890# if ISO_14755
891 // iso14755 part 5.2 handling: release time
892 // first: controls
893 if ((ev.state & ControlMask)
894 && ((keysym >= 0x40 && keysym <= 0x5f)
895 || (keysym >= 0x61 && keysym <= 0x7f)))
896 {
897 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
898 commit_iso14755 ();
899
900 return;
901 }
902
903 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
904 if (i[0] == keysym)
905 {
906 iso14755buf = ISO_14755_51 | i[1];
907 commit_iso14755 ();
908
909 return;
910 }
911
912 scr_bell ();
913# endif
914 iso14755buf = 0;
915
916 return;
917 }
918 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
919 {
920# if ISO_14755
921 scr_overlay_off ();
922# endif
923 if (iso14755buf & ISO_14755_51)
924 commit_iso14755 ();
925#if ISO_14755
926 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
927 {
928 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
929
930 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
931 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
932 }
933# endif
934 else
935 iso14755buf = 0;
936 }
937#endif
938
939 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
940 return;
941
942#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
943 if (!(ev.state & ControlMask))
944 slip_wheel_ev.stop ();
945 else if (keysym == XK_Control_L || keysym == XK_Control_R)
946 mouse_slip_wheel_speed = 0;
947#endif
948}
949
896#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 950#if defined (KEYSYM_RESOURCE)
897/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
898/* attempt to `write' count to the input buffer */
899unsigned int 951unsigned int
900rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 952rxvt_term::cmd_write (const char *str, unsigned int count)
901{ 953{
902 unsigned int n, s; 954 unsigned int n, s;
903 955
904 n = cmdbuf_ptr - cmdbuf_base; 956 n = cmdbuf_ptr - cmdbuf_base;
905 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 957 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
931void 983void
932rxvt_term::flush () 984rxvt_term::flush ()
933{ 985{
934 flush_ev.stop (); 986 flush_ev.stop ();
935 987
936#ifdef TRANSPARENT 988#ifdef HAVE_BG_PIXMAP
937 if (want_full_refresh) 989 if (bgPixmap.check_clearChanged ())
938 { 990 {
939 want_full_refresh = 0; 991// scr_clear (true); This needs to be researched further!
940 scr_clear ();
941 scr_touch (false); 992 scr_touch (false);
942 } 993 }
943#endif 994#endif
944 995
945 if (want_refresh) 996 if (want_refresh)
946 { 997 {
998 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
999 {
1000 int row = view_start;
1001 int end_row = row + nrow;
1002
1003 while (row > top_row && ROW (row - 1).is_longer ())
1004 --row;
1005
1006 do
1007 {
1008 int start_row = row;
1009 line_t *l;
1010
1011 do
1012 {
1013 l = &ROW (row++);
1014
1015 if (!(l->f & LINE_FILTERED))
1016 {
1017 // line not filtered, mark it as filtered
1018 l->f |= LINE_FILTERED;
1019 while (l->is_longer ())
1020 {
1021 l = &ROW (row++);
1022 l->f |= LINE_FILTERED;
1023 }
1024
1025 // and filter it
1026 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
1027
1028 break;
1029 }
1030 }
1031 while (l->is_longer () && row < end_row);
1032 }
1033 while (row < end_row);
1034 }
1035
947 scr_refresh (refresh_type); 1036 scr_refresh ();
948 scrollbar_show (1); 1037 scrollbar_show (1);
949#ifdef USE_XIM 1038#ifdef USE_XIM
950 IMSendSpot (); 1039 IMSendSpot ();
951#endif 1040#endif
952 } 1041 }
953 1042
954 display->flush (); 1043 display->flush ();
955} 1044}
956 1045
1046/* checks wether a refresh is requested and starts the refresh timer */
957void 1047void
958rxvt_term::check_cb (check_watcher &w) 1048rxvt_term::refresh_check ()
959{ 1049{
960 SET_R (this); 1050 if (want_refresh && !flush_ev.is_active ())
961 SET_LOCALE (locale); 1051 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
962 1052
963 display->flush (); 1053 display->flush ();
964
965 if (want_refresh && !flush_ev.active)
966 flush_ev.start (NOW + 0.01);
967} 1054}
968 1055
969void 1056void
970rxvt_term::flush_cb (time_watcher &w) 1057rxvt_term::flush_cb (ev::timer &w, int revents)
971{ 1058{
972 SET_R (this); 1059 make_current ();
973 SET_LOCALE (locale);
974 1060
975 refresh_limit = 1;
976 refresh_count = 0; 1061 refresh_count = 0;
977 flush (); 1062 flush ();
978} 1063}
979 1064
980#ifdef CURSOR_BLINK 1065#ifdef CURSOR_BLINK
981void 1066void
982rxvt_term::cursor_blink_cb (time_watcher &w) 1067rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
983{ 1068{
984 hidden_cursor = !hidden_cursor; 1069 hidden_cursor = !hidden_cursor;
985 want_refresh = 1; 1070 want_refresh = 1;
986 1071 refresh_check ();
987 w.start (w.at + BLINK_INTERVAL);
988} 1072}
989#endif 1073#endif
990 1074
991#ifdef TEXT_BLINK 1075#ifdef TEXT_BLINK
992void 1076void
993rxvt_term::text_blink_cb (time_watcher &w) 1077rxvt_term::text_blink_cb (ev::timer &w, int revents)
994{ 1078{
995 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1079 if (scr_refresh_rend (RS_Blink, RS_Blink))
996 { 1080 {
997 hidden_text = !hidden_text; 1081 hidden_text = !hidden_text;
998 want_refresh = 1; 1082 want_refresh = 1;
999 w.start (w.at + TEXT_BLINK_INTERVAL); 1083 refresh_check ();
1000 } 1084 }
1085 else
1086 w.stop ();
1001} 1087}
1002#endif 1088#endif
1003 1089
1004#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1090#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1005void 1091void
1006rxvt_term::cont_scroll_cb (time_watcher &w) 1092rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1007{ 1093{
1008 if ((scrollbar_isUp() || scrollbar_isDn()) && 1094 if ((scrollbar_isUp () || scrollbar_isDn ())
1009 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1095 && scr_page (scrollbar_isUp () ? UP : DN, 1))
1010 { 1096 {
1011 refresh_type |= SMOOTH_REFRESH;
1012 want_refresh = 1; 1097 want_refresh = 1;
1013 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1098 refresh_check ();
1014 } 1099 }
1100 else
1101 w.stop ();
1015} 1102}
1016#endif 1103#endif
1017 1104
1018#ifdef SELECTION_SCROLLING 1105#ifdef SELECTION_SCROLLING
1019void 1106void
1020rxvt_term::sel_scroll_cb (time_watcher &w) 1107rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1021{ 1108{
1022 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1109 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1023 { 1110 {
1024 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1111 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1025 refresh_type |= SMOOTH_REFRESH;
1026 want_refresh = 1; 1112 want_refresh = 1;
1027 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1113 refresh_check ();
1028 } 1114 }
1115 else
1116 w.stop ();
1029} 1117}
1030#endif 1118#endif
1031 1119
1032#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1120#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1033void 1121void
1034rxvt_term::slip_wheel_cb (time_watcher &w) 1122rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1035{ 1123{
1036 if (mouse_slip_wheel_speed == 0 1124 if (scr_changeview (view_start - mouse_slip_wheel_speed))
1037 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1038 : scr_page (UP, mouse_slip_wheel_speed))
1039 { 1125 {
1040 if (view_start == nscrolled ||
1041 view_start == 0)
1042 mouse_slip_wheel_speed = 0;
1043
1044 refresh_type |= SMOOTH_REFRESH;
1045 want_refresh = 1; 1126 want_refresh = 1;
1046 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1127 refresh_check ();
1128 }
1129
1130 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1047 } 1131 {
1132 mouse_slip_wheel_speed = 0;
1133 w.stop ();
1134 }
1048} 1135}
1136#endif
1137
1138#if LINUX_YIELD_HACK
1139static struct event_handler
1140{
1141 ev::prepare yield_ev;
1142
1143 void yield_cb (ev::prepare &w, int revents)
1144 {
1145 // this should really be sched_yield(), but the linux guys thought
1146 // that giving a process calling sched_yield () less cpu time than
1147 // ones with high nice levels is a useful thing to do. It surely is is
1148 // allowed by the sus... as is returning ENOSYS.
1149
1150 struct timespec ts = { 0, 0 };
1151 nanosleep (&ts, 0);
1152
1153 w.stop ();
1154 }
1155
1156 event_handler ()
1157 : yield_ev (this, &event_handler::yield_cb)
1158 {
1159 }
1160} event_handler;
1049#endif 1161#endif
1050 1162
1051bool 1163bool
1052rxvt_term::pty_fill () 1164rxvt_term::pty_fill ()
1053{ 1165{
1054 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1166 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1055 1167
1056 if (CBUFSIZ == n) 1168 if (CBUFSIZ == n)
1057 { 1169 {
1058 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1170 rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n");
1059 n = 0; 1171 n = 0;
1060 } 1172 }
1061 1173
1062 memmove (cmdbuf_base, cmdbuf_ptr, n); 1174 memmove (cmdbuf_base, cmdbuf_ptr, n);
1063 cmdbuf_ptr = cmdbuf_base; 1175 cmdbuf_ptr = cmdbuf_base;
1064 cmdbuf_endp = cmdbuf_ptr + n; 1176 cmdbuf_endp = cmdbuf_ptr + n;
1065 1177
1066 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1178 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1067 1179
1068 if (n > 0) 1180 if (r > 0)
1069 { 1181 {
1070 cmdbuf_endp += n; 1182 cmdbuf_endp += r;
1071 return true; 1183 return true;
1072 } 1184 }
1073 else if (n < 0 && errno != EAGAIN) 1185 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1186 {
1187#if LINUX_YIELD_HACK
1188 if (display->is_local)
1189 event_handler.yield_ev.start ();
1190#endif
1191 }
1192 else
1193 {
1194 pty_ev.stop ();
1195
1196 if (!option (Opt_hold))
1074 destroy (); 1197 destroy ();
1075 1198 }
1199
1076 return false; 1200 return false;
1077} 1201}
1078 1202
1079void 1203void
1080rxvt_term::pty_cb (io_watcher &w, short revents) 1204rxvt_term::pty_cb (ev::io &w, int revents)
1081{ 1205{
1082 SET_R (this); 1206 make_current ();
1083 SET_LOCALE (locale);
1084 1207
1085 if (revents & EVENT_READ) 1208 if (revents & ev::READ)
1086 // loop, but don't allow a single term to monopolize us 1209 // loop, but don't allow a single term to monopolize us
1087 while (pty_fill ()) 1210 while (pty_fill ())
1088 if (cmd_parse ()) 1211 if (cmd_parse ())
1089 break; 1212 break;
1090 1213
1091 if (revents & EVENT_WRITE) 1214 if (revents & ev::WRITE)
1092 pty_write (); 1215 pty_write ();
1216
1217 refresh_check ();
1093} 1218}
1094 1219
1095void 1220void
1096rxvt_term::pointer_unblank () 1221rxvt_term::pointer_unblank ()
1097{ 1222{
1098 XDefineCursor (display->display, vt, TermWin_cursor); 1223 XDefineCursor (dpy, vt, TermWin_cursor);
1099 recolour_cursor (); 1224 recolour_cursor ();
1100 1225
1101#ifdef POINTER_BLANK 1226#ifdef POINTER_BLANK
1102 hidden_pointer = 0; 1227 hidden_pointer = 0;
1103 1228
1104 if (options & Opt_pointerBlank) 1229 if (option (Opt_pointerBlank))
1105 pointer_ev.start (NOW + pointerBlankDelay); 1230 pointer_ev.start (pointerBlankDelay);
1106#endif 1231#endif
1107} 1232}
1108 1233
1109#ifdef POINTER_BLANK 1234#ifdef POINTER_BLANK
1110void 1235void
1111rxvt_term::pointer_blank () 1236rxvt_term::pointer_blank ()
1112{ 1237{
1113 if (! (options & Opt_pointerBlank)) 1238 if (!option (Opt_pointerBlank))
1114 return; 1239 return;
1115 1240
1116 XDefineCursor (display->display, vt, display->blank_cursor); 1241 XDefineCursor (dpy, vt, display->blank_cursor);
1117 XFlush (display->display); 1242 XFlush (dpy);
1118 1243
1119 hidden_pointer = 1; 1244 hidden_pointer = 1;
1120} 1245}
1121 1246
1122void 1247void
1123rxvt_term::pointer_cb (time_watcher &w) 1248rxvt_term::pointer_cb (ev::timer &w, int revents)
1124{ 1249{
1125 SET_R (this); 1250 make_current ();
1126 SET_LOCALE (locale);
1127 1251
1128 pointer_blank (); 1252 pointer_blank ();
1129} 1253}
1130#endif 1254#endif
1131 1255
1132void 1256void
1133rxvt_term::mouse_report (XButtonEvent &ev) 1257rxvt_term::mouse_report (XButtonEvent &ev)
1134{ 1258{
1135 int button_number, key_state = 0; 1259 int button_number, key_state = 0;
1136 int x, y; 1260 int x, y;
1261 int code = 32;
1137 1262
1138 x = ev.x; 1263 x = Pixel2Col (ev.x);
1139 y = ev.y; 1264 y = Pixel2Row (ev.y);
1140 pixel_position (&x, &y); 1265 if (ev.type == MotionNotify)
1266 {
1267 if (x == mouse_row && y == mouse_col)
1268 return;
1269 mouse_row = x;
1270 mouse_col = y;
1271 code += 32;
1272 }
1141 1273
1142 if (MEvent.button == AnyButton) 1274 if (MEvent.button == AnyButton)
1143 button_number = 3; 1275 button_number = 3;
1144 else 1276 else
1145 { 1277 {
1191 x + 1, 1323 x + 1,
1192 y + 1); 1324 y + 1);
1193#endif 1325#endif
1194 1326
1195 tt_printf ("\033[M%c%c%c", 1327 tt_printf ("\033[M%c%c%c",
1196 (32 + button_number + key_state), 1328 (code + button_number + key_state),
1197 (32 + x + 1), 1329 (32 + x + 1),
1198 (32 + y + 1)); 1330 (32 + y + 1));
1199} 1331}
1200
1201#ifdef USING_W11LIB
1202void
1203rxvt_W11_process_x_event (XEvent *ev)
1204{
1205 rxvt_t *r = rxvt_get_r ();
1206
1207 x_cb (*ev);
1208}
1209#endif
1210 1332
1211/*{{{ process an X event */ 1333/*{{{ process an X event */
1212void 1334void
1213rxvt_term::x_cb (XEvent &ev) 1335rxvt_term::x_cb (XEvent &ev)
1214{ 1336{
1215 dDisp; 1337 make_current ();
1216 1338
1217 SET_R (this); 1339 dLocal (Display *, dpy);
1218 SET_LOCALE (locale);
1219 1340
1220#if defined(CURSOR_BLINK) 1341 if (ev.xany.window == vt
1221 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1342 && SHOULD_INVOKE (HOOK_X_EVENT)
1222 { 1343 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1223 if (hidden_cursor) 1344 return;
1224 {
1225 hidden_cursor = 0;
1226 want_refresh = 1;
1227 }
1228 1345
1229 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1346 // for XQueryPointer
1230 }
1231#endif
1232
1233#if defined(POINTER_BLANK)
1234 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1235 {
1236 if (ev.type == MotionNotify
1237 || ev.type == ButtonPress
1238 || ev.type == ButtonRelease)
1239 if (hidden_pointer)
1240 pointer_unblank ();
1241
1242 if (ev.type == KeyPress && hidden_pointer == 0)
1243 pointer_blank ();
1244 }
1245#endif
1246
1247 Window unused_root, unused_child; 1347 Window unused_root, unused_child;
1248 int unused_root_x, unused_root_y; 1348 int unused_root_x, unused_root_y;
1249 unsigned int unused_mask; 1349 unsigned int unused_mask;
1250 1350
1251 switch (ev.type) 1351 switch (ev.type)
1252 { 1352 {
1253 case KeyPress: 1353 case KeyPress:
1254#if ISO_14755 1354 key_press (ev.xkey);
1255 if (!(iso14755buf & ISO_14755_52))
1256#endif
1257 lookup_key (ev.xkey);
1258
1259 break; 1355 break;
1260 1356
1261 case KeyRelease: 1357 case KeyRelease:
1262 { 1358 key_release (ev.xkey);
1263#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1264 KeySym ks;
1265
1266 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1267#endif
1268
1269#if ENABLE_FRILLS || ISO_14755
1270 // ISO 14755 support
1271 if (iso14755buf)
1272 if (iso14755buf & ISO_14755_52)
1273 {
1274# if ENABLE_OVERLAY
1275 scr_overlay_off ();
1276# endif
1277# if ISO_14755
1278 // iso14755 part 5.2 handling: release time
1279 // first: controls
1280 if ((ev.xkey.state & ControlMask)
1281 && ((ks >= 0x40 && ks <= 0x5f)
1282 || (ks >= 0x61 && ks <= 0x7f)))
1283 {
1284 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1285 commit_iso14755 ();
1286 return; // case-break;
1287 }
1288
1289 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1290 if (i[0] == ks)
1291 {
1292 iso14755buf = ISO_14755_51 | i[1];
1293 commit_iso14755 ();
1294 return; // case-break;
1295 }
1296
1297 scr_bell ();
1298# endif
1299 iso14755buf = 0;
1300 break;
1301 }
1302 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1303 {
1304# if ENABLE_OVERLAY
1305 scr_overlay_off ();
1306# endif
1307 if (iso14755buf & ISO_14755_51)
1308 commit_iso14755 ();
1309#if ISO_14755
1310 else if (iso14755buf & ISO_14755_STARTED)
1311 {
1312 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1313
1314 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1315 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1316 }
1317# endif
1318 else
1319 iso14755buf = 0;
1320 }
1321#endif
1322
1323#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1324 if (!(ev.xkey.state & ControlMask))
1325 slip_wheel_ev.stop ();
1326 else if (ks == XK_Control_L || ks == XK_Control_R)
1327 mouse_slip_wheel_speed = 0;
1328#endif
1329 break; 1359 break;
1330 }
1331 1360
1332 case ButtonPress: 1361 case ButtonPress:
1333 button_press (ev.xbutton); 1362 button_press (ev.xbutton);
1334 break; 1363 break;
1335 1364
1337 button_release (ev.xbutton); 1366 button_release (ev.xbutton);
1338 break; 1367 break;
1339 1368
1340 case ClientMessage: 1369 case ClientMessage:
1341 if (ev.xclient.format == 32 1370 if (ev.xclient.format == 32
1342 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) 1371 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1343 { 1372 {
1373 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1374 {
1375 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1376 {
1344 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1377 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1378 {
1379 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1345 destroy (); 1380 destroy ();
1381 }
1346#if ENABLE_EWMH 1382#if ENABLE_EWMH
1347 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1383 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1348 XSendEvent (disp, ev.xclient.window = display->root, 1384 XSendEvent (dpy, ev.xclient.window = display->root,
1349 False, SubstructureRedirectMask | SubstructureNotifyMask, 1385 False, SubstructureRedirectMask | SubstructureNotifyMask,
1350 &ev); 1386 &ev);
1387#endif
1388 }
1389 }
1390#if ENABLE_XEMBED
1391 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1392 {
1393 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1394 focus_in ();
1395 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1396 focus_out ();
1397 }
1351#endif 1398#endif
1352 } 1399 }
1353#if ENABLE_XEMBED
1354 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1355 {
1356 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1357 focus_in ();
1358 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1359 focus_out ();
1360 }
1361#endif
1362#ifdef OFFIX_DND
1363 /* OffiX Dnd (drag 'n' drop) protocol */
1364 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1365 && (ev.xclient.data.l[0] == DndFile
1366 || ev.xclient.data.l[0] == DndDir
1367 || ev.xclient.data.l[0] == DndLink))
1368 {
1369 /* Get Dnd data */
1370 Atom ActualType;
1371 int ActualFormat;
1372 unsigned char *data;
1373 unsigned long Size, RemainingBytes;
1374
1375 XGetWindowProperty (disp, display->root,
1376 xa[XA_DNDSELECTION],
1377 0L, 1000000L,
1378 False, AnyPropertyType,
1379 &ActualType, &ActualFormat,
1380 &Size, &RemainingBytes,
1381 &data);
1382 set_string_property (XA_CUT_BUFFER0, data);
1383 XFree (data);
1384 selection_paste (display->root, XA_CUT_BUFFER0, true);
1385 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1386 }
1387#endif /* OFFIX_DND */
1388 break;
1389
1390 case MappingNotify:
1391 XRefreshKeyboardMapping (&ev.xmapping);
1392 break; 1400 break;
1393 1401
1394 /* 1402 /*
1395 * XXX: this is not the _current_ arrangement 1403 * XXX: this is not the _current_ arrangement
1396 * Here's my conclusion: 1404 * Here's my conclusion:
1415 break; 1423 break;
1416 } 1424 }
1417 break; 1425 break;
1418 1426
1419 case FocusIn: 1427 case FocusIn:
1428 if (ev.xfocus.detail != NotifyInferior
1429 && ev.xfocus.detail != NotifyPointer
1430 && ev.xfocus.mode != NotifyGrab)
1420 focus_in (); 1431 focus_in ();
1421 break; 1432 break;
1422 1433
1423 case FocusOut: 1434 case FocusOut:
1435 if (ev.xfocus.detail != NotifyInferior
1436 && ev.xfocus.detail != NotifyPointer
1437 && ev.xfocus.mode != NotifyGrab)
1424 focus_out (); 1438 focus_out ();
1425 break; 1439 break;
1426 1440
1427 case ConfigureNotify: 1441 case ConfigureNotify:
1442 /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1443 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1444 szHint.width, szHint.height); */
1428 if (ev.xconfigure.window == parent[0]) 1445 if (ev.xconfigure.window == parent[0])
1429 { 1446 {
1430 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)) 1447 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1431 ; 1448 ;
1432 1449
1433 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) 1450 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1434 { 1451 {
1435 seen_resize = 1; 1452 seen_resize = 1;
1436 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1453 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1437 } 1454 }
1438 1455 else
1439#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1456 {
1440 if (options & Opt_transparent) 1457#ifdef HAVE_BG_PIXMAP
1441 check_our_parents (); 1458 if (bgPixmap.window_position_sensitive ())
1459 update_background ();
1442#endif 1460#endif
1461 }
1462
1463 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1443 } 1464 }
1444 break; 1465 break;
1445 1466
1446 case PropertyNotify: 1467 case PropertyNotify:
1468 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1447 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1469 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1448 && ev.xproperty.state == PropertyNewValue) 1470 && ev.xproperty.state == PropertyNewValue)
1449 selection_property (ev.xproperty.window, ev.xproperty.atom); 1471 selection_property (ev.xproperty.window, ev.xproperty.atom);
1450 1472
1451 break; 1473 break;
1452 1474
1453 case SelectionClear: 1475 case SelectionClear:
1454 selection_clear (); 1476 selection_clear ();
1459 selection_paste (ev.xselection.requestor, ev.xselection.property, true); 1481 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1460 break; 1482 break;
1461 1483
1462 case SelectionRequest: 1484 case SelectionRequest:
1463 selection_send (ev.xselectionrequest); 1485 selection_send (ev.xselectionrequest);
1486 break;
1487
1488 case MapNotify:
1489 mapped = 1;
1490#ifdef TEXT_BLINK
1491 text_blink_ev.start ();
1492#endif
1493 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1464 break; 1494 break;
1465 1495
1466 case UnmapNotify: 1496 case UnmapNotify:
1467 mapped = 0; 1497 mapped = 0;
1468#ifdef TEXT_BLINK 1498#ifdef TEXT_BLINK
1469 text_blink_ev.stop (); 1499 text_blink_ev.stop ();
1470#endif 1500#endif
1501 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1471 break; 1502 break;
1472
1473 case MapNotify:
1474 mapped = 1;
1475#ifdef TEXT_BLINK
1476 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1477#endif
1478 break;
1479
1480#ifdef TRANSPARENT
1481 case ReparentNotify:
1482 rootwin_cb (ev);
1483 break;
1484#endif /* TRANSPARENT */
1485 1503
1486 case GraphicsExpose: 1504 case GraphicsExpose:
1487 case Expose: 1505 case Expose:
1488 if (ev.xany.window == vt) 1506 if (ev.xany.window == vt)
1489 { 1507 {
1490 do 1508 do
1509 {
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1510 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1511 ev.xexpose.width, ev.xexpose.height, False);
1512 }
1493 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)); 1513 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1494 1514
1495 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1515 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1496 1516
1497 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) 1517 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1518 {
1498 scr_expose (ev.xexpose.x, ev.xexpose.y, 1519 scr_expose (ev.xexpose.x, ev.xexpose.y,
1499 ev.xexpose.width, ev.xexpose.height, False); 1520 ev.xexpose.width, ev.xexpose.height, False);
1521 }
1500 1522
1501 scr_refresh (refresh_type); 1523 want_refresh = 1;
1502 } 1524 }
1503 else 1525 else
1504 { 1526 {
1505 XEvent unused_event; 1527 XEvent unused_event;
1506 1528
1507 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1529 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1508 ; 1530 ;
1509 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1531 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1510 ; 1532 ;
1511 1533
1512 if (isScrollbarWindow (ev.xany.window)) 1534 if (isScrollbarWindow (ev.xany.window))
1513 { 1535 {
1514 scrollBar.setIdle (); 1536 scrollBar.setIdle ();
1515 scrollbar_show (0); 1537 scrollbar_show (0);
1516 } 1538 }
1517#ifdef MENUBAR
1518 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1519 menubar_expose ();
1520#endif
1521
1522#ifdef TRANSPARENT
1523 if (am_transparent && ev.xany.window == parent[0])
1524 XClearWindow (disp, ev.xany.window);
1525#endif
1526 } 1539 }
1527 break; 1540 break;
1528 1541
1529 case MotionNotify: 1542 case MotionNotify:
1530#ifdef POINTER_BLANK 1543#ifdef POINTER_BLANK
1531 if (hidden_pointer) 1544 if (hidden_pointer)
1532 pointer_unblank (); 1545 pointer_unblank ();
1533#endif 1546#endif
1534#if MENUBAR 1547 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1535 if (isMenuBarWindow (ev.xany.window)) 1548 || priv_modes & PrivMode_MouseAnyEvent)
1536 {
1537 menubar_control (ev.xbutton); 1549 mouse_report (ev.xbutton);
1538 break;
1539 }
1540#endif
1541 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1550 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1542 break; 1551 break;
1543 1552
1544 if (ev.xany.window == vt) 1553 if (ev.xany.window == vt)
1545 { 1554 {
1555 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1556 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1557 ; // nop
1546 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1558 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1547 { 1559 {
1548 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) 1560 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1549 ; 1561 ;
1550 1562
1551 XQueryPointer (disp, vt, 1563 XQueryPointer (dpy, vt,
1552 &unused_root, &unused_child, 1564 &unused_root, &unused_child,
1553 &unused_root_x, &unused_root_y, 1565 &unused_root_x, &unused_root_y,
1554 &ev.xbutton.x, &ev.xbutton.y, 1566 &ev.xbutton.x, &ev.xbutton.y,
1555 &ev.xbutton.state); 1567 &ev.xbutton.state);
1556#ifdef MOUSE_THRESHOLD 1568#ifdef MOUSE_THRESHOLD
1576 int dist; 1588 int dist;
1577 1589
1578 /* don't clobber the current delay if we are 1590 /* don't clobber the current delay if we are
1579 * already in the middle of scrolling. 1591 * already in the middle of scrolling.
1580 */ 1592 */
1581 if (!sel_scroll_ev.active) 1593 if (!sel_scroll_ev.is_active ())
1582 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1594 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1583 1595
1584 /* save the event params so we can highlight 1596 /* save the event params so we can highlight
1585 * the selection in the pending-scroll loop 1597 * the selection in the pending-scroll loop
1586 */ 1598 */
1587 selection_save_x = ev.xbutton.x; 1599 selection_save_x = ev.xbutton.x;
1601 } 1613 }
1602 1614
1603 scroll_selection_lines = Pixel2Height (dist) 1615 scroll_selection_lines = Pixel2Height (dist)
1604 / SELECTION_SCROLL_LINE_SPEEDUP 1616 / SELECTION_SCROLL_LINE_SPEEDUP
1605 + 1; 1617 + 1;
1606 MIN_IT (scroll_selection_lines, 1618 min_it (scroll_selection_lines,
1607 SELECTION_SCROLL_MAX_LINES); 1619 SELECTION_SCROLL_MAX_LINES);
1608 } 1620 }
1609 else 1621 else
1610 { 1622 {
1611 /* we are within the text window, so we 1623 /* we are within the text window, so we
1612 * shouldn't be scrolling 1624 * shouldn't be scrolling
1613 */ 1625 */
1614 if (sel_scroll_ev.active)
1615 sel_scroll_ev.stop(); 1626 sel_scroll_ev.stop();
1616 } 1627 }
1617#endif 1628#endif
1618#ifdef MOUSE_THRESHOLD 1629#ifdef MOUSE_THRESHOLD
1619 } 1630 }
1620#endif 1631#endif
1621 } 1632 }
1622 } 1633 }
1623 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1634 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1624 { 1635 {
1625 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1636 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1626 MotionNotify, &ev)) 1637 MotionNotify, &ev))
1627 ; 1638 ;
1628 1639
1629 XQueryPointer (disp, scrollBar.win, 1640 XQueryPointer (dpy, scrollBar.win,
1630 &unused_root, &unused_child, 1641 &unused_root, &unused_child,
1631 &unused_root_x, &unused_root_y, 1642 &unused_root_x, &unused_root_y,
1632 &ev.xbutton.x, &ev.xbutton.y, 1643 &ev.xbutton.x, &ev.xbutton.y,
1633 &unused_mask); 1644 &unused_mask);
1634 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1645 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1635 scrollbar_size ()); 1646 scrollbar_size ());
1636 scr_refresh (refresh_type);
1637 refresh_limit = 0; 1647 want_refresh = 1;
1638 scrollbar_show (1); 1648 scrollbar_show (1);
1639 } 1649 }
1640 break; 1650 break;
1641 } 1651 }
1652
1653#if defined(CURSOR_BLINK)
1654 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1655 {
1656 if (hidden_cursor)
1657 {
1658 hidden_cursor = 0;
1659 want_refresh = 1;
1660 }
1661
1662 cursor_blink_ev.again ();
1663 }
1664#endif
1665
1666#if defined(POINTER_BLANK)
1667 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1668 {
1669 if (ev.type == MotionNotify
1670 || ev.type == ButtonPress
1671 || ev.type == ButtonRelease)
1672 if (hidden_pointer)
1673 pointer_unblank ();
1674
1675 if (ev.type == KeyPress && hidden_pointer == 0)
1676 pointer_blank ();
1677 }
1678#endif
1679
1680 refresh_check ();
1642} 1681}
1643 1682
1644void 1683void
1645rxvt_term::focus_in () 1684rxvt_term::focus_in ()
1646{ 1685{
1647 if (!focus) 1686 if (!focus)
1648 { 1687 {
1649 focus = 1; 1688 focus = 1;
1650 want_refresh = 1; 1689 want_refresh = 1;
1690
1691 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1692
1651#if USE_XIM 1693#if USE_XIM
1652 if (Input_Context != NULL) 1694 if (Input_Context != NULL)
1653 { 1695 {
1654 IMSetStatusPosition (); 1696 IMSetPosition ();
1655 XSetICFocus (Input_Context); 1697 XSetICFocus (Input_Context);
1656 } 1698 }
1657#endif 1699#endif
1658#if CURSOR_BLINK 1700#if CURSOR_BLINK
1659 if (options & Opt_cursorBlink) 1701 if (option (Opt_cursorBlink))
1660 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1702 cursor_blink_ev.again ();
1661#endif 1703#endif
1662#if OFF_FOCUS_FADING 1704#if OFF_FOCUS_FADING
1663 if (rs[Rs_fade]) 1705 if (rs[Rs_fade])
1664 { 1706 {
1665 pix_colors = pix_colors_focused; 1707 pix_colors = pix_colors_focused;
1666 scr_recolour (); 1708 scr_recolour ();
1667 } 1709 }
1668#endif 1710#endif
1711#if ENABLE_FRILLS
1712 if (option (Opt_urgentOnBell))
1713 {
1714 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1715 {
1716 h->flags &= ~XUrgencyHint;
1717 XSetWMHints (dpy, parent[0], h);
1718 }
1719 }
1720#endif
1669 } 1721 }
1670} 1722}
1671 1723
1672void 1724void
1673rxvt_term::focus_out () 1725rxvt_term::focus_out ()
1675 if (focus) 1727 if (focus)
1676 { 1728 {
1677 focus = 0; 1729 focus = 0;
1678 want_refresh = 1; 1730 want_refresh = 1;
1679 1731
1732 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1733
1680#if ENABLE_FRILLS || ISO_14755 1734#if ENABLE_FRILLS || ISO_14755
1735 if (iso14755buf)
1736 {
1681 iso14755buf = 0; 1737 iso14755buf = 0;
1682#endif 1738# if ISO_14755
1683#if ENABLE_OVERLAY
1684 scr_overlay_off (); 1739 scr_overlay_off ();
1740# endif
1741 }
1685#endif 1742#endif
1686#if USE_XIM 1743#if USE_XIM
1687 if (Input_Context != NULL) 1744 if (Input_Context != NULL)
1688 XUnsetICFocus (Input_Context); 1745 XUnsetICFocus (Input_Context);
1689#endif 1746#endif
1690#if CURSOR_BLINK 1747#if CURSOR_BLINK
1691 if (options & Opt_cursorBlink) 1748 if (option (Opt_cursorBlink))
1692 cursor_blink_ev.stop (); 1749 cursor_blink_ev.stop ();
1750
1693 hidden_cursor = 0; 1751 hidden_cursor = 0;
1694#endif 1752#endif
1695#if OFF_FOCUS_FADING 1753#if OFF_FOCUS_FADING
1696 if (rs[Rs_fade]) 1754 if (rs[Rs_fade])
1697 { 1755 {
1700 } 1758 }
1701#endif 1759#endif
1702 } 1760 }
1703} 1761}
1704 1762
1705#if TRANSPARENT 1763void
1764rxvt_term::update_fade_color (unsigned int idx)
1765{
1766#if OFF_FOCUS_FADING
1767 if (rs[Rs_fade])
1768 {
1769 rgba c;
1770 pix_colors [Color_fade].get (c);
1771 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1772 }
1773#endif
1774}
1775
1776#if ENABLE_TRANSPARENCY || ENABLE_PERL
1706void 1777void
1707rxvt_term::rootwin_cb (XEvent &ev) 1778rxvt_term::rootwin_cb (XEvent &ev)
1708{ 1779{
1709 SET_R (this); 1780 make_current ();
1710 SET_LOCALE (locale);
1711 1781
1782 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1783 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1784 return;
1785
1786# if ENABLE_TRANSPARENCY
1712 switch (ev.type) 1787 switch (ev.type)
1713 { 1788 {
1714 case PropertyNotify: 1789 case PropertyNotify:
1715 /* 1790 /*
1716 * if user used some Esetroot compatible prog to set the root bg, 1791 * if user used some Esetroot compatible prog to set the root bg,
1717 * use the property to determine the pixmap. We use it later on. 1792 * use the property to determine the pixmap. We use it later on.
1718 */ 1793 */
1719 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1794 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1720 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1795 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1721 return; 1796 {
1797 bgPixmap.set_root_pixmap ();
1798 update_background ();
1799 }
1722 1800
1723 /* FALLTHROUGH */
1724 case ReparentNotify:
1725 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1726 want_refresh = want_full_refresh = 1;
1727 break; 1801 break;
1728 } 1802 }
1803# endif
1804
1805 refresh_check ();
1729} 1806}
1730#endif 1807#endif
1731 1808
1732void 1809void
1733rxvt_term::button_press (XButtonEvent &ev) 1810rxvt_term::button_press (XButtonEvent &ev)
1734{ 1811{
1735 int reportmode = 0, clickintime; 1812 int reportmode = 0, clickintime;
1736 1813
1737 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1814 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1815
1738 if (!bypass_keystate) 1816 if (!bypass_keystate)
1739 reportmode = !! (priv_modes & PrivMode_mouse_report); 1817 reportmode = !! (priv_modes & PrivMode_mouse_report);
1740 1818
1741 /* 1819 /*
1742 * VT window processing of button press 1820 * VT window processing of button press
1743 */ 1821 */
1744 if (ev.window == vt) 1822 if (ev.window == vt)
1745 { 1823 {
1824 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1825 return;
1826
1746#if ISO_14755 1827#if ISO_14755
1747 // 5.4 1828 // 5.4
1748 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1829 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1749 { 1830 {
1750 iso14755_54 (ev.x, ev.y); 1831 iso14755_54 (ev.x, ev.y);
1762#ifdef MOUSE_REPORT_DOUBLECLICK 1843#ifdef MOUSE_REPORT_DOUBLECLICK
1763 if (ev.button == MEvent.button && clickintime) 1844 if (ev.button == MEvent.button && clickintime)
1764 { 1845 {
1765 /* same button, within alloted time */ 1846 /* same button, within alloted time */
1766 MEvent.clicks++; 1847 MEvent.clicks++;
1848
1767 if (MEvent.clicks > 1) 1849 if (MEvent.clicks > 1)
1768 { 1850 {
1769 /* only report double clicks */ 1851 /* only report double clicks */
1770 MEvent.clicks = 2; 1852 MEvent.clicks = 2;
1771 mouse_report (ev); 1853 mouse_report (ev);
1783 mouse_report (ev); 1865 mouse_report (ev);
1784 } 1866 }
1785#else 1867#else
1786 MEvent.button = ev.button; 1868 MEvent.button = ev.button;
1787 mouse_report (ev); 1869 mouse_report (ev);
1788#endif /* MOUSE_REPORT_DOUBLECLICK */ 1870#endif /* MOUSE_REPORT_DOUBLECLICK */
1789 1871
1790 } 1872 }
1791 else 1873 else
1792 { 1874 {
1793 if (ev.button != MEvent.button) 1875 if (ev.button != MEvent.button)
1803#else 1885#else
1804 selection.rect = false; 1886 selection.rect = false;
1805#endif 1887#endif
1806 1888
1807 /* allow shift+left click to extend selection */ 1889 /* allow shift+left click to extend selection */
1808 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1890 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1809 { 1891 {
1810 if (MEvent.button == Button1 && clickintime) 1892 if (MEvent.button == Button1 && clickintime)
1811 selection_rotate (ev.x, ev.y); 1893 selection_rotate (ev.x, ev.y);
1812 else 1894 else
1813 selection_extend (ev.x, ev.y, 1); 1895 selection_extend (ev.x, ev.y, 1);
1887 tt_printf ("\033[5~"); 1969 tt_printf ("\033[5~");
1888 break; 1970 break;
1889 } 1971 }
1890 } 1972 }
1891 else 1973 else
1892#endif /* NO_SCROLLBAR_REPORT */ 1974#endif /* NO_SCROLLBAR_REPORT */
1893 1975
1894 { 1976 {
1895 char upordown = 0; 1977 char upordown = 0;
1896 1978
1897 if (scrollBar.style == R_SB_NEXT) 1979 if (scrollBar.style == R_SB_NEXT)
1898 { 1980 {
1899 if (scrollbarnext_upButton (ev.y)) 1981 if (scrollbarnext_upButton (ev.y))
1900 upordown = -1; /* up */ 1982 upordown = -1; /* up */
1906 if (scrollbarrxvt_upButton (ev.y)) 1988 if (scrollbarrxvt_upButton (ev.y))
1907 upordown = -1; /* up */ 1989 upordown = -1; /* up */
1908 else if (scrollbarrxvt_dnButton (ev.y)) 1990 else if (scrollbarrxvt_dnButton (ev.y))
1909 upordown = 1; /* down */ 1991 upordown = 1; /* down */
1910 } 1992 }
1993
1911 if (upordown) 1994 if (upordown)
1912 { 1995 {
1913#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1996#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1997 if (!cont_scroll_ev.is_active ())
1914 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1998 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1915#endif 1999#endif
1916 if (scr_page (upordown < 0 ? UP : DN, 1)) 2000 if (scr_page (upordown < 0 ? UP : DN, 1))
1917 { 2001 {
1918 if (upordown < 0) 2002 if (upordown < 0)
1919 scrollBar.setUp (); 2003 scrollBar.setUp ();
1978 } 2062 }
1979 2063
1980 break; 2064 break;
1981 } 2065 }
1982 } 2066 }
2067
1983 return; 2068 return;
1984 } 2069 }
1985#if MENUBAR
1986 /*
1987 * Menubar window processing of button press
1988 */
1989 if (isMenuBarWindow (ev.window))
1990 menubar_control (ev);
1991#endif
1992} 2070}
1993 2071
1994void 2072void
1995rxvt_term::button_release (XButtonEvent &ev) 2073rxvt_term::button_release (XButtonEvent &ev)
1996{ 2074{
2002 2080
2003 if (scrollbar_isUpDn ()) 2081 if (scrollbar_isUpDn ())
2004 { 2082 {
2005 scrollBar.setIdle (); 2083 scrollBar.setIdle ();
2006 scrollbar_show (0); 2084 scrollbar_show (0);
2007#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2008 refresh_type &= ~SMOOTH_REFRESH;
2009#endif
2010 } 2085 }
2011 2086
2012#ifdef SELECTION_SCROLLING 2087#ifdef SELECTION_SCROLLING
2013 if (sel_scroll_ev.active)
2014 sel_scroll_ev.stop(); 2088 sel_scroll_ev.stop();
2015#endif 2089#endif
2016 2090
2017 if (ev.window == vt) 2091 if (ev.window == vt)
2018 { 2092 {
2093 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2094 return;
2095
2019#if ISO_14755 2096#if ISO_14755
2020 // 5.4 2097 // 5.4
2021 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2098 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2022 return; 2099 return;
2023#endif 2100#endif
2101
2024 if (reportmode) 2102 if (reportmode)
2025 { 2103 {
2026 /* mouse report from vt window */ 2104 /* mouse report from vt window */
2027 /* don't report release of wheel "buttons" */ 2105 /* don't report release of wheel "buttons" */
2028 if (ev.button >= 4) 2106 if (ev.button >= 4)
2039 mouse_report (ev); 2117 mouse_report (ev);
2040 } 2118 }
2041#else /* MOUSE_REPORT_DOUBLECLICK */ 2119#else /* MOUSE_REPORT_DOUBLECLICK */
2042 MEvent.button = AnyButton; 2120 MEvent.button = AnyButton;
2043 mouse_report (ev); 2121 mouse_report (ev);
2044#endif /* MOUSE_REPORT_DOUBLECLICK */ 2122#endif /* MOUSE_REPORT_DOUBLECLICK */
2045 return; 2123 return;
2046 } 2124 }
2047 2125
2048 /* 2126 /*
2049 * dumb hack to compensate for the failure of click-and-drag 2127 * dumb hack to compensate for the failure of click-and-drag
2058 { 2136 {
2059 case Button1: 2137 case Button1:
2060 case Button3: 2138 case Button3:
2061 selection_make (ev.time); 2139 selection_make (ev.time);
2062 break; 2140 break;
2141
2063 case Button2: 2142 case Button2:
2064 selection_request (ev.time, ev.x, ev.y); 2143 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2144 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2065 break; 2145 break;
2146
2066#ifdef MOUSE_WHEEL 2147#ifdef MOUSE_WHEEL
2067 case Button4: 2148 case Button4:
2068 case Button5: 2149 case Button5:
2069 { 2150 {
2070 int i; 2151 int i;
2072 2153
2073 v = ev.button == Button4 ? UP : DN; 2154 v = ev.button == Button4 ? UP : DN;
2074 2155
2075 if (ev.state & ShiftMask) 2156 if (ev.state & ShiftMask)
2076 i = 1; 2157 i = 1;
2077 else if (options & Opt_mouseWheelScrollPage) 2158 else if (option (Opt_mouseWheelScrollPage))
2078 i = nrow - 1; 2159 i = nrow - 1;
2079 else 2160 else
2080 i = 5; 2161 i = 5;
2081 2162
2082# ifdef MOUSE_SLIP_WHEELING 2163# ifdef MOUSE_SLIP_WHEELING
2084 { 2165 {
2085 mouse_slip_wheel_speed += v ? -1 : 1; 2166 mouse_slip_wheel_speed += v ? -1 : 1;
2086 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2167 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2087 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2168 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2088 2169
2089 if (slip_wheel_ev.at < NOW) 2170 if (!slip_wheel_ev.is_active ())
2090 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2171 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2091
2092 slip_wheel_ev.start ();
2093 } 2172 }
2094 else 2173 else
2095 { 2174 {
2096# endif 2175# endif
2097# ifdef JUMP_MOUSE_WHEEL
2098 scr_page (v, i); 2176 scr_page (v, i);
2099 scr_refresh (SMOOTH_REFRESH);
2100 scrollbar_show (1); 2177 scrollbar_show (1);
2101# else
2102 while (i--)
2103 {
2104 scr_page (v, 1);
2105 scr_refresh (SMOOTH_REFRESH);
2106 scrollbar_show (1);
2107 }
2108# endif
2109# ifdef MOUSE_SLIP_WHEELING 2178# ifdef MOUSE_SLIP_WHEELING
2110 } 2179 }
2111#endif 2180# endif
2112 } 2181 }
2113 break; 2182 break;
2114#endif 2183#endif
2115 } 2184 }
2116 } 2185 }
2117#ifdef MENUBAR
2118 else if (isMenuBarWindow (ev.window))
2119 menubar_control (ev);
2120#endif
2121} 2186}
2122
2123#ifdef TRANSPARENT
2124#if TINTING
2125/* taken from aterm-0.4.2 */
2126
2127typedef uint32_t RUINT32T;
2128
2129void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2130{
2131 int sh_r, sh_g, sh_b;
2132 RUINT32T mask_r, mask_g, mask_b;
2133 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2134 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2135 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2136 int i;
2137
2138 Visual *visual = display->visual;
2139
2140 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2141
2142 /* for convenience */
2143 mask_r = visual->red_mask;
2144 mask_g = visual->green_mask;
2145 mask_b = visual->blue_mask;
2146
2147 /* boring lookup table pre-initialization */
2148 switch (srcImage->bits_per_pixel) {
2149 case 15:
2150 if ((mask_r != 0x7c00) ||
2151 (mask_g != 0x03e0) ||
2152 (mask_b != 0x001f))
2153 return;
2154 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2155 lookup_r = lookup;
2156 lookup_g = lookup+32;
2157 lookup_b = lookup+32+32;
2158 sh_r = 10;
2159 sh_g = 5;
2160 sh_b = 0;
2161 break;
2162 case 16:
2163 if ((mask_r != 0xf800) ||
2164 (mask_g != 0x07e0) ||
2165 (mask_b != 0x001f))
2166 return;
2167 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2168 lookup_r = lookup;
2169 lookup_g = lookup+32;
2170 lookup_b = lookup+32+64;
2171 sh_r = 11;
2172 sh_g = 5;
2173 sh_b = 0;
2174 break;
2175 case 24:
2176 if ((mask_r != 0xff0000) ||
2177 (mask_g != 0x00ff00) ||
2178 (mask_b != 0x0000ff))
2179 return;
2180 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2181 lookup_r = lookup;
2182 lookup_g = lookup+256;
2183 lookup_b = lookup+256+256;
2184 sh_r = 16;
2185 sh_g = 8;
2186 sh_b = 0;
2187 break;
2188 case 32:
2189 if ((mask_r != 0xff0000) ||
2190 (mask_g != 0x00ff00) ||
2191 (mask_b != 0x0000ff))
2192 return;
2193 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2194 lookup_r = lookup;
2195 lookup_g = lookup+256;
2196 lookup_b = lookup+256+256;
2197 sh_r = 16;
2198 sh_g = 8;
2199 sh_b = 0;
2200 break;
2201 default:
2202 return; /* we do not support this color depth */
2203 }
2204
2205 /* prepare limits for color transformation (each channel is handled separately) */
2206 if (shade < 0) {
2207 shade = -shade;
2208 if (shade < 0) shade = 0;
2209 if (shade > 100) shade = 100;
2210
2211 lower_lim_r = 65535-rm;
2212 lower_lim_g = 65535-gm;
2213 lower_lim_b = 65535-bm;
2214
2215 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2216 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2217 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2218
2219 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2220 } else {
2221 if (shade < 0) shade = 0;
2222 if (shade > 100) shade = 100;
2223
2224 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2225
2226 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2227 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2228 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2229 }
2230
2231 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2232 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2233 {
2234 unsigned int tmp;
2235
2236 tmp = lower_lim_r;
2237 lower_lim_r = lower_lim_b;
2238 lower_lim_b = tmp;
2239
2240 tmp = upper_lim_r;
2241 upper_lim_r = upper_lim_b;
2242 upper_lim_b = tmp;
2243 }
2244
2245 /* fill our lookup tables */
2246 for (i = 0; i <= mask_r>>sh_r; i++)
2247 {
2248 RUINT32T tmp;
2249 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2250 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2251 lookup_r[i] = (tmp/65535)<<sh_r;
2252 }
2253 for (i = 0; i <= mask_g>>sh_g; i++)
2254 {
2255 RUINT32T tmp;
2256 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2257 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2258 lookup_g[i] = (tmp/65535)<<sh_g;
2259 }
2260 for (i = 0; i <= mask_b>>sh_b; i++)
2261 {
2262 RUINT32T tmp;
2263 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2264 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2265 lookup_b[i] = (tmp/65535)<<sh_b;
2266 }
2267
2268 /* apply table to input image (replacing colors by newly calculated ones) */
2269 switch (srcImage->bits_per_pixel)
2270 {
2271 case 15:
2272 {
2273 unsigned short *p1, *pf, *p, *pl;
2274 p1 = (unsigned short *) srcImage->data;
2275 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2276 while (p1 < pf)
2277 {
2278 p = p1;
2279 pl = p1 + srcImage->width;
2280 for (; p < pl; p++)
2281 {
2282 *p = lookup_r[(*p & 0x7c00)>>10] |
2283 lookup_g[(*p & 0x03e0)>> 5] |
2284 lookup_b[(*p & 0x001f)];
2285 }
2286 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2287 }
2288 break;
2289 }
2290 case 16:
2291 {
2292 unsigned short *p1, *pf, *p, *pl;
2293 p1 = (unsigned short *) srcImage->data;
2294 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2295 while (p1 < pf)
2296 {
2297 p = p1;
2298 pl = p1 + srcImage->width;
2299 for (; p < pl; p++)
2300 {
2301 *p = lookup_r[(*p & 0xf800)>>11] |
2302 lookup_g[(*p & 0x07e0)>> 5] |
2303 lookup_b[(*p & 0x001f)];
2304 }
2305 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2306 }
2307 break;
2308 }
2309 case 24:
2310 {
2311 unsigned char *p1, *pf, *p, *pl;
2312 p1 = (unsigned char *) srcImage->data;
2313 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2314 while (p1 < pf)
2315 {
2316 p = p1;
2317 pl = p1 + srcImage->width * 3;
2318 for (; p < pl; p += 3)
2319 {
2320 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2321 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2322 p[2] = lookup_r[(p[2] & 0x0000ff)];
2323 }
2324 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2325 }
2326 break;
2327 }
2328 case 32:
2329 {
2330 RUINT32T *p1, *pf, *p, *pl;
2331 p1 = (RUINT32T *) srcImage->data;
2332 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2333
2334 while (p1 < pf)
2335 {
2336 p = p1;
2337 pl = p1 + srcImage->width;
2338 for (; p < pl; p++)
2339 {
2340 *p = lookup_r[(*p & 0xff0000)>>16] |
2341 lookup_g[(*p & 0x00ff00)>> 8] |
2342 lookup_b[(*p & 0x0000ff)] |
2343 (*p & ~0xffffff);
2344 }
2345 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2346 }
2347 break;
2348 }
2349 }
2350
2351 free (lookup);
2352}
2353#endif
2354
2355/*
2356 * Check our parents are still who we think they are.
2357 * Do transparency updates if required
2358 */
2359int
2360rxvt_term::check_our_parents ()
2361{
2362 int i, pchanged, aformat, have_pixmap, rootdepth;
2363 unsigned long nitems, bytes_after;
2364 Atom atype;
2365 unsigned char *prop = NULL;
2366 Window root, oldp, *list;
2367 Pixmap rootpixmap = None;
2368 XWindowAttributes wattr, wrootattr;
2369 dDisp;
2370
2371 pchanged = 0;
2372
2373 if (!(options & Opt_transparent))
2374 return pchanged; /* Don't try any more */
2375
2376 XGetWindowAttributes (disp, display->root, &wrootattr);
2377 rootdepth = wrootattr.depth;
2378
2379 XGetWindowAttributes (disp, parent[0], &wattr);
2380
2381 if (rootdepth != wattr.depth)
2382 {
2383 if (am_transparent)
2384 {
2385 pchanged = 1;
2386 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2387 am_transparent = am_pixmap_trans = 0;
2388 }
2389
2390 return pchanged; /* Don't try any more */
2391 }
2392
2393 /* Get all X ops out of the queue so that our information is up-to-date. */
2394 XSync (disp, False);
2395
2396 /*
2397 * Make the frame window set by the window manager have
2398 * the root background. Some window managers put multiple nested frame
2399 * windows for each client, so we have to take care about that.
2400 */
2401 i = (xa[XA_XROOTPMAP_ID]
2402 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2403 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2404 &nitems, &bytes_after, &prop) == Success);
2405
2406 if (!i || prop == NULL)
2407 i = (xa[XA_ESETROOT_PMAP_ID]
2408 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2409 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2410 &nitems, &bytes_after, &prop) == Success);
2411
2412 if (!i || prop == NULL
2413#if TINTING
2414 || !rs[Rs_color + Color_tint]
2415#endif
2416 )
2417 have_pixmap = 0;
2418 else
2419 {
2420 have_pixmap = 1;
2421 rootpixmap = *(Pixmap *)prop;
2422 XFree (prop);
2423 }
2424
2425 if (have_pixmap)
2426 {
2427 /*
2428 * Copy display->root pixmap transparency
2429 */
2430 int sx, sy, nx, ny;
2431 unsigned int nw, nh;
2432 Window cr;
2433 XImage *image;
2434 GC gc;
2435 XGCValues gcvalue;
2436
2437 XTranslateCoordinates (disp, parent[0], display->root,
2438 0, 0, &sx, &sy, &cr);
2439 nw = (unsigned int)szHint.width;
2440 nh = (unsigned int)szHint.height;
2441 nx = ny = 0;
2442
2443 if (sx < 0)
2444 {
2445 nw += sx;
2446 nx = -sx;
2447 sx = 0;
2448 }
2449
2450 if (sy < 0)
2451 {
2452 nh += sy;
2453 ny = -sy;
2454 sy = 0;
2455 }
2456
2457 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2458 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2459
2460 XSync (disp, False);
2461 allowedxerror = -1;
2462 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2463
2464 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2465 /* XXX: may need a delay here? */
2466 allowedxerror = 0;
2467
2468 if (image == NULL)
2469 {
2470 if (am_transparent && am_pixmap_trans)
2471 {
2472 pchanged = 1;
2473 if (pixmap != None)
2474 {
2475 XFreePixmap (disp, pixmap);
2476 pixmap = None;
2477 }
2478 }
2479
2480 am_pixmap_trans = 0;
2481 }
2482 else
2483 {
2484 if (pixmap != None)
2485 XFreePixmap (disp, pixmap);
2486
2487#if TINTING
2488 if (ISSET_PIXCOLOR (Color_tint))
2489 {
2490 unsigned short rm, gm, bm;
2491 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2492
2493 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2494
2495 ShadeXImage (display, image, shade, rm, gm, bm);
2496 }
2497#endif
2498
2499 pixmap = XCreatePixmap (disp, vt,
2500 szHint.width, szHint.height, image->depth);
2501 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2502 XPutImage (disp, pixmap, gc, image, 0, 0,
2503 nx, ny, image->width, image->height);
2504 XFreeGC (disp, gc);
2505 XDestroyImage (image);
2506 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2507 XClearWindow (disp, parent[0]);
2508
2509 if (!am_transparent || !am_pixmap_trans)
2510 pchanged = 1;
2511
2512 am_transparent = am_pixmap_trans = 1;
2513 }
2514 }
2515
2516 if (am_pixmap_trans)
2517 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2518 else
2519 {
2520 unsigned int n;
2521 /*
2522 * InheritPixmap transparency
2523 */
2524 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2525 {
2526 oldp = parent[i];
2527 XQueryTree (disp, parent[i - 1], &root,
2528 &parent[i], &list, &n);
2529 XFree (list);
2530
2531 if (parent[i] == display->root)
2532 {
2533 if (oldp != None)
2534 pchanged = 1;
2535
2536 break;
2537 }
2538
2539 if (oldp != parent[i])
2540 pchanged = 1;
2541 }
2542
2543 n = 0;
2544
2545 if (pchanged)
2546 {
2547 for (; n < (unsigned int)i; n++)
2548 {
2549 XGetWindowAttributes (disp, parent[n], &wattr);
2550 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2551 {
2552 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2553 break;
2554 }
2555 }
2556 }
2557
2558 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2559 {
2560 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2561 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2562 am_transparent = 0;
2563 /* XXX: also turn off Opt_transparent? */
2564 }
2565 else
2566 {
2567#if WAIT_FOR_WM
2568 /* wait (an arbitrary period) for the WM to do its thing
2569 * needed for fvwm2.2.2 (and before?) */
2570 sleep (1);
2571#endif
2572 for (n = 0; n < (unsigned int)i; n++)
2573 {
2574 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2575 XClearWindow (disp, parent[n]);
2576 }
2577
2578 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2579 am_transparent = 1;
2580 }
2581
2582 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2583 parent[i] = None;
2584 }
2585
2586 if (scrollBar.win)
2587 {
2588 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2589 scrollBar.setIdle ();
2590 scrollbar_show (0);
2591 }
2592
2593 if (am_transparent)
2594 {
2595 want_refresh = want_full_refresh = 1;
2596 if (am_pixmap_trans)
2597 flush ();
2598 }
2599
2600 return pchanged;
2601}
2602#endif
2603 2187
2604/*}}} */ 2188/*}}} */
2605 2189
2606bool 2190bool
2607rxvt_term::cmd_parse () 2191rxvt_term::cmd_parse ()
2608{ 2192{
2609 bool flag = false; 2193 bool flag = false;
2610 unicode_t ch = NOCHAR; 2194 wchar_t ch = NOCHAR;
2611 unsigned char *seq_begin; // remember start of esc-sequence here 2195 char *seq_begin; // remember start of esc-sequence here
2612 2196
2613 for (;;) 2197 for (;;)
2614 { 2198 {
2615 if (ch == NOCHAR) 2199 if (ch == NOCHAR)
2616 { 2200 {
2617 seq_begin = cmdbuf_ptr; 2201 seq_begin = cmdbuf_ptr;
2618 ch = next_char (); 2202 ch = next_char ();
2619 }
2620 2203
2621 if (ch == NOCHAR) // TODO: improve 2204 if (ch == NOCHAR)
2622 break; 2205 break;
2206 }
2623 2207
2624 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2208 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2625 { 2209 {
2626 if (!seen_input) 2210 if (!seen_input)
2627 { 2211 {
2636 if (seen_resize && cmd_pid) 2220 if (seen_resize && cmd_pid)
2637 kill (-cmd_pid, SIGWINCH); 2221 kill (-cmd_pid, SIGWINCH);
2638 } 2222 }
2639 2223
2640 /* Read a text string from the input buffer */ 2224 /* Read a text string from the input buffer */
2641 unicode_t buf[UBUFSIZ]; 2225 wchar_t buf[UBUFSIZ];
2642 bool refreshnow = false; 2226 bool refreshnow = false;
2643 int nlines = 0; 2227 int nlines = 0;
2644 unicode_t *str = buf; 2228 wchar_t *str = buf;
2645 unicode_t *eol = str + min (ncol, UBUFSIZ); 2229 wchar_t *eol = str + min (ncol, UBUFSIZ);
2646 2230
2647 for (;;) 2231 for (;;)
2648 { 2232 {
2649 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2233 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2650 break; 2234 break;
2656 if (ch == C0_LF) 2240 if (ch == C0_LF)
2657 nlines++; 2241 nlines++;
2658 2242
2659 refresh_count++; 2243 refresh_count++;
2660 2244
2661 if (!(options & Opt_jumpScroll) 2245 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2662 || (refresh_count >= refresh_limit * (nrow - 1)))
2663 { 2246 {
2247 refresh_count = 0;
2248
2249 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2250 {
2664 refreshnow = true; 2251 refreshnow = true;
2665 ch = NOCHAR; 2252 ch = NOCHAR;
2666 break; 2253 break;
2254 }
2667 } 2255 }
2668 2256
2669 // scr_add_lines only works for nlines <= nrow - 1. 2257 // scr_add_lines only works for nlines <= nrow - 1.
2670 if (nlines >= nrow - 1) 2258 if (nlines >= nrow - 1)
2671 { 2259 {
2260 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2261 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2672 scr_add_lines (buf, nlines, str - buf); 2262 scr_add_lines (buf, str - buf, nlines);
2263
2673 nlines = 0; 2264 nlines = 0;
2674 str = buf; 2265 str = buf;
2675 eol = str + min (ncol, UBUFSIZ); 2266 eol = str + min (ncol, UBUFSIZ);
2676 } 2267 }
2677 2268
2690 2281
2691 seq_begin = cmdbuf_ptr; 2282 seq_begin = cmdbuf_ptr;
2692 ch = next_char (); 2283 ch = next_char ();
2693 } 2284 }
2694 2285
2286 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2287 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2695 scr_add_lines (buf, nlines, str - buf); 2288 scr_add_lines (buf, str - buf, nlines);
2696 2289
2697 /* 2290 /*
2698 * If there have been a lot of new lines, then update the screen 2291 * If there have been a lot of new lines, then update the screen
2699 * What the heck I'll cheat and only refresh less than every page-full. 2292 * What the heck we'll cheat and only refresh less than every page-full.
2700 * the number of pages between refreshes is refresh_limit, which 2293 * if skipScroll is enabled.
2701 * is incremented here because we must be doing flat-out scrolling.
2702 */ 2294 */
2703 if (refreshnow) 2295 if (refreshnow)
2704 { 2296 {
2705 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2706 refresh_limit++;
2707 else
2708 {
2709 flag = true; 2297 flag = true;
2710 scr_refresh (refresh_type); 2298 scr_refresh ();
2711 } 2299 want_refresh = 1;
2712 } 2300 }
2713 2301
2714 } 2302 }
2715 else 2303 else
2716 { 2304 {
2730 } 2318 }
2731 2319
2732 return flag; 2320 return flag;
2733} 2321}
2734 2322
2735// read the next octet
2736unicode_t
2737rxvt_term::next_octet ()
2738{
2739 return cmdbuf_ptr < cmdbuf_endp
2740 ? *cmdbuf_ptr++
2741 : NOCHAR;
2742}
2743
2744// read the next character 2323// read the next character
2745unicode_t 2324wchar_t
2746rxvt_term::next_char () 2325rxvt_term::next_char () NOTHROW
2747{ 2326{
2748 while (cmdbuf_ptr < cmdbuf_endp) 2327 while (cmdbuf_ptr < cmdbuf_endp)
2749 { 2328 {
2750 // assume 7-bit to be ascii ALWAYS 2329 // assume 7-bit to be ascii ALWAYS
2751 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2330 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2752 return *cmdbuf_ptr++; 2331 return *cmdbuf_ptr++;
2753 2332
2754 wchar_t wc; 2333 wchar_t wc;
2755 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2334 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2756 2335
2757 if (len == (size_t)-2) 2336 if (len == (size_t)-2)
2758 { 2337 {
2759 // the mbstate stores incomplete sequences. didn't know this :/ 2338 // the mbstate stores incomplete sequences. didn't know this :/
2760 cmdbuf_ptr = cmdbuf_endp; 2339 cmdbuf_ptr = cmdbuf_endp;
2761 break; 2340 break;
2762 } 2341 }
2763 2342
2764 if (len == (size_t)-1) 2343 if (len == (size_t)-1)
2765 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2344 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2766 2345
2767 // assume wchar == unicode 2346 // assume wchar == unicode
2768 cmdbuf_ptr += len; 2347 cmdbuf_ptr += len;
2769 return wc & UNICODE_MASK; 2348 return wc & UNICODE_MASK;
2770 } 2349 }
2771 2350
2772 return NOCHAR; 2351 return NOCHAR;
2773} 2352}
2353
2354// read the next octet
2355uint32_t
2356rxvt_term::next_octet () NOTHROW
2357{
2358 return cmdbuf_ptr < cmdbuf_endp
2359 ? (unsigned char)*cmdbuf_ptr++
2360 : NOCHAR;
2361}
2362
2363static class out_of_input out_of_input;
2774 2364
2775/* rxvt_cmd_getc () - Return next input character */ 2365/* rxvt_cmd_getc () - Return next input character */
2776/* 2366/*
2777 * Return the next input character after first passing any keyboard input 2367 * Return the next input character after first passing any keyboard input
2778 * to the command. 2368 * to the command.
2779 */ 2369 */
2780unicode_t 2370wchar_t
2781rxvt_term::cmd_getc () 2371rxvt_term::cmd_getc () THROW ((class out_of_input))
2782{ 2372{
2783 unicode_t c = next_char (); 2373 wchar_t c = next_char ();
2784 2374
2785 if (c == NOCHAR) 2375 if (c == NOCHAR)
2786 throw out_of_input; 2376 throw out_of_input;
2787 2377
2788 return c; 2378 return c;
2789} 2379}
2790 2380
2791unicode_t 2381uint32_t
2792rxvt_term::cmd_get8 () 2382rxvt_term::cmd_get8 () THROW ((class out_of_input))
2793{ 2383{
2794 unicode_t c = next_octet (); 2384 uint32_t c = next_octet ();
2795 2385
2796 if (c == NOCHAR) 2386 if (c == NOCHAR)
2797 throw out_of_input; 2387 throw out_of_input;
2798 2388
2799 return c; 2389 return c;
2863 { 2453 {
2864 if ((buf[len++] = cmd_getc ()) == 'i') 2454 if ((buf[len++] = cmd_getc ()) == 'i')
2865 break; /* done = 1 */ 2455 break; /* done = 1 */
2866 } 2456 }
2867 } 2457 }
2868 2458
2869 for (i = 0; i < len; i++) 2459 for (i = 0; i < len; i++)
2870 if (putc (buf[i], fd) == EOF) 2460 if (putc (buf[i], fd) == EOF)
2871 { 2461 {
2872 done = 1; 2462 done = 1;
2873 break; 2463 break;
2875 } 2465 }
2876 } 2466 }
2877 2467
2878 pclose_printer (fd); 2468 pclose_printer (fd);
2879} 2469}
2880#endif /* PRINTPIPE */ 2470#endif /* PRINTPIPE */
2881/*}}} */ 2471/*}}} */
2882 2472
2883/* *INDENT-OFF* */ 2473/* *INDENT-OFF* */
2884enum { 2474enum {
2885 C1_40 = 0x40, 2475 C1_40 = 0x40,
2899 case C0_ESC: 2489 case C0_ESC:
2900 process_escape_seq (); 2490 process_escape_seq ();
2901 break; 2491 break;
2902 case C0_ENQ: /* terminal Status */ 2492 case C0_ENQ: /* terminal Status */
2903 if (rs[Rs_answerbackstring]) 2493 if (rs[Rs_answerbackstring])
2904 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2494 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2905 (unsigned int)strlen (rs[Rs_answerbackstring]));
2906 else 2495 else
2907 tt_write ((unsigned char *)VT100_ANS, 2496 tt_write (VT100_ANS, strlen (VT100_ANS));
2908 (unsigned int)strlen (VT100_ANS));
2909 break; 2497 break;
2910 case C0_BEL: /* bell */ 2498 case C0_BEL: /* bell */
2911 scr_bell (); 2499 scr_bell ();
2912 break; 2500 break;
2913 case C0_BS: /* backspace */ 2501 case C0_BS: /* backspace */
2937 process_dcs_seq (); 2525 process_dcs_seq ();
2938 break; 2526 break;
2939 case 0x9b: /* CSI */ 2527 case 0x9b: /* CSI */
2940 process_csi_seq (); 2528 process_csi_seq ();
2941 break; 2529 break;
2942 case 0x9d: /* CSI */ 2530 case 0x9d: /* OSC */
2943 process_osc_seq (); 2531 process_osc_seq ();
2944 break; 2532 break;
2945#endif 2533#endif
2946 } 2534 }
2947} 2535}
3037 scr_charset_set (2, (unsigned int)cmd_getc ()); 2625 scr_charset_set (2, (unsigned int)cmd_getc ());
3038 break; 2626 break;
3039 case '+': 2627 case '+':
3040 scr_charset_set (3, (unsigned int)cmd_getc ()); 2628 scr_charset_set (3, (unsigned int)cmd_getc ());
3041 break; 2629 break;
3042#if ENABLE_FRILLS 2630#if !ENABLE_MINIMAL
3043 case '6': 2631 case '6':
3044 scr_backindex (); 2632 scr_backindex ();
3045 break; 2633 break;
3046#endif 2634#endif
3047 case '7': 2635 case '7':
3048 scr_cursor (SAVE); 2636 scr_cursor (SAVE);
3049 break; 2637 break;
3050 case '8': 2638 case '8':
3051 scr_cursor (RESTORE); 2639 scr_cursor (RESTORE);
3052 break; 2640 break;
3053#if ENABLE_FRILLS 2641#if !ENABLE_MINIMAL
3054 case '9': 2642 case '9':
3055 scr_forwardindex (); 2643 scr_forwardindex ();
3056 break; 2644 break;
3057#endif 2645#endif
3058 case '=': 2646 case '=':
3068 break; 2656 break;
3069 2657
3070 /* 8.3.87: NEXT LINE */ 2658 /* 8.3.87: NEXT LINE */
3071 case C1_NEL: /* ESC E */ 2659 case C1_NEL: /* ESC E */
3072 { 2660 {
3073 unicode_t nlcr[] = { C0_LF, C0_CR }; 2661 wchar_t nlcr[] = { C0_LF, C0_CR };
3074 scr_add_lines (nlcr, 1, 2); 2662 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3075 } 2663 }
3076 break; 2664 break;
3077 2665
3078 /* kidnapped escape sequence: Should be 8.3.48 */ 2666 /* kidnapped escape sequence: Should be 8.3.48 */
3079 case C1_ESA: /* ESC G */ 2667 case C1_ESA: /* ESC G */
3101 process_dcs_seq (); 2689 process_dcs_seq ();
3102 break; 2690 break;
3103 2691
3104 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2692 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3105 case C1_SCI: /* ESC Z */ 2693 case C1_SCI: /* ESC Z */
3106 tt_write ((const unsigned char *)ESCZ_ANSWER, 2694 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3107 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3108 break; /* steal obsolete ESC [ c */ 2695 break; /* steal obsolete ESC [ c */
3109 2696
3110 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2697 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3111 case C1_CSI: /* ESC [ */ 2698 case C1_CSI: /* ESC [ */
3112 process_csi_seq (); 2699 process_csi_seq ();
3174rxvt_term::process_csi_seq () 2761rxvt_term::process_csi_seq ()
3175{ 2762{
3176 unicode_t ch, priv, i; 2763 unicode_t ch, priv, i;
3177 unsigned int nargs, p; 2764 unsigned int nargs, p;
3178 int n, ndef; 2765 int n, ndef;
3179 int arg[ESC_ARGS]; 2766 int arg[ESC_ARGS] = { };
3180 2767
3181 for (nargs = ESC_ARGS; nargs > 0;) 2768 nargs = 0;
3182 arg[--nargs] = 0;
3183 2769
3184 priv = 0; 2770 priv = 0;
3185 ch = cmd_getc (); 2771 ch = cmd_getc ();
3186 if (ch >= '<' && ch <= '?') 2772 if (ch >= '<' && ch <= '?')
2773 {
3187 { /* '<' '=' '>' '?' */ 2774 /* '<' '=' '>' '?' */
3188 priv = ch; 2775 priv = ch;
3189 ch = cmd_getc (); 2776 ch = cmd_getc ();
3190 } 2777 }
3191 2778
3192 /* read any numerical arguments */ 2779 /* read any numerical arguments */
3221 ndef = get_byte_array_bit (csi_defaults, i); 2808 ndef = get_byte_array_bit (csi_defaults, i);
3222 for (p = 0; p < nargs; p++) 2809 for (p = 0; p < nargs; p++)
3223 if (arg[p] == -1) 2810 if (arg[p] == -1)
3224 arg[p] = ndef; 2811 arg[p] = ndef;
3225 2812
3226#ifdef DEBUG_CMD
3227 fprintf (stderr, "CSI ");
3228 for (p = 0; p < nargs; p++)
3229 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3230 fprintf (stderr, "%c\n", ch);
3231#endif
3232
3233 /* 2813 /*
3234 * private mode handling 2814 * private mode handling
3235 */ 2815 */
3236 if (priv) 2816 if (priv)
3237 { 2817 {
3238 switch (priv) 2818 switch (priv)
3239 { 2819 {
3240 case '>': 2820 case '>':
3241 if (ch == CSI_DA) /* secondary device attributes */ 2821 if (ch == CSI_DA) /* secondary device attributes */
3242 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2822 {
2823 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2824 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2825 //
2826 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2827 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2828 // versions.
2829 //
2830 tt_printf ("\033[>%d;95;0c", 'U');
2831 }
3243 break; 2832 break;
3244 case '?': 2833 case '?':
3245 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2834 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3246 process_terminal_mode (ch, priv, nargs, arg); 2835 process_terminal_mode (ch, priv, nargs, arg);
3247 break; 2836 break;
3352 2941
3353 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 2942 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3354 arg[0] = -arg[0]; 2943 arg[0] = -arg[0];
3355 /* FALLTHROUGH */ 2944 /* FALLTHROUGH */
3356 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2945 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3357 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 2946 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3358 break; 2947 break;
3359 2948
3360 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 2949 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3361 tt_write ((const unsigned char *)VT100_ANS, 2950 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3362 (unsigned int) (sizeof (VT100_ANS) - 1));
3363 break; 2951 break;
3364 2952
3365 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 2953 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3366 process_sgr_mode (nargs, arg); 2954 process_sgr_mode (nargs, arg);
3367 break; 2955 break;
3374 break; 2962 break;
3375 case 6: /* CPR requested */ 2963 case 6: /* CPR requested */
3376 scr_report_position (); 2964 scr_report_position ();
3377 break; 2965 break;
3378 case 7: /* unofficial extension */ 2966 case 7: /* unofficial extension */
3379 if (options & Opt_insecure) 2967 if (option (Opt_insecure))
3380 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2968 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3381 break; 2969 break;
3382 case 8: /* unofficial extension */ 2970 case 8: /* unofficial extension */
3383 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2971 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3384 break; 2972 break;
3451 break; 3039 break;
3452 case CSI_75: 3040 case CSI_75:
3453 scr_cursor (RESTORE); 3041 scr_cursor (RESTORE);
3454 break; 3042 break;
3455 3043
3456#if ENABLE_FRILLS 3044#if !ENABLE_MINIMAL
3457 case CSI_74: 3045 case CSI_74:
3458 process_window_ops (arg, nargs); 3046 process_window_ops (arg, nargs);
3459 break; 3047 break;
3460#endif 3048#endif
3461 3049
3468 break; 3056 break;
3469 } 3057 }
3470} 3058}
3471/*}}} */ 3059/*}}} */
3472 3060
3473#if ENABLE_FRILLS 3061#if !ENABLE_MINIMAL
3474/* ARGSUSED */ 3062/* ARGSUSED */
3475void 3063void
3476rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3064rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3477{ 3065{
3478 int x, y; 3066 int x, y;
3479 XWindowAttributes wattr; 3067 XWindowAttributes wattr;
3480 Window wdummy; 3068 Window wdummy;
3481 dDisp; 3069
3070 dLocal (Display *, dpy);
3482 3071
3483 if (nargs == 0) 3072 if (nargs == 0)
3484 return; 3073 return;
3485 3074
3486 switch (args[0]) 3075 switch (args[0])
3487 { 3076 {
3488 /* 3077 /*
3489 * commands 3078 * commands
3490 */ 3079 */
3491 case 1: /* deiconify window */ 3080 case 1: /* deiconify window */
3492 XMapWindow (disp, parent[0]); 3081 XMapWindow (dpy, parent[0]);
3493 break; 3082 break;
3494 case 2: /* iconify window */ 3083 case 2: /* iconify window */
3495 XIconifyWindow (disp, parent[0], display->screen); 3084 XIconifyWindow (dpy, parent[0], display->screen);
3496 break; 3085 break;
3497 case 3: /* set position (pixels) */ 3086 case 3: /* set position (pixels) */
3498 XMoveWindow (disp, parent[0], args[1], args[2]); 3087 XMoveWindow (dpy, parent[0], args[1], args[2]);
3499 break; 3088 break;
3500 case 4: /* set size (pixels) */ 3089 case 4: /* set size (pixels) */
3501 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3090 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3502 break; 3091 break;
3503 case 5: /* raise window */ 3092 case 5: /* raise window */
3504 XRaiseWindow (disp, parent[0]); 3093 XRaiseWindow (dpy, parent[0]);
3505 break; 3094 break;
3506 case 6: /* lower window */ 3095 case 6: /* lower window */
3507 XLowerWindow (disp, parent[0]); 3096 XLowerWindow (dpy, parent[0]);
3508 break; 3097 break;
3509 case 7: /* refresh window */ 3098 case 7: /* refresh window */
3510 scr_touch (true); 3099 scr_touch (true);
3511 break; 3100 break;
3512 case 8: /* set size (chars) */ 3101 case 8: /* set size (chars) */
3519 if (args[0] >= 24) /* set height (chars) */ 3108 if (args[0] >= 24) /* set height (chars) */
3520 set_widthheight ((unsigned int)width, 3109 set_widthheight ((unsigned int)width,
3521 (unsigned int) (args[1] * fheight)); 3110 (unsigned int) (args[1] * fheight));
3522 break; 3111 break;
3523 3112
3524
3525 /* 3113 /*
3526 * reports - some output format copied from XTerm 3114 * reports - some output format copied from XTerm
3527 */ 3115 */
3528 case 11: /* report window state */ 3116 case 11: /* report window state */
3529 XGetWindowAttributes (disp, parent[0], &wattr); 3117 XGetWindowAttributes (dpy, parent[0], &wattr);
3530 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3118 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3531 break; 3119 break;
3532 case 13: /* report window position */ 3120 case 13: /* report window position */
3533 XGetWindowAttributes (disp, parent[0], &wattr); 3121 XGetWindowAttributes (dpy, parent[0], &wattr);
3534 XTranslateCoordinates (disp, parent[0], wattr.root, 3122 XTranslateCoordinates (dpy, parent[0], wattr.root,
3535 -wattr.border_width, -wattr.border_width, 3123 -wattr.border_width, -wattr.border_width,
3536 &x, &y, &wdummy); 3124 &x, &y, &wdummy);
3537 tt_printf ("\033[3;%d;%dt", x, y); 3125 tt_printf ("\033[3;%d;%dt", x, y);
3538 break; 3126 break;
3539 case 14: /* report window size (pixels) */ 3127 case 14: /* report window size (pixels) */
3540 XGetWindowAttributes (disp, parent[0], &wattr); 3128 XGetWindowAttributes (dpy, parent[0], &wattr);
3541 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3129 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3542 break; 3130 break;
3543 case 18: /* report text area size (chars) */ 3131 case 18: /* report text area size (chars) */
3544 tt_printf ("\033[8;%d;%dt", nrow, ncol); 3132 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3545 break; 3133 break;
3547 tt_printf ("\033[9;%d;%dt", nrow, ncol); 3135 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3548 break; 3136 break;
3549 case 20: /* report icon label */ 3137 case 20: /* report icon label */
3550 { 3138 {
3551 char *s; 3139 char *s;
3552 XGetIconName (disp, parent[0], &s); 3140 XGetIconName (dpy, parent[0], &s);
3553 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3141 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3554 XFree (s); 3142 XFree (s);
3555 } 3143 }
3556 break; 3144 break;
3557 case 21: /* report window title */ 3145 case 21: /* report window title */
3558 { 3146 {
3559 char *s; 3147 char *s;
3560 XFetchName (disp, parent[0], &s); 3148 XFetchName (dpy, parent[0], &s);
3561 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3149 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3562 XFree (s); 3150 XFree (s);
3563 } 3151 }
3564 break; 3152 break;
3565 } 3153 }
3566} 3154}
3569/*----------------------------------------------------------------------*/ 3157/*----------------------------------------------------------------------*/
3570/* 3158/*
3571 * get input up until STRING TERMINATOR (or BEL) 3159 * get input up until STRING TERMINATOR (or BEL)
3572 * ends_how is terminator used. returned input must be free()'d 3160 * ends_how is terminator used. returned input must be free()'d
3573 */ 3161 */
3574unsigned char * 3162char *
3575rxvt_term::get_to_st (unicode_t &ends_how) 3163rxvt_term::get_to_st (unicode_t &ends_how)
3576{ 3164{
3577 unicode_t ch; 3165 unicode_t ch;
3578 bool seen_esc = false; 3166 bool seen_esc = false;
3579 unsigned int n = 0; 3167 unsigned int n = 0;
3593 seen_esc = true; 3181 seen_esc = true;
3594 continue; 3182 continue;
3595 } 3183 }
3596 else if (ch == C0_BEL || ch == CHAR_ST) 3184 else if (ch == C0_BEL || ch == CHAR_ST)
3597 break; 3185 break;
3186 else if (ch == C0_SYN)
3187 ch = cmd_get8 ();
3598 else if (ch < 0x20) 3188 else if (ch < 0x20)
3599 return NULL; /* other control character - exit */ 3189 return NULL; /* other control character - exit */
3600 3190
3601 seen_esc = false; 3191 seen_esc = false;
3602 3192
3603 if (n >= STRING_MAX - 1) 3193 if (n >= STRING_MAX - 1)
3604 // stop at some sane length 3194 // stop at some sane length
3605 return NULL; 3195 return NULL;
3606 3196
3607 if (ch == C0_SYN)
3608 string[n++] = cmd_get8 ();
3609 else
3610 string[n++] = ch; 3197 string[n++] = ch;
3611 } 3198 }
3612 3199
3613 string[n++] = '\0'; 3200 string[n++] = '\0';
3614 3201
3615 ends_how = (ch == 0x5c ? C0_ESC : ch); 3202 ends_how = (ch == 0x5c ? C0_ESC : ch);
3616 3203
3617 return (unsigned char *)rxvt_wcstombs (string); 3204 return rxvt_wcstombs (string);
3618} 3205}
3619 3206
3620/*----------------------------------------------------------------------*/ 3207/*----------------------------------------------------------------------*/
3621/* 3208/*
3622 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3209 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3623 */ 3210 */
3624void 3211void
3625rxvt_term::process_dcs_seq () 3212rxvt_term::process_dcs_seq ()
3626{ 3213{
3627 unsigned char *s; 3214 char *s;
3628 unicode_t eh; 3215 unicode_t eh;
3629 3216
3630 /* 3217 /*
3631 * Not handled yet 3218 * Not handled yet
3632 */ 3219 */
3651 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3238 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3652 arg = arg * 10 + (ch - '0'); 3239 arg = arg * 10 + (ch - '0');
3653 3240
3654 if (ch == ';') 3241 if (ch == ';')
3655 { 3242 {
3656 unsigned char *s = get_to_st (eh); 3243 char *s = get_to_st (eh);
3657 3244
3658 if (s) 3245 if (s)
3659 { 3246 {
3660 process_xterm_seq (arg, (char *)s, eh); 3247 process_xterm_seq (arg, s, eh);
3661 free (s); 3248 free (s);
3662 } 3249 }
3663 } 3250 }
3664} 3251}
3665 3252
3666void 3253void
3667rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3254rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3668{ 3255{
3669 if (str[0] == '?' && !str[1]) 3256 if (str[0] == '?' && !str[1])
3670 { 3257 {
3671 unsigned short r, g, b; 3258 rgba c;
3672 pix_colors_focused[color].get (display, r, g, b); 3259 pix_colors_focused[color].get (c);
3260
3261#if XFT
3262 if (c.a != rgba::MAX_CC)
3263 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3264 else
3265#endif
3673 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3266 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3674 } 3267 }
3675 else 3268 else
3676 set_window_color (color, str); 3269 set_window_color (color, str);
3677} 3270}
3678 3271
3679/* 3272/*
3680 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3273 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3681 */ 3274 */
3682void 3275void
3683rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3276rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3684{ 3277{
3685 int changed = 0;
3686 int color; 3278 int color;
3687 char *buf, *name; 3279 char *buf, *name;
3688 bool query = str[0] == '?' && !str[1]; 3280 bool query = str[0] == '?' && !str[1];
3689 int saveop = op; 3281 int saveop = op;
3690 dDisp; 3282
3283 dLocal (Display *, dpy);
3691 3284
3692 assert (str != NULL); 3285 assert (str != NULL);
3286
3287 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3288 return;
3289
3693 switch (op) 3290 switch (op)
3694 { 3291 {
3695 case XTerm_name: 3292 case XTerm_name:
3696 set_title (str); 3293 set_title (str);
3697 /* FALLTHROUGH */ 3294 /* FALLTHROUGH */
3711 unsigned long bytes_after; 3308 unsigned long bytes_after;
3712 unsigned char *value = 0; 3309 unsigned char *value = 0;
3713 const char *str = ""; 3310 const char *str = "";
3714 3311
3715 if (prop 3312 if (prop
3716 && XGetWindowProperty (disp, parent[0], 3313 && XGetWindowProperty (dpy, parent[0],
3717 prop, 0, 1<<16, 0, AnyPropertyType, 3314 prop, 0, 1<<16, 0, AnyPropertyType,
3718 &actual_type, &actual_format, 3315 &actual_type, &actual_format,
3719 &nitems, &bytes_after, &value) == Success 3316 &nitems, &bytes_after, &value) == Success
3720 && actual_type != None 3317 && actual_type != None
3721 && actual_format == 8) 3318 && actual_format == 8)
3722 str = (const char *)(value); 3319 str = (const char *)(value);
3723 3320
3724 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3321 tt_printf ("\033]%d;%s%c", op, str, resp);
3725 3322
3726 XFree (value); 3323 XFree (value);
3727 } 3324 }
3728 else 3325 else
3729 { 3326 {
3733 { 3330 {
3734 *eq = 0; 3331 *eq = 0;
3735 set_utf8_property (display->atom (str), eq + 1); 3332 set_utf8_property (display->atom (str), eq + 1);
3736 } 3333 }
3737 else 3334 else
3738 XDeleteProperty (disp, parent[0], 3335 XDeleteProperty (dpy, parent[0],
3739 display->atom (str)); 3336 display->atom (str));
3740 } 3337 }
3741 break; 3338 break;
3742 3339
3743 case XTerm_Color: 3340 case XTerm_Color:
3745 { 3342 {
3746 if ((name = strchr (buf, ';')) == NULL) 3343 if ((name = strchr (buf, ';')) == NULL)
3747 break; 3344 break;
3748 3345
3749 *name++ = '\0'; 3346 *name++ = '\0';
3750 color = atoi (buf); 3347 color = atoi (buf) + minCOLOR;
3751 3348
3752 if (color < 0 || color >= TOTAL_COLORS) 3349 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3753 break; 3350 break;
3754 3351
3755 if ((buf = strchr (name, ';')) != NULL) 3352 if ((buf = strchr (name, ';')) != NULL)
3756 *buf++ = '\0'; 3353 *buf++ = '\0';
3757 3354
3758 if (name[0] == '?' && !name[1]) 3355 process_color_seq (op, color, name, resp);
3759 {
3760 unsigned short r, g, b;
3761 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3762 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3763 }
3764 else
3765 set_window_color (color + minCOLOR, name);
3766 } 3356 }
3767 break; 3357 break;
3768 case XTerm_Color00: 3358 case XTerm_Color00:
3769 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3359 process_color_seq (op, Color_fg, str, resp);
3770 break; 3360 break;
3771 case XTerm_Color01: 3361 case XTerm_Color01:
3772 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3362 process_color_seq (op, Color_bg, str, resp);
3773 break; 3363 break;
3774#ifndef NO_CURSORCOLOR 3364#ifndef NO_CURSORCOLOR
3775 case XTerm_Color_cursor: 3365 case XTerm_Color_cursor:
3776 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3366 process_color_seq (op, Color_cursor, str, resp);
3777 break; 3367 break;
3778#endif 3368#endif
3779 case XTerm_Color_pointer_fg: 3369 case XTerm_Color_pointer_fg:
3780 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3370 process_color_seq (op, Color_pointer_fg, str, resp);
3781 break; 3371 break;
3782 case XTerm_Color_pointer_bg: 3372 case XTerm_Color_pointer_bg:
3783 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3373 process_color_seq (op, Color_pointer_bg, str, resp);
3784 break; 3374 break;
3785#ifndef NO_BOLD_UNDERLINE_REVERSE 3375#ifndef NO_BOLD_UNDERLINE_REVERSE
3786 case XTerm_Color_BD:
3787 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3788 break;
3789 case XTerm_Color_UL:
3790 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3791 break;
3792 case XTerm_Color_RV: 3376 case XTerm_Color_RV:
3793 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3377 process_color_seq (op, Color_RV, str, resp);
3378 break;
3379 case Rxvt_Color_BD:
3380 case URxvt_Color_BD:
3381 process_color_seq (op, Color_BD, str, resp);
3382 break;
3383 case Rxvt_Color_UL:
3384 case URxvt_Color_UL:
3385 process_color_seq (op, Color_UL, str, resp);
3794 break; 3386 break;
3795 case URxvt_Color_IT: 3387 case URxvt_Color_IT:
3796 process_color_seq (URxvt_Color_IT, Color_IT, str, resp); 3388 process_color_seq (op, Color_IT, str, resp);
3797 break; 3389 break;
3798#endif 3390#endif
3799#if TRANSPARENT && TINTING 3391#if ENABLE_TRANSPARENCY
3800 case URxvt_Color_tint: 3392 case URxvt_Color_tint:
3801 process_color_seq (URxvt_Color_tint, Color_tint, str, resp); 3393 process_color_seq (op, Color_tint, str, resp);
3802 check_our_parents (); 3394 {
3803 if (am_transparent) 3395 bool changed = false;
3804 want_full_refresh = want_refresh = 1;
3805 break;
3806#endif
3807 3396
3397 if (ISSET_PIXCOLOR (Color_tint))
3398 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3399 else
3400 changed = bgPixmap.unset_tint ();
3401
3402 if (changed)
3403 update_background ();
3404 }
3405
3406 break;
3407#endif
3408
3409#if BG_IMAGE_FROM_FILE
3808 case XTerm_Pixmap: 3410 case Rxvt_Pixmap:
3809 if (*str != ';') 3411 if (!strcmp (str, "?"))
3810 { 3412 {
3811#if XPM_BACKGROUND 3413 char str[256];
3812 scale_pixmap (""); /* reset to default scaling */ 3414
3813 set_bgPixmap (str); /* change pixmap */ 3415 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
3814#endif 3416 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3815 scr_touch (true); 3417 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3418 process_xterm_seq (XTerm_title, str, CHAR_ST);
3816 } 3419 }
3817 while ((str = strchr (str, ';')) != NULL) 3420 else
3818 { 3421 {
3422 int changed = 0;
3423
3424 if (*str != ';')
3425 {
3426 /* reset to default scaling :*/
3427 bgPixmap.unset_geometry ();
3428 if (bgPixmap.set_file (str)) /* change pixmap */
3429 changed++;
3430 str = strchr (str, ';');
3431 if (str == NULL)
3432 bgPixmap.set_defaultGeometry ();
3433 }
3434
3435 while (str)
3436 {
3819 str++; 3437 str++;
3820#if XPM_BACKGROUND 3438 if (bgPixmap.set_geometry (str))
3821 changed += scale_pixmap (str); 3439 changed++;
3822#endif 3440 str = strchr (str, ';');
3441 }
3442
3443 if (changed)
3444 update_background ();
3823 } 3445 }
3824
3825 if (changed)
3826 {
3827#ifdef XPM_BACKGROUND
3828 resize_pixmap ();
3829#endif
3830 scr_touch (true);
3831 }
3832 break; 3446 break;
3447#endif
3833 3448
3834 case XTerm_restoreFG: 3449 case Rxvt_restoreFG:
3835 set_window_color (Color_fg, str); 3450 set_window_color (Color_fg, str);
3836 break; 3451 break;
3837 case XTerm_restoreBG: 3452 case Rxvt_restoreBG:
3838 set_window_color (Color_bg, str); 3453 set_window_color (Color_bg, str);
3839 break; 3454 break;
3840 3455
3841 case XTerm_logfile: 3456 case XTerm_logfile:
3842 // TODO, when secure mode? 3457 // TODO, when secure mode?
3843 break; 3458 break;
3844 3459
3845#ifdef MENUBAR
3846 case URxvt_Menu:
3847 if (options & Opt_insecure)
3848 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3849 break;
3850#endif
3851#if 0 3460#if 0
3852 case XTerm_dumpscreen: /* no error notices */ 3461 case Rxvt_dumpscreen: /* no error notices */
3853 { 3462 {
3854 int fd; 3463 int fd;
3855 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3464 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3856 { 3465 {
3857 scr_dump (fd); 3466 scr_dump (fd);
3868 case URxvt_italicFont: 3477 case URxvt_italicFont:
3869 case URxvt_boldItalicFont: 3478 case URxvt_boldItalicFont:
3870#endif 3479#endif
3871 if (query) 3480 if (query)
3872 tt_printf ("\33]%d;%-.250s%c", saveop, 3481 tt_printf ("\33]%d;%-.250s%c", saveop,
3873 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3482 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3874 ? fontset[op - URxvt_font]->fontdesc : "", 3483 ? fontset[op - URxvt_font]->fontdesc : "",
3875 resp); 3484 resp);
3876 else 3485 else
3877 { 3486 {
3878 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3487 const char *&res = rs[Rs_font + (op - URxvt_font)];
3881 allocated.push_back ((void *)res); 3490 allocated.push_back ((void *)res);
3882 set_fonts (); 3491 set_fonts ();
3883 } 3492 }
3884 break; 3493 break;
3885 3494
3886#if ENABLE_FRILLS 3495 case URxvt_version:
3496 if (query)
3497 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3498 op,
3499 rs[Rs_name], VERSION[0], VERSION[2],
3500 resp);
3501 break;
3502
3503#if !ENABLE_MINIMAL
3887 case URxvt_locale: 3504 case URxvt_locale:
3888 if (query) 3505 if (query)
3889 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp); 3506 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3890 else 3507 else
3891 { 3508 {
3892 set_locale (str); 3509 set_locale (str);
3893 pty.set_utf8_mode (enc_utf8); 3510 pty->set_utf8_mode (enc_utf8);
3894 init_xlocale (); 3511 init_xlocale ();
3895 } 3512 }
3896 break; 3513 break;
3897 3514
3898 case URxvt_view_up: 3515 case URxvt_view_up:
3899 case URxvt_view_down: 3516 case URxvt_view_down:
3517 {
3900 int lines = atoi (str); 3518 int lines = atoi (str);
3901 3519
3902 if (lines) 3520 if (lines)
3903 scr_page (op == URxvt_view_up ? UP : DN, lines); 3521 scr_page (op == URxvt_view_up ? UP : DN, lines);
3904 else 3522 else
3905 {
3906 scr_erase_savelines (); 3523 scr_erase_savelines ();
3907 } 3524 }
3908 3525
3526 break;
3527#endif
3528
3529#if ENABLE_PERL
3530 case URxvt_perl:
3531 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END)))
3532 ; // no responses yet
3909 break; 3533 break;
3910#endif 3534#endif
3911 } 3535 }
3912} 3536}
3913/*----------------------------------------------------------------------*/ 3537/*----------------------------------------------------------------------*/
3944 return state; 3568 return state;
3945} 3569}
3946 3570
3947/* we're not using priv _yet_ */ 3571/* we're not using priv _yet_ */
3948void 3572void
3949rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3573rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3950{ 3574{
3951 unsigned int i, j; 3575 unsigned int i, j;
3952 int state; 3576 int state;
3953 3577
3954 static const struct 3578 static const struct
3955 { 3579 {
3956 const int argval; 3580 const int argval;
3957 const unsigned long bit; 3581 const unsigned long bit;
3958 }
3959
3960 argtopriv[] = { 3582 } argtopriv[] = {
3961 { 1, PrivMode_aplCUR }, 3583 { 1, PrivMode_aplCUR },
3962 { 2, PrivMode_vt52 }, 3584 { 2, PrivMode_vt52 },
3963 { 3, PrivMode_132 }, 3585 { 3, PrivMode_132 },
3964 { 4, PrivMode_smoothScroll }, 3586 { 4, PrivMode_smoothScroll },
3965 { 5, PrivMode_rVideo }, 3587 { 5, PrivMode_rVideo },
3966 { 6, PrivMode_relOrigin }, 3588 { 6, PrivMode_relOrigin },
3967 { 7, PrivMode_Autowrap }, 3589 { 7, PrivMode_Autowrap },
3968 // 8, bi-directional support mode 3590 // 8, bi-directional support mode
3969 { 9, PrivMode_MouseX10 }, 3591 { 9, PrivMode_MouseX10 },
3970#ifdef menuBar_esc
3971 { menuBar_esc, PrivMode_menuBar },
3972#endif
3973 // 18, 19 printing-related 3592 // 18, 19 printing-related
3974 { 25, PrivMode_VisibleCursor }, 3593 { 25, PrivMode_VisibleCursor },
3975#ifdef scrollBar_esc 3594#ifdef scrollBar_esc
3976 { scrollBar_esc, PrivMode_scrollBar }, 3595 { scrollBar_esc, PrivMode_scrollBar },
3977#endif 3596#endif
3984 { 66, PrivMode_aplKP }, 3603 { 66, PrivMode_aplKP },
3985#ifndef NO_BACKSPACE_KEY 3604#ifndef NO_BACKSPACE_KEY
3986 { 67, PrivMode_BackSpace }, 3605 { 67, PrivMode_BackSpace },
3987#endif 3606#endif
3988 { 1000, PrivMode_MouseX11 }, 3607 { 1000, PrivMode_MouseX11 },
3989 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3608 { 1002, PrivMode_MouseBtnEvent },
3990 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3609 { 1003, PrivMode_MouseAnyEvent },
3991 // 1003 Use All Motion Mouse Tracking. NYI, TODO
3992 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3610 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3993 { 1011, PrivMode_Keypress }, // rxvt extension 3611 { 1011, PrivMode_Keypress }, // rxvt extension
3994 // 1035 enable modifiers for alt, numlock NYI 3612 // 1035 enable modifiers for alt, numlock NYI
3995 // 1036 send ESC for meta keys NYI 3613 // 1036 send ESC for meta keys NYI
3996 // 1037 send DEL for keypad delete NYI 3614 // 1037 send DEL for keypad delete NYI
4022 } 3640 }
4023 3641
4024 /* extra handling for values with state unkept */ 3642 /* extra handling for values with state unkept */
4025 switch (arg[i]) 3643 switch (arg[i])
4026 { 3644 {
3645#if ENABLE_STYLES
3646 case 1021:
3647 set_option (Opt_intensityStyles, mode);
3648
3649 scr_touch (true);
3650 break;
3651#endif
4027 case 1048: /* alternative cursor save */ 3652 case 1048: /* alternative cursor save */
4028 case 1049: 3653 case 1049:
4029 if (options & Opt_secondaryScreen) 3654 if (option (Opt_secondaryScreen))
4030 if (mode == 0) 3655 if (mode == 0)
4031 scr_cursor (RESTORE); 3656 scr_cursor (RESTORE);
4032 else if (mode == 1) 3657 else if (mode == 1)
4033 scr_cursor (SAVE); 3658 scr_cursor (SAVE);
4034 break; 3659 break;
4049 case 3: /* 80/132 */ 3674 case 3: /* 80/132 */
4050 if (priv_modes & PrivMode_132OK) 3675 if (priv_modes & PrivMode_132OK)
4051 set_widthheight (((state ? 132 : 80) * fwidth), height); 3676 set_widthheight (((state ? 132 : 80) * fwidth), height);
4052 break; 3677 break;
4053 case 4: /* smooth scrolling */ 3678 case 4: /* smooth scrolling */
4054 if (state)
4055 options &= ~Opt_jumpScroll;
4056 else
4057 options |= Opt_jumpScroll; 3679 set_option (Opt_jumpScroll, !state);
4058 break; 3680 break;
4059 case 5: /* reverse video */ 3681 case 5: /* reverse video */
4060 scr_rvideo_mode (state); 3682 scr_rvideo_mode (state);
4061 break; 3683 break;
4062 case 6: /* relative/absolute origins */ 3684 case 6: /* relative/absolute origins */
4066 scr_autowrap (state); 3688 scr_autowrap (state);
4067 break; 3689 break;
4068 /* case 8: - auto repeat, can't do on a per window basis */ 3690 /* case 8: - auto repeat, can't do on a per window basis */
4069 case 9: /* X10 mouse reporting */ 3691 case 9: /* X10 mouse reporting */
4070 if (state) /* orthogonal */ 3692 if (state) /* orthogonal */
4071 priv_modes &= ~PrivMode_MouseX11; 3693 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4072 break; 3694 break;
4073#ifdef menuBar_esc
4074 case menuBar_esc:
4075#ifdef MENUBAR
4076 map_menuBar (state);
4077#endif
4078 break;
4079#endif
4080#ifdef scrollBar_esc 3695#ifdef scrollBar_esc
4081 case scrollBar_esc: 3696 case scrollBar_esc:
4082 if (scrollbar_mapping (state)) 3697 if (scrollbar_mapping (state))
4083 { 3698 {
4084 resize_all_windows (0, 0, 0); 3699 resize_all_windows (0, 0, 0);
4096 break; 3711 break;
4097 /* case 66: - application key pad */ 3712 /* case 66: - application key pad */
4098 /* case 67: - backspace key */ 3713 /* case 67: - backspace key */
4099 case 1000: /* X11 mouse reporting */ 3714 case 1000: /* X11 mouse reporting */
4100 if (state) /* orthogonal */ 3715 if (state) /* orthogonal */
4101 priv_modes &= ~PrivMode_MouseX10; 3716 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4102 break; 3717 break;
4103#if 0
4104 case 1001: 3718 case 1002:
4105 break; /* X11 mouse highlighting */ 3719 case 1003:
4106#endif 3720 if (state)
3721 {
3722 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3723 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3724 vt_emask_mouse = PointerMotionMask;
3725 }
3726 else
3727 vt_emask_mouse = NoEventMask;
3728 vt_select_input ();
3729 break;
4107 case 1010: /* scroll to bottom on TTY output inhibit */ 3730 case 1010: /* scroll to bottom on TTY output inhibit */
4108 if (state)
4109 options &= ~Opt_scrollTtyOutput;
4110 else
4111 options |= Opt_scrollTtyOutput; 3731 set_option (Opt_scrollTtyOutput, !state);
4112 break; 3732 break;
4113 case 1011: /* scroll to bottom on key press */ 3733 case 1011: /* scroll to bottom on key press */
4114 if (state)
4115 options |= Opt_scrollTtyKeypress; 3734 set_option (Opt_scrollTtyKeypress, state);
4116 else
4117 options &= ~Opt_scrollTtyKeypress;
4118 break; 3735 break;
4119 case 1047: /* secondary screen w/ clearing last */ 3736 case 1047: /* secondary screen w/ clearing last */
4120 if (options & Opt_secondaryScreen) 3737 if (option (Opt_secondaryScreen))
4121 if (current_screen != PRIMARY) 3738 if (current_screen != PRIMARY)
4122 scr_erase_screen (2); 3739 scr_erase_screen (2);
4123 scr_change_screen (state); 3740 scr_change_screen (state);
4124 break; 3741 break;
4125 case 1049: /* secondary screen w/ clearing first */ 3742 case 1049: /* secondary screen w/ clearing first */
4126 scr_change_screen (state); 3743 scr_change_screen (state);
4127 if (options & Opt_secondaryScreen) 3744 if (option (Opt_secondaryScreen))
4128 if (current_screen != PRIMARY) 3745 if (current_screen != PRIMARY)
4129 scr_erase_screen (2); 3746 scr_erase_screen (2);
4130 break; 3747 break;
4131 default: 3748 default:
4132 break; 3749 break;
4260 scr_color (Color_bg, Color_bg); 3877 scr_color (Color_bg, Color_bg);
4261 break; 3878 break;
4262 3879
4263 //case 50: // not variable spacing 3880 //case 50: // not variable spacing
4264 3881
4265#ifndef NO_BRIGHTCOLOR 3882#if !ENABLE_MINIMAL
4266 case 90: 3883 case 90:
4267 case 91: /* set bright fg color */ 3884 case 91: /* set bright fg color */
4268 case 92: 3885 case 92:
4269 case 93: 3886 case 93:
4270 case 94: 3887 case 94:
4282 case 106: 3899 case 106:
4283 case 107: 3900 case 107:
4284 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 3901 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4285 break; 3902 break;
4286#endif 3903#endif
4287
4288 } 3904 }
4289 } 3905 }
4290} 3906}
4291/*}}} */ 3907/*}}} */
4292 3908
4295rxvt_term::process_graphics () 3911rxvt_term::process_graphics ()
4296{ 3912{
4297 unicode_t ch, cmd = cmd_getc (); 3913 unicode_t ch, cmd = cmd_getc ();
4298 3914
4299 if (cmd == 'Q') 3915 if (cmd == 'Q')
3916 {
4300 { /* query graphics */ 3917 /* query graphics */
4301 tt_printf ("\033G0\012"); /* no graphics */ 3918 tt_printf ("\033G0\012"); /* no graphics */
4302 return; 3919 return;
4303 } 3920 }
4304 /* swallow other graphics sequences until terminating ':' */ 3921 /* swallow other graphics sequences until terminating ':' */
4305 do 3922 do
4316 */ 3933 */
4317void 3934void
4318rxvt_term::tt_printf (const char *fmt,...) 3935rxvt_term::tt_printf (const char *fmt,...)
4319{ 3936{
4320 va_list arg_ptr; 3937 va_list arg_ptr;
4321 unsigned char buf[256]; 3938 char buf[256];
4322 3939
4323 va_start (arg_ptr, fmt); 3940 va_start (arg_ptr, fmt);
4324 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 3941 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4325 va_end (arg_ptr); 3942 va_end (arg_ptr);
4326 tt_write (buf, strlen (buf)); 3943 tt_write (buf, strlen (buf));
4331 * or generated by us in response to a query ESC sequence. 3948 * or generated by us in response to a query ESC sequence.
4332 */ 3949 */
4333const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 3950const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4334 3951
4335void 3952void
4336rxvt_term::tt_write (const unsigned char *data, unsigned int len) 3953rxvt_term::tt_write (const char *data, unsigned int len)
4337{ 3954{
3955 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
3956 return;
3957
3958 if (pty->pty < 0)
3959 return;
3960
4338 if (v_buflen == 0) 3961 if (v_buflen == 0)
4339 { 3962 {
4340 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 3963 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4341 3964
4342 if ((unsigned int)written == len) 3965 if ((unsigned int)written == len)
4343 return; 3966 return;
4344 3967
4345 data += written; 3968 data += written;
4346 len -= written; 3969 len -= written;
4347 } 3970 }
4348 3971
4349 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 3972 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4350 3973
4351 memcpy (v_buffer + v_buflen, data, len); 3974 memcpy (v_buffer + v_buflen, data, len);
4352 v_buflen += len; 3975 v_buflen += len;
4353 3976
4354 pty_ev.set (EVENT_READ | EVENT_WRITE); 3977 pty_ev.set (ev::READ | ev::WRITE);
4355} 3978}
4356 3979
4357void rxvt_term::pty_write () 3980void rxvt_term::pty_write ()
4358{ 3981{
4359 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 3982 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4360 3983
4361 if (written > 0) 3984 if (written > 0)
4362 { 3985 {
4363 v_buflen -= written; 3986 v_buflen -= written;
4364 3987
4365 if (v_buflen == 0) 3988 if (v_buflen == 0)
4366 { 3989 {
4367 free (v_buffer); 3990 free (v_buffer);
4368 v_buffer = 0; 3991 v_buffer = 0;
4369 v_buflen = 0;
4370 3992
4371 pty_ev.set (EVENT_READ); 3993 pty_ev.set (ev::READ);
4372 return; 3994 return;
4373 } 3995 }
4374 3996
4375 memmove (v_buffer, v_buffer + written, v_buflen); 3997 memmove (v_buffer, v_buffer + written, v_buflen);
4376 } 3998 }
4377 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 3999 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4378 // original code just ignores this... 4000 pty_ev.set (ev::READ);
4379 destroy ();
4380} 4001}
4381 4002
4382/*----------------------- end-of-file (C source) -----------------------*/ 4003/*----------------------- end-of-file (C source) -----------------------*/
4383 4004

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines