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.197 by root, Thu Feb 17 15:07:48 2005 UTC vs.
Revision 1.363 by root, Sun Nov 11 04:08: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");
552 newlen = 0; 596 newlen = 0;
553 } 597 }
554 break; 598 break;
555 599
556#ifdef XK_KP_Left 600#ifdef XK_KP_Left
601 case XK_KP_Left: /* \033Ot or standard */
557 case XK_KP_Up: /* \033Ox or standard */ 602 case XK_KP_Up: /* \033Ox or standard */
603 case XK_KP_Right: /* \033Ov or standard */
558 case XK_KP_Down: /* \033Or or standard */ 604 case XK_KP_Down: /* \033Or or standard */
559 case XK_KP_Right: /* \033Ov or standard */ 605 if (kp)
560 case XK_KP_Left: /* \033Ot or standard */
561 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
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 HAVE_BG_PIXMAP
930 if (want_full_refresh) 1041 if (bgPixmap.check_clearChanged ())
931 { 1042 {
932 want_full_refresh = 0; 1043// scr_clear (true); This needs to be researched further!
933 scr_clear ();
934 scr_touch (false); 1044 scr_touch (false);
935 } 1045 }
936#endif 1046#endif
937 1047
938 if (want_refresh) 1048 if (want_refresh)
939 { 1049 {
1050 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
1051 {
1052 int row = view_start;
1053 int end_row = row + nrow;
1054
1055 while (row > top_row && ROW (row - 1).is_longer ())
1056 --row;
1057
1058 do
1059 {
1060 int start_row = row;
1061 line_t *l;
1062
1063 do
1064 {
1065 l = &ROW (row++);
1066
1067 if (!(l->f & LINE_FILTERED))
1068 {
1069 // line not filtered, mark it as filtered
1070 l->f |= LINE_FILTERED;
1071 while (l->is_longer ())
1072 {
1073 l = &ROW (row++);
1074 l->f |= LINE_FILTERED;
1075 }
1076
1077 // and filter it
1078 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
1079
1080 break;
1081 }
1082 }
1083 while (l->is_longer () && row < end_row);
1084 }
1085 while (row < end_row);
1086 }
1087
940 scr_refresh (refresh_type); 1088 scr_refresh ();
941 scrollbar_show (1); 1089 scrollbar_show (1);
942#ifdef USE_XIM 1090#ifdef USE_XIM
943 IMSendSpot (); 1091 IMSendSpot ();
944#endif 1092#endif
945 } 1093 }
946 1094
947 display->flush (); 1095 display->flush ();
948} 1096}
949 1097
950void 1098void
951rxvt_term::check_cb (check_watcher &w) 1099rxvt_term::prepare_cb (ev::prepare &w, int revents)
952{ 1100{
953 SET_R (this); 1101 make_current ();
954 SET_LOCALE (locale);
955 1102
956 display->flush (); 1103 display->flush ();
957 1104
958 if (want_refresh && !flush_ev.active) 1105 if (want_refresh && !flush_ev.active)
959 flush_ev.start (NOW + 0.01); 1106 flush_ev.start (1. / 60.); // refresh at max. 60 hz normally
960} 1107}
961 1108
962void 1109void
963rxvt_term::flush_cb (time_watcher &w) 1110rxvt_term::flush_cb (ev::timer &w, int revents)
964{ 1111{
965 SET_R (this); 1112 make_current ();
966 SET_LOCALE (locale);
967 1113
968 refresh_limit = 1;
969 refresh_count = 0; 1114 refresh_count = 0;
970 flush (); 1115 flush ();
971} 1116}
972 1117
973#ifdef CURSOR_BLINK 1118#ifdef CURSOR_BLINK
974void 1119void
975rxvt_term::cursor_blink_cb (time_watcher &w) 1120rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
976{ 1121{
977 hidden_cursor = !hidden_cursor; 1122 hidden_cursor = !hidden_cursor;
978 want_refresh = 1; 1123 want_refresh = 1;
979
980 w.start (w.at + BLINK_INTERVAL);
981} 1124}
982#endif 1125#endif
983 1126
984#ifdef TEXT_BLINK 1127#ifdef TEXT_BLINK
985void 1128void
986rxvt_term::text_blink_cb (time_watcher &w) 1129rxvt_term::text_blink_cb (ev::timer &w, int revents)
987{ 1130{
988 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1131 if (scr_refresh_rend (RS_Blink, RS_Blink))
989 { 1132 {
990 hidden_text = !hidden_text; 1133 hidden_text = !hidden_text;
991 want_refresh = 1; 1134 want_refresh = 1;
992 w.start (w.at + TEXT_BLINK_INTERVAL);
993 } 1135 }
994} 1136}
995#endif 1137#endif
996 1138
997#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1139#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
998void 1140void
999rxvt_term::cont_scroll_cb (time_watcher &w) 1141rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1000{ 1142{
1001 if ((scrollbar_isUp() || scrollbar_isDn()) && 1143 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1002 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1144 scr_page (scrollbar_isUp() ? UP : DN, 1))
1003 {
1004 refresh_type |= SMOOTH_REFRESH;
1005 want_refresh = 1; 1145 want_refresh = 1;
1006 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1146 else
1007 } 1147 w.stop ();
1008} 1148}
1009#endif 1149#endif
1010 1150
1011#ifdef SELECTION_SCROLLING 1151#ifdef SELECTION_SCROLLING
1012void 1152void
1013rxvt_term::sel_scroll_cb (time_watcher &w) 1153rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1014{ 1154{
1015 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1155 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1016 { 1156 {
1017 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1157 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1018 refresh_type |= SMOOTH_REFRESH;
1019 want_refresh = 1; 1158 want_refresh = 1;
1020 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1021 } 1159 }
1160 else
1161 w.stop ();
1022} 1162}
1023#endif 1163#endif
1024 1164
1025#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1165#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1026void 1166void
1027rxvt_term::slip_wheel_cb (time_watcher &w) 1167rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1028{ 1168{
1029 if (mouse_slip_wheel_speed == 0 1169 if (mouse_slip_wheel_speed == 0
1030 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1170 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1031 : scr_page (UP, mouse_slip_wheel_speed)) 1171 : scr_page (UP, mouse_slip_wheel_speed))
1032 { 1172 {
1033 if (TermWin.view_start == TermWin.nscrolled || 1173 if (view_start == top_row || view_start == 0)
1034 TermWin.view_start == 0)
1035 mouse_slip_wheel_speed = 0; 1174 mouse_slip_wheel_speed = 0;
1036 1175
1037 refresh_type |= SMOOTH_REFRESH;
1038 want_refresh = 1; 1176 want_refresh = 1;
1039 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1177 }
1178 else
1179 w.stop ();
1180}
1181#endif
1182
1183#if LINUX_YIELD_HACK
1184static struct event_handler
1185{
1186 ev::prepare yield_ev;
1187
1188 void yield_cb (ev::prepare &w, int revents)
1189 {
1190 // this should really be sched_yield(), but the linux guys thought
1191 // that giving a process calling sched_yield () less cpu time than
1192 // ones with high nice levels is a useful thing to do. It surely is is
1193 // allowed by the sus... as is returning ENOSYS.
1194
1195 struct timespec ts = { 0, 0 };
1196 nanosleep (&ts, 0);
1197
1198 w.stop ();
1040 } 1199 }
1041} 1200
1201 event_handler ()
1202 : yield_ev (this, &event_handler::yield_cb)
1203 {
1204 }
1205} event_handler;
1042#endif 1206#endif
1043 1207
1044bool 1208bool
1045rxvt_term::pty_fill () 1209rxvt_term::pty_fill ()
1046{ 1210{
1047 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1211 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1048 1212
1049 if (CBUFSIZ == n) 1213 if (CBUFSIZ == n)
1050 { 1214 {
1051 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1215 rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n");
1052 n = 0; 1216 n = 0;
1053 } 1217 }
1054 1218
1055 memmove (cmdbuf_base, cmdbuf_ptr, n); 1219 memmove (cmdbuf_base, cmdbuf_ptr, n);
1056 cmdbuf_ptr = cmdbuf_base; 1220 cmdbuf_ptr = cmdbuf_base;
1057 cmdbuf_endp = cmdbuf_ptr + n; 1221 cmdbuf_endp = cmdbuf_ptr + n;
1058 1222
1059 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1223 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1060 1224
1061 if (n > 0) 1225 if (r > 0)
1062 { 1226 {
1063 cmdbuf_endp += n; 1227 cmdbuf_endp += r;
1064 return true; 1228 return true;
1065 } 1229 }
1066 else if (n < 0 && errno != EAGAIN) 1230 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1231 {
1232#if LINUX_YIELD_HACK
1233 if (display->is_local)
1234 event_handler.yield_ev.start ();
1235#endif
1236 }
1237 else
1238 {
1239 pty_ev.stop ();
1240
1241 if (!option (Opt_hold))
1067 destroy (); 1242 destroy ();
1068 1243 }
1244
1069 return false; 1245 return false;
1070} 1246}
1071 1247
1072void 1248void
1073rxvt_term::pty_cb (io_watcher &w, short revents) 1249rxvt_term::pty_cb (ev::io &w, int revents)
1074{ 1250{
1075 SET_R (this); 1251 make_current ();
1076 SET_LOCALE (locale);
1077 1252
1078 if (revents & EVENT_READ) 1253 if (revents & ev::READ)
1079 // loop, but don't allow a single term to monopolize us 1254 // loop, but don't allow a single term to monopolize us
1080 while (pty_fill ()) 1255 while (pty_fill ())
1081 if (cmd_parse ()) 1256 if (cmd_parse ())
1082 break; 1257 break;
1083 1258
1084 if (revents & EVENT_WRITE) 1259 if (revents & ev::WRITE)
1085 pty_write (); 1260 pty_write ();
1086} 1261}
1087 1262
1088void 1263void
1089rxvt_term::pointer_unblank () 1264rxvt_term::pointer_unblank ()
1090{ 1265{
1091 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1266 XDefineCursor (dpy, vt, TermWin_cursor);
1092 recolour_cursor (); 1267 recolour_cursor ();
1093 1268
1094#ifdef POINTER_BLANK 1269#ifdef POINTER_BLANK
1095 hidden_pointer = 0; 1270 hidden_pointer = 0;
1096 1271
1097 if (options & Opt_pointerBlank) 1272 if (option (Opt_pointerBlank))
1098 pointer_ev.start (NOW + pointerBlankDelay); 1273 pointer_ev.start (pointerBlankDelay);
1099#endif 1274#endif
1100} 1275}
1101 1276
1102#ifdef POINTER_BLANK 1277#ifdef POINTER_BLANK
1103void 1278void
1104rxvt_term::pointer_blank () 1279rxvt_term::pointer_blank ()
1105{ 1280{
1106 if (! (options & Opt_pointerBlank)) 1281 if (!option (Opt_pointerBlank))
1107 return; 1282 return;
1108 1283
1109 XDefineCursor (display->display, TermWin.vt, display->blank_cursor); 1284 XDefineCursor (dpy, vt, display->blank_cursor);
1110 XFlush (display->display); 1285 XFlush (dpy);
1111 1286
1112 hidden_pointer = 1; 1287 hidden_pointer = 1;
1113} 1288}
1114 1289
1115void 1290void
1116rxvt_term::pointer_cb (time_watcher &w) 1291rxvt_term::pointer_cb (ev::timer &w, int revents)
1117{ 1292{
1118 SET_R (this); 1293 make_current ();
1119 SET_LOCALE (locale);
1120 1294
1121 pointer_blank (); 1295 pointer_blank ();
1122} 1296}
1123#endif 1297#endif
1124 1298
1125void 1299void
1126rxvt_term::mouse_report (XButtonEvent &ev) 1300rxvt_term::mouse_report (XButtonEvent &ev)
1127{ 1301{
1128 int button_number, key_state = 0; 1302 int button_number, key_state = 0;
1129 int x, y; 1303 int x, y;
1304 int code = 32;
1130 1305
1131 x = ev.x; 1306 x = Pixel2Col (ev.x);
1132 y = ev.y; 1307 y = Pixel2Row (ev.y);
1133 pixel_position (&x, &y); 1308 if (ev.type == MotionNotify) {
1309 if (x == mouse_row && y == mouse_col)
1310 return;
1311 mouse_row = x;
1312 mouse_col = y;
1313 code += 32;
1314 }
1134 1315
1135 if (MEvent.button == AnyButton) 1316 if (MEvent.button == AnyButton)
1136 button_number = 3; 1317 button_number = 3;
1137 else 1318 else
1138 { 1319 {
1184 x + 1, 1365 x + 1,
1185 y + 1); 1366 y + 1);
1186#endif 1367#endif
1187 1368
1188 tt_printf ("\033[M%c%c%c", 1369 tt_printf ("\033[M%c%c%c",
1189 (32 + button_number + key_state), 1370 (code + button_number + key_state),
1190 (32 + x + 1), 1371 (32 + x + 1),
1191 (32 + y + 1)); 1372 (32 + y + 1));
1192} 1373}
1193
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 1374
1204/*{{{ process an X event */ 1375/*{{{ process an X event */
1205void 1376void
1206rxvt_term::x_cb (XEvent &ev) 1377rxvt_term::x_cb (XEvent &ev)
1207{ 1378{
1208 dDisp; 1379 make_current ();
1209 1380
1210 SET_R (this); 1381 dLocal (Display *, dpy);
1211 SET_LOCALE (locale);
1212 1382
1213#if defined(CURSOR_BLINK) 1383 if (ev.xany.window == vt
1214 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1384 && SHOULD_INVOKE (HOOK_X_EVENT)
1215 { 1385 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1216 if (hidden_cursor) 1386 return;
1217 {
1218 hidden_cursor = 0;
1219 want_refresh = 1;
1220 }
1221 1387
1222 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1388 // 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; 1389 Window unused_root, unused_child;
1241 int unused_root_x, unused_root_y; 1390 int unused_root_x, unused_root_y;
1242 unsigned int unused_mask; 1391 unsigned int unused_mask;
1243 1392
1244 switch (ev.type) 1393 switch (ev.type)
1245 { 1394 {
1246 case KeyPress: 1395 case KeyPress:
1247#if ISO_14755 1396 key_press (ev.xkey);
1248 if (!(iso14755buf & ISO_14755_52))
1249#endif
1250 lookup_key (ev.xkey);
1251
1252 break; 1397 break;
1253 1398
1254 case KeyRelease: 1399 case KeyRelease:
1255 { 1400 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; 1401 break;
1323 }
1324 1402
1325 case ButtonPress: 1403 case ButtonPress:
1326 button_press (ev.xbutton); 1404 button_press (ev.xbutton);
1327 break; 1405 break;
1328 1406
1330 button_release (ev.xbutton); 1408 button_release (ev.xbutton);
1331 break; 1409 break;
1332 1410
1333 case ClientMessage: 1411 case ClientMessage:
1334 if (ev.xclient.format == 32 1412 if (ev.xclient.format == 32
1335 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) 1413 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1336 destroy ();
1337#ifdef OFFIX_DND
1338 /* OffiX Dnd (drag 'n' drop) protocol */
1339 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1340 && (ev.xclient.data.l[0] == DndFile
1341 || ev.xclient.data.l[0] == DndDir
1342 || ev.xclient.data.l[0] == DndLink))
1343 { 1414 {
1344 /* Get Dnd data */ 1415 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1345 Atom ActualType; 1416 {
1346 int ActualFormat; 1417 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1347 unsigned char *data; 1418 {
1348 unsigned long Size, RemainingBytes; 1419 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1349 1420 {
1350 XGetWindowProperty (disp, display->root, 1421 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1351 xa[XA_DNDSELECTION], 1422 destroy ();
1352 0L, 1000000L, 1423 }
1353 False, AnyPropertyType, 1424#if ENABLE_EWMH
1354 &ActualType, &ActualFormat, 1425 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1355 &Size, &RemainingBytes, 1426 XSendEvent (dpy, ev.xclient.window = display->root,
1427 False, SubstructureRedirectMask | SubstructureNotifyMask,
1356 &data); 1428 &ev);
1357 set_string_property (XA_CUT_BUFFER0, data); 1429#endif
1358 XFree (data); 1430 }
1359 selection_paste (display->root, XA_CUT_BUFFER0, true); 1431 }
1360 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime); 1432#if ENABLE_XEMBED
1433 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1434 {
1435 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1436 focus_in ();
1437 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1438 focus_out ();
1439 }
1440#endif
1361 } 1441 }
1362#endif /* OFFIX_DND */
1363 break;
1364
1365 case MappingNotify:
1366 XRefreshKeyboardMapping (&ev.xmapping);
1367 break; 1442 break;
1368 1443
1369 /* 1444 /*
1370 * XXX: this is not the _current_ arrangement 1445 * XXX: this is not the _current_ arrangement
1371 * Here's my conclusion: 1446 * Here's my conclusion:
1390 break; 1465 break;
1391 } 1466 }
1392 break; 1467 break;
1393 1468
1394 case FocusIn: 1469 case FocusIn:
1395 if (!TermWin.focus) 1470 if (ev.xfocus.detail != NotifyInferior
1471 && ev.xfocus.detail != NotifyPointer
1472 && ev.xfocus.mode != NotifyGrab)
1473 focus_in ();
1474 break;
1475
1476 case FocusOut:
1477 if (ev.xfocus.detail != NotifyInferior
1478 && ev.xfocus.detail != NotifyPointer
1479 && ev.xfocus.mode != NotifyGrab)
1480 focus_out ();
1481 break;
1482
1483 case ConfigureNotify:
1484 /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1485 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1486 szHint.width, szHint.height); */
1487 if (ev.xconfigure.window == parent[0])
1396 { 1488 {
1397 TermWin.focus = 1;
1398 want_refresh = 1;
1399#ifdef USE_XIM
1400 if (Input_Context != NULL)
1401 {
1402 IMSetStatusPosition ();
1403 XSetICFocus (Input_Context);
1404 }
1405#endif
1406#ifdef CURSOR_BLINK
1407 if (options & Opt_cursorBlink)
1408 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1409#endif
1410#ifdef OFF_FOCUS_FADING
1411 if (rs[Rs_fade])
1412 {
1413 pix_colors = pix_colors_focused;
1414 scr_recolour ();
1415 }
1416#endif
1417
1418 }
1419 break;
1420
1421 case FocusOut:
1422 if (TermWin.focus)
1423 {
1424 TermWin.focus = 0;
1425 want_refresh = 1;
1426
1427#if ENABLE_FRILLS || ISO_14755
1428 iso14755buf = 0;
1429#endif
1430#if ENABLE_OVERLAY
1431 scr_overlay_off ();
1432#endif
1433#ifdef USE_XIM
1434 if (Input_Context != NULL)
1435 XUnsetICFocus (Input_Context);
1436#endif
1437#ifdef CURSOR_BLINK
1438 if (options & Opt_cursorBlink)
1439 cursor_blink_ev.stop ();
1440 hidden_cursor = 0;
1441#endif
1442#ifdef OFF_FOCUS_FADING
1443 if (rs[Rs_fade])
1444 {
1445 pix_colors = pix_colors_unfocused;
1446 scr_recolour ();
1447 }
1448#endif
1449 }
1450 break;
1451
1452 case ConfigureNotify:
1453 if (ev.xconfigure.window == TermWin.parent[0])
1454 {
1455 int height, width;
1456
1457 do
1458 { /* Wrap lots of configures into one */
1459 width = ev.xconfigure.width;
1460 height = ev.xconfigure.height;
1461 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1462 }
1463 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); 1489 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1490 ;
1464 1491
1465 if (szHint.width != width || szHint.height != height) 1492 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1466 { 1493 {
1467 seen_resize = 1; 1494 seen_resize = 1;
1468 resize_all_windows (width, height, 1); 1495 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1469 } 1496 }
1470 1497 else
1471#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1498 {
1472 if (options & Opt_transparent) 1499#ifdef HAVE_BG_PIXMAP
1473 check_our_parents (); 1500 if (bgPixmap.window_position_sensitive ())
1501 update_background ();
1474#endif 1502#endif
1503 }
1504 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1475 } 1505 }
1476 break; 1506 break;
1477 1507
1478 case PropertyNotify: 1508 case PropertyNotify:
1509 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1479 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1510 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1480 && ev.xproperty.state == PropertyNewValue) 1511 && ev.xproperty.state == PropertyNewValue)
1481 selection_property (ev.xproperty.window, ev.xproperty.atom); 1512 selection_property (ev.xproperty.window, ev.xproperty.atom);
1482 1513
1483 break; 1514 break;
1484 1515
1485 case SelectionClear: 1516 case SelectionClear:
1486 selection_clear (); 1517 selection_clear ();
1493 1524
1494 case SelectionRequest: 1525 case SelectionRequest:
1495 selection_send (ev.xselectionrequest); 1526 selection_send (ev.xselectionrequest);
1496 break; 1527 break;
1497 1528
1529 case MapNotify:
1530 mapped = 1;
1531#ifdef TEXT_BLINK
1532 text_blink_ev.start (TEXT_BLINK_INTERVAL);
1533#endif
1534 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1535 break;
1536
1498 case UnmapNotify: 1537 case UnmapNotify:
1499 TermWin.mapped = 0; 1538 mapped = 0;
1500#ifdef TEXT_BLINK 1539#ifdef TEXT_BLINK
1501 text_blink_ev.stop (); 1540 text_blink_ev.stop ();
1502#endif 1541#endif
1542 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1503 break; 1543 break;
1504
1505 case MapNotify:
1506 TermWin.mapped = 1;
1507#ifdef TEXT_BLINK
1508 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1509#endif
1510 break;
1511
1512#ifdef TRANSPARENT
1513 case ReparentNotify:
1514 rootwin_cb (ev);
1515 break;
1516#endif /* TRANSPARENT */
1517 1544
1518 case GraphicsExpose: 1545 case GraphicsExpose:
1519 case Expose: 1546 case Expose:
1520 if (ev.xany.window == TermWin.vt) 1547 if (ev.xany.window == vt)
1521 { 1548 {
1522 do 1549 do
1550 {
1523 scr_expose (ev.xexpose.x, ev.xexpose.y, 1551 scr_expose (ev.xexpose.x, ev.xexpose.y,
1524 ev.xexpose.width, ev.xexpose.height, False); 1552 ev.xexpose.width, ev.xexpose.height, False);
1553 }
1525 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1554 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1526 1555
1527 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1556 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1528 1557
1529 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1558 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1559 {
1530 scr_expose (ev.xexpose.x, ev.xexpose.y, 1560 scr_expose (ev.xexpose.x, ev.xexpose.y,
1531 ev.xexpose.width, ev.xexpose.height, False); 1561 ev.xexpose.width, ev.xexpose.height, False);
1532 1562 }
1533 scr_refresh (refresh_type); 1563 want_refresh = 1;
1534 } 1564 }
1535 else 1565 else
1536 { 1566 {
1537 XEvent unused_event; 1567 XEvent unused_event;
1538 1568
1539 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1569 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1540 ; 1570 ;
1541 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1571 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1542 ; 1572 ;
1543 1573
1544 if (isScrollbarWindow (ev.xany.window)) 1574 if (isScrollbarWindow (ev.xany.window))
1545 { 1575 {
1546 scrollBar.setIdle (); 1576 scrollBar.setIdle ();
1547 scrollbar_show (0); 1577 scrollbar_show (0);
1548 } 1578 }
1549#ifdef MENUBAR
1550 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1551 menubar_expose ();
1552#endif
1553
1554#ifdef TRANSPARENT
1555 if (am_transparent && ev.xany.window == TermWin.parent[0])
1556 XClearWindow (disp, ev.xany.window);
1557#endif
1558 } 1579 }
1559 break; 1580 break;
1560 1581
1561 case MotionNotify: 1582 case MotionNotify:
1562#ifdef POINTER_BLANK 1583#ifdef POINTER_BLANK
1563 if (hidden_pointer) 1584 if (hidden_pointer)
1564 pointer_unblank (); 1585 pointer_unblank ();
1565#endif 1586#endif
1566#if MENUBAR 1587 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1567 if (isMenuBarWindow (ev.xany.window)) 1588 || priv_modes & PrivMode_MouseAnyEvent)
1568 {
1569 menubar_control (ev.xbutton); 1589 mouse_report (ev.xbutton);
1570 break;
1571 }
1572#endif
1573 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1590 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1574 break; 1591 break;
1575 1592
1576 if (ev.xany.window == TermWin.vt) 1593 if (ev.xany.window == vt)
1577 { 1594 {
1595 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1596 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1597 ; // nop
1578 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1598 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1579 { 1599 {
1580 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1600 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1581 ; 1601 ;
1582 1602
1583 XQueryPointer (disp, TermWin.vt, 1603 XQueryPointer (dpy, vt,
1584 &unused_root, &unused_child, 1604 &unused_root, &unused_child,
1585 &unused_root_x, &unused_root_y, 1605 &unused_root_x, &unused_root_y,
1586 &ev.xbutton.x, &ev.xbutton.y, 1606 &ev.xbutton.x, &ev.xbutton.y,
1587 &ev.xbutton.state); 1607 &ev.xbutton.state);
1588#ifdef MOUSE_THRESHOLD 1608#ifdef MOUSE_THRESHOLD
1600#endif 1620#endif
1601 selection_extend (ev.xbutton.x, ev.xbutton.y, 1621 selection_extend (ev.xbutton.x, ev.xbutton.y,
1602 ev.xbutton.state & Button3Mask ? 2 : 0); 1622 ev.xbutton.state & Button3Mask ? 2 : 0);
1603 1623
1604#ifdef SELECTION_SCROLLING 1624#ifdef SELECTION_SCROLLING
1605 if (ev.xbutton.y < TermWin.int_bwidth 1625 if (ev.xbutton.y < int_bwidth
1606 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1626 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1607 { 1627 {
1608 int dist; 1628 int dist;
1609 1629
1610 /* don't clobber the current delay if we are 1630 /* don't clobber the current delay if we are
1611 * already in the middle of scrolling. 1631 * already in the middle of scrolling.
1612 */ 1632 */
1613 if (!sel_scroll_ev.active) 1633 if (!sel_scroll_ev.active)
1614 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1634 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1615 1635
1616 /* save the event params so we can highlight 1636 /* save the event params so we can highlight
1617 * the selection in the pending-scroll loop 1637 * the selection in the pending-scroll loop
1618 */ 1638 */
1619 selection_save_x = ev.xbutton.x; 1639 selection_save_x = ev.xbutton.x;
1620 selection_save_y = ev.xbutton.y; 1640 selection_save_y = ev.xbutton.y;
1621 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1641 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1622 1642
1623 /* calc number of lines to scroll */ 1643 /* calc number of lines to scroll */
1624 if (ev.xbutton.y < TermWin.int_bwidth) 1644 if (ev.xbutton.y < int_bwidth)
1625 { 1645 {
1626 scroll_selection_dir = UP; 1646 scroll_selection_dir = UP;
1627 dist = TermWin.int_bwidth - ev.xbutton.y; 1647 dist = int_bwidth - ev.xbutton.y;
1628 } 1648 }
1629 else 1649 else
1630 { 1650 {
1631 scroll_selection_dir = DN; 1651 scroll_selection_dir = DN;
1632 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1652 dist = ev.xbutton.y - (int_bwidth + height);
1633 } 1653 }
1634 1654
1635 scroll_selection_lines = Pixel2Height (dist) 1655 scroll_selection_lines = Pixel2Height (dist)
1636 / SELECTION_SCROLL_LINE_SPEEDUP 1656 / SELECTION_SCROLL_LINE_SPEEDUP
1637 + 1; 1657 + 1;
1638 MIN_IT (scroll_selection_lines, 1658 min_it (scroll_selection_lines,
1639 SELECTION_SCROLL_MAX_LINES); 1659 SELECTION_SCROLL_MAX_LINES);
1640 } 1660 }
1641 else 1661 else
1642 { 1662 {
1643 /* we are within the text window, so we 1663 /* we are within the text window, so we
1652#endif 1672#endif
1653 } 1673 }
1654 } 1674 }
1655 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1675 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1656 { 1676 {
1657 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1677 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1658 MotionNotify, &ev)) 1678 MotionNotify, &ev))
1659 ; 1679 ;
1660 1680
1661 XQueryPointer (disp, scrollBar.win, 1681 XQueryPointer (dpy, scrollBar.win,
1662 &unused_root, &unused_child, 1682 &unused_root, &unused_child,
1663 &unused_root_x, &unused_root_y, 1683 &unused_root_x, &unused_root_y,
1664 &ev.xbutton.x, &ev.xbutton.y, 1684 &ev.xbutton.x, &ev.xbutton.y,
1665 &unused_mask); 1685 &unused_mask);
1666 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1686 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1667 scrollbar_size ()); 1687 scrollbar_size ());
1668 scr_refresh (refresh_type);
1669 refresh_limit = 0; 1688 want_refresh = 1;
1670 scrollbar_show (1); 1689 scrollbar_show (1);
1671 } 1690 }
1672 break; 1691 break;
1673 } 1692 }
1674}
1675 1693
1676#if TRANSPARENT 1694#if defined(CURSOR_BLINK)
1695 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1696 {
1697 if (hidden_cursor)
1698 {
1699 hidden_cursor = 0;
1700 want_refresh = 1;
1701 }
1702
1703 cursor_blink_ev.again ();
1704 }
1705#endif
1706
1707#if defined(POINTER_BLANK)
1708 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1709 {
1710 if (ev.type == MotionNotify
1711 || ev.type == ButtonPress
1712 || ev.type == ButtonRelease)
1713 if (hidden_pointer)
1714 pointer_unblank ();
1715
1716 if (ev.type == KeyPress && hidden_pointer == 0)
1717 pointer_blank ();
1718 }
1719#endif
1720}
1721
1722void
1723rxvt_term::focus_in ()
1724{
1725 if (!focus)
1726 {
1727 focus = 1;
1728 want_refresh = 1;
1729
1730 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1731
1732#if USE_XIM
1733 if (Input_Context != NULL)
1734 {
1735 IMSetPosition ();
1736 XSetICFocus (Input_Context);
1737 }
1738#endif
1739#if CURSOR_BLINK
1740 if (option (Opt_cursorBlink))
1741 cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL);
1742#endif
1743#if OFF_FOCUS_FADING
1744 if (rs[Rs_fade])
1745 {
1746 pix_colors = pix_colors_focused;
1747 scr_recolour ();
1748 }
1749#endif
1750#if ENABLE_FRILLS
1751 if (option (Opt_urgentOnBell))
1752 {
1753 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1754 {
1755 h->flags &= ~XUrgencyHint;
1756 XSetWMHints (dpy, parent[0], h);
1757 }
1758 }
1759#endif
1760 }
1761}
1762
1763void
1764rxvt_term::focus_out ()
1765{
1766 if (focus)
1767 {
1768 focus = 0;
1769 want_refresh = 1;
1770
1771 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1772
1773#if ENABLE_FRILLS || ISO_14755
1774 if (iso14755buf)
1775 {
1776 iso14755buf = 0;
1777# if ISO_14755
1778 scr_overlay_off ();
1779# endif
1780 }
1781#endif
1782#if USE_XIM
1783 if (Input_Context != NULL)
1784 XUnsetICFocus (Input_Context);
1785#endif
1786#if CURSOR_BLINK
1787 if (option (Opt_cursorBlink))
1788 cursor_blink_ev.stop ();
1789
1790 hidden_cursor = 0;
1791#endif
1792#if OFF_FOCUS_FADING
1793 if (rs[Rs_fade])
1794 {
1795 pix_colors = pix_colors_unfocused;
1796 scr_recolour ();
1797 }
1798#endif
1799 }
1800}
1801
1802void
1803rxvt_term::update_fade_color (unsigned int idx)
1804{
1805#if OFF_FOCUS_FADING
1806 if (rs[Rs_fade])
1807 {
1808 rgba c;
1809 pix_colors [Color_fade].get (c);
1810 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1811 }
1812#endif
1813}
1814
1815#if ENABLE_TRANSPARENCY || ENABLE_PERL
1677void 1816void
1678rxvt_term::rootwin_cb (XEvent &ev) 1817rxvt_term::rootwin_cb (XEvent &ev)
1679{ 1818{
1680 SET_R (this); 1819 make_current ();
1681 SET_LOCALE (locale);
1682 1820
1821 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1822 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1823 return;
1824
1825# if ENABLE_TRANSPARENCY
1683 switch (ev.type) 1826 switch (ev.type)
1684 { 1827 {
1685 case PropertyNotify: 1828 case PropertyNotify:
1686 /* 1829 /*
1687 * if user used some Esetroot compatible prog to set the root bg, 1830 * if user used some Esetroot compatible prog to set the root bg,
1688 * use the property to determine the pixmap. We use it later on. 1831 * use the property to determine the pixmap. We use it later on.
1689 */ 1832 */
1690 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1833 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1691 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1834 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1692 return; 1835 {
1693 1836 bgPixmap.set_root_pixmap ();
1694 /* FALLTHROUGH */ 1837 update_background ();
1695 case ReparentNotify: 1838 }
1696 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1697 want_refresh = want_full_refresh = 1;
1698 break; 1839 break;
1699 } 1840 }
1841# endif
1700} 1842}
1701#endif 1843#endif
1702 1844
1703void 1845void
1704rxvt_term::button_press (XButtonEvent &ev) 1846rxvt_term::button_press (XButtonEvent &ev)
1705{ 1847{
1706 int reportmode = 0, clickintime; 1848 int reportmode = 0, clickintime;
1707 1849
1708 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1850 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1851
1709 if (!bypass_keystate) 1852 if (!bypass_keystate)
1710 reportmode = !! (priv_modes & PrivMode_mouse_report); 1853 reportmode = !! (priv_modes & PrivMode_mouse_report);
1711 1854
1712 /* 1855 /*
1713 * VT window processing of button press 1856 * VT window processing of button press
1714 */ 1857 */
1715 if (ev.window == TermWin.vt) 1858 if (ev.window == vt)
1716 { 1859 {
1860 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1861 return;
1862
1717#if ISO_14755 1863#if ISO_14755
1718 // 5.4 1864 // 5.4
1719 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1865 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1720 { 1866 {
1721 iso14755_54 (ev.x, ev.y); 1867 iso14755_54 (ev.x, ev.y);
1733#ifdef MOUSE_REPORT_DOUBLECLICK 1879#ifdef MOUSE_REPORT_DOUBLECLICK
1734 if (ev.button == MEvent.button && clickintime) 1880 if (ev.button == MEvent.button && clickintime)
1735 { 1881 {
1736 /* same button, within alloted time */ 1882 /* same button, within alloted time */
1737 MEvent.clicks++; 1883 MEvent.clicks++;
1884
1738 if (MEvent.clicks > 1) 1885 if (MEvent.clicks > 1)
1739 { 1886 {
1740 /* only report double clicks */ 1887 /* only report double clicks */
1741 MEvent.clicks = 2; 1888 MEvent.clicks = 2;
1742 mouse_report (ev); 1889 mouse_report (ev);
1774#else 1921#else
1775 selection.rect = false; 1922 selection.rect = false;
1776#endif 1923#endif
1777 1924
1778 /* allow shift+left click to extend selection */ 1925 /* allow shift+left click to extend selection */
1779 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1926 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1780 { 1927 {
1781 if (MEvent.button == Button1 && clickintime) 1928 if (MEvent.button == Button1 && clickintime)
1782 selection_rotate (ev.x, ev.y); 1929 selection_rotate (ev.x, ev.y);
1783 else 1930 else
1784 selection_extend (ev.x, ev.y, 1); 1931 selection_extend (ev.x, ev.y, 1);
1880 upordown = 1; /* down */ 2027 upordown = 1; /* down */
1881 } 2028 }
1882 if (upordown) 2029 if (upordown)
1883 { 2030 {
1884#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 2031#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1885 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 2032 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1886#endif 2033#endif
1887 if (scr_page (upordown < 0 ? UP : DN, 1)) 2034 if (scr_page (upordown < 0 ? UP : DN, 1))
1888 { 2035 {
1889 if (upordown < 0) 2036 if (upordown < 0)
1890 scrollBar.setUp (); 2037 scrollBar.setUp ();
1925 case Button3: 2072 case Button3:
1926 if (scrollBar.style != R_SB_XTERM) 2073 if (scrollBar.style != R_SB_XTERM)
1927 { 2074 {
1928 if (scrollbar_above_slider (ev.y)) 2075 if (scrollbar_above_slider (ev.y))
1929# ifdef RXVT_SCROLL_FULL 2076# ifdef RXVT_SCROLL_FULL
1930 scr_page (UP, TermWin.nrow - 1); 2077 scr_page (UP, nrow - 1);
1931# else 2078# else
1932 scr_page (UP, TermWin.nrow / 4); 2079 scr_page (UP, nrow / 4);
1933# endif 2080# endif
1934 else if (scrollbar_below_slider (ev.y)) 2081 else if (scrollbar_below_slider (ev.y))
1935# ifdef RXVT_SCROLL_FULL 2082# ifdef RXVT_SCROLL_FULL
1936 scr_page (DN, TermWin.nrow - 1); 2083 scr_page (DN, nrow - 1);
1937# else 2084# else
1938 scr_page (DN, TermWin.nrow / 4); 2085 scr_page (DN, nrow / 4);
1939# endif 2086# endif
1940 else 2087 else
1941 scrollBar.setMotion (); 2088 scrollBar.setMotion ();
1942 } 2089 }
1943 else 2090 else
1944 { 2091 {
1945 scr_page ((ev.button == Button1 ? DN : UP), 2092 scr_page ((ev.button == Button1 ? DN : UP),
1946 (TermWin.nrow 2093 (nrow
1947 * scrollbar_position (ev.y) 2094 * scrollbar_position (ev.y)
1948 / scrollbar_size ())); 2095 / scrollbar_size ()));
1949 } 2096 }
1950 2097
1951 break; 2098 break;
1952 } 2099 }
1953 } 2100 }
2101
1954 return; 2102 return;
1955 } 2103 }
1956#if MENUBAR
1957 /*
1958 * Menubar window processing of button press
1959 */
1960 if (isMenuBarWindow (ev.window))
1961 menubar_control (ev);
1962#endif
1963} 2104}
1964 2105
1965void 2106void
1966rxvt_term::button_release (XButtonEvent &ev) 2107rxvt_term::button_release (XButtonEvent &ev)
1967{ 2108{
1973 2114
1974 if (scrollbar_isUpDn ()) 2115 if (scrollbar_isUpDn ())
1975 { 2116 {
1976 scrollBar.setIdle (); 2117 scrollBar.setIdle ();
1977 scrollbar_show (0); 2118 scrollbar_show (0);
1978#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1979 refresh_type &= ~SMOOTH_REFRESH;
1980#endif
1981 } 2119 }
1982 2120
1983#ifdef SELECTION_SCROLLING 2121#ifdef SELECTION_SCROLLING
1984 if (sel_scroll_ev.active) 2122 if (sel_scroll_ev.active)
1985 sel_scroll_ev.stop(); 2123 sel_scroll_ev.stop();
1986#endif 2124#endif
1987 2125
1988 if (ev.window == TermWin.vt) 2126 if (ev.window == vt)
1989 { 2127 {
2128 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2129 return;
2130
1990#if ISO_14755 2131#if ISO_14755
1991 // 5.4 2132 // 5.4
1992 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2133 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1993 return; 2134 return;
1994#endif 2135#endif
2136
1995 if (reportmode) 2137 if (reportmode)
1996 { 2138 {
1997 /* mouse report from vt window */ 2139 /* mouse report from vt window */
1998 /* don't report release of wheel "buttons" */ 2140 /* don't report release of wheel "buttons" */
1999 if (ev.button >= 4) 2141 if (ev.button >= 4)
2029 { 2171 {
2030 case Button1: 2172 case Button1:
2031 case Button3: 2173 case Button3:
2032 selection_make (ev.time); 2174 selection_make (ev.time);
2033 break; 2175 break;
2176
2034 case Button2: 2177 case Button2:
2035 selection_request (ev.time, ev.x, ev.y); 2178 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2179 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2036 break; 2180 break;
2181
2037#ifdef MOUSE_WHEEL 2182#ifdef MOUSE_WHEEL
2038 case Button4: 2183 case Button4:
2039 case Button5: 2184 case Button5:
2040 { 2185 {
2041 int i; 2186 int i;
2043 2188
2044 v = ev.button == Button4 ? UP : DN; 2189 v = ev.button == Button4 ? UP : DN;
2045 2190
2046 if (ev.state & ShiftMask) 2191 if (ev.state & ShiftMask)
2047 i = 1; 2192 i = 1;
2048 else if (options & Opt_mouseWheelScrollPage) 2193 else if (option (Opt_mouseWheelScrollPage))
2049 i = TermWin.nrow - 1; 2194 i = nrow - 1;
2050 else 2195 else
2051 i = 5; 2196 i = 5;
2052 2197
2053# ifdef MOUSE_SLIP_WHEELING 2198# ifdef MOUSE_SLIP_WHEELING
2054 if (ev.state & ControlMask) 2199 if (ev.state & ControlMask)
2055 { 2200 {
2056 mouse_slip_wheel_speed += v ? -1 : 1; 2201 mouse_slip_wheel_speed += v ? -1 : 1;
2057 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2202 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2058 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; 2203 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2059 2204
2060 if (slip_wheel_ev.at < NOW) 2205 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2061 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2062
2063 slip_wheel_ev.start ();
2064 } 2206 }
2065 else 2207 else
2066 { 2208 {
2067# endif 2209# endif
2068# ifdef JUMP_MOUSE_WHEEL
2069 scr_page (v, i); 2210 scr_page (v, i);
2070 scr_refresh (SMOOTH_REFRESH);
2071 scrollbar_show (1); 2211 scrollbar_show (1);
2072# else
2073 while (i--)
2074 {
2075 scr_page (v, 1);
2076 scr_refresh (SMOOTH_REFRESH);
2077 scrollbar_show (1);
2078 }
2079# endif
2080# ifdef MOUSE_SLIP_WHEELING 2212# ifdef MOUSE_SLIP_WHEELING
2081 } 2213 }
2082#endif 2214# endif
2083 } 2215 }
2084 break; 2216 break;
2085#endif 2217#endif
2086 } 2218 }
2087 } 2219 }
2088#ifdef MENUBAR
2089 else if (isMenuBarWindow (ev.window))
2090 menubar_control (ev);
2091#endif
2092} 2220}
2093
2094#ifdef TRANSPARENT
2095#if TINTING
2096/* taken from aterm-0.4.2 */
2097
2098typedef uint32_t RUINT32T;
2099
2100void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2101{
2102 int sh_r, sh_g, sh_b;
2103 RUINT32T mask_r, mask_g, mask_b;
2104 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2105 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2106 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2107 int i;
2108
2109 Visual *visual = display->visual;
2110
2111 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2112
2113 /* for convenience */
2114 mask_r = visual->red_mask;
2115 mask_g = visual->green_mask;
2116 mask_b = visual->blue_mask;
2117
2118 /* boring lookup table pre-initialization */
2119 switch (srcImage->bits_per_pixel) {
2120 case 15:
2121 if ((mask_r != 0x7c00) ||
2122 (mask_g != 0x03e0) ||
2123 (mask_b != 0x001f))
2124 return;
2125 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2126 lookup_r = lookup;
2127 lookup_g = lookup+32;
2128 lookup_b = lookup+32+32;
2129 sh_r = 10;
2130 sh_g = 5;
2131 sh_b = 0;
2132 break;
2133 case 16:
2134 if ((mask_r != 0xf800) ||
2135 (mask_g != 0x07e0) ||
2136 (mask_b != 0x001f))
2137 return;
2138 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2139 lookup_r = lookup;
2140 lookup_g = lookup+32;
2141 lookup_b = lookup+32+64;
2142 sh_r = 11;
2143 sh_g = 5;
2144 sh_b = 0;
2145 break;
2146 case 24:
2147 if ((mask_r != 0xff0000) ||
2148 (mask_g != 0x00ff00) ||
2149 (mask_b != 0x0000ff))
2150 return;
2151 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2152 lookup_r = lookup;
2153 lookup_g = lookup+256;
2154 lookup_b = lookup+256+256;
2155 sh_r = 16;
2156 sh_g = 8;
2157 sh_b = 0;
2158 break;
2159 case 32:
2160 if ((mask_r != 0xff0000) ||
2161 (mask_g != 0x00ff00) ||
2162 (mask_b != 0x0000ff))
2163 return;
2164 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2165 lookup_r = lookup;
2166 lookup_g = lookup+256;
2167 lookup_b = lookup+256+256;
2168 sh_r = 16;
2169 sh_g = 8;
2170 sh_b = 0;
2171 break;
2172 default:
2173 return; /* we do not support this color depth */
2174 }
2175
2176 /* prepare limits for color transformation (each channel is handled separately) */
2177 if (shade < 0) {
2178 shade = -shade;
2179 if (shade < 0) shade = 0;
2180 if (shade > 100) shade = 100;
2181
2182 lower_lim_r = 65535-rm;
2183 lower_lim_g = 65535-gm;
2184 lower_lim_b = 65535-bm;
2185
2186 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2187 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2188 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2189
2190 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2191 } else {
2192 if (shade < 0) shade = 0;
2193 if (shade > 100) shade = 100;
2194
2195 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2196
2197 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2198 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2199 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2200 }
2201
2202 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2203 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2204 {
2205 unsigned int tmp;
2206
2207 tmp = lower_lim_r;
2208 lower_lim_r = lower_lim_b;
2209 lower_lim_b = tmp;
2210
2211 tmp = upper_lim_r;
2212 upper_lim_r = upper_lim_b;
2213 upper_lim_b = tmp;
2214 }
2215
2216 /* fill our lookup tables */
2217 for (i = 0; i <= mask_r>>sh_r; i++)
2218 {
2219 RUINT32T tmp;
2220 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2221 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2222 lookup_r[i] = (tmp/65535)<<sh_r;
2223 }
2224 for (i = 0; i <= mask_g>>sh_g; i++)
2225 {
2226 RUINT32T tmp;
2227 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2228 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2229 lookup_g[i] = (tmp/65535)<<sh_g;
2230 }
2231 for (i = 0; i <= mask_b>>sh_b; i++)
2232 {
2233 RUINT32T tmp;
2234 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2235 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2236 lookup_b[i] = (tmp/65535)<<sh_b;
2237 }
2238
2239 /* apply table to input image (replacing colors by newly calculated ones) */
2240 switch (srcImage->bits_per_pixel)
2241 {
2242 case 15:
2243 {
2244 unsigned short *p1, *pf, *p, *pl;
2245 p1 = (unsigned short *) srcImage->data;
2246 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2247 while (p1 < pf)
2248 {
2249 p = p1;
2250 pl = p1 + srcImage->width;
2251 for (; p < pl; p++)
2252 {
2253 *p = lookup_r[(*p & 0x7c00)>>10] |
2254 lookup_g[(*p & 0x03e0)>> 5] |
2255 lookup_b[(*p & 0x001f)];
2256 }
2257 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2258 }
2259 break;
2260 }
2261 case 16:
2262 {
2263 unsigned short *p1, *pf, *p, *pl;
2264 p1 = (unsigned short *) srcImage->data;
2265 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2266 while (p1 < pf)
2267 {
2268 p = p1;
2269 pl = p1 + srcImage->width;
2270 for (; p < pl; p++)
2271 {
2272 *p = lookup_r[(*p & 0xf800)>>11] |
2273 lookup_g[(*p & 0x07e0)>> 5] |
2274 lookup_b[(*p & 0x001f)];
2275 }
2276 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2277 }
2278 break;
2279 }
2280 case 24:
2281 {
2282 unsigned char *p1, *pf, *p, *pl;
2283 p1 = (unsigned char *) srcImage->data;
2284 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2285 while (p1 < pf)
2286 {
2287 p = p1;
2288 pl = p1 + srcImage->width * 3;
2289 for (; p < pl; p += 3)
2290 {
2291 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2292 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2293 p[2] = lookup_r[(p[2] & 0x0000ff)];
2294 }
2295 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2296 }
2297 break;
2298 }
2299 case 32:
2300 {
2301 RUINT32T *p1, *pf, *p, *pl;
2302 p1 = (RUINT32T *) srcImage->data;
2303 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2304
2305 while (p1 < pf)
2306 {
2307 p = p1;
2308 pl = p1 + srcImage->width;
2309 for (; p < pl; p++)
2310 {
2311 *p = lookup_r[(*p & 0xff0000)>>16] |
2312 lookup_g[(*p & 0x00ff00)>> 8] |
2313 lookup_b[(*p & 0x0000ff)] |
2314 (*p & ~0xffffff);
2315 }
2316 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2317 }
2318 break;
2319 }
2320 }
2321
2322 free (lookup);
2323}
2324#endif
2325
2326/*
2327 * Check our parents are still who we think they are.
2328 * Do transparency updates if required
2329 */
2330int
2331rxvt_term::check_our_parents ()
2332{
2333 int i, pchanged, aformat, have_pixmap, rootdepth;
2334 unsigned long nitems, bytes_after;
2335 Atom atype;
2336 unsigned char *prop = NULL;
2337 Window root, oldp, *list;
2338 Pixmap rootpixmap = None;
2339 XWindowAttributes wattr, wrootattr;
2340 dDisp;
2341
2342 pchanged = 0;
2343
2344 if (!(options & Opt_transparent))
2345 return pchanged; /* Don't try any more */
2346
2347 XGetWindowAttributes (disp, display->root, &wrootattr);
2348 rootdepth = wrootattr.depth;
2349
2350 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2351
2352 if (rootdepth != wattr.depth)
2353 {
2354 if (am_transparent)
2355 {
2356 pchanged = 1;
2357 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2358 am_transparent = am_pixmap_trans = 0;
2359 }
2360
2361 return pchanged; /* Don't try any more */
2362 }
2363
2364 /* Get all X ops out of the queue so that our information is up-to-date. */
2365 XSync (disp, False);
2366
2367 /*
2368 * Make the frame window set by the window manager have
2369 * the root background. Some window managers put multiple nested frame
2370 * windows for each client, so we have to take care about that.
2371 */
2372 i = (xa[XA_XROOTPMAP_ID]
2373 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2374 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2375 &nitems, &bytes_after, &prop) == Success);
2376
2377 if (!i || prop == NULL)
2378 i = (xa[XA_ESETROOT_PMAP_ID]
2379 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2380 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2381 &nitems, &bytes_after, &prop) == Success);
2382
2383 if (!i || prop == NULL
2384#if TINTING
2385 || !rs[Rs_color + Color_tint]
2386#endif
2387 )
2388 have_pixmap = 0;
2389 else
2390 {
2391 have_pixmap = 1;
2392 rootpixmap = *(Pixmap *)prop;
2393 XFree (prop);
2394 }
2395
2396 if (have_pixmap)
2397 {
2398 /*
2399 * Copy display->root pixmap transparency
2400 */
2401 int sx, sy, nx, ny;
2402 unsigned int nw, nh;
2403 Window cr;
2404 XImage *image;
2405 GC gc;
2406 XGCValues gcvalue;
2407
2408 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2409 0, 0, &sx, &sy, &cr);
2410 nw = (unsigned int)szHint.width;
2411 nh = (unsigned int)szHint.height;
2412 nx = ny = 0;
2413
2414 if (sx < 0)
2415 {
2416 nw += sx;
2417 nx = -sx;
2418 sx = 0;
2419 }
2420
2421 if (sy < 0)
2422 {
2423 nh += sy;
2424 ny = -sy;
2425 sy = 0;
2426 }
2427
2428 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2429 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2430
2431 XSync (disp, False);
2432 allowedxerror = -1;
2433 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2434
2435 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2436 /* XXX: may need a delay here? */
2437 allowedxerror = 0;
2438
2439 if (image == NULL)
2440 {
2441 if (am_transparent && am_pixmap_trans)
2442 {
2443 pchanged = 1;
2444 if (TermWin.pixmap != None)
2445 {
2446 XFreePixmap (disp, TermWin.pixmap);
2447 TermWin.pixmap = None;
2448 }
2449 }
2450
2451 am_pixmap_trans = 0;
2452 }
2453 else
2454 {
2455 if (TermWin.pixmap != None)
2456 XFreePixmap (disp, TermWin.pixmap);
2457
2458#if TINTING
2459 if (ISSET_PIXCOLOR (Color_tint))
2460 {
2461 unsigned short rm, gm, bm;
2462 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2463
2464 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2465
2466 ShadeXImage (display, image, shade, rm, gm, bm);
2467 }
2468#endif
2469
2470 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2471 szHint.width, szHint.height, image->depth);
2472 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2473 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2474 nx, ny, image->width, image->height);
2475 XFreeGC (disp, gc);
2476 XDestroyImage (image);
2477 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2478 XClearWindow (disp, TermWin.parent[0]);
2479
2480 if (!am_transparent || !am_pixmap_trans)
2481 pchanged = 1;
2482
2483 am_transparent = am_pixmap_trans = 1;
2484 }
2485 }
2486
2487 if (am_pixmap_trans)
2488 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2489 else
2490 {
2491 unsigned int n;
2492 /*
2493 * InheritPixmap transparency
2494 */
2495 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2496 {
2497 oldp = TermWin.parent[i];
2498 XQueryTree (disp, TermWin.parent[i - 1], &root,
2499 &TermWin.parent[i], &list, &n);
2500 XFree (list);
2501
2502 if (TermWin.parent[i] == display->root)
2503 {
2504 if (oldp != None)
2505 pchanged = 1;
2506
2507 break;
2508 }
2509
2510 if (oldp != TermWin.parent[i])
2511 pchanged = 1;
2512 }
2513
2514 n = 0;
2515
2516 if (pchanged)
2517 {
2518 for (; n < (unsigned int)i; n++)
2519 {
2520 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2521 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2522 {
2523 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2524 break;
2525 }
2526 }
2527 }
2528
2529 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2530 {
2531 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2532 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2533 am_transparent = 0;
2534 /* XXX: also turn off Opt_transparent? */
2535 }
2536 else
2537 {
2538#if WAIT_FOR_WM
2539 /* wait (an arbitrary period) for the WM to do its thing
2540 * needed for fvwm2.2.2 (and before?) */
2541 sleep (1);
2542#endif
2543 for (n = 0; n < (unsigned int)i; n++)
2544 {
2545 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2546 XClearWindow (disp, TermWin.parent[n]);
2547 }
2548
2549 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2550 am_transparent = 1;
2551 }
2552
2553 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2554 TermWin.parent[i] = None;
2555 }
2556
2557 if (scrollBar.win)
2558 {
2559 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2560 scrollBar.setIdle ();
2561 scrollbar_show (0);
2562 }
2563
2564 if (am_transparent)
2565 {
2566 want_refresh = want_full_refresh = 1;
2567 if (am_pixmap_trans)
2568 flush ();
2569 }
2570
2571 return pchanged;
2572}
2573#endif
2574 2221
2575/*}}} */ 2222/*}}} */
2576 2223
2577bool 2224bool
2578rxvt_term::cmd_parse () 2225rxvt_term::cmd_parse ()
2579{ 2226{
2580 bool flag = false; 2227 bool flag = false;
2581 unicode_t ch = NOCHAR; 2228 wchar_t ch = NOCHAR;
2582 unsigned char *seq_begin; // remember start of esc-sequence here 2229 char *seq_begin; // remember start of esc-sequence here
2583 2230
2584 for (;;) 2231 for (;;)
2585 { 2232 {
2586 if (ch == NOCHAR) 2233 if (ch == NOCHAR)
2587 { 2234 {
2588 seq_begin = cmdbuf_ptr; 2235 seq_begin = cmdbuf_ptr;
2589 ch = next_char (); 2236 ch = next_char ();
2590 }
2591 2237
2592 if (ch == NOCHAR) // TODO: improve 2238 if (ch == NOCHAR)
2593 break; 2239 break;
2240 }
2594 2241
2595 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2242 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2596 { 2243 {
2597 if (!seen_input) 2244 if (!seen_input)
2598 { 2245 {
2607 if (seen_resize && cmd_pid) 2254 if (seen_resize && cmd_pid)
2608 kill (-cmd_pid, SIGWINCH); 2255 kill (-cmd_pid, SIGWINCH);
2609 } 2256 }
2610 2257
2611 /* Read a text string from the input buffer */ 2258 /* Read a text string from the input buffer */
2612 unicode_t buf[UBUFSIZ]; 2259 wchar_t buf[UBUFSIZ];
2613 bool refreshnow = false; 2260 bool refreshnow = false;
2614 int nlines = 0; 2261 int nlines = 0;
2615 unicode_t *str = buf; 2262 wchar_t *str = buf;
2263 wchar_t *eol = str + min (ncol, UBUFSIZ);
2616 2264
2617 for (;;) 2265 for (;;)
2618 { 2266 {
2619 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2267 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2620 break; 2268 break;
2621 2269
2622 *str++ = ch; 2270 *str++ = ch;
2623 2271
2624 if (ch == C0_LF) 2272 if (ch == C0_LF || str >= eol)
2625 { 2273 {
2274 if (ch == C0_LF)
2626 nlines++; 2275 nlines++;
2276
2627 refresh_count++; 2277 refresh_count++;
2628 2278
2629 if (!(options & Opt_jumpScroll) 2279 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2630 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2631 { 2280 {
2281 refresh_count = 0;
2282
2283 if (!option (Opt_skipScroll) || ev::ev_time () > ev::now () + 1. / 60.)
2284 {
2632 refreshnow = true; 2285 refreshnow = true;
2633 ch = NOCHAR; 2286 ch = NOCHAR;
2634 break; 2287 break;
2288 }
2635 } 2289 }
2636 2290
2637 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2291 // scr_add_lines only works for nlines <= nrow - 1.
2638 if (nlines >= TermWin.nrow - 1) 2292 if (nlines >= nrow - 1)
2639 { 2293 {
2294 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2295 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2640 scr_add_lines (buf, nlines, str - buf); 2296 scr_add_lines (buf, str - buf, nlines);
2297
2641 nlines = 0; 2298 nlines = 0;
2642 str = buf; 2299 str = buf;
2300 eol = str + min (ncol, UBUFSIZ);
2643 } 2301 }
2644 }
2645 2302
2646 if (str >= buf + UBUFSIZ) 2303 if (str >= eol)
2647 { 2304 {
2305 if (eol >= buf + UBUFSIZ)
2306 {
2648 ch = NOCHAR; 2307 ch = NOCHAR;
2649 break; 2308 break;
2309 }
2310 else
2311 eol = min (eol + ncol, buf + UBUFSIZ);
2312 }
2313
2650 } 2314 }
2651 2315
2652 seq_begin = cmdbuf_ptr; 2316 seq_begin = cmdbuf_ptr;
2653 ch = next_char (); 2317 ch = next_char ();
2654 } 2318 }
2655 2319
2320 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2321 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2656 scr_add_lines (buf, nlines, str - buf); 2322 scr_add_lines (buf, str - buf, nlines);
2657 2323
2658 /* 2324 /*
2659 * If there have been a lot of new lines, then update the screen 2325 * If there have been a lot of new lines, then update the screen
2660 * What the heck I'll cheat and only refresh less than every page-full. 2326 * What the heck we'll cheat and only refresh less than every page-full.
2661 * the number of pages between refreshes is refresh_limit, which 2327 * if skipScroll is enabled.
2662 * is incremented here because we must be doing flat-out scrolling.
2663 */ 2328 */
2664 if (refreshnow) 2329 if (refreshnow)
2665 { 2330 {
2666 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2667 refresh_limit++;
2668 else
2669 {
2670 flag = true; 2331 flag = true;
2671 scr_refresh (refresh_type); 2332 scr_refresh ();
2672 } 2333 want_refresh = 1;
2673 } 2334 }
2674 2335
2675 } 2336 }
2676 else 2337 else
2677 { 2338 {
2691 } 2352 }
2692 2353
2693 return flag; 2354 return flag;
2694} 2355}
2695 2356
2696// read the next octet
2697unicode_t
2698rxvt_term::next_octet ()
2699{
2700 return cmdbuf_ptr < cmdbuf_endp
2701 ? *cmdbuf_ptr++
2702 : NOCHAR;
2703}
2704
2705// read the next character 2357// read the next character
2706unicode_t 2358wchar_t
2707rxvt_term::next_char () 2359rxvt_term::next_char () NOTHROW
2708{ 2360{
2709 while (cmdbuf_ptr < cmdbuf_endp) 2361 while (cmdbuf_ptr < cmdbuf_endp)
2710 { 2362 {
2711 // assume 7-bit to be ascii ALWAYS 2363 // assume 7-bit to be ascii ALWAYS
2712 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2364 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2713 return *cmdbuf_ptr++; 2365 return *cmdbuf_ptr++;
2714 2366
2715 wchar_t wc; 2367 wchar_t wc;
2716 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2368 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2717 2369
2718 if (len == (size_t)-2) 2370 if (len == (size_t)-2)
2719 { 2371 {
2720 // the mbstate stores incomplete sequences. didn't know this :/ 2372 // the mbstate stores incomplete sequences. didn't know this :/
2721 cmdbuf_ptr = cmdbuf_endp; 2373 cmdbuf_ptr = cmdbuf_endp;
2722 break; 2374 break;
2723 } 2375 }
2724 2376
2725 if (len == (size_t)-1) 2377 if (len == (size_t)-1)
2726 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2378 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2727 2379
2728 // assume wchar == unicode 2380 // assume wchar == unicode
2729 cmdbuf_ptr += len; 2381 cmdbuf_ptr += len;
2730 return wc & UNICODE_MASK; 2382 return wc & UNICODE_MASK;
2731 } 2383 }
2732 2384
2733 return NOCHAR; 2385 return NOCHAR;
2734} 2386}
2387
2388// read the next octet
2389uint32_t
2390rxvt_term::next_octet () NOTHROW
2391{
2392 return cmdbuf_ptr < cmdbuf_endp
2393 ? (unsigned char)*cmdbuf_ptr++
2394 : NOCHAR;
2395}
2396
2397static class out_of_input out_of_input;
2735 2398
2736/* rxvt_cmd_getc () - Return next input character */ 2399/* rxvt_cmd_getc () - Return next input character */
2737/* 2400/*
2738 * Return the next input character after first passing any keyboard input 2401 * Return the next input character after first passing any keyboard input
2739 * to the command. 2402 * to the command.
2740 */ 2403 */
2741unicode_t 2404wchar_t
2742rxvt_term::cmd_getc () 2405rxvt_term::cmd_getc () THROW ((class out_of_input))
2743{ 2406{
2744 unicode_t c = next_char (); 2407 wchar_t c = next_char ();
2745 2408
2746 if (c == NOCHAR) 2409 if (c == NOCHAR)
2747 throw out_of_input; 2410 throw out_of_input;
2748 2411
2749 return c; 2412 return c;
2750} 2413}
2751 2414
2752unicode_t 2415uint32_t
2753rxvt_term::cmd_get8 () 2416rxvt_term::cmd_get8 () THROW ((class out_of_input))
2754{ 2417{
2755 unicode_t c = next_octet (); 2418 uint32_t c = next_octet ();
2756 2419
2757 if (c == NOCHAR) 2420 if (c == NOCHAR)
2758 throw out_of_input; 2421 throw out_of_input;
2759 2422
2760 return c; 2423 return c;
2824 { 2487 {
2825 if ((buf[len++] = cmd_getc ()) == 'i') 2488 if ((buf[len++] = cmd_getc ()) == 'i')
2826 break; /* done = 1 */ 2489 break; /* done = 1 */
2827 } 2490 }
2828 } 2491 }
2829 2492
2830 for (i = 0; i < len; i++) 2493 for (i = 0; i < len; i++)
2831 if (putc (buf[i], fd) == EOF) 2494 if (putc (buf[i], fd) == EOF)
2832 { 2495 {
2833 done = 1; 2496 done = 1;
2834 break; 2497 break;
2860 case C0_ESC: 2523 case C0_ESC:
2861 process_escape_seq (); 2524 process_escape_seq ();
2862 break; 2525 break;
2863 case C0_ENQ: /* terminal Status */ 2526 case C0_ENQ: /* terminal Status */
2864 if (rs[Rs_answerbackstring]) 2527 if (rs[Rs_answerbackstring])
2865 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2528 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2866 (unsigned int)strlen (rs[Rs_answerbackstring]));
2867 else 2529 else
2868 tt_write ((unsigned char *)VT100_ANS, 2530 tt_write (VT100_ANS, strlen (VT100_ANS));
2869 (unsigned int)strlen (VT100_ANS));
2870 break; 2531 break;
2871 case C0_BEL: /* bell */ 2532 case C0_BEL: /* bell */
2872 scr_bell (); 2533 scr_bell ();
2873 break; 2534 break;
2874 case C0_BS: /* backspace */ 2535 case C0_BS: /* backspace */
2898 process_dcs_seq (); 2559 process_dcs_seq ();
2899 break; 2560 break;
2900 case 0x9b: /* CSI */ 2561 case 0x9b: /* CSI */
2901 process_csi_seq (); 2562 process_csi_seq ();
2902 break; 2563 break;
2903 case 0x9d: /* CSI */ 2564 case 0x9d: /* OSC */
2904 process_osc_seq (); 2565 process_osc_seq ();
2905 break; 2566 break;
2906#endif 2567#endif
2907 } 2568 }
2908} 2569}
2998 scr_charset_set (2, (unsigned int)cmd_getc ()); 2659 scr_charset_set (2, (unsigned int)cmd_getc ());
2999 break; 2660 break;
3000 case '+': 2661 case '+':
3001 scr_charset_set (3, (unsigned int)cmd_getc ()); 2662 scr_charset_set (3, (unsigned int)cmd_getc ());
3002 break; 2663 break;
3003#if ENABLE_FRILLS 2664#if !ENABLE_MINIMAL
3004 case '6': 2665 case '6':
3005 scr_backindex (); 2666 scr_backindex ();
3006 break; 2667 break;
3007#endif 2668#endif
3008 case '7': 2669 case '7':
3009 scr_cursor (SAVE); 2670 scr_cursor (SAVE);
3010 break; 2671 break;
3011 case '8': 2672 case '8':
3012 scr_cursor (RESTORE); 2673 scr_cursor (RESTORE);
3013 break; 2674 break;
3014#if ENABLE_FRILLS 2675#if !ENABLE_MINIMAL
3015 case '9': 2676 case '9':
3016 scr_forwardindex (); 2677 scr_forwardindex ();
3017 break; 2678 break;
3018#endif 2679#endif
3019 case '=': 2680 case '=':
3029 break; 2690 break;
3030 2691
3031 /* 8.3.87: NEXT LINE */ 2692 /* 8.3.87: NEXT LINE */
3032 case C1_NEL: /* ESC E */ 2693 case C1_NEL: /* ESC E */
3033 { 2694 {
3034 unicode_t nlcr[] = { C0_LF, C0_CR }; 2695 wchar_t nlcr[] = { C0_LF, C0_CR };
3035 scr_add_lines (nlcr, 1, 2); 2696 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3036 } 2697 }
3037 break; 2698 break;
3038 2699
3039 /* kidnapped escape sequence: Should be 8.3.48 */ 2700 /* kidnapped escape sequence: Should be 8.3.48 */
3040 case C1_ESA: /* ESC G */ 2701 case C1_ESA: /* ESC G */
3062 process_dcs_seq (); 2723 process_dcs_seq ();
3063 break; 2724 break;
3064 2725
3065 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2726 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3066 case C1_SCI: /* ESC Z */ 2727 case C1_SCI: /* ESC Z */
3067 tt_write ((const unsigned char *)ESCZ_ANSWER, 2728 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3068 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3069 break; /* steal obsolete ESC [ c */ 2729 break; /* steal obsolete ESC [ c */
3070 2730
3071 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2731 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3072 case C1_CSI: /* ESC [ */ 2732 case C1_CSI: /* ESC [ */
3073 process_csi_seq (); 2733 process_csi_seq ();
3135rxvt_term::process_csi_seq () 2795rxvt_term::process_csi_seq ()
3136{ 2796{
3137 unicode_t ch, priv, i; 2797 unicode_t ch, priv, i;
3138 unsigned int nargs, p; 2798 unsigned int nargs, p;
3139 int n, ndef; 2799 int n, ndef;
3140 int arg[ESC_ARGS]; 2800 int arg[ESC_ARGS] = { };
3141 2801
3142 for (nargs = ESC_ARGS; nargs > 0;) 2802 nargs = 0;
3143 arg[--nargs] = 0;
3144 2803
3145 priv = 0; 2804 priv = 0;
3146 ch = cmd_getc (); 2805 ch = cmd_getc ();
3147 if (ch >= '<' && ch <= '?') 2806 if (ch >= '<' && ch <= '?')
3148 { /* '<' '=' '>' '?' */ 2807 { /* '<' '=' '>' '?' */
3182 ndef = get_byte_array_bit (csi_defaults, i); 2841 ndef = get_byte_array_bit (csi_defaults, i);
3183 for (p = 0; p < nargs; p++) 2842 for (p = 0; p < nargs; p++)
3184 if (arg[p] == -1) 2843 if (arg[p] == -1)
3185 arg[p] = ndef; 2844 arg[p] = ndef;
3186 2845
3187#ifdef DEBUG_CMD
3188 fprintf (stderr, "CSI ");
3189 for (p = 0; p < nargs; p++)
3190 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3191 fprintf (stderr, "%c\n", ch);
3192#endif
3193
3194 /* 2846 /*
3195 * private mode handling 2847 * private mode handling
3196 */ 2848 */
3197 if (priv) 2849 if (priv)
3198 { 2850 {
3199 switch (priv) 2851 switch (priv)
3200 { 2852 {
3201 case '>': 2853 case '>':
3202 if (ch == CSI_DA) /* secondary device attributes */ 2854 if (ch == CSI_DA) /* secondary device attributes */
3203 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2855 {
2856 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2857 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2858 //
2859 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2860 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2861 // versions.
2862 //
2863 tt_printf ("\033[>%d;95;0c", 'U');
2864 }
3204 break; 2865 break;
3205 case '?': 2866 case '?':
3206 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2867 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3207 process_terminal_mode (ch, priv, nargs, arg); 2868 process_terminal_mode (ch, priv, nargs, arg);
3208 break; 2869 break;
3313 2974
3314 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 2975 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3315 arg[0] = -arg[0]; 2976 arg[0] = -arg[0];
3316 /* FALLTHROUGH */ 2977 /* FALLTHROUGH */
3317 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2978 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3318 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 2979 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3319 break; 2980 break;
3320 2981
3321 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 2982 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3322 tt_write ((const unsigned char *)VT100_ANS, 2983 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3323 (unsigned int) (sizeof (VT100_ANS) - 1));
3324 break; 2984 break;
3325 2985
3326 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 2986 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3327 process_sgr_mode (nargs, arg); 2987 process_sgr_mode (nargs, arg);
3328 break; 2988 break;
3335 break; 2995 break;
3336 case 6: /* CPR requested */ 2996 case 6: /* CPR requested */
3337 scr_report_position (); 2997 scr_report_position ();
3338 break; 2998 break;
3339 case 7: /* unofficial extension */ 2999 case 7: /* unofficial extension */
3340 if (options & Opt_insecure) 3000 if (option (Opt_insecure))
3341 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3001 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3342 break; 3002 break;
3343 case 8: /* unofficial extension */ 3003 case 8: /* unofficial extension */
3344 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3004 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3345 break; 3005 break;
3412 break; 3072 break;
3413 case CSI_75: 3073 case CSI_75:
3414 scr_cursor (RESTORE); 3074 scr_cursor (RESTORE);
3415 break; 3075 break;
3416 3076
3417#if ENABLE_FRILLS 3077#if !ENABLE_MINIMAL
3418 case CSI_74: 3078 case CSI_74:
3419 process_window_ops (arg, nargs); 3079 process_window_ops (arg, nargs);
3420 break; 3080 break;
3421#endif 3081#endif
3422 3082
3429 break; 3089 break;
3430 } 3090 }
3431} 3091}
3432/*}}} */ 3092/*}}} */
3433 3093
3434#if ENABLE_FRILLS 3094#if !ENABLE_MINIMAL
3435/* ARGSUSED */ 3095/* ARGSUSED */
3436void 3096void
3437rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3097rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3438{ 3098{
3439 int x, y; 3099 int x, y;
3440 XWindowAttributes wattr; 3100 XWindowAttributes wattr;
3441 Window wdummy; 3101 Window wdummy;
3442 dDisp; 3102
3103 dLocal (Display *, dpy);
3443 3104
3444 if (nargs == 0) 3105 if (nargs == 0)
3445 return; 3106 return;
3446 3107
3447 switch (args[0]) 3108 switch (args[0])
3448 { 3109 {
3449 /* 3110 /*
3450 * commands 3111 * commands
3451 */ 3112 */
3452 case 1: /* deiconify window */ 3113 case 1: /* deiconify window */
3453 XMapWindow (disp, TermWin.parent[0]); 3114 XMapWindow (dpy, parent[0]);
3454 break; 3115 break;
3455 case 2: /* iconify window */ 3116 case 2: /* iconify window */
3456 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3117 XIconifyWindow (dpy, parent[0], display->screen);
3457 break; 3118 break;
3458 case 3: /* set position (pixels) */ 3119 case 3: /* set position (pixels) */
3459 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3120 XMoveWindow (dpy, parent[0], args[1], args[2]);
3460 break; 3121 break;
3461 case 4: /* set size (pixels) */ 3122 case 4: /* set size (pixels) */
3462 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3123 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3463 break; 3124 break;
3464 case 5: /* raise window */ 3125 case 5: /* raise window */
3465 XRaiseWindow (disp, TermWin.parent[0]); 3126 XRaiseWindow (dpy, parent[0]);
3466 break; 3127 break;
3467 case 6: /* lower window */ 3128 case 6: /* lower window */
3468 XLowerWindow (disp, TermWin.parent[0]); 3129 XLowerWindow (dpy, parent[0]);
3469 break; 3130 break;
3470 case 7: /* refresh window */ 3131 case 7: /* refresh window */
3471 scr_touch (true); 3132 scr_touch (true);
3472 break; 3133 break;
3473 case 8: /* set size (chars) */ 3134 case 8: /* set size (chars) */
3474 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3135 set_widthheight ((unsigned int) (args[2] * fwidth),
3475 (unsigned int) (args[1] * TermWin.fheight)); 3136 (unsigned int) (args[1] * fheight));
3476 break; 3137 break;
3477 3138
3478 //case 9: NYI, TODO, restore maximized window or maximize window 3139 //case 9: NYI, TODO, restore maximized window or maximize window
3479 default: 3140 default:
3480 if (args[0] >= 24) /* set height (chars) */ 3141 if (args[0] >= 24) /* set height (chars) */
3481 set_widthheight ((unsigned int)TermWin.width, 3142 set_widthheight ((unsigned int)width,
3482 (unsigned int) (args[1] * TermWin.fheight)); 3143 (unsigned int) (args[1] * fheight));
3483 break; 3144 break;
3484
3485 3145
3486 /* 3146 /*
3487 * reports - some output format copied from XTerm 3147 * reports - some output format copied from XTerm
3488 */ 3148 */
3489 case 11: /* report window state */ 3149 case 11: /* report window state */
3490 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3150 XGetWindowAttributes (dpy, parent[0], &wattr);
3491 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3151 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3492 break; 3152 break;
3493 case 13: /* report window position */ 3153 case 13: /* report window position */
3494 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3154 XGetWindowAttributes (dpy, parent[0], &wattr);
3495 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3155 XTranslateCoordinates (dpy, parent[0], wattr.root,
3496 -wattr.border_width, -wattr.border_width, 3156 -wattr.border_width, -wattr.border_width,
3497 &x, &y, &wdummy); 3157 &x, &y, &wdummy);
3498 tt_printf ("\033[3;%d;%dt", x, y); 3158 tt_printf ("\033[3;%d;%dt", x, y);
3499 break; 3159 break;
3500 case 14: /* report window size (pixels) */ 3160 case 14: /* report window size (pixels) */
3501 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3161 XGetWindowAttributes (dpy, parent[0], &wattr);
3502 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3162 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3503 break; 3163 break;
3504 case 18: /* report text area size (chars) */ 3164 case 18: /* report text area size (chars) */
3505 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3165 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3506 break; 3166 break;
3507 case 19: /* report window size (chars) */ 3167 case 19: /* report window size (chars) */
3508 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3168 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3509 break; 3169 break;
3510 case 20: /* report icon label */ 3170 case 20: /* report icon label */
3511 { 3171 {
3512 char *s; 3172 char *s;
3513 XGetIconName (disp, TermWin.parent[0], &s); 3173 XGetIconName (dpy, parent[0], &s);
3514 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3174 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3515 XFree (s); 3175 XFree (s);
3516 } 3176 }
3517 break; 3177 break;
3518 case 21: /* report window title */ 3178 case 21: /* report window title */
3519 { 3179 {
3520 char *s; 3180 char *s;
3521 XFetchName (disp, TermWin.parent[0], &s); 3181 XFetchName (dpy, parent[0], &s);
3522 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3182 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3523 XFree (s); 3183 XFree (s);
3524 } 3184 }
3525 break; 3185 break;
3526 } 3186 }
3527} 3187}
3530/*----------------------------------------------------------------------*/ 3190/*----------------------------------------------------------------------*/
3531/* 3191/*
3532 * get input up until STRING TERMINATOR (or BEL) 3192 * get input up until STRING TERMINATOR (or BEL)
3533 * ends_how is terminator used. returned input must be free()'d 3193 * ends_how is terminator used. returned input must be free()'d
3534 */ 3194 */
3535unsigned char * 3195char *
3536rxvt_term::get_to_st (unicode_t &ends_how) 3196rxvt_term::get_to_st (unicode_t &ends_how)
3537{ 3197{
3538 unicode_t ch; 3198 unicode_t ch;
3539 bool seen_esc = false; 3199 bool seen_esc = false;
3540 unsigned int n = 0; 3200 unsigned int n = 0;
3554 seen_esc = true; 3214 seen_esc = true;
3555 continue; 3215 continue;
3556 } 3216 }
3557 else if (ch == C0_BEL || ch == CHAR_ST) 3217 else if (ch == C0_BEL || ch == CHAR_ST)
3558 break; 3218 break;
3219 else if (ch == C0_SYN)
3220 ch = cmd_get8 ();
3559 else if (ch < 0x20) 3221 else if (ch < 0x20)
3560 return NULL; /* other control character - exit */ 3222 return NULL; /* other control character - exit */
3561 3223
3562 seen_esc = false; 3224 seen_esc = false;
3563 3225
3564 if (n >= sizeof (string) - 1) 3226 if (n >= STRING_MAX - 1)
3565 // stop at some sane length 3227 // stop at some sane length
3566 return NULL; 3228 return NULL;
3567 3229
3568 if (ch == C0_SYN)
3569 string[n++] = cmd_get8 ();
3570 else
3571 string[n++] = ch; 3230 string[n++] = ch;
3572 } 3231 }
3573 3232
3574 string[n++] = '\0'; 3233 string[n++] = '\0';
3575 3234
3576 ends_how = (ch == 0x5c ? C0_ESC : ch); 3235 ends_how = (ch == 0x5c ? C0_ESC : ch);
3577 3236
3578 return (unsigned char *)rxvt_wcstombs (string); 3237 return rxvt_wcstombs (string);
3579} 3238}
3580 3239
3581/*----------------------------------------------------------------------*/ 3240/*----------------------------------------------------------------------*/
3582/* 3241/*
3583 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3242 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3584 */ 3243 */
3585void 3244void
3586rxvt_term::process_dcs_seq () 3245rxvt_term::process_dcs_seq ()
3587{ 3246{
3588 unsigned char *s; 3247 char *s;
3589 unicode_t eh; 3248 unicode_t eh;
3590 3249
3591 /* 3250 /*
3592 * Not handled yet 3251 * Not handled yet
3593 */ 3252 */
3612 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3271 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3613 arg = arg * 10 + (ch - '0'); 3272 arg = arg * 10 + (ch - '0');
3614 3273
3615 if (ch == ';') 3274 if (ch == ';')
3616 { 3275 {
3617 unsigned char *s = get_to_st (eh); 3276 char *s = get_to_st (eh);
3618 3277
3619 if (s) 3278 if (s)
3620 { 3279 {
3621 process_xterm_seq (arg, (char *)s, eh); 3280 process_xterm_seq (arg, s, eh);
3622 free (s); 3281 free (s);
3623 } 3282 }
3624 } 3283 }
3625} 3284}
3626 3285
3627void 3286void
3628rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3287rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3629{ 3288{
3630 if (str[0] == '?' && !str[1]) 3289 if (str[0] == '?' && !str[1])
3631 { 3290 {
3632 unsigned short r, g, b; 3291 rgba c;
3633 pix_colors_focused[color].get (display, r, g, b); 3292 pix_colors_focused[color].get (c);
3293
3294#if XFT
3295 if (c.a != rgba::MAX_CC)
3296 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3297 else
3298#endif
3634 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3299 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3635 } 3300 }
3636 else 3301 else
3637 set_window_color (color, str); 3302 set_window_color (color, str);
3638} 3303}
3639 3304
3640/* 3305/*
3641 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3306 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3642 * 0 = change iconName/title
3643 * 1 = change iconName
3644 * 2 = change title
3645 * 4 = change color
3646 * 10 = change fg color
3647 * 11 = change bg color
3648 * 12 = change text color
3649 * 13 = change mouse foreground color
3650 * 17 = change highlight character colour
3651 * 18 = change bold character color
3652 * 19 = change underlined character color
3653 * 46 = change logfile (not implemented)
3654 * 50 = change font
3655 *
3656 * rxvt extensions:
3657 * 20 = bg pixmap
3658 * 39 = change default fg color
3659 * 49 = change default bg color
3660 * 55 = dump scrollback buffer and all of screen
3661 * 701 = change locale
3662 * 702 = find font
3663 * 703 = menu
3664 */ 3307 */
3665void 3308void
3666rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3309rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3667{ 3310{
3668 int changed = 0;
3669 int color; 3311 int color;
3670 char *buf, *name; 3312 char *buf, *name;
3671 bool query = str[0] == '?' && !str[1]; 3313 bool query = str[0] == '?' && !str[1];
3672 int saveop = op; 3314 int saveop = op;
3673 dDisp; 3315
3316 dLocal (Display *, dpy);
3674 3317
3675 assert (str != NULL); 3318 assert (str != NULL);
3319
3320 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3321 return;
3322
3676 switch (op) 3323 switch (op)
3677 { 3324 {
3678 case XTerm_name: 3325 case XTerm_name:
3679 set_title (str); 3326 set_title (str);
3680 /* FALLTHROUGH */ 3327 /* FALLTHROUGH */
3694 unsigned long bytes_after; 3341 unsigned long bytes_after;
3695 unsigned char *value = 0; 3342 unsigned char *value = 0;
3696 const char *str = ""; 3343 const char *str = "";
3697 3344
3698 if (prop 3345 if (prop
3699 && XGetWindowProperty (disp, TermWin.parent[0], 3346 && XGetWindowProperty (dpy, parent[0],
3700 prop, 0, 1<<16, 0, AnyPropertyType, 3347 prop, 0, 1<<16, 0, AnyPropertyType,
3701 &actual_type, &actual_format, 3348 &actual_type, &actual_format,
3702 &nitems, &bytes_after, &value) == Success 3349 &nitems, &bytes_after, &value) == Success
3703 && actual_type != None 3350 && actual_type != None
3704 && actual_format == 8) 3351 && actual_format == 8)
3705 str = (const char *)(value); 3352 str = (const char *)(value);
3706 3353
3707 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3354 tt_printf ("\033]%d;%s%c", op, str, resp);
3708 3355
3709 XFree (value); 3356 XFree (value);
3710 } 3357 }
3711 else 3358 else
3712 { 3359 {
3716 { 3363 {
3717 *eq = 0; 3364 *eq = 0;
3718 set_utf8_property (display->atom (str), eq + 1); 3365 set_utf8_property (display->atom (str), eq + 1);
3719 } 3366 }
3720 else 3367 else
3721 XDeleteProperty (disp, TermWin.parent[0], 3368 XDeleteProperty (dpy, parent[0],
3722 display->atom (str)); 3369 display->atom (str));
3723 } 3370 }
3724 break; 3371 break;
3725 3372
3726 case XTerm_Color: 3373 case XTerm_Color:
3728 { 3375 {
3729 if ((name = strchr (buf, ';')) == NULL) 3376 if ((name = strchr (buf, ';')) == NULL)
3730 break; 3377 break;
3731 3378
3732 *name++ = '\0'; 3379 *name++ = '\0';
3733 color = atoi (buf); 3380 color = atoi (buf) + minCOLOR;
3734 3381
3735 if (color < 0 || color >= TOTAL_COLORS) 3382 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3736 break; 3383 break;
3737 3384
3738 if ((buf = strchr (name, ';')) != NULL) 3385 if ((buf = strchr (name, ';')) != NULL)
3739 *buf++ = '\0'; 3386 *buf++ = '\0';
3740 3387
3741 if (name[0] == '?' && !name[1]) 3388 process_color_seq (op, color, name, resp);
3742 {
3743 unsigned short r, g, b;
3744 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3745 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3746 }
3747 else
3748 set_window_color (color + minCOLOR, name);
3749 } 3389 }
3750 break; 3390 break;
3751 case XTerm_Color00: 3391 case XTerm_Color00:
3752 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3392 process_color_seq (op, Color_fg, str, resp);
3753 break; 3393 break;
3754 case XTerm_Color01: 3394 case XTerm_Color01:
3755 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3395 process_color_seq (op, Color_bg, str, resp);
3756 break; 3396 break;
3757#ifndef NO_CURSORCOLOR 3397#ifndef NO_CURSORCOLOR
3758 case XTerm_Color_cursor: 3398 case XTerm_Color_cursor:
3759 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3399 process_color_seq (op, Color_cursor, str, resp);
3760 break; 3400 break;
3761#endif 3401#endif
3762 case XTerm_Color_pointer_fg: 3402 case XTerm_Color_pointer_fg:
3763 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3403 process_color_seq (op, Color_pointer_fg, str, resp);
3764 break; 3404 break;
3765 case XTerm_Color_pointer_bg: 3405 case XTerm_Color_pointer_bg:
3766 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3406 process_color_seq (op, Color_pointer_bg, str, resp);
3767 break; 3407 break;
3768#ifndef NO_BOLD_UNDERLINE_REVERSE 3408#ifndef NO_BOLD_UNDERLINE_REVERSE
3769 case XTerm_Color_BD:
3770 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3771 break;
3772 case XTerm_Color_IT:
3773 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3774 break;
3775 case XTerm_Color_UL:
3776 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3777 break;
3778 case XTerm_Color_RV: 3409 case XTerm_Color_RV:
3779 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3410 process_color_seq (op, Color_RV, str, resp);
3780 break; 3411 break;
3412 case Rxvt_Color_BD:
3413 case URxvt_Color_BD:
3414 process_color_seq (op, Color_BD, str, resp);
3415 break;
3416 case Rxvt_Color_UL:
3417 case URxvt_Color_UL:
3418 process_color_seq (op, Color_UL, str, resp);
3419 break;
3420 case URxvt_Color_IT:
3421 process_color_seq (op, Color_IT, str, resp);
3422 break;
3781#endif 3423#endif
3782#if TRANSPARENT && TINTING 3424#if ENABLE_TRANSPARENCY
3783 case XTerm_Color_tint: 3425 case URxvt_Color_tint:
3784 process_color_seq (XTerm_Color_tint, Color_tint, str, resp); 3426 process_color_seq (op, Color_tint, str, resp);
3785 check_our_parents (); 3427 {
3786 if (am_transparent) 3428 bool changed = false;
3787 want_full_refresh = want_refresh = 1; 3429 if (ISSET_PIXCOLOR (Color_tint))
3788 break; 3430 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3789#endif 3431 else
3432 changed = bgPixmap.unset_tint ();
3433 if (changed)
3434 update_background ();
3435 }
3790 3436
3437 break;
3438#endif
3439
3440#if BG_IMAGE_FROM_FILE
3791 case XTerm_Pixmap: 3441 case Rxvt_Pixmap:
3792 if (*str != ';') 3442 if (!strcmp (str, "?"))
3793 { 3443 {
3794#if XPM_BACKGROUND 3444 char str[256];
3795 scale_pixmap (""); /* reset to default scaling */ 3445
3796 set_bgPixmap (str); /* change pixmap */ 3446 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
3797#endif 3447 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3798 scr_touch (true); 3448 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3449 process_xterm_seq (XTerm_title, str, CHAR_ST);
3799 } 3450 }
3800 while ((str = strchr (str, ';')) != NULL) 3451 else
3801 { 3452 {
3453 int changed = 0;
3454
3455 if (*str != ';')
3456 {
3457 /* reset to default scaling :*/
3458 bgPixmap.unset_geometry ();
3459 if (bgPixmap.set_file (str)) /* change pixmap */
3460 changed++;
3461 str = strchr (str, ';');
3462 if (str == NULL)
3463 bgPixmap.set_defaultGeometry ();
3464 }
3465 while (str)
3466 {
3802 str++; 3467 str++;
3803#if XPM_BACKGROUND 3468 if (bgPixmap.set_geometry (str))
3804 changed += scale_pixmap (str); 3469 changed++;
3805#endif 3470 str = strchr (str, ';');
3471 }
3472 if (changed)
3473 update_background ();
3806 } 3474 }
3807
3808 if (changed)
3809 {
3810#ifdef XPM_BACKGROUND
3811 resize_pixmap ();
3812#endif
3813 scr_touch (true);
3814 }
3815 break; 3475 break;
3476#endif
3816 3477
3817 case XTerm_restoreFG: 3478 case Rxvt_restoreFG:
3818 set_window_color (Color_fg, str); 3479 set_window_color (Color_fg, str);
3819 break; 3480 break;
3820 case XTerm_restoreBG: 3481 case Rxvt_restoreBG:
3821 set_window_color (Color_bg, str); 3482 set_window_color (Color_bg, str);
3822 break; 3483 break;
3823 3484
3824 case XTerm_logfile: 3485 case XTerm_logfile:
3825 // TODO, when secure mode? 3486 // TODO, when secure mode?
3826 break; 3487 break;
3827 3488
3489#if 0
3490 case Rxvt_dumpscreen: /* no error notices */
3491 {
3492 int fd;
3493 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3494 {
3495 scr_dump (fd);
3496 close (fd);
3497 }
3498 }
3499 break;
3500#endif
3828 case XTerm_font: 3501 case XTerm_font:
3829 op = URxvt_font; 3502 op = URxvt_font;
3830 case URxvt_font: 3503 case URxvt_font:
3831#if ENABLE_STYLES 3504#if ENABLE_STYLES
3832 case URxvt_boldFont: 3505 case URxvt_boldFont:
3833 case URxvt_italicFont: 3506 case URxvt_italicFont:
3834 case URxvt_boldItalicFont: 3507 case URxvt_boldItalicFont:
3835#endif 3508#endif
3836 if (query) 3509 if (query)
3837 tt_printf ("\33]%d;%-.250s%c", saveop, 3510 tt_printf ("\33]%d;%-.250s%c", saveop,
3838 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3511 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3839 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3512 ? fontset[op - URxvt_font]->fontdesc : "",
3840 resp); 3513 resp);
3841 else 3514 else
3842 { 3515 {
3843 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3516 const char *&res = rs[Rs_font + (op - URxvt_font)];
3844 3517
3846 allocated.push_back ((void *)res); 3519 allocated.push_back ((void *)res);
3847 set_fonts (); 3520 set_fonts ();
3848 } 3521 }
3849 break; 3522 break;
3850 3523
3851#if ENABLE_FRILLS 3524 case URxvt_version:
3852 case XTerm_locale:
3853 if (query) 3525 if (query)
3526 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3527 op,
3528 rs[Rs_name], VERSION[0], VERSION[2],
3529 resp);
3530 break;
3531
3532#if !ENABLE_MINIMAL
3533 case URxvt_locale:
3534 if (query)
3854 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3535 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3855 else 3536 else
3856 { 3537 {
3857 set_locale (str); 3538 set_locale (str);
3858 pty.set_utf8_mode (enc_utf8); 3539 pty->set_utf8_mode (enc_utf8);
3859# ifdef USE_XIM
3860 im_cb (); 3540 init_xlocale ();
3861# endif
3862 } 3541 }
3863 break; 3542 break;
3864#endif
3865 3543
3866#ifdef MENUBAR 3544 case URxvt_view_up:
3867 case XTerm_Menu: 3545 case URxvt_view_down:
3868 if (options & Opt_insecure) 3546 {
3869 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3547 int lines = atoi (str);
3548
3549 if (lines)
3550 scr_page (op == URxvt_view_up ? UP : DN, lines);
3551 else
3552 scr_erase_savelines ();
3553 }
3554
3870 break; 3555 break;
3871#endif 3556#endif
3872#if 0 3557
3873 case XTerm_dumpscreen: /* no error notices */ 3558#if ENABLE_PERL
3874 { 3559 case URxvt_perl:
3875 int fd; 3560 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END)))
3876 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3561 ; // no responses yet
3877 {
3878 scr_dump (fd);
3879 close (fd);
3880 }
3881 }
3882 break; 3562 break;
3883#endif 3563#endif
3884 } 3564 }
3885} 3565}
3886/*----------------------------------------------------------------------*/ 3566/*----------------------------------------------------------------------*/
3917 return state; 3597 return state;
3918} 3598}
3919 3599
3920/* we're not using priv _yet_ */ 3600/* we're not using priv _yet_ */
3921void 3601void
3922rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3602rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3923{ 3603{
3924 unsigned int i, j; 3604 unsigned int i, j;
3925 int state; 3605 int state;
3926 3606
3927 static const struct 3607 static const struct
3928 { 3608 {
3929 const int argval; 3609 const int argval;
3930 const unsigned long bit; 3610 const unsigned long bit;
3931 }
3932
3933 argtopriv[] = { 3611 } argtopriv[] = {
3934 { 1, PrivMode_aplCUR }, 3612 { 1, PrivMode_aplCUR },
3935 { 2, PrivMode_vt52 }, 3613 { 2, PrivMode_vt52 },
3936 { 3, PrivMode_132 }, 3614 { 3, PrivMode_132 },
3937 { 4, PrivMode_smoothScroll }, 3615 { 4, PrivMode_smoothScroll },
3938 { 5, PrivMode_rVideo }, 3616 { 5, PrivMode_rVideo },
3939 { 6, PrivMode_relOrigin }, 3617 { 6, PrivMode_relOrigin },
3940 { 7, PrivMode_Autowrap }, 3618 { 7, PrivMode_Autowrap },
3941 // 8, bi-directional support mode 3619 // 8, bi-directional support mode
3942 { 9, PrivMode_MouseX10 }, 3620 { 9, PrivMode_MouseX10 },
3943#ifdef menuBar_esc
3944 { menuBar_esc, PrivMode_menuBar },
3945#endif
3946 // 18, 19 printing-related 3621 // 18, 19 printing-related
3947 { 25, PrivMode_VisibleCursor }, 3622 { 25, PrivMode_VisibleCursor },
3948#ifdef scrollBar_esc 3623#ifdef scrollBar_esc
3949 { scrollBar_esc, PrivMode_scrollBar }, 3624 { scrollBar_esc, PrivMode_scrollBar },
3950#endif 3625#endif
3958#ifndef NO_BACKSPACE_KEY 3633#ifndef NO_BACKSPACE_KEY
3959 { 67, PrivMode_BackSpace }, 3634 { 67, PrivMode_BackSpace },
3960#endif 3635#endif
3961 { 1000, PrivMode_MouseX11 }, 3636 { 1000, PrivMode_MouseX11 },
3962 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3637 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3963 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3638 { 1002, PrivMode_MouseBtnEvent },
3964 // 1003 Use All Motion Mouse Tracking. NYI, TODO 3639 { 1003, PrivMode_MouseAnyEvent },
3965 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3640 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3966 { 1011, PrivMode_Keypress }, // rxvt extension 3641 { 1011, PrivMode_Keypress }, // rxvt extension
3967 // 1035 enable modifiers for alt, numlock NYI 3642 // 1035 enable modifiers for alt, numlock NYI
3968 // 1036 send ESC for meta keys NYI 3643 // 1036 send ESC for meta keys NYI
3969 // 1037 send DEL for keypad delete NYI 3644 // 1037 send DEL for keypad delete NYI
3995 } 3670 }
3996 3671
3997 /* extra handling for values with state unkept */ 3672 /* extra handling for values with state unkept */
3998 switch (arg[i]) 3673 switch (arg[i])
3999 { 3674 {
3675#if ENABLE_STYLES
3676 case 1021:
3677 set_option (Opt_intensityStyles, mode);
3678
3679 scr_touch (true);
3680 break;
3681#endif
4000 case 1048: /* alternative cursor save */ 3682 case 1048: /* alternative cursor save */
4001 case 1049: 3683 case 1049:
4002 if (options & Opt_secondaryScreen) 3684 if (option (Opt_secondaryScreen))
4003 if (mode == 0) 3685 if (mode == 0)
4004 scr_cursor (RESTORE); 3686 scr_cursor (RESTORE);
4005 else if (mode == 1) 3687 else if (mode == 1)
4006 scr_cursor (SAVE); 3688 scr_cursor (SAVE);
4007 break; 3689 break;
4019 */ 3701 */
4020 PrivMode (1, PrivMode_vt52); 3702 PrivMode (1, PrivMode_vt52);
4021 break; 3703 break;
4022 case 3: /* 80/132 */ 3704 case 3: /* 80/132 */
4023 if (priv_modes & PrivMode_132OK) 3705 if (priv_modes & PrivMode_132OK)
4024 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 3706 set_widthheight (((state ? 132 : 80) * fwidth), height);
4025 break; 3707 break;
4026 case 4: /* smooth scrolling */ 3708 case 4: /* smooth scrolling */
4027 if (state)
4028 options &= ~Opt_jumpScroll;
4029 else
4030 options |= Opt_jumpScroll; 3709 set_option (Opt_jumpScroll, !state);
4031 break; 3710 break;
4032 case 5: /* reverse video */ 3711 case 5: /* reverse video */
4033 scr_rvideo_mode (state); 3712 scr_rvideo_mode (state);
4034 break; 3713 break;
4035 case 6: /* relative/absolute origins */ 3714 case 6: /* relative/absolute origins */
4039 scr_autowrap (state); 3718 scr_autowrap (state);
4040 break; 3719 break;
4041 /* case 8: - auto repeat, can't do on a per window basis */ 3720 /* case 8: - auto repeat, can't do on a per window basis */
4042 case 9: /* X10 mouse reporting */ 3721 case 9: /* X10 mouse reporting */
4043 if (state) /* orthogonal */ 3722 if (state) /* orthogonal */
4044 priv_modes &= ~PrivMode_MouseX11; 3723 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4045 break; 3724 break;
4046#ifdef menuBar_esc
4047 case menuBar_esc:
4048#ifdef MENUBAR
4049 map_menuBar (state);
4050#endif
4051 break;
4052#endif
4053#ifdef scrollBar_esc 3725#ifdef scrollBar_esc
4054 case scrollBar_esc: 3726 case scrollBar_esc:
4055 if (scrollbar_mapping (state)) 3727 if (scrollbar_mapping (state))
4056 { 3728 {
4057 resize_all_windows (0, 0, 0); 3729 resize_all_windows (0, 0, 0);
4069 break; 3741 break;
4070 /* case 66: - application key pad */ 3742 /* case 66: - application key pad */
4071 /* case 67: - backspace key */ 3743 /* case 67: - backspace key */
4072 case 1000: /* X11 mouse reporting */ 3744 case 1000: /* X11 mouse reporting */
4073 if (state) /* orthogonal */ 3745 if (state) /* orthogonal */
4074 priv_modes &= ~PrivMode_MouseX10; 3746 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4075 break; 3747 break;
4076#if 0 3748#if 0
4077 case 1001: 3749 case 1001:
4078 break; /* X11 mouse highlighting */ 3750 break; /* X11 mouse highlighting */
4079#endif 3751#endif
3752 case 1002:
3753 case 1003:
3754 if (state) {
3755 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3756 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3757 vt_emask_mouse = PointerMotionMask;
3758 } else
3759 vt_emask_mouse = NoEventMask;
3760 vt_select_input ();
3761 break;
4080 case 1010: /* scroll to bottom on TTY output inhibit */ 3762 case 1010: /* scroll to bottom on TTY output inhibit */
4081 if (state)
4082 options &= ~Opt_scrollTtyOutput;
4083 else
4084 options |= Opt_scrollTtyOutput; 3763 set_option (Opt_scrollTtyOutput, !state);
4085 break; 3764 break;
4086 case 1011: /* scroll to bottom on key press */ 3765 case 1011: /* scroll to bottom on key press */
4087 if (state)
4088 options |= Opt_scrollTtyKeypress; 3766 set_option (Opt_scrollTtyKeypress, state);
4089 else
4090 options &= ~Opt_scrollTtyKeypress;
4091 break; 3767 break;
4092 case 1047: /* secondary screen w/ clearing last */ 3768 case 1047: /* secondary screen w/ clearing last */
4093 if (options & Opt_secondaryScreen) 3769 if (option (Opt_secondaryScreen))
4094 if (current_screen != PRIMARY) 3770 if (current_screen != PRIMARY)
4095 scr_erase_screen (2); 3771 scr_erase_screen (2);
4096 scr_change_screen (state); 3772 scr_change_screen (state);
4097 break; 3773 break;
4098 case 1049: /* secondary screen w/ clearing first */ 3774 case 1049: /* secondary screen w/ clearing first */
4099 scr_change_screen (state); 3775 scr_change_screen (state);
4100 if (options & Opt_secondaryScreen) 3776 if (option (Opt_secondaryScreen))
4101 if (current_screen != PRIMARY) 3777 if (current_screen != PRIMARY)
4102 scr_erase_screen (2); 3778 scr_erase_screen (2);
4103 break; 3779 break;
4104 default: 3780 default:
4105 break; 3781 break;
4233 scr_color (Color_bg, Color_bg); 3909 scr_color (Color_bg, Color_bg);
4234 break; 3910 break;
4235 3911
4236 //case 50: // not variable spacing 3912 //case 50: // not variable spacing
4237 3913
4238#ifndef NO_BRIGHTCOLOR 3914#if !ENABLE_MINIMAL
4239 case 90: 3915 case 90:
4240 case 91: /* set bright fg color */ 3916 case 91: /* set bright fg color */
4241 case 92: 3917 case 92:
4242 case 93: 3918 case 93:
4243 case 94: 3919 case 94:
4255 case 106: 3931 case 106:
4256 case 107: 3932 case 107:
4257 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 3933 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4258 break; 3934 break;
4259#endif 3935#endif
4260
4261 } 3936 }
4262 } 3937 }
4263} 3938}
4264/*}}} */ 3939/*}}} */
4265 3940
4289 */ 3964 */
4290void 3965void
4291rxvt_term::tt_printf (const char *fmt,...) 3966rxvt_term::tt_printf (const char *fmt,...)
4292{ 3967{
4293 va_list arg_ptr; 3968 va_list arg_ptr;
4294 unsigned char buf[256]; 3969 char buf[256];
4295 3970
4296 va_start (arg_ptr, fmt); 3971 va_start (arg_ptr, fmt);
4297 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 3972 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4298 va_end (arg_ptr); 3973 va_end (arg_ptr);
4299 tt_write (buf, strlen (buf)); 3974 tt_write (buf, strlen (buf));
4304 * or generated by us in response to a query ESC sequence. 3979 * or generated by us in response to a query ESC sequence.
4305 */ 3980 */
4306const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 3981const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4307 3982
4308void 3983void
4309rxvt_term::tt_write (const unsigned char *data, unsigned int len) 3984rxvt_term::tt_write (const char *data, unsigned int len)
4310{ 3985{
3986 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
3987 return;
3988
3989 if (pty->pty < 0)
3990 return;
3991
4311 if (v_buflen == 0) 3992 if (v_buflen == 0)
4312 { 3993 {
4313 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 3994 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4314 3995
4315 if ((unsigned int)written == len) 3996 if ((unsigned int)written == len)
4316 return; 3997 return;
4317 3998
4318 data += written; 3999 data += written;
4319 len -= written; 4000 len -= written;
4320 } 4001 }
4321 4002
4322 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4003 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4323 4004
4324 memcpy (v_buffer + v_buflen, data, len); 4005 memcpy (v_buffer + v_buflen, data, len);
4325 v_buflen += len; 4006 v_buflen += len;
4326 4007
4327 pty_ev.set (EVENT_READ | EVENT_WRITE); 4008 pty_ev.set (ev::READ | ev::WRITE);
4328} 4009}
4329 4010
4330void rxvt_term::pty_write () 4011void rxvt_term::pty_write ()
4331{ 4012{
4332 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4013 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4333 4014
4334 if (written > 0) 4015 if (written > 0)
4335 { 4016 {
4336 v_buflen -= written; 4017 v_buflen -= written;
4337 4018
4338 if (v_buflen == 0) 4019 if (v_buflen == 0)
4339 { 4020 {
4340 free (v_buffer); 4021 free (v_buffer);
4341 v_buffer = 0; 4022 v_buffer = 0;
4342 v_buflen = 0;
4343 4023
4344 pty_ev.set (EVENT_READ); 4024 pty_ev.set (ev::READ);
4345 return; 4025 return;
4346 } 4026 }
4347 4027
4348 memmove (v_buffer, v_buffer + written, v_buflen); 4028 memmove (v_buffer, v_buffer + written, v_buflen);
4349 } 4029 }
4350 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4030 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4351 // original code just ignores this... 4031 pty_ev.set (ev::READ);
4352 destroy ();
4353} 4032}
4354 4033
4355/*----------------------- end-of-file (C source) -----------------------*/ 4034/*----------------------- end-of-file (C source) -----------------------*/
4356 4035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines