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.198 by root, Sat Feb 19 01:07:58 2005 UTC vs.
Revision 1.364 by ayin, Mon Nov 12 14:53:13 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;
554#ifdef XK_KP_Home
555 static const KeySym keypadtrans[] = {
556 XK_KP_7, // XK_KP_Home
557 XK_KP_4, // XK_KP_Left
558 XK_KP_8, // XK_KP_Up
559 XK_KP_6, // XK_KP_Right
560 XK_KP_2, // XK_KP_Down
561#ifndef UNSHIFTED_SCROLLKEYS
562 XK_KP_9, // XK_KP_Prior
563 XK_KP_3, // XK_KP_Next
564#else
565 XK_Prior,
566 XK_Next,
567#endif
568 XK_KP_1, // XK_KP_End
569 XK_KP_5, // XK_KP_Begin
570 };
571
572 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin))
573 {
574 unsigned int index = keysym - XK_KP_Home;
575 keysym = kp ? keypadtrans[index] : XK_Home + index;
576 }
577 else if (keysym == XK_KP_Insert)
578 keysym = kp ? XK_KP_0 : XK_Insert;
579#ifndef NO_DELETE_KEY
580 else if (keysym == XK_KP_Delete)
581 keysym = kp ? XK_KP_Decimal : XK_Delete;
582#endif
583#endif
510 switch (keysym) 584 switch (keysym)
511 { 585 {
512#ifndef NO_BACKSPACE_KEY 586#ifndef NO_BACKSPACE_KEY
513 case XK_BackSpace: 587 case XK_BackSpace:
514 if (priv_modes & PrivMode_HaveBackSpace) 588 if (priv_modes & PrivMode_HaveBackSpace)
516 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) 590 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
517 ^ !!ctrl) ? '\b' : '\177'; 591 ^ !!ctrl) ? '\b' : '\177';
518 kbuf[1] = '\0'; 592 kbuf[1] = '\0';
519 } 593 }
520 else 594 else
521 strcpy (kbuf, key_backspace); 595 strcpy (kbuf, rs[Rs_backspace_key]);
522 break; 596 break;
523#endif 597#endif
524#ifndef NO_DELETE_KEY 598#ifndef NO_DELETE_KEY
525# ifdef XK_KP_Prior
526 case XK_KP_Delete:
527 /* allow shift to override */
528 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
529 {
530 strcpy (kbuf, "\033On");
531 break;
532 }
533 /* FALLTHROUGH */
534# endif
535 case XK_Delete: 599 case XK_Delete:
536 strcpy (kbuf, key_delete); 600 strcpy (kbuf, rs[Rs_delete_key]);
537 break; 601 break;
538#endif 602#endif
539 case XK_Tab: 603 case XK_Tab:
540 if (shft) 604 if (shft)
541 strcpy (kbuf, "\033[Z"); 605 strcpy (kbuf, "\033[Z");
551#endif 615#endif
552 newlen = 0; 616 newlen = 0;
553 } 617 }
554 break; 618 break;
555 619
556#ifdef XK_KP_Left
557 case XK_KP_Up: /* \033Ox or standard */
558 case XK_KP_Down: /* \033Or or standard */
559 case XK_KP_Right: /* \033Ov or standard */
560 case XK_KP_Left: /* \033Ot or standard */
561 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
562 {
563 strcpy (kbuf, "\033OZ");
564 kbuf[2] = "txvr"[keysym - XK_KP_Left];
565 break;
566 }
567 else
568 /* translate to std. cursor key */
569 keysym = XK_Left + (keysym - XK_KP_Left);
570 /* FALLTHROUGH */
571#endif
572 case XK_Up: /* "\033[A" */ 620 case XK_Up: /* "\033[A" */
573 case XK_Down: /* "\033[B" */ 621 case XK_Down: /* "\033[B" */
574 case XK_Right: /* "\033[C" */ 622 case XK_Right: /* "\033[C" */
575 case XK_Left: /* "\033[D" */ 623 case XK_Left: /* "\033[D" */
576 strcpy (kbuf, "\033[Z"); 624 strcpy (kbuf, "\033[Z");
586 else if (priv_modes & PrivMode_aplCUR) 634 else if (priv_modes & PrivMode_aplCUR)
587 kbuf[1] = 'O'; 635 kbuf[1] = 'O';
588 break; 636 break;
589 637
590#ifndef UNSHIFTED_SCROLLKEYS 638#ifndef UNSHIFTED_SCROLLKEYS
591# ifdef XK_KP_Prior
592 case XK_KP_Prior:
593 /* allow shift to override */
594 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
595 {
596 strcpy (kbuf, "\033Oy");
597 break;
598 }
599 /* FALLTHROUGH */
600# endif
601 case XK_Prior: 639 case XK_Prior:
602 strcpy (kbuf, "\033[5~"); 640 strcpy (kbuf, "\033[5~");
603 break; 641 break;
604# ifdef XK_KP_Next
605 case XK_KP_Next:
606 /* allow shift to override */
607 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
608 {
609 strcpy (kbuf, "\033Os");
610 break;
611 }
612 /* FALLTHROUGH */
613# endif
614 case XK_Next: 642 case XK_Next:
615 strcpy (kbuf, "\033[6~"); 643 strcpy (kbuf, "\033[6~");
616 break; 644 break;
617#endif 645#endif
618 case XK_KP_Enter: 646 case XK_KP_Enter:
619 /* allow shift to override */ 647 /* allow shift to override */
620 if ((priv_modes & PrivMode_aplKP) ? !shft : shft) 648 if (kp)
621 { 649 {
622 strcpy (kbuf, "\033OM"); 650 strcpy (kbuf, "\033OM");
623 break; 651 break;
624 } 652 }
625 653
637 kbuf[0] = '\015'; 665 kbuf[0] = '\015';
638 kbuf[1] = '\0'; 666 kbuf[1] = '\0';
639 } 667 }
640 break; 668 break;
641 669
642#ifdef XK_KP_Begin
643 case XK_KP_Begin:
644 strcpy (kbuf, "\033Ou");
645 break;
646
647#endif
648 case XK_KP_F1: /* "\033OP" */ 670 case XK_KP_F1: /* "\033OP" */
649 case XK_KP_F2: /* "\033OQ" */ 671 case XK_KP_F2: /* "\033OQ" */
650 case XK_KP_F3: /* "\033OR" */ 672 case XK_KP_F3: /* "\033OR" */
651 case XK_KP_F4: /* "\033OS" */ 673 case XK_KP_F4: /* "\033OS" */
652 strcpy (kbuf, "\033OP"); 674 strcpy (kbuf, "\033OP");
668 case XK_KP_6: /* "\033Ov" : "6" */ 690 case XK_KP_6: /* "\033Ov" : "6" */
669 case XK_KP_7: /* "\033Ow" : "7" */ 691 case XK_KP_7: /* "\033Ow" : "7" */
670 case XK_KP_8: /* "\033Ox" : "8" */ 692 case XK_KP_8: /* "\033Ox" : "8" */
671 case XK_KP_9: /* "\033Oy" : "9" */ 693 case XK_KP_9: /* "\033Oy" : "9" */
672 /* allow shift to override */ 694 /* allow shift to override */
673 if ((priv_modes & PrivMode_aplKP) ? !shft : shft) 695 if (kp)
674 { 696 {
675 strcpy (kbuf, "\033Oj"); 697 strcpy (kbuf, "\033Oj");
676 kbuf[2] += (keysym - XK_KP_Multiply); 698 kbuf[2] += (keysym - XK_KP_Multiply);
677 } 699 }
678 else 700 else
684 706
685 case XK_Find: 707 case XK_Find:
686 strcpy (kbuf, "\033[1~"); 708 strcpy (kbuf, "\033[1~");
687 break; 709 break;
688 710
689#ifdef XK_KP_End
690 case XK_KP_Insert:
691 /* allow shift to override */
692 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
693 {
694 strcpy (kbuf, "\033Op");
695 break;
696 }
697 /* FALLTHROUGH */
698#endif
699 case XK_Insert: 711 case XK_Insert:
700 strcpy (kbuf, "\033[2~"); 712 strcpy (kbuf, "\033[2~");
701 break; 713 break;
702#ifdef DXK_Remove /* support for DEC remove like key */ 714#ifdef DXK_Remove /* support for DEC remove like key */
703 case DXK_Remove: 715 case DXK_Remove:
707 strcpy (kbuf, "\033[3~"); 719 strcpy (kbuf, "\033[3~");
708 break; 720 break;
709 case XK_Select: 721 case XK_Select:
710 strcpy (kbuf, "\033[4~"); 722 strcpy (kbuf, "\033[4~");
711 break; 723 break;
712#ifdef XK_KP_End
713 case XK_KP_End:
714 /* allow shift to override */
715 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
716 {
717 strcpy (kbuf, "\033Oq");
718 break;
719 }
720 /* FALLTHROUGH */
721#endif
722 case XK_End: 724 case XK_End:
723 strcpy (kbuf, KS_END); 725 strcpy (kbuf, KS_END);
724 break; 726 break;
725#ifdef XK_KP_Home
726 case XK_KP_Home:
727 /* allow shift to override */
728 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
729 {
730 strcpy (kbuf, "\033Ow");
731 break;
732 }
733 /* FALLTHROUGH */
734#endif
735 case XK_Home: 727 case XK_Home:
736 strcpy (kbuf, KS_HOME); 728 strcpy (kbuf, KS_HOME);
737 break; 729 break;
738 730
739#define FKEY(n, fkey) \ 731#define FKEY(n, fkey) \
823 { 815 {
824#ifdef META8_OPTION 816#ifdef META8_OPTION
825 /* set 8-bit on */ 817 /* set 8-bit on */
826 if (meta && (meta_char == 0x80)) 818 if (meta && (meta_char == 0x80))
827 { 819 {
828 unsigned char *ch; 820 char *ch;
829 821
830 for (ch = kbuf; ch < kbuf + len; ch++) 822 for (ch = kbuf; ch < kbuf + len; ch++)
831 *ch |= 0x80; 823 *ch |= 0x80;
832 824
833 meta = 0; 825 meta = 0;
835#endif 827#endif
836 /* nil */ ; 828 /* nil */ ;
837 } 829 }
838 } 830 }
839 831
832 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
833 return;
834
840 if (len <= 0) 835 if (len <= 0)
841 return; /* not mapped */ 836 return; /* not mapped */
842 837
843 if (options & Opt_scrollTtyKeypress) 838 if (option (Opt_scrollTtyKeypress))
844 if (TermWin.view_start) 839 if (view_start)
845 { 840 {
846 TermWin.view_start = 0; 841 view_start = 0;
847 want_refresh = 1; 842 want_refresh = 1;
848 } 843 }
849 844
850 /* 845 /*
851 * these modifications only affect the static keybuffer 846 * these modifications only affect the static keybuffer
866#ifdef META8_OPTION 861#ifdef META8_OPTION
867 && meta_char == C0_ESC 862 && meta_char == C0_ESC
868#endif 863#endif
869 ) 864 )
870 { 865 {
871 const unsigned char ch = C0_ESC; 866 const char ch = C0_ESC;
872 tt_write (&ch, 1); 867 tt_write (&ch, 1);
873 } 868 }
874 869
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); 870 tt_write (kbuf, (unsigned int)len);
886} 871}
887/*}}} */
888 872
873void
874rxvt_term::key_release (XKeyEvent &ev)
875{
876#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
877 KeySym keysym;
878
879 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
880#endif
881
882#if ENABLE_FRILLS || ISO_14755
883 // ISO 14755 support
884 if (iso14755buf)
885 if (iso14755buf & ISO_14755_52)
886 {
887# if ISO_14755
888 scr_overlay_off ();
889# endif
890# if ISO_14755
891 // iso14755 part 5.2 handling: release time
892 // first: controls
893 if ((ev.state & ControlMask)
894 && ((keysym >= 0x40 && keysym <= 0x5f)
895 || (keysym >= 0x61 && keysym <= 0x7f)))
896 {
897 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
898 commit_iso14755 ();
899
900 return;
901 }
902
903 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
904 if (i[0] == keysym)
905 {
906 iso14755buf = ISO_14755_51 | i[1];
907 commit_iso14755 ();
908
909 return;
910 }
911
912 scr_bell ();
913# endif
914 iso14755buf = 0;
915
916 return;
917 }
918 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
919 {
920# if ISO_14755
921 scr_overlay_off ();
922# endif
923 if (iso14755buf & ISO_14755_51)
924 commit_iso14755 ();
925#if ISO_14755
926 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
927 {
928 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
929
930 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
931 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
932 }
933# endif
934 else
935 iso14755buf = 0;
936 }
937#endif
938
939 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
940 return;
941
942#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
943 if (!(ev.state & ControlMask))
944 slip_wheel_ev.stop ();
945 else if (keysym == XK_Control_L || keysym == XK_Control_R)
946 mouse_slip_wheel_speed = 0;
947#endif
948}
949
889#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 950#if defined (KEYSYM_RESOURCE)
890/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
891/* attempt to `write' count to the input buffer */
892unsigned int 951unsigned int
893rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 952rxvt_term::cmd_write (const char *str, unsigned int count)
894{ 953{
895 unsigned int n, s; 954 unsigned int n, s;
896 955
897 n = cmdbuf_ptr - cmdbuf_base; 956 n = cmdbuf_ptr - cmdbuf_base;
898 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 957 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
924void 983void
925rxvt_term::flush () 984rxvt_term::flush ()
926{ 985{
927 flush_ev.stop (); 986 flush_ev.stop ();
928 987
929#ifdef TRANSPARENT 988#ifdef HAVE_BG_PIXMAP
930 if (want_full_refresh) 989 if (bgPixmap.check_clearChanged ())
931 { 990 {
932 want_full_refresh = 0; 991// scr_clear (true); This needs to be researched further!
933 scr_clear ();
934 scr_touch (false); 992 scr_touch (false);
935 } 993 }
936#endif 994#endif
937 995
938 if (want_refresh) 996 if (want_refresh)
939 { 997 {
998 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
999 {
1000 int row = view_start;
1001 int end_row = row + nrow;
1002
1003 while (row > top_row && ROW (row - 1).is_longer ())
1004 --row;
1005
1006 do
1007 {
1008 int start_row = row;
1009 line_t *l;
1010
1011 do
1012 {
1013 l = &ROW (row++);
1014
1015 if (!(l->f & LINE_FILTERED))
1016 {
1017 // line not filtered, mark it as filtered
1018 l->f |= LINE_FILTERED;
1019 while (l->is_longer ())
1020 {
1021 l = &ROW (row++);
1022 l->f |= LINE_FILTERED;
1023 }
1024
1025 // and filter it
1026 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
1027
1028 break;
1029 }
1030 }
1031 while (l->is_longer () && row < end_row);
1032 }
1033 while (row < end_row);
1034 }
1035
940 scr_refresh (refresh_type); 1036 scr_refresh ();
941 scrollbar_show (1); 1037 scrollbar_show (1);
942#ifdef USE_XIM 1038#ifdef USE_XIM
943 IMSendSpot (); 1039 IMSendSpot ();
944#endif 1040#endif
945 } 1041 }
946 1042
947 display->flush (); 1043 display->flush ();
948} 1044}
949 1045
950void 1046void
951rxvt_term::check_cb (check_watcher &w) 1047rxvt_term::prepare_cb (ev::prepare &w, int revents)
952{ 1048{
953 SET_R (this); 1049 make_current ();
954 SET_LOCALE (locale);
955 1050
956 display->flush (); 1051 display->flush ();
957 1052
958 if (want_refresh && !flush_ev.active) 1053 if (want_refresh && !flush_ev.active)
959 flush_ev.start (NOW + 0.01); 1054 flush_ev.start (1. / 60.); // refresh at max. 60 hz normally
960} 1055}
961 1056
962void 1057void
963rxvt_term::flush_cb (time_watcher &w) 1058rxvt_term::flush_cb (ev::timer &w, int revents)
964{ 1059{
965 SET_R (this); 1060 make_current ();
966 SET_LOCALE (locale);
967 1061
968 refresh_limit = 1;
969 refresh_count = 0; 1062 refresh_count = 0;
970 flush (); 1063 flush ();
971} 1064}
972 1065
973#ifdef CURSOR_BLINK 1066#ifdef CURSOR_BLINK
974void 1067void
975rxvt_term::cursor_blink_cb (time_watcher &w) 1068rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
976{ 1069{
977 hidden_cursor = !hidden_cursor; 1070 hidden_cursor = !hidden_cursor;
978 want_refresh = 1; 1071 want_refresh = 1;
979
980 w.start (w.at + BLINK_INTERVAL);
981} 1072}
982#endif 1073#endif
983 1074
984#ifdef TEXT_BLINK 1075#ifdef TEXT_BLINK
985void 1076void
986rxvt_term::text_blink_cb (time_watcher &w) 1077rxvt_term::text_blink_cb (ev::timer &w, int revents)
987{ 1078{
988 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1079 if (scr_refresh_rend (RS_Blink, RS_Blink))
989 { 1080 {
990 hidden_text = !hidden_text; 1081 hidden_text = !hidden_text;
991 want_refresh = 1; 1082 want_refresh = 1;
992 w.start (w.at + TEXT_BLINK_INTERVAL);
993 } 1083 }
994} 1084}
995#endif 1085#endif
996 1086
997#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1087#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
998void 1088void
999rxvt_term::cont_scroll_cb (time_watcher &w) 1089rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1000{ 1090{
1001 if ((scrollbar_isUp() || scrollbar_isDn()) && 1091 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1002 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1092 scr_page (scrollbar_isUp() ? UP : DN, 1))
1003 {
1004 refresh_type |= SMOOTH_REFRESH;
1005 want_refresh = 1; 1093 want_refresh = 1;
1006 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1094 else
1007 } 1095 w.stop ();
1008} 1096}
1009#endif 1097#endif
1010 1098
1011#ifdef SELECTION_SCROLLING 1099#ifdef SELECTION_SCROLLING
1012void 1100void
1013rxvt_term::sel_scroll_cb (time_watcher &w) 1101rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1014{ 1102{
1015 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1103 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1016 { 1104 {
1017 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1105 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1018 refresh_type |= SMOOTH_REFRESH;
1019 want_refresh = 1; 1106 want_refresh = 1;
1020 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1021 } 1107 }
1108 else
1109 w.stop ();
1022} 1110}
1023#endif 1111#endif
1024 1112
1025#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1113#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1026void 1114void
1027rxvt_term::slip_wheel_cb (time_watcher &w) 1115rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1028{ 1116{
1029 if (mouse_slip_wheel_speed == 0 1117 if (mouse_slip_wheel_speed == 0
1030 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1118 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1031 : scr_page (UP, mouse_slip_wheel_speed)) 1119 : scr_page (UP, mouse_slip_wheel_speed))
1032 { 1120 {
1033 if (TermWin.view_start == TermWin.nscrolled || 1121 if (view_start == top_row || view_start == 0)
1034 TermWin.view_start == 0)
1035 mouse_slip_wheel_speed = 0; 1122 mouse_slip_wheel_speed = 0;
1036 1123
1037 refresh_type |= SMOOTH_REFRESH;
1038 want_refresh = 1; 1124 want_refresh = 1;
1039 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1125 }
1126 else
1127 w.stop ();
1128}
1129#endif
1130
1131#if LINUX_YIELD_HACK
1132static struct event_handler
1133{
1134 ev::prepare yield_ev;
1135
1136 void yield_cb (ev::prepare &w, int revents)
1137 {
1138 // this should really be sched_yield(), but the linux guys thought
1139 // that giving a process calling sched_yield () less cpu time than
1140 // ones with high nice levels is a useful thing to do. It surely is is
1141 // allowed by the sus... as is returning ENOSYS.
1142
1143 struct timespec ts = { 0, 0 };
1144 nanosleep (&ts, 0);
1145
1146 w.stop ();
1040 } 1147 }
1041} 1148
1149 event_handler ()
1150 : yield_ev (this, &event_handler::yield_cb)
1151 {
1152 }
1153} event_handler;
1042#endif 1154#endif
1043 1155
1044bool 1156bool
1045rxvt_term::pty_fill () 1157rxvt_term::pty_fill ()
1046{ 1158{
1047 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1159 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1048 1160
1049 if (CBUFSIZ == n) 1161 if (CBUFSIZ == n)
1050 { 1162 {
1051 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1163 rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n");
1052 n = 0; 1164 n = 0;
1053 } 1165 }
1054 1166
1055 memmove (cmdbuf_base, cmdbuf_ptr, n); 1167 memmove (cmdbuf_base, cmdbuf_ptr, n);
1056 cmdbuf_ptr = cmdbuf_base; 1168 cmdbuf_ptr = cmdbuf_base;
1057 cmdbuf_endp = cmdbuf_ptr + n; 1169 cmdbuf_endp = cmdbuf_ptr + n;
1058 1170
1059 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1171 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1060 1172
1061 if (n > 0) 1173 if (r > 0)
1062 { 1174 {
1063 cmdbuf_endp += n; 1175 cmdbuf_endp += r;
1064 return true; 1176 return true;
1065 } 1177 }
1066 else if (n < 0 && errno != EAGAIN) 1178 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1179 {
1180#if LINUX_YIELD_HACK
1181 if (display->is_local)
1182 event_handler.yield_ev.start ();
1183#endif
1184 }
1185 else
1186 {
1187 pty_ev.stop ();
1188
1189 if (!option (Opt_hold))
1067 destroy (); 1190 destroy ();
1068 1191 }
1192
1069 return false; 1193 return false;
1070} 1194}
1071 1195
1072void 1196void
1073rxvt_term::pty_cb (io_watcher &w, short revents) 1197rxvt_term::pty_cb (ev::io &w, int revents)
1074{ 1198{
1075 SET_R (this); 1199 make_current ();
1076 SET_LOCALE (locale);
1077 1200
1078 if (revents & EVENT_READ) 1201 if (revents & ev::READ)
1079 // loop, but don't allow a single term to monopolize us 1202 // loop, but don't allow a single term to monopolize us
1080 while (pty_fill ()) 1203 while (pty_fill ())
1081 if (cmd_parse ()) 1204 if (cmd_parse ())
1082 break; 1205 break;
1083 1206
1084 if (revents & EVENT_WRITE) 1207 if (revents & ev::WRITE)
1085 pty_write (); 1208 pty_write ();
1086} 1209}
1087 1210
1088void 1211void
1089rxvt_term::pointer_unblank () 1212rxvt_term::pointer_unblank ()
1090{ 1213{
1091 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1214 XDefineCursor (dpy, vt, TermWin_cursor);
1092 recolour_cursor (); 1215 recolour_cursor ();
1093 1216
1094#ifdef POINTER_BLANK 1217#ifdef POINTER_BLANK
1095 hidden_pointer = 0; 1218 hidden_pointer = 0;
1096 1219
1097 if (options & Opt_pointerBlank) 1220 if (option (Opt_pointerBlank))
1098 pointer_ev.start (NOW + pointerBlankDelay); 1221 pointer_ev.start (pointerBlankDelay);
1099#endif 1222#endif
1100} 1223}
1101 1224
1102#ifdef POINTER_BLANK 1225#ifdef POINTER_BLANK
1103void 1226void
1104rxvt_term::pointer_blank () 1227rxvt_term::pointer_blank ()
1105{ 1228{
1106 if (! (options & Opt_pointerBlank)) 1229 if (!option (Opt_pointerBlank))
1107 return; 1230 return;
1108 1231
1109 XDefineCursor (display->display, TermWin.vt, display->blank_cursor); 1232 XDefineCursor (dpy, vt, display->blank_cursor);
1110 XFlush (display->display); 1233 XFlush (dpy);
1111 1234
1112 hidden_pointer = 1; 1235 hidden_pointer = 1;
1113} 1236}
1114 1237
1115void 1238void
1116rxvt_term::pointer_cb (time_watcher &w) 1239rxvt_term::pointer_cb (ev::timer &w, int revents)
1117{ 1240{
1118 SET_R (this); 1241 make_current ();
1119 SET_LOCALE (locale);
1120 1242
1121 pointer_blank (); 1243 pointer_blank ();
1122} 1244}
1123#endif 1245#endif
1124 1246
1125void 1247void
1126rxvt_term::mouse_report (XButtonEvent &ev) 1248rxvt_term::mouse_report (XButtonEvent &ev)
1127{ 1249{
1128 int button_number, key_state = 0; 1250 int button_number, key_state = 0;
1129 int x, y; 1251 int x, y;
1252 int code = 32;
1130 1253
1131 x = ev.x; 1254 x = Pixel2Col (ev.x);
1132 y = ev.y; 1255 y = Pixel2Row (ev.y);
1133 pixel_position (&x, &y); 1256 if (ev.type == MotionNotify) {
1257 if (x == mouse_row && y == mouse_col)
1258 return;
1259 mouse_row = x;
1260 mouse_col = y;
1261 code += 32;
1262 }
1134 1263
1135 if (MEvent.button == AnyButton) 1264 if (MEvent.button == AnyButton)
1136 button_number = 3; 1265 button_number = 3;
1137 else 1266 else
1138 { 1267 {
1184 x + 1, 1313 x + 1,
1185 y + 1); 1314 y + 1);
1186#endif 1315#endif
1187 1316
1188 tt_printf ("\033[M%c%c%c", 1317 tt_printf ("\033[M%c%c%c",
1189 (32 + button_number + key_state), 1318 (code + button_number + key_state),
1190 (32 + x + 1), 1319 (32 + x + 1),
1191 (32 + y + 1)); 1320 (32 + y + 1));
1192} 1321}
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 1322
1204/*{{{ process an X event */ 1323/*{{{ process an X event */
1205void 1324void
1206rxvt_term::x_cb (XEvent &ev) 1325rxvt_term::x_cb (XEvent &ev)
1207{ 1326{
1208 dDisp; 1327 make_current ();
1209 1328
1210 SET_R (this); 1329 dLocal (Display *, dpy);
1211 SET_LOCALE (locale);
1212 1330
1213#if defined(CURSOR_BLINK) 1331 if (ev.xany.window == vt
1214 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1332 && SHOULD_INVOKE (HOOK_X_EVENT)
1215 { 1333 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1216 if (hidden_cursor) 1334 return;
1217 {
1218 hidden_cursor = 0;
1219 want_refresh = 1;
1220 }
1221 1335
1222 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1336 // 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; 1337 Window unused_root, unused_child;
1241 int unused_root_x, unused_root_y; 1338 int unused_root_x, unused_root_y;
1242 unsigned int unused_mask; 1339 unsigned int unused_mask;
1243 1340
1244 switch (ev.type) 1341 switch (ev.type)
1245 { 1342 {
1246 case KeyPress: 1343 case KeyPress:
1247#if ISO_14755 1344 key_press (ev.xkey);
1248 if (!(iso14755buf & ISO_14755_52))
1249#endif
1250 lookup_key (ev.xkey);
1251
1252 break; 1345 break;
1253 1346
1254 case KeyRelease: 1347 case KeyRelease:
1255 { 1348 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; 1349 break;
1323 }
1324 1350
1325 case ButtonPress: 1351 case ButtonPress:
1326 button_press (ev.xbutton); 1352 button_press (ev.xbutton);
1327 break; 1353 break;
1328 1354
1330 button_release (ev.xbutton); 1356 button_release (ev.xbutton);
1331 break; 1357 break;
1332 1358
1333 case ClientMessage: 1359 case ClientMessage:
1334 if (ev.xclient.format == 32 1360 if (ev.xclient.format == 32
1361 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1362 {
1335 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS] 1363 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1364 {
1365 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1366 {
1336 && ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1367 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1337 destroy (); 1368 {
1369 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1370 destroy ();
1371 }
1372#if ENABLE_EWMH
1373 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1374 XSendEvent (dpy, ev.xclient.window = display->root,
1375 False, SubstructureRedirectMask | SubstructureNotifyMask,
1376 &ev);
1377#endif
1378 }
1379 }
1338#if ENABLE_XEMBED 1380#if ENABLE_XEMBED
1339 else if (ev.xclient.format == 32
1340 && ev.xclient.message_type == xa[XA_XEMBED]) 1381 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1341 { 1382 {
1342 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) 1383 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1343 focus_in (); 1384 focus_in ();
1344 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1385 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1345 focus_out (); 1386 focus_out ();
1387 }
1388#endif
1346 } 1389 }
1347#endif
1348#ifdef OFFIX_DND
1349 /* OffiX Dnd (drag 'n' drop) protocol */
1350 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1351 && (ev.xclient.data.l[0] == DndFile
1352 || ev.xclient.data.l[0] == DndDir
1353 || ev.xclient.data.l[0] == DndLink))
1354 {
1355 /* Get Dnd data */
1356 Atom ActualType;
1357 int ActualFormat;
1358 unsigned char *data;
1359 unsigned long Size, RemainingBytes;
1360
1361 XGetWindowProperty (disp, display->root,
1362 xa[XA_DNDSELECTION],
1363 0L, 1000000L,
1364 False, AnyPropertyType,
1365 &ActualType, &ActualFormat,
1366 &Size, &RemainingBytes,
1367 &data);
1368 set_string_property (XA_CUT_BUFFER0, data);
1369 XFree (data);
1370 selection_paste (display->root, XA_CUT_BUFFER0, true);
1371 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1372 }
1373#endif /* OFFIX_DND */
1374 break;
1375
1376 case MappingNotify:
1377 XRefreshKeyboardMapping (&ev.xmapping);
1378 break; 1390 break;
1379 1391
1380 /* 1392 /*
1381 * XXX: this is not the _current_ arrangement 1393 * XXX: this is not the _current_ arrangement
1382 * Here's my conclusion: 1394 * Here's my conclusion:
1401 break; 1413 break;
1402 } 1414 }
1403 break; 1415 break;
1404 1416
1405 case FocusIn: 1417 case FocusIn:
1418 if (ev.xfocus.detail != NotifyInferior
1419 && ev.xfocus.detail != NotifyPointer
1420 && ev.xfocus.mode != NotifyGrab)
1406 focus_in (); 1421 focus_in ();
1407 break; 1422 break;
1408 1423
1409 case FocusOut: 1424 case FocusOut:
1425 if (ev.xfocus.detail != NotifyInferior
1426 && ev.xfocus.detail != NotifyPointer
1427 && ev.xfocus.mode != NotifyGrab)
1410 focus_out (); 1428 focus_out ();
1411 break; 1429 break;
1412 1430
1413 case ConfigureNotify: 1431 case ConfigureNotify:
1432 /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1433 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1434 szHint.width, szHint.height); */
1414 if (ev.xconfigure.window == TermWin.parent[0]) 1435 if (ev.xconfigure.window == parent[0])
1415 { 1436 {
1416 int height, width;
1417
1418 do
1419 { /* Wrap lots of configures into one */
1420 width = ev.xconfigure.width;
1421 height = ev.xconfigure.height;
1422 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1423 }
1424 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); 1437 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1438 ;
1425 1439
1426 if (szHint.width != width || szHint.height != height) 1440 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1427 { 1441 {
1428 seen_resize = 1; 1442 seen_resize = 1;
1429 resize_all_windows (width, height, 1); 1443 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1430 } 1444 }
1431 1445 else
1432#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1446 {
1433 if (options & Opt_transparent) 1447#ifdef HAVE_BG_PIXMAP
1434 check_our_parents (); 1448 if (bgPixmap.window_position_sensitive ())
1449 update_background ();
1435#endif 1450#endif
1451 }
1452 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1436 } 1453 }
1437 break; 1454 break;
1438 1455
1439 case PropertyNotify: 1456 case PropertyNotify:
1457 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1440 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1458 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1441 && ev.xproperty.state == PropertyNewValue) 1459 && ev.xproperty.state == PropertyNewValue)
1442 selection_property (ev.xproperty.window, ev.xproperty.atom); 1460 selection_property (ev.xproperty.window, ev.xproperty.atom);
1443 1461
1444 break; 1462 break;
1445 1463
1446 case SelectionClear: 1464 case SelectionClear:
1447 selection_clear (); 1465 selection_clear ();
1454 1472
1455 case SelectionRequest: 1473 case SelectionRequest:
1456 selection_send (ev.xselectionrequest); 1474 selection_send (ev.xselectionrequest);
1457 break; 1475 break;
1458 1476
1477 case MapNotify:
1478 mapped = 1;
1479#ifdef TEXT_BLINK
1480 text_blink_ev.start (TEXT_BLINK_INTERVAL);
1481#endif
1482 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1483 break;
1484
1459 case UnmapNotify: 1485 case UnmapNotify:
1460 TermWin.mapped = 0; 1486 mapped = 0;
1461#ifdef TEXT_BLINK 1487#ifdef TEXT_BLINK
1462 text_blink_ev.stop (); 1488 text_blink_ev.stop ();
1463#endif 1489#endif
1490 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1464 break; 1491 break;
1465
1466 case MapNotify:
1467 TermWin.mapped = 1;
1468#ifdef TEXT_BLINK
1469 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1470#endif
1471 break;
1472
1473#ifdef TRANSPARENT
1474 case ReparentNotify:
1475 rootwin_cb (ev);
1476 break;
1477#endif /* TRANSPARENT */
1478 1492
1479 case GraphicsExpose: 1493 case GraphicsExpose:
1480 case Expose: 1494 case Expose:
1481 if (ev.xany.window == TermWin.vt) 1495 if (ev.xany.window == vt)
1482 { 1496 {
1483 do 1497 do
1498 {
1484 scr_expose (ev.xexpose.x, ev.xexpose.y, 1499 scr_expose (ev.xexpose.x, ev.xexpose.y,
1485 ev.xexpose.width, ev.xexpose.height, False); 1500 ev.xexpose.width, ev.xexpose.height, False);
1501 }
1486 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1502 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1487 1503
1488 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1504 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1489 1505
1490 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1506 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1507 {
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1508 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1509 ev.xexpose.width, ev.xexpose.height, False);
1493 1510 }
1494 scr_refresh (refresh_type); 1511 want_refresh = 1;
1495 } 1512 }
1496 else 1513 else
1497 { 1514 {
1498 XEvent unused_event; 1515 XEvent unused_event;
1499 1516
1500 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1517 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1501 ; 1518 ;
1502 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1519 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1503 ; 1520 ;
1504 1521
1505 if (isScrollbarWindow (ev.xany.window)) 1522 if (isScrollbarWindow (ev.xany.window))
1506 { 1523 {
1507 scrollBar.setIdle (); 1524 scrollBar.setIdle ();
1508 scrollbar_show (0); 1525 scrollbar_show (0);
1509 } 1526 }
1510#ifdef MENUBAR
1511 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1512 menubar_expose ();
1513#endif
1514
1515#ifdef TRANSPARENT
1516 if (am_transparent && ev.xany.window == TermWin.parent[0])
1517 XClearWindow (disp, ev.xany.window);
1518#endif
1519 } 1527 }
1520 break; 1528 break;
1521 1529
1522 case MotionNotify: 1530 case MotionNotify:
1523#ifdef POINTER_BLANK 1531#ifdef POINTER_BLANK
1524 if (hidden_pointer) 1532 if (hidden_pointer)
1525 pointer_unblank (); 1533 pointer_unblank ();
1526#endif 1534#endif
1527#if MENUBAR 1535 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1528 if (isMenuBarWindow (ev.xany.window)) 1536 || priv_modes & PrivMode_MouseAnyEvent)
1529 {
1530 menubar_control (ev.xbutton); 1537 mouse_report (ev.xbutton);
1531 break;
1532 }
1533#endif
1534 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1538 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1535 break; 1539 break;
1536 1540
1537 if (ev.xany.window == TermWin.vt) 1541 if (ev.xany.window == vt)
1538 { 1542 {
1543 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1544 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1545 ; // nop
1539 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1546 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1540 { 1547 {
1541 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1548 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1542 ; 1549 ;
1543 1550
1544 XQueryPointer (disp, TermWin.vt, 1551 XQueryPointer (dpy, vt,
1545 &unused_root, &unused_child, 1552 &unused_root, &unused_child,
1546 &unused_root_x, &unused_root_y, 1553 &unused_root_x, &unused_root_y,
1547 &ev.xbutton.x, &ev.xbutton.y, 1554 &ev.xbutton.x, &ev.xbutton.y,
1548 &ev.xbutton.state); 1555 &ev.xbutton.state);
1549#ifdef MOUSE_THRESHOLD 1556#ifdef MOUSE_THRESHOLD
1561#endif 1568#endif
1562 selection_extend (ev.xbutton.x, ev.xbutton.y, 1569 selection_extend (ev.xbutton.x, ev.xbutton.y,
1563 ev.xbutton.state & Button3Mask ? 2 : 0); 1570 ev.xbutton.state & Button3Mask ? 2 : 0);
1564 1571
1565#ifdef SELECTION_SCROLLING 1572#ifdef SELECTION_SCROLLING
1566 if (ev.xbutton.y < TermWin.int_bwidth 1573 if (ev.xbutton.y < int_bwidth
1567 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1574 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1568 { 1575 {
1569 int dist; 1576 int dist;
1570 1577
1571 /* don't clobber the current delay if we are 1578 /* don't clobber the current delay if we are
1572 * already in the middle of scrolling. 1579 * already in the middle of scrolling.
1573 */ 1580 */
1574 if (!sel_scroll_ev.active) 1581 if (!sel_scroll_ev.active)
1575 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1582 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1576 1583
1577 /* save the event params so we can highlight 1584 /* save the event params so we can highlight
1578 * the selection in the pending-scroll loop 1585 * the selection in the pending-scroll loop
1579 */ 1586 */
1580 selection_save_x = ev.xbutton.x; 1587 selection_save_x = ev.xbutton.x;
1581 selection_save_y = ev.xbutton.y; 1588 selection_save_y = ev.xbutton.y;
1582 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1589 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1583 1590
1584 /* calc number of lines to scroll */ 1591 /* calc number of lines to scroll */
1585 if (ev.xbutton.y < TermWin.int_bwidth) 1592 if (ev.xbutton.y < int_bwidth)
1586 { 1593 {
1587 scroll_selection_dir = UP; 1594 scroll_selection_dir = UP;
1588 dist = TermWin.int_bwidth - ev.xbutton.y; 1595 dist = int_bwidth - ev.xbutton.y;
1589 } 1596 }
1590 else 1597 else
1591 { 1598 {
1592 scroll_selection_dir = DN; 1599 scroll_selection_dir = DN;
1593 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1600 dist = ev.xbutton.y - (int_bwidth + height);
1594 } 1601 }
1595 1602
1596 scroll_selection_lines = Pixel2Height (dist) 1603 scroll_selection_lines = Pixel2Height (dist)
1597 / SELECTION_SCROLL_LINE_SPEEDUP 1604 / SELECTION_SCROLL_LINE_SPEEDUP
1598 + 1; 1605 + 1;
1599 MIN_IT (scroll_selection_lines, 1606 min_it (scroll_selection_lines,
1600 SELECTION_SCROLL_MAX_LINES); 1607 SELECTION_SCROLL_MAX_LINES);
1601 } 1608 }
1602 else 1609 else
1603 { 1610 {
1604 /* we are within the text window, so we 1611 /* we are within the text window, so we
1613#endif 1620#endif
1614 } 1621 }
1615 } 1622 }
1616 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1623 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1617 { 1624 {
1618 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1625 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1619 MotionNotify, &ev)) 1626 MotionNotify, &ev))
1620 ; 1627 ;
1621 1628
1622 XQueryPointer (disp, scrollBar.win, 1629 XQueryPointer (dpy, scrollBar.win,
1623 &unused_root, &unused_child, 1630 &unused_root, &unused_child,
1624 &unused_root_x, &unused_root_y, 1631 &unused_root_x, &unused_root_y,
1625 &ev.xbutton.x, &ev.xbutton.y, 1632 &ev.xbutton.x, &ev.xbutton.y,
1626 &unused_mask); 1633 &unused_mask);
1627 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1634 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1628 scrollbar_size ()); 1635 scrollbar_size ());
1629 scr_refresh (refresh_type);
1630 refresh_limit = 0; 1636 want_refresh = 1;
1631 scrollbar_show (1); 1637 scrollbar_show (1);
1632 } 1638 }
1633 break; 1639 break;
1634 } 1640 }
1641
1642#if defined(CURSOR_BLINK)
1643 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1644 {
1645 if (hidden_cursor)
1646 {
1647 hidden_cursor = 0;
1648 want_refresh = 1;
1649 }
1650
1651 cursor_blink_ev.again ();
1652 }
1653#endif
1654
1655#if defined(POINTER_BLANK)
1656 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1657 {
1658 if (ev.type == MotionNotify
1659 || ev.type == ButtonPress
1660 || ev.type == ButtonRelease)
1661 if (hidden_pointer)
1662 pointer_unblank ();
1663
1664 if (ev.type == KeyPress && hidden_pointer == 0)
1665 pointer_blank ();
1666 }
1667#endif
1635} 1668}
1636 1669
1637void 1670void
1638rxvt_term::focus_in () 1671rxvt_term::focus_in ()
1639{ 1672{
1640 if (!TermWin.focus) 1673 if (!focus)
1641 { 1674 {
1642 TermWin.focus = 1; 1675 focus = 1;
1643 want_refresh = 1; 1676 want_refresh = 1;
1677
1678 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1679
1644#ifdef USE_XIM 1680#if USE_XIM
1645 if (Input_Context != NULL) 1681 if (Input_Context != NULL)
1646 { 1682 {
1647 IMSetStatusPosition (); 1683 IMSetPosition ();
1648 XSetICFocus (Input_Context); 1684 XSetICFocus (Input_Context);
1649 } 1685 }
1650#endif 1686#endif
1651#ifdef CURSOR_BLINK 1687#if CURSOR_BLINK
1652 if (options & Opt_cursorBlink) 1688 if (option (Opt_cursorBlink))
1653 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1689 cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL);
1654#endif 1690#endif
1655#ifdef OFF_FOCUS_FADING 1691#if OFF_FOCUS_FADING
1656 if (rs[Rs_fade]) 1692 if (rs[Rs_fade])
1657 { 1693 {
1658 pix_colors = pix_colors_focused; 1694 pix_colors = pix_colors_focused;
1659 scr_recolour (); 1695 scr_recolour ();
1660 } 1696 }
1661#endif 1697#endif
1698#if ENABLE_FRILLS
1699 if (option (Opt_urgentOnBell))
1700 {
1701 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1702 {
1703 h->flags &= ~XUrgencyHint;
1704 XSetWMHints (dpy, parent[0], h);
1705 }
1706 }
1707#endif
1662 } 1708 }
1663} 1709}
1664 1710
1665void 1711void
1666rxvt_term::focus_out () 1712rxvt_term::focus_out ()
1667{ 1713{
1668 if (TermWin.focus) 1714 if (focus)
1669 { 1715 {
1670 TermWin.focus = 0; 1716 focus = 0;
1671 want_refresh = 1; 1717 want_refresh = 1;
1672 1718
1719 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1720
1673#if ENABLE_FRILLS || ISO_14755 1721#if ENABLE_FRILLS || ISO_14755
1722 if (iso14755buf)
1723 {
1674 iso14755buf = 0; 1724 iso14755buf = 0;
1675#endif 1725# if ISO_14755
1676#if ENABLE_OVERLAY
1677 scr_overlay_off (); 1726 scr_overlay_off ();
1678#endif 1727# endif
1728 }
1729#endif
1679#ifdef USE_XIM 1730#if USE_XIM
1680 if (Input_Context != NULL) 1731 if (Input_Context != NULL)
1681 XUnsetICFocus (Input_Context); 1732 XUnsetICFocus (Input_Context);
1682#endif 1733#endif
1683#ifdef CURSOR_BLINK 1734#if CURSOR_BLINK
1684 if (options & Opt_cursorBlink) 1735 if (option (Opt_cursorBlink))
1685 cursor_blink_ev.stop (); 1736 cursor_blink_ev.stop ();
1737
1686 hidden_cursor = 0; 1738 hidden_cursor = 0;
1687#endif 1739#endif
1688#ifdef OFF_FOCUS_FADING 1740#if OFF_FOCUS_FADING
1689 if (rs[Rs_fade]) 1741 if (rs[Rs_fade])
1690 { 1742 {
1691 pix_colors = pix_colors_unfocused; 1743 pix_colors = pix_colors_unfocused;
1692 scr_recolour (); 1744 scr_recolour ();
1693 } 1745 }
1694#endif 1746#endif
1695 } 1747 }
1696} 1748}
1697 1749
1698#if TRANSPARENT 1750void
1751rxvt_term::update_fade_color (unsigned int idx)
1752{
1753#if OFF_FOCUS_FADING
1754 if (rs[Rs_fade])
1755 {
1756 rgba c;
1757 pix_colors [Color_fade].get (c);
1758 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1759 }
1760#endif
1761}
1762
1763#if ENABLE_TRANSPARENCY || ENABLE_PERL
1699void 1764void
1700rxvt_term::rootwin_cb (XEvent &ev) 1765rxvt_term::rootwin_cb (XEvent &ev)
1701{ 1766{
1702 SET_R (this); 1767 make_current ();
1703 SET_LOCALE (locale);
1704 1768
1769 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1770 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1771 return;
1772
1773# if ENABLE_TRANSPARENCY
1705 switch (ev.type) 1774 switch (ev.type)
1706 { 1775 {
1707 case PropertyNotify: 1776 case PropertyNotify:
1708 /* 1777 /*
1709 * if user used some Esetroot compatible prog to set the root bg, 1778 * if user used some Esetroot compatible prog to set the root bg,
1710 * use the property to determine the pixmap. We use it later on. 1779 * use the property to determine the pixmap. We use it later on.
1711 */ 1780 */
1712 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1781 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1713 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1782 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1714 return; 1783 {
1715 1784 bgPixmap.set_root_pixmap ();
1716 /* FALLTHROUGH */ 1785 update_background ();
1717 case ReparentNotify: 1786 }
1718 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1719 want_refresh = want_full_refresh = 1;
1720 break; 1787 break;
1721 } 1788 }
1789# endif
1722} 1790}
1723#endif 1791#endif
1724 1792
1725void 1793void
1726rxvt_term::button_press (XButtonEvent &ev) 1794rxvt_term::button_press (XButtonEvent &ev)
1727{ 1795{
1728 int reportmode = 0, clickintime; 1796 int reportmode = 0, clickintime;
1729 1797
1730 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1798 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1799
1731 if (!bypass_keystate) 1800 if (!bypass_keystate)
1732 reportmode = !! (priv_modes & PrivMode_mouse_report); 1801 reportmode = !! (priv_modes & PrivMode_mouse_report);
1733 1802
1734 /* 1803 /*
1735 * VT window processing of button press 1804 * VT window processing of button press
1736 */ 1805 */
1737 if (ev.window == TermWin.vt) 1806 if (ev.window == vt)
1738 { 1807 {
1808 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1809 return;
1810
1739#if ISO_14755 1811#if ISO_14755
1740 // 5.4 1812 // 5.4
1741 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1813 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1742 { 1814 {
1743 iso14755_54 (ev.x, ev.y); 1815 iso14755_54 (ev.x, ev.y);
1755#ifdef MOUSE_REPORT_DOUBLECLICK 1827#ifdef MOUSE_REPORT_DOUBLECLICK
1756 if (ev.button == MEvent.button && clickintime) 1828 if (ev.button == MEvent.button && clickintime)
1757 { 1829 {
1758 /* same button, within alloted time */ 1830 /* same button, within alloted time */
1759 MEvent.clicks++; 1831 MEvent.clicks++;
1832
1760 if (MEvent.clicks > 1) 1833 if (MEvent.clicks > 1)
1761 { 1834 {
1762 /* only report double clicks */ 1835 /* only report double clicks */
1763 MEvent.clicks = 2; 1836 MEvent.clicks = 2;
1764 mouse_report (ev); 1837 mouse_report (ev);
1796#else 1869#else
1797 selection.rect = false; 1870 selection.rect = false;
1798#endif 1871#endif
1799 1872
1800 /* allow shift+left click to extend selection */ 1873 /* allow shift+left click to extend selection */
1801 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1874 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1802 { 1875 {
1803 if (MEvent.button == Button1 && clickintime) 1876 if (MEvent.button == Button1 && clickintime)
1804 selection_rotate (ev.x, ev.y); 1877 selection_rotate (ev.x, ev.y);
1805 else 1878 else
1806 selection_extend (ev.x, ev.y, 1); 1879 selection_extend (ev.x, ev.y, 1);
1902 upordown = 1; /* down */ 1975 upordown = 1; /* down */
1903 } 1976 }
1904 if (upordown) 1977 if (upordown)
1905 { 1978 {
1906#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1979#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1907 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1980 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1908#endif 1981#endif
1909 if (scr_page (upordown < 0 ? UP : DN, 1)) 1982 if (scr_page (upordown < 0 ? UP : DN, 1))
1910 { 1983 {
1911 if (upordown < 0) 1984 if (upordown < 0)
1912 scrollBar.setUp (); 1985 scrollBar.setUp ();
1947 case Button3: 2020 case Button3:
1948 if (scrollBar.style != R_SB_XTERM) 2021 if (scrollBar.style != R_SB_XTERM)
1949 { 2022 {
1950 if (scrollbar_above_slider (ev.y)) 2023 if (scrollbar_above_slider (ev.y))
1951# ifdef RXVT_SCROLL_FULL 2024# ifdef RXVT_SCROLL_FULL
1952 scr_page (UP, TermWin.nrow - 1); 2025 scr_page (UP, nrow - 1);
1953# else 2026# else
1954 scr_page (UP, TermWin.nrow / 4); 2027 scr_page (UP, nrow / 4);
1955# endif 2028# endif
1956 else if (scrollbar_below_slider (ev.y)) 2029 else if (scrollbar_below_slider (ev.y))
1957# ifdef RXVT_SCROLL_FULL 2030# ifdef RXVT_SCROLL_FULL
1958 scr_page (DN, TermWin.nrow - 1); 2031 scr_page (DN, nrow - 1);
1959# else 2032# else
1960 scr_page (DN, TermWin.nrow / 4); 2033 scr_page (DN, nrow / 4);
1961# endif 2034# endif
1962 else 2035 else
1963 scrollBar.setMotion (); 2036 scrollBar.setMotion ();
1964 } 2037 }
1965 else 2038 else
1966 { 2039 {
1967 scr_page ((ev.button == Button1 ? DN : UP), 2040 scr_page ((ev.button == Button1 ? DN : UP),
1968 (TermWin.nrow 2041 (nrow
1969 * scrollbar_position (ev.y) 2042 * scrollbar_position (ev.y)
1970 / scrollbar_size ())); 2043 / scrollbar_size ()));
1971 } 2044 }
1972 2045
1973 break; 2046 break;
1974 } 2047 }
1975 } 2048 }
2049
1976 return; 2050 return;
1977 } 2051 }
1978#if MENUBAR
1979 /*
1980 * Menubar window processing of button press
1981 */
1982 if (isMenuBarWindow (ev.window))
1983 menubar_control (ev);
1984#endif
1985} 2052}
1986 2053
1987void 2054void
1988rxvt_term::button_release (XButtonEvent &ev) 2055rxvt_term::button_release (XButtonEvent &ev)
1989{ 2056{
1995 2062
1996 if (scrollbar_isUpDn ()) 2063 if (scrollbar_isUpDn ())
1997 { 2064 {
1998 scrollBar.setIdle (); 2065 scrollBar.setIdle ();
1999 scrollbar_show (0); 2066 scrollbar_show (0);
2000#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2001 refresh_type &= ~SMOOTH_REFRESH;
2002#endif
2003 } 2067 }
2004 2068
2005#ifdef SELECTION_SCROLLING 2069#ifdef SELECTION_SCROLLING
2006 if (sel_scroll_ev.active) 2070 if (sel_scroll_ev.active)
2007 sel_scroll_ev.stop(); 2071 sel_scroll_ev.stop();
2008#endif 2072#endif
2009 2073
2010 if (ev.window == TermWin.vt) 2074 if (ev.window == vt)
2011 { 2075 {
2076 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2077 return;
2078
2012#if ISO_14755 2079#if ISO_14755
2013 // 5.4 2080 // 5.4
2014 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2081 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2015 return; 2082 return;
2016#endif 2083#endif
2084
2017 if (reportmode) 2085 if (reportmode)
2018 { 2086 {
2019 /* mouse report from vt window */ 2087 /* mouse report from vt window */
2020 /* don't report release of wheel "buttons" */ 2088 /* don't report release of wheel "buttons" */
2021 if (ev.button >= 4) 2089 if (ev.button >= 4)
2051 { 2119 {
2052 case Button1: 2120 case Button1:
2053 case Button3: 2121 case Button3:
2054 selection_make (ev.time); 2122 selection_make (ev.time);
2055 break; 2123 break;
2124
2056 case Button2: 2125 case Button2:
2057 selection_request (ev.time, ev.x, ev.y); 2126 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2127 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2058 break; 2128 break;
2129
2059#ifdef MOUSE_WHEEL 2130#ifdef MOUSE_WHEEL
2060 case Button4: 2131 case Button4:
2061 case Button5: 2132 case Button5:
2062 { 2133 {
2063 int i; 2134 int i;
2065 2136
2066 v = ev.button == Button4 ? UP : DN; 2137 v = ev.button == Button4 ? UP : DN;
2067 2138
2068 if (ev.state & ShiftMask) 2139 if (ev.state & ShiftMask)
2069 i = 1; 2140 i = 1;
2070 else if (options & Opt_mouseWheelScrollPage) 2141 else if (option (Opt_mouseWheelScrollPage))
2071 i = TermWin.nrow - 1; 2142 i = nrow - 1;
2072 else 2143 else
2073 i = 5; 2144 i = 5;
2074 2145
2075# ifdef MOUSE_SLIP_WHEELING 2146# ifdef MOUSE_SLIP_WHEELING
2076 if (ev.state & ControlMask) 2147 if (ev.state & ControlMask)
2077 { 2148 {
2078 mouse_slip_wheel_speed += v ? -1 : 1; 2149 mouse_slip_wheel_speed += v ? -1 : 1;
2079 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2150 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2080 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; 2151 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2081 2152
2082 if (slip_wheel_ev.at < NOW) 2153 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2083 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2084
2085 slip_wheel_ev.start ();
2086 } 2154 }
2087 else 2155 else
2088 { 2156 {
2089# endif 2157# endif
2090# ifdef JUMP_MOUSE_WHEEL
2091 scr_page (v, i); 2158 scr_page (v, i);
2092 scr_refresh (SMOOTH_REFRESH);
2093 scrollbar_show (1); 2159 scrollbar_show (1);
2094# else
2095 while (i--)
2096 {
2097 scr_page (v, 1);
2098 scr_refresh (SMOOTH_REFRESH);
2099 scrollbar_show (1);
2100 }
2101# endif
2102# ifdef MOUSE_SLIP_WHEELING 2160# ifdef MOUSE_SLIP_WHEELING
2103 } 2161 }
2104#endif 2162# endif
2105 } 2163 }
2106 break; 2164 break;
2107#endif 2165#endif
2108 } 2166 }
2109 } 2167 }
2110#ifdef MENUBAR
2111 else if (isMenuBarWindow (ev.window))
2112 menubar_control (ev);
2113#endif
2114} 2168}
2115
2116#ifdef TRANSPARENT
2117#if TINTING
2118/* taken from aterm-0.4.2 */
2119
2120typedef uint32_t RUINT32T;
2121
2122void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2123{
2124 int sh_r, sh_g, sh_b;
2125 RUINT32T mask_r, mask_g, mask_b;
2126 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2127 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2128 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2129 int i;
2130
2131 Visual *visual = display->visual;
2132
2133 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2134
2135 /* for convenience */
2136 mask_r = visual->red_mask;
2137 mask_g = visual->green_mask;
2138 mask_b = visual->blue_mask;
2139
2140 /* boring lookup table pre-initialization */
2141 switch (srcImage->bits_per_pixel) {
2142 case 15:
2143 if ((mask_r != 0x7c00) ||
2144 (mask_g != 0x03e0) ||
2145 (mask_b != 0x001f))
2146 return;
2147 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2148 lookup_r = lookup;
2149 lookup_g = lookup+32;
2150 lookup_b = lookup+32+32;
2151 sh_r = 10;
2152 sh_g = 5;
2153 sh_b = 0;
2154 break;
2155 case 16:
2156 if ((mask_r != 0xf800) ||
2157 (mask_g != 0x07e0) ||
2158 (mask_b != 0x001f))
2159 return;
2160 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2161 lookup_r = lookup;
2162 lookup_g = lookup+32;
2163 lookup_b = lookup+32+64;
2164 sh_r = 11;
2165 sh_g = 5;
2166 sh_b = 0;
2167 break;
2168 case 24:
2169 if ((mask_r != 0xff0000) ||
2170 (mask_g != 0x00ff00) ||
2171 (mask_b != 0x0000ff))
2172 return;
2173 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2174 lookup_r = lookup;
2175 lookup_g = lookup+256;
2176 lookup_b = lookup+256+256;
2177 sh_r = 16;
2178 sh_g = 8;
2179 sh_b = 0;
2180 break;
2181 case 32:
2182 if ((mask_r != 0xff0000) ||
2183 (mask_g != 0x00ff00) ||
2184 (mask_b != 0x0000ff))
2185 return;
2186 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2187 lookup_r = lookup;
2188 lookup_g = lookup+256;
2189 lookup_b = lookup+256+256;
2190 sh_r = 16;
2191 sh_g = 8;
2192 sh_b = 0;
2193 break;
2194 default:
2195 return; /* we do not support this color depth */
2196 }
2197
2198 /* prepare limits for color transformation (each channel is handled separately) */
2199 if (shade < 0) {
2200 shade = -shade;
2201 if (shade < 0) shade = 0;
2202 if (shade > 100) shade = 100;
2203
2204 lower_lim_r = 65535-rm;
2205 lower_lim_g = 65535-gm;
2206 lower_lim_b = 65535-bm;
2207
2208 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2209 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2210 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2211
2212 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2213 } else {
2214 if (shade < 0) shade = 0;
2215 if (shade > 100) shade = 100;
2216
2217 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2218
2219 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2220 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2221 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2222 }
2223
2224 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2225 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2226 {
2227 unsigned int tmp;
2228
2229 tmp = lower_lim_r;
2230 lower_lim_r = lower_lim_b;
2231 lower_lim_b = tmp;
2232
2233 tmp = upper_lim_r;
2234 upper_lim_r = upper_lim_b;
2235 upper_lim_b = tmp;
2236 }
2237
2238 /* fill our lookup tables */
2239 for (i = 0; i <= mask_r>>sh_r; i++)
2240 {
2241 RUINT32T tmp;
2242 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2243 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2244 lookup_r[i] = (tmp/65535)<<sh_r;
2245 }
2246 for (i = 0; i <= mask_g>>sh_g; i++)
2247 {
2248 RUINT32T tmp;
2249 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2250 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2251 lookup_g[i] = (tmp/65535)<<sh_g;
2252 }
2253 for (i = 0; i <= mask_b>>sh_b; i++)
2254 {
2255 RUINT32T tmp;
2256 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2257 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2258 lookup_b[i] = (tmp/65535)<<sh_b;
2259 }
2260
2261 /* apply table to input image (replacing colors by newly calculated ones) */
2262 switch (srcImage->bits_per_pixel)
2263 {
2264 case 15:
2265 {
2266 unsigned short *p1, *pf, *p, *pl;
2267 p1 = (unsigned short *) srcImage->data;
2268 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2269 while (p1 < pf)
2270 {
2271 p = p1;
2272 pl = p1 + srcImage->width;
2273 for (; p < pl; p++)
2274 {
2275 *p = lookup_r[(*p & 0x7c00)>>10] |
2276 lookup_g[(*p & 0x03e0)>> 5] |
2277 lookup_b[(*p & 0x001f)];
2278 }
2279 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2280 }
2281 break;
2282 }
2283 case 16:
2284 {
2285 unsigned short *p1, *pf, *p, *pl;
2286 p1 = (unsigned short *) srcImage->data;
2287 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2288 while (p1 < pf)
2289 {
2290 p = p1;
2291 pl = p1 + srcImage->width;
2292 for (; p < pl; p++)
2293 {
2294 *p = lookup_r[(*p & 0xf800)>>11] |
2295 lookup_g[(*p & 0x07e0)>> 5] |
2296 lookup_b[(*p & 0x001f)];
2297 }
2298 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2299 }
2300 break;
2301 }
2302 case 24:
2303 {
2304 unsigned char *p1, *pf, *p, *pl;
2305 p1 = (unsigned char *) srcImage->data;
2306 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2307 while (p1 < pf)
2308 {
2309 p = p1;
2310 pl = p1 + srcImage->width * 3;
2311 for (; p < pl; p += 3)
2312 {
2313 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2314 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2315 p[2] = lookup_r[(p[2] & 0x0000ff)];
2316 }
2317 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2318 }
2319 break;
2320 }
2321 case 32:
2322 {
2323 RUINT32T *p1, *pf, *p, *pl;
2324 p1 = (RUINT32T *) srcImage->data;
2325 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2326
2327 while (p1 < pf)
2328 {
2329 p = p1;
2330 pl = p1 + srcImage->width;
2331 for (; p < pl; p++)
2332 {
2333 *p = lookup_r[(*p & 0xff0000)>>16] |
2334 lookup_g[(*p & 0x00ff00)>> 8] |
2335 lookup_b[(*p & 0x0000ff)] |
2336 (*p & ~0xffffff);
2337 }
2338 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2339 }
2340 break;
2341 }
2342 }
2343
2344 free (lookup);
2345}
2346#endif
2347
2348/*
2349 * Check our parents are still who we think they are.
2350 * Do transparency updates if required
2351 */
2352int
2353rxvt_term::check_our_parents ()
2354{
2355 int i, pchanged, aformat, have_pixmap, rootdepth;
2356 unsigned long nitems, bytes_after;
2357 Atom atype;
2358 unsigned char *prop = NULL;
2359 Window root, oldp, *list;
2360 Pixmap rootpixmap = None;
2361 XWindowAttributes wattr, wrootattr;
2362 dDisp;
2363
2364 pchanged = 0;
2365
2366 if (!(options & Opt_transparent))
2367 return pchanged; /* Don't try any more */
2368
2369 XGetWindowAttributes (disp, display->root, &wrootattr);
2370 rootdepth = wrootattr.depth;
2371
2372 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2373
2374 if (rootdepth != wattr.depth)
2375 {
2376 if (am_transparent)
2377 {
2378 pchanged = 1;
2379 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2380 am_transparent = am_pixmap_trans = 0;
2381 }
2382
2383 return pchanged; /* Don't try any more */
2384 }
2385
2386 /* Get all X ops out of the queue so that our information is up-to-date. */
2387 XSync (disp, False);
2388
2389 /*
2390 * Make the frame window set by the window manager have
2391 * the root background. Some window managers put multiple nested frame
2392 * windows for each client, so we have to take care about that.
2393 */
2394 i = (xa[XA_XROOTPMAP_ID]
2395 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2396 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2397 &nitems, &bytes_after, &prop) == Success);
2398
2399 if (!i || prop == NULL)
2400 i = (xa[XA_ESETROOT_PMAP_ID]
2401 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2402 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2403 &nitems, &bytes_after, &prop) == Success);
2404
2405 if (!i || prop == NULL
2406#if TINTING
2407 || !rs[Rs_color + Color_tint]
2408#endif
2409 )
2410 have_pixmap = 0;
2411 else
2412 {
2413 have_pixmap = 1;
2414 rootpixmap = *(Pixmap *)prop;
2415 XFree (prop);
2416 }
2417
2418 if (have_pixmap)
2419 {
2420 /*
2421 * Copy display->root pixmap transparency
2422 */
2423 int sx, sy, nx, ny;
2424 unsigned int nw, nh;
2425 Window cr;
2426 XImage *image;
2427 GC gc;
2428 XGCValues gcvalue;
2429
2430 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2431 0, 0, &sx, &sy, &cr);
2432 nw = (unsigned int)szHint.width;
2433 nh = (unsigned int)szHint.height;
2434 nx = ny = 0;
2435
2436 if (sx < 0)
2437 {
2438 nw += sx;
2439 nx = -sx;
2440 sx = 0;
2441 }
2442
2443 if (sy < 0)
2444 {
2445 nh += sy;
2446 ny = -sy;
2447 sy = 0;
2448 }
2449
2450 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2451 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2452
2453 XSync (disp, False);
2454 allowedxerror = -1;
2455 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2456
2457 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2458 /* XXX: may need a delay here? */
2459 allowedxerror = 0;
2460
2461 if (image == NULL)
2462 {
2463 if (am_transparent && am_pixmap_trans)
2464 {
2465 pchanged = 1;
2466 if (TermWin.pixmap != None)
2467 {
2468 XFreePixmap (disp, TermWin.pixmap);
2469 TermWin.pixmap = None;
2470 }
2471 }
2472
2473 am_pixmap_trans = 0;
2474 }
2475 else
2476 {
2477 if (TermWin.pixmap != None)
2478 XFreePixmap (disp, TermWin.pixmap);
2479
2480#if TINTING
2481 if (ISSET_PIXCOLOR (Color_tint))
2482 {
2483 unsigned short rm, gm, bm;
2484 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2485
2486 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2487
2488 ShadeXImage (display, image, shade, rm, gm, bm);
2489 }
2490#endif
2491
2492 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2493 szHint.width, szHint.height, image->depth);
2494 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2495 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2496 nx, ny, image->width, image->height);
2497 XFreeGC (disp, gc);
2498 XDestroyImage (image);
2499 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2500 XClearWindow (disp, TermWin.parent[0]);
2501
2502 if (!am_transparent || !am_pixmap_trans)
2503 pchanged = 1;
2504
2505 am_transparent = am_pixmap_trans = 1;
2506 }
2507 }
2508
2509 if (am_pixmap_trans)
2510 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2511 else
2512 {
2513 unsigned int n;
2514 /*
2515 * InheritPixmap transparency
2516 */
2517 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2518 {
2519 oldp = TermWin.parent[i];
2520 XQueryTree (disp, TermWin.parent[i - 1], &root,
2521 &TermWin.parent[i], &list, &n);
2522 XFree (list);
2523
2524 if (TermWin.parent[i] == display->root)
2525 {
2526 if (oldp != None)
2527 pchanged = 1;
2528
2529 break;
2530 }
2531
2532 if (oldp != TermWin.parent[i])
2533 pchanged = 1;
2534 }
2535
2536 n = 0;
2537
2538 if (pchanged)
2539 {
2540 for (; n < (unsigned int)i; n++)
2541 {
2542 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2543 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2544 {
2545 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2546 break;
2547 }
2548 }
2549 }
2550
2551 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2552 {
2553 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2554 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2555 am_transparent = 0;
2556 /* XXX: also turn off Opt_transparent? */
2557 }
2558 else
2559 {
2560#if WAIT_FOR_WM
2561 /* wait (an arbitrary period) for the WM to do its thing
2562 * needed for fvwm2.2.2 (and before?) */
2563 sleep (1);
2564#endif
2565 for (n = 0; n < (unsigned int)i; n++)
2566 {
2567 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2568 XClearWindow (disp, TermWin.parent[n]);
2569 }
2570
2571 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2572 am_transparent = 1;
2573 }
2574
2575 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2576 TermWin.parent[i] = None;
2577 }
2578
2579 if (scrollBar.win)
2580 {
2581 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2582 scrollBar.setIdle ();
2583 scrollbar_show (0);
2584 }
2585
2586 if (am_transparent)
2587 {
2588 want_refresh = want_full_refresh = 1;
2589 if (am_pixmap_trans)
2590 flush ();
2591 }
2592
2593 return pchanged;
2594}
2595#endif
2596 2169
2597/*}}} */ 2170/*}}} */
2598 2171
2599bool 2172bool
2600rxvt_term::cmd_parse () 2173rxvt_term::cmd_parse ()
2601{ 2174{
2602 bool flag = false; 2175 bool flag = false;
2603 unicode_t ch = NOCHAR; 2176 wchar_t ch = NOCHAR;
2604 unsigned char *seq_begin; // remember start of esc-sequence here 2177 char *seq_begin; // remember start of esc-sequence here
2605 2178
2606 for (;;) 2179 for (;;)
2607 { 2180 {
2608 if (ch == NOCHAR) 2181 if (ch == NOCHAR)
2609 { 2182 {
2610 seq_begin = cmdbuf_ptr; 2183 seq_begin = cmdbuf_ptr;
2611 ch = next_char (); 2184 ch = next_char ();
2612 }
2613 2185
2614 if (ch == NOCHAR) // TODO: improve 2186 if (ch == NOCHAR)
2615 break; 2187 break;
2188 }
2616 2189
2617 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2190 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2618 { 2191 {
2619 if (!seen_input) 2192 if (!seen_input)
2620 { 2193 {
2629 if (seen_resize && cmd_pid) 2202 if (seen_resize && cmd_pid)
2630 kill (-cmd_pid, SIGWINCH); 2203 kill (-cmd_pid, SIGWINCH);
2631 } 2204 }
2632 2205
2633 /* Read a text string from the input buffer */ 2206 /* Read a text string from the input buffer */
2634 unicode_t buf[UBUFSIZ]; 2207 wchar_t buf[UBUFSIZ];
2635 bool refreshnow = false; 2208 bool refreshnow = false;
2636 int nlines = 0; 2209 int nlines = 0;
2637 unicode_t *str = buf; 2210 wchar_t *str = buf;
2211 wchar_t *eol = str + min (ncol, UBUFSIZ);
2638 2212
2639 for (;;) 2213 for (;;)
2640 { 2214 {
2641 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2215 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2642 break; 2216 break;
2643 2217
2644 *str++ = ch; 2218 *str++ = ch;
2645 2219
2646 if (ch == C0_LF) 2220 if (ch == C0_LF || str >= eol)
2647 { 2221 {
2222 if (ch == C0_LF)
2648 nlines++; 2223 nlines++;
2224
2649 refresh_count++; 2225 refresh_count++;
2650 2226
2651 if (!(options & Opt_jumpScroll) 2227 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2652 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2653 { 2228 {
2229 refresh_count = 0;
2230
2231 if (!option (Opt_skipScroll) || ev::ev_time () > ev::now () + 1. / 60.)
2232 {
2654 refreshnow = true; 2233 refreshnow = true;
2655 ch = NOCHAR; 2234 ch = NOCHAR;
2656 break; 2235 break;
2236 }
2657 } 2237 }
2658 2238
2659 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2239 // scr_add_lines only works for nlines <= nrow - 1.
2660 if (nlines >= TermWin.nrow - 1) 2240 if (nlines >= nrow - 1)
2661 { 2241 {
2242 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2243 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2662 scr_add_lines (buf, nlines, str - buf); 2244 scr_add_lines (buf, str - buf, nlines);
2245
2663 nlines = 0; 2246 nlines = 0;
2664 str = buf; 2247 str = buf;
2248 eol = str + min (ncol, UBUFSIZ);
2665 } 2249 }
2666 }
2667 2250
2668 if (str >= buf + UBUFSIZ) 2251 if (str >= eol)
2669 { 2252 {
2253 if (eol >= buf + UBUFSIZ)
2254 {
2670 ch = NOCHAR; 2255 ch = NOCHAR;
2671 break; 2256 break;
2257 }
2258 else
2259 eol = min (eol + ncol, buf + UBUFSIZ);
2260 }
2261
2672 } 2262 }
2673 2263
2674 seq_begin = cmdbuf_ptr; 2264 seq_begin = cmdbuf_ptr;
2675 ch = next_char (); 2265 ch = next_char ();
2676 } 2266 }
2677 2267
2268 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2269 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2678 scr_add_lines (buf, nlines, str - buf); 2270 scr_add_lines (buf, str - buf, nlines);
2679 2271
2680 /* 2272 /*
2681 * If there have been a lot of new lines, then update the screen 2273 * If there have been a lot of new lines, then update the screen
2682 * What the heck I'll cheat and only refresh less than every page-full. 2274 * What the heck we'll cheat and only refresh less than every page-full.
2683 * the number of pages between refreshes is refresh_limit, which 2275 * if skipScroll is enabled.
2684 * is incremented here because we must be doing flat-out scrolling.
2685 */ 2276 */
2686 if (refreshnow) 2277 if (refreshnow)
2687 { 2278 {
2688 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2689 refresh_limit++;
2690 else
2691 {
2692 flag = true; 2279 flag = true;
2693 scr_refresh (refresh_type); 2280 scr_refresh ();
2694 } 2281 want_refresh = 1;
2695 } 2282 }
2696 2283
2697 } 2284 }
2698 else 2285 else
2699 { 2286 {
2713 } 2300 }
2714 2301
2715 return flag; 2302 return flag;
2716} 2303}
2717 2304
2718// read the next octet
2719unicode_t
2720rxvt_term::next_octet ()
2721{
2722 return cmdbuf_ptr < cmdbuf_endp
2723 ? *cmdbuf_ptr++
2724 : NOCHAR;
2725}
2726
2727// read the next character 2305// read the next character
2728unicode_t 2306wchar_t
2729rxvt_term::next_char () 2307rxvt_term::next_char () NOTHROW
2730{ 2308{
2731 while (cmdbuf_ptr < cmdbuf_endp) 2309 while (cmdbuf_ptr < cmdbuf_endp)
2732 { 2310 {
2733 // assume 7-bit to be ascii ALWAYS 2311 // assume 7-bit to be ascii ALWAYS
2734 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2312 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2735 return *cmdbuf_ptr++; 2313 return *cmdbuf_ptr++;
2736 2314
2737 wchar_t wc; 2315 wchar_t wc;
2738 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2316 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2739 2317
2740 if (len == (size_t)-2) 2318 if (len == (size_t)-2)
2741 { 2319 {
2742 // the mbstate stores incomplete sequences. didn't know this :/ 2320 // the mbstate stores incomplete sequences. didn't know this :/
2743 cmdbuf_ptr = cmdbuf_endp; 2321 cmdbuf_ptr = cmdbuf_endp;
2744 break; 2322 break;
2745 } 2323 }
2746 2324
2747 if (len == (size_t)-1) 2325 if (len == (size_t)-1)
2748 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2326 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2749 2327
2750 // assume wchar == unicode 2328 // assume wchar == unicode
2751 cmdbuf_ptr += len; 2329 cmdbuf_ptr += len;
2752 return wc & UNICODE_MASK; 2330 return wc & UNICODE_MASK;
2753 } 2331 }
2754 2332
2755 return NOCHAR; 2333 return NOCHAR;
2756} 2334}
2335
2336// read the next octet
2337uint32_t
2338rxvt_term::next_octet () NOTHROW
2339{
2340 return cmdbuf_ptr < cmdbuf_endp
2341 ? (unsigned char)*cmdbuf_ptr++
2342 : NOCHAR;
2343}
2344
2345static class out_of_input out_of_input;
2757 2346
2758/* rxvt_cmd_getc () - Return next input character */ 2347/* rxvt_cmd_getc () - Return next input character */
2759/* 2348/*
2760 * Return the next input character after first passing any keyboard input 2349 * Return the next input character after first passing any keyboard input
2761 * to the command. 2350 * to the command.
2762 */ 2351 */
2763unicode_t 2352wchar_t
2764rxvt_term::cmd_getc () 2353rxvt_term::cmd_getc () THROW ((class out_of_input))
2765{ 2354{
2766 unicode_t c = next_char (); 2355 wchar_t c = next_char ();
2767 2356
2768 if (c == NOCHAR) 2357 if (c == NOCHAR)
2769 throw out_of_input; 2358 throw out_of_input;
2770 2359
2771 return c; 2360 return c;
2772} 2361}
2773 2362
2774unicode_t 2363uint32_t
2775rxvt_term::cmd_get8 () 2364rxvt_term::cmd_get8 () THROW ((class out_of_input))
2776{ 2365{
2777 unicode_t c = next_octet (); 2366 uint32_t c = next_octet ();
2778 2367
2779 if (c == NOCHAR) 2368 if (c == NOCHAR)
2780 throw out_of_input; 2369 throw out_of_input;
2781 2370
2782 return c; 2371 return c;
2846 { 2435 {
2847 if ((buf[len++] = cmd_getc ()) == 'i') 2436 if ((buf[len++] = cmd_getc ()) == 'i')
2848 break; /* done = 1 */ 2437 break; /* done = 1 */
2849 } 2438 }
2850 } 2439 }
2851 2440
2852 for (i = 0; i < len; i++) 2441 for (i = 0; i < len; i++)
2853 if (putc (buf[i], fd) == EOF) 2442 if (putc (buf[i], fd) == EOF)
2854 { 2443 {
2855 done = 1; 2444 done = 1;
2856 break; 2445 break;
2882 case C0_ESC: 2471 case C0_ESC:
2883 process_escape_seq (); 2472 process_escape_seq ();
2884 break; 2473 break;
2885 case C0_ENQ: /* terminal Status */ 2474 case C0_ENQ: /* terminal Status */
2886 if (rs[Rs_answerbackstring]) 2475 if (rs[Rs_answerbackstring])
2887 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2476 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2888 (unsigned int)strlen (rs[Rs_answerbackstring]));
2889 else 2477 else
2890 tt_write ((unsigned char *)VT100_ANS, 2478 tt_write (VT100_ANS, strlen (VT100_ANS));
2891 (unsigned int)strlen (VT100_ANS));
2892 break; 2479 break;
2893 case C0_BEL: /* bell */ 2480 case C0_BEL: /* bell */
2894 scr_bell (); 2481 scr_bell ();
2895 break; 2482 break;
2896 case C0_BS: /* backspace */ 2483 case C0_BS: /* backspace */
2920 process_dcs_seq (); 2507 process_dcs_seq ();
2921 break; 2508 break;
2922 case 0x9b: /* CSI */ 2509 case 0x9b: /* CSI */
2923 process_csi_seq (); 2510 process_csi_seq ();
2924 break; 2511 break;
2925 case 0x9d: /* CSI */ 2512 case 0x9d: /* OSC */
2926 process_osc_seq (); 2513 process_osc_seq ();
2927 break; 2514 break;
2928#endif 2515#endif
2929 } 2516 }
2930} 2517}
3020 scr_charset_set (2, (unsigned int)cmd_getc ()); 2607 scr_charset_set (2, (unsigned int)cmd_getc ());
3021 break; 2608 break;
3022 case '+': 2609 case '+':
3023 scr_charset_set (3, (unsigned int)cmd_getc ()); 2610 scr_charset_set (3, (unsigned int)cmd_getc ());
3024 break; 2611 break;
3025#if ENABLE_FRILLS 2612#if !ENABLE_MINIMAL
3026 case '6': 2613 case '6':
3027 scr_backindex (); 2614 scr_backindex ();
3028 break; 2615 break;
3029#endif 2616#endif
3030 case '7': 2617 case '7':
3031 scr_cursor (SAVE); 2618 scr_cursor (SAVE);
3032 break; 2619 break;
3033 case '8': 2620 case '8':
3034 scr_cursor (RESTORE); 2621 scr_cursor (RESTORE);
3035 break; 2622 break;
3036#if ENABLE_FRILLS 2623#if !ENABLE_MINIMAL
3037 case '9': 2624 case '9':
3038 scr_forwardindex (); 2625 scr_forwardindex ();
3039 break; 2626 break;
3040#endif 2627#endif
3041 case '=': 2628 case '=':
3051 break; 2638 break;
3052 2639
3053 /* 8.3.87: NEXT LINE */ 2640 /* 8.3.87: NEXT LINE */
3054 case C1_NEL: /* ESC E */ 2641 case C1_NEL: /* ESC E */
3055 { 2642 {
3056 unicode_t nlcr[] = { C0_LF, C0_CR }; 2643 wchar_t nlcr[] = { C0_LF, C0_CR };
3057 scr_add_lines (nlcr, 1, 2); 2644 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3058 } 2645 }
3059 break; 2646 break;
3060 2647
3061 /* kidnapped escape sequence: Should be 8.3.48 */ 2648 /* kidnapped escape sequence: Should be 8.3.48 */
3062 case C1_ESA: /* ESC G */ 2649 case C1_ESA: /* ESC G */
3084 process_dcs_seq (); 2671 process_dcs_seq ();
3085 break; 2672 break;
3086 2673
3087 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2674 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3088 case C1_SCI: /* ESC Z */ 2675 case C1_SCI: /* ESC Z */
3089 tt_write ((const unsigned char *)ESCZ_ANSWER, 2676 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3090 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3091 break; /* steal obsolete ESC [ c */ 2677 break; /* steal obsolete ESC [ c */
3092 2678
3093 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2679 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3094 case C1_CSI: /* ESC [ */ 2680 case C1_CSI: /* ESC [ */
3095 process_csi_seq (); 2681 process_csi_seq ();
3157rxvt_term::process_csi_seq () 2743rxvt_term::process_csi_seq ()
3158{ 2744{
3159 unicode_t ch, priv, i; 2745 unicode_t ch, priv, i;
3160 unsigned int nargs, p; 2746 unsigned int nargs, p;
3161 int n, ndef; 2747 int n, ndef;
3162 int arg[ESC_ARGS]; 2748 int arg[ESC_ARGS] = { };
3163 2749
3164 for (nargs = ESC_ARGS; nargs > 0;) 2750 nargs = 0;
3165 arg[--nargs] = 0;
3166 2751
3167 priv = 0; 2752 priv = 0;
3168 ch = cmd_getc (); 2753 ch = cmd_getc ();
3169 if (ch >= '<' && ch <= '?') 2754 if (ch >= '<' && ch <= '?')
3170 { /* '<' '=' '>' '?' */ 2755 { /* '<' '=' '>' '?' */
3204 ndef = get_byte_array_bit (csi_defaults, i); 2789 ndef = get_byte_array_bit (csi_defaults, i);
3205 for (p = 0; p < nargs; p++) 2790 for (p = 0; p < nargs; p++)
3206 if (arg[p] == -1) 2791 if (arg[p] == -1)
3207 arg[p] = ndef; 2792 arg[p] = ndef;
3208 2793
3209#ifdef DEBUG_CMD
3210 fprintf (stderr, "CSI ");
3211 for (p = 0; p < nargs; p++)
3212 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3213 fprintf (stderr, "%c\n", ch);
3214#endif
3215
3216 /* 2794 /*
3217 * private mode handling 2795 * private mode handling
3218 */ 2796 */
3219 if (priv) 2797 if (priv)
3220 { 2798 {
3221 switch (priv) 2799 switch (priv)
3222 { 2800 {
3223 case '>': 2801 case '>':
3224 if (ch == CSI_DA) /* secondary device attributes */ 2802 if (ch == CSI_DA) /* secondary device attributes */
3225 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2803 {
2804 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2805 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2806 //
2807 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2808 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2809 // versions.
2810 //
2811 tt_printf ("\033[>%d;95;0c", 'U');
2812 }
3226 break; 2813 break;
3227 case '?': 2814 case '?':
3228 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2815 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3229 process_terminal_mode (ch, priv, nargs, arg); 2816 process_terminal_mode (ch, priv, nargs, arg);
3230 break; 2817 break;
3335 2922
3336 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 2923 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3337 arg[0] = -arg[0]; 2924 arg[0] = -arg[0];
3338 /* FALLTHROUGH */ 2925 /* FALLTHROUGH */
3339 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2926 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3340 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 2927 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3341 break; 2928 break;
3342 2929
3343 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 2930 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3344 tt_write ((const unsigned char *)VT100_ANS, 2931 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3345 (unsigned int) (sizeof (VT100_ANS) - 1));
3346 break; 2932 break;
3347 2933
3348 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 2934 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3349 process_sgr_mode (nargs, arg); 2935 process_sgr_mode (nargs, arg);
3350 break; 2936 break;
3357 break; 2943 break;
3358 case 6: /* CPR requested */ 2944 case 6: /* CPR requested */
3359 scr_report_position (); 2945 scr_report_position ();
3360 break; 2946 break;
3361 case 7: /* unofficial extension */ 2947 case 7: /* unofficial extension */
3362 if (options & Opt_insecure) 2948 if (option (Opt_insecure))
3363 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2949 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3364 break; 2950 break;
3365 case 8: /* unofficial extension */ 2951 case 8: /* unofficial extension */
3366 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2952 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3367 break; 2953 break;
3434 break; 3020 break;
3435 case CSI_75: 3021 case CSI_75:
3436 scr_cursor (RESTORE); 3022 scr_cursor (RESTORE);
3437 break; 3023 break;
3438 3024
3439#if ENABLE_FRILLS 3025#if !ENABLE_MINIMAL
3440 case CSI_74: 3026 case CSI_74:
3441 process_window_ops (arg, nargs); 3027 process_window_ops (arg, nargs);
3442 break; 3028 break;
3443#endif 3029#endif
3444 3030
3451 break; 3037 break;
3452 } 3038 }
3453} 3039}
3454/*}}} */ 3040/*}}} */
3455 3041
3456#if ENABLE_FRILLS 3042#if !ENABLE_MINIMAL
3457/* ARGSUSED */ 3043/* ARGSUSED */
3458void 3044void
3459rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3045rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3460{ 3046{
3461 int x, y; 3047 int x, y;
3462 XWindowAttributes wattr; 3048 XWindowAttributes wattr;
3463 Window wdummy; 3049 Window wdummy;
3464 dDisp; 3050
3051 dLocal (Display *, dpy);
3465 3052
3466 if (nargs == 0) 3053 if (nargs == 0)
3467 return; 3054 return;
3468 3055
3469 switch (args[0]) 3056 switch (args[0])
3470 { 3057 {
3471 /* 3058 /*
3472 * commands 3059 * commands
3473 */ 3060 */
3474 case 1: /* deiconify window */ 3061 case 1: /* deiconify window */
3475 XMapWindow (disp, TermWin.parent[0]); 3062 XMapWindow (dpy, parent[0]);
3476 break; 3063 break;
3477 case 2: /* iconify window */ 3064 case 2: /* iconify window */
3478 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3065 XIconifyWindow (dpy, parent[0], display->screen);
3479 break; 3066 break;
3480 case 3: /* set position (pixels) */ 3067 case 3: /* set position (pixels) */
3481 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3068 XMoveWindow (dpy, parent[0], args[1], args[2]);
3482 break; 3069 break;
3483 case 4: /* set size (pixels) */ 3070 case 4: /* set size (pixels) */
3484 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3071 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3485 break; 3072 break;
3486 case 5: /* raise window */ 3073 case 5: /* raise window */
3487 XRaiseWindow (disp, TermWin.parent[0]); 3074 XRaiseWindow (dpy, parent[0]);
3488 break; 3075 break;
3489 case 6: /* lower window */ 3076 case 6: /* lower window */
3490 XLowerWindow (disp, TermWin.parent[0]); 3077 XLowerWindow (dpy, parent[0]);
3491 break; 3078 break;
3492 case 7: /* refresh window */ 3079 case 7: /* refresh window */
3493 scr_touch (true); 3080 scr_touch (true);
3494 break; 3081 break;
3495 case 8: /* set size (chars) */ 3082 case 8: /* set size (chars) */
3496 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3083 set_widthheight ((unsigned int) (args[2] * fwidth),
3497 (unsigned int) (args[1] * TermWin.fheight)); 3084 (unsigned int) (args[1] * fheight));
3498 break; 3085 break;
3499 3086
3500 //case 9: NYI, TODO, restore maximized window or maximize window 3087 //case 9: NYI, TODO, restore maximized window or maximize window
3501 default: 3088 default:
3502 if (args[0] >= 24) /* set height (chars) */ 3089 if (args[0] >= 24) /* set height (chars) */
3503 set_widthheight ((unsigned int)TermWin.width, 3090 set_widthheight ((unsigned int)width,
3504 (unsigned int) (args[1] * TermWin.fheight)); 3091 (unsigned int) (args[1] * fheight));
3505 break; 3092 break;
3506
3507 3093
3508 /* 3094 /*
3509 * reports - some output format copied from XTerm 3095 * reports - some output format copied from XTerm
3510 */ 3096 */
3511 case 11: /* report window state */ 3097 case 11: /* report window state */
3512 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3098 XGetWindowAttributes (dpy, parent[0], &wattr);
3513 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3099 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3514 break; 3100 break;
3515 case 13: /* report window position */ 3101 case 13: /* report window position */
3516 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3102 XGetWindowAttributes (dpy, parent[0], &wattr);
3517 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3103 XTranslateCoordinates (dpy, parent[0], wattr.root,
3518 -wattr.border_width, -wattr.border_width, 3104 -wattr.border_width, -wattr.border_width,
3519 &x, &y, &wdummy); 3105 &x, &y, &wdummy);
3520 tt_printf ("\033[3;%d;%dt", x, y); 3106 tt_printf ("\033[3;%d;%dt", x, y);
3521 break; 3107 break;
3522 case 14: /* report window size (pixels) */ 3108 case 14: /* report window size (pixels) */
3523 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3109 XGetWindowAttributes (dpy, parent[0], &wattr);
3524 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3110 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3525 break; 3111 break;
3526 case 18: /* report text area size (chars) */ 3112 case 18: /* report text area size (chars) */
3527 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3113 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3528 break; 3114 break;
3529 case 19: /* report window size (chars) */ 3115 case 19: /* report window size (chars) */
3530 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3116 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3531 break; 3117 break;
3532 case 20: /* report icon label */ 3118 case 20: /* report icon label */
3533 { 3119 {
3534 char *s; 3120 char *s;
3535 XGetIconName (disp, TermWin.parent[0], &s); 3121 XGetIconName (dpy, parent[0], &s);
3536 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3122 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3537 XFree (s); 3123 XFree (s);
3538 } 3124 }
3539 break; 3125 break;
3540 case 21: /* report window title */ 3126 case 21: /* report window title */
3541 { 3127 {
3542 char *s; 3128 char *s;
3543 XFetchName (disp, TermWin.parent[0], &s); 3129 XFetchName (dpy, parent[0], &s);
3544 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3130 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3545 XFree (s); 3131 XFree (s);
3546 } 3132 }
3547 break; 3133 break;
3548 } 3134 }
3549} 3135}
3552/*----------------------------------------------------------------------*/ 3138/*----------------------------------------------------------------------*/
3553/* 3139/*
3554 * get input up until STRING TERMINATOR (or BEL) 3140 * get input up until STRING TERMINATOR (or BEL)
3555 * ends_how is terminator used. returned input must be free()'d 3141 * ends_how is terminator used. returned input must be free()'d
3556 */ 3142 */
3557unsigned char * 3143char *
3558rxvt_term::get_to_st (unicode_t &ends_how) 3144rxvt_term::get_to_st (unicode_t &ends_how)
3559{ 3145{
3560 unicode_t ch; 3146 unicode_t ch;
3561 bool seen_esc = false; 3147 bool seen_esc = false;
3562 unsigned int n = 0; 3148 unsigned int n = 0;
3576 seen_esc = true; 3162 seen_esc = true;
3577 continue; 3163 continue;
3578 } 3164 }
3579 else if (ch == C0_BEL || ch == CHAR_ST) 3165 else if (ch == C0_BEL || ch == CHAR_ST)
3580 break; 3166 break;
3167 else if (ch == C0_SYN)
3168 ch = cmd_get8 ();
3581 else if (ch < 0x20) 3169 else if (ch < 0x20)
3582 return NULL; /* other control character - exit */ 3170 return NULL; /* other control character - exit */
3583 3171
3584 seen_esc = false; 3172 seen_esc = false;
3585 3173
3586 if (n >= sizeof (string) - 1) 3174 if (n >= STRING_MAX - 1)
3587 // stop at some sane length 3175 // stop at some sane length
3588 return NULL; 3176 return NULL;
3589 3177
3590 if (ch == C0_SYN)
3591 string[n++] = cmd_get8 ();
3592 else
3593 string[n++] = ch; 3178 string[n++] = ch;
3594 } 3179 }
3595 3180
3596 string[n++] = '\0'; 3181 string[n++] = '\0';
3597 3182
3598 ends_how = (ch == 0x5c ? C0_ESC : ch); 3183 ends_how = (ch == 0x5c ? C0_ESC : ch);
3599 3184
3600 return (unsigned char *)rxvt_wcstombs (string); 3185 return rxvt_wcstombs (string);
3601} 3186}
3602 3187
3603/*----------------------------------------------------------------------*/ 3188/*----------------------------------------------------------------------*/
3604/* 3189/*
3605 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3190 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3606 */ 3191 */
3607void 3192void
3608rxvt_term::process_dcs_seq () 3193rxvt_term::process_dcs_seq ()
3609{ 3194{
3610 unsigned char *s; 3195 char *s;
3611 unicode_t eh; 3196 unicode_t eh;
3612 3197
3613 /* 3198 /*
3614 * Not handled yet 3199 * Not handled yet
3615 */ 3200 */
3634 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3219 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3635 arg = arg * 10 + (ch - '0'); 3220 arg = arg * 10 + (ch - '0');
3636 3221
3637 if (ch == ';') 3222 if (ch == ';')
3638 { 3223 {
3639 unsigned char *s = get_to_st (eh); 3224 char *s = get_to_st (eh);
3640 3225
3641 if (s) 3226 if (s)
3642 { 3227 {
3643 process_xterm_seq (arg, (char *)s, eh); 3228 process_xterm_seq (arg, s, eh);
3644 free (s); 3229 free (s);
3645 } 3230 }
3646 } 3231 }
3647} 3232}
3648 3233
3649void 3234void
3650rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3235rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3651{ 3236{
3652 if (str[0] == '?' && !str[1]) 3237 if (str[0] == '?' && !str[1])
3653 { 3238 {
3654 unsigned short r, g, b; 3239 rgba c;
3655 pix_colors_focused[color].get (display, r, g, b); 3240 pix_colors_focused[color].get (c);
3241
3242#if XFT
3243 if (c.a != rgba::MAX_CC)
3244 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3245 else
3246#endif
3656 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3247 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3657 } 3248 }
3658 else 3249 else
3659 set_window_color (color, str); 3250 set_window_color (color, str);
3660} 3251}
3661 3252
3662/* 3253/*
3663 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3254 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3664 * 0 = change iconName/title
3665 * 1 = change iconName
3666 * 2 = change title
3667 * 4 = change color
3668 * 10 = change fg color
3669 * 11 = change bg color
3670 * 12 = change text color
3671 * 13 = change mouse foreground color
3672 * 17 = change highlight character colour
3673 * 18 = change bold character color
3674 * 19 = change underlined character color
3675 * 46 = change logfile (not implemented)
3676 * 50 = change font
3677 *
3678 * rxvt extensions:
3679 * 20 = bg pixmap
3680 * 39 = change default fg color
3681 * 49 = change default bg color
3682 * 55 = dump scrollback buffer and all of screen
3683 * 701 = change locale
3684 * 702 = find font
3685 * 703 = menu
3686 */ 3255 */
3687void 3256void
3688rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3257rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3689{ 3258{
3690 int changed = 0;
3691 int color; 3259 int color;
3692 char *buf, *name; 3260 char *buf, *name;
3693 bool query = str[0] == '?' && !str[1]; 3261 bool query = str[0] == '?' && !str[1];
3694 int saveop = op; 3262 int saveop = op;
3695 dDisp; 3263
3264 dLocal (Display *, dpy);
3696 3265
3697 assert (str != NULL); 3266 assert (str != NULL);
3267
3268 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3269 return;
3270
3698 switch (op) 3271 switch (op)
3699 { 3272 {
3700 case XTerm_name: 3273 case XTerm_name:
3701 set_title (str); 3274 set_title (str);
3702 /* FALLTHROUGH */ 3275 /* FALLTHROUGH */
3716 unsigned long bytes_after; 3289 unsigned long bytes_after;
3717 unsigned char *value = 0; 3290 unsigned char *value = 0;
3718 const char *str = ""; 3291 const char *str = "";
3719 3292
3720 if (prop 3293 if (prop
3721 && XGetWindowProperty (disp, TermWin.parent[0], 3294 && XGetWindowProperty (dpy, parent[0],
3722 prop, 0, 1<<16, 0, AnyPropertyType, 3295 prop, 0, 1<<16, 0, AnyPropertyType,
3723 &actual_type, &actual_format, 3296 &actual_type, &actual_format,
3724 &nitems, &bytes_after, &value) == Success 3297 &nitems, &bytes_after, &value) == Success
3725 && actual_type != None 3298 && actual_type != None
3726 && actual_format == 8) 3299 && actual_format == 8)
3727 str = (const char *)(value); 3300 str = (const char *)(value);
3728 3301
3729 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3302 tt_printf ("\033]%d;%s%c", op, str, resp);
3730 3303
3731 XFree (value); 3304 XFree (value);
3732 } 3305 }
3733 else 3306 else
3734 { 3307 {
3738 { 3311 {
3739 *eq = 0; 3312 *eq = 0;
3740 set_utf8_property (display->atom (str), eq + 1); 3313 set_utf8_property (display->atom (str), eq + 1);
3741 } 3314 }
3742 else 3315 else
3743 XDeleteProperty (disp, TermWin.parent[0], 3316 XDeleteProperty (dpy, parent[0],
3744 display->atom (str)); 3317 display->atom (str));
3745 } 3318 }
3746 break; 3319 break;
3747 3320
3748 case XTerm_Color: 3321 case XTerm_Color:
3750 { 3323 {
3751 if ((name = strchr (buf, ';')) == NULL) 3324 if ((name = strchr (buf, ';')) == NULL)
3752 break; 3325 break;
3753 3326
3754 *name++ = '\0'; 3327 *name++ = '\0';
3755 color = atoi (buf); 3328 color = atoi (buf) + minCOLOR;
3756 3329
3757 if (color < 0 || color >= TOTAL_COLORS) 3330 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3758 break; 3331 break;
3759 3332
3760 if ((buf = strchr (name, ';')) != NULL) 3333 if ((buf = strchr (name, ';')) != NULL)
3761 *buf++ = '\0'; 3334 *buf++ = '\0';
3762 3335
3763 if (name[0] == '?' && !name[1]) 3336 process_color_seq (op, color, name, resp);
3764 {
3765 unsigned short r, g, b;
3766 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3767 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3768 }
3769 else
3770 set_window_color (color + minCOLOR, name);
3771 } 3337 }
3772 break; 3338 break;
3773 case XTerm_Color00: 3339 case XTerm_Color00:
3774 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3340 process_color_seq (op, Color_fg, str, resp);
3775 break; 3341 break;
3776 case XTerm_Color01: 3342 case XTerm_Color01:
3777 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3343 process_color_seq (op, Color_bg, str, resp);
3778 break; 3344 break;
3779#ifndef NO_CURSORCOLOR 3345#ifndef NO_CURSORCOLOR
3780 case XTerm_Color_cursor: 3346 case XTerm_Color_cursor:
3781 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3347 process_color_seq (op, Color_cursor, str, resp);
3782 break; 3348 break;
3783#endif 3349#endif
3784 case XTerm_Color_pointer_fg: 3350 case XTerm_Color_pointer_fg:
3785 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3351 process_color_seq (op, Color_pointer_fg, str, resp);
3786 break; 3352 break;
3787 case XTerm_Color_pointer_bg: 3353 case XTerm_Color_pointer_bg:
3788 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3354 process_color_seq (op, Color_pointer_bg, str, resp);
3789 break; 3355 break;
3790#ifndef NO_BOLD_UNDERLINE_REVERSE 3356#ifndef NO_BOLD_UNDERLINE_REVERSE
3791 case XTerm_Color_BD:
3792 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3793 break;
3794 case XTerm_Color_IT:
3795 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3796 break;
3797 case XTerm_Color_UL:
3798 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3799 break;
3800 case XTerm_Color_RV: 3357 case XTerm_Color_RV:
3801 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3358 process_color_seq (op, Color_RV, str, resp);
3802 break; 3359 break;
3360 case Rxvt_Color_BD:
3361 case URxvt_Color_BD:
3362 process_color_seq (op, Color_BD, str, resp);
3363 break;
3364 case Rxvt_Color_UL:
3365 case URxvt_Color_UL:
3366 process_color_seq (op, Color_UL, str, resp);
3367 break;
3368 case URxvt_Color_IT:
3369 process_color_seq (op, Color_IT, str, resp);
3370 break;
3803#endif 3371#endif
3804#if TRANSPARENT && TINTING 3372#if ENABLE_TRANSPARENCY
3805 case XTerm_Color_tint: 3373 case URxvt_Color_tint:
3806 process_color_seq (XTerm_Color_tint, Color_tint, str, resp); 3374 process_color_seq (op, Color_tint, str, resp);
3807 check_our_parents (); 3375 {
3808 if (am_transparent) 3376 bool changed = false;
3809 want_full_refresh = want_refresh = 1; 3377 if (ISSET_PIXCOLOR (Color_tint))
3810 break; 3378 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3811#endif 3379 else
3380 changed = bgPixmap.unset_tint ();
3381 if (changed)
3382 update_background ();
3383 }
3812 3384
3385 break;
3386#endif
3387
3388#if BG_IMAGE_FROM_FILE
3813 case XTerm_Pixmap: 3389 case Rxvt_Pixmap:
3814 if (*str != ';') 3390 if (!strcmp (str, "?"))
3815 { 3391 {
3816#if XPM_BACKGROUND 3392 char str[256];
3817 scale_pixmap (""); /* reset to default scaling */ 3393
3818 set_bgPixmap (str); /* change pixmap */ 3394 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
3819#endif 3395 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3820 scr_touch (true); 3396 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3397 process_xterm_seq (XTerm_title, str, CHAR_ST);
3821 } 3398 }
3822 while ((str = strchr (str, ';')) != NULL) 3399 else
3823 { 3400 {
3401 int changed = 0;
3402
3403 if (*str != ';')
3404 {
3405 /* reset to default scaling :*/
3406 bgPixmap.unset_geometry ();
3407 if (bgPixmap.set_file (str)) /* change pixmap */
3408 changed++;
3409 str = strchr (str, ';');
3410 if (str == NULL)
3411 bgPixmap.set_defaultGeometry ();
3412 }
3413 while (str)
3414 {
3824 str++; 3415 str++;
3825#if XPM_BACKGROUND 3416 if (bgPixmap.set_geometry (str))
3826 changed += scale_pixmap (str); 3417 changed++;
3827#endif 3418 str = strchr (str, ';');
3419 }
3420 if (changed)
3421 update_background ();
3828 } 3422 }
3829
3830 if (changed)
3831 {
3832#ifdef XPM_BACKGROUND
3833 resize_pixmap ();
3834#endif
3835 scr_touch (true);
3836 }
3837 break; 3423 break;
3424#endif
3838 3425
3839 case XTerm_restoreFG: 3426 case Rxvt_restoreFG:
3840 set_window_color (Color_fg, str); 3427 set_window_color (Color_fg, str);
3841 break; 3428 break;
3842 case XTerm_restoreBG: 3429 case Rxvt_restoreBG:
3843 set_window_color (Color_bg, str); 3430 set_window_color (Color_bg, str);
3844 break; 3431 break;
3845 3432
3846 case XTerm_logfile: 3433 case XTerm_logfile:
3847 // TODO, when secure mode? 3434 // TODO, when secure mode?
3848 break; 3435 break;
3849 3436
3437#if 0
3438 case Rxvt_dumpscreen: /* no error notices */
3439 {
3440 int fd;
3441 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3442 {
3443 scr_dump (fd);
3444 close (fd);
3445 }
3446 }
3447 break;
3448#endif
3850 case XTerm_font: 3449 case XTerm_font:
3851 op = URxvt_font; 3450 op = URxvt_font;
3852 case URxvt_font: 3451 case URxvt_font:
3853#if ENABLE_STYLES 3452#if ENABLE_STYLES
3854 case URxvt_boldFont: 3453 case URxvt_boldFont:
3855 case URxvt_italicFont: 3454 case URxvt_italicFont:
3856 case URxvt_boldItalicFont: 3455 case URxvt_boldItalicFont:
3857#endif 3456#endif
3858 if (query) 3457 if (query)
3859 tt_printf ("\33]%d;%-.250s%c", saveop, 3458 tt_printf ("\33]%d;%-.250s%c", saveop,
3860 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3459 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3861 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3460 ? fontset[op - URxvt_font]->fontdesc : "",
3862 resp); 3461 resp);
3863 else 3462 else
3864 { 3463 {
3865 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3464 const char *&res = rs[Rs_font + (op - URxvt_font)];
3866 3465
3868 allocated.push_back ((void *)res); 3467 allocated.push_back ((void *)res);
3869 set_fonts (); 3468 set_fonts ();
3870 } 3469 }
3871 break; 3470 break;
3872 3471
3873#if ENABLE_FRILLS 3472 case URxvt_version:
3874 case XTerm_locale:
3875 if (query) 3473 if (query)
3474 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3475 op,
3476 rs[Rs_name], VERSION[0], VERSION[2],
3477 resp);
3478 break;
3479
3480#if !ENABLE_MINIMAL
3481 case URxvt_locale:
3482 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3483 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3877 else 3484 else
3878 { 3485 {
3879 set_locale (str); 3486 set_locale (str);
3880 pty.set_utf8_mode (enc_utf8); 3487 pty->set_utf8_mode (enc_utf8);
3881# ifdef USE_XIM
3882 im_cb (); 3488 init_xlocale ();
3883# endif
3884 } 3489 }
3885 break; 3490 break;
3886#endif
3887 3491
3888#ifdef MENUBAR 3492 case URxvt_view_up:
3889 case XTerm_Menu: 3493 case URxvt_view_down:
3890 if (options & Opt_insecure) 3494 {
3891 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3495 int lines = atoi (str);
3496
3497 if (lines)
3498 scr_page (op == URxvt_view_up ? UP : DN, lines);
3499 else
3500 scr_erase_savelines ();
3501 }
3502
3892 break; 3503 break;
3893#endif 3504#endif
3894#if 0 3505
3895 case XTerm_dumpscreen: /* no error notices */ 3506#if ENABLE_PERL
3896 { 3507 case URxvt_perl:
3897 int fd; 3508 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END)))
3898 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3509 ; // no responses yet
3899 {
3900 scr_dump (fd);
3901 close (fd);
3902 }
3903 }
3904 break; 3510 break;
3905#endif 3511#endif
3906 } 3512 }
3907} 3513}
3908/*----------------------------------------------------------------------*/ 3514/*----------------------------------------------------------------------*/
3939 return state; 3545 return state;
3940} 3546}
3941 3547
3942/* we're not using priv _yet_ */ 3548/* we're not using priv _yet_ */
3943void 3549void
3944rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3550rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3945{ 3551{
3946 unsigned int i, j; 3552 unsigned int i, j;
3947 int state; 3553 int state;
3948 3554
3949 static const struct 3555 static const struct
3950 { 3556 {
3951 const int argval; 3557 const int argval;
3952 const unsigned long bit; 3558 const unsigned long bit;
3953 }
3954
3955 argtopriv[] = { 3559 } argtopriv[] = {
3956 { 1, PrivMode_aplCUR }, 3560 { 1, PrivMode_aplCUR },
3957 { 2, PrivMode_vt52 }, 3561 { 2, PrivMode_vt52 },
3958 { 3, PrivMode_132 }, 3562 { 3, PrivMode_132 },
3959 { 4, PrivMode_smoothScroll }, 3563 { 4, PrivMode_smoothScroll },
3960 { 5, PrivMode_rVideo }, 3564 { 5, PrivMode_rVideo },
3961 { 6, PrivMode_relOrigin }, 3565 { 6, PrivMode_relOrigin },
3962 { 7, PrivMode_Autowrap }, 3566 { 7, PrivMode_Autowrap },
3963 // 8, bi-directional support mode 3567 // 8, bi-directional support mode
3964 { 9, PrivMode_MouseX10 }, 3568 { 9, PrivMode_MouseX10 },
3965#ifdef menuBar_esc
3966 { menuBar_esc, PrivMode_menuBar },
3967#endif
3968 // 18, 19 printing-related 3569 // 18, 19 printing-related
3969 { 25, PrivMode_VisibleCursor }, 3570 { 25, PrivMode_VisibleCursor },
3970#ifdef scrollBar_esc 3571#ifdef scrollBar_esc
3971 { scrollBar_esc, PrivMode_scrollBar }, 3572 { scrollBar_esc, PrivMode_scrollBar },
3972#endif 3573#endif
3980#ifndef NO_BACKSPACE_KEY 3581#ifndef NO_BACKSPACE_KEY
3981 { 67, PrivMode_BackSpace }, 3582 { 67, PrivMode_BackSpace },
3982#endif 3583#endif
3983 { 1000, PrivMode_MouseX11 }, 3584 { 1000, PrivMode_MouseX11 },
3984 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3585 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3985 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3586 { 1002, PrivMode_MouseBtnEvent },
3986 // 1003 Use All Motion Mouse Tracking. NYI, TODO 3587 { 1003, PrivMode_MouseAnyEvent },
3987 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3588 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3988 { 1011, PrivMode_Keypress }, // rxvt extension 3589 { 1011, PrivMode_Keypress }, // rxvt extension
3989 // 1035 enable modifiers for alt, numlock NYI 3590 // 1035 enable modifiers for alt, numlock NYI
3990 // 1036 send ESC for meta keys NYI 3591 // 1036 send ESC for meta keys NYI
3991 // 1037 send DEL for keypad delete NYI 3592 // 1037 send DEL for keypad delete NYI
4017 } 3618 }
4018 3619
4019 /* extra handling for values with state unkept */ 3620 /* extra handling for values with state unkept */
4020 switch (arg[i]) 3621 switch (arg[i])
4021 { 3622 {
3623#if ENABLE_STYLES
3624 case 1021:
3625 set_option (Opt_intensityStyles, mode);
3626
3627 scr_touch (true);
3628 break;
3629#endif
4022 case 1048: /* alternative cursor save */ 3630 case 1048: /* alternative cursor save */
4023 case 1049: 3631 case 1049:
4024 if (options & Opt_secondaryScreen) 3632 if (option (Opt_secondaryScreen))
4025 if (mode == 0) 3633 if (mode == 0)
4026 scr_cursor (RESTORE); 3634 scr_cursor (RESTORE);
4027 else if (mode == 1) 3635 else if (mode == 1)
4028 scr_cursor (SAVE); 3636 scr_cursor (SAVE);
4029 break; 3637 break;
4041 */ 3649 */
4042 PrivMode (1, PrivMode_vt52); 3650 PrivMode (1, PrivMode_vt52);
4043 break; 3651 break;
4044 case 3: /* 80/132 */ 3652 case 3: /* 80/132 */
4045 if (priv_modes & PrivMode_132OK) 3653 if (priv_modes & PrivMode_132OK)
4046 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 3654 set_widthheight (((state ? 132 : 80) * fwidth), height);
4047 break; 3655 break;
4048 case 4: /* smooth scrolling */ 3656 case 4: /* smooth scrolling */
4049 if (state)
4050 options &= ~Opt_jumpScroll;
4051 else
4052 options |= Opt_jumpScroll; 3657 set_option (Opt_jumpScroll, !state);
4053 break; 3658 break;
4054 case 5: /* reverse video */ 3659 case 5: /* reverse video */
4055 scr_rvideo_mode (state); 3660 scr_rvideo_mode (state);
4056 break; 3661 break;
4057 case 6: /* relative/absolute origins */ 3662 case 6: /* relative/absolute origins */
4061 scr_autowrap (state); 3666 scr_autowrap (state);
4062 break; 3667 break;
4063 /* case 8: - auto repeat, can't do on a per window basis */ 3668 /* case 8: - auto repeat, can't do on a per window basis */
4064 case 9: /* X10 mouse reporting */ 3669 case 9: /* X10 mouse reporting */
4065 if (state) /* orthogonal */ 3670 if (state) /* orthogonal */
4066 priv_modes &= ~PrivMode_MouseX11; 3671 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4067 break; 3672 break;
4068#ifdef menuBar_esc
4069 case menuBar_esc:
4070#ifdef MENUBAR
4071 map_menuBar (state);
4072#endif
4073 break;
4074#endif
4075#ifdef scrollBar_esc 3673#ifdef scrollBar_esc
4076 case scrollBar_esc: 3674 case scrollBar_esc:
4077 if (scrollbar_mapping (state)) 3675 if (scrollbar_mapping (state))
4078 { 3676 {
4079 resize_all_windows (0, 0, 0); 3677 resize_all_windows (0, 0, 0);
4091 break; 3689 break;
4092 /* case 66: - application key pad */ 3690 /* case 66: - application key pad */
4093 /* case 67: - backspace key */ 3691 /* case 67: - backspace key */
4094 case 1000: /* X11 mouse reporting */ 3692 case 1000: /* X11 mouse reporting */
4095 if (state) /* orthogonal */ 3693 if (state) /* orthogonal */
4096 priv_modes &= ~PrivMode_MouseX10; 3694 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4097 break; 3695 break;
4098#if 0 3696#if 0
4099 case 1001: 3697 case 1001:
4100 break; /* X11 mouse highlighting */ 3698 break; /* X11 mouse highlighting */
4101#endif 3699#endif
3700 case 1002:
3701 case 1003:
3702 if (state) {
3703 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3704 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3705 vt_emask_mouse = PointerMotionMask;
3706 } else
3707 vt_emask_mouse = NoEventMask;
3708 vt_select_input ();
3709 break;
4102 case 1010: /* scroll to bottom on TTY output inhibit */ 3710 case 1010: /* scroll to bottom on TTY output inhibit */
4103 if (state)
4104 options &= ~Opt_scrollTtyOutput;
4105 else
4106 options |= Opt_scrollTtyOutput; 3711 set_option (Opt_scrollTtyOutput, !state);
4107 break; 3712 break;
4108 case 1011: /* scroll to bottom on key press */ 3713 case 1011: /* scroll to bottom on key press */
4109 if (state)
4110 options |= Opt_scrollTtyKeypress; 3714 set_option (Opt_scrollTtyKeypress, state);
4111 else
4112 options &= ~Opt_scrollTtyKeypress;
4113 break; 3715 break;
4114 case 1047: /* secondary screen w/ clearing last */ 3716 case 1047: /* secondary screen w/ clearing last */
4115 if (options & Opt_secondaryScreen) 3717 if (option (Opt_secondaryScreen))
4116 if (current_screen != PRIMARY) 3718 if (current_screen != PRIMARY)
4117 scr_erase_screen (2); 3719 scr_erase_screen (2);
4118 scr_change_screen (state); 3720 scr_change_screen (state);
4119 break; 3721 break;
4120 case 1049: /* secondary screen w/ clearing first */ 3722 case 1049: /* secondary screen w/ clearing first */
4121 scr_change_screen (state); 3723 scr_change_screen (state);
4122 if (options & Opt_secondaryScreen) 3724 if (option (Opt_secondaryScreen))
4123 if (current_screen != PRIMARY) 3725 if (current_screen != PRIMARY)
4124 scr_erase_screen (2); 3726 scr_erase_screen (2);
4125 break; 3727 break;
4126 default: 3728 default:
4127 break; 3729 break;
4255 scr_color (Color_bg, Color_bg); 3857 scr_color (Color_bg, Color_bg);
4256 break; 3858 break;
4257 3859
4258 //case 50: // not variable spacing 3860 //case 50: // not variable spacing
4259 3861
4260#ifndef NO_BRIGHTCOLOR 3862#if !ENABLE_MINIMAL
4261 case 90: 3863 case 90:
4262 case 91: /* set bright fg color */ 3864 case 91: /* set bright fg color */
4263 case 92: 3865 case 92:
4264 case 93: 3866 case 93:
4265 case 94: 3867 case 94:
4277 case 106: 3879 case 106:
4278 case 107: 3880 case 107:
4279 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 3881 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4280 break; 3882 break;
4281#endif 3883#endif
4282
4283 } 3884 }
4284 } 3885 }
4285} 3886}
4286/*}}} */ 3887/*}}} */
4287 3888
4311 */ 3912 */
4312void 3913void
4313rxvt_term::tt_printf (const char *fmt,...) 3914rxvt_term::tt_printf (const char *fmt,...)
4314{ 3915{
4315 va_list arg_ptr; 3916 va_list arg_ptr;
4316 unsigned char buf[256]; 3917 char buf[256];
4317 3918
4318 va_start (arg_ptr, fmt); 3919 va_start (arg_ptr, fmt);
4319 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 3920 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4320 va_end (arg_ptr); 3921 va_end (arg_ptr);
4321 tt_write (buf, strlen (buf)); 3922 tt_write (buf, strlen (buf));
4326 * or generated by us in response to a query ESC sequence. 3927 * or generated by us in response to a query ESC sequence.
4327 */ 3928 */
4328const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 3929const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4329 3930
4330void 3931void
4331rxvt_term::tt_write (const unsigned char *data, unsigned int len) 3932rxvt_term::tt_write (const char *data, unsigned int len)
4332{ 3933{
3934 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
3935 return;
3936
3937 if (pty->pty < 0)
3938 return;
3939
4333 if (v_buflen == 0) 3940 if (v_buflen == 0)
4334 { 3941 {
4335 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 3942 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4336 3943
4337 if ((unsigned int)written == len) 3944 if ((unsigned int)written == len)
4338 return; 3945 return;
4339 3946
4340 data += written; 3947 data += written;
4341 len -= written; 3948 len -= written;
4342 } 3949 }
4343 3950
4344 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 3951 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4345 3952
4346 memcpy (v_buffer + v_buflen, data, len); 3953 memcpy (v_buffer + v_buflen, data, len);
4347 v_buflen += len; 3954 v_buflen += len;
4348 3955
4349 pty_ev.set (EVENT_READ | EVENT_WRITE); 3956 pty_ev.set (ev::READ | ev::WRITE);
4350} 3957}
4351 3958
4352void rxvt_term::pty_write () 3959void rxvt_term::pty_write ()
4353{ 3960{
4354 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 3961 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4355 3962
4356 if (written > 0) 3963 if (written > 0)
4357 { 3964 {
4358 v_buflen -= written; 3965 v_buflen -= written;
4359 3966
4360 if (v_buflen == 0) 3967 if (v_buflen == 0)
4361 { 3968 {
4362 free (v_buffer); 3969 free (v_buffer);
4363 v_buffer = 0; 3970 v_buffer = 0;
4364 v_buflen = 0;
4365 3971
4366 pty_ev.set (EVENT_READ); 3972 pty_ev.set (ev::READ);
4367 return; 3973 return;
4368 } 3974 }
4369 3975
4370 memmove (v_buffer, v_buffer + written, v_buflen); 3976 memmove (v_buffer, v_buffer + written, v_buflen);
4371 } 3977 }
4372 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 3978 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4373 // original code just ignores this... 3979 pty_ev.set (ev::READ);
4374 destroy ();
4375} 3980}
4376 3981
4377/*----------------------- end-of-file (C source) -----------------------*/ 3982/*----------------------- end-of-file (C source) -----------------------*/
4378 3983

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines