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.302 by root, Tue Jan 31 21:35:39 2006 UTC vs.
Revision 1.454 by sf-exg, Sat Aug 21 16:07:15 2010 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-2006 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com>
31 * Copyright (c) 2007 Emanuele Giaquinta <e.giaquinta@glauco.it>
31 * 32 *
32 * This program is free software; you can redistribute it and/or modify 33 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by 34 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or 35 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version. 36 * (at your option) any later version.
55# include "keyboard.h" 56# include "keyboard.h"
56#endif 57#endif
57 58
58#include <csignal> 59#include <csignal>
59 60
61#if LINUX_YIELD_HACK
62# include <ctime>
63#endif
64
60/*----------------------------------------------------------------------*/ 65/*----------------------------------------------------------------------*/
61 66
62#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 67#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
63 68
64#if ENABLE_FRILLS || ISO_14755 69#if ENABLE_FRILLS || ISO_14755
91 XK_Shift_L, 0x21e7, 96 XK_Shift_L, 0x21e7,
92 XK_Shift_R, 0x21e7, 97 XK_Shift_R, 0x21e7,
93 98
94 XK_Shift_Lock, 0x21eb, 99 XK_Shift_Lock, 0x21eb,
95 XK_ISO_Lock, 0x21eb, 100 XK_ISO_Lock, 0x21eb,
96 XK_ISO_Lock, 0x21eb,
97 XK_Caps_Lock, 0x21ec, 101 XK_Caps_Lock, 0x21ec,
98 XK_Num_Lock, 0x21ed, 102 XK_Num_Lock, 0x21ed,
99 XK_ISO_Level3_Shift, 0x21ee, 103 XK_ISO_Level3_Shift, 0x21ee,
100 XK_ISO_Level3_Lock, 0x21ef, 104 XK_ISO_Level3_Lock, 0x21ef,
101 XK_ISO_Group_Lock, 0x21f0, 105 XK_ISO_Group_Lock, 0x21f0,
158 162
159void 163void
160rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) 164rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
161{ 165{
162 rxvt_fontset *fs = FONTSET (r); 166 rxvt_fontset *fs = FONTSET (r);
163 rxvt_font *f = (*fs)[fs->find_font (ch)];
164 wchar_t *chr, *alloc, ch2, *fname; 167 wchar_t *chr, *alloc, ch2, **fname;
165 int len; 168 int len;
166
167 fname = rxvt_utf8towcs (f->name);
168 169
169# if ENABLE_COMBINING 170# if ENABLE_COMBINING
170 if (IS_COMPOSE (ch)) 171 if (IS_COMPOSE (ch))
171 { 172 {
172 len = rxvt_composite.expand (ch, 0); 173 len = rxvt_composite.expand (ch, 0);
193 r & RS_Blink ? " blink" : "", 194 r & RS_Blink ? " blink" : "",
194 r & RS_RVid ? " rvid" : "", 195 r & RS_RVid ? " rvid" : "",
195 r & RS_Uline ? " uline" : "", 196 r & RS_Uline ? " uline" : "",
196 r & RS_Careful ? " careful" : ""); 197 r & RS_Careful ? " careful" : "");
197 198
199 int width = 0;
200 fname = rxvt_temp_buf<wchar_t *> (len);
201 for (int i = 0; i < len; i++)
202 {
203 rxvt_font *f = (*fs)[fs->find_font_idx (chr[i])];
204 fname[i] = rxvt_utf8towcs (f->name);
198 int width = wcswidth (fname, wcslen (fname)); 205 max_it (width, wcswidth (fname[i], wcslen (fname[i])));
206 }
199 207
200 max_it (width, 8+5); // for char + hey 208 max_it (width, 8+5); // for char + hex
201 max_it (width, strlen (attr)); 209 max_it (width, strlen (attr));
202 210
203 if (y >= 0) 211 if (y >= 0)
204 { 212 {
205 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; 213 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
206 x = 0; 214 x = 0;
207 } 215 }
208 216
209 scr_overlay_new (x, y, width, len + 2); 217 scr_overlay_new (x, y, width, len * 2 + 1);
210 218
211 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 219 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
212 220
213 for (int y = 0; y < len; y++) 221 for (int y = 0; y < len; y++)
214 { 222 {
217 ch = *chr++; 225 ch = *chr++;
218 226
219 sprintf (buf, "%8x", ch); 227 sprintf (buf, "%8x", ch);
220 scr_overlay_set (0, y, buf); 228 scr_overlay_set (0, y, buf);
221 scr_overlay_set (9, y, '='); 229 scr_overlay_set (9, y, '=');
222# if !UNICODE3 230# if !UNICODE_3
223 if (ch >= 0x10000) 231 if (ch >= 0x10000)
224 ch = 0xfffd; 232 ch = 0xfffd;
225# endif 233# endif
226 scr_overlay_set (11, y, ch, r); 234 scr_overlay_set (11, y, ch, r);
227 235
233// char buf[4+4+3+1]; 241// char buf[4+4+3+1];
234// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y); 242// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y);
235// scr_overlay_set (0, 0, buf); 243// scr_overlay_set (0, 0, buf);
236// } 244// }
237 scr_overlay_set (0, len , attr); 245 scr_overlay_set (0, len , attr);
246 for (int i = 0; i < len; i++)
247 {
238 scr_overlay_set (0, len + 1, fname); 248 scr_overlay_set (0, len + 1 + i, fname[i]);
239
240 free (fname); 249 free (fname[i]);
250 }
241 251
242# if ENABLE_COMBINING 252# if ENABLE_COMBINING
243 if (alloc) 253 if (alloc)
244 delete [] alloc; 254 delete [] alloc;
245# endif 255# endif
275 } 285 }
276 286
277 iso14755buf = 0; 287 iso14755buf = 0;
278} 288}
279 289
280int 290static int
281rxvt_term::hex_keyval (XKeyEvent &ev) 291hex_keyval (XKeyEvent &ev)
282{ 292{
283 // check wether this event corresponds to a hex digit 293 // check whether this event corresponds to a hex digit
284 // if the modifiers had not been pressed. 294 // if the modifiers had not been pressed.
285 for (int index = 0; index < 8; index++) 295 for (int index = 0; index < 8; index++)
286 { 296 {
287 KeySym k = XLookupKeysym (&ev, index); 297 KeySym k = XLookupKeysym (&ev, index);
288 298
294 304
295 return -1; 305 return -1;
296} 306}
297#endif 307#endif
298 308
299/*{{{ Convert the keypress event into a string */ 309static inline KeySym
310translate_keypad (KeySym keysym, bool kp)
311{
312#ifdef XK_KP_Home
313 static const KeySym keypadtrans[] = {
314 XK_KP_7, // XK_KP_Home
315 XK_KP_4, // XK_KP_Left
316 XK_KP_8, // XK_KP_Up
317 XK_KP_6, // XK_KP_Right
318 XK_KP_2, // XK_KP_Down
319# ifndef UNSHIFTED_SCROLLKEYS
320 XK_KP_9, // XK_KP_Prior
321 XK_KP_3, // XK_KP_Next
322# else
323 XK_Prior,
324 XK_Next,
325# endif
326 XK_KP_1, // XK_KP_End
327 XK_KP_5, // XK_KP_Begin
328 };
329
330 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin))
331 {
332 unsigned int index = keysym - XK_KP_Home;
333 keysym = kp ? keypadtrans[index] : XK_Home + index;
334 }
335 else if (keysym == XK_KP_Insert)
336 keysym = kp ? XK_KP_0 : XK_Insert;
337# ifndef NO_DELETE_KEY
338 else if (keysym == XK_KP_Delete)
339 keysym = kp ? XK_KP_Decimal : XK_Delete;
340# endif
341#endif
342 return keysym;
343}
344
345static inline int
346map_function_key (KeySym keysym)
347{
348 int param = 0;
349
350 if (IN_RANGE_INC (keysym, XK_F1, XK_F35))
351 {
352 param = 11 + keysym - XK_F1;
353 if (keysym >= XK_F17)
354 param += 4;
355 else if (keysym >= XK_F15)
356 param += 3;
357 else if (keysym >= XK_F11)
358 param += 2;
359 else if (keysym >= XK_F6)
360 param += 1;
361 }
362 else
363 switch (keysym)
364 {
365 case XK_Find:
366 param = 1;
367 break;
368 case XK_Insert:
369 param = 2;
370 break;
371#ifdef DXK_Remove
372 case DXK_Remove:
373#endif
374 case XK_Execute:
375 param = 3;
376 break;
377 case XK_Select:
378 param = 4;
379 break;
380#ifndef UNSHIFTED_SCROLLKEYS
381 case XK_Prior:
382 param = 5;
383 break;
384 case XK_Next:
385 param = 6;
386 break;
387 case XK_Home:
388 param = 7;
389 break;
390 case XK_End:
391 param = 8;
392 break;
393#endif
394 case XK_Help:
395 param = 28;
396 break;
397 case XK_Menu:
398 param = 29;
399 break;
400 }
401 return param;
402}
403
300void 404void
301rxvt_term::lookup_key (XKeyEvent &ev) 405rxvt_term::key_press (XKeyEvent &ev)
302{ 406{
303 int ctrl, meta, shft, len; 407 int ctrl, meta, shft, len;
304 unsigned int newlen;
305 KeySym keysym; 408 KeySym keysym;
306 int valid_keysym; 409 int valid_keysym;
307 char kbuf[KBUFSZ]; 410 char kbuf[KBUFSZ];
411
412#if ISO_14755
413 if (iso14755buf & ISO_14755_52)
414 return;
415#endif
308 416
309 /* 417 /*
310 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 418 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
311 * escape sequence to toggle the Keypad. 419 * escape sequence to toggle the Keypad.
312 * 420 *
313 * Always permit `shift' to override the current setting 421 * Always permit `shift' to override the current setting
314 */ 422 */
315 shft = ev.state & ShiftMask; 423 shft = ev.state & ShiftMask;
316 ctrl = ev.state & ControlMask; 424 ctrl = ev.state & ControlMask;
317 meta = ev.state & ModMetaMask; 425 meta = ev.state & ModMetaMask;
318
319 if (numlock_state || (ev.state & ModNumLockMask))
320 {
321 numlock_state = (ev.state & ModNumLockMask);
322 PrivMode ((!numlock_state), PrivMode_aplKP);
323 }
324 426
325 kbuf[0] = 0; 427 kbuf[0] = 0;
326 428
327#ifdef USE_XIM 429#ifdef USE_XIM
328 if (Input_Context) 430 if (Input_Context)
403#ifdef PAGING_CONTEXT_LINES 505#ifdef PAGING_CONTEXT_LINES
404 lnsppg = nrow - PAGING_CONTEXT_LINES; 506 lnsppg = nrow - PAGING_CONTEXT_LINES;
405#else 507#else
406 lnsppg = nrow * 4 / 5; 508 lnsppg = nrow * 4 / 5;
407#endif 509#endif
510 max_it (lnsppg, 1);
511
408 if (keysym == XK_Prior) 512 if (keysym == XK_Prior)
409 { 513 {
410 scr_page (UP, lnsppg); 514 scr_page (UP, lnsppg);
411 return; 515 return;
412 } 516 }
477 } 581 }
478 } 582 }
479 583
480#if ENABLE_FRILLS || ISO_14755 584#if ENABLE_FRILLS || ISO_14755
481 // ISO 14755 support 585 // ISO 14755 support
482 if (shft && ctrl) 586 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51))
483 { 587 {
484 int hv; 588 int hv;
485 589
486 if (iso14755buf & ISO_14755_51 590 if (iso14755buf & ISO_14755_51
487 && (keysym == XK_space || keysym == XK_KP_Space 591 && (keysym == XK_space || keysym == XK_KP_Space
489 { 593 {
490 commit_iso14755 (); 594 commit_iso14755 ();
491 iso14755buf = ISO_14755_51; 595 iso14755buf = ISO_14755_51;
492# if ISO_14755 596# if ISO_14755
493 iso14755_51 (0); 597 iso14755_51 (0);
598# endif
599 return;
600 }
601 else if (keysym == XK_BackSpace)
602 {
603 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
604# if ISO_14755
605 iso14755_51 (iso14755buf & ISO_14755_MASK);
494# endif 606# endif
495 return; 607 return;
496 } 608 }
497 else if ((hv = hex_keyval (ev)) >= 0) 609 else if ((hv = hex_keyval (ev)) >= 0)
498 { 610 {
503# endif 615# endif
504 return; 616 return;
505 } 617 }
506 else 618 else
507 { 619 {
508# if ENABLE_OVERLAY 620# if ISO_14755
509 scr_overlay_off (); 621 scr_overlay_off ();
510# endif 622# endif
511 iso14755buf = 0; 623 iso14755buf = 0;
512 } 624 }
513 } 625 }
626 else if (option (Opt_iso14755) &&
514 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 627 ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
515 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 628 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))))
516 if (!(iso14755buf & ISO_14755_STARTED)) 629 if (!(iso14755buf & ISO_14755_STARTED))
517 { 630 {
518 iso14755buf |= ISO_14755_STARTED; 631 iso14755buf |= ISO_14755_STARTED;
519# if ENABLE_OVERLAY 632# if ISO_14755
520 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 633 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
521 scr_overlay_set (0, 0, "ISO 14755 mode"); 634 scr_overlay_set (0, 0, "ISO 14755 mode");
522# endif 635# endif
523 } 636 }
524#endif 637#endif
525 638
526#ifdef PRINTPIPE 639#ifdef PRINTPIPE
527 if (keysym == XK_Print) 640 if (keysym == XK_Print)
528 { 641 {
529 scr_printscreen (ctrl | shft); 642 scr_printscreen (ctrl | shft);
530 return; 643 return;
531 } 644 }
532#endif 645#endif
533 646
534 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 647 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
535 { 648 {
649 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
650 unsigned int newlen = 1;
651
652 if (ev.state & ModNumLockMask)
653 kp = false;
654
655 keysym = translate_keypad (keysym, kp);
656
657 switch (keysym)
536 { 658 {
659#ifndef NO_BACKSPACE_KEY
660 case XK_BackSpace:
661 if (priv_modes & PrivMode_HaveBackSpace)
662 {
663 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
664 ^ !!ctrl) ? '\b' : '\177';
665 kbuf[1] = '\0';
666 }
667 else
668 strcpy (kbuf, rs[Rs_backspace_key]);
669 break;
670#endif
671#ifndef NO_DELETE_KEY
672 case XK_Delete:
673 strcpy (kbuf, rs[Rs_delete_key]);
674 break;
675#endif
676 case XK_Tab:
677 if (shft)
678 strcpy (kbuf, "\033[Z");
679 else
680 {
681#ifdef CTRL_TAB_MAKES_META
682 if (ctrl)
683 meta = 1;
684#endif
685#ifdef MOD4_TAB_MAKES_META
686 if (ev.state & Mod4Mask)
687 meta = 1;
688#endif
537 newlen = 1; 689 newlen = 0;
538 switch (keysym) 690 }
691 break;
692
693 case XK_Up: /* "\033[A" */
694 case XK_Down: /* "\033[B" */
695 case XK_Right: /* "\033[C" */
696 case XK_Left: /* "\033[D" */
697 strcpy (kbuf, "\033[Z");
698 kbuf[2] = "DACB"[keysym - XK_Left];
699 /* do Shift first */
700 if (shft)
701 kbuf[2] = "dacb"[keysym - XK_Left];
702 else if (ctrl)
703 {
704 kbuf[1] = 'O';
705 kbuf[2] = "dacb"[keysym - XK_Left];
706 }
707 else if (priv_modes & PrivMode_aplCUR)
708 kbuf[1] = 'O';
709 break;
710
711 case XK_KP_Enter:
712 /* allow shift to override */
713 if (kp)
714 {
715 strcpy (kbuf, "\033OM");
716 break;
717 }
718
719 /* FALLTHROUGH */
720
721 case XK_Return:
722 if (priv_modes & PrivMode_LFNL)
723 {
724 kbuf[0] = '\015';
725 kbuf[1] = '\012';
726 kbuf[2] = '\0';
727 }
728 else
729 {
730 kbuf[0] = '\015';
731 kbuf[1] = '\0';
732 }
733 break;
734
735 case XK_KP_F1: /* "\033OP" */
736 case XK_KP_F2: /* "\033OQ" */
737 case XK_KP_F3: /* "\033OR" */
738 case XK_KP_F4: /* "\033OS" */
739 strcpy (kbuf, "\033OP");
740 kbuf[2] += (keysym - XK_KP_F1);
741 break;
742
743 case XK_KP_Multiply: /* "\033Oj" : "*" */
744 case XK_KP_Add: /* "\033Ok" : "+" */
745 case XK_KP_Separator: /* "\033Ol" : "," */
746 case XK_KP_Subtract: /* "\033Om" : "-" */
747 case XK_KP_Decimal: /* "\033On" : "." */
748 case XK_KP_Divide: /* "\033Oo" : "/" */
749 case XK_KP_0: /* "\033Op" : "0" */
750 case XK_KP_1: /* "\033Oq" : "1" */
751 case XK_KP_2: /* "\033Or" : "2" */
752 case XK_KP_3: /* "\033Os" : "3" */
753 case XK_KP_4: /* "\033Ot" : "4" */
754 case XK_KP_5: /* "\033Ou" : "5" */
755 case XK_KP_6: /* "\033Ov" : "6" */
756 case XK_KP_7: /* "\033Ow" : "7" */
757 case XK_KP_8: /* "\033Ox" : "8" */
758 case XK_KP_9: /* "\033Oy" : "9" */
759 /* allow shift to override */
760 if (kp)
761 {
762 strcpy (kbuf, "\033Oj");
763 kbuf[2] += (keysym - XK_KP_Multiply);
764 }
765 else
766 {
767 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
768 kbuf[1] = '\0';
769 }
770 break;
771
772 default:
539 { 773 {
540#ifndef NO_BACKSPACE_KEY 774 int param = map_function_key (keysym);
541 case XK_BackSpace: 775 if (param > 0)
542 if (priv_modes & PrivMode_HaveBackSpace)
543 { 776 {
544 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) 777 int n = sprintf (kbuf,"\033[%d~", param);
545 ^ !!ctrl) ? '\b' : '\177'; 778 /*
546 kbuf[1] = '\0'; 779 * pass Shift/Control indicators for function keys ending with `~'
780 *
781 * eg,
782 * Prior = "ESC[5~"
783 * Shift+Prior = "ESC[5$"
784 * Ctrl+Prior = "ESC[5^"
785 * Ctrl+Shift+Prior = "ESC[5@"
786 */
787 kbuf[n-1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
547 } 788 }
548 else 789 else
549 strcpy (kbuf, key_backspace);
550 break;
551#endif
552#ifndef NO_DELETE_KEY
553# ifdef XK_KP_Prior
554 case XK_KP_Delete:
555 /* allow shift to override */
556 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
557 {
558 strcpy (kbuf, "\033On");
559 break;
560 }
561 /* FALLTHROUGH */
562# endif
563 case XK_Delete:
564 strcpy (kbuf, key_delete);
565 break;
566#endif
567 case XK_Tab:
568 if (shft)
569 strcpy (kbuf, "\033[Z");
570 else
571 {
572#ifdef CTRL_TAB_MAKES_META
573 if (ctrl)
574 meta = 1;
575#endif
576#ifdef MOD4_TAB_MAKES_META
577 if (ev.state & Mod4Mask)
578 meta = 1;
579#endif
580 newlen = 0;
581 }
582 break;
583
584#ifdef XK_KP_Left
585 case XK_KP_Up: /* \033Ox or standard */
586 case XK_KP_Down: /* \033Or or standard */
587 case XK_KP_Right: /* \033Ov or standard */
588 case XK_KP_Left: /* \033Ot or standard */
589 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
590 {
591 strcpy (kbuf, "\033OZ");
592 kbuf[2] = "txvr"[keysym - XK_KP_Left];
593 break;
594 }
595 else
596 /* translate to std. cursor key */
597 keysym = XK_Left + (keysym - XK_KP_Left);
598 /* FALLTHROUGH */
599#endif
600 case XK_Up: /* "\033[A" */
601 case XK_Down: /* "\033[B" */
602 case XK_Right: /* "\033[C" */
603 case XK_Left: /* "\033[D" */
604 strcpy (kbuf, "\033[Z");
605 kbuf[2] = "DACB"[keysym - XK_Left];
606 /* do Shift first */
607 if (shft)
608 kbuf[2] = "dacb"[keysym - XK_Left];
609 else if (ctrl)
610 {
611 kbuf[1] = 'O';
612 kbuf[2] = "dacb"[keysym - XK_Left];
613 }
614 else if (priv_modes & PrivMode_aplCUR)
615 kbuf[1] = 'O';
616 break;
617
618#ifndef UNSHIFTED_SCROLLKEYS
619# ifdef XK_KP_Prior
620 case XK_KP_Prior:
621 /* allow shift to override */
622 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
623 {
624 strcpy (kbuf, "\033Oy");
625 break;
626 }
627 /* FALLTHROUGH */
628# endif
629 case XK_Prior:
630 strcpy (kbuf, "\033[5~");
631 break;
632# ifdef XK_KP_Next
633 case XK_KP_Next:
634 /* allow shift to override */
635 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
636 {
637 strcpy (kbuf, "\033Os");
638 break;
639 }
640 /* FALLTHROUGH */
641# endif
642 case XK_Next:
643 strcpy (kbuf, "\033[6~");
644 break;
645#endif
646 case XK_KP_Enter:
647 /* allow shift to override */
648 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
649 {
650 strcpy (kbuf, "\033OM");
651 break;
652 }
653
654 /* FALLTHROUGH */
655
656 case XK_Return:
657 if (priv_modes & PrivMode_LFNL)
658 {
659 kbuf[0] = '\015';
660 kbuf[1] = '\012';
661 kbuf[2] = '\0';
662 }
663 else
664 {
665 kbuf[0] = '\015';
666 kbuf[1] = '\0';
667 }
668 break;
669
670#ifdef XK_KP_Begin
671 case XK_KP_Begin:
672 strcpy (kbuf, "\033Ou");
673 break;
674
675#endif
676 case XK_KP_F1: /* "\033OP" */
677 case XK_KP_F2: /* "\033OQ" */
678 case XK_KP_F3: /* "\033OR" */
679 case XK_KP_F4: /* "\033OS" */
680 strcpy (kbuf, "\033OP");
681 kbuf[2] += (keysym - XK_KP_F1);
682 break;
683
684 case XK_KP_Multiply: /* "\033Oj" : "*" */
685 case XK_KP_Add: /* "\033Ok" : "+" */
686 case XK_KP_Separator: /* "\033Ol" : "," */
687 case XK_KP_Subtract: /* "\033Om" : "-" */
688 case XK_KP_Decimal: /* "\033On" : "." */
689 case XK_KP_Divide: /* "\033Oo" : "/" */
690 case XK_KP_0: /* "\033Op" : "0" */
691 case XK_KP_1: /* "\033Oq" : "1" */
692 case XK_KP_2: /* "\033Or" : "2" */
693 case XK_KP_3: /* "\033Os" : "3" */
694 case XK_KP_4: /* "\033Ot" : "4" */
695 case XK_KP_5: /* "\033Ou" : "5" */
696 case XK_KP_6: /* "\033Ov" : "6" */
697 case XK_KP_7: /* "\033Ow" : "7" */
698 case XK_KP_8: /* "\033Ox" : "8" */
699 case XK_KP_9: /* "\033Oy" : "9" */
700 /* allow shift to override */
701 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
702 {
703 strcpy (kbuf, "\033Oj");
704 kbuf[2] += (keysym - XK_KP_Multiply);
705 }
706 else
707 {
708 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
709 kbuf[1] = '\0';
710 }
711 break;
712
713 case XK_Find:
714 strcpy (kbuf, "\033[1~");
715 break;
716
717#ifdef XK_KP_End
718 case XK_KP_Insert:
719 /* allow shift to override */
720 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
721 {
722 strcpy (kbuf, "\033Op");
723 break;
724 }
725 /* FALLTHROUGH */
726#endif
727 case XK_Insert:
728 strcpy (kbuf, "\033[2~");
729 break;
730#ifdef DXK_Remove /* support for DEC remove like key */
731 case DXK_Remove:
732 /* FALLTHROUGH */
733#endif
734 case XK_Execute:
735 strcpy (kbuf, "\033[3~");
736 break;
737 case XK_Select:
738 strcpy (kbuf, "\033[4~");
739 break;
740#ifdef XK_KP_End
741 case XK_KP_End:
742 /* allow shift to override */
743 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
744 {
745 strcpy (kbuf, "\033Oq");
746 break;
747 }
748 /* FALLTHROUGH */
749#endif
750 case XK_End:
751 strcpy (kbuf, KS_END);
752 break;
753#ifdef XK_KP_Home
754 case XK_KP_Home:
755 /* allow shift to override */
756 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
757 {
758 strcpy (kbuf, "\033Ow");
759 break;
760 }
761 /* FALLTHROUGH */
762#endif
763 case XK_Home:
764 strcpy (kbuf, KS_HOME);
765 break;
766
767#define FKEY(n, fkey) \
768 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
769
770 case XK_F1: /* "\033[11~" */
771 case XK_F2: /* "\033[12~" */
772 case XK_F3: /* "\033[13~" */
773 case XK_F4: /* "\033[14~" */
774 case XK_F5: /* "\033[15~" */
775 FKEY (11, XK_F1);
776 break;
777 case XK_F6: /* "\033[17~" */
778 case XK_F7: /* "\033[18~" */
779 case XK_F8: /* "\033[19~" */
780 case XK_F9: /* "\033[20~" */
781 case XK_F10: /* "\033[21~" */
782 FKEY (17, XK_F6);
783 break;
784 case XK_F11: /* "\033[23~" */
785 case XK_F12: /* "\033[24~" */
786 case XK_F13: /* "\033[25~" */
787 case XK_F14: /* "\033[26~" */
788 FKEY (23, XK_F11);
789 break;
790 case XK_F15: /* "\033[28~" */
791 case XK_F16: /* "\033[29~" */
792 FKEY (28, XK_F15);
793 break;
794 case XK_Help: /* "\033[28~" */
795 FKEY (28, XK_Help);
796 break;
797 case XK_Menu: /* "\033[29~" */
798 FKEY (29, XK_Menu);
799 break;
800 case XK_F17: /* "\033[31~" */
801 case XK_F18: /* "\033[32~" */
802 case XK_F19: /* "\033[33~" */
803 case XK_F20: /* "\033[34~" */
804 case XK_F21: /* "\033[35~" */
805 case XK_F22: /* "\033[36~" */
806 case XK_F23: /* "\033[37~" */
807 case XK_F24: /* "\033[38~" */
808 case XK_F25: /* "\033[39~" */
809 case XK_F26: /* "\033[40~" */
810 case XK_F27: /* "\033[41~" */
811 case XK_F28: /* "\033[42~" */
812 case XK_F29: /* "\033[43~" */
813 case XK_F30: /* "\033[44~" */
814 case XK_F31: /* "\033[45~" */
815 case XK_F32: /* "\033[46~" */
816 case XK_F33: /* "\033[47~" */
817 case XK_F34: /* "\033[48~" */
818 case XK_F35: /* "\033[49~" */
819 FKEY (31, XK_F17);
820 break;
821#undef FKEY
822 default:
823 newlen = 0; 790 newlen = 0;
824 break;
825 } 791 }
826 792 break;
827 if (newlen)
828 len = strlen (kbuf);
829 } 793 }
794
795 if (newlen)
796 len = strlen (kbuf);
830 797
831 /* 798 /*
832 * Pass meta for all function keys, if 'meta' option set 799 * Pass meta for all function keys, if 'meta' option set
833 */ 800 */
834#ifdef META8_OPTION 801#ifdef META8_OPTION
869 return; 836 return;
870 837
871 if (len <= 0) 838 if (len <= 0)
872 return; /* not mapped */ 839 return; /* not mapped */
873 840
874 if (OPTION (Opt_scrollTtyKeypress)) 841 if (option (Opt_scrollTtyKeypress))
875 if (view_start) 842 if (view_start)
876 { 843 {
877 view_start = 0; 844 view_start = 0;
878 want_refresh = 1; 845 want_refresh = 1;
879 } 846 }
880 847
881 /* 848 /*
882 * these modifications only affect the static keybuffer
883 * pass Shift/Control indicators for function keys ending with `~'
884 *
885 * eg,
886 * Prior = "ESC[5~"
887 * Shift+Prior = "ESC[5$"
888 * Ctrl+Prior = "ESC[5^"
889 * Ctrl+Shift+Prior = "ESC[5@"
890 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>). 849 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
891 */ 850 */
892 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
893 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
894 851
895 /* escape prefix */ 852 /* escape prefix */
896 if (meta 853 if (meta
897#ifdef META8_OPTION 854#ifdef META8_OPTION
898 && meta_char == C0_ESC 855 && meta_char == C0_ESC
903 tt_write (&ch, 1); 860 tt_write (&ch, 1);
904 } 861 }
905 862
906 tt_write (kbuf, (unsigned int)len); 863 tt_write (kbuf, (unsigned int)len);
907} 864}
908/*}}} */ 865
866void
867rxvt_term::key_release (XKeyEvent &ev)
868{
869#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
870 KeySym keysym;
871
872 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
873#endif
874
875#if ENABLE_FRILLS || ISO_14755
876 // ISO 14755 support
877 if (iso14755buf)
878 if (iso14755buf & ISO_14755_52)
879 {
880# if ISO_14755
881 scr_overlay_off ();
882# endif
883# if ISO_14755
884 // iso14755 part 5.2 handling: release time
885 // first: controls
886 if ((ev.state & ControlMask)
887 && ((keysym >= 0x40 && keysym <= 0x5f)
888 || (keysym >= 0x61 && keysym <= 0x7f)))
889 {
890 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
891 commit_iso14755 ();
892
893 return;
894 }
895
896 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
897 if (i[0] == keysym)
898 {
899 iso14755buf = ISO_14755_51 | i[1];
900 commit_iso14755 ();
901
902 return;
903 }
904
905 scr_bell ();
906# endif
907 iso14755buf = 0;
908
909 return;
910 }
911 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
912 {
913# if ISO_14755
914 scr_overlay_off ();
915# endif
916 if (iso14755buf & ISO_14755_51)
917 commit_iso14755 ();
918#if ISO_14755
919 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
920 {
921 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
922
923 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
924 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
925 }
926# endif
927 else
928 iso14755buf = 0;
929 }
930#endif
931
932 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
933 return;
934
935#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
936 if (!(ev.state & ControlMask))
937 slip_wheel_ev.stop ();
938 else if (keysym == XK_Control_L || keysym == XK_Control_R)
939 mouse_slip_wheel_speed = 0;
940#endif
941}
909 942
910#if defined (KEYSYM_RESOURCE) 943#if defined (KEYSYM_RESOURCE)
911unsigned int 944unsigned int
912rxvt_term::cmd_write (const char *str, unsigned int count) 945rxvt_term::cmd_write (const char *str, unsigned int count)
913{ 946{
943void 976void
944rxvt_term::flush () 977rxvt_term::flush ()
945{ 978{
946 flush_ev.stop (); 979 flush_ev.stop ();
947 980
948#ifdef TRANSPARENT 981#ifdef HAVE_BG_PIXMAP
949 if (want_full_refresh) 982 if (bgPixmap.check_clearChanged ())
950 { 983 {
951 want_full_refresh = 0; 984// scr_clear (true); This needs to be researched further!
952 scr_clear ();
953 scr_touch (false); 985 scr_touch (false);
954 } 986 }
955#endif 987#endif
956 988
957 if (want_refresh) 989 if (want_refresh)
993 } 1025 }
994 while (row < end_row); 1026 while (row < end_row);
995 } 1027 }
996 1028
997 scr_refresh (); 1029 scr_refresh ();
998 scrollbar_show (1); 1030 scrollBar.show (1);
999#ifdef USE_XIM 1031#ifdef USE_XIM
1000 IMSendSpot (); 1032 IMSendSpot ();
1001#endif 1033#endif
1002 } 1034 }
1003 1035
1004 display->flush (); 1036 display->flush ();
1005} 1037}
1006 1038
1039/* checks whether a refresh is requested and starts the refresh timer */
1007void 1040void
1008rxvt_term::check_cb (check_watcher &w) 1041rxvt_term::refresh_check ()
1042{
1043 if (want_refresh && !flush_ev.is_active ())
1044 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
1045
1046 display->flush ();
1047}
1048
1049void
1050rxvt_term::flush_cb (ev::timer &w, int revents)
1009{ 1051{
1010 make_current (); 1052 make_current ();
1011 1053
1012 display->flush ();
1013
1014 if (want_refresh && !flush_ev.active)
1015 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
1016}
1017
1018void
1019rxvt_term::flush_cb (time_watcher &w)
1020{
1021 make_current ();
1022
1023 refresh_limit = 1;
1024 refresh_count = 0; 1054 refresh_count = 0;
1025 flush (); 1055 flush ();
1026} 1056}
1027 1057
1028#ifdef CURSOR_BLINK 1058#ifdef CURSOR_BLINK
1029void 1059void
1030rxvt_term::cursor_blink_cb (time_watcher &w) 1060rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
1031{ 1061{
1032 hidden_cursor = !hidden_cursor; 1062 hidden_cursor = !hidden_cursor;
1033 want_refresh = 1; 1063 want_refresh = 1;
1034 1064 refresh_check ();
1035 w.start (w.at + CURSOR_BLINK_INTERVAL);
1036} 1065}
1037#endif 1066#endif
1038 1067
1039#ifdef TEXT_BLINK 1068#ifdef TEXT_BLINK
1040void 1069void
1041rxvt_term::text_blink_cb (time_watcher &w) 1070rxvt_term::text_blink_cb (ev::timer &w, int revents)
1042{ 1071{
1043 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1072 if (scr_refresh_rend (RS_Blink, RS_Blink))
1044 { 1073 {
1045 hidden_text = !hidden_text; 1074 hidden_text = !hidden_text;
1046 want_refresh = 1; 1075 want_refresh = 1;
1047 w.start (w.at + TEXT_BLINK_INTERVAL); 1076 refresh_check ();
1048 } 1077 }
1078 else
1079 w.stop ();
1049} 1080}
1050#endif 1081#endif
1051 1082
1052#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1083#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1053void 1084void
1054rxvt_term::cont_scroll_cb (time_watcher &w) 1085rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1055{ 1086{
1056 if ((scrollbar_isUp() || scrollbar_isDn()) && 1087 if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
1057 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1088 && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1))
1058 { 1089 {
1059 want_refresh = 1; 1090 want_refresh = 1;
1060 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1091 refresh_check ();
1061 } 1092 }
1093 else
1094 w.stop ();
1062} 1095}
1063#endif 1096#endif
1064 1097
1065#ifdef SELECTION_SCROLLING 1098#ifdef SELECTION_SCROLLING
1066void 1099void
1067rxvt_term::sel_scroll_cb (time_watcher &w) 1100rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1068{ 1101{
1069 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1102 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1070 { 1103 {
1071 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1104 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1072 want_refresh = 1; 1105 want_refresh = 1;
1073 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1106 refresh_check ();
1074 } 1107 }
1108 else
1109 w.stop ();
1075} 1110}
1076#endif 1111#endif
1077 1112
1078#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1113#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1079void 1114void
1080rxvt_term::slip_wheel_cb (time_watcher &w) 1115rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1081{ 1116{
1082 if (mouse_slip_wheel_speed == 0 1117 if (scr_changeview (view_start - mouse_slip_wheel_speed))
1083 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1084 : scr_page (UP, mouse_slip_wheel_speed))
1085 { 1118 {
1086 if (view_start == top_row || view_start == 0)
1087 mouse_slip_wheel_speed = 0;
1088
1089 want_refresh = 1; 1119 want_refresh = 1;
1090 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1120 refresh_check ();
1121 }
1122
1123 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1124 {
1125 mouse_slip_wheel_speed = 0;
1126 w.stop ();
1091 } 1127 }
1092} 1128}
1093#endif 1129#endif
1094 1130
1095#if LINUX_YIELD_HACK 1131#if LINUX_YIELD_HACK
1096static struct event_handler 1132static struct event_handler
1097{ 1133{
1098 check_watcher yield_ev; 1134 ev::prepare yield_ev;
1099 1135
1100 void yield_cb (check_watcher &w) 1136 void yield_cb (ev::prepare &w, int revents)
1101 { 1137 {
1102 usleep (0); 1138 // this should really be sched_yield(), but the linux guys thought
1139 // that giving a process calling sched_yield () less cpu time than
1140 // ones with high nice levels is a useful thing to do. It surely is is
1141 // allowed by the sus... as is returning ENOSYS.
1142 // since the linux guys additionally thought that breaking the only
1143 // known workaround against their unusable sched_yield hack is cool,
1144 // we just nanosleep a bit and hope for the best.
1145
1146 struct timespec ts = { 0, 1000 };
1147 nanosleep (&ts, 0);
1148
1103 w.stop (); 1149 w.stop ();
1104 } 1150 }
1105 1151
1106 event_handler () 1152 event_handler ()
1107 : yield_ev (this, &event_handler::yield_cb) 1153 : yield_ev (this, &event_handler::yield_cb)
1141 } 1187 }
1142 else 1188 else
1143 { 1189 {
1144 pty_ev.stop (); 1190 pty_ev.stop ();
1145 1191
1146 if (!OPTION (Opt_hold)) 1192 if (!option (Opt_hold))
1147 destroy (); 1193 destroy ();
1148 } 1194 }
1149 1195
1150 return false; 1196 return false;
1151} 1197}
1152 1198
1153void 1199void
1154rxvt_term::pty_cb (io_watcher &w, short revents) 1200rxvt_term::pty_cb (ev::io &w, int revents)
1155{ 1201{
1156 make_current (); 1202 make_current ();
1157 1203
1158 if (revents & EVENT_READ) 1204 if (revents & ev::READ)
1159 // loop, but don't allow a single term to monopolize us 1205 // loop, but don't allow a single term to monopolize us
1160 while (pty_fill ()) 1206 for (int i = CBUFCNT; i-- && pty_fill (); )
1161 if (cmd_parse ()) 1207 cmd_parse ();
1162 break;
1163 1208
1164 if (revents & EVENT_WRITE) 1209 if (revents & ev::WRITE)
1165 pty_write (); 1210 pty_write ();
1211
1212 refresh_check ();
1166} 1213}
1167 1214
1168void 1215void
1169rxvt_term::pointer_unblank () 1216rxvt_term::pointer_unblank ()
1170{ 1217{
1171 XDefineCursor (xdisp, vt, TermWin_cursor); 1218 XDefineCursor (dpy, vt, TermWin_cursor);
1172 recolour_cursor (); 1219 recolour_cursor ();
1173 1220
1174#ifdef POINTER_BLANK 1221#ifdef POINTER_BLANK
1175 hidden_pointer = 0; 1222 hidden_pointer = 0;
1176 1223
1177 if (OPTION (Opt_pointerBlank)) 1224 if (option (Opt_pointerBlank))
1178 pointer_ev.start (NOW + pointerBlankDelay); 1225 pointer_ev.start (pointerBlankDelay);
1179#endif 1226#endif
1180} 1227}
1181 1228
1182#ifdef POINTER_BLANK 1229#ifdef POINTER_BLANK
1183void 1230void
1184rxvt_term::pointer_blank () 1231rxvt_term::pointer_blank ()
1185{ 1232{
1186 if (!OPTION (Opt_pointerBlank)) 1233 if (!option (Opt_pointerBlank))
1187 return; 1234 return;
1188 1235
1189 XDefineCursor (xdisp, vt, display->blank_cursor); 1236 XDefineCursor (dpy, vt, display->blank_cursor);
1190 XFlush (xdisp); 1237 XFlush (dpy);
1191 1238
1192 hidden_pointer = 1; 1239 hidden_pointer = 1;
1193} 1240}
1194 1241
1195void 1242void
1196rxvt_term::pointer_cb (time_watcher &w) 1243rxvt_term::pointer_cb (ev::timer &w, int revents)
1197{ 1244{
1198 make_current (); 1245 make_current ();
1199 1246
1200 pointer_blank (); 1247 pointer_blank ();
1201} 1248}
1204void 1251void
1205rxvt_term::mouse_report (XButtonEvent &ev) 1252rxvt_term::mouse_report (XButtonEvent &ev)
1206{ 1253{
1207 int button_number, key_state = 0; 1254 int button_number, key_state = 0;
1208 int x, y; 1255 int x, y;
1256 int code = 32;
1209 1257
1210 x = ev.x; 1258 x = Pixel2Col (ev.x);
1211 y = ev.y; 1259 y = Pixel2Row (ev.y);
1212 pixel_position (&x, &y); 1260 if (ev.type == MotionNotify)
1261 {
1262 if (x == mouse_row && y == mouse_col)
1263 return;
1264 mouse_row = x;
1265 mouse_col = y;
1266 code += 32;
1267 }
1213 1268
1214 if (MEvent.button == AnyButton) 1269 if (MEvent.button == AnyButton)
1215 button_number = 3; 1270 button_number = 3;
1216 else 1271 else
1217 { 1272 {
1263 x + 1, 1318 x + 1,
1264 y + 1); 1319 y + 1);
1265#endif 1320#endif
1266 1321
1267 tt_printf ("\033[M%c%c%c", 1322 tt_printf ("\033[M%c%c%c",
1268 (32 + button_number + key_state), 1323 (code + button_number + key_state),
1269 (32 + x + 1), 1324 (32 + x + 1),
1270 (32 + y + 1)); 1325 (32 + y + 1));
1271} 1326}
1272 1327
1273/*{{{ process an X event */ 1328/*{{{ process an X event */
1274void 1329void
1275rxvt_term::x_cb (XEvent &ev) 1330rxvt_term::x_cb (XEvent &ev)
1276{ 1331{
1277 make_current (); 1332 make_current ();
1278 1333
1279 dLocal (Display *, xdisp); 1334 dLocal (Display *, dpy);
1280 1335
1281 if (ev.xany.window == vt 1336 if (ev.xany.window == vt
1282 && SHOULD_INVOKE (HOOK_X_EVENT) 1337 && SHOULD_INVOKE (HOOK_X_EVENT)
1283 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) 1338 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1284 return; 1339 return;
1289 unsigned int unused_mask; 1344 unsigned int unused_mask;
1290 1345
1291 switch (ev.type) 1346 switch (ev.type)
1292 { 1347 {
1293 case KeyPress: 1348 case KeyPress:
1294#if ISO_14755 1349 key_press (ev.xkey);
1295 if (!(iso14755buf & ISO_14755_52))
1296#endif
1297 lookup_key (ev.xkey);
1298
1299 break; 1350 break;
1300 1351
1301 case KeyRelease: 1352 case KeyRelease:
1302 { 1353 key_release (ev.xkey);
1303#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1304 KeySym keysym;
1305
1306 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1307#endif
1308
1309#if ENABLE_FRILLS || ISO_14755
1310 // ISO 14755 support
1311 if (iso14755buf)
1312 if (iso14755buf & ISO_14755_52)
1313 {
1314# if ENABLE_OVERLAY
1315 scr_overlay_off ();
1316# endif
1317# if ISO_14755
1318 // iso14755 part 5.2 handling: release time
1319 // first: controls
1320 if ((ev.xkey.state & ControlMask)
1321 && ((keysym >= 0x40 && keysym <= 0x5f)
1322 || (keysym >= 0x61 && keysym <= 0x7f)))
1323 {
1324 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1325 commit_iso14755 ();
1326 goto skip_switch;
1327 }
1328
1329 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1330 if (i[0] == keysym)
1331 {
1332 iso14755buf = ISO_14755_51 | i[1];
1333 commit_iso14755 ();
1334 goto skip_switch;
1335 }
1336
1337 scr_bell ();
1338# endif
1339 iso14755buf = 0;
1340 break;
1341 }
1342 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1343 {
1344# if ENABLE_OVERLAY
1345 scr_overlay_off ();
1346# endif
1347 if (iso14755buf & ISO_14755_51)
1348 commit_iso14755 ();
1349#if ISO_14755
1350 else if (iso14755buf & ISO_14755_STARTED)
1351 {
1352 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1353
1354 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1355 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1356 }
1357# endif
1358 else
1359 iso14755buf = 0;
1360 }
1361#endif
1362
1363 if (ev.xany.window == vt
1364 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1365 break;
1366
1367#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1368 if (!(ev.xkey.state & ControlMask))
1369 slip_wheel_ev.stop ();
1370 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1371 mouse_slip_wheel_speed = 0;
1372#endif
1373 break; 1354 break;
1374 }
1375 1355
1376 case ButtonPress: 1356 case ButtonPress:
1377 button_press (ev.xbutton); 1357 button_press (ev.xbutton);
1378 break; 1358 break;
1379 1359
1394 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) 1374 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1395 destroy (); 1375 destroy ();
1396 } 1376 }
1397#if ENABLE_EWMH 1377#if ENABLE_EWMH
1398 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1378 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1399 XSendEvent (xdisp, ev.xclient.window = display->root, 1379 XSendEvent (dpy, ev.xclient.window = display->root,
1400 False, SubstructureRedirectMask | SubstructureNotifyMask, 1380 False, SubstructureRedirectMask | SubstructureNotifyMask,
1401 &ev); 1381 &ev);
1402#endif 1382#endif
1403 } 1383 }
1404 } 1384 }
1410 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1390 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1411 focus_out (); 1391 focus_out ();
1412 } 1392 }
1413#endif 1393#endif
1414 } 1394 }
1415 break;
1416
1417 case MappingNotify:
1418 XRefreshKeyboardMapping (&ev.xmapping);
1419 break; 1395 break;
1420 1396
1421 /* 1397 /*
1422 * XXX: this is not the _current_ arrangement 1398 * XXX: this is not the _current_ arrangement
1423 * Here's my conclusion: 1399 * Here's my conclusion:
1442 break; 1418 break;
1443 } 1419 }
1444 break; 1420 break;
1445 1421
1446 case FocusIn: 1422 case FocusIn:
1423 if (ev.xfocus.detail != NotifyInferior
1424 && ev.xfocus.detail != NotifyPointer
1425 && ev.xfocus.mode != NotifyGrab)
1447 focus_in (); 1426 focus_in ();
1448 break; 1427 break;
1449 1428
1450 case FocusOut: 1429 case FocusOut:
1430 if (ev.xfocus.detail != NotifyInferior
1431 && ev.xfocus.detail != NotifyPointer
1432 && ev.xfocus.mode != NotifyGrab)
1451 focus_out (); 1433 focus_out ();
1452 break; 1434 break;
1453 1435
1454 case ConfigureNotify: 1436 case ConfigureNotify:
1437 /*fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1438 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1439 szHint.width, szHint.height);*/
1455 if (ev.xconfigure.window == parent[0]) 1440 if (ev.xconfigure.window == parent[0])
1456 { 1441 {
1457 while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) 1442 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1458 ; 1443 ;
1459 1444
1460 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) 1445 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1461 { 1446 {
1462 seen_resize = 1; 1447 seen_resize = 1;
1463 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1448 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1464 } 1449 }
1450 else
1451 {
1452#ifdef HAVE_BG_PIXMAP
1453 if (bgPixmap.window_position_sensitive ())
1454 {
1455 if (mapped)
1456 update_background ();
1457 else
1458 bgPixmap.invalidate ();
1459 }
1460#endif
1461 }
1465 1462
1466 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); 1463 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1467
1468#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1469 if (OPTION (Opt_transparent))
1470 check_our_parents ();
1471#endif
1472 } 1464 }
1473 break; 1465 break;
1474 1466
1475 case PropertyNotify: 1467 case PropertyNotify:
1476 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) 1468 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1479 selection_property (ev.xproperty.window, ev.xproperty.atom); 1471 selection_property (ev.xproperty.window, ev.xproperty.atom);
1480 1472
1481 break; 1473 break;
1482 1474
1483 case SelectionClear: 1475 case SelectionClear:
1484 selection_clear (); 1476 selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]);
1485 break; 1477 break;
1486 1478
1487 case SelectionNotify: 1479 case SelectionNotify:
1488 if (selection_wait == Sel_normal) 1480 if (selection_wait == Sel_normal)
1489 selection_paste (ev.xselection.requestor, ev.xselection.property, true); 1481 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1492 case SelectionRequest: 1484 case SelectionRequest:
1493 selection_send (ev.xselectionrequest); 1485 selection_send (ev.xselectionrequest);
1494 break; 1486 break;
1495 1487
1496 case MapNotify: 1488 case MapNotify:
1489#ifdef HAVE_BG_PIXMAP
1490 /* This is needed specifically to fix the case of no window manager or a
1491 * non-reparenting window manager. In those cases we never get first
1492 * ConfigureNotify. Also that speeds startup under normal WM, by taking
1493 * care of multiplicity of ConfigureNotify events arriving while WM does
1494 * reparenting.
1495 * We should not render background immediately, as there could be several
1496 * ConfigureNotify's to follow. Lets take care of all of them in one scoop
1497 * by scheduling background redraw as soon as we can, but giving a short
1498 * bit of time for ConfigureNotifies to arrive.
1499 * We should render background PRIOR to drawing any text, but AFTER all
1500 * of ConfigureNotifys for the best results.
1501 */
1502 if (bgPixmap.flags & bgPixmap_t::isInvalid)
1503 update_background_ev.start (0.025);
1504#endif
1497 mapped = 1; 1505 mapped = 1;
1498#ifdef TEXT_BLINK 1506#ifdef TEXT_BLINK
1499 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1507 text_blink_ev.start ();
1500#endif 1508#endif
1501 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1509 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1502 break; 1510 break;
1503 1511
1504 case UnmapNotify: 1512 case UnmapNotify:
1506#ifdef TEXT_BLINK 1514#ifdef TEXT_BLINK
1507 text_blink_ev.stop (); 1515 text_blink_ev.stop ();
1508#endif 1516#endif
1509 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1517 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1510 break; 1518 break;
1511
1512#ifdef TRANSPARENT
1513 case ReparentNotify:
1514 rootwin_cb (ev);
1515 break;
1516#endif /* TRANSPARENT */
1517 1519
1518 case GraphicsExpose: 1520 case GraphicsExpose:
1519 case Expose: 1521 case Expose:
1520 if (ev.xany.window == vt) 1522 if (ev.xany.window == vt)
1521 { 1523 {
1522 do 1524 do
1525 {
1523 scr_expose (ev.xexpose.x, ev.xexpose.y, 1526 scr_expose (ev.xexpose.x, ev.xexpose.y,
1524 ev.xexpose.width, ev.xexpose.height, False); 1527 ev.xexpose.width, ev.xexpose.height, False);
1528 }
1525 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); 1529 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1526 1530
1527 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1531 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1528 1532
1529 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) 1533 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1534 {
1530 scr_expose (ev.xexpose.x, ev.xexpose.y, 1535 scr_expose (ev.xexpose.x, ev.xexpose.y,
1531 ev.xexpose.width, ev.xexpose.height, False); 1536 ev.xexpose.width, ev.xexpose.height, False);
1537 }
1532 1538
1533 want_refresh = 1; 1539 want_refresh = 1;
1534 } 1540 }
1535 else 1541 else
1536 { 1542 {
1537 XEvent unused_event; 1543 XEvent unused_event;
1538 1544
1539 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) 1545 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1540 ; 1546 ;
1541 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) 1547 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1542 ; 1548 ;
1543 1549
1544 if (isScrollbarWindow (ev.xany.window)) 1550 if (scrollBar.state && ev.xany.window == scrollBar.win)
1545 { 1551 {
1546 scrollBar.setIdle (); 1552 scrollBar.state = STATE_IDLE;
1547 scrollbar_show (0); 1553 scrollBar.show (0);
1548 } 1554 }
1549
1550#ifdef TRANSPARENT
1551 if (am_transparent && ev.xany.window == parent[0])
1552 XClearWindow (xdisp, ev.xany.window);
1553#endif
1554 } 1555 }
1555 break; 1556 break;
1556 1557
1557 case MotionNotify: 1558 case MotionNotify:
1558#ifdef POINTER_BLANK 1559#ifdef POINTER_BLANK
1559 if (hidden_pointer) 1560 if (hidden_pointer)
1560 pointer_unblank (); 1561 pointer_unblank ();
1561#endif 1562#endif
1563 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1564 || priv_modes & PrivMode_MouseAnyEvent)
1565 mouse_report (ev.xbutton);
1562 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1566 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1563 break; 1567 break;
1564 1568
1565 if (ev.xany.window == vt) 1569 if (ev.xany.window == vt)
1566 { 1570 {
1567 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) 1571 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1568 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) 1572 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1569 ; // nop 1573 ; // nop
1570 else if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1574 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1571 { 1575 {
1572 while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) 1576 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1573 ; 1577 ;
1574 1578
1575 XQueryPointer (xdisp, vt, 1579 XQueryPointer (dpy, vt,
1576 &unused_root, &unused_child, 1580 &unused_root, &unused_child,
1577 &unused_root_x, &unused_root_y, 1581 &unused_root_x, &unused_root_y,
1578 &ev.xbutton.x, &ev.xbutton.y, 1582 &ev.xbutton.x, &ev.xbutton.y,
1579 &ev.xbutton.state); 1583 &ev.xbutton.state);
1580#ifdef MOUSE_THRESHOLD 1584#ifdef MOUSE_THRESHOLD
1600 int dist; 1604 int dist;
1601 1605
1602 /* don't clobber the current delay if we are 1606 /* don't clobber the current delay if we are
1603 * already in the middle of scrolling. 1607 * already in the middle of scrolling.
1604 */ 1608 */
1605 if (!sel_scroll_ev.active) 1609 if (!sel_scroll_ev.is_active ())
1606 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1610 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1607 1611
1608 /* save the event params so we can highlight 1612 /* save the event params so we can highlight
1609 * the selection in the pending-scroll loop 1613 * the selection in the pending-scroll loop
1610 */ 1614 */
1611 selection_save_x = ev.xbutton.x; 1615 selection_save_x = ev.xbutton.x;
1633 else 1637 else
1634 { 1638 {
1635 /* we are within the text window, so we 1639 /* we are within the text window, so we
1636 * shouldn't be scrolling 1640 * shouldn't be scrolling
1637 */ 1641 */
1638 if (sel_scroll_ev.active)
1639 sel_scroll_ev.stop(); 1642 sel_scroll_ev.stop();
1640 } 1643 }
1641#endif 1644#endif
1642#ifdef MOUSE_THRESHOLD 1645#ifdef MOUSE_THRESHOLD
1643 } 1646 }
1644#endif 1647#endif
1645 } 1648 }
1646 } 1649 }
1647 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1650 else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win)
1648 { 1651 {
1649 while (XCheckTypedWindowEvent (xdisp, scrollBar.win, 1652 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1650 MotionNotify, &ev)) 1653 MotionNotify, &ev))
1651 ; 1654 ;
1652 1655
1653 XQueryPointer (xdisp, scrollBar.win, 1656 XQueryPointer (dpy, scrollBar.win,
1654 &unused_root, &unused_child, 1657 &unused_root, &unused_child,
1655 &unused_root_x, &unused_root_y, 1658 &unused_root_x, &unused_root_y,
1656 &ev.xbutton.x, &ev.xbutton.y, 1659 &ev.xbutton.x, &ev.xbutton.y,
1657 &unused_mask); 1660 &unused_mask);
1658 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1661 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1659 scrollbar_size ()); 1662 scrollBar.size ());
1660 want_refresh = 1; 1663 want_refresh = 1;
1661 refresh_limit = 0;
1662 scrollbar_show (1); 1664 scrollBar.show (1);
1663 } 1665 }
1664 break; 1666 break;
1665 } 1667 }
1666 1668
1667skip_switch: ;
1668
1669#if defined(CURSOR_BLINK) 1669#if defined(CURSOR_BLINK)
1670 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) 1670 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1671 { 1671 {
1672 if (hidden_cursor) 1672 if (hidden_cursor)
1673 { 1673 {
1674 hidden_cursor = 0; 1674 hidden_cursor = 0;
1675 want_refresh = 1; 1675 want_refresh = 1;
1676 } 1676 }
1677 1677
1678 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1678 cursor_blink_ev.again ();
1679 } 1679 }
1680#endif 1680#endif
1681 1681
1682#if defined(POINTER_BLANK) 1682#if defined(POINTER_BLANK)
1683 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) 1683 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1684 { 1684 {
1685 if (ev.type == MotionNotify 1685 if (ev.type == MotionNotify
1686 || ev.type == ButtonPress 1686 || ev.type == ButtonPress
1687 || ev.type == ButtonRelease) 1687 || ev.type == ButtonRelease)
1688 if (hidden_pointer) 1688 if (hidden_pointer)
1690 1690
1691 if (ev.type == KeyPress && hidden_pointer == 0) 1691 if (ev.type == KeyPress && hidden_pointer == 0)
1692 pointer_blank (); 1692 pointer_blank ();
1693 } 1693 }
1694#endif 1694#endif
1695
1696 refresh_check ();
1695} 1697}
1698
1699#if ENABLE_FRILLS
1700void
1701rxvt_term::set_urgency (bool enable)
1702{
1703 if (enable == urgency_hint)
1704 return;
1705
1706 if (XWMHints *h = XGetWMHints (dpy, parent[0]))
1707 {
1708 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1709 XSetWMHints (dpy, parent[0], h);
1710 urgency_hint = enable;
1711 }
1712}
1713#endif
1696 1714
1697void 1715void
1698rxvt_term::focus_in () 1716rxvt_term::focus_in ()
1699{ 1717{
1700 if (!focus) 1718 if (!focus)
1701 { 1719 {
1702 focus = 1; 1720 focus = 1;
1703 want_refresh = 1; 1721 want_refresh = 1;
1704 1722
1705 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1706
1707#if USE_XIM 1723#if USE_XIM
1708 if (Input_Context != NULL) 1724 if (Input_Context != NULL)
1709 { 1725 {
1710 IMSetStatusPosition (); 1726 IMSetPosition ();
1711 XSetICFocus (Input_Context); 1727 XSetICFocus (Input_Context);
1712 } 1728 }
1713#endif 1729#endif
1714#if CURSOR_BLINK 1730#if CURSOR_BLINK
1715 if (OPTION (Opt_cursorBlink)) 1731 if (option (Opt_cursorBlink))
1716 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1732 cursor_blink_ev.again ();
1717#endif 1733#endif
1718#if OFF_FOCUS_FADING 1734#if OFF_FOCUS_FADING
1719 if (rs[Rs_fade]) 1735 if (rs[Rs_fade])
1720 { 1736 {
1721 pix_colors = pix_colors_focused; 1737 pix_colors = pix_colors_focused;
1722 scr_recolour (); 1738 scr_recolour ();
1723 } 1739 }
1724#endif 1740#endif
1741#if ENABLE_FRILLS
1742 if (option (Opt_urgentOnBell))
1743 set_urgency (0);
1744#endif
1745
1746 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1725 } 1747 }
1726} 1748}
1727 1749
1728void 1750void
1729rxvt_term::focus_out () 1751rxvt_term::focus_out ()
1731 if (focus) 1753 if (focus)
1732 { 1754 {
1733 focus = 0; 1755 focus = 0;
1734 want_refresh = 1; 1756 want_refresh = 1;
1735 1757
1736 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); 1758#if ENABLE_FRILLS
1737 1759 if (option (Opt_urgentOnBell))
1760 set_urgency (0);
1761#endif
1738#if ENABLE_FRILLS || ISO_14755 1762#if ENABLE_FRILLS || ISO_14755
1739 if (iso14755buf) 1763 if (iso14755buf)
1740 { 1764 {
1741 iso14755buf = 0; 1765 iso14755buf = 0;
1742# if ENABLE_OVERLAY 1766# if ISO_14755
1743 scr_overlay_off (); 1767 scr_overlay_off ();
1744# endif 1768# endif
1745 } 1769 }
1746#endif 1770#endif
1747#if USE_XIM 1771#if USE_XIM
1748 if (Input_Context != NULL) 1772 if (Input_Context != NULL)
1749 XUnsetICFocus (Input_Context); 1773 XUnsetICFocus (Input_Context);
1750#endif 1774#endif
1751#if CURSOR_BLINK 1775#if CURSOR_BLINK
1752 if (OPTION (Opt_cursorBlink)) 1776 if (option (Opt_cursorBlink))
1753 cursor_blink_ev.stop (); 1777 cursor_blink_ev.stop ();
1778
1754 hidden_cursor = 0; 1779 hidden_cursor = 0;
1755#endif 1780#endif
1756#if OFF_FOCUS_FADING 1781#if OFF_FOCUS_FADING
1757 if (rs[Rs_fade]) 1782 if (rs[Rs_fade])
1758 { 1783 {
1759 pix_colors = pix_colors_unfocused; 1784 pix_colors = pix_colors_unfocused;
1760 scr_recolour (); 1785 scr_recolour ();
1761 } 1786 }
1762#endif 1787#endif
1788
1789 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1790 }
1791}
1792
1793void
1794rxvt_term::update_fade_color (unsigned int idx)
1795{
1796#if OFF_FOCUS_FADING
1797 if (rs[Rs_fade])
1763 } 1798 {
1799 rgba c;
1800 pix_colors [Color_fade].get (c);
1801 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1802 }
1803#endif
1764} 1804}
1765 1805
1766#if TRANSPARENT 1806#if ENABLE_TRANSPARENCY || ENABLE_PERL
1767void 1807void
1768rxvt_term::rootwin_cb (XEvent &ev) 1808rxvt_term::rootwin_cb (XEvent &ev)
1769{ 1809{
1770 make_current (); 1810 make_current ();
1771 1811
1812 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1813 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1814 return;
1815
1816# if ENABLE_TRANSPARENCY
1772 switch (ev.type) 1817 switch (ev.type)
1773 { 1818 {
1774 case PropertyNotify: 1819 case PropertyNotify:
1775 /* 1820 /*
1776 * if user used some Esetroot compatible prog to set the root bg, 1821 * if user used some Esetroot compatible prog to set the root bg,
1777 * use the property to determine the pixmap. We use it later on. 1822 * use the property to determine the pixmap. We use it later on.
1778 */ 1823 */
1779 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1824 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1780 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1825 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1781 return; 1826 {
1827 bgPixmap.set_root_pixmap ();
1828 update_background ();
1829 }
1782 1830
1783 /* FALLTHROUGH */
1784 case ReparentNotify:
1785 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1786 want_refresh = want_full_refresh = 1;
1787 break; 1831 break;
1788 } 1832 }
1833# endif
1834
1835 refresh_check ();
1789} 1836}
1790#endif 1837#endif
1791 1838
1792void 1839void
1793rxvt_term::button_press (XButtonEvent &ev) 1840rxvt_term::button_press (XButtonEvent &ev)
1824 /* save the xbutton state (for ButtonRelease) */ 1871 /* save the xbutton state (for ButtonRelease) */
1825 MEvent.state = ev.state; 1872 MEvent.state = ev.state;
1826#ifdef MOUSE_REPORT_DOUBLECLICK 1873#ifdef MOUSE_REPORT_DOUBLECLICK
1827 if (ev.button == MEvent.button && clickintime) 1874 if (ev.button == MEvent.button && clickintime)
1828 { 1875 {
1829 /* same button, within alloted time */ 1876 /* same button, within allowed time */
1830 MEvent.clicks++; 1877 MEvent.clicks++;
1831 1878
1832 if (MEvent.clicks > 1) 1879 if (MEvent.clicks > 1)
1833 { 1880 {
1834 /* only report double clicks */ 1881 /* only report double clicks */
1848 mouse_report (ev); 1895 mouse_report (ev);
1849 } 1896 }
1850#else 1897#else
1851 MEvent.button = ev.button; 1898 MEvent.button = ev.button;
1852 mouse_report (ev); 1899 mouse_report (ev);
1853#endif /* MOUSE_REPORT_DOUBLECLICK */ 1900#endif /* MOUSE_REPORT_DOUBLECLICK */
1854 1901
1855 } 1902 }
1856 else 1903 else
1857 { 1904 {
1858 if (ev.button != MEvent.button) 1905 if (ev.button != MEvent.button)
1906 } 1953 }
1907 1954
1908 /* 1955 /*
1909 * Scrollbar window processing of button press 1956 * Scrollbar window processing of button press
1910 */ 1957 */
1911 if (isScrollbarWindow (ev.window)) 1958 if (scrollBar.state && ev.window == scrollBar.win)
1912 { 1959 {
1913 scrollBar.setIdle (); 1960 page_dirn direction = NO_DIR;
1961
1962 if (scrollBar.upButton (ev.y))
1963 direction = UP; /* up */
1964 else if (scrollBar.dnButton (ev.y))
1965 direction = DN; /* down */
1966
1967 scrollBar.state = STATE_IDLE;
1914 /* 1968 /*
1915 * Rxvt-style scrollbar: 1969 * Rxvt-style scrollbar:
1916 * move up if mouse is above slider 1970 * move up if mouse is above slider
1917 * move dn if mouse is below slider 1971 * move dn if mouse is below slider
1918 * 1972 *
1927 /* 1981 /*
1928 * Mouse report disabled scrollbar: 1982 * Mouse report disabled scrollbar:
1929 * arrow buttons - send up/down 1983 * arrow buttons - send up/down
1930 * click on scrollbar - send pageup/down 1984 * click on scrollbar - send pageup/down
1931 */ 1985 */
1932 if ((scrollBar.style == R_SB_NEXT 1986 if (direction == UP)
1933 && scrollbarnext_upButton (ev.y))
1934 || (scrollBar.style == R_SB_RXVT
1935 && scrollbarrxvt_upButton (ev.y)))
1936 tt_printf ("\033[A"); 1987 tt_printf ("\033[A");
1937 else if ((scrollBar.style == R_SB_NEXT 1988 else if (direction == DN)
1938 && scrollbarnext_dnButton (ev.y))
1939 || (scrollBar.style == R_SB_RXVT
1940 && scrollbarrxvt_dnButton (ev.y)))
1941 tt_printf ("\033[B"); 1989 tt_printf ("\033[B");
1942 else 1990 else
1943 switch (ev.button) 1991 switch (ev.button)
1944 { 1992 {
1945 case Button2: 1993 case Button2:
1952 tt_printf ("\033[5~"); 2000 tt_printf ("\033[5~");
1953 break; 2001 break;
1954 } 2002 }
1955 } 2003 }
1956 else 2004 else
1957#endif /* NO_SCROLLBAR_REPORT */ 2005#endif /* NO_SCROLLBAR_REPORT */
1958
1959 {
1960 char upordown = 0;
1961
1962 if (scrollBar.style == R_SB_NEXT)
1963 { 2006 {
1964 if (scrollbarnext_upButton (ev.y)) 2007 if (direction != NO_DIR)
1965 upordown = -1; /* up */
1966 else if (scrollbarnext_dnButton (ev.y))
1967 upordown = 1; /* down */
1968 }
1969 else if (scrollBar.style == R_SB_RXVT)
1970 {
1971 if (scrollbarrxvt_upButton (ev.y))
1972 upordown = -1; /* up */
1973 else if (scrollbarrxvt_dnButton (ev.y))
1974 upordown = 1; /* down */
1975 }
1976 if (upordown)
1977 { 2008 {
1978#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 2009#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2010 if (!cont_scroll_ev.is_active ())
1979 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 2011 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1980#endif 2012#endif
1981 if (scr_page (upordown < 0 ? UP : DN, 1)) 2013 if (scr_page (direction, 1))
1982 { 2014 {
1983 if (upordown < 0) 2015 if (direction == UP)
1984 scrollBar.setUp (); 2016 scrollBar.state = STATE_UP;
1985 else 2017 else
1986 scrollBar.setDn (); 2018 scrollBar.state = STATE_DOWN;
1987 } 2019 }
1988 } 2020 }
1989 else 2021 else
1990 switch (ev.button) 2022 switch (ev.button)
1991 { 2023 {
1992 case Button2: 2024 case Button2:
1993 switch (scrollbar_align) 2025 switch (scrollBar.align)
1994 { 2026 {
1995 case R_SB_ALIGN_TOP: 2027 case R_SB_ALIGN_TOP:
1996 csrO = 0; 2028 csrO = 0;
1997 break; 2029 break;
1998 case R_SB_ALIGN_CENTRE: 2030 case R_SB_ALIGN_CENTRE:
2004 } 2036 }
2005 2037
2006 if (scrollBar.style == R_SB_XTERM 2038 if (scrollBar.style == R_SB_XTERM
2007 || scrollbar_above_slider (ev.y) 2039 || scrollbar_above_slider (ev.y)
2008 || scrollbar_below_slider (ev.y)) 2040 || scrollbar_below_slider (ev.y))
2009 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2041 scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ());
2010 2042
2011 scrollBar.setMotion (); 2043 scrollBar.state = STATE_MOTION;
2012 break; 2044 break;
2013 2045
2014 case Button1: 2046 case Button1:
2015 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2047 if (scrollBar.align == R_SB_ALIGN_CENTRE)
2016 csrO = ev.y - scrollBar.top; 2048 csrO = ev.y - scrollBar.top;
2017 /* FALLTHROUGH */ 2049 /* FALLTHROUGH */
2018 2050
2019 case Button3: 2051 case Button3:
2020 if (scrollBar.style != R_SB_XTERM) 2052 if (scrollBar.style != R_SB_XTERM)
2030 scr_page (DN, nrow - 1); 2062 scr_page (DN, nrow - 1);
2031# else 2063# else
2032 scr_page (DN, nrow / 4); 2064 scr_page (DN, nrow / 4);
2033# endif 2065# endif
2034 else 2066 else
2035 scrollBar.setMotion (); 2067 scrollBar.state = STATE_MOTION;
2036 } 2068 }
2037 else 2069 else
2038 { 2070 {
2039 scr_page ((ev.button == Button1 ? DN : UP), 2071 scr_page ((ev.button == Button1 ? DN : UP),
2040 (nrow 2072 (nrow
2041 * scrollbar_position (ev.y) 2073 * scrollbar_position (ev.y)
2042 / scrollbar_size ())); 2074 / scrollBar.size ()));
2043 } 2075 }
2044 2076
2045 break; 2077 break;
2046 } 2078 }
2047 } 2079 }
2057 2089
2058 csrO = 0; /* reset csr Offset */ 2090 csrO = 0; /* reset csr Offset */
2059 if (!bypass_keystate) 2091 if (!bypass_keystate)
2060 reportmode = !! (priv_modes & PrivMode_mouse_report); 2092 reportmode = !! (priv_modes & PrivMode_mouse_report);
2061 2093
2062 if (scrollbar_isUpDn ()) 2094 if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
2063 { 2095 {
2064 scrollBar.setIdle (); 2096 scrollBar.state = STATE_IDLE;
2065 scrollbar_show (0); 2097 scrollBar.show (0);
2066 } 2098 }
2067 2099
2068#ifdef SELECTION_SCROLLING 2100#ifdef SELECTION_SCROLLING
2069 if (sel_scroll_ev.active)
2070 sel_scroll_ev.stop(); 2101 sel_scroll_ev.stop();
2071#endif 2102#endif
2072 2103
2073 if (ev.window == vt) 2104 if (ev.window == vt)
2074 { 2105 {
2075 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) 2106 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2099 mouse_report (ev); 2130 mouse_report (ev);
2100 } 2131 }
2101#else /* MOUSE_REPORT_DOUBLECLICK */ 2132#else /* MOUSE_REPORT_DOUBLECLICK */
2102 MEvent.button = AnyButton; 2133 MEvent.button = AnyButton;
2103 mouse_report (ev); 2134 mouse_report (ev);
2104#endif /* MOUSE_REPORT_DOUBLECLICK */ 2135#endif /* MOUSE_REPORT_DOUBLECLICK */
2105 return; 2136 return;
2106 } 2137 }
2107 2138
2108 /* 2139 /*
2109 * dumb hack to compensate for the failure of click-and-drag 2140 * dumb hack to compensate for the failure of click-and-drag
2121 selection_make (ev.time); 2152 selection_make (ev.time);
2122 break; 2153 break;
2123 2154
2124 case Button2: 2155 case Button2:
2125 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? 2156 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2126 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary); 2157 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2127 break; 2158 break;
2128 2159
2129#ifdef MOUSE_WHEEL 2160#ifdef MOUSE_WHEEL
2130 case Button4: 2161 case Button4:
2131 case Button5: 2162 case Button5:
2135 2166
2136 v = ev.button == Button4 ? UP : DN; 2167 v = ev.button == Button4 ? UP : DN;
2137 2168
2138 if (ev.state & ShiftMask) 2169 if (ev.state & ShiftMask)
2139 i = 1; 2170 i = 1;
2140 else if (OPTION (Opt_mouseWheelScrollPage)) 2171 else if (option (Opt_mouseWheelScrollPage))
2141 i = nrow - 1; 2172 i = nrow - 1;
2142 else 2173 else
2143 i = 5; 2174 i = 5;
2144 2175
2145# ifdef MOUSE_SLIP_WHEELING 2176# ifdef MOUSE_SLIP_WHEELING
2147 { 2178 {
2148 mouse_slip_wheel_speed += v ? -1 : 1; 2179 mouse_slip_wheel_speed += v ? -1 : 1;
2149 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2180 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2150 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2181 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2151 2182
2152 if (slip_wheel_ev.at < NOW) 2183 if (!slip_wheel_ev.is_active ())
2153 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2184 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2154
2155 slip_wheel_ev.start ();
2156 } 2185 }
2157 else 2186 else
2187# endif
2158 { 2188 {
2159# endif
2160 scr_page (v, i); 2189 scr_page (v, i);
2161 scrollbar_show (1); 2190 scrollBar.show (1);
2162# ifdef MOUSE_SLIP_WHEELING
2163 } 2191 }
2164# endif
2165 } 2192 }
2166 break; 2193 break;
2167#endif 2194#endif
2168 } 2195 }
2169 } 2196 }
2170} 2197}
2171 2198
2172#ifdef TRANSPARENT
2173#if TINTING
2174/* taken from aterm-0.4.2 */
2175
2176typedef uint32_t RUINT32T;
2177
2178void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
2179{
2180 int sh_r, sh_g, sh_b;
2181 RUINT32T mask_r, mask_g, mask_b;
2182 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2183 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2184 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2185 int i;
2186
2187 Visual *visual = term->visual;
2188
2189 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2190
2191 /* for convenience */
2192 mask_r = visual->red_mask;
2193 mask_g = visual->green_mask;
2194 mask_b = visual->blue_mask;
2195
2196 /* boring lookup table pre-initialization */
2197 switch (srcImage->bits_per_pixel) {
2198 case 15:
2199 if ((mask_r != 0x7c00) ||
2200 (mask_g != 0x03e0) ||
2201 (mask_b != 0x001f))
2202 return;
2203 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2204 lookup_r = lookup;
2205 lookup_g = lookup+32;
2206 lookup_b = lookup+32+32;
2207 sh_r = 10;
2208 sh_g = 5;
2209 sh_b = 0;
2210 break;
2211 case 16:
2212 if ((mask_r != 0xf800) ||
2213 (mask_g != 0x07e0) ||
2214 (mask_b != 0x001f))
2215 return;
2216 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2217 lookup_r = lookup;
2218 lookup_g = lookup+32;
2219 lookup_b = lookup+32+64;
2220 sh_r = 11;
2221 sh_g = 5;
2222 sh_b = 0;
2223 break;
2224 case 24:
2225 if ((mask_r != 0xff0000) ||
2226 (mask_g != 0x00ff00) ||
2227 (mask_b != 0x0000ff))
2228 return;
2229 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2230 lookup_r = lookup;
2231 lookup_g = lookup+256;
2232 lookup_b = lookup+256+256;
2233 sh_r = 16;
2234 sh_g = 8;
2235 sh_b = 0;
2236 break;
2237 case 32:
2238 if ((mask_r != 0xff0000) ||
2239 (mask_g != 0x00ff00) ||
2240 (mask_b != 0x0000ff))
2241 return;
2242 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2243 lookup_r = lookup;
2244 lookup_g = lookup+256;
2245 lookup_b = lookup+256+256;
2246 sh_r = 16;
2247 sh_g = 8;
2248 sh_b = 0;
2249 break;
2250 default:
2251 return; /* we do not support this color depth */
2252 }
2253
2254 /* prepare limits for color transformation (each channel is handled separately) */
2255 if (shade < 0) {
2256 shade = -shade;
2257 if (shade < 0) shade = 0;
2258 if (shade > 100) shade = 100;
2259
2260 lower_lim_r = 65535-rm;
2261 lower_lim_g = 65535-gm;
2262 lower_lim_b = 65535-bm;
2263
2264 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2265 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2266 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2267
2268 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2269 } else {
2270 if (shade < 0) shade = 0;
2271 if (shade > 100) shade = 100;
2272
2273 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2274
2275 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2276 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2277 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2278 }
2279
2280 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2281 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2282 {
2283 unsigned int tmp;
2284
2285 tmp = lower_lim_r;
2286 lower_lim_r = lower_lim_b;
2287 lower_lim_b = tmp;
2288
2289 tmp = upper_lim_r;
2290 upper_lim_r = upper_lim_b;
2291 upper_lim_b = tmp;
2292 }
2293
2294 /* fill our lookup tables */
2295 for (i = 0; i <= mask_r>>sh_r; i++)
2296 {
2297 RUINT32T tmp;
2298 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2299 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2300 lookup_r[i] = (tmp/65535)<<sh_r;
2301 }
2302 for (i = 0; i <= mask_g>>sh_g; i++)
2303 {
2304 RUINT32T tmp;
2305 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2306 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2307 lookup_g[i] = (tmp/65535)<<sh_g;
2308 }
2309 for (i = 0; i <= mask_b>>sh_b; i++)
2310 {
2311 RUINT32T tmp;
2312 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2313 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2314 lookup_b[i] = (tmp/65535)<<sh_b;
2315 }
2316
2317 /* apply table to input image (replacing colors by newly calculated ones) */
2318 switch (srcImage->bits_per_pixel)
2319 {
2320 case 15:
2321 {
2322 unsigned short *p1, *pf, *p, *pl;
2323 p1 = (unsigned short *) srcImage->data;
2324 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2325 while (p1 < pf)
2326 {
2327 p = p1;
2328 pl = p1 + srcImage->width;
2329 for (; p < pl; p++)
2330 {
2331 *p = lookup_r[(*p & 0x7c00)>>10] |
2332 lookup_g[(*p & 0x03e0)>> 5] |
2333 lookup_b[(*p & 0x001f)];
2334 }
2335 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2336 }
2337 break;
2338 }
2339 case 16:
2340 {
2341 unsigned short *p1, *pf, *p, *pl;
2342 p1 = (unsigned short *) srcImage->data;
2343 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2344 while (p1 < pf)
2345 {
2346 p = p1;
2347 pl = p1 + srcImage->width;
2348 for (; p < pl; p++)
2349 {
2350 *p = lookup_r[(*p & 0xf800)>>11] |
2351 lookup_g[(*p & 0x07e0)>> 5] |
2352 lookup_b[(*p & 0x001f)];
2353 }
2354 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2355 }
2356 break;
2357 }
2358 case 24:
2359 {
2360 unsigned char *p1, *pf, *p, *pl;
2361 p1 = (unsigned char *) srcImage->data;
2362 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2363 while (p1 < pf)
2364 {
2365 p = p1;
2366 pl = p1 + srcImage->width * 3;
2367 for (; p < pl; p += 3)
2368 {
2369 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2370 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2371 p[2] = lookup_r[(p[2] & 0x0000ff)];
2372 }
2373 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2374 }
2375 break;
2376 }
2377 case 32:
2378 {
2379 RUINT32T *p1, *pf, *p, *pl;
2380 p1 = (RUINT32T *) srcImage->data;
2381 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2382
2383 while (p1 < pf)
2384 {
2385 p = p1;
2386 pl = p1 + srcImage->width;
2387 for (; p < pl; p++)
2388 {
2389 *p = lookup_r[(*p & 0xff0000)>>16] |
2390 lookup_g[(*p & 0x00ff00)>> 8] |
2391 lookup_b[(*p & 0x0000ff)] |
2392 (*p & ~0xffffff);
2393 }
2394 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2395 }
2396 break;
2397 }
2398 }
2399
2400 free (lookup);
2401}
2402#endif
2403
2404/*
2405 * Check our parents are still who we think they are.
2406 * Do transparency updates if required
2407 */
2408int
2409rxvt_term::check_our_parents ()
2410{
2411 int i, pchanged, aformat, have_pixmap, rootdepth;
2412 unsigned long nitems, bytes_after;
2413 Atom atype;
2414 unsigned char *prop = NULL;
2415 Window root, oldp, *list;
2416 Pixmap rootpixmap = None;
2417 XWindowAttributes wattr, wrootattr;
2418
2419 pchanged = 0;
2420
2421 if (!OPTION (Opt_transparent))
2422 return pchanged; /* Don't try any more */
2423
2424 XGetWindowAttributes (xdisp, display->root, &wrootattr);
2425 rootdepth = wrootattr.depth;
2426
2427 XGetWindowAttributes (xdisp, parent[0], &wattr);
2428
2429 if (rootdepth != wattr.depth)
2430 {
2431 if (am_transparent)
2432 {
2433 pchanged = 1;
2434 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2435 am_transparent = am_pixmap_trans = 0;
2436 }
2437
2438 return pchanged; /* Don't try any more */
2439 }
2440
2441 /* Get all X ops out of the queue so that our information is up-to-date. */
2442 XSync (xdisp, False);
2443
2444 /*
2445 * Make the frame window set by the window manager have
2446 * the root background. Some window managers put multiple nested frame
2447 * windows for each client, so we have to take care about that.
2448 */
2449 i = (xa[XA_XROOTPMAP_ID]
2450 && XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID],
2451 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2452 &nitems, &bytes_after, &prop) == Success);
2453
2454 if (!i || prop == NULL)
2455 i = (xa[XA_ESETROOT_PMAP_ID]
2456 && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID],
2457 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2458 &nitems, &bytes_after, &prop) == Success);
2459
2460 if (!i || prop == NULL
2461#if TINTING
2462 || !ISSET_PIXCOLOR (Color_tint)
2463#endif
2464 )
2465 have_pixmap = 0;
2466 else
2467 {
2468 have_pixmap = 1;
2469 rootpixmap = *(Pixmap *)prop;
2470 XFree (prop);
2471 }
2472
2473 if (have_pixmap)
2474 {
2475 /*
2476 * Copy display->root pixmap transparency
2477 */
2478 int sx, sy, nx, ny;
2479 unsigned int nw, nh;
2480 Window cr;
2481 XImage *image;
2482 GC gc;
2483 XGCValues gcvalue;
2484
2485 XTranslateCoordinates (xdisp, parent[0], display->root,
2486 0, 0, &sx, &sy, &cr);
2487 nw = (unsigned int)szHint.width;
2488 nh = (unsigned int)szHint.height;
2489 nx = ny = 0;
2490
2491 if (sx < 0)
2492 {
2493 nw += sx;
2494 nx = -sx;
2495 sx = 0;
2496 }
2497
2498 if (sy < 0)
2499 {
2500 nh += sy;
2501 ny = -sy;
2502 sy = 0;
2503 }
2504
2505 min_it (nw, (unsigned int) (wrootattr.width - sx));
2506 min_it (nh, (unsigned int) (wrootattr.height - sy));
2507
2508 XSync (xdisp, False);
2509 allowedxerror = -1;
2510 image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2511
2512 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2513 /* XXX: may need a delay here? */
2514 allowedxerror = 0;
2515
2516 if (image == NULL)
2517 {
2518 if (am_transparent && am_pixmap_trans)
2519 {
2520 pchanged = 1;
2521 if (pixmap != None)
2522 {
2523 XFreePixmap (xdisp, pixmap);
2524 pixmap = None;
2525 }
2526 }
2527
2528 am_pixmap_trans = 0;
2529 }
2530 else
2531 {
2532 if (pixmap != None)
2533 XFreePixmap (xdisp, pixmap);
2534
2535#if TINTING
2536 if (ISSET_PIXCOLOR (Color_tint))
2537 {
2538 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2539
2540 rgba c;
2541 pix_colors_focused [Color_tint].get (c);
2542
2543 ShadeXImage (this, image, shade, c.r, c.g, c.b);
2544 }
2545#endif
2546
2547 pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth);
2548 gc = XCreateGC (xdisp, vt, 0UL, &gcvalue);
2549 XPutImage (xdisp, pixmap, gc, image, 0, 0,
2550 nx, ny, image->width, image->height);
2551 XFreeGC (xdisp, gc);
2552 XDestroyImage (image);
2553 XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap);
2554 XClearWindow (xdisp, parent[0]);
2555
2556 if (!am_transparent || !am_pixmap_trans)
2557 pchanged = 1;
2558
2559 am_transparent = am_pixmap_trans = 1;
2560 }
2561 }
2562
2563 if (am_pixmap_trans)
2564 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2565 else
2566 {
2567 unsigned int n;
2568 /*
2569 * InheritPixmap transparency
2570 */
2571 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2572 {
2573 oldp = parent[i];
2574 XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
2575 XFree (list);
2576
2577 if (parent[i] == display->root)
2578 {
2579 if (oldp != None)
2580 pchanged = 1;
2581
2582 break;
2583 }
2584
2585 if (oldp != parent[i])
2586 pchanged = 1;
2587 }
2588
2589 n = 0;
2590
2591 if (pchanged)
2592 for (; n < (unsigned int)i; n++)
2593 {
2594 XGetWindowAttributes (xdisp, parent[n], &wattr);
2595
2596 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2597 {
2598 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2599 break;
2600 }
2601 }
2602
2603 if (n > (sizeof (parent) / sizeof (parent[0])))
2604 {
2605 XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
2606 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2607 am_transparent = 0;
2608 /* XXX: also turn off Opt_transparent? */
2609 }
2610 else
2611 {
2612 for (n = 0; n < (unsigned int)i; n++)
2613 {
2614 XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative);
2615 XClearWindow (xdisp, parent[n]);
2616 }
2617
2618 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2619 am_transparent = 1;
2620 }
2621
2622 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2623 parent[i] = None;
2624 }
2625
2626 if (scrollBar.win)
2627 {
2628 XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative);
2629 scrollBar.setIdle ();
2630 scrollbar_show (0);
2631 }
2632
2633 if (am_transparent)
2634 {
2635 want_refresh = want_full_refresh = 1;
2636 if (am_pixmap_trans)
2637 flush ();
2638 }
2639
2640 return pchanged;
2641}
2642#endif
2643
2644/*}}} */ 2199/*}}} */
2645 2200
2646bool 2201void
2647rxvt_term::cmd_parse () 2202rxvt_term::cmd_parse ()
2648{ 2203{
2649 bool flag = false;
2650 wchar_t ch = NOCHAR; 2204 wchar_t ch = NOCHAR;
2651 char *seq_begin; // remember start of esc-sequence here 2205 char *seq_begin; // remember start of esc-sequence here
2652 2206
2653 for (;;) 2207 for (;;)
2654 { 2208 {
2655 if (ch == NOCHAR) 2209 if (expect_false (ch == NOCHAR))
2656 { 2210 {
2657 seq_begin = cmdbuf_ptr; 2211 seq_begin = cmdbuf_ptr;
2658 ch = next_char (); 2212 ch = next_char ();
2659 2213
2660 if (ch == NOCHAR) 2214 if (ch == NOCHAR)
2661 break; 2215 break;
2662 } 2216 }
2663 2217
2664 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2218 if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2665 { 2219 {
2666 if (!seen_input) 2220 if (expect_false (!seen_input))
2667 { 2221 {
2668 seen_input = 1; 2222 seen_input = 1;
2669 // many badly-written programs (e.g. jed) contain a race condition: 2223 // many badly-written programs (e.g. jed) contain a race condition:
2670 // they first read the screensize and then install a SIGWINCH handler. 2224 // they first read the screensize and then install a SIGWINCH handler.
2671 // some window managers resize the window early, and these programs 2225 // some window managers resize the window early, and these programs
2684 wchar_t *str = buf; 2238 wchar_t *str = buf;
2685 wchar_t *eol = str + min (ncol, UBUFSIZ); 2239 wchar_t *eol = str + min (ncol, UBUFSIZ);
2686 2240
2687 for (;;) 2241 for (;;)
2688 { 2242 {
2689 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2243 if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2690 break; 2244 break;
2691 2245
2692 *str++ = ch; 2246 *str++ = ch;
2693 2247
2694 if (ch == C0_LF || str >= eol) 2248 if (expect_false (ch == C0_LF || str >= eol))
2695 { 2249 {
2696 if (ch == C0_LF) 2250 if (ch == C0_LF)
2697 nlines++; 2251 nlines++;
2698 2252
2699 refresh_count++; 2253 refresh_count++;
2700 2254
2701 if (!OPTION (Opt_jumpScroll) 2255 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2702 || (refresh_count >= refresh_limit * (nrow - 1)))
2703 { 2256 {
2704 refreshnow = true;
2705 refresh_count = 0; 2257 refresh_count = 0;
2258
2259 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2260 {
2261 refreshnow = true;
2706 ch = NOCHAR; 2262 ch = NOCHAR;
2707 break; 2263 break;
2264 }
2708 } 2265 }
2709 2266
2710 // scr_add_lines only works for nlines <= nrow - 1. 2267 // scr_add_lines only works for nlines <= nrow - 1.
2711 if (nlines >= nrow - 1) 2268 if (nlines >= nrow - 1)
2712 { 2269 {
2740 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) 2297 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2741 scr_add_lines (buf, str - buf, nlines); 2298 scr_add_lines (buf, str - buf, nlines);
2742 2299
2743 /* 2300 /*
2744 * If there have been a lot of new lines, then update the screen 2301 * If there have been a lot of new lines, then update the screen
2745 * What the heck I'll cheat and only refresh less than every page-full. 2302 * What the heck we'll cheat and only refresh less than every page-full.
2746 * the number of pages between refreshes is refresh_limit, which 2303 * if skipScroll is enabled.
2747 * is incremented here because we must be doing flat-out scrolling.
2748 */ 2304 */
2749 if (refreshnow) 2305 if (refreshnow)
2750 { 2306 {
2751 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2752 refresh_limit++;
2753 else
2754 {
2755 flag = true;
2756 scr_refresh (); 2307 scr_refresh ();
2757 want_refresh = 1; 2308 want_refresh = 1;
2758 }
2759 } 2309 }
2760
2761 } 2310 }
2762 else 2311 else
2763 { 2312 {
2764 try 2313 try
2765 { 2314 {
2773 } 2322 }
2774 2323
2775 ch = NOCHAR; 2324 ch = NOCHAR;
2776 } 2325 }
2777 } 2326 }
2778
2779 return flag;
2780} 2327}
2781 2328
2782// read the next character 2329// read the next character
2783wchar_t 2330wchar_t
2784rxvt_term::next_char () NOTHROW 2331rxvt_term::next_char () NOTHROW
2785{ 2332{
2786 while (cmdbuf_ptr < cmdbuf_endp) 2333 while (cmdbuf_ptr < cmdbuf_endp)
2787 { 2334 {
2788 // assume 7-bit to be ascii ALWAYS 2335 // assume 7-bit to be ascii ALWAYS
2789 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2336 if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2790 return *cmdbuf_ptr++; 2337 return *cmdbuf_ptr++;
2791 2338
2792 wchar_t wc; 2339 wchar_t wc;
2793 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2340 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2794 2341
2798 cmdbuf_ptr = cmdbuf_endp; 2345 cmdbuf_ptr = cmdbuf_endp;
2799 break; 2346 break;
2800 } 2347 }
2801 2348
2802 if (len == (size_t)-1) 2349 if (len == (size_t)-1)
2350 {
2351 mbstate.reset (); // reset now undefined conversion state
2803 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2352 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2353 }
2804 2354
2805 // assume wchar == unicode 2355 // assume wchar == unicode
2806 cmdbuf_ptr += len; 2356 cmdbuf_ptr += len;
2807 return wc & UNICODE_MASK; 2357 return wc & UNICODE_MASK;
2808 } 2358 }
2852/*----------------------------------------------------------------------*/ 2402/*----------------------------------------------------------------------*/
2853#ifdef PRINTPIPE 2403#ifdef PRINTPIPE
2854FILE * 2404FILE *
2855rxvt_term::popen_printer () 2405rxvt_term::popen_printer ()
2856{ 2406{
2857 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2407 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2858 2408
2859 if (stream == NULL) 2409 if (stream == NULL)
2860 rxvt_warn ("can't open printer pipe, not printing.\n"); 2410 rxvt_warn ("can't open printer pipe, not printing.\n");
2861 2411
2862 return stream; 2412 return stream;
2873 * simulate attached vt100 printer 2423 * simulate attached vt100 printer
2874 */ 2424 */
2875void 2425void
2876rxvt_term::process_print_pipe () 2426rxvt_term::process_print_pipe ()
2877{ 2427{
2878 int done; 2428 FILE *fd = popen_printer ();
2879 FILE *fd;
2880 2429
2881 if ((fd = popen_printer ()) == NULL) 2430 if (!fd)
2882 return; 2431 return;
2883 2432
2884 /* 2433 /*
2885 * Send all input to the printer until either ESC[4i or ESC[?4i 2434 * Send all input to the printer until either ESC[4i or ESC[?4i
2886 * is received. 2435 * is received.
2887 */ 2436 */
2888 for (done = 0; !done;) 2437 for (int done = 0; !done; )
2889 { 2438 {
2890 unsigned char buf[8]; 2439 unsigned char buf[8];
2891 unicode_t ch; 2440 unicode_t ch;
2892 unsigned int i, len; 2441 unsigned int i, len;
2893 2442
2912 { 2461 {
2913 if ((buf[len++] = cmd_getc ()) == 'i') 2462 if ((buf[len++] = cmd_getc ()) == 'i')
2914 break; /* done = 1 */ 2463 break; /* done = 1 */
2915 } 2464 }
2916 } 2465 }
2917 2466
2918 for (i = 0; i < len; i++) 2467 for (i = 0; i < len; i++)
2919 if (putc (buf[i], fd) == EOF) 2468 if (putc (buf[i], fd) == EOF)
2920 { 2469 {
2921 done = 1; 2470 done = 1;
2922 break; 2471 break;
2924 } 2473 }
2925 } 2474 }
2926 2475
2927 pclose_printer (fd); 2476 pclose_printer (fd);
2928} 2477}
2929#endif /* PRINTPIPE */ 2478#endif /* PRINTPIPE */
2930/*}}} */ 2479/*}}} */
2931 2480
2932/* *INDENT-OFF* */ 2481/* *INDENT-OFF* */
2933enum { 2482enum {
2934 C1_40 = 0x40, 2483 C1_40 = 0x40,
2984 process_dcs_seq (); 2533 process_dcs_seq ();
2985 break; 2534 break;
2986 case 0x9b: /* CSI */ 2535 case 0x9b: /* CSI */
2987 process_csi_seq (); 2536 process_csi_seq ();
2988 break; 2537 break;
2989 case 0x9d: /* CSI */ 2538 case 0x9d: /* OSC */
2990 process_osc_seq (); 2539 process_osc_seq ();
2991 break; 2540 break;
2992#endif 2541#endif
2993 } 2542 }
2994} 2543}
3038 break; 2587 break;
3039 case 'Z': /* identify the terminal type */ 2588 case 'Z': /* identify the terminal type */
3040 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2589 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3041 break; 2590 break;
3042 case '<': /* turn off VT52 mode */ 2591 case '<': /* turn off VT52 mode */
3043 PrivMode (0, PrivMode_vt52); 2592 set_privmode (PrivMode_vt52, 0);
3044 break; 2593 break;
3045 case 'F': /* use special graphics character set */ 2594 case 'F': /* use special graphics character set */
3046 case 'G': /* use regular character set */ 2595 case 'G': /* use regular character set */
3047 /* unimplemented */ 2596 /* unimplemented */
3048 break; 2597 break;
3102 scr_forwardindex (); 2651 scr_forwardindex ();
3103 break; 2652 break;
3104#endif 2653#endif
3105 case '=': 2654 case '=':
3106 case '>': 2655 case '>':
3107 PrivMode ((ch == '='), PrivMode_aplKP); 2656 set_privmode (PrivMode_aplKP, ch == '=');
3108 break; 2657 break;
3109 2658
3110 case C1_40: 2659 case C1_40:
3111 cmd_getc (); 2660 cmd_getc ();
3112 break; 2661 break;
3151 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2700 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3152 case C1_SCI: /* ESC Z */ 2701 case C1_SCI: /* ESC Z */
3153 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); 2702 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3154 break; /* steal obsolete ESC [ c */ 2703 break; /* steal obsolete ESC [ c */
3155 2704
3156 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2705 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
3157 case C1_CSI: /* ESC [ */ 2706 case C1_CSI: /* ESC [ */
3158 process_csi_seq (); 2707 process_csi_seq ();
3159 break; 2708 break;
3160 2709
3161 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2710 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
3162 case C1_OSC: /* ESC ] */ 2711 case C1_OSC: /* ESC ] */
3163 process_osc_seq (); 2712 process_osc_seq ();
3164 break; 2713 break;
3165 2714
3166 /* 8.3.106: RESET TO INITIAL STATE */ 2715 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
3167 case 'c': 2716 case 'c':
3168 mbstate.reset (); 2717 mbstate.reset ();
3169 scr_poweron (); 2718 scr_poweron ();
3170 scrollbar_show (1); 2719 scrollBar.show (1);
3171 break; 2720 break;
3172 2721
3173 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2722 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3174 case 'n': 2723 case 'n':
3175 scr_charset_choose (2); 2724 scr_charset_choose (2);
3220rxvt_term::process_csi_seq () 2769rxvt_term::process_csi_seq ()
3221{ 2770{
3222 unicode_t ch, priv, i; 2771 unicode_t ch, priv, i;
3223 unsigned int nargs, p; 2772 unsigned int nargs, p;
3224 int n, ndef; 2773 int n, ndef;
3225 int arg[ESC_ARGS]; 2774 int arg[ESC_ARGS] = { };
3226 2775
3227 for (nargs = ESC_ARGS; nargs > 0;) 2776 nargs = 0;
3228 arg[--nargs] = 0;
3229 2777
3230 priv = 0; 2778 priv = 0;
3231 ch = cmd_getc (); 2779 ch = cmd_getc ();
3232 if (ch >= '<' && ch <= '?') 2780 if ((ch >= '<' && ch <= '?') || ch == '!')
2781 {
3233 { /* '<' '=' '>' '?' */ 2782 /* '<' '=' '>' '?' '!' */
3234 priv = ch; 2783 priv = ch;
3235 ch = cmd_getc (); 2784 ch = cmd_getc ();
3236 } 2785 }
3237 2786
3238 /* read any numerical arguments */ 2787 /* read any numerical arguments */
3277 switch (priv) 2826 switch (priv)
3278 { 2827 {
3279 case '>': 2828 case '>':
3280 if (ch == CSI_DA) /* secondary device attributes */ 2829 if (ch == CSI_DA) /* secondary device attributes */
3281 { 2830 {
3282 // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, 2831 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
3283 // 'U' for rxvt-unicode != 7.[34] (where it was broken). 2832 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
3284 // 2833 //
3285 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt 2834 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
3286 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify 2835 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
3287 // that we do not support xterm mouse reporting (should be 95 when we do). 2836 // versions.
3288 // 2837 //
3289 tt_printf ("\033[>%d;94;0c", 'U'); 2838 tt_printf ("\033[>%d;95;0c", 'U');
3290 } 2839 }
3291 break; 2840 break;
2841
3292 case '?': 2842 case '?':
3293 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2843 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3294 process_terminal_mode (ch, priv, nargs, arg); 2844 process_terminal_mode (ch, priv, nargs, arg);
3295 break; 2845 break;
2846
2847 case '!':
2848 if (ch == CSI_70)
2849 {
2850 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2851 scr_soft_reset ();
2852
2853 static const int pm_h[] = { 7, 25 };
2854 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1049 };
2855
2856 process_terminal_mode ('h', 0, sizeof (pm_h) / sizeof (pm_h[0]), pm_h);
2857 process_terminal_mode ('l', 0, sizeof (pm_l) / sizeof (pm_l[0]), pm_l);
3296 } 2858 }
2859 break;
2860 }
2861
3297 return; 2862 return;
3298 } 2863 }
3299 2864
3300 switch (ch) 2865 switch (ch)
3301 { 2866 {
3421 break; 2986 break;
3422 case 6: /* CPR requested */ 2987 case 6: /* CPR requested */
3423 scr_report_position (); 2988 scr_report_position ();
3424 break; 2989 break;
3425 case 7: /* unofficial extension */ 2990 case 7: /* unofficial extension */
3426 if (OPTION (Opt_insecure)) 2991 if (option (Opt_insecure))
3427 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2992 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3428 break; 2993 break;
3429 case 8: /* unofficial extension */ 2994 case 8: /* unofficial extension */
3430 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2995 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3431 break; 2996 break;
3524{ 3089{
3525 int x, y; 3090 int x, y;
3526 XWindowAttributes wattr; 3091 XWindowAttributes wattr;
3527 Window wdummy; 3092 Window wdummy;
3528 3093
3529 dLocal (Display *, xdisp); 3094 dLocal (Display *, dpy);
3530 3095
3531 if (nargs == 0) 3096 if (nargs == 0)
3532 return; 3097 return;
3533 3098
3534 switch (args[0]) 3099 switch (args[0])
3535 { 3100 {
3536 /* 3101 /*
3537 * commands 3102 * commands
3538 */ 3103 */
3539 case 1: /* deiconify window */ 3104 case 1: /* deiconify window */
3540 XMapWindow (xdisp, parent[0]); 3105 XMapWindow (dpy, parent[0]);
3541 break; 3106 break;
3542 case 2: /* iconify window */ 3107 case 2: /* iconify window */
3543 XIconifyWindow (xdisp, parent[0], display->screen); 3108 XIconifyWindow (dpy, parent[0], display->screen);
3544 break; 3109 break;
3545 case 3: /* set position (pixels) */ 3110 case 3: /* set position (pixels) */
3546 XMoveWindow (xdisp, parent[0], args[1], args[2]); 3111 XMoveWindow (dpy, parent[0], args[1], args[2]);
3547 break; 3112 break;
3548 case 4: /* set size (pixels) */ 3113 case 4: /* set size (pixels) */
3549 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3114 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3550 break; 3115 break;
3551 case 5: /* raise window */ 3116 case 5: /* raise window */
3552 XRaiseWindow (xdisp, parent[0]); 3117 XRaiseWindow (dpy, parent[0]);
3553 break; 3118 break;
3554 case 6: /* lower window */ 3119 case 6: /* lower window */
3555 XLowerWindow (xdisp, parent[0]); 3120 XLowerWindow (dpy, parent[0]);
3556 break; 3121 break;
3557 case 7: /* refresh window */ 3122 case 7: /* refresh window */
3558 scr_touch (true); 3123 scr_touch (true);
3559 break; 3124 break;
3560 case 8: /* set size (chars) */ 3125 case 8: /* set size (chars) */
3571 3136
3572 /* 3137 /*
3573 * reports - some output format copied from XTerm 3138 * reports - some output format copied from XTerm
3574 */ 3139 */
3575 case 11: /* report window state */ 3140 case 11: /* report window state */
3576 XGetWindowAttributes (xdisp, parent[0], &wattr); 3141 XGetWindowAttributes (dpy, parent[0], &wattr);
3577 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3142 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3578 break; 3143 break;
3579 case 13: /* report window position */ 3144 case 13: /* report window position */
3580 XGetWindowAttributes (xdisp, parent[0], &wattr); 3145 XGetWindowAttributes (dpy, parent[0], &wattr);
3581 XTranslateCoordinates (xdisp, parent[0], wattr.root, 3146 XTranslateCoordinates (dpy, parent[0], wattr.root,
3582 -wattr.border_width, -wattr.border_width, 3147 -wattr.border_width, -wattr.border_width,
3583 &x, &y, &wdummy); 3148 &x, &y, &wdummy);
3584 tt_printf ("\033[3;%d;%dt", x, y); 3149 tt_printf ("\033[3;%d;%dt", x, y);
3585 break; 3150 break;
3586 case 14: /* report window size (pixels) */ 3151 case 14: /* report window size (pixels) */
3587 XGetWindowAttributes (xdisp, parent[0], &wattr); 3152 XGetWindowAttributes (dpy, parent[0], &wattr);
3588 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3153 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3589 break; 3154 break;
3590 case 18: /* report text area size (chars) */ 3155 case 18: /* report text area size (chars) */
3591 tt_printf ("\033[8;%d;%dt", nrow, ncol); 3156 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3592 break; 3157 break;
3594 tt_printf ("\033[9;%d;%dt", nrow, ncol); 3159 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3595 break; 3160 break;
3596 case 20: /* report icon label */ 3161 case 20: /* report icon label */
3597 { 3162 {
3598 char *s; 3163 char *s;
3599 XGetIconName (xdisp, parent[0], &s); 3164 XGetIconName (dpy, parent[0], &s);
3600 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3165 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3601 XFree (s); 3166 XFree (s);
3602 } 3167 }
3603 break; 3168 break;
3604 case 21: /* report window title */ 3169 case 21: /* report window title */
3605 { 3170 {
3606 char *s; 3171 char *s;
3607 XFetchName (xdisp, parent[0], &s); 3172 XFetchName (dpy, parent[0], &s);
3608 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3173 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3609 XFree (s); 3174 XFree (s);
3610 } 3175 }
3611 break; 3176 break;
3612 } 3177 }
3613} 3178}
3640 seen_esc = true; 3205 seen_esc = true;
3641 continue; 3206 continue;
3642 } 3207 }
3643 else if (ch == C0_BEL || ch == CHAR_ST) 3208 else if (ch == C0_BEL || ch == CHAR_ST)
3644 break; 3209 break;
3210 else if (ch == C0_SYN)
3211 ch = cmd_get8 ();
3645 else if (ch < 0x20) 3212 else if (ch < 0x20)
3646 return NULL; /* other control character - exit */ 3213 return NULL; /* other control character - exit */
3647 3214
3648 seen_esc = false; 3215 seen_esc = false;
3649 3216
3650 if (n >= STRING_MAX - 1) 3217 if (n >= STRING_MAX - 1)
3651 // stop at some sane length 3218 // stop at some sane length
3652 return NULL; 3219 return NULL;
3653 3220
3654 if (ch == C0_SYN)
3655 string[n++] = cmd_get8 ();
3656 else
3657 string[n++] = ch; 3221 string[n++] = ch;
3658 } 3222 }
3659 3223
3660 string[n++] = '\0'; 3224 string[n++] = '\0';
3661 3225
3662 ends_how = (ch == 0x5c ? C0_ESC : ch); 3226 ends_how = (ch == 0x5c ? C0_ESC : ch);
3669 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3233 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3670 */ 3234 */
3671void 3235void
3672rxvt_term::process_dcs_seq () 3236rxvt_term::process_dcs_seq ()
3673{ 3237{
3674 char *s;
3675 unicode_t eh;
3676
3677 /* 3238 /*
3678 * Not handled yet 3239 * Not handled yet
3679 */ 3240 */
3241
3242 unicode_t eh;
3680 s = get_to_st (eh); 3243 char *s = get_to_st (eh);
3681 if (s) 3244 if (s)
3682 free (s); 3245 free (s);
3683 3246
3684 return; 3247 return;
3685} 3248}
3689 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 3252 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3690 */ 3253 */
3691void 3254void
3692rxvt_term::process_osc_seq () 3255rxvt_term::process_osc_seq ()
3693{ 3256{
3694 unicode_t ch, eh;
3695 int arg; 3257 int arg;
3696 3258
3697 ch = cmd_getc (); 3259 unicode_t ch = cmd_getc ();
3698 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3260 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3699 arg = arg * 10 + (ch - '0'); 3261 arg = arg * 10 + (ch - '0');
3700 3262
3701 if (ch == ';') 3263 if (ch == ';')
3702 { 3264 {
3265 unicode_t eh;
3703 char *s = get_to_st (eh); 3266 char *s = get_to_st (eh);
3704 3267
3705 if (s) 3268 if (s)
3706 { 3269 {
3707 process_xterm_seq (arg, s, eh); 3270 process_xterm_seq (arg, s, eh);
3731 3294
3732/* 3295/*
3733 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3296 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3734 */ 3297 */
3735void 3298void
3736rxvt_term::process_xterm_seq (int op, const char *str, char resp) 3299rxvt_term::process_xterm_seq (int op, char *str, char resp)
3737{ 3300{
3738 int color; 3301 int color;
3739 char *buf, *name; 3302 char *buf, *name;
3740 bool query = str[0] == '?' && !str[1]; 3303 bool query = str[0] == '?' && !str[1];
3741 int saveop = op; 3304 int saveop = op;
3742 3305
3743 dLocal (Display *, xdisp); 3306 dLocal (Display *, dpy);
3744 3307
3745 assert (str != NULL); 3308 assert (str != NULL);
3309
3310 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3311 return;
3312
3746 switch (op) 3313 switch (op)
3747 { 3314 {
3748 case XTerm_name: 3315 case XTerm_name:
3749 set_title (str); 3316 set_title (str);
3750 /* FALLTHROUGH */ 3317 /* FALLTHROUGH */
3764 unsigned long bytes_after; 3331 unsigned long bytes_after;
3765 unsigned char *value = 0; 3332 unsigned char *value = 0;
3766 const char *str = ""; 3333 const char *str = "";
3767 3334
3768 if (prop 3335 if (prop
3769 && XGetWindowProperty (xdisp, parent[0], 3336 && XGetWindowProperty (dpy, parent[0],
3770 prop, 0, 1<<16, 0, AnyPropertyType, 3337 prop, 0, 1<<16, 0, AnyPropertyType,
3771 &actual_type, &actual_format, 3338 &actual_type, &actual_format,
3772 &nitems, &bytes_after, &value) == Success 3339 &nitems, &bytes_after, &value) == Success
3773 && actual_type != None 3340 && actual_type != None
3774 && actual_format == 8) 3341 && actual_format == 8)
3778 3345
3779 XFree (value); 3346 XFree (value);
3780 } 3347 }
3781 else 3348 else
3782 { 3349 {
3783 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3350 char *eq = strchr (str, '=');
3784 3351
3785 if (eq) 3352 if (eq)
3786 { 3353 {
3787 *eq = 0; 3354 *eq = 0;
3788 set_utf8_property (display->atom (str), eq + 1); 3355 set_utf8_property (display->atom (str), eq + 1);
3789 } 3356 }
3790 else 3357 else
3791 XDeleteProperty (xdisp, parent[0], 3358 XDeleteProperty (dpy, parent[0],
3792 display->atom (str)); 3359 display->atom (str));
3793 } 3360 }
3794 break; 3361 break;
3795 3362
3796 case XTerm_Color: 3363 case XTerm_Color:
3809 *buf++ = '\0'; 3376 *buf++ = '\0';
3810 3377
3811 process_color_seq (op, color, name, resp); 3378 process_color_seq (op, color, name, resp);
3812 } 3379 }
3813 break; 3380 break;
3381 case Rxvt_restoreFG:
3814 case XTerm_Color00: 3382 case XTerm_Color00:
3815 process_color_seq (op, Color_fg, str, resp); 3383 process_color_seq (op, Color_fg, str, resp);
3816 break; 3384 break;
3385 case Rxvt_restoreBG:
3817 case XTerm_Color01: 3386 case XTerm_Color01:
3818 process_color_seq (op, Color_bg, str, resp); 3387 process_color_seq (op, Color_bg, str, resp);
3819 break; 3388 break;
3820#ifndef NO_CURSORCOLOR 3389#ifndef NO_CURSORCOLOR
3821 case XTerm_Color_cursor: 3390 case XTerm_Color_cursor:
3826 process_color_seq (op, Color_pointer_fg, str, resp); 3395 process_color_seq (op, Color_pointer_fg, str, resp);
3827 break; 3396 break;
3828 case XTerm_Color_pointer_bg: 3397 case XTerm_Color_pointer_bg:
3829 process_color_seq (op, Color_pointer_bg, str, resp); 3398 process_color_seq (op, Color_pointer_bg, str, resp);
3830 break; 3399 break;
3400#ifdef OPTION_HC
3401 case XTerm_Color_HC:
3402 process_color_seq (op, Color_HC, str, resp);
3403 break;
3404 case XTerm_Color_HTC:
3405 process_color_seq (op, Color_HTC, str, resp);
3406 break;
3407#endif
3831#ifndef NO_BOLD_UNDERLINE_REVERSE 3408#ifndef NO_BOLD_UNDERLINE_REVERSE
3832 case XTerm_Color_RV:
3833 process_color_seq (op, Color_RV, str, resp);
3834 break;
3835 case Rxvt_Color_BD:
3836 case URxvt_Color_BD: 3409 case URxvt_Color_BD:
3837 process_color_seq (op, Color_BD, str, resp); 3410 process_color_seq (op, Color_BD, str, resp);
3838 break; 3411 break;
3839 case Rxvt_Color_UL:
3840 case URxvt_Color_UL: 3412 case URxvt_Color_UL:
3841 process_color_seq (op, Color_UL, str, resp); 3413 process_color_seq (op, Color_UL, str, resp);
3842 break; 3414 break;
3843 case URxvt_Color_IT: 3415 case URxvt_Color_IT:
3844 process_color_seq (op, Color_IT, str, resp); 3416 process_color_seq (op, Color_IT, str, resp);
3845 break; 3417 break;
3846#endif 3418#endif
3847#if TRANSPARENT && TINTING 3419 case URxvt_Color_border:
3420 process_color_seq (op, Color_border, str, resp);
3421 break;
3422#if ENABLE_TRANSPARENCY
3848 case URxvt_Color_tint: 3423 case URxvt_Color_tint:
3849 process_color_seq (op, Color_tint, str, resp); 3424 process_color_seq (op, Color_tint, str, resp);
3425 {
3426 bool changed = false;
3850 3427
3851 check_our_parents (); 3428 if (ISSET_PIXCOLOR (Color_tint))
3429 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3430 else
3431 changed = bgPixmap.unset_tint ();
3852 3432
3853 if (am_transparent) 3433 if (changed)
3854 want_full_refresh = want_refresh = 1; 3434 update_background ();
3435 }
3855 3436
3856 break; 3437 break;
3857#endif 3438#endif
3858 3439
3440#if BG_IMAGE_FROM_FILE
3859 case Rxvt_Pixmap: 3441 case Rxvt_Pixmap:
3860 { 3442 if (!strcmp (str, "?"))
3861 if (*str != ';')
3862 { 3443 {
3863#if XPM_BACKGROUND 3444 char str[256];
3864 scale_pixmap (""); /* reset to default scaling */ 3445
3865 set_bgPixmap (str); /* change pixmap */ 3446 sprintf (str, "[%dx%d+%d+%d]",
3866 scr_touch (true); 3447 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3867#endif 3448 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3449 process_xterm_seq (XTerm_title, str, CHAR_ST);
3868 } 3450 }
3869 3451 else
3452 {
3870 int changed = 0; 3453 int changed = 0;
3871 3454
3872 while ((str = strchr (str, ';')) != NULL) 3455 if (*str != ';')
3873 { 3456 {
3457 /* reset to default scaling :*/
3458 bgPixmap.unset_geometry ();
3459 if (bgPixmap.set_file (str)) /* change pixmap */
3460 changed++;
3461 str = strchr (str, ';');
3462 if (str == NULL)
3463 bgPixmap.set_defaultGeometry ();
3464 }
3465
3466 while (str)
3467 {
3874 str++; 3468 str++;
3875#if XPM_BACKGROUND 3469 if (bgPixmap.set_geometry (str))
3876 changed += scale_pixmap (str); 3470 changed++;
3877#endif 3471 str = strchr (str, ';');
3878 } 3472 }
3879 3473
3880 if (changed) 3474 if (changed)
3881 { 3475 update_background ();
3882#ifdef XPM_BACKGROUND
3883 resize_pixmap ();
3884 scr_touch (true);
3885#endif
3886 } 3476 }
3887 }
3888 break; 3477 break;
3889 3478#endif
3890 case Rxvt_restoreFG:
3891 set_window_color (Color_fg, str);
3892 break;
3893 case Rxvt_restoreBG:
3894 set_window_color (Color_bg, str);
3895 break;
3896 3479
3897 case XTerm_logfile: 3480 case XTerm_logfile:
3898 // TODO, when secure mode? 3481 // TODO, when secure mode?
3899 break; 3482 break;
3900 3483
3918 case URxvt_italicFont: 3501 case URxvt_italicFont:
3919 case URxvt_boldItalicFont: 3502 case URxvt_boldItalicFont:
3920#endif 3503#endif
3921 if (query) 3504 if (query)
3922 tt_printf ("\33]%d;%-.250s%c", saveop, 3505 tt_printf ("\33]%d;%-.250s%c", saveop,
3923 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3506 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3924 ? fontset[op - URxvt_font]->fontdesc : "", 3507 ? fontset[op - URxvt_font]->fontdesc : "",
3925 resp); 3508 resp);
3926 else 3509 else
3927 { 3510 {
3928 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3511 const char *&res = rs[Rs_font + (op - URxvt_font)];
3942 break; 3525 break;
3943 3526
3944#if !ENABLE_MINIMAL 3527#if !ENABLE_MINIMAL
3945 case URxvt_locale: 3528 case URxvt_locale:
3946 if (query) 3529 if (query)
3947 tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp); 3530 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3948 else 3531 else
3949 { 3532 {
3950 set_locale (str); 3533 set_locale (str);
3951 pty->set_utf8_mode (enc_utf8); 3534 pty->set_utf8_mode (enc_utf8);
3952 init_xlocale (); 3535 init_xlocale ();
3967 break; 3550 break;
3968#endif 3551#endif
3969 3552
3970#if ENABLE_PERL 3553#if ENABLE_PERL
3971 case URxvt_perl: 3554 case URxvt_perl:
3972 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END))) 3555 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3973 ; // no responses yet
3974 break; 3556 break;
3975#endif 3557#endif
3976 } 3558 }
3977} 3559}
3978/*----------------------------------------------------------------------*/ 3560/*----------------------------------------------------------------------*/
4001 { 3583 {
4002 if (mode == 'r') 3584 if (mode == 'r')
4003 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3585 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
4004 else 3586 else
4005 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3587 state = (mode == 't') ? ! (priv_modes & bit) : mode;
4006 PrivMode (state, bit); 3588
3589 set_privmode (bit, state);
4007 } 3590 }
4008 3591
4009 return state; 3592 return state;
4010} 3593}
4011 3594
4015{ 3598{
4016 unsigned int i, j; 3599 unsigned int i, j;
4017 int state; 3600 int state;
4018 3601
4019 static const struct 3602 static const struct
4020 { 3603 {
4021 const int argval; 3604 const int argval;
4022 const unsigned long bit; 3605 const unsigned long bit;
4023 }
4024
4025 argtopriv[] = { 3606 } argtopriv[] = {
4026 { 1, PrivMode_aplCUR }, 3607 { 1, PrivMode_aplCUR }, // DECCKM
4027 { 2, PrivMode_vt52 }, 3608 { 2, PrivMode_vt52 },
4028 { 3, PrivMode_132 }, 3609 { 3, PrivMode_132 }, // DECCOLM
4029 { 4, PrivMode_smoothScroll }, 3610 { 4, PrivMode_smoothScroll }, // DECSCLM
4030 { 5, PrivMode_rVideo }, 3611 { 5, PrivMode_rVideo }, // DECSCNM
4031 { 6, PrivMode_relOrigin }, 3612 { 6, PrivMode_relOrigin }, // DECOM
4032 { 7, PrivMode_Autowrap }, 3613 { 7, PrivMode_Autowrap }, // DECAWM
4033 // 8, bi-directional support mode 3614 // 8, auto-repeat keys // DECARM
4034 { 9, PrivMode_MouseX10 }, 3615 { 9, PrivMode_MouseX10 },
4035 // 18, 19 printing-related 3616 // 18 end FF to printer after print screen
3617 // 19 Print screen prints full screen/scroll region
4036 { 25, PrivMode_VisibleCursor }, 3618 { 25, PrivMode_VisibleCursor }, // cnorm/cvvis/civis
4037#ifdef scrollBar_esc 3619#ifdef scrollBar_esc
4038 { scrollBar_esc, PrivMode_scrollBar }, 3620 { scrollBar_esc, PrivMode_scrollBar },
4039#endif 3621#endif
4040 { 35, PrivMode_ShiftKeys }, // rxvt extension 3622 { 35, PrivMode_ShiftKeys }, // rxvt extension
3623 // 38, tektronix mode // DECTEK
4041 { 40, PrivMode_132OK }, 3624 { 40, PrivMode_132OK },
4042 // 41 xterm more fixes NYI 3625 // 41 xterm more fixes NYI
4043 // 45 margin bell NYI 3626 // 45 margin bell NYI
4044 // 46 start logging 3627 // 46 start logging
4045 { 47, PrivMode_Screen }, 3628 { 47, PrivMode_Screen },
4046 { 66, PrivMode_aplKP }, 3629 { 66, PrivMode_aplKP }, // DECPAM/DECPNM
4047#ifndef NO_BACKSPACE_KEY 3630#ifndef NO_BACKSPACE_KEY
4048 { 67, PrivMode_BackSpace }, 3631 { 67, PrivMode_BackSpace }, // DECBKM
4049#endif 3632#endif
4050 { 1000, PrivMode_MouseX11 }, 3633 { 1000, PrivMode_MouseX11 },
4051 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3634 { 1002, PrivMode_MouseBtnEvent },
4052 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3635 { 1003, PrivMode_MouseAnyEvent },
4053 // 1003 Use All Motion Mouse Tracking. NYI, TODO
4054 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3636 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4055 { 1011, PrivMode_Keypress }, // rxvt extension 3637 { 1011, PrivMode_Keypress }, // rxvt extension
4056 // 1035 enable modifiers for alt, numlock NYI 3638 // 1035 enable modifiers for alt, numlock NYI
4057 // 1036 send ESC for meta keys NYI 3639 // 1036 send ESC for meta keys NYI
4058 // 1037 send DEL for keypad delete NYI 3640 // 1037 send DEL for keypad delete NYI
4059 { 1047, PrivMode_Screen }, 3641 { 1047, PrivMode_Screen },
4060 // 1048 save and restore cursor 3642 // 1048 save and restore cursor
4061 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3643 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4062 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3644 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3645 { 2004, PrivMode_BracketPaste },
4063 }; 3646 };
4064 3647
4065 if (nargs == 0) 3648 if (nargs == 0)
4066 return; 3649 return;
4067 3650
4092 3675
4093 scr_touch (true); 3676 scr_touch (true);
4094 break; 3677 break;
4095#endif 3678#endif
4096 case 1048: /* alternative cursor save */ 3679 case 1048: /* alternative cursor save */
4097 case 1049:
4098 if (OPTION (Opt_secondaryScreen)) 3680 if (option (Opt_secondaryScreen))
4099 if (mode == 0) 3681 if (mode == 0)
4100 scr_cursor (RESTORE); 3682 scr_cursor (RESTORE);
4101 else if (mode == 1) 3683 else if (mode == 1)
4102 scr_cursor (SAVE); 3684 scr_cursor (SAVE);
4103 break; 3685 break;
4111 case 2: /* VT52 mode */ 3693 case 2: /* VT52 mode */
4112 /* oddball mode. should be set regardless of set/reset 3694 /* oddball mode. should be set regardless of set/reset
4113 * parameter. Return from VT52 mode with an ESC < from 3695 * parameter. Return from VT52 mode with an ESC < from
4114 * within VT52 mode 3696 * within VT52 mode
4115 */ 3697 */
4116 PrivMode (1, PrivMode_vt52); 3698 set_privmode (PrivMode_vt52, 1);
4117 break; 3699 break;
4118 case 3: /* 80/132 */ 3700 case 3: /* 80/132 */
4119 if (priv_modes & PrivMode_132OK) 3701 if (priv_modes & PrivMode_132OK)
4120 set_widthheight (((state ? 132 : 80) * fwidth), height); 3702 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
4121 break; 3703 break;
4122 case 4: /* smooth scrolling */ 3704 case 4: /* smooth scrolling */
4123 set_option (Opt_jumpScroll, !state); 3705 set_option (Opt_jumpScroll, !state);
4124 break; 3706 break;
4125 case 5: /* reverse video */ 3707 case 5: /* reverse video */
4132 scr_autowrap (state); 3714 scr_autowrap (state);
4133 break; 3715 break;
4134 /* case 8: - auto repeat, can't do on a per window basis */ 3716 /* case 8: - auto repeat, can't do on a per window basis */
4135 case 9: /* X10 mouse reporting */ 3717 case 9: /* X10 mouse reporting */
4136 if (state) /* orthogonal */ 3718 if (state) /* orthogonal */
4137 priv_modes &= ~PrivMode_MouseX11; 3719 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4138 break; 3720 break;
4139#ifdef scrollBar_esc 3721#ifdef scrollBar_esc
4140 case scrollBar_esc: 3722 case scrollBar_esc:
4141 if (scrollbar_mapping (state)) 3723 if (scrollBar.map (state))
4142 { 3724 {
4143 resize_all_windows (0, 0, 0); 3725 resize_all_windows (0, 0, 0);
4144 scr_touch (true); 3726 scr_touch (true);
4145 } 3727 }
4146 break; 3728 break;
4155 break; 3737 break;
4156 /* case 66: - application key pad */ 3738 /* case 66: - application key pad */
4157 /* case 67: - backspace key */ 3739 /* case 67: - backspace key */
4158 case 1000: /* X11 mouse reporting */ 3740 case 1000: /* X11 mouse reporting */
4159 if (state) /* orthogonal */ 3741 if (state) /* orthogonal */
4160 priv_modes &= ~PrivMode_MouseX10; 3742 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4161 break; 3743 break;
4162#if 0
4163 case 1001: 3744 case 1002:
4164 break; /* X11 mouse highlighting */ 3745 case 1003:
4165#endif 3746 if (state)
3747 {
3748 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3749 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3750 vt_emask_mouse = PointerMotionMask;
3751 }
3752 else
3753 vt_emask_mouse = NoEventMask;
3754
3755 vt_select_input ();
3756 break;
4166 case 1010: /* scroll to bottom on TTY output inhibit */ 3757 case 1010: /* scroll to bottom on TTY output inhibit */
4167 set_option (Opt_scrollTtyOutput, !state); 3758 set_option (Opt_scrollTtyOutput, !state);
4168 break; 3759 break;
4169 case 1011: /* scroll to bottom on key press */ 3760 case 1011: /* scroll to bottom on key press */
4170 set_option (Opt_scrollTtyKeypress, state); 3761 set_option (Opt_scrollTtyKeypress, state);
4171 break; 3762 break;
4172 case 1047: /* secondary screen w/ clearing last */ 3763 case 1047: /* secondary screen w/ clearing last */
4173 if (OPTION (Opt_secondaryScreen)) 3764 if (option (Opt_secondaryScreen))
4174 if (current_screen != PRIMARY) 3765 if (!state)
4175 scr_erase_screen (2); 3766 scr_erase_screen (2);
3767
4176 scr_change_screen (state); 3768 scr_change_screen (state);
4177 break; 3769 break;
4178 case 1049: /* secondary screen w/ clearing first */ 3770 case 1049: /* secondary screen w/ clearing first */
3771 if (option (Opt_secondaryScreen))
3772 if (state)
3773 scr_cursor (SAVE);
3774
4179 scr_change_screen (state); 3775 scr_change_screen (state);
3776
4180 if (OPTION (Opt_secondaryScreen)) 3777 if (option (Opt_secondaryScreen))
4181 if (current_screen != PRIMARY) 3778 if (state)
4182 scr_erase_screen (2); 3779 scr_erase_screen (2);
3780 else
3781 scr_cursor (RESTORE);
4183 break; 3782 break;
4184 default: 3783 default:
4185 break; 3784 break;
4186 } 3785 }
4187 } 3786 }
4347rxvt_term::process_graphics () 3946rxvt_term::process_graphics ()
4348{ 3947{
4349 unicode_t ch, cmd = cmd_getc (); 3948 unicode_t ch, cmd = cmd_getc ();
4350 3949
4351 if (cmd == 'Q') 3950 if (cmd == 'Q')
3951 {
4352 { /* query graphics */ 3952 /* query graphics */
4353 tt_printf ("\033G0\012"); /* no graphics */ 3953 tt_printf ("\033G0\012"); /* no graphics */
4354 return; 3954 return;
4355 } 3955 }
4356 /* swallow other graphics sequences until terminating ':' */ 3956 /* swallow other graphics sequences until terminating ':' */
4357 do 3957 do
4407 v_buffer = (char *)realloc (v_buffer, v_buflen + len); 4007 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4408 4008
4409 memcpy (v_buffer + v_buflen, data, len); 4009 memcpy (v_buffer + v_buflen, data, len);
4410 v_buflen += len; 4010 v_buflen += len;
4411 4011
4412 pty_ev.set (EVENT_READ | EVENT_WRITE); 4012 pty_ev.set (ev::READ | ev::WRITE);
4413} 4013}
4414 4014
4415void rxvt_term::pty_write () 4015void rxvt_term::pty_write ()
4416{ 4016{
4417 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4017 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4422 4022
4423 if (v_buflen == 0) 4023 if (v_buflen == 0)
4424 { 4024 {
4425 free (v_buffer); 4025 free (v_buffer);
4426 v_buffer = 0; 4026 v_buffer = 0;
4427 v_buflen = 0;
4428 4027
4429 pty_ev.set (EVENT_READ); 4028 pty_ev.set (ev::READ);
4430 return; 4029 return;
4431 } 4030 }
4432 4031
4433 memmove (v_buffer, v_buffer + written, v_buflen); 4032 memmove (v_buffer, v_buffer + written, v_buflen);
4434 } 4033 }
4435 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4034 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4436 pty_ev.set (EVENT_READ); 4035 pty_ev.set (ev::READ);
4437} 4036}
4438 4037
4439/*----------------------- end-of-file (C source) -----------------------*/ 4038/*----------------------- end-of-file (C source) -----------------------*/
4440 4039

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines