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.200 by root, Sun Feb 20 19:45:30 2005 UTC vs.
Revision 1.352 by ayin, Sun Sep 9 10:35:00 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines