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.199 by root, Sun Feb 20 02:00:43 2005 UTC vs.
Revision 1.365 by ayin, Thu Nov 15 10:13:37 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: command.C 2 * File: command.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2005 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-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 {
1258 if (x == mouse_row && y == mouse_col)
1259 return;
1260 mouse_row = x;
1261 mouse_col = y;
1262 code += 32;
1263 }
1134 1264
1135 if (MEvent.button == AnyButton) 1265 if (MEvent.button == AnyButton)
1136 button_number = 3; 1266 button_number = 3;
1137 else 1267 else
1138 { 1268 {
1184 x + 1, 1314 x + 1,
1185 y + 1); 1315 y + 1);
1186#endif 1316#endif
1187 1317
1188 tt_printf ("\033[M%c%c%c", 1318 tt_printf ("\033[M%c%c%c",
1189 (32 + button_number + key_state), 1319 (code + button_number + key_state),
1190 (32 + x + 1), 1320 (32 + x + 1),
1191 (32 + y + 1)); 1321 (32 + y + 1));
1192} 1322}
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 1323
1204/*{{{ process an X event */ 1324/*{{{ process an X event */
1205void 1325void
1206rxvt_term::x_cb (XEvent &ev) 1326rxvt_term::x_cb (XEvent &ev)
1207{ 1327{
1208 dDisp; 1328 make_current ();
1209 1329
1210 SET_R (this); 1330 dLocal (Display *, dpy);
1211 SET_LOCALE (locale);
1212 1331
1213#if defined(CURSOR_BLINK) 1332 if (ev.xany.window == vt
1214 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1333 && SHOULD_INVOKE (HOOK_X_EVENT)
1215 { 1334 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1216 if (hidden_cursor) 1335 return;
1217 {
1218 hidden_cursor = 0;
1219 want_refresh = 1;
1220 }
1221 1336
1222 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1337 // 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; 1338 Window unused_root, unused_child;
1241 int unused_root_x, unused_root_y; 1339 int unused_root_x, unused_root_y;
1242 unsigned int unused_mask; 1340 unsigned int unused_mask;
1243 1341
1244 switch (ev.type) 1342 switch (ev.type)
1245 { 1343 {
1246 case KeyPress: 1344 case KeyPress:
1247#if ISO_14755 1345 key_press (ev.xkey);
1248 if (!(iso14755buf & ISO_14755_52))
1249#endif
1250 lookup_key (ev.xkey);
1251
1252 break; 1346 break;
1253 1347
1254 case KeyRelease: 1348 case KeyRelease:
1255 { 1349 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; 1350 break;
1323 }
1324 1351
1325 case ButtonPress: 1352 case ButtonPress:
1326 button_press (ev.xbutton); 1353 button_press (ev.xbutton);
1327 break; 1354 break;
1328 1355
1330 button_release (ev.xbutton); 1357 button_release (ev.xbutton);
1331 break; 1358 break;
1332 1359
1333 case ClientMessage: 1360 case ClientMessage:
1334 if (ev.xclient.format == 32 1361 if (ev.xclient.format == 32
1362 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1363 {
1335 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS] 1364 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1365 {
1366 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1367 {
1336 && ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1368 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1337 destroy (); 1369 {
1370 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1371 destroy ();
1372 }
1373#if ENABLE_EWMH
1374 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1375 XSendEvent (dpy, ev.xclient.window = display->root,
1376 False, SubstructureRedirectMask | SubstructureNotifyMask,
1377 &ev);
1378#endif
1379 }
1380 }
1338#if ENABLE_XEMBED 1381#if ENABLE_XEMBED
1339 else if (ev.xclient.format == 32
1340 && ev.xclient.message_type == xa[XA_XEMBED]) 1382 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1341 { 1383 {
1342 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) 1384 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1343 focus_in (); 1385 focus_in ();
1344 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1386 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1345 focus_out (); 1387 focus_out ();
1388 }
1389#endif
1346 } 1390 }
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; 1391 break;
1379 1392
1380 /* 1393 /*
1381 * XXX: this is not the _current_ arrangement 1394 * XXX: this is not the _current_ arrangement
1382 * Here's my conclusion: 1395 * Here's my conclusion:
1401 break; 1414 break;
1402 } 1415 }
1403 break; 1416 break;
1404 1417
1405 case FocusIn: 1418 case FocusIn:
1419 if (ev.xfocus.detail != NotifyInferior
1420 && ev.xfocus.detail != NotifyPointer
1421 && ev.xfocus.mode != NotifyGrab)
1406 focus_in (); 1422 focus_in ();
1407 break; 1423 break;
1408 1424
1409 case FocusOut: 1425 case FocusOut:
1426 if (ev.xfocus.detail != NotifyInferior
1427 && ev.xfocus.detail != NotifyPointer
1428 && ev.xfocus.mode != NotifyGrab)
1410 focus_out (); 1429 focus_out ();
1411 break; 1430 break;
1412 1431
1413 case ConfigureNotify: 1432 case ConfigureNotify:
1433 /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1434 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1435 szHint.width, szHint.height); */
1414 if (ev.xconfigure.window == TermWin.parent[0]) 1436 if (ev.xconfigure.window == parent[0])
1415 { 1437 {
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)); 1438 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1439 ;
1425 1440
1426 if (szHint.width != width || szHint.height != height) 1441 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1427 { 1442 {
1428 seen_resize = 1; 1443 seen_resize = 1;
1429 resize_all_windows (width, height, 1); 1444 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1430 } 1445 }
1431 1446 else
1432#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1447 {
1433 if (options & Opt_transparent) 1448#ifdef HAVE_BG_PIXMAP
1434 check_our_parents (); 1449 if (bgPixmap.window_position_sensitive ())
1450 update_background ();
1435#endif 1451#endif
1452 }
1453 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1436 } 1454 }
1437 break; 1455 break;
1438 1456
1439 case PropertyNotify: 1457 case PropertyNotify:
1458 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1440 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1459 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1441 && ev.xproperty.state == PropertyNewValue) 1460 && ev.xproperty.state == PropertyNewValue)
1442 selection_property (ev.xproperty.window, ev.xproperty.atom); 1461 selection_property (ev.xproperty.window, ev.xproperty.atom);
1443 1462
1444 break; 1463 break;
1445 1464
1446 case SelectionClear: 1465 case SelectionClear:
1447 selection_clear (); 1466 selection_clear ();
1454 1473
1455 case SelectionRequest: 1474 case SelectionRequest:
1456 selection_send (ev.xselectionrequest); 1475 selection_send (ev.xselectionrequest);
1457 break; 1476 break;
1458 1477
1478 case MapNotify:
1479 mapped = 1;
1480#ifdef TEXT_BLINK
1481 text_blink_ev.start (TEXT_BLINK_INTERVAL);
1482#endif
1483 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1484 break;
1485
1459 case UnmapNotify: 1486 case UnmapNotify:
1460 TermWin.mapped = 0; 1487 mapped = 0;
1461#ifdef TEXT_BLINK 1488#ifdef TEXT_BLINK
1462 text_blink_ev.stop (); 1489 text_blink_ev.stop ();
1463#endif 1490#endif
1491 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1464 break; 1492 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 1493
1479 case GraphicsExpose: 1494 case GraphicsExpose:
1480 case Expose: 1495 case Expose:
1481 if (ev.xany.window == TermWin.vt) 1496 if (ev.xany.window == vt)
1482 { 1497 {
1483 do 1498 do
1499 {
1484 scr_expose (ev.xexpose.x, ev.xexpose.y, 1500 scr_expose (ev.xexpose.x, ev.xexpose.y,
1485 ev.xexpose.width, ev.xexpose.height, False); 1501 ev.xexpose.width, ev.xexpose.height, False);
1502 }
1486 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1503 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1487 1504
1488 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1505 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1489 1506
1490 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1507 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1508 {
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1509 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1510 ev.xexpose.width, ev.xexpose.height, False);
1493 1511 }
1494 scr_refresh (refresh_type); 1512 want_refresh = 1;
1495 } 1513 }
1496 else 1514 else
1497 { 1515 {
1498 XEvent unused_event; 1516 XEvent unused_event;
1499 1517
1500 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1518 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1501 ; 1519 ;
1502 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1520 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1503 ; 1521 ;
1504 1522
1505 if (isScrollbarWindow (ev.xany.window)) 1523 if (isScrollbarWindow (ev.xany.window))
1506 { 1524 {
1507 scrollBar.setIdle (); 1525 scrollBar.setIdle ();
1508 scrollbar_show (0); 1526 scrollbar_show (0);
1509 } 1527 }
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 } 1528 }
1520 break; 1529 break;
1521 1530
1522 case MotionNotify: 1531 case MotionNotify:
1523#ifdef POINTER_BLANK 1532#ifdef POINTER_BLANK
1524 if (hidden_pointer) 1533 if (hidden_pointer)
1525 pointer_unblank (); 1534 pointer_unblank ();
1526#endif 1535#endif
1527#if MENUBAR 1536 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1528 if (isMenuBarWindow (ev.xany.window)) 1537 || priv_modes & PrivMode_MouseAnyEvent)
1529 {
1530 menubar_control (ev.xbutton); 1538 mouse_report (ev.xbutton);
1531 break;
1532 }
1533#endif
1534 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1539 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1535 break; 1540 break;
1536 1541
1537 if (ev.xany.window == TermWin.vt) 1542 if (ev.xany.window == vt)
1538 { 1543 {
1544 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1545 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1546 ; // nop
1539 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1547 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1540 { 1548 {
1541 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1549 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1542 ; 1550 ;
1543 1551
1544 XQueryPointer (disp, TermWin.vt, 1552 XQueryPointer (dpy, vt,
1545 &unused_root, &unused_child, 1553 &unused_root, &unused_child,
1546 &unused_root_x, &unused_root_y, 1554 &unused_root_x, &unused_root_y,
1547 &ev.xbutton.x, &ev.xbutton.y, 1555 &ev.xbutton.x, &ev.xbutton.y,
1548 &ev.xbutton.state); 1556 &ev.xbutton.state);
1549#ifdef MOUSE_THRESHOLD 1557#ifdef MOUSE_THRESHOLD
1561#endif 1569#endif
1562 selection_extend (ev.xbutton.x, ev.xbutton.y, 1570 selection_extend (ev.xbutton.x, ev.xbutton.y,
1563 ev.xbutton.state & Button3Mask ? 2 : 0); 1571 ev.xbutton.state & Button3Mask ? 2 : 0);
1564 1572
1565#ifdef SELECTION_SCROLLING 1573#ifdef SELECTION_SCROLLING
1566 if (ev.xbutton.y < TermWin.int_bwidth 1574 if (ev.xbutton.y < int_bwidth
1567 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1575 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1568 { 1576 {
1569 int dist; 1577 int dist;
1570 1578
1571 /* don't clobber the current delay if we are 1579 /* don't clobber the current delay if we are
1572 * already in the middle of scrolling. 1580 * already in the middle of scrolling.
1573 */ 1581 */
1574 if (!sel_scroll_ev.active) 1582 if (!sel_scroll_ev.active)
1575 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1583 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1576 1584
1577 /* save the event params so we can highlight 1585 /* save the event params so we can highlight
1578 * the selection in the pending-scroll loop 1586 * the selection in the pending-scroll loop
1579 */ 1587 */
1580 selection_save_x = ev.xbutton.x; 1588 selection_save_x = ev.xbutton.x;
1581 selection_save_y = ev.xbutton.y; 1589 selection_save_y = ev.xbutton.y;
1582 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1590 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1583 1591
1584 /* calc number of lines to scroll */ 1592 /* calc number of lines to scroll */
1585 if (ev.xbutton.y < TermWin.int_bwidth) 1593 if (ev.xbutton.y < int_bwidth)
1586 { 1594 {
1587 scroll_selection_dir = UP; 1595 scroll_selection_dir = UP;
1588 dist = TermWin.int_bwidth - ev.xbutton.y; 1596 dist = int_bwidth - ev.xbutton.y;
1589 } 1597 }
1590 else 1598 else
1591 { 1599 {
1592 scroll_selection_dir = DN; 1600 scroll_selection_dir = DN;
1593 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1601 dist = ev.xbutton.y - (int_bwidth + height);
1594 } 1602 }
1595 1603
1596 scroll_selection_lines = Pixel2Height (dist) 1604 scroll_selection_lines = Pixel2Height (dist)
1597 / SELECTION_SCROLL_LINE_SPEEDUP 1605 / SELECTION_SCROLL_LINE_SPEEDUP
1598 + 1; 1606 + 1;
1599 MIN_IT (scroll_selection_lines, 1607 min_it (scroll_selection_lines,
1600 SELECTION_SCROLL_MAX_LINES); 1608 SELECTION_SCROLL_MAX_LINES);
1601 } 1609 }
1602 else 1610 else
1603 { 1611 {
1604 /* we are within the text window, so we 1612 /* we are within the text window, so we
1613#endif 1621#endif
1614 } 1622 }
1615 } 1623 }
1616 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1624 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1617 { 1625 {
1618 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1626 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1619 MotionNotify, &ev)) 1627 MotionNotify, &ev))
1620 ; 1628 ;
1621 1629
1622 XQueryPointer (disp, scrollBar.win, 1630 XQueryPointer (dpy, scrollBar.win,
1623 &unused_root, &unused_child, 1631 &unused_root, &unused_child,
1624 &unused_root_x, &unused_root_y, 1632 &unused_root_x, &unused_root_y,
1625 &ev.xbutton.x, &ev.xbutton.y, 1633 &ev.xbutton.x, &ev.xbutton.y,
1626 &unused_mask); 1634 &unused_mask);
1627 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1635 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1628 scrollbar_size ()); 1636 scrollbar_size ());
1629 scr_refresh (refresh_type);
1630 refresh_limit = 0; 1637 want_refresh = 1;
1631 scrollbar_show (1); 1638 scrollbar_show (1);
1632 } 1639 }
1633 break; 1640 break;
1634 } 1641 }
1642
1643#if defined(CURSOR_BLINK)
1644 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1645 {
1646 if (hidden_cursor)
1647 {
1648 hidden_cursor = 0;
1649 want_refresh = 1;
1650 }
1651
1652 cursor_blink_ev.again ();
1653 }
1654#endif
1655
1656#if defined(POINTER_BLANK)
1657 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1658 {
1659 if (ev.type == MotionNotify
1660 || ev.type == ButtonPress
1661 || ev.type == ButtonRelease)
1662 if (hidden_pointer)
1663 pointer_unblank ();
1664
1665 if (ev.type == KeyPress && hidden_pointer == 0)
1666 pointer_blank ();
1667 }
1668#endif
1635} 1669}
1636 1670
1637void 1671void
1638rxvt_term::focus_in () 1672rxvt_term::focus_in ()
1639{ 1673{
1640 if (!TermWin.focus) 1674 if (!focus)
1641 { 1675 {
1642 TermWin.focus = 1; 1676 focus = 1;
1643 want_refresh = 1; 1677 want_refresh = 1;
1678
1679 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1680
1644#ifdef USE_XIM 1681#if USE_XIM
1645 if (Input_Context != NULL) 1682 if (Input_Context != NULL)
1646 { 1683 {
1647 IMSetStatusPosition (); 1684 IMSetPosition ();
1648 XSetICFocus (Input_Context); 1685 XSetICFocus (Input_Context);
1649 } 1686 }
1650#endif 1687#endif
1651#ifdef CURSOR_BLINK 1688#if CURSOR_BLINK
1652 if (options & Opt_cursorBlink) 1689 if (option (Opt_cursorBlink))
1653 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1690 cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL);
1654#endif 1691#endif
1655#ifdef OFF_FOCUS_FADING 1692#if OFF_FOCUS_FADING
1656 if (rs[Rs_fade]) 1693 if (rs[Rs_fade])
1657 { 1694 {
1658 pix_colors = pix_colors_focused; 1695 pix_colors = pix_colors_focused;
1659 scr_recolour (); 1696 scr_recolour ();
1660 } 1697 }
1661#endif 1698#endif
1699#if ENABLE_FRILLS
1700 if (option (Opt_urgentOnBell))
1701 {
1702 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1703 {
1704 h->flags &= ~XUrgencyHint;
1705 XSetWMHints (dpy, parent[0], h);
1706 }
1707 }
1708#endif
1662 } 1709 }
1663} 1710}
1664 1711
1665void 1712void
1666rxvt_term::focus_out () 1713rxvt_term::focus_out ()
1667{ 1714{
1668 if (TermWin.focus) 1715 if (focus)
1669 { 1716 {
1670 TermWin.focus = 0; 1717 focus = 0;
1671 want_refresh = 1; 1718 want_refresh = 1;
1672 1719
1720 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1721
1673#if ENABLE_FRILLS || ISO_14755 1722#if ENABLE_FRILLS || ISO_14755
1723 if (iso14755buf)
1724 {
1674 iso14755buf = 0; 1725 iso14755buf = 0;
1675#endif 1726# if ISO_14755
1676#if ENABLE_OVERLAY
1677 scr_overlay_off (); 1727 scr_overlay_off ();
1678#endif 1728# endif
1729 }
1730#endif
1679#ifdef USE_XIM 1731#if USE_XIM
1680 if (Input_Context != NULL) 1732 if (Input_Context != NULL)
1681 XUnsetICFocus (Input_Context); 1733 XUnsetICFocus (Input_Context);
1682#endif 1734#endif
1683#ifdef CURSOR_BLINK 1735#if CURSOR_BLINK
1684 if (options & Opt_cursorBlink) 1736 if (option (Opt_cursorBlink))
1685 cursor_blink_ev.stop (); 1737 cursor_blink_ev.stop ();
1738
1686 hidden_cursor = 0; 1739 hidden_cursor = 0;
1687#endif 1740#endif
1688#ifdef OFF_FOCUS_FADING 1741#if OFF_FOCUS_FADING
1689 if (rs[Rs_fade]) 1742 if (rs[Rs_fade])
1690 { 1743 {
1691 pix_colors = pix_colors_unfocused; 1744 pix_colors = pix_colors_unfocused;
1692 scr_recolour (); 1745 scr_recolour ();
1693 } 1746 }
1694#endif 1747#endif
1695 } 1748 }
1696} 1749}
1697 1750
1698#if TRANSPARENT 1751void
1752rxvt_term::update_fade_color (unsigned int idx)
1753{
1754#if OFF_FOCUS_FADING
1755 if (rs[Rs_fade])
1756 {
1757 rgba c;
1758 pix_colors [Color_fade].get (c);
1759 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1760 }
1761#endif
1762}
1763
1764#if ENABLE_TRANSPARENCY || ENABLE_PERL
1699void 1765void
1700rxvt_term::rootwin_cb (XEvent &ev) 1766rxvt_term::rootwin_cb (XEvent &ev)
1701{ 1767{
1702 SET_R (this); 1768 make_current ();
1703 SET_LOCALE (locale);
1704 1769
1770 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1771 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1772 return;
1773
1774# if ENABLE_TRANSPARENCY
1705 switch (ev.type) 1775 switch (ev.type)
1706 { 1776 {
1707 case PropertyNotify: 1777 case PropertyNotify:
1708 /* 1778 /*
1709 * if user used some Esetroot compatible prog to set the root bg, 1779 * 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. 1780 * use the property to determine the pixmap. We use it later on.
1711 */ 1781 */
1712 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1782 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1713 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1783 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1714 return; 1784 {
1715 1785 bgPixmap.set_root_pixmap ();
1716 /* FALLTHROUGH */ 1786 update_background ();
1717 case ReparentNotify: 1787 }
1718 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1719 want_refresh = want_full_refresh = 1;
1720 break; 1788 break;
1721 } 1789 }
1790# endif
1722} 1791}
1723#endif 1792#endif
1724 1793
1725void 1794void
1726rxvt_term::button_press (XButtonEvent &ev) 1795rxvt_term::button_press (XButtonEvent &ev)
1727{ 1796{
1728 int reportmode = 0, clickintime; 1797 int reportmode = 0, clickintime;
1729 1798
1730 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1799 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1800
1731 if (!bypass_keystate) 1801 if (!bypass_keystate)
1732 reportmode = !! (priv_modes & PrivMode_mouse_report); 1802 reportmode = !! (priv_modes & PrivMode_mouse_report);
1733 1803
1734 /* 1804 /*
1735 * VT window processing of button press 1805 * VT window processing of button press
1736 */ 1806 */
1737 if (ev.window == TermWin.vt) 1807 if (ev.window == vt)
1738 { 1808 {
1809 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1810 return;
1811
1739#if ISO_14755 1812#if ISO_14755
1740 // 5.4 1813 // 5.4
1741 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1814 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1742 { 1815 {
1743 iso14755_54 (ev.x, ev.y); 1816 iso14755_54 (ev.x, ev.y);
1755#ifdef MOUSE_REPORT_DOUBLECLICK 1828#ifdef MOUSE_REPORT_DOUBLECLICK
1756 if (ev.button == MEvent.button && clickintime) 1829 if (ev.button == MEvent.button && clickintime)
1757 { 1830 {
1758 /* same button, within alloted time */ 1831 /* same button, within alloted time */
1759 MEvent.clicks++; 1832 MEvent.clicks++;
1833
1760 if (MEvent.clicks > 1) 1834 if (MEvent.clicks > 1)
1761 { 1835 {
1762 /* only report double clicks */ 1836 /* only report double clicks */
1763 MEvent.clicks = 2; 1837 MEvent.clicks = 2;
1764 mouse_report (ev); 1838 mouse_report (ev);
1796#else 1870#else
1797 selection.rect = false; 1871 selection.rect = false;
1798#endif 1872#endif
1799 1873
1800 /* allow shift+left click to extend selection */ 1874 /* allow shift+left click to extend selection */
1801 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1875 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1802 { 1876 {
1803 if (MEvent.button == Button1 && clickintime) 1877 if (MEvent.button == Button1 && clickintime)
1804 selection_rotate (ev.x, ev.y); 1878 selection_rotate (ev.x, ev.y);
1805 else 1879 else
1806 selection_extend (ev.x, ev.y, 1); 1880 selection_extend (ev.x, ev.y, 1);
1902 upordown = 1; /* down */ 1976 upordown = 1; /* down */
1903 } 1977 }
1904 if (upordown) 1978 if (upordown)
1905 { 1979 {
1906#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1980#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1907 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1981 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1908#endif 1982#endif
1909 if (scr_page (upordown < 0 ? UP : DN, 1)) 1983 if (scr_page (upordown < 0 ? UP : DN, 1))
1910 { 1984 {
1911 if (upordown < 0) 1985 if (upordown < 0)
1912 scrollBar.setUp (); 1986 scrollBar.setUp ();
1947 case Button3: 2021 case Button3:
1948 if (scrollBar.style != R_SB_XTERM) 2022 if (scrollBar.style != R_SB_XTERM)
1949 { 2023 {
1950 if (scrollbar_above_slider (ev.y)) 2024 if (scrollbar_above_slider (ev.y))
1951# ifdef RXVT_SCROLL_FULL 2025# ifdef RXVT_SCROLL_FULL
1952 scr_page (UP, TermWin.nrow - 1); 2026 scr_page (UP, nrow - 1);
1953# else 2027# else
1954 scr_page (UP, TermWin.nrow / 4); 2028 scr_page (UP, nrow / 4);
1955# endif 2029# endif
1956 else if (scrollbar_below_slider (ev.y)) 2030 else if (scrollbar_below_slider (ev.y))
1957# ifdef RXVT_SCROLL_FULL 2031# ifdef RXVT_SCROLL_FULL
1958 scr_page (DN, TermWin.nrow - 1); 2032 scr_page (DN, nrow - 1);
1959# else 2033# else
1960 scr_page (DN, TermWin.nrow / 4); 2034 scr_page (DN, nrow / 4);
1961# endif 2035# endif
1962 else 2036 else
1963 scrollBar.setMotion (); 2037 scrollBar.setMotion ();
1964 } 2038 }
1965 else 2039 else
1966 { 2040 {
1967 scr_page ((ev.button == Button1 ? DN : UP), 2041 scr_page ((ev.button == Button1 ? DN : UP),
1968 (TermWin.nrow 2042 (nrow
1969 * scrollbar_position (ev.y) 2043 * scrollbar_position (ev.y)
1970 / scrollbar_size ())); 2044 / scrollbar_size ()));
1971 } 2045 }
1972 2046
1973 break; 2047 break;
1974 } 2048 }
1975 } 2049 }
2050
1976 return; 2051 return;
1977 } 2052 }
1978#if MENUBAR
1979 /*
1980 * Menubar window processing of button press
1981 */
1982 if (isMenuBarWindow (ev.window))
1983 menubar_control (ev);
1984#endif
1985} 2053}
1986 2054
1987void 2055void
1988rxvt_term::button_release (XButtonEvent &ev) 2056rxvt_term::button_release (XButtonEvent &ev)
1989{ 2057{
1995 2063
1996 if (scrollbar_isUpDn ()) 2064 if (scrollbar_isUpDn ())
1997 { 2065 {
1998 scrollBar.setIdle (); 2066 scrollBar.setIdle ();
1999 scrollbar_show (0); 2067 scrollbar_show (0);
2000#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2001 refresh_type &= ~SMOOTH_REFRESH;
2002#endif
2003 } 2068 }
2004 2069
2005#ifdef SELECTION_SCROLLING 2070#ifdef SELECTION_SCROLLING
2006 if (sel_scroll_ev.active) 2071 if (sel_scroll_ev.active)
2007 sel_scroll_ev.stop(); 2072 sel_scroll_ev.stop();
2008#endif 2073#endif
2009 2074
2010 if (ev.window == TermWin.vt) 2075 if (ev.window == vt)
2011 { 2076 {
2077 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2078 return;
2079
2012#if ISO_14755 2080#if ISO_14755
2013 // 5.4 2081 // 5.4
2014 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2082 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2015 return; 2083 return;
2016#endif 2084#endif
2085
2017 if (reportmode) 2086 if (reportmode)
2018 { 2087 {
2019 /* mouse report from vt window */ 2088 /* mouse report from vt window */
2020 /* don't report release of wheel "buttons" */ 2089 /* don't report release of wheel "buttons" */
2021 if (ev.button >= 4) 2090 if (ev.button >= 4)
2051 { 2120 {
2052 case Button1: 2121 case Button1:
2053 case Button3: 2122 case Button3:
2054 selection_make (ev.time); 2123 selection_make (ev.time);
2055 break; 2124 break;
2125
2056 case Button2: 2126 case Button2:
2057 selection_request (ev.time, ev.x, ev.y); 2127 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2128 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2058 break; 2129 break;
2130
2059#ifdef MOUSE_WHEEL 2131#ifdef MOUSE_WHEEL
2060 case Button4: 2132 case Button4:
2061 case Button5: 2133 case Button5:
2062 { 2134 {
2063 int i; 2135 int i;
2065 2137
2066 v = ev.button == Button4 ? UP : DN; 2138 v = ev.button == Button4 ? UP : DN;
2067 2139
2068 if (ev.state & ShiftMask) 2140 if (ev.state & ShiftMask)
2069 i = 1; 2141 i = 1;
2070 else if (options & Opt_mouseWheelScrollPage) 2142 else if (option (Opt_mouseWheelScrollPage))
2071 i = TermWin.nrow - 1; 2143 i = nrow - 1;
2072 else 2144 else
2073 i = 5; 2145 i = 5;
2074 2146
2075# ifdef MOUSE_SLIP_WHEELING 2147# ifdef MOUSE_SLIP_WHEELING
2076 if (ev.state & ControlMask) 2148 if (ev.state & ControlMask)
2077 { 2149 {
2078 mouse_slip_wheel_speed += v ? -1 : 1; 2150 mouse_slip_wheel_speed += v ? -1 : 1;
2079 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;
2080 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; 2152 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2081 2153
2082 if (slip_wheel_ev.at < NOW) 2154 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 } 2155 }
2087 else 2156 else
2088 { 2157 {
2089# endif 2158# endif
2090# ifdef JUMP_MOUSE_WHEEL
2091 scr_page (v, i); 2159 scr_page (v, i);
2092 scr_refresh (SMOOTH_REFRESH);
2093 scrollbar_show (1); 2160 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 2161# ifdef MOUSE_SLIP_WHEELING
2103 } 2162 }
2104#endif 2163# endif
2105 } 2164 }
2106 break; 2165 break;
2107#endif 2166#endif
2108 } 2167 }
2109 } 2168 }
2110#ifdef MENUBAR
2111 else if (isMenuBarWindow (ev.window))
2112 menubar_control (ev);
2113#endif
2114} 2169}
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 2170
2597/*}}} */ 2171/*}}} */
2598 2172
2599bool 2173bool
2600rxvt_term::cmd_parse () 2174rxvt_term::cmd_parse ()
2601{ 2175{
2602 bool flag = false; 2176 bool flag = false;
2603 unicode_t ch = NOCHAR; 2177 wchar_t ch = NOCHAR;
2604 unsigned char *seq_begin; // remember start of esc-sequence here 2178 char *seq_begin; // remember start of esc-sequence here
2605 2179
2606 for (;;) 2180 for (;;)
2607 { 2181 {
2608 if (ch == NOCHAR) 2182 if (ch == NOCHAR)
2609 { 2183 {
2610 seq_begin = cmdbuf_ptr; 2184 seq_begin = cmdbuf_ptr;
2611 ch = next_char (); 2185 ch = next_char ();
2612 }
2613 2186
2614 if (ch == NOCHAR) // TODO: improve 2187 if (ch == NOCHAR)
2615 break; 2188 break;
2189 }
2616 2190
2617 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2191 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2618 { 2192 {
2619 if (!seen_input) 2193 if (!seen_input)
2620 { 2194 {
2629 if (seen_resize && cmd_pid) 2203 if (seen_resize && cmd_pid)
2630 kill (-cmd_pid, SIGWINCH); 2204 kill (-cmd_pid, SIGWINCH);
2631 } 2205 }
2632 2206
2633 /* Read a text string from the input buffer */ 2207 /* Read a text string from the input buffer */
2634 unicode_t buf[UBUFSIZ]; 2208 wchar_t buf[UBUFSIZ];
2635 bool refreshnow = false; 2209 bool refreshnow = false;
2636 int nlines = 0; 2210 int nlines = 0;
2637 unicode_t *str = buf; 2211 wchar_t *str = buf;
2212 wchar_t *eol = str + min (ncol, UBUFSIZ);
2638 2213
2639 for (;;) 2214 for (;;)
2640 { 2215 {
2641 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2216 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2642 break; 2217 break;
2643 2218
2644 *str++ = ch; 2219 *str++ = ch;
2645 2220
2646 if (ch == C0_LF) 2221 if (ch == C0_LF || str >= eol)
2647 { 2222 {
2223 if (ch == C0_LF)
2648 nlines++; 2224 nlines++;
2225
2649 refresh_count++; 2226 refresh_count++;
2650 2227
2651 if (!(options & Opt_jumpScroll) 2228 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2652 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2653 { 2229 {
2230 refresh_count = 0;
2231
2232 if (!option (Opt_skipScroll) || ev::ev_time () > ev::now () + 1. / 60.)
2233 {
2654 refreshnow = true; 2234 refreshnow = true;
2655 ch = NOCHAR; 2235 ch = NOCHAR;
2656 break; 2236 break;
2237 }
2657 } 2238 }
2658 2239
2659 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2240 // scr_add_lines only works for nlines <= nrow - 1.
2660 if (nlines >= TermWin.nrow - 1) 2241 if (nlines >= nrow - 1)
2661 { 2242 {
2243 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2244 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2662 scr_add_lines (buf, nlines, str - buf); 2245 scr_add_lines (buf, str - buf, nlines);
2246
2663 nlines = 0; 2247 nlines = 0;
2664 str = buf; 2248 str = buf;
2249 eol = str + min (ncol, UBUFSIZ);
2665 } 2250 }
2666 }
2667 2251
2668 if (str >= buf + UBUFSIZ) 2252 if (str >= eol)
2669 { 2253 {
2254 if (eol >= buf + UBUFSIZ)
2255 {
2670 ch = NOCHAR; 2256 ch = NOCHAR;
2671 break; 2257 break;
2258 }
2259 else
2260 eol = min (eol + ncol, buf + UBUFSIZ);
2261 }
2262
2672 } 2263 }
2673 2264
2674 seq_begin = cmdbuf_ptr; 2265 seq_begin = cmdbuf_ptr;
2675 ch = next_char (); 2266 ch = next_char ();
2676 } 2267 }
2677 2268
2269 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2270 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2678 scr_add_lines (buf, nlines, str - buf); 2271 scr_add_lines (buf, str - buf, nlines);
2679 2272
2680 /* 2273 /*
2681 * If there have been a lot of new lines, then update the screen 2274 * 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. 2275 * 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 2276 * if skipScroll is enabled.
2684 * is incremented here because we must be doing flat-out scrolling.
2685 */ 2277 */
2686 if (refreshnow) 2278 if (refreshnow)
2687 { 2279 {
2688 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2689 refresh_limit++;
2690 else
2691 {
2692 flag = true; 2280 flag = true;
2693 scr_refresh (refresh_type); 2281 scr_refresh ();
2694 } 2282 want_refresh = 1;
2695 } 2283 }
2696 2284
2697 } 2285 }
2698 else 2286 else
2699 { 2287 {
2713 } 2301 }
2714 2302
2715 return flag; 2303 return flag;
2716} 2304}
2717 2305
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 2306// read the next character
2728unicode_t 2307wchar_t
2729rxvt_term::next_char () 2308rxvt_term::next_char () NOTHROW
2730{ 2309{
2731 while (cmdbuf_ptr < cmdbuf_endp) 2310 while (cmdbuf_ptr < cmdbuf_endp)
2732 { 2311 {
2733 // assume 7-bit to be ascii ALWAYS 2312 // assume 7-bit to be ascii ALWAYS
2734 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2313 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2735 return *cmdbuf_ptr++; 2314 return *cmdbuf_ptr++;
2736 2315
2737 wchar_t wc; 2316 wchar_t wc;
2738 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2317 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2739 2318
2740 if (len == (size_t)-2) 2319 if (len == (size_t)-2)
2741 { 2320 {
2742 // the mbstate stores incomplete sequences. didn't know this :/ 2321 // the mbstate stores incomplete sequences. didn't know this :/
2743 cmdbuf_ptr = cmdbuf_endp; 2322 cmdbuf_ptr = cmdbuf_endp;
2744 break; 2323 break;
2745 } 2324 }
2746 2325
2747 if (len == (size_t)-1) 2326 if (len == (size_t)-1)
2748 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2327 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2749 2328
2750 // assume wchar == unicode 2329 // assume wchar == unicode
2751 cmdbuf_ptr += len; 2330 cmdbuf_ptr += len;
2752 return wc & UNICODE_MASK; 2331 return wc & UNICODE_MASK;
2753 } 2332 }
2754 2333
2755 return NOCHAR; 2334 return NOCHAR;
2756} 2335}
2336
2337// read the next octet
2338uint32_t
2339rxvt_term::next_octet () NOTHROW
2340{
2341 return cmdbuf_ptr < cmdbuf_endp
2342 ? (unsigned char)*cmdbuf_ptr++
2343 : NOCHAR;
2344}
2345
2346static class out_of_input out_of_input;
2757 2347
2758/* rxvt_cmd_getc () - Return next input character */ 2348/* rxvt_cmd_getc () - Return next input character */
2759/* 2349/*
2760 * Return the next input character after first passing any keyboard input 2350 * Return the next input character after first passing any keyboard input
2761 * to the command. 2351 * to the command.
2762 */ 2352 */
2763unicode_t 2353wchar_t
2764rxvt_term::cmd_getc () 2354rxvt_term::cmd_getc () THROW ((class out_of_input))
2765{ 2355{
2766 unicode_t c = next_char (); 2356 wchar_t c = next_char ();
2767 2357
2768 if (c == NOCHAR) 2358 if (c == NOCHAR)
2769 throw out_of_input; 2359 throw out_of_input;
2770 2360
2771 return c; 2361 return c;
2772} 2362}
2773 2363
2774unicode_t 2364uint32_t
2775rxvt_term::cmd_get8 () 2365rxvt_term::cmd_get8 () THROW ((class out_of_input))
2776{ 2366{
2777 unicode_t c = next_octet (); 2367 uint32_t c = next_octet ();
2778 2368
2779 if (c == NOCHAR) 2369 if (c == NOCHAR)
2780 throw out_of_input; 2370 throw out_of_input;
2781 2371
2782 return c; 2372 return c;
2846 { 2436 {
2847 if ((buf[len++] = cmd_getc ()) == 'i') 2437 if ((buf[len++] = cmd_getc ()) == 'i')
2848 break; /* done = 1 */ 2438 break; /* done = 1 */
2849 } 2439 }
2850 } 2440 }
2851 2441
2852 for (i = 0; i < len; i++) 2442 for (i = 0; i < len; i++)
2853 if (putc (buf[i], fd) == EOF) 2443 if (putc (buf[i], fd) == EOF)
2854 { 2444 {
2855 done = 1; 2445 done = 1;
2856 break; 2446 break;
2882 case C0_ESC: 2472 case C0_ESC:
2883 process_escape_seq (); 2473 process_escape_seq ();
2884 break; 2474 break;
2885 case C0_ENQ: /* terminal Status */ 2475 case C0_ENQ: /* terminal Status */
2886 if (rs[Rs_answerbackstring]) 2476 if (rs[Rs_answerbackstring])
2887 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2477 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2888 (unsigned int)strlen (rs[Rs_answerbackstring]));
2889 else 2478 else
2890 tt_write ((unsigned char *)VT100_ANS, 2479 tt_write (VT100_ANS, strlen (VT100_ANS));
2891 (unsigned int)strlen (VT100_ANS));
2892 break; 2480 break;
2893 case C0_BEL: /* bell */ 2481 case C0_BEL: /* bell */
2894 scr_bell (); 2482 scr_bell ();
2895 break; 2483 break;
2896 case C0_BS: /* backspace */ 2484 case C0_BS: /* backspace */
2920 process_dcs_seq (); 2508 process_dcs_seq ();
2921 break; 2509 break;
2922 case 0x9b: /* CSI */ 2510 case 0x9b: /* CSI */
2923 process_csi_seq (); 2511 process_csi_seq ();
2924 break; 2512 break;
2925 case 0x9d: /* CSI */ 2513 case 0x9d: /* OSC */
2926 process_osc_seq (); 2514 process_osc_seq ();
2927 break; 2515 break;
2928#endif 2516#endif
2929 } 2517 }
2930} 2518}
3020 scr_charset_set (2, (unsigned int)cmd_getc ()); 2608 scr_charset_set (2, (unsigned int)cmd_getc ());
3021 break; 2609 break;
3022 case '+': 2610 case '+':
3023 scr_charset_set (3, (unsigned int)cmd_getc ()); 2611 scr_charset_set (3, (unsigned int)cmd_getc ());
3024 break; 2612 break;
3025#if ENABLE_FRILLS 2613#if !ENABLE_MINIMAL
3026 case '6': 2614 case '6':
3027 scr_backindex (); 2615 scr_backindex ();
3028 break; 2616 break;
3029#endif 2617#endif
3030 case '7': 2618 case '7':
3031 scr_cursor (SAVE); 2619 scr_cursor (SAVE);
3032 break; 2620 break;
3033 case '8': 2621 case '8':
3034 scr_cursor (RESTORE); 2622 scr_cursor (RESTORE);
3035 break; 2623 break;
3036#if ENABLE_FRILLS 2624#if !ENABLE_MINIMAL
3037 case '9': 2625 case '9':
3038 scr_forwardindex (); 2626 scr_forwardindex ();
3039 break; 2627 break;
3040#endif 2628#endif
3041 case '=': 2629 case '=':
3051 break; 2639 break;
3052 2640
3053 /* 8.3.87: NEXT LINE */ 2641 /* 8.3.87: NEXT LINE */
3054 case C1_NEL: /* ESC E */ 2642 case C1_NEL: /* ESC E */
3055 { 2643 {
3056 unicode_t nlcr[] = { C0_LF, C0_CR }; 2644 wchar_t nlcr[] = { C0_LF, C0_CR };
3057 scr_add_lines (nlcr, 1, 2); 2645 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3058 } 2646 }
3059 break; 2647 break;
3060 2648
3061 /* kidnapped escape sequence: Should be 8.3.48 */ 2649 /* kidnapped escape sequence: Should be 8.3.48 */
3062 case C1_ESA: /* ESC G */ 2650 case C1_ESA: /* ESC G */
3084 process_dcs_seq (); 2672 process_dcs_seq ();
3085 break; 2673 break;
3086 2674
3087 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2675 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3088 case C1_SCI: /* ESC Z */ 2676 case C1_SCI: /* ESC Z */
3089 tt_write ((const unsigned char *)ESCZ_ANSWER, 2677 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3090 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3091 break; /* steal obsolete ESC [ c */ 2678 break; /* steal obsolete ESC [ c */
3092 2679
3093 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2680 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3094 case C1_CSI: /* ESC [ */ 2681 case C1_CSI: /* ESC [ */
3095 process_csi_seq (); 2682 process_csi_seq ();
3157rxvt_term::process_csi_seq () 2744rxvt_term::process_csi_seq ()
3158{ 2745{
3159 unicode_t ch, priv, i; 2746 unicode_t ch, priv, i;
3160 unsigned int nargs, p; 2747 unsigned int nargs, p;
3161 int n, ndef; 2748 int n, ndef;
3162 int arg[ESC_ARGS]; 2749 int arg[ESC_ARGS] = { };
3163 2750
3164 for (nargs = ESC_ARGS; nargs > 0;) 2751 nargs = 0;
3165 arg[--nargs] = 0;
3166 2752
3167 priv = 0; 2753 priv = 0;
3168 ch = cmd_getc (); 2754 ch = cmd_getc ();
3169 if (ch >= '<' && ch <= '?') 2755 if (ch >= '<' && ch <= '?')
3170 { /* '<' '=' '>' '?' */ 2756 { /* '<' '=' '>' '?' */
3204 ndef = get_byte_array_bit (csi_defaults, i); 2790 ndef = get_byte_array_bit (csi_defaults, i);
3205 for (p = 0; p < nargs; p++) 2791 for (p = 0; p < nargs; p++)
3206 if (arg[p] == -1) 2792 if (arg[p] == -1)
3207 arg[p] = ndef; 2793 arg[p] = ndef;
3208 2794
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 /* 2795 /*
3217 * private mode handling 2796 * private mode handling
3218 */ 2797 */
3219 if (priv) 2798 if (priv)
3220 { 2799 {
3221 switch (priv) 2800 switch (priv)
3222 { 2801 {
3223 case '>': 2802 case '>':
3224 if (ch == CSI_DA) /* secondary device attributes */ 2803 if (ch == CSI_DA) /* secondary device attributes */
3225 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2804 {
2805 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2806 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2807 //
2808 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2809 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2810 // versions.
2811 //
2812 tt_printf ("\033[>%d;95;0c", 'U');
2813 }
3226 break; 2814 break;
3227 case '?': 2815 case '?':
3228 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2816 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3229 process_terminal_mode (ch, priv, nargs, arg); 2817 process_terminal_mode (ch, priv, nargs, arg);
3230 break; 2818 break;
3335 2923
3336 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 2924 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3337 arg[0] = -arg[0]; 2925 arg[0] = -arg[0];
3338 /* FALLTHROUGH */ 2926 /* FALLTHROUGH */
3339 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2927 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3340 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 2928 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3341 break; 2929 break;
3342 2930
3343 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 2931 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3344 tt_write ((const unsigned char *)VT100_ANS, 2932 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3345 (unsigned int) (sizeof (VT100_ANS) - 1));
3346 break; 2933 break;
3347 2934
3348 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 2935 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3349 process_sgr_mode (nargs, arg); 2936 process_sgr_mode (nargs, arg);
3350 break; 2937 break;
3357 break; 2944 break;
3358 case 6: /* CPR requested */ 2945 case 6: /* CPR requested */
3359 scr_report_position (); 2946 scr_report_position ();
3360 break; 2947 break;
3361 case 7: /* unofficial extension */ 2948 case 7: /* unofficial extension */
3362 if (options & Opt_insecure) 2949 if (option (Opt_insecure))
3363 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2950 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3364 break; 2951 break;
3365 case 8: /* unofficial extension */ 2952 case 8: /* unofficial extension */
3366 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2953 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3367 break; 2954 break;
3434 break; 3021 break;
3435 case CSI_75: 3022 case CSI_75:
3436 scr_cursor (RESTORE); 3023 scr_cursor (RESTORE);
3437 break; 3024 break;
3438 3025
3439#if ENABLE_FRILLS 3026#if !ENABLE_MINIMAL
3440 case CSI_74: 3027 case CSI_74:
3441 process_window_ops (arg, nargs); 3028 process_window_ops (arg, nargs);
3442 break; 3029 break;
3443#endif 3030#endif
3444 3031
3451 break; 3038 break;
3452 } 3039 }
3453} 3040}
3454/*}}} */ 3041/*}}} */
3455 3042
3456#if ENABLE_FRILLS 3043#if !ENABLE_MINIMAL
3457/* ARGSUSED */ 3044/* ARGSUSED */
3458void 3045void
3459rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3046rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3460{ 3047{
3461 int x, y; 3048 int x, y;
3462 XWindowAttributes wattr; 3049 XWindowAttributes wattr;
3463 Window wdummy; 3050 Window wdummy;
3464 dDisp; 3051
3052 dLocal (Display *, dpy);
3465 3053
3466 if (nargs == 0) 3054 if (nargs == 0)
3467 return; 3055 return;
3468 3056
3469 switch (args[0]) 3057 switch (args[0])
3470 { 3058 {
3471 /* 3059 /*
3472 * commands 3060 * commands
3473 */ 3061 */
3474 case 1: /* deiconify window */ 3062 case 1: /* deiconify window */
3475 XMapWindow (disp, TermWin.parent[0]); 3063 XMapWindow (dpy, parent[0]);
3476 break; 3064 break;
3477 case 2: /* iconify window */ 3065 case 2: /* iconify window */
3478 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3066 XIconifyWindow (dpy, parent[0], display->screen);
3479 break; 3067 break;
3480 case 3: /* set position (pixels) */ 3068 case 3: /* set position (pixels) */
3481 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3069 XMoveWindow (dpy, parent[0], args[1], args[2]);
3482 break; 3070 break;
3483 case 4: /* set size (pixels) */ 3071 case 4: /* set size (pixels) */
3484 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3072 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3485 break; 3073 break;
3486 case 5: /* raise window */ 3074 case 5: /* raise window */
3487 XRaiseWindow (disp, TermWin.parent[0]); 3075 XRaiseWindow (dpy, parent[0]);
3488 break; 3076 break;
3489 case 6: /* lower window */ 3077 case 6: /* lower window */
3490 XLowerWindow (disp, TermWin.parent[0]); 3078 XLowerWindow (dpy, parent[0]);
3491 break; 3079 break;
3492 case 7: /* refresh window */ 3080 case 7: /* refresh window */
3493 scr_touch (true); 3081 scr_touch (true);
3494 break; 3082 break;
3495 case 8: /* set size (chars) */ 3083 case 8: /* set size (chars) */
3496 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3084 set_widthheight ((unsigned int) (args[2] * fwidth),
3497 (unsigned int) (args[1] * TermWin.fheight)); 3085 (unsigned int) (args[1] * fheight));
3498 break; 3086 break;
3499 3087
3500 //case 9: NYI, TODO, restore maximized window or maximize window 3088 //case 9: NYI, TODO, restore maximized window or maximize window
3501 default: 3089 default:
3502 if (args[0] >= 24) /* set height (chars) */ 3090 if (args[0] >= 24) /* set height (chars) */
3503 set_widthheight ((unsigned int)TermWin.width, 3091 set_widthheight ((unsigned int)width,
3504 (unsigned int) (args[1] * TermWin.fheight)); 3092 (unsigned int) (args[1] * fheight));
3505 break; 3093 break;
3506
3507 3094
3508 /* 3095 /*
3509 * reports - some output format copied from XTerm 3096 * reports - some output format copied from XTerm
3510 */ 3097 */
3511 case 11: /* report window state */ 3098 case 11: /* report window state */
3512 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3099 XGetWindowAttributes (dpy, parent[0], &wattr);
3513 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3100 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3514 break; 3101 break;
3515 case 13: /* report window position */ 3102 case 13: /* report window position */
3516 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3103 XGetWindowAttributes (dpy, parent[0], &wattr);
3517 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3104 XTranslateCoordinates (dpy, parent[0], wattr.root,
3518 -wattr.border_width, -wattr.border_width, 3105 -wattr.border_width, -wattr.border_width,
3519 &x, &y, &wdummy); 3106 &x, &y, &wdummy);
3520 tt_printf ("\033[3;%d;%dt", x, y); 3107 tt_printf ("\033[3;%d;%dt", x, y);
3521 break; 3108 break;
3522 case 14: /* report window size (pixels) */ 3109 case 14: /* report window size (pixels) */
3523 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3110 XGetWindowAttributes (dpy, parent[0], &wattr);
3524 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3111 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3525 break; 3112 break;
3526 case 18: /* report text area size (chars) */ 3113 case 18: /* report text area size (chars) */
3527 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3114 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3528 break; 3115 break;
3529 case 19: /* report window size (chars) */ 3116 case 19: /* report window size (chars) */
3530 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3117 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3531 break; 3118 break;
3532 case 20: /* report icon label */ 3119 case 20: /* report icon label */
3533 { 3120 {
3534 char *s; 3121 char *s;
3535 XGetIconName (disp, TermWin.parent[0], &s); 3122 XGetIconName (dpy, parent[0], &s);
3536 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3123 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3537 XFree (s); 3124 XFree (s);
3538 } 3125 }
3539 break; 3126 break;
3540 case 21: /* report window title */ 3127 case 21: /* report window title */
3541 { 3128 {
3542 char *s; 3129 char *s;
3543 XFetchName (disp, TermWin.parent[0], &s); 3130 XFetchName (dpy, parent[0], &s);
3544 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3131 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3545 XFree (s); 3132 XFree (s);
3546 } 3133 }
3547 break; 3134 break;
3548 } 3135 }
3549} 3136}
3552/*----------------------------------------------------------------------*/ 3139/*----------------------------------------------------------------------*/
3553/* 3140/*
3554 * get input up until STRING TERMINATOR (or BEL) 3141 * get input up until STRING TERMINATOR (or BEL)
3555 * ends_how is terminator used. returned input must be free()'d 3142 * ends_how is terminator used. returned input must be free()'d
3556 */ 3143 */
3557unsigned char * 3144char *
3558rxvt_term::get_to_st (unicode_t &ends_how) 3145rxvt_term::get_to_st (unicode_t &ends_how)
3559{ 3146{
3560 unicode_t ch; 3147 unicode_t ch;
3561 bool seen_esc = false; 3148 bool seen_esc = false;
3562 unsigned int n = 0; 3149 unsigned int n = 0;
3576 seen_esc = true; 3163 seen_esc = true;
3577 continue; 3164 continue;
3578 } 3165 }
3579 else if (ch == C0_BEL || ch == CHAR_ST) 3166 else if (ch == C0_BEL || ch == CHAR_ST)
3580 break; 3167 break;
3168 else if (ch == C0_SYN)
3169 ch = cmd_get8 ();
3581 else if (ch < 0x20) 3170 else if (ch < 0x20)
3582 return NULL; /* other control character - exit */ 3171 return NULL; /* other control character - exit */
3583 3172
3584 seen_esc = false; 3173 seen_esc = false;
3585 3174
3586 if (n >= sizeof (string) - 1) 3175 if (n >= STRING_MAX - 1)
3587 // stop at some sane length 3176 // stop at some sane length
3588 return NULL; 3177 return NULL;
3589 3178
3590 if (ch == C0_SYN)
3591 string[n++] = cmd_get8 ();
3592 else
3593 string[n++] = ch; 3179 string[n++] = ch;
3594 } 3180 }
3595 3181
3596 string[n++] = '\0'; 3182 string[n++] = '\0';
3597 3183
3598 ends_how = (ch == 0x5c ? C0_ESC : ch); 3184 ends_how = (ch == 0x5c ? C0_ESC : ch);
3599 3185
3600 return (unsigned char *)rxvt_wcstombs (string); 3186 return rxvt_wcstombs (string);
3601} 3187}
3602 3188
3603/*----------------------------------------------------------------------*/ 3189/*----------------------------------------------------------------------*/
3604/* 3190/*
3605 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3191 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3606 */ 3192 */
3607void 3193void
3608rxvt_term::process_dcs_seq () 3194rxvt_term::process_dcs_seq ()
3609{ 3195{
3610 unsigned char *s; 3196 char *s;
3611 unicode_t eh; 3197 unicode_t eh;
3612 3198
3613 /* 3199 /*
3614 * Not handled yet 3200 * Not handled yet
3615 */ 3201 */
3634 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3220 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3635 arg = arg * 10 + (ch - '0'); 3221 arg = arg * 10 + (ch - '0');
3636 3222
3637 if (ch == ';') 3223 if (ch == ';')
3638 { 3224 {
3639 unsigned char *s = get_to_st (eh); 3225 char *s = get_to_st (eh);
3640 3226
3641 if (s) 3227 if (s)
3642 { 3228 {
3643 process_xterm_seq (arg, (char *)s, eh); 3229 process_xterm_seq (arg, s, eh);
3644 free (s); 3230 free (s);
3645 } 3231 }
3646 } 3232 }
3647} 3233}
3648 3234
3649void 3235void
3650rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3236rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3651{ 3237{
3652 if (str[0] == '?' && !str[1]) 3238 if (str[0] == '?' && !str[1])
3653 { 3239 {
3654 unsigned short r, g, b; 3240 rgba c;
3655 pix_colors_focused[color].get (display, r, g, b); 3241 pix_colors_focused[color].get (c);
3242
3243#if XFT
3244 if (c.a != rgba::MAX_CC)
3245 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3246 else
3247#endif
3656 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3248 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3657 } 3249 }
3658 else 3250 else
3659 set_window_color (color, str); 3251 set_window_color (color, str);
3660} 3252}
3661 3253
3662/* 3254/*
3663 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3255 * 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 */ 3256 */
3687void 3257void
3688rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3258rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3689{ 3259{
3690 int changed = 0;
3691 int color; 3260 int color;
3692 char *buf, *name; 3261 char *buf, *name;
3693 bool query = str[0] == '?' && !str[1]; 3262 bool query = str[0] == '?' && !str[1];
3694 int saveop = op; 3263 int saveop = op;
3695 dDisp; 3264
3265 dLocal (Display *, dpy);
3696 3266
3697 assert (str != NULL); 3267 assert (str != NULL);
3268
3269 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3270 return;
3271
3698 switch (op) 3272 switch (op)
3699 { 3273 {
3700 case XTerm_name: 3274 case XTerm_name:
3701 set_title (str); 3275 set_title (str);
3702 /* FALLTHROUGH */ 3276 /* FALLTHROUGH */
3716 unsigned long bytes_after; 3290 unsigned long bytes_after;
3717 unsigned char *value = 0; 3291 unsigned char *value = 0;
3718 const char *str = ""; 3292 const char *str = "";
3719 3293
3720 if (prop 3294 if (prop
3721 && XGetWindowProperty (disp, TermWin.parent[0], 3295 && XGetWindowProperty (dpy, parent[0],
3722 prop, 0, 1<<16, 0, AnyPropertyType, 3296 prop, 0, 1<<16, 0, AnyPropertyType,
3723 &actual_type, &actual_format, 3297 &actual_type, &actual_format,
3724 &nitems, &bytes_after, &value) == Success 3298 &nitems, &bytes_after, &value) == Success
3725 && actual_type != None 3299 && actual_type != None
3726 && actual_format == 8) 3300 && actual_format == 8)
3727 str = (const char *)(value); 3301 str = (const char *)(value);
3728 3302
3729 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3303 tt_printf ("\033]%d;%s%c", op, str, resp);
3730 3304
3731 XFree (value); 3305 XFree (value);
3732 } 3306 }
3733 else 3307 else
3734 { 3308 {
3738 { 3312 {
3739 *eq = 0; 3313 *eq = 0;
3740 set_utf8_property (display->atom (str), eq + 1); 3314 set_utf8_property (display->atom (str), eq + 1);
3741 } 3315 }
3742 else 3316 else
3743 XDeleteProperty (disp, TermWin.parent[0], 3317 XDeleteProperty (dpy, parent[0],
3744 display->atom (str)); 3318 display->atom (str));
3745 } 3319 }
3746 break; 3320 break;
3747 3321
3748 case XTerm_Color: 3322 case XTerm_Color:
3750 { 3324 {
3751 if ((name = strchr (buf, ';')) == NULL) 3325 if ((name = strchr (buf, ';')) == NULL)
3752 break; 3326 break;
3753 3327
3754 *name++ = '\0'; 3328 *name++ = '\0';
3755 color = atoi (buf); 3329 color = atoi (buf) + minCOLOR;
3756 3330
3757 if (color < 0 || color >= TOTAL_COLORS) 3331 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3758 break; 3332 break;
3759 3333
3760 if ((buf = strchr (name, ';')) != NULL) 3334 if ((buf = strchr (name, ';')) != NULL)
3761 *buf++ = '\0'; 3335 *buf++ = '\0';
3762 3336
3763 if (name[0] == '?' && !name[1]) 3337 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 } 3338 }
3772 break; 3339 break;
3773 case XTerm_Color00: 3340 case XTerm_Color00:
3774 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3341 process_color_seq (op, Color_fg, str, resp);
3775 break; 3342 break;
3776 case XTerm_Color01: 3343 case XTerm_Color01:
3777 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3344 process_color_seq (op, Color_bg, str, resp);
3778 break; 3345 break;
3779#ifndef NO_CURSORCOLOR 3346#ifndef NO_CURSORCOLOR
3780 case XTerm_Color_cursor: 3347 case XTerm_Color_cursor:
3781 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3348 process_color_seq (op, Color_cursor, str, resp);
3782 break; 3349 break;
3783#endif 3350#endif
3784 case XTerm_Color_pointer_fg: 3351 case XTerm_Color_pointer_fg:
3785 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3352 process_color_seq (op, Color_pointer_fg, str, resp);
3786 break; 3353 break;
3787 case XTerm_Color_pointer_bg: 3354 case XTerm_Color_pointer_bg:
3788 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3355 process_color_seq (op, Color_pointer_bg, str, resp);
3789 break; 3356 break;
3790#ifndef NO_BOLD_UNDERLINE_REVERSE 3357#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: 3358 case XTerm_Color_RV:
3801 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3359 process_color_seq (op, Color_RV, str, resp);
3802 break; 3360 break;
3361 case Rxvt_Color_BD:
3362 case URxvt_Color_BD:
3363 process_color_seq (op, Color_BD, str, resp);
3364 break;
3365 case Rxvt_Color_UL:
3366 case URxvt_Color_UL:
3367 process_color_seq (op, Color_UL, str, resp);
3368 break;
3369 case URxvt_Color_IT:
3370 process_color_seq (op, Color_IT, str, resp);
3371 break;
3803#endif 3372#endif
3804#if TRANSPARENT && TINTING 3373#if ENABLE_TRANSPARENCY
3805 case XTerm_Color_tint: 3374 case URxvt_Color_tint:
3806 process_color_seq (XTerm_Color_tint, Color_tint, str, resp); 3375 process_color_seq (op, Color_tint, str, resp);
3807 check_our_parents (); 3376 {
3808 if (am_transparent) 3377 bool changed = false;
3809 want_full_refresh = want_refresh = 1; 3378 if (ISSET_PIXCOLOR (Color_tint))
3810 break; 3379 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3811#endif 3380 else
3381 changed = bgPixmap.unset_tint ();
3382 if (changed)
3383 update_background ();
3384 }
3812 3385
3386 break;
3387#endif
3388
3389#if BG_IMAGE_FROM_FILE
3813 case XTerm_Pixmap: 3390 case Rxvt_Pixmap:
3814 if (*str != ';') 3391 if (!strcmp (str, "?"))
3815 { 3392 {
3816#if XPM_BACKGROUND 3393 char str[256];
3817 scale_pixmap (""); /* reset to default scaling */ 3394
3818 set_bgPixmap (str); /* change pixmap */ 3395 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
3819#endif 3396 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3820 scr_touch (true); 3397 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3398 process_xterm_seq (XTerm_title, str, CHAR_ST);
3821 } 3399 }
3822 while ((str = strchr (str, ';')) != NULL) 3400 else
3823 { 3401 {
3402 int changed = 0;
3403
3404 if (*str != ';')
3405 {
3406 /* reset to default scaling :*/
3407 bgPixmap.unset_geometry ();
3408 if (bgPixmap.set_file (str)) /* change pixmap */
3409 changed++;
3410 str = strchr (str, ';');
3411 if (str == NULL)
3412 bgPixmap.set_defaultGeometry ();
3413 }
3414 while (str)
3415 {
3824 str++; 3416 str++;
3825#if XPM_BACKGROUND 3417 if (bgPixmap.set_geometry (str))
3826 changed += scale_pixmap (str); 3418 changed++;
3827#endif 3419 str = strchr (str, ';');
3420 }
3421 if (changed)
3422 update_background ();
3828 } 3423 }
3829
3830 if (changed)
3831 {
3832#ifdef XPM_BACKGROUND
3833 resize_pixmap ();
3834#endif
3835 scr_touch (true);
3836 }
3837 break; 3424 break;
3425#endif
3838 3426
3839 case XTerm_restoreFG: 3427 case Rxvt_restoreFG:
3840 set_window_color (Color_fg, str); 3428 set_window_color (Color_fg, str);
3841 break; 3429 break;
3842 case XTerm_restoreBG: 3430 case Rxvt_restoreBG:
3843 set_window_color (Color_bg, str); 3431 set_window_color (Color_bg, str);
3844 break; 3432 break;
3845 3433
3846 case XTerm_logfile: 3434 case XTerm_logfile:
3847 // TODO, when secure mode? 3435 // TODO, when secure mode?
3848 break; 3436 break;
3849 3437
3438#if 0
3439 case Rxvt_dumpscreen: /* no error notices */
3440 {
3441 int fd;
3442 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3443 {
3444 scr_dump (fd);
3445 close (fd);
3446 }
3447 }
3448 break;
3449#endif
3850 case XTerm_font: 3450 case XTerm_font:
3851 op = URxvt_font; 3451 op = URxvt_font;
3852 case URxvt_font: 3452 case URxvt_font:
3853#if ENABLE_STYLES 3453#if ENABLE_STYLES
3854 case URxvt_boldFont: 3454 case URxvt_boldFont:
3855 case URxvt_italicFont: 3455 case URxvt_italicFont:
3856 case URxvt_boldItalicFont: 3456 case URxvt_boldItalicFont:
3857#endif 3457#endif
3858 if (query) 3458 if (query)
3859 tt_printf ("\33]%d;%-.250s%c", saveop, 3459 tt_printf ("\33]%d;%-.250s%c", saveop,
3860 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3460 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3861 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3461 ? fontset[op - URxvt_font]->fontdesc : "",
3862 resp); 3462 resp);
3863 else 3463 else
3864 { 3464 {
3865 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3465 const char *&res = rs[Rs_font + (op - URxvt_font)];
3866 3466
3868 allocated.push_back ((void *)res); 3468 allocated.push_back ((void *)res);
3869 set_fonts (); 3469 set_fonts ();
3870 } 3470 }
3871 break; 3471 break;
3872 3472
3873#if ENABLE_FRILLS 3473 case URxvt_version:
3874 case XTerm_locale:
3875 if (query) 3474 if (query)
3475 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3476 op,
3477 rs[Rs_name], VERSION[0], VERSION[2],
3478 resp);
3479 break;
3480
3481#if !ENABLE_MINIMAL
3482 case URxvt_locale:
3483 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3484 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3877 else 3485 else
3878 { 3486 {
3879 set_locale (str); 3487 set_locale (str);
3880 pty.set_utf8_mode (enc_utf8); 3488 pty->set_utf8_mode (enc_utf8);
3881 init_xlocale (); 3489 init_xlocale ();
3882 } 3490 }
3883 break; 3491 break;
3884#endif
3885 3492
3886#ifdef MENUBAR 3493 case URxvt_view_up:
3887 case XTerm_Menu: 3494 case URxvt_view_down:
3888 if (options & Opt_insecure) 3495 {
3889 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3496 int lines = atoi (str);
3497
3498 if (lines)
3499 scr_page (op == URxvt_view_up ? UP : DN, lines);
3500 else
3501 scr_erase_savelines ();
3502 }
3503
3890 break; 3504 break;
3891#endif 3505#endif
3892#if 0 3506
3893 case XTerm_dumpscreen: /* no error notices */ 3507#if ENABLE_PERL
3894 { 3508 case URxvt_perl:
3895 int fd; 3509 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END)))
3896 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3510 ; // no responses yet
3897 {
3898 scr_dump (fd);
3899 close (fd);
3900 }
3901 }
3902 break; 3511 break;
3903#endif 3512#endif
3904 } 3513 }
3905} 3514}
3906/*----------------------------------------------------------------------*/ 3515/*----------------------------------------------------------------------*/
3937 return state; 3546 return state;
3938} 3547}
3939 3548
3940/* we're not using priv _yet_ */ 3549/* we're not using priv _yet_ */
3941void 3550void
3942rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3551rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3943{ 3552{
3944 unsigned int i, j; 3553 unsigned int i, j;
3945 int state; 3554 int state;
3946 3555
3947 static const struct 3556 static const struct
3948 { 3557 {
3949 const int argval; 3558 const int argval;
3950 const unsigned long bit; 3559 const unsigned long bit;
3951 }
3952
3953 argtopriv[] = { 3560 } argtopriv[] = {
3954 { 1, PrivMode_aplCUR }, 3561 { 1, PrivMode_aplCUR },
3955 { 2, PrivMode_vt52 }, 3562 { 2, PrivMode_vt52 },
3956 { 3, PrivMode_132 }, 3563 { 3, PrivMode_132 },
3957 { 4, PrivMode_smoothScroll }, 3564 { 4, PrivMode_smoothScroll },
3958 { 5, PrivMode_rVideo }, 3565 { 5, PrivMode_rVideo },
3959 { 6, PrivMode_relOrigin }, 3566 { 6, PrivMode_relOrigin },
3960 { 7, PrivMode_Autowrap }, 3567 { 7, PrivMode_Autowrap },
3961 // 8, bi-directional support mode 3568 // 8, bi-directional support mode
3962 { 9, PrivMode_MouseX10 }, 3569 { 9, PrivMode_MouseX10 },
3963#ifdef menuBar_esc
3964 { menuBar_esc, PrivMode_menuBar },
3965#endif
3966 // 18, 19 printing-related 3570 // 18, 19 printing-related
3967 { 25, PrivMode_VisibleCursor }, 3571 { 25, PrivMode_VisibleCursor },
3968#ifdef scrollBar_esc 3572#ifdef scrollBar_esc
3969 { scrollBar_esc, PrivMode_scrollBar }, 3573 { scrollBar_esc, PrivMode_scrollBar },
3970#endif 3574#endif
3978#ifndef NO_BACKSPACE_KEY 3582#ifndef NO_BACKSPACE_KEY
3979 { 67, PrivMode_BackSpace }, 3583 { 67, PrivMode_BackSpace },
3980#endif 3584#endif
3981 { 1000, PrivMode_MouseX11 }, 3585 { 1000, PrivMode_MouseX11 },
3982 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3586 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3983 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3587 { 1002, PrivMode_MouseBtnEvent },
3984 // 1003 Use All Motion Mouse Tracking. NYI, TODO 3588 { 1003, PrivMode_MouseAnyEvent },
3985 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3589 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3986 { 1011, PrivMode_Keypress }, // rxvt extension 3590 { 1011, PrivMode_Keypress }, // rxvt extension
3987 // 1035 enable modifiers for alt, numlock NYI 3591 // 1035 enable modifiers for alt, numlock NYI
3988 // 1036 send ESC for meta keys NYI 3592 // 1036 send ESC for meta keys NYI
3989 // 1037 send DEL for keypad delete NYI 3593 // 1037 send DEL for keypad delete NYI
4015 } 3619 }
4016 3620
4017 /* extra handling for values with state unkept */ 3621 /* extra handling for values with state unkept */
4018 switch (arg[i]) 3622 switch (arg[i])
4019 { 3623 {
3624#if ENABLE_STYLES
3625 case 1021:
3626 set_option (Opt_intensityStyles, mode);
3627
3628 scr_touch (true);
3629 break;
3630#endif
4020 case 1048: /* alternative cursor save */ 3631 case 1048: /* alternative cursor save */
4021 case 1049: 3632 case 1049:
4022 if (options & Opt_secondaryScreen) 3633 if (option (Opt_secondaryScreen))
4023 if (mode == 0) 3634 if (mode == 0)
4024 scr_cursor (RESTORE); 3635 scr_cursor (RESTORE);
4025 else if (mode == 1) 3636 else if (mode == 1)
4026 scr_cursor (SAVE); 3637 scr_cursor (SAVE);
4027 break; 3638 break;
4039 */ 3650 */
4040 PrivMode (1, PrivMode_vt52); 3651 PrivMode (1, PrivMode_vt52);
4041 break; 3652 break;
4042 case 3: /* 80/132 */ 3653 case 3: /* 80/132 */
4043 if (priv_modes & PrivMode_132OK) 3654 if (priv_modes & PrivMode_132OK)
4044 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 3655 set_widthheight (((state ? 132 : 80) * fwidth), height);
4045 break; 3656 break;
4046 case 4: /* smooth scrolling */ 3657 case 4: /* smooth scrolling */
4047 if (state)
4048 options &= ~Opt_jumpScroll;
4049 else
4050 options |= Opt_jumpScroll; 3658 set_option (Opt_jumpScroll, !state);
4051 break; 3659 break;
4052 case 5: /* reverse video */ 3660 case 5: /* reverse video */
4053 scr_rvideo_mode (state); 3661 scr_rvideo_mode (state);
4054 break; 3662 break;
4055 case 6: /* relative/absolute origins */ 3663 case 6: /* relative/absolute origins */
4059 scr_autowrap (state); 3667 scr_autowrap (state);
4060 break; 3668 break;
4061 /* case 8: - auto repeat, can't do on a per window basis */ 3669 /* case 8: - auto repeat, can't do on a per window basis */
4062 case 9: /* X10 mouse reporting */ 3670 case 9: /* X10 mouse reporting */
4063 if (state) /* orthogonal */ 3671 if (state) /* orthogonal */
4064 priv_modes &= ~PrivMode_MouseX11; 3672 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4065 break; 3673 break;
4066#ifdef menuBar_esc
4067 case menuBar_esc:
4068#ifdef MENUBAR
4069 map_menuBar (state);
4070#endif
4071 break;
4072#endif
4073#ifdef scrollBar_esc 3674#ifdef scrollBar_esc
4074 case scrollBar_esc: 3675 case scrollBar_esc:
4075 if (scrollbar_mapping (state)) 3676 if (scrollbar_mapping (state))
4076 { 3677 {
4077 resize_all_windows (0, 0, 0); 3678 resize_all_windows (0, 0, 0);
4089 break; 3690 break;
4090 /* case 66: - application key pad */ 3691 /* case 66: - application key pad */
4091 /* case 67: - backspace key */ 3692 /* case 67: - backspace key */
4092 case 1000: /* X11 mouse reporting */ 3693 case 1000: /* X11 mouse reporting */
4093 if (state) /* orthogonal */ 3694 if (state) /* orthogonal */
4094 priv_modes &= ~PrivMode_MouseX10; 3695 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4095 break; 3696 break;
4096#if 0 3697#if 0
4097 case 1001: 3698 case 1001:
4098 break; /* X11 mouse highlighting */ 3699 break; /* X11 mouse highlighting */
4099#endif 3700#endif
3701 case 1002:
3702 case 1003:
3703 if (state)
3704 {
3705 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3706 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3707 vt_emask_mouse = PointerMotionMask;
3708 }
3709 else
3710 vt_emask_mouse = NoEventMask;
3711 vt_select_input ();
3712 break;
4100 case 1010: /* scroll to bottom on TTY output inhibit */ 3713 case 1010: /* scroll to bottom on TTY output inhibit */
4101 if (state)
4102 options &= ~Opt_scrollTtyOutput;
4103 else
4104 options |= Opt_scrollTtyOutput; 3714 set_option (Opt_scrollTtyOutput, !state);
4105 break; 3715 break;
4106 case 1011: /* scroll to bottom on key press */ 3716 case 1011: /* scroll to bottom on key press */
4107 if (state)
4108 options |= Opt_scrollTtyKeypress; 3717 set_option (Opt_scrollTtyKeypress, state);
4109 else
4110 options &= ~Opt_scrollTtyKeypress;
4111 break; 3718 break;
4112 case 1047: /* secondary screen w/ clearing last */ 3719 case 1047: /* secondary screen w/ clearing last */
4113 if (options & Opt_secondaryScreen) 3720 if (option (Opt_secondaryScreen))
4114 if (current_screen != PRIMARY) 3721 if (current_screen != PRIMARY)
4115 scr_erase_screen (2); 3722 scr_erase_screen (2);
4116 scr_change_screen (state); 3723 scr_change_screen (state);
4117 break; 3724 break;
4118 case 1049: /* secondary screen w/ clearing first */ 3725 case 1049: /* secondary screen w/ clearing first */
4119 scr_change_screen (state); 3726 scr_change_screen (state);
4120 if (options & Opt_secondaryScreen) 3727 if (option (Opt_secondaryScreen))
4121 if (current_screen != PRIMARY) 3728 if (current_screen != PRIMARY)
4122 scr_erase_screen (2); 3729 scr_erase_screen (2);
4123 break; 3730 break;
4124 default: 3731 default:
4125 break; 3732 break;
4253 scr_color (Color_bg, Color_bg); 3860 scr_color (Color_bg, Color_bg);
4254 break; 3861 break;
4255 3862
4256 //case 50: // not variable spacing 3863 //case 50: // not variable spacing
4257 3864
4258#ifndef NO_BRIGHTCOLOR 3865#if !ENABLE_MINIMAL
4259 case 90: 3866 case 90:
4260 case 91: /* set bright fg color */ 3867 case 91: /* set bright fg color */
4261 case 92: 3868 case 92:
4262 case 93: 3869 case 93:
4263 case 94: 3870 case 94:
4275 case 106: 3882 case 106:
4276 case 107: 3883 case 107:
4277 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 3884 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4278 break; 3885 break;
4279#endif 3886#endif
4280
4281 } 3887 }
4282 } 3888 }
4283} 3889}
4284/*}}} */ 3890/*}}} */
4285 3891
4309 */ 3915 */
4310void 3916void
4311rxvt_term::tt_printf (const char *fmt,...) 3917rxvt_term::tt_printf (const char *fmt,...)
4312{ 3918{
4313 va_list arg_ptr; 3919 va_list arg_ptr;
4314 unsigned char buf[256]; 3920 char buf[256];
4315 3921
4316 va_start (arg_ptr, fmt); 3922 va_start (arg_ptr, fmt);
4317 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 3923 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4318 va_end (arg_ptr); 3924 va_end (arg_ptr);
4319 tt_write (buf, strlen (buf)); 3925 tt_write (buf, strlen (buf));
4324 * or generated by us in response to a query ESC sequence. 3930 * or generated by us in response to a query ESC sequence.
4325 */ 3931 */
4326const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 3932const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4327 3933
4328void 3934void
4329rxvt_term::tt_write (const unsigned char *data, unsigned int len) 3935rxvt_term::tt_write (const char *data, unsigned int len)
4330{ 3936{
3937 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
3938 return;
3939
3940 if (pty->pty < 0)
3941 return;
3942
4331 if (v_buflen == 0) 3943 if (v_buflen == 0)
4332 { 3944 {
4333 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 3945 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4334 3946
4335 if ((unsigned int)written == len) 3947 if ((unsigned int)written == len)
4336 return; 3948 return;
4337 3949
4338 data += written; 3950 data += written;
4339 len -= written; 3951 len -= written;
4340 } 3952 }
4341 3953
4342 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 3954 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4343 3955
4344 memcpy (v_buffer + v_buflen, data, len); 3956 memcpy (v_buffer + v_buflen, data, len);
4345 v_buflen += len; 3957 v_buflen += len;
4346 3958
4347 pty_ev.set (EVENT_READ | EVENT_WRITE); 3959 pty_ev.set (ev::READ | ev::WRITE);
4348} 3960}
4349 3961
4350void rxvt_term::pty_write () 3962void rxvt_term::pty_write ()
4351{ 3963{
4352 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 3964 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4353 3965
4354 if (written > 0) 3966 if (written > 0)
4355 { 3967 {
4356 v_buflen -= written; 3968 v_buflen -= written;
4357 3969
4358 if (v_buflen == 0) 3970 if (v_buflen == 0)
4359 { 3971 {
4360 free (v_buffer); 3972 free (v_buffer);
4361 v_buffer = 0; 3973 v_buffer = 0;
4362 v_buflen = 0;
4363 3974
4364 pty_ev.set (EVENT_READ); 3975 pty_ev.set (ev::READ);
4365 return; 3976 return;
4366 } 3977 }
4367 3978
4368 memmove (v_buffer, v_buffer + written, v_buflen); 3979 memmove (v_buffer, v_buffer + written, v_buflen);
4369 } 3980 }
4370 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 3981 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4371 // original code just ignores this... 3982 pty_ev.set (ev::READ);
4372 destroy ();
4373} 3983}
4374 3984
4375/*----------------------- end-of-file (C source) -----------------------*/ 3985/*----------------------- end-of-file (C source) -----------------------*/
4376 3986

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines