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.216 by root, Tue Dec 27 01:25:42 2005 UTC vs.
Revision 1.508 by sf-exg, Fri Apr 13 09:23:58 2012 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-2011 Marc Lehmann <schmorp@schmorp.de>
31 * Copyright (c) 2007 Emanuele Giaquinta <e.giaquinta@glauco.it>
31 * 32 *
32 * This program is free software; you can redistribute it and/or modify 33 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by 34 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or 35 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version. 36 * (at your option) any later version.
43 * along with this program; if not, write to the Free Software 44 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/ 46 *----------------------------------------------------------------------*/
46 47
47/*{{{ includes: */ 48/*{{{ includes: */
48#include "../config.h" /* NECESSARY */ 49#include "../config.h"
49#include "rxvt.h" /* NECESSARY */ 50#include "rxvt.h"
51#include "rxvtperl.h"
50#include "version.h" 52#include "version.h"
51#include "command.h" 53#include "command.h"
52 54
53#ifdef KEYSYM_RESOURCE 55#ifdef KEYSYM_RESOURCE
54# include "keyboard.h" 56# include "keyboard.h"
55#endif 57#endif
56 58
57#include <csignal> 59#include <signal.h>
60
61#if LINUX_YIELD_HACK
62# include <time.h>
63#endif
58 64
59/*----------------------------------------------------------------------*/ 65/*----------------------------------------------------------------------*/
60 66
61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 67#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 68
66#if ENABLE_FRILLS || ISO_14755 69#if ENABLE_FRILLS || ISO_14755
67 70
68#define ISO_14755_STARTED 0x80000000UL 71#define ISO_14755_STARTED 0x80000000UL
69#define ISO_14755_51 0x40000000UL // basic (section 5.1) 72#define ISO_14755_51 0x40000000UL // basic (section 5.1)
93 XK_Shift_L, 0x21e7, 96 XK_Shift_L, 0x21e7,
94 XK_Shift_R, 0x21e7, 97 XK_Shift_R, 0x21e7,
95 98
96 XK_Shift_Lock, 0x21eb, 99 XK_Shift_Lock, 0x21eb,
97 XK_ISO_Lock, 0x21eb, 100 XK_ISO_Lock, 0x21eb,
98 XK_ISO_Lock, 0x21eb,
99 XK_Caps_Lock, 0x21ec, 101 XK_Caps_Lock, 0x21ec,
100 XK_Num_Lock, 0x21ed, 102 XK_Num_Lock, 0x21ed,
101 XK_ISO_Level3_Shift, 0x21ee, 103 XK_ISO_Level3_Shift, 0x21ee,
102 XK_ISO_Level3_Lock, 0x21ef, 104 XK_ISO_Level3_Lock, 0x21ef,
103 XK_ISO_Group_Lock, 0x21f0, 105 XK_ISO_Group_Lock, 0x21f0,
141 || !IN_RANGE_EXC (y, 0, nrow)) 143 || !IN_RANGE_EXC (y, 0, nrow))
142 return; 144 return;
143 145
144 for (;;) 146 for (;;)
145 { 147 {
146 const line_t &l = ROW(y - view_start); 148 const line_t &l = ROW(y + view_start);
147 149
148 text_t t = l.t[x]; 150 text_t t = l.t[x];
149 151
150 if (t != NOCHAR || !x) 152 if (t != NOCHAR || !x)
151 { 153 {
152 iso14755_51 (l.t[x], l.r[x]); 154 iso14755_51 (l.t[x], l.r[x], x, y);
153 iso14755buf = ISO_14755_54; 155 iso14755buf = ISO_14755_54;
154 break; 156 break;
155 } 157 }
156 158
157 x--; 159 x--;
158 } 160 }
159} 161}
160#endif
161 162
162#if ENABLE_OVERLAY
163void 163void
164rxvt_term::iso14755_51 (unicode_t ch, rend_t r) 164rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
165{ 165{
166 rxvt_fontset *fs = FONTSET (r); 166 rxvt_fontset *fs = FONTSET (r);
167 rxvt_font *f = (*fs)[fs->find_font (ch)];
168 wchar_t *chr, *alloc, ch2, *fname; 167 wchar_t *chr, *alloc, ch2, **fname;
169 int len; 168 int len;
170 169
171 fname = rxvt_utf8towcs (f->name);
172
173#if ENABLE_COMBINING 170# if ENABLE_COMBINING
174 if (IS_COMPOSE (ch)) 171 if (IS_COMPOSE (ch))
175 { 172 {
176 len = rxvt_composite.expand (ch, 0); 173 len = rxvt_composite.expand (ch, 0);
177 alloc = chr = new wchar_t[len]; 174 alloc = chr = new wchar_t[len];
178 rxvt_composite.expand (ch, chr); 175 rxvt_composite.expand (ch, chr);
179 } 176 }
180 else 177 else
181#endif 178# endif
182 { 179 {
183 ch2 = ch; 180 ch2 = ch;
184 181
185 alloc = 0; 182 alloc = 0;
186 chr = &ch2; 183 chr = &ch2;
189 186
190 char attr[80]; // plenty 187 char attr[80]; // plenty
191 188
192 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", 189 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
193 (int)r, 190 (int)r,
194 GET_FGCOLOR (r), GET_BGCOLOR (r), 191 fgcolor_of (r), bgcolor_of (r),
195 r & RS_Bold ? " bold" : "", 192 r & RS_Bold ? " bold" : "",
196 r & RS_Italic ? " italic" : "", 193 r & RS_Italic ? " italic" : "",
197 r & RS_Blink ? " blink" : "", 194 r & RS_Blink ? " blink" : "",
198 r & RS_RVid ? " rvid" : "", 195 r & RS_RVid ? " rvid" : "",
199 r & RS_Uline ? " uline" : "", 196 r & RS_Uline ? " uline" : "",
200 r & RS_Careful ? " careful" : ""); 197 r & RS_Careful ? " careful" : "");
201 198
199 int width = 0;
200 fname = rxvt_temp_buf<wchar_t *> (len);
201 for (int i = 0; i < len; i++)
202 {
203 rxvt_font *f = (*fs)[fs->find_font_idx (chr[i])];
204 fname[i] = rxvt_utf8towcs (f->name);
202 int width = wcswidth (fname, wcslen (fname)); 205 max_it (width, wcswidth (fname[i], wcslen (fname[i])));
206 }
203 207
204 max_it (width, 8+5); // for char + hey 208 max_it (width, 8+5); // for char + hex
205 max_it (width, strlen (attr)); 209 max_it (width, strlen (attr));
206 210
211 if (y >= 0)
212 {
213 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
214 x = 0;
215 }
216
207 scr_overlay_new (0, -1, width, len + 2); 217 scr_overlay_new (x, y, width, len * 2 + 1);
208 218
209 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 219 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
210 220
211 for (int y = 0; y < len; y++) 221 for (int y = 0; y < len; y++)
212 { 222 {
215 ch = *chr++; 225 ch = *chr++;
216 226
217 sprintf (buf, "%8x", ch); 227 sprintf (buf, "%8x", ch);
218 scr_overlay_set (0, y, buf); 228 scr_overlay_set (0, y, buf);
219 scr_overlay_set (9, y, '='); 229 scr_overlay_set (9, y, '=');
220#if !UNICODE3 230# if !UNICODE_3
221 if (ch >= 0x10000) 231 if (ch >= 0x10000)
222 ch = 0xfffd; 232 ch = 0xfffd;
223#endif 233# endif
224 scr_overlay_set (11, y, ch, r); 234 scr_overlay_set (11, y, ch, r);
235
236 if (WCWIDTH (ch) >= 2)
225 scr_overlay_set (12, y, NOCHAR, r); 237 scr_overlay_set (12, y, NOCHAR, r);
226 } 238 }
227 239
240// {
241// char buf[4+4+3+1];
242// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y);
243// scr_overlay_set (0, 0, buf);
244// }
228 scr_overlay_set (0, len , attr); 245 scr_overlay_set (0, len , attr);
246 for (int i = 0; i < len; i++)
247 {
229 scr_overlay_set (0, len + 1, fname); 248 scr_overlay_set (0, len + 1 + i, fname[i]);
230
231 free (fname); 249 free (fname[i]);
250 }
232 251
233#if ENABLE_COMBINING 252# if ENABLE_COMBINING
234 if (alloc) 253 if (alloc)
235 delete [] alloc; 254 delete [] alloc;
236#endif 255# endif
237} 256}
238#endif 257#endif
239 258
240void 259void
241rxvt_term::commit_iso14755 () 260rxvt_term::commit_iso14755 ()
242{ 261{
243 wchar_t ch[2];
244
245 ch[0] = iso14755buf & ISO_14755_MASK; 262 wchar_t ch = iso14755buf & ISO_14755_MASK;
246 ch[1] = 0;
247 263
248 if (iso14755buf & ISO_14755_51) 264 if (iso14755buf & ISO_14755_51)
249 { 265 {
250 char mb[16]; 266 char mb[MB_LEN_MAX];
251 int len; 267 int len;
252 268
253 // allow verbatim 0-bytes and control-bytes to be entered 269 // allow verbatim 0-bytes and control-bytes to be entered
254 if (ch[0] >= 0x20) 270 if (ch >= 0x20)
255 len = wcstombs (mb, ch, 16); 271 len = wctomb (mb, ch);
256 else 272 else
257 { 273 {
258 mb[0] = ch[0]; 274 mb[0] = ch;
259 len = 1; 275 len = 1;
260 } 276 }
261 277
262 if (len > 0) 278 if (len > 0)
263 tt_write ((unsigned char *)mb, len); 279 tt_write (mb, len);
264 else 280 else
265 scr_bell (); 281 scr_bell ();
266 } 282 }
267 283
268 iso14755buf = 0; 284 iso14755buf = 0;
269} 285}
270 286
271int 287static int
272rxvt_term::hex_keyval (XKeyEvent &ev) 288hex_keyval (XKeyEvent &ev)
273{ 289{
274 // check wether this event corresponds to a hex digit 290 // check whether this event corresponds to a hex digit
275 // if the modifiers had not been pressed. 291 // if the modifiers had not been pressed.
276 for (int index = 0; index < 8; index++) 292 for (int index = 0; index < 8; index++)
277 { 293 {
278 KeySym k = XLookupKeysym (&ev, index); 294 KeySym k = XLookupKeysym (&ev, index);
279 295
285 301
286 return -1; 302 return -1;
287} 303}
288#endif 304#endif
289 305
290/*{{{ Convert the keypress event into a string */ 306static inline KeySym
307translate_keypad (KeySym keysym, bool kp)
308{
309#ifdef XK_KP_Home
310 static const KeySym keypadtrans[] = {
311 XK_KP_7, // XK_KP_Home
312 XK_KP_4, // XK_KP_Left
313 XK_KP_8, // XK_KP_Up
314 XK_KP_6, // XK_KP_Right
315 XK_KP_2, // XK_KP_Down
316# ifndef UNSHIFTED_SCROLLKEYS
317 XK_KP_9, // XK_KP_Prior
318 XK_KP_3, // XK_KP_Next
319# else
320 XK_Prior,
321 XK_Next,
322# endif
323 XK_KP_1, // XK_KP_End
324 XK_KP_5, // XK_KP_Begin
325 };
326
327 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin))
328 {
329 unsigned int index = keysym - XK_KP_Home;
330 keysym = kp ? keypadtrans[index] : XK_Home + index;
331 }
332 else if (keysym == XK_KP_Insert)
333 keysym = kp ? XK_KP_0 : XK_Insert;
334# ifndef NO_DELETE_KEY
335 else if (keysym == XK_KP_Delete)
336 keysym = kp ? XK_KP_Decimal : XK_Delete;
337# endif
338#endif
339 return keysym;
340}
341
342static inline int
343map_function_key (KeySym keysym)
344{
345 int param = 0;
346
347 if (IN_RANGE_INC (keysym, XK_F1, XK_F35))
348 {
349 param = 11 + keysym - XK_F1;
350 if (keysym >= XK_F17)
351 param += 4;
352 else if (keysym >= XK_F15)
353 param += 3;
354 else if (keysym >= XK_F11)
355 param += 2;
356 else if (keysym >= XK_F6)
357 param += 1;
358 }
359 else
360 switch (keysym)
361 {
362 case XK_Find:
363 param = 1;
364 break;
365 case XK_Insert:
366 param = 2;
367 break;
368#ifdef DXK_Remove
369 case DXK_Remove:
370#endif
371 case XK_Execute:
372 param = 3;
373 break;
374 case XK_Select:
375 param = 4;
376 break;
377#ifndef UNSHIFTED_SCROLLKEYS
378 case XK_Prior:
379 param = 5;
380 break;
381 case XK_Next:
382 param = 6;
383 break;
384 case XK_Home:
385 param = 7;
386 break;
387 case XK_End:
388 param = 8;
389 break;
390#endif
391 case XK_Help:
392 param = 28;
393 break;
394 case XK_Menu:
395 param = 29;
396 break;
397 }
398 return param;
399}
400
291void 401void
292rxvt_term::lookup_key (XKeyEvent &ev) 402rxvt_term::key_press (XKeyEvent &ev)
293{ 403{
294 int ctrl, meta, shft, len; 404 int ctrl, meta, shft, len;
295 unsigned int newlen;
296 KeySym keysym; 405 KeySym keysym;
297#ifdef DEBUG_CMD
298 static int debug_key = 1; /* accessible by a debugger only */
299#endif
300 int valid_keysym; 406 int valid_keysym;
301 unsigned char kbuf[KBUFSZ]; 407 char kbuf[KBUFSZ];
408
409#if ISO_14755
410 if (iso14755buf & ISO_14755_52)
411 return;
412#endif
302 413
303 /* 414 /*
304 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 415 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
305 * escape sequence to toggle the Keypad. 416 * escape sequence to toggle the Keypad.
306 * 417 *
308 */ 419 */
309 shft = ev.state & ShiftMask; 420 shft = ev.state & ShiftMask;
310 ctrl = ev.state & ControlMask; 421 ctrl = ev.state & ControlMask;
311 meta = ev.state & ModMetaMask; 422 meta = ev.state & ModMetaMask;
312 423
313 if (numlock_state || (ev.state & ModNumLockMask))
314 {
315 numlock_state = (ev.state & ModNumLockMask);
316 PrivMode ((!numlock_state), PrivMode_aplKP);
317 }
318
319 kbuf[0] = 0; 424 kbuf[0] = 0;
320 425
321#ifdef USE_XIM 426#ifdef USE_XIM
322 if (Input_Context) 427 if (Input_Context)
323 { 428 {
324 Status status_return; 429 Status status_return;
325 430
326#if 0 431#if 0
327#ifdef X_HAVE_UTF8_STRING 432#ifdef X_HAVE_UTF8_STRING
328 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 433 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
329 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 434 len = Xutf8LookupString (Input_Context, &ev, kbuf,
330 KBUFSZ, &keysym, &status_return); 435 KBUFSZ, &keysym, &status_return);
331 else 436 else
332#endif 437#endif
333#endif 438#endif
334 { 439 {
371 || status_return == XLookupBoth; 476 || status_return == XLookupBoth;
372 } 477 }
373 else 478 else
374#endif 479#endif
375 { 480 {
376 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 481 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
377 valid_keysym = keysym != NoSymbol; 482 valid_keysym = keysym != NoSymbol;
378 } 483 }
379 484
380 if (valid_keysym) 485 if (valid_keysym)
381 { 486 {
397#ifdef PAGING_CONTEXT_LINES 502#ifdef PAGING_CONTEXT_LINES
398 lnsppg = nrow - PAGING_CONTEXT_LINES; 503 lnsppg = nrow - PAGING_CONTEXT_LINES;
399#else 504#else
400 lnsppg = nrow * 4 / 5; 505 lnsppg = nrow * 4 / 5;
401#endif 506#endif
507 max_it (lnsppg, 1);
508
402 if (keysym == XK_Prior) 509 if (keysym == XK_Prior)
403 { 510 {
404 scr_page (UP, lnsppg); 511 scr_page (UP, lnsppg);
405 return; 512 return;
406 } 513 }
433 scr_move_to (0, 1); 540 scr_move_to (0, 1);
434 return; 541 return;
435 } 542 }
436 else if (keysym == XK_End) 543 else if (keysym == XK_End)
437 { 544 {
438 scr_move_to (1, 0); 545 scr_move_to (1, 1);
439 return; 546 return;
440 } 547 }
441 } 548 }
442#endif 549#endif
443 } 550 }
454 { 561 {
455 switch (keysym) 562 switch (keysym)
456 { 563 {
457 /* normal XTerm key bindings */ 564 /* normal XTerm key bindings */
458 case XK_Insert: /* Shift+Insert = paste mouse selection */ 565 case XK_Insert: /* Shift+Insert = paste mouse selection */
459 selection_request (ev.time, 0, 0); 566 selection_request (ev.time);
460 return; 567 return;
461#if TODO 568#if TODO
462 /* rxvt extras */ 569 /* rxvt extras */
463 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 570 case XK_KP_Add: /* Shift+KP_Add = bigger font */
464 change_font (FONT_UP);
465 return; 571 return;
466 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 572 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
467 change_font (FONT_DN);
468 return; 573 return;
469#endif 574#endif
470 } 575 }
471 } 576 }
472 } 577 }
473 578
474#if ENABLE_FRILLS || ISO_14755 579#if ENABLE_FRILLS || ISO_14755
475 // ISO 14755 support 580 // ISO 14755 support
476 if (shft && ctrl) 581 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51))
477 { 582 {
478 int hv; 583 int hv;
479 584
480 if (iso14755buf & ISO_14755_51 585 if (iso14755buf & ISO_14755_51
481 && (keysym == XK_space || keysym == XK_KP_Space 586 && (keysym == XK_space || keysym == XK_KP_Space
483 { 588 {
484 commit_iso14755 (); 589 commit_iso14755 ();
485 iso14755buf = ISO_14755_51; 590 iso14755buf = ISO_14755_51;
486# if ISO_14755 591# if ISO_14755
487 iso14755_51 (0); 592 iso14755_51 (0);
593# endif
594 return;
595 }
596 else if (keysym == XK_BackSpace)
597 {
598 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
599# if ISO_14755
600 iso14755_51 (iso14755buf & ISO_14755_MASK);
488# endif 601# endif
489 return; 602 return;
490 } 603 }
491 else if ((hv = hex_keyval (ev)) >= 0) 604 else if ((hv = hex_keyval (ev)) >= 0)
492 { 605 {
497# endif 610# endif
498 return; 611 return;
499 } 612 }
500 else 613 else
501 { 614 {
502# if ENABLE_OVERLAY 615# if ISO_14755
503 scr_overlay_off (); 616 scr_overlay_off ();
504# endif 617# endif
505 iso14755buf = 0; 618 iso14755buf = 0;
506 } 619 }
507 } 620 }
621 else if (option (Opt_iso14755) &&
508 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 622 ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
509 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 623 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))))
510 if (!(iso14755buf & ISO_14755_STARTED)) 624 if (!(iso14755buf & ISO_14755_STARTED))
511 { 625 {
512 iso14755buf |= ISO_14755_STARTED; 626 iso14755buf |= ISO_14755_STARTED;
513# if ENABLE_OVERLAY 627# if ISO_14755
514 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 628 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
515 scr_overlay_set (0, 0, "ISO 14755 mode"); 629 scr_overlay_set (0, 0, "ISO 14755 mode");
516# endif 630# endif
517 } 631 }
518#endif 632#endif
519 633
520#ifdef PRINTPIPE 634#ifdef PRINTPIPE
521 if (keysym == XK_Print) 635 if (keysym == XK_Print)
522 { 636 {
523 scr_printscreen (ctrl | shft); 637 scr_printscreen (ctrl | shft);
524 return; 638 return;
525 } 639 }
526#endif 640#endif
527 641
528 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 642 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
529 { 643 {
644 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
645 unsigned int newlen = 1;
646
647 if (ev.state & ModNumLockMask)
648 kp = false;
649
650 keysym = translate_keypad (keysym, kp);
651
652 switch (keysym)
530 { 653 {
654#ifndef NO_BACKSPACE_KEY
655 case XK_BackSpace:
656 if (priv_modes & PrivMode_HaveBackSpace)
657 {
658 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
659 ^ !!ctrl) ? '\b' : '\177';
660 kbuf[1] = '\0';
661 }
662 else
663 strcpy (kbuf, rs[Rs_backspace_key]);
664 break;
665#endif
666#ifndef NO_DELETE_KEY
667 case XK_Delete:
668 strcpy (kbuf, rs[Rs_delete_key]);
669 break;
670#endif
671 case XK_Tab:
672 if (shft)
673 strcpy (kbuf, "\033[Z");
674 else
675 {
676#ifdef CTRL_TAB_MAKES_META
677 if (ctrl)
678 meta = 1;
679#endif
680#ifdef MOD4_TAB_MAKES_META
681 if (ev.state & Mod4Mask)
682 meta = 1;
683#endif
531 newlen = 1; 684 newlen = 0;
532 switch (keysym) 685 }
686 break;
687
688 case XK_Up: /* "\033[A" */
689 case XK_Down: /* "\033[B" */
690 case XK_Right: /* "\033[C" */
691 case XK_Left: /* "\033[D" */
692 strcpy (kbuf, "\033[Z");
693 kbuf[2] = "DACB"[keysym - XK_Left];
694 /* do Shift first */
695 if (shft)
696 kbuf[2] = "dacb"[keysym - XK_Left];
697 else if (ctrl)
698 {
699 kbuf[1] = 'O';
700 kbuf[2] = "dacb"[keysym - XK_Left];
701 }
702 else if (priv_modes & PrivMode_aplCUR)
703 kbuf[1] = 'O';
704 break;
705
706 case XK_KP_Enter:
707 /* allow shift to override */
708 if (kp)
709 {
710 strcpy (kbuf, "\033OM");
711 break;
712 }
713
714 /* FALLTHROUGH */
715
716 case XK_Return:
717 if (priv_modes & PrivMode_LFNL)
718 {
719 kbuf[0] = '\015';
720 kbuf[1] = '\012';
721 kbuf[2] = '\0';
722 }
723 else
724 {
725 kbuf[0] = '\015';
726 kbuf[1] = '\0';
727 }
728 break;
729
730 case XK_KP_F1: /* "\033OP" */
731 case XK_KP_F2: /* "\033OQ" */
732 case XK_KP_F3: /* "\033OR" */
733 case XK_KP_F4: /* "\033OS" */
734 strcpy (kbuf, "\033OP");
735 kbuf[2] += (keysym - XK_KP_F1);
736 break;
737
738 case XK_KP_Multiply: /* "\033Oj" : "*" */
739 case XK_KP_Add: /* "\033Ok" : "+" */
740 case XK_KP_Separator: /* "\033Ol" : "," */
741 case XK_KP_Subtract: /* "\033Om" : "-" */
742 case XK_KP_Decimal: /* "\033On" : "." */
743 case XK_KP_Divide: /* "\033Oo" : "/" */
744 case XK_KP_0: /* "\033Op" : "0" */
745 case XK_KP_1: /* "\033Oq" : "1" */
746 case XK_KP_2: /* "\033Or" : "2" */
747 case XK_KP_3: /* "\033Os" : "3" */
748 case XK_KP_4: /* "\033Ot" : "4" */
749 case XK_KP_5: /* "\033Ou" : "5" */
750 case XK_KP_6: /* "\033Ov" : "6" */
751 case XK_KP_7: /* "\033Ow" : "7" */
752 case XK_KP_8: /* "\033Ox" : "8" */
753 case XK_KP_9: /* "\033Oy" : "9" */
754 /* allow shift to override */
755 if (kp)
756 {
757 strcpy (kbuf, "\033Oj");
758 kbuf[2] += (keysym - XK_KP_Multiply);
759 }
760 else
761 {
762 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
763 kbuf[1] = '\0';
764 }
765 break;
766
767 default:
533 { 768 {
534#ifndef NO_BACKSPACE_KEY 769 int param = map_function_key (keysym);
535 case XK_BackSpace: 770 if (param > 0)
536 if (priv_modes & PrivMode_HaveBackSpace) 771 sprintf (kbuf,"\033[%d~", param);
537 {
538 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
539 ^ !!ctrl) ? '\b' : '\177';
540 kbuf[1] = '\0';
541 }
542 else 772 else
543 strcpy (kbuf, key_backspace);
544 break;
545#endif
546#ifndef NO_DELETE_KEY
547# ifdef XK_KP_Prior
548 case XK_KP_Delete:
549 /* allow shift to override */
550 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
551 {
552 strcpy (kbuf, "\033On");
553 break;
554 }
555 /* FALLTHROUGH */
556# endif
557 case XK_Delete:
558 strcpy (kbuf, key_delete);
559 break;
560#endif
561 case XK_Tab:
562 if (shft)
563 strcpy (kbuf, "\033[Z");
564 else
565 {
566#ifdef CTRL_TAB_MAKES_META
567 if (ctrl)
568 meta = 1;
569#endif
570#ifdef MOD4_TAB_MAKES_META
571 if (ev.state & Mod4Mask)
572 meta = 1;
573#endif
574 newlen = 0;
575 }
576 break;
577
578#ifdef XK_KP_Left
579 case XK_KP_Up: /* \033Ox or standard */
580 case XK_KP_Down: /* \033Or or standard */
581 case XK_KP_Right: /* \033Ov or standard */
582 case XK_KP_Left: /* \033Ot or standard */
583 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
584 {
585 strcpy (kbuf, "\033OZ");
586 kbuf[2] = "txvr"[keysym - XK_KP_Left];
587 break;
588 }
589 else
590 /* translate to std. cursor key */
591 keysym = XK_Left + (keysym - XK_KP_Left);
592 /* FALLTHROUGH */
593#endif
594 case XK_Up: /* "\033[A" */
595 case XK_Down: /* "\033[B" */
596 case XK_Right: /* "\033[C" */
597 case XK_Left: /* "\033[D" */
598 strcpy (kbuf, "\033[Z");
599 kbuf[2] = "DACB"[keysym - XK_Left];
600 /* do Shift first */
601 if (shft)
602 kbuf[2] = "dacb"[keysym - XK_Left];
603 else if (ctrl)
604 {
605 kbuf[1] = 'O';
606 kbuf[2] = "dacb"[keysym - XK_Left];
607 }
608 else if (priv_modes & PrivMode_aplCUR)
609 kbuf[1] = 'O';
610 break;
611
612#ifndef UNSHIFTED_SCROLLKEYS
613# ifdef XK_KP_Prior
614 case XK_KP_Prior:
615 /* allow shift to override */
616 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
617 {
618 strcpy (kbuf, "\033Oy");
619 break;
620 }
621 /* FALLTHROUGH */
622# endif
623 case XK_Prior:
624 strcpy (kbuf, "\033[5~");
625 break;
626# ifdef XK_KP_Next
627 case XK_KP_Next:
628 /* allow shift to override */
629 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
630 {
631 strcpy (kbuf, "\033Os");
632 break;
633 }
634 /* FALLTHROUGH */
635# endif
636 case XK_Next:
637 strcpy (kbuf, "\033[6~");
638 break;
639#endif
640 case XK_KP_Enter:
641 /* allow shift to override */
642 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
643 {
644 strcpy (kbuf, "\033OM");
645 break;
646 }
647
648 /* FALLTHROUGH */
649
650 case XK_Return:
651 if (priv_modes & PrivMode_LFNL)
652 {
653 kbuf[0] = '\015';
654 kbuf[1] = '\012';
655 kbuf[2] = '\0';
656 }
657 else
658 {
659 kbuf[0] = '\015';
660 kbuf[1] = '\0';
661 }
662 break;
663
664#ifdef XK_KP_Begin
665 case XK_KP_Begin:
666 strcpy (kbuf, "\033Ou");
667 break;
668
669#endif
670 case XK_KP_F1: /* "\033OP" */
671 case XK_KP_F2: /* "\033OQ" */
672 case XK_KP_F3: /* "\033OR" */
673 case XK_KP_F4: /* "\033OS" */
674 strcpy (kbuf, "\033OP");
675 kbuf[2] += (keysym - XK_KP_F1);
676 break;
677
678 case XK_KP_Multiply: /* "\033Oj" : "*" */
679 case XK_KP_Add: /* "\033Ok" : "+" */
680 case XK_KP_Separator: /* "\033Ol" : "," */
681 case XK_KP_Subtract: /* "\033Om" : "-" */
682 case XK_KP_Decimal: /* "\033On" : "." */
683 case XK_KP_Divide: /* "\033Oo" : "/" */
684 case XK_KP_0: /* "\033Op" : "0" */
685 case XK_KP_1: /* "\033Oq" : "1" */
686 case XK_KP_2: /* "\033Or" : "2" */
687 case XK_KP_3: /* "\033Os" : "3" */
688 case XK_KP_4: /* "\033Ot" : "4" */
689 case XK_KP_5: /* "\033Ou" : "5" */
690 case XK_KP_6: /* "\033Ov" : "6" */
691 case XK_KP_7: /* "\033Ow" : "7" */
692 case XK_KP_8: /* "\033Ox" : "8" */
693 case XK_KP_9: /* "\033Oy" : "9" */
694 /* allow shift to override */
695 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
696 {
697 strcpy (kbuf, "\033Oj");
698 kbuf[2] += (keysym - XK_KP_Multiply);
699 }
700 else
701 {
702 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
703 kbuf[1] = '\0';
704 }
705 break;
706
707 case XK_Find:
708 strcpy (kbuf, "\033[1~");
709 break;
710
711#ifdef XK_KP_End
712 case XK_KP_Insert:
713 /* allow shift to override */
714 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
715 {
716 strcpy (kbuf, "\033Op");
717 break;
718 }
719 /* FALLTHROUGH */
720#endif
721 case XK_Insert:
722 strcpy (kbuf, "\033[2~");
723 break;
724#ifdef DXK_Remove /* support for DEC remove like key */
725 case DXK_Remove:
726 /* FALLTHROUGH */
727#endif
728 case XK_Execute:
729 strcpy (kbuf, "\033[3~");
730 break;
731 case XK_Select:
732 strcpy (kbuf, "\033[4~");
733 break;
734#ifdef XK_KP_End
735 case XK_KP_End:
736 /* allow shift to override */
737 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
738 {
739 strcpy (kbuf, "\033Oq");
740 break;
741 }
742 /* FALLTHROUGH */
743#endif
744 case XK_End:
745 strcpy (kbuf, KS_END);
746 break;
747#ifdef XK_KP_Home
748 case XK_KP_Home:
749 /* allow shift to override */
750 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
751 {
752 strcpy (kbuf, "\033Ow");
753 break;
754 }
755 /* FALLTHROUGH */
756#endif
757 case XK_Home:
758 strcpy (kbuf, KS_HOME);
759 break;
760
761#define FKEY(n, fkey) \
762 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
763
764 case XK_F1: /* "\033[11~" */
765 case XK_F2: /* "\033[12~" */
766 case XK_F3: /* "\033[13~" */
767 case XK_F4: /* "\033[14~" */
768 case XK_F5: /* "\033[15~" */
769 FKEY (11, XK_F1);
770 break;
771 case XK_F6: /* "\033[17~" */
772 case XK_F7: /* "\033[18~" */
773 case XK_F8: /* "\033[19~" */
774 case XK_F9: /* "\033[20~" */
775 case XK_F10: /* "\033[21~" */
776 FKEY (17, XK_F6);
777 break;
778 case XK_F11: /* "\033[23~" */
779 case XK_F12: /* "\033[24~" */
780 case XK_F13: /* "\033[25~" */
781 case XK_F14: /* "\033[26~" */
782 FKEY (23, XK_F11);
783 break;
784 case XK_F15: /* "\033[28~" */
785 case XK_F16: /* "\033[29~" */
786 FKEY (28, XK_F15);
787 break;
788 case XK_Help: /* "\033[28~" */
789 FKEY (28, XK_Help);
790 break;
791 case XK_Menu: /* "\033[29~" */
792 FKEY (29, XK_Menu);
793 break;
794 case XK_F17: /* "\033[31~" */
795 case XK_F18: /* "\033[32~" */
796 case XK_F19: /* "\033[33~" */
797 case XK_F20: /* "\033[34~" */
798 case XK_F21: /* "\033[35~" */
799 case XK_F22: /* "\033[36~" */
800 case XK_F23: /* "\033[37~" */
801 case XK_F24: /* "\033[38~" */
802 case XK_F25: /* "\033[39~" */
803 case XK_F26: /* "\033[40~" */
804 case XK_F27: /* "\033[41~" */
805 case XK_F28: /* "\033[42~" */
806 case XK_F29: /* "\033[43~" */
807 case XK_F30: /* "\033[44~" */
808 case XK_F31: /* "\033[45~" */
809 case XK_F32: /* "\033[46~" */
810 case XK_F33: /* "\033[47~" */
811 case XK_F34: /* "\033[48~" */
812 case XK_F35: /* "\033[49~" */
813 FKEY (31, XK_F17);
814 break;
815#undef FKEY
816 default:
817 newlen = 0; 773 newlen = 0;
818 break;
819 } 774 }
820 775 break;
821 if (newlen)
822 len = strlen (kbuf);
823 } 776 }
824 777
778 if (newlen)
779 len = strlen (kbuf);
780
781 if (len > 0)
782 {
825 /* 783 /*
784 * pass Shift/Control indicators for function keys ending with `~'
785 *
786 * eg,
787 * Prior = "ESC[5~"
788 * Shift+Prior = "ESC[5$"
789 * Ctrl+Prior = "ESC[5^"
790 * Ctrl+Shift+Prior = "ESC[5@"
791 */
792 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
793 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
794
795 /*
826 * Pass meta for all function keys, if 'meta' option set 796 * Pass meta for all function keys, if 'meta' option set
827 */ 797 */
828#ifdef META8_OPTION 798#ifdef META8_OPTION
829 if (meta && (meta_char == 0x80) && len > 0) 799 if (meta && (meta_char == 0x80))
830 kbuf[len - 1] |= 0x80; 800 kbuf[len - 1] |= 0x80;
831#endif 801#endif
802 }
832 803
833 } 804 }
834 else if (ctrl && keysym == XK_minus) 805 else if (ctrl && keysym == XK_minus)
835 { 806 {
836 len = 1; 807 len = 1;
845 { 816 {
846#ifdef META8_OPTION 817#ifdef META8_OPTION
847 /* set 8-bit on */ 818 /* set 8-bit on */
848 if (meta && (meta_char == 0x80)) 819 if (meta && (meta_char == 0x80))
849 { 820 {
850 unsigned char *ch; 821 char *ch;
851 822
852 for (ch = kbuf; ch < kbuf + len; ch++) 823 for (ch = kbuf; ch < kbuf + len; ch++)
853 *ch |= 0x80; 824 *ch |= 0x80;
854 825
855 meta = 0; 826 meta = 0;
857#endif 828#endif
858 /* nil */ ; 829 /* nil */ ;
859 } 830 }
860 } 831 }
861 832
833 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
834 return;
835
862 if (len <= 0) 836 if (len <= 0)
863 return; /* not mapped */ 837 return; /* not mapped */
864 838
865 if (options & Opt_scrollTtyKeypress) 839 if (option (Opt_scrollTtyKeypress))
866 if (view_start) 840 if (view_start)
867 { 841 {
868 view_start = 0; 842 view_start = 0;
869 want_refresh = 1; 843 want_refresh = 1;
870 } 844 }
871 845
872 /*
873 * these modifications only affect the static keybuffer
874 * pass Shift/Control indicators for function keys ending with `~'
875 *
876 * eg,
877 * Prior = "ESC[5~"
878 * Shift+Prior = "ESC[5$"
879 * Ctrl+Prior = "ESC[5^"
880 * Ctrl+Shift+Prior = "ESC[5@"
881 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
882 */
883 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
884 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
885
886 /* escape prefix */ 846 /* escape prefix */
887 if (meta 847 if (meta
888#ifdef META8_OPTION 848#ifdef META8_OPTION
889 && meta_char == C0_ESC 849 && meta_char == C0_ESC
890#endif 850#endif
891 ) 851 )
892 { 852 {
893 const unsigned char ch = C0_ESC; 853 const char ch = C0_ESC;
894 tt_write (&ch, 1); 854 tt_write (&ch, 1);
895 } 855 }
896 856
897#if defined(DEBUG_CMD)
898 /* Display keyboard buffer contents */
899 unsigned char *p;
900 int i;
901
902 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
903 for (i = 0, p = kbuf; i < len; i++, p++)
904 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
905 fprintf (stderr, "'\n");
906#endif /* DEBUG_CMD */
907 tt_write (kbuf, (unsigned int)len); 857 tt_write (kbuf, (unsigned int)len);
908} 858}
909/*}}} */
910 859
911#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 860void
912/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 861rxvt_term::key_release (XKeyEvent &ev)
913/* attempt to `write' count to the input buffer */
914unsigned int
915rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
916{ 862{
917 unsigned int n, s; 863#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
864 KeySym keysym;
918 865
919 n = cmdbuf_ptr - cmdbuf_base; 866 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
920 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 867#endif
921 868
922 if (n > 0 && s < count) 869#if ENABLE_FRILLS || ISO_14755
870 // ISO 14755 support
871 if (iso14755buf)
872 if (iso14755buf & ISO_14755_52)
923 { 873 {
924 memmove (cmdbuf_base, cmdbuf_ptr, 874# if ISO_14755
925 (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); 875 scr_overlay_off ();
926 cmdbuf_ptr = cmdbuf_base;
927 cmdbuf_endp -= n;
928 s += n;
929 }
930
931 if (count > s)
932 {
933 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
934 count = s;
935 }
936
937 for (; count--;)
938 *cmdbuf_endp++ = *str++;
939
940 cmd_parse ();
941
942 return 0;
943}
944#endif 876# endif
877# if ISO_14755
878 // iso14755 part 5.2 handling: release time
879 // first: controls
880 if ((ev.state & ControlMask)
881 && ((keysym >= 0x40 && keysym <= 0x5f)
882 || (keysym >= 0x61 && keysym <= 0x7f)))
883 {
884 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
885 commit_iso14755 ();
886
887 return;
888 }
889
890 for (unsigned short *i = iso14755_symtab; i[0]; i += 2)
891 if (i[0] == keysym)
892 {
893 iso14755buf = ISO_14755_51 | i[1];
894 commit_iso14755 ();
895
896 return;
897 }
898
899 scr_bell ();
900# endif
901 iso14755buf = 0;
902
903 return;
904 }
905 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
906 {
907# if ISO_14755
908 scr_overlay_off ();
909# endif
910 if (iso14755buf & ISO_14755_51)
911 commit_iso14755 ();
912#if ISO_14755
913 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
914 {
915 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
916
917 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
918 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
919 }
920# endif
921 else
922 iso14755buf = 0;
923 }
924#endif
925
926 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
927 return;
928
929#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
930 if (!(ev.state & ControlMask))
931 slip_wheel_ev.stop ();
932 else if (keysym == XK_Control_L || keysym == XK_Control_R)
933 mouse_slip_wheel_speed = 0;
934#endif
935}
945 936
946void 937void
947rxvt_term::flush () 938rxvt_term::flush ()
948{ 939{
949 flush_ev.stop (); 940 flush_ev.stop ();
950 941
951#ifdef TRANSPARENT 942#ifdef HAVE_BG_PIXMAP
952 if (want_full_refresh) 943 if (bg_flags & BG_NEEDS_REFRESH)
953 { 944 {
954 want_full_refresh = 0; 945 bg_flags &= ~BG_NEEDS_REFRESH;
955 scr_clear ();
956 scr_touch (false); 946 scr_touch (false);
957 } 947 }
958#endif 948#endif
959 949
960 if (want_refresh) 950 if (want_refresh)
961 { 951 {
952 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
953 {
954 int row = view_start;
955 int end_row = row + nrow;
956
957 while (row > top_row && ROW (row - 1).is_longer ())
958 --row;
959
960 do
961 {
962 int start_row = row;
963 line_t *l;
964
965 do
966 {
967 l = &ROW (row++);
968
969 if (!(l->f & LINE_FILTERED))
970 {
971 // line not filtered, mark it as filtered
972 l->f |= LINE_FILTERED;
973 while (l->is_longer ())
974 {
975 l = &ROW (row++);
976 l->f |= LINE_FILTERED;
977 }
978
979 // and filter it
980 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
981
982 break;
983 }
984 }
985 while (l->is_longer () && row < end_row);
986 }
987 while (row < end_row);
988 }
989
962 scr_refresh (refresh_type); 990 scr_refresh ();
963 scrollbar_show (1); 991 scrollBar.show (1);
964#ifdef USE_XIM 992#ifdef USE_XIM
965 IMSendSpot (); 993 im_send_spot ();
966#endif 994#endif
967 } 995 }
968 996
969 display->flush (); 997 display->flush ();
970} 998}
971 999
1000/* checks whether a refresh is requested and starts the refresh timer */
972void 1001void
973rxvt_term::check_cb (check_watcher &w) 1002rxvt_term::refresh_check ()
974{ 1003{
975 SET_R (this); 1004 if (want_refresh && !flush_ev.is_active ())
976 SET_LOCALE (locale); 1005 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
977 1006
978 display->flush (); 1007 display->flush ();
979
980 if (want_refresh && !flush_ev.active)
981 flush_ev.start (NOW + 0.01);
982} 1008}
983 1009
984void 1010void
985rxvt_term::flush_cb (time_watcher &w) 1011rxvt_term::flush_cb (ev::timer &w, int revents)
986{ 1012{
987 SET_R (this); 1013 make_current ();
988 SET_LOCALE (locale);
989 1014
990 refresh_limit = 1;
991 refresh_count = 0; 1015 refresh_count = 0;
992 flush (); 1016 flush ();
993} 1017}
994 1018
995#ifdef CURSOR_BLINK 1019#ifdef CURSOR_BLINK
996void 1020void
1021rxvt_term::cursor_blink_reset ()
1022{
1023 if (hidden_cursor)
1024 {
1025 hidden_cursor = 0;
1026 want_refresh = 1;
1027 }
1028
1029 if (option (Opt_cursorBlink))
1030 cursor_blink_ev.again ();
1031 else
1032 cursor_blink_ev.stop ();
1033}
1034
1035void
997rxvt_term::cursor_blink_cb (time_watcher &w) 1036rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
998{ 1037{
999 hidden_cursor = !hidden_cursor; 1038 hidden_cursor = !hidden_cursor;
1000 want_refresh = 1; 1039 want_refresh = 1;
1001 1040 refresh_check ();
1002 w.start (w.at + BLINK_INTERVAL);
1003} 1041}
1004#endif 1042#endif
1005 1043
1006#ifdef TEXT_BLINK 1044#ifdef TEXT_BLINK
1007void 1045void
1008rxvt_term::text_blink_cb (time_watcher &w) 1046rxvt_term::text_blink_cb (ev::timer &w, int revents)
1009{ 1047{
1010 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1048 if (scr_refresh_rend (RS_Blink, RS_Blink))
1011 { 1049 {
1012 hidden_text = !hidden_text; 1050 hidden_text = !hidden_text;
1013 want_refresh = 1; 1051 want_refresh = 1;
1014 w.start (w.at + TEXT_BLINK_INTERVAL); 1052 refresh_check ();
1015 } 1053 }
1054 else
1055 w.stop ();
1016} 1056}
1017#endif 1057#endif
1018 1058
1019#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1059#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1020void 1060void
1021rxvt_term::cont_scroll_cb (time_watcher &w) 1061rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1022{ 1062{
1023 if ((scrollbar_isUp() || scrollbar_isDn()) && 1063 if ((scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN)
1024 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1064 && scr_page (scrollBar.state == SB_STATE_UP ? UP : DN, 1))
1025 { 1065 {
1026 refresh_type |= SMOOTH_REFRESH;
1027 want_refresh = 1; 1066 want_refresh = 1;
1028 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1067 refresh_check ();
1029 } 1068 }
1069 else
1070 w.stop ();
1030} 1071}
1031#endif 1072#endif
1032 1073
1033#ifdef SELECTION_SCROLLING 1074#ifdef SELECTION_SCROLLING
1034void 1075void
1035rxvt_term::sel_scroll_cb (time_watcher &w) 1076rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1036{ 1077{
1037 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1078 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1038 { 1079 {
1039 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1080 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1040 refresh_type |= SMOOTH_REFRESH;
1041 want_refresh = 1; 1081 want_refresh = 1;
1042 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1082 refresh_check ();
1043 } 1083 }
1084 else
1085 w.stop ();
1044} 1086}
1045#endif 1087#endif
1046 1088
1047#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1089#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1048void 1090void
1049rxvt_term::slip_wheel_cb (time_watcher &w) 1091rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1050{ 1092{
1051 if (mouse_slip_wheel_speed == 0 1093 if (scr_changeview (view_start - mouse_slip_wheel_speed))
1052 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1053 : scr_page (UP, mouse_slip_wheel_speed))
1054 { 1094 {
1055 if (view_start == nsaved ||
1056 view_start == 0)
1057 mouse_slip_wheel_speed = 0;
1058
1059 refresh_type |= SMOOTH_REFRESH;
1060 want_refresh = 1; 1095 want_refresh = 1;
1061 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1096 refresh_check ();
1097 }
1098
1099 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1062 } 1100 {
1101 mouse_slip_wheel_speed = 0;
1102 w.stop ();
1103 }
1104}
1105#endif
1106
1107#if LINUX_YIELD_HACK
1108static struct event_handler
1109{
1110 ev::prepare yield_ev;
1111
1112 void yield_cb (ev::prepare &w, int revents)
1113 {
1114 // this should really be sched_yield(), but the linux guys thought
1115 // that giving a process calling sched_yield () less cpu time than
1116 // ones with high nice levels is a useful thing to do. It surely is is
1117 // allowed by the sus... as is returning ENOSYS.
1118 // since the linux guys additionally thought that breaking the only
1119 // known workaround against their unusable sched_yield hack is cool,
1120 // we just nanosleep a bit and hope for the best.
1121
1122 struct timespec ts = { 0, 1000 };
1123 nanosleep (&ts, 0);
1124
1125 w.stop ();
1126 }
1127
1128 event_handler ()
1129 : yield_ev (this, &event_handler::yield_cb)
1130 {
1131 }
1132} event_handler;
1133#endif
1134
1135/* make sure all the cmd data is at beginning of cmdbuf */
1136void
1137rxvt_term::cmdbuf_reify ()
1138{
1139 if (cmdbuf_ptr == cmdbuf_base)
1140 return;
1141
1142 ssize_t used = cmdbuf_endp - cmdbuf_ptr;
1143
1144 memmove (cmdbuf_base, cmdbuf_ptr, used);
1145 cmdbuf_ptr = cmdbuf_base;
1146 cmdbuf_endp = cmdbuf_ptr + used;
1147
1148}
1149
1150#if defined (KEYSYM_RESOURCE)
1151void
1152rxvt_term::cmdbuf_append (const char *str, size_t count)
1153{
1154 cmdbuf_reify ();
1155
1156 size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp;
1157
1158 if (count > avail)
1159 return;
1160
1161 memcpy (cmdbuf_endp, str, count);
1162 cmdbuf_endp += count;
1163
1164 cmd_parse ();
1063} 1165}
1064#endif 1166#endif
1065 1167
1066bool 1168bool
1067rxvt_term::pty_fill () 1169rxvt_term::pty_fill ()
1068{ 1170{
1069 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1171 cmdbuf_reify ();
1070 1172
1071 if (CBUFSIZ == n) 1173 size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp;
1072 { 1174
1073 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1175 if (!avail)
1074 n = 0;
1075 } 1176 {
1076 1177 // normally this indicates a "too long" command sequence - just drop the data we have
1077 memmove (cmdbuf_base, cmdbuf_ptr, n);
1078 cmdbuf_ptr = cmdbuf_base; 1178 cmdbuf_ptr = cmdbuf_base;
1079 cmdbuf_endp = cmdbuf_ptr + n; 1179 cmdbuf_endp = cmdbuf_ptr;
1180 avail = CBUFSIZ;
1181 }
1080 1182
1081 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1183 ssize_t r = read (pty->pty, cmdbuf_endp, avail);
1082 1184
1083 if (n > 0) 1185 if (r > 0)
1084 { 1186 {
1085 cmdbuf_endp += n; 1187 cmdbuf_endp += r;
1086 return true; 1188 return true;
1087 } 1189 }
1088 else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0) 1190 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1191 {
1192#if LINUX_YIELD_HACK
1193 if (display->is_local)
1194 event_handler.yield_ev.start ();
1195#endif
1196 }
1197 else
1089 { 1198 {
1090 pty_ev.stop (); 1199 pty_ev.stop ();
1091 1200
1092 if (!(options & Opt_hold)) 1201 if (!option (Opt_hold))
1093 destroy (); 1202 destroy ();
1094 } 1203 }
1095 1204
1096 return false; 1205 return false;
1097} 1206}
1098 1207
1099void 1208void
1100rxvt_term::pty_cb (io_watcher &w, short revents) 1209rxvt_term::pty_cb (ev::io &w, int revents)
1101{ 1210{
1102 SET_R (this); 1211 make_current ();
1103 SET_LOCALE (locale);
1104 1212
1105 if (revents & EVENT_READ) 1213 if (revents & ev::READ)
1106 // loop, but don't allow a single term to monopolize us 1214 // loop, but don't allow a single term to monopolize us
1107 while (pty_fill ()) 1215 for (int i = CBUFCNT; i-- && pty_fill (); )
1108 if (cmd_parse ()) 1216 cmd_parse ();
1109 break;
1110 1217
1111 if (revents & EVENT_WRITE) 1218 if (revents & ev::WRITE)
1112 pty_write (); 1219 pty_write ();
1220
1221 refresh_check ();
1113} 1222}
1114 1223
1115void 1224void
1116rxvt_term::pointer_unblank () 1225rxvt_term::pointer_unblank ()
1117{ 1226{
1118 XDefineCursor (display->display, vt, TermWin_cursor); 1227 XDefineCursor (dpy, vt, TermWin_cursor);
1119 recolour_cursor (); 1228 recolour_cursor ();
1120 1229
1121#ifdef POINTER_BLANK 1230#ifdef POINTER_BLANK
1122 hidden_pointer = 0; 1231 hidden_pointer = 0;
1123 1232
1124 if (options & Opt_pointerBlank) 1233 if (option (Opt_pointerBlank))
1125 pointer_ev.start (NOW + pointerBlankDelay); 1234 pointer_ev.start (pointerBlankDelay);
1126#endif 1235#endif
1127} 1236}
1128 1237
1129#ifdef POINTER_BLANK 1238#ifdef POINTER_BLANK
1130void 1239void
1131rxvt_term::pointer_blank () 1240rxvt_term::pointer_blank ()
1132{ 1241{
1133 if (! (options & Opt_pointerBlank)) 1242 if (!option (Opt_pointerBlank))
1134 return; 1243 return;
1135 1244
1136 XDefineCursor (display->display, vt, display->blank_cursor); 1245 XDefineCursor (dpy, vt, display->blank_cursor);
1137 XFlush (display->display); 1246 XFlush (dpy);
1138 1247
1139 hidden_pointer = 1; 1248 hidden_pointer = 1;
1140} 1249}
1141 1250
1142void 1251void
1143rxvt_term::pointer_cb (time_watcher &w) 1252rxvt_term::pointer_cb (ev::timer &w, int revents)
1144{ 1253{
1145 SET_R (this); 1254 make_current ();
1146 SET_LOCALE (locale);
1147 1255
1148 pointer_blank (); 1256 pointer_blank ();
1149} 1257}
1150#endif 1258#endif
1151 1259
1152void 1260void
1153rxvt_term::mouse_report (XButtonEvent &ev) 1261rxvt_term::mouse_report (XButtonEvent &ev)
1154{ 1262{
1155 int button_number, key_state = 0; 1263 int button_number, key_state = 0;
1156 int x, y; 1264 int x, y;
1265 int code = 32;
1157 1266
1158 x = ev.x; 1267 x = Pixel2Col (ev.x) + 1;
1159 y = ev.y; 1268 y = Pixel2Row (ev.y) + 1;
1160 pixel_position (&x, &y); 1269
1270 if (ev.type == MotionNotify)
1271 {
1272 if (x == mouse_row && y == mouse_col)
1273 return;
1274
1275 mouse_row = x;
1276 mouse_col = y;
1277 code += 32;
1278 }
1161 1279
1162 if (MEvent.button == AnyButton) 1280 if (MEvent.button == AnyButton)
1163 button_number = 3; 1281 button_number = 3;
1164 else 1282 else
1165 { 1283 {
1166 button_number = MEvent.button - Button1; 1284 button_number = MEvent.button - Button1;
1167 /* add 0x3D for wheel events, like xterm does */ 1285 /* add 0x3D for wheel events, like xterm does */
1168 if (button_number >= 3) 1286 if (button_number >= 3)
1169 button_number += (64 - 3); 1287 button_number += 64 - 3;
1170 } 1288 }
1171 1289
1172 if (priv_modes & PrivMode_MouseX10) 1290 if (priv_modes & PrivMode_MouseX10)
1173 { 1291 {
1174 /* 1292 /*
1206 fputc ('A', stderr); 1324 fputc ('A', stderr);
1207 if (key_state & 32) 1325 if (key_state & 32)
1208 fputc ('2', stderr); 1326 fputc ('2', stderr);
1209 fprintf (stderr, "]: <%d>, %d/%d\n", 1327 fprintf (stderr, "]: <%d>, %d/%d\n",
1210 button_number, 1328 button_number,
1211 x + 1, 1329 x,
1212 y + 1); 1330 y);
1213#endif 1331#endif
1214 1332
1333#if ENABLE_FRILLS
1334 if (priv_modes & PrivMode_ExtMouseRight)
1335 tt_printf ("\033[%d;%d;%dM",
1336 code + button_number + key_state,
1337 x,
1338 y);
1339 else if (priv_modes & PrivMode_ExtModeMouse)
1340 tt_printf ("\033[M%c%lc%lc",
1341 code + button_number + key_state,
1342 wint_t (32 + x),
1343 wint_t (32 + y));
1344 else
1345#endif
1215 tt_printf ("\033[M%c%c%c", 1346 tt_printf ("\033[M%c%c%c",
1216 (32 + button_number + key_state), 1347 code + button_number + key_state,
1217 (32 + x + 1), 1348 32 + x,
1218 (32 + y + 1)); 1349 32 + y);
1219} 1350}
1220
1221#ifdef USING_W11LIB
1222void
1223rxvt_W11_process_x_event (XEvent *ev)
1224{
1225 rxvt_t *r = rxvt_get_r ();
1226
1227 x_cb (*ev);
1228}
1229#endif
1230 1351
1231/*{{{ process an X event */ 1352/*{{{ process an X event */
1232void 1353void
1233rxvt_term::x_cb (XEvent &ev) 1354rxvt_term::x_cb (XEvent &ev)
1234{ 1355{
1235 dDisp; 1356 make_current ();
1236 1357
1237 SET_R (this); 1358 dLocal (Display *, dpy);
1238 SET_LOCALE (locale);
1239 1359
1240#if defined(CURSOR_BLINK) 1360 if (ev.xany.window == vt
1241 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1361 && SHOULD_INVOKE (HOOK_X_EVENT)
1242 { 1362 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1243 if (hidden_cursor) 1363 return;
1244 {
1245 hidden_cursor = 0;
1246 want_refresh = 1;
1247 }
1248 1364
1249 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1365 // for XQueryPointer
1250 }
1251#endif
1252
1253#if defined(POINTER_BLANK)
1254 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1255 {
1256 if (ev.type == MotionNotify
1257 || ev.type == ButtonPress
1258 || ev.type == ButtonRelease)
1259 if (hidden_pointer)
1260 pointer_unblank ();
1261
1262 if (ev.type == KeyPress && hidden_pointer == 0)
1263 pointer_blank ();
1264 }
1265#endif
1266
1267 Window unused_root, unused_child; 1366 Window unused_root, unused_child;
1268 int unused_root_x, unused_root_y; 1367 int unused_root_x, unused_root_y;
1269 unsigned int unused_mask; 1368 unsigned int unused_mask;
1270 1369
1271 switch (ev.type) 1370 switch (ev.type)
1272 { 1371 {
1273 case KeyPress: 1372 case KeyPress:
1274#if ISO_14755 1373 key_press (ev.xkey);
1275 if (!(iso14755buf & ISO_14755_52))
1276#endif
1277 lookup_key (ev.xkey);
1278
1279 break; 1374 break;
1280 1375
1281 case KeyRelease: 1376 case KeyRelease:
1282 { 1377 key_release (ev.xkey);
1283#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1284 KeySym ks;
1285
1286 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1287#endif
1288
1289#if ENABLE_FRILLS || ISO_14755
1290 // ISO 14755 support
1291 if (iso14755buf)
1292 if (iso14755buf & ISO_14755_52)
1293 {
1294# if ENABLE_OVERLAY
1295 scr_overlay_off ();
1296# endif
1297# if ISO_14755
1298 // iso14755 part 5.2 handling: release time
1299 // first: controls
1300 if ((ev.xkey.state & ControlMask)
1301 && ((ks >= 0x40 && ks <= 0x5f)
1302 || (ks >= 0x61 && ks <= 0x7f)))
1303 {
1304 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1305 commit_iso14755 ();
1306 return; // case-break;
1307 }
1308
1309 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1310 if (i[0] == ks)
1311 {
1312 iso14755buf = ISO_14755_51 | i[1];
1313 commit_iso14755 ();
1314 return; // case-break;
1315 }
1316
1317 scr_bell ();
1318# endif
1319 iso14755buf = 0;
1320 break;
1321 }
1322 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1323 {
1324# if ENABLE_OVERLAY
1325 scr_overlay_off ();
1326# endif
1327 if (iso14755buf & ISO_14755_51)
1328 commit_iso14755 ();
1329#if ISO_14755
1330 else if (iso14755buf & ISO_14755_STARTED)
1331 {
1332 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1333
1334 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1335 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1336 }
1337# endif
1338 else
1339 iso14755buf = 0;
1340 }
1341#endif
1342
1343#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1344 if (!(ev.xkey.state & ControlMask))
1345 slip_wheel_ev.stop ();
1346 else if (ks == XK_Control_L || ks == XK_Control_R)
1347 mouse_slip_wheel_speed = 0;
1348#endif
1349 break; 1378 break;
1350 }
1351 1379
1352 case ButtonPress: 1380 case ButtonPress:
1353 button_press (ev.xbutton); 1381 button_press (ev.xbutton);
1354 break; 1382 break;
1355 1383
1357 button_release (ev.xbutton); 1385 button_release (ev.xbutton);
1358 break; 1386 break;
1359 1387
1360 case ClientMessage: 1388 case ClientMessage:
1361 if (ev.xclient.format == 32 1389 if (ev.xclient.format == 32
1362 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) 1390 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1363 { 1391 {
1392 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1393 {
1394 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1395 {
1364 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1396 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1397 {
1398 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1365 destroy (); 1399 destroy ();
1400 }
1366#if ENABLE_EWMH 1401#if ENABLE_EWMH
1367 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1402 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1368 XSendEvent (disp, ev.xclient.window = display->root, 1403 XSendEvent (dpy, ev.xclient.window = display->root,
1369 False, SubstructureRedirectMask | SubstructureNotifyMask, 1404 False, SubstructureRedirectMask | SubstructureNotifyMask,
1370 &ev); 1405 &ev);
1406#endif
1407 }
1408 }
1409#if ENABLE_XEMBED
1410 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1411 {
1412 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1413 focus_in ();
1414 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1415 focus_out ();
1416 }
1371#endif 1417#endif
1372 } 1418 }
1373#if ENABLE_XEMBED
1374 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1375 {
1376 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1377 focus_in ();
1378 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1379 focus_out ();
1380 }
1381#endif
1382#ifdef OFFIX_DND
1383 /* OffiX Dnd (drag 'n' drop) protocol */
1384 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1385 && (ev.xclient.data.l[0] == DndFile
1386 || ev.xclient.data.l[0] == DndDir
1387 || ev.xclient.data.l[0] == DndLink))
1388 {
1389 /* Get Dnd data */
1390 Atom ActualType;
1391 int ActualFormat;
1392 unsigned char *data;
1393 unsigned long Size, RemainingBytes;
1394
1395 XGetWindowProperty (disp, display->root,
1396 xa[XA_DNDSELECTION],
1397 0L, 1000000L,
1398 False, AnyPropertyType,
1399 &ActualType, &ActualFormat,
1400 &Size, &RemainingBytes,
1401 &data);
1402 set_string_property (XA_CUT_BUFFER0, data);
1403 XFree (data);
1404 selection_paste (display->root, XA_CUT_BUFFER0, true);
1405 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1406 }
1407#endif /* OFFIX_DND */
1408 break;
1409
1410 case MappingNotify:
1411 XRefreshKeyboardMapping (&ev.xmapping);
1412 break; 1419 break;
1413 1420
1414 /* 1421 /*
1415 * XXX: this is not the _current_ arrangement 1422 * XXX: this is not the _current_ arrangement
1416 * Here's my conclusion: 1423 * Here's my conclusion:
1435 break; 1442 break;
1436 } 1443 }
1437 break; 1444 break;
1438 1445
1439 case FocusIn: 1446 case FocusIn:
1447 if (ev.xfocus.detail != NotifyInferior
1448 && ev.xfocus.detail != NotifyPointer
1449 && ev.xfocus.mode != NotifyGrab)
1440 focus_in (); 1450 focus_in ();
1441 break; 1451 break;
1442 1452
1443 case FocusOut: 1453 case FocusOut:
1454 if (ev.xfocus.detail != NotifyInferior
1455 && ev.xfocus.detail != NotifyPointer
1456 && ev.xfocus.mode != NotifyGrab)
1444 focus_out (); 1457 focus_out ();
1445 break; 1458 break;
1446 1459
1447 case ConfigureNotify: 1460 case ConfigureNotify:
1448 if (ev.xconfigure.window == parent[0]) 1461 if (ev.xconfigure.window == parent)
1449 { 1462 {
1450 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)) 1463 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1451 ; 1464 ;
1465
1466#ifdef HAVE_BG_PIXMAP
1467 bool moved = false;
1468 if (bg_window_position_sensitive ())
1469 {
1470 int x, y;
1471 if (ev.xconfigure.send_event)
1472 {
1473 x = ev.xconfigure.x;
1474 y = ev.xconfigure.y;
1475 }
1476 else
1477 get_window_origin (x, y);
1478
1479 if (bg_set_position (x, y)
1480 || !(bg_flags & BG_IS_VALID))
1481 moved = true;
1482 }
1483#endif
1452 1484
1453 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) 1485 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1454 { 1486 {
1455 seen_resize = 1; 1487 seen_resize = 1;
1456 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1488 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1457 } 1489 }
1458 1490 else
1459#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1491 {
1460 if (options & Opt_transparent) 1492#ifdef HAVE_BG_PIXMAP
1461 check_our_parents (); 1493 if (moved)
1494 update_background ();
1462#endif 1495#endif
1496 }
1497
1498 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1463 } 1499 }
1464 break; 1500 break;
1465 1501
1466 case PropertyNotify: 1502 case PropertyNotify:
1467 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1503 HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END));
1468 && ev.xproperty.state == PropertyNewValue)
1469 selection_property (ev.xproperty.window, ev.xproperty.atom);
1470
1471 break; 1504 break;
1472 1505
1473 case SelectionClear: 1506 case SelectionClear:
1474 selection_clear (); 1507 selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]);
1475 break;
1476
1477 case SelectionNotify:
1478 if (selection_wait == Sel_normal)
1479 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1480 break; 1508 break;
1481 1509
1482 case SelectionRequest: 1510 case SelectionRequest:
1483 selection_send (ev.xselectionrequest); 1511 selection_send (ev.xselectionrequest);
1512 break;
1513
1514 case MapNotify:
1515#ifdef HAVE_BG_PIXMAP
1516 /* This is needed specifically to fix the case of no window manager or a
1517 * non-reparenting window manager. In those cases we never get first
1518 * ConfigureNotify. Also that speeds startup under normal WM, by taking
1519 * care of multiplicity of ConfigureNotify events arriving while WM does
1520 * reparenting.
1521 * We should not render background immediately, as there could be several
1522 * ConfigureNotify's to follow. Lets take care of all of them in one scoop
1523 * by scheduling background redraw as soon as we can, but giving a short
1524 * bit of time for ConfigureNotifies to arrive.
1525 * We should render background PRIOR to drawing any text, but AFTER all
1526 * of ConfigureNotifys for the best results.
1527 */
1528 if (!(bg_flags & BG_IS_VALID))
1529 update_background_ev.start (0.025);
1530#endif
1531 mapped = 1;
1532#ifdef TEXT_BLINK
1533 text_blink_ev.start ();
1534#endif
1535 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1484 break; 1536 break;
1485 1537
1486 case UnmapNotify: 1538 case UnmapNotify:
1487 mapped = 0; 1539 mapped = 0;
1488#ifdef TEXT_BLINK 1540#ifdef TEXT_BLINK
1489 text_blink_ev.stop (); 1541 text_blink_ev.stop ();
1490#endif 1542#endif
1543 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1491 break; 1544 break;
1492
1493 case MapNotify:
1494 mapped = 1;
1495#ifdef TEXT_BLINK
1496 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1497#endif
1498 break;
1499
1500#ifdef TRANSPARENT
1501 case ReparentNotify:
1502 rootwin_cb (ev);
1503 break;
1504#endif /* TRANSPARENT */
1505 1545
1506 case GraphicsExpose: 1546 case GraphicsExpose:
1507 case Expose: 1547 case Expose:
1508 if (ev.xany.window == vt) 1548 if (ev.xany.window == vt)
1509 { 1549 {
1510 do 1550 do
1551 {
1511 scr_expose (ev.xexpose.x, ev.xexpose.y, 1552 scr_expose (ev.xexpose.x, ev.xexpose.y,
1512 ev.xexpose.width, ev.xexpose.height, False); 1553 ev.xexpose.width, ev.xexpose.height, false);
1554 }
1513 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)); 1555 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1514 1556
1515 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1557 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1516 1558
1517 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) 1559 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1560 {
1518 scr_expose (ev.xexpose.x, ev.xexpose.y, 1561 scr_expose (ev.xexpose.x, ev.xexpose.y,
1519 ev.xexpose.width, ev.xexpose.height, False); 1562 ev.xexpose.width, ev.xexpose.height, false);
1563 }
1520 1564
1521 scr_refresh (refresh_type); 1565 want_refresh = 1;
1522 } 1566 }
1523 else 1567 else
1524 { 1568 {
1525 XEvent unused_event; 1569 XEvent unused_event;
1526 1570
1527 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1571 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1528 ; 1572 ;
1529 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1573 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1530 ; 1574 ;
1531 1575
1532 if (isScrollbarWindow (ev.xany.window)) 1576 if (scrollBar.state && ev.xany.window == scrollBar.win)
1533 { 1577 {
1534 scrollBar.setIdle (); 1578 scrollBar.state = SB_STATE_IDLE;
1535 scrollbar_show (0); 1579 scrollBar.show (0);
1536 } 1580 }
1537#ifdef MENUBAR
1538 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1539 menubar_expose ();
1540#endif
1541
1542#ifdef TRANSPARENT
1543 if (am_transparent && ev.xany.window == parent[0])
1544 XClearWindow (disp, ev.xany.window);
1545#endif
1546 } 1581 }
1547 break; 1582 break;
1548 1583
1549 case MotionNotify: 1584 case MotionNotify:
1550#ifdef POINTER_BLANK 1585#ifdef POINTER_BLANK
1551 if (hidden_pointer) 1586 if (hidden_pointer)
1552 pointer_unblank (); 1587 pointer_unblank ();
1553#endif 1588#endif
1554#if MENUBAR 1589 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1555 if (isMenuBarWindow (ev.xany.window)) 1590 || priv_modes & PrivMode_MouseAnyEvent)
1556 {
1557 menubar_control (ev.xbutton); 1591 mouse_report (ev.xbutton);
1558 break;
1559 }
1560#endif
1561 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1592 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1562 break; 1593 break;
1563 1594
1564 if (ev.xany.window == vt) 1595 if (ev.xany.window == vt)
1565 { 1596 {
1597 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1598 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1599 ; // nop
1566 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1600 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1567 { 1601 {
1568 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) 1602 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1569 ; 1603 ;
1570 1604
1571 XQueryPointer (disp, vt, 1605 XQueryPointer (dpy, vt,
1572 &unused_root, &unused_child, 1606 &unused_root, &unused_child,
1573 &unused_root_x, &unused_root_y, 1607 &unused_root_x, &unused_root_y,
1574 &ev.xbutton.x, &ev.xbutton.y, 1608 &ev.xbutton.x, &ev.xbutton.y,
1575 &ev.xbutton.state); 1609 &ev.xbutton.state);
1576#ifdef MOUSE_THRESHOLD 1610#ifdef MOUSE_THRESHOLD
1596 int dist; 1630 int dist;
1597 1631
1598 /* don't clobber the current delay if we are 1632 /* don't clobber the current delay if we are
1599 * already in the middle of scrolling. 1633 * already in the middle of scrolling.
1600 */ 1634 */
1601 if (!sel_scroll_ev.active) 1635 if (!sel_scroll_ev.is_active ())
1602 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1636 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1603 1637
1604 /* save the event params so we can highlight 1638 /* save the event params so we can highlight
1605 * the selection in the pending-scroll loop 1639 * the selection in the pending-scroll loop
1606 */ 1640 */
1607 selection_save_x = ev.xbutton.x; 1641 selection_save_x = ev.xbutton.x;
1615 dist = int_bwidth - ev.xbutton.y; 1649 dist = int_bwidth - ev.xbutton.y;
1616 } 1650 }
1617 else 1651 else
1618 { 1652 {
1619 scroll_selection_dir = DN; 1653 scroll_selection_dir = DN;
1620 dist = ev.xbutton.y - (int_bwidth + height); 1654 dist = ev.xbutton.y - (int_bwidth + vt_height);
1621 } 1655 }
1622 1656
1623 scroll_selection_lines = Pixel2Height (dist) 1657 scroll_selection_lines = Pixel2Height (dist)
1624 / SELECTION_SCROLL_LINE_SPEEDUP 1658 / SELECTION_SCROLL_LINE_SPEEDUP
1625 + 1; 1659 + 1;
1629 else 1663 else
1630 { 1664 {
1631 /* we are within the text window, so we 1665 /* we are within the text window, so we
1632 * shouldn't be scrolling 1666 * shouldn't be scrolling
1633 */ 1667 */
1634 if (sel_scroll_ev.active)
1635 sel_scroll_ev.stop(); 1668 sel_scroll_ev.stop();
1636 } 1669 }
1637#endif 1670#endif
1638#ifdef MOUSE_THRESHOLD 1671#ifdef MOUSE_THRESHOLD
1639 } 1672 }
1640#endif 1673#endif
1641 } 1674 }
1642 } 1675 }
1643 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1676 else if (scrollBar.state == SB_STATE_MOTION && ev.xany.window == scrollBar.win)
1644 { 1677 {
1645 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1678 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1646 MotionNotify, &ev)) 1679 MotionNotify, &ev))
1647 ; 1680 ;
1648 1681
1649 XQueryPointer (disp, scrollBar.win, 1682 XQueryPointer (dpy, scrollBar.win,
1650 &unused_root, &unused_child, 1683 &unused_root, &unused_child,
1651 &unused_root_x, &unused_root_y, 1684 &unused_root_x, &unused_root_y,
1652 &ev.xbutton.x, &ev.xbutton.y, 1685 &ev.xbutton.x, &ev.xbutton.y,
1653 &unused_mask); 1686 &unused_mask);
1654 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1687 scr_move_to (scrollBar.position (ev.xbutton.y) - csrO,
1655 scrollbar_size ()); 1688 scrollBar.size ());
1656 scr_refresh (refresh_type);
1657 refresh_limit = 0; 1689 want_refresh = 1;
1658 scrollbar_show (1); 1690 scrollBar.show (1);
1659 } 1691 }
1660 break; 1692 break;
1661 } 1693 }
1694
1695#if defined(CURSOR_BLINK)
1696 if (ev.type == KeyPress)
1697 cursor_blink_reset ();
1698#endif
1699
1700#if defined(POINTER_BLANK)
1701 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1702 {
1703 if (ev.type == MotionNotify
1704 || ev.type == ButtonPress
1705 || ev.type == ButtonRelease)
1706 if (hidden_pointer)
1707 pointer_unblank ();
1708
1709 if (ev.type == KeyPress && hidden_pointer == 0)
1710 pointer_blank ();
1711 }
1712#endif
1713
1714 refresh_check ();
1662} 1715}
1716
1717#if ENABLE_FRILLS
1718void
1719rxvt_term::set_urgency (bool enable)
1720{
1721 if (enable == urgency_hint)
1722 return;
1723
1724 if (XWMHints *h = XGetWMHints (dpy, parent))
1725 {
1726 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1727 XSetWMHints (dpy, parent, h);
1728 urgency_hint = enable;
1729 XFree (h);
1730 }
1731}
1732#endif
1663 1733
1664void 1734void
1665rxvt_term::focus_in () 1735rxvt_term::focus_in ()
1666{ 1736{
1667 if (!focus) 1737 if (!focus)
1668 { 1738 {
1669 focus = 1; 1739 focus = 1;
1670 want_refresh = 1; 1740 want_refresh = 1;
1741
1671#if USE_XIM 1742#if USE_XIM
1672 if (Input_Context != NULL) 1743 if (Input_Context != NULL)
1673 { 1744 {
1674 IMSetStatusPosition (); 1745 im_set_position ();
1675 XSetICFocus (Input_Context); 1746 XSetICFocus (Input_Context);
1676 } 1747 }
1677#endif 1748#endif
1678#if CURSOR_BLINK 1749#if CURSOR_BLINK
1679 if (options & Opt_cursorBlink) 1750 if (option (Opt_cursorBlink))
1680 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1751 cursor_blink_ev.again ();
1681#endif 1752#endif
1682#if OFF_FOCUS_FADING 1753#if OFF_FOCUS_FADING
1683 if (rs[Rs_fade]) 1754 if (rs[Rs_fade])
1684 { 1755 {
1685 pix_colors = pix_colors_focused; 1756 pix_colors = pix_colors_focused;
1686 scr_recolour (); 1757 scr_recolour ();
1687 } 1758 }
1688#endif 1759#endif
1760#if ENABLE_FRILLS
1761 if (option (Opt_urgentOnBell))
1762 set_urgency (0);
1763#endif
1764
1765 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1689 } 1766 }
1690} 1767}
1691 1768
1692void 1769void
1693rxvt_term::focus_out () 1770rxvt_term::focus_out ()
1695 if (focus) 1772 if (focus)
1696 { 1773 {
1697 focus = 0; 1774 focus = 0;
1698 want_refresh = 1; 1775 want_refresh = 1;
1699 1776
1777#if ENABLE_FRILLS
1778 if (option (Opt_urgentOnBell))
1779 set_urgency (0);
1780#endif
1700#if ENABLE_FRILLS || ISO_14755 1781#if ENABLE_FRILLS || ISO_14755
1782 if (iso14755buf)
1783 {
1701 iso14755buf = 0; 1784 iso14755buf = 0;
1702#endif 1785# if ISO_14755
1703#if ENABLE_OVERLAY
1704 scr_overlay_off (); 1786 scr_overlay_off ();
1787# endif
1788 }
1705#endif 1789#endif
1706#if USE_XIM 1790#if USE_XIM
1707 if (Input_Context != NULL) 1791 if (Input_Context != NULL)
1708 XUnsetICFocus (Input_Context); 1792 XUnsetICFocus (Input_Context);
1709#endif 1793#endif
1710#if CURSOR_BLINK 1794#if CURSOR_BLINK
1711 if (options & Opt_cursorBlink) 1795 if (option (Opt_cursorBlink))
1712 cursor_blink_ev.stop (); 1796 cursor_blink_ev.stop ();
1797
1713 hidden_cursor = 0; 1798 hidden_cursor = 0;
1714#endif 1799#endif
1715#if OFF_FOCUS_FADING 1800#if OFF_FOCUS_FADING
1716 if (rs[Rs_fade]) 1801 if (rs[Rs_fade])
1717 { 1802 {
1718 pix_colors = pix_colors_unfocused; 1803 pix_colors = pix_colors_unfocused;
1719 scr_recolour (); 1804 scr_recolour ();
1720 } 1805 }
1721#endif 1806#endif
1807
1808 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1809 }
1810}
1811
1812void
1813rxvt_term::update_fade_color (unsigned int idx)
1814{
1815#if OFF_FOCUS_FADING
1816 if (rs[Rs_fade])
1722 } 1817 {
1818 rgba c;
1819 pix_colors [Color_fade].get (c);
1820 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1821 }
1822#endif
1723} 1823}
1724 1824
1725#if TRANSPARENT 1825#if ENABLE_TRANSPARENCY || ENABLE_PERL
1726void 1826void
1727rxvt_term::rootwin_cb (XEvent &ev) 1827rxvt_term::rootwin_cb (XEvent &ev)
1728{ 1828{
1729 SET_R (this); 1829 make_current ();
1730 SET_LOCALE (locale);
1731 1830
1831 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1832 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1833 return;
1834
1835# if ENABLE_TRANSPARENCY
1732 switch (ev.type) 1836 switch (ev.type)
1733 { 1837 {
1734 case PropertyNotify: 1838 case PropertyNotify:
1735 /* 1839 /*
1736 * if user used some Esetroot compatible prog to set the root bg, 1840 * if user used some Esetroot compatible prog to set the root bg,
1737 * use the property to determine the pixmap. We use it later on. 1841 * use the property to determine the pixmap. We use it later on.
1738 */ 1842 */
1739 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1843 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1740 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1844 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1741 return; 1845 {
1846 bg_set_root_pixmap ();
1847 update_background ();
1848 }
1742 1849
1743 /* FALLTHROUGH */
1744 case ReparentNotify:
1745 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1746 want_refresh = want_full_refresh = 1;
1747 break; 1850 break;
1748 } 1851 }
1852# endif
1853
1854 refresh_check ();
1749} 1855}
1750#endif 1856#endif
1751 1857
1752void 1858void
1753rxvt_term::button_press (XButtonEvent &ev) 1859rxvt_term::button_press (XButtonEvent &ev)
1754{ 1860{
1755 int reportmode = 0, clickintime; 1861 int reportmode = 0, clickintime;
1756 1862
1757 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1863 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1864
1758 if (!bypass_keystate) 1865 if (!bypass_keystate)
1759 reportmode = !! (priv_modes & PrivMode_mouse_report); 1866 reportmode = !! (priv_modes & PrivMode_mouse_report);
1760 1867
1761 /* 1868 /*
1762 * VT window processing of button press 1869 * VT window processing of button press
1763 */ 1870 */
1764 if (ev.window == vt) 1871 if (ev.window == vt)
1765 { 1872 {
1873 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1874 return;
1875
1766#if ISO_14755 1876#if ISO_14755
1767 // 5.4 1877 // 5.4
1768 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1878 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1769 { 1879 {
1770 iso14755_54 (ev.x, ev.y); 1880 iso14755_54 (ev.x, ev.y);
1780 /* save the xbutton state (for ButtonRelease) */ 1890 /* save the xbutton state (for ButtonRelease) */
1781 MEvent.state = ev.state; 1891 MEvent.state = ev.state;
1782#ifdef MOUSE_REPORT_DOUBLECLICK 1892#ifdef MOUSE_REPORT_DOUBLECLICK
1783 if (ev.button == MEvent.button && clickintime) 1893 if (ev.button == MEvent.button && clickintime)
1784 { 1894 {
1785 /* same button, within alloted time */ 1895 /* same button, within allowed time */
1786 MEvent.clicks++; 1896 MEvent.clicks++;
1897
1787 if (MEvent.clicks > 1) 1898 if (MEvent.clicks > 1)
1788 { 1899 {
1789 /* only report double clicks */ 1900 /* only report double clicks */
1790 MEvent.clicks = 2; 1901 MEvent.clicks = 2;
1791 mouse_report (ev); 1902 mouse_report (ev);
1803 mouse_report (ev); 1914 mouse_report (ev);
1804 } 1915 }
1805#else 1916#else
1806 MEvent.button = ev.button; 1917 MEvent.button = ev.button;
1807 mouse_report (ev); 1918 mouse_report (ev);
1808#endif /* MOUSE_REPORT_DOUBLECLICK */ 1919#endif /* MOUSE_REPORT_DOUBLECLICK */
1809 1920
1810 } 1921 }
1811 else 1922 else
1812 { 1923 {
1813 if (ev.button != MEvent.button) 1924 if (ev.button != MEvent.button)
1823#else 1934#else
1824 selection.rect = false; 1935 selection.rect = false;
1825#endif 1936#endif
1826 1937
1827 /* allow shift+left click to extend selection */ 1938 /* allow shift+left click to extend selection */
1828 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1939 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1829 { 1940 {
1830 if (MEvent.button == Button1 && clickintime) 1941 if (MEvent.button == Button1 && clickintime)
1831 selection_rotate (ev.x, ev.y); 1942 selection_rotate (ev.x, ev.y);
1832 else 1943 else
1833 selection_extend (ev.x, ev.y, 1); 1944 selection_extend (ev.x, ev.y, 1);
1861 } 1972 }
1862 1973
1863 /* 1974 /*
1864 * Scrollbar window processing of button press 1975 * Scrollbar window processing of button press
1865 */ 1976 */
1866 if (isScrollbarWindow (ev.window)) 1977 if (scrollBar.state && ev.window == scrollBar.win)
1867 { 1978 {
1868 scrollBar.setIdle (); 1979 page_dirn direction = NO_DIR;
1980
1981 if (scrollBar.upButton (ev.y))
1982 direction = UP; /* up */
1983 else if (scrollBar.dnButton (ev.y))
1984 direction = DN; /* down */
1985
1986 scrollBar.state = SB_STATE_IDLE;
1869 /* 1987 /*
1870 * Rxvt-style scrollbar: 1988 * Rxvt-style scrollbar:
1871 * move up if mouse is above slider 1989 * move up if mouse is above slider
1872 * move dn if mouse is below slider 1990 * move dn if mouse is below slider
1873 * 1991 *
1882 /* 2000 /*
1883 * Mouse report disabled scrollbar: 2001 * Mouse report disabled scrollbar:
1884 * arrow buttons - send up/down 2002 * arrow buttons - send up/down
1885 * click on scrollbar - send pageup/down 2003 * click on scrollbar - send pageup/down
1886 */ 2004 */
1887 if ((scrollBar.style == R_SB_NEXT 2005 if (direction == UP)
1888 && scrollbarnext_upButton (ev.y))
1889 || (scrollBar.style == R_SB_RXVT
1890 && scrollbarrxvt_upButton (ev.y)))
1891 tt_printf ("\033[A"); 2006 tt_printf ("\033[A");
1892 else if ((scrollBar.style == R_SB_NEXT 2007 else if (direction == DN)
1893 && scrollbarnext_dnButton (ev.y))
1894 || (scrollBar.style == R_SB_RXVT
1895 && scrollbarrxvt_dnButton (ev.y)))
1896 tt_printf ("\033[B"); 2008 tt_printf ("\033[B");
1897 else 2009 else
1898 switch (ev.button) 2010 switch (ev.button)
1899 { 2011 {
1900 case Button2: 2012 case Button2:
1907 tt_printf ("\033[5~"); 2019 tt_printf ("\033[5~");
1908 break; 2020 break;
1909 } 2021 }
1910 } 2022 }
1911 else 2023 else
1912#endif /* NO_SCROLLBAR_REPORT */ 2024#endif /* NO_SCROLLBAR_REPORT */
1913
1914 {
1915 char upordown = 0;
1916
1917 if (scrollBar.style == R_SB_NEXT)
1918 { 2025 {
1919 if (scrollbarnext_upButton (ev.y)) 2026 if (direction != NO_DIR)
1920 upordown = -1; /* up */
1921 else if (scrollbarnext_dnButton (ev.y))
1922 upordown = 1; /* down */
1923 }
1924 else if (scrollBar.style == R_SB_RXVT)
1925 {
1926 if (scrollbarrxvt_upButton (ev.y))
1927 upordown = -1; /* up */
1928 else if (scrollbarrxvt_dnButton (ev.y))
1929 upordown = 1; /* down */
1930 }
1931 if (upordown)
1932 { 2027 {
1933#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 2028#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2029 if (!cont_scroll_ev.is_active ())
1934 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 2030 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1935#endif 2031#endif
1936 if (scr_page (upordown < 0 ? UP : DN, 1)) 2032 if (scr_page (direction, 1))
1937 { 2033 {
1938 if (upordown < 0) 2034 if (direction == UP)
1939 scrollBar.setUp (); 2035 scrollBar.state = SB_STATE_UP;
1940 else 2036 else
1941 scrollBar.setDn (); 2037 scrollBar.state = SB_STATE_DOWN;
1942 } 2038 }
1943 } 2039 }
1944 else 2040 else
1945 switch (ev.button) 2041 switch (ev.button)
1946 { 2042 {
1947 case Button2: 2043 case Button2:
1948 switch (scrollbar_align) 2044 switch (scrollBar.align)
1949 { 2045 {
1950 case R_SB_ALIGN_TOP: 2046 case SB_ALIGN_TOP:
1951 csrO = 0; 2047 csrO = 0;
1952 break; 2048 break;
1953 case R_SB_ALIGN_CENTRE: 2049 case SB_ALIGN_CENTRE:
1954 csrO = (scrollBar.bot - scrollBar.top) / 2; 2050 csrO = (scrollBar.bot - scrollBar.top) / 2;
1955 break; 2051 break;
1956 case R_SB_ALIGN_BOTTOM: 2052 case SB_ALIGN_BOTTOM:
1957 csrO = scrollBar.bot - scrollBar.top; 2053 csrO = scrollBar.bot - scrollBar.top;
1958 break; 2054 break;
1959 } 2055 }
1960 2056
1961 if (scrollBar.style == R_SB_XTERM 2057 if (scrollBar.style == SB_STYLE_XTERM
1962 || scrollbar_above_slider (ev.y) 2058 || scrollBar.above_slider (ev.y)
1963 || scrollbar_below_slider (ev.y)) 2059 || scrollBar.below_slider (ev.y))
1964 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2060 scr_move_to (scrollBar.position (ev.y) - csrO, scrollBar.size ());
1965 2061
1966 scrollBar.setMotion (); 2062 scrollBar.state = SB_STATE_MOTION;
1967 break; 2063 break;
1968 2064
1969 case Button1: 2065 case Button1:
1970 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2066 if (scrollBar.align == SB_ALIGN_CENTRE)
1971 csrO = ev.y - scrollBar.top; 2067 csrO = ev.y - scrollBar.top;
1972 /* FALLTHROUGH */ 2068 /* FALLTHROUGH */
1973 2069
1974 case Button3: 2070 case Button3:
1975 if (scrollBar.style != R_SB_XTERM) 2071 if (scrollBar.style != SB_STYLE_XTERM)
1976 { 2072 {
1977 if (scrollbar_above_slider (ev.y)) 2073 if (scrollBar.above_slider (ev.y))
1978# ifdef RXVT_SCROLL_FULL 2074# ifdef RXVT_SCROLL_FULL
1979 scr_page (UP, nrow - 1); 2075 scr_page (UP, nrow - 1);
1980# else 2076# else
1981 scr_page (UP, nrow / 4); 2077 scr_page (UP, nrow / 4);
1982# endif 2078# endif
1983 else if (scrollbar_below_slider (ev.y)) 2079 else if (scrollBar.below_slider (ev.y))
1984# ifdef RXVT_SCROLL_FULL 2080# ifdef RXVT_SCROLL_FULL
1985 scr_page (DN, nrow - 1); 2081 scr_page (DN, nrow - 1);
1986# else 2082# else
1987 scr_page (DN, nrow / 4); 2083 scr_page (DN, nrow / 4);
1988# endif 2084# endif
1989 else 2085 else
1990 scrollBar.setMotion (); 2086 scrollBar.state = SB_STATE_MOTION;
1991 } 2087 }
1992 else 2088 else
1993 { 2089 {
1994 scr_page ((ev.button == Button1 ? DN : UP), 2090 scr_page ((ev.button == Button1 ? DN : UP),
1995 (nrow 2091 (nrow
1996 * scrollbar_position (ev.y) 2092 * scrollBar.position (ev.y)
1997 / scrollbar_size ())); 2093 / scrollBar.size ()));
1998 } 2094 }
1999 2095
2000 break; 2096 break;
2001 } 2097 }
2002 } 2098 }
2099
2003 return; 2100 return;
2004 } 2101 }
2005#if MENUBAR
2006 /*
2007 * Menubar window processing of button press
2008 */
2009 if (isMenuBarWindow (ev.window))
2010 menubar_control (ev);
2011#endif
2012} 2102}
2013 2103
2014void 2104void
2015rxvt_term::button_release (XButtonEvent &ev) 2105rxvt_term::button_release (XButtonEvent &ev)
2016{ 2106{
2018 2108
2019 csrO = 0; /* reset csr Offset */ 2109 csrO = 0; /* reset csr Offset */
2020 if (!bypass_keystate) 2110 if (!bypass_keystate)
2021 reportmode = !! (priv_modes & PrivMode_mouse_report); 2111 reportmode = !! (priv_modes & PrivMode_mouse_report);
2022 2112
2023 if (scrollbar_isUpDn ()) 2113 if (scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN)
2024 { 2114 {
2025 scrollBar.setIdle (); 2115 scrollBar.state = SB_STATE_IDLE;
2026 scrollbar_show (0); 2116 scrollBar.show (0);
2027#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2028 refresh_type &= ~SMOOTH_REFRESH;
2029#endif
2030 } 2117 }
2031 2118
2032#ifdef SELECTION_SCROLLING 2119#ifdef SELECTION_SCROLLING
2033 if (sel_scroll_ev.active)
2034 sel_scroll_ev.stop(); 2120 sel_scroll_ev.stop();
2035#endif 2121#endif
2036 2122
2037 if (ev.window == vt) 2123 if (ev.window == vt)
2038 { 2124 {
2125 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2126 return;
2127
2039#if ISO_14755 2128#if ISO_14755
2040 // 5.4 2129 // 5.4
2041 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2130 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2042 return; 2131 return;
2043#endif 2132#endif
2133
2044 if (reportmode) 2134 if (reportmode)
2045 { 2135 {
2046 /* mouse report from vt window */ 2136 /* mouse report from vt window */
2047 /* don't report release of wheel "buttons" */ 2137 /* don't report release of wheel "buttons" */
2048 if (ev.button >= 4) 2138 if (ev.button >= 4)
2059 mouse_report (ev); 2149 mouse_report (ev);
2060 } 2150 }
2061#else /* MOUSE_REPORT_DOUBLECLICK */ 2151#else /* MOUSE_REPORT_DOUBLECLICK */
2062 MEvent.button = AnyButton; 2152 MEvent.button = AnyButton;
2063 mouse_report (ev); 2153 mouse_report (ev);
2064#endif /* MOUSE_REPORT_DOUBLECLICK */ 2154#endif /* MOUSE_REPORT_DOUBLECLICK */
2065 return; 2155 return;
2066 } 2156 }
2067 2157
2068 /* 2158 /*
2069 * dumb hack to compensate for the failure of click-and-drag 2159 * dumb hack to compensate for the failure of click-and-drag
2078 { 2168 {
2079 case Button1: 2169 case Button1:
2080 case Button3: 2170 case Button3:
2081 selection_make (ev.time); 2171 selection_make (ev.time);
2082 break; 2172 break;
2173
2083 case Button2: 2174 case Button2:
2084 selection_request (ev.time, ev.x, ev.y); 2175 if (IN_RANGE_EXC (ev.x, 0, vt_width) && IN_RANGE_EXC (ev.y, 0, vt_height)) // inside window?
2176 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2085 break; 2177 break;
2178
2086#ifdef MOUSE_WHEEL 2179#ifdef MOUSE_WHEEL
2087 case Button4: 2180 case Button4:
2088 case Button5: 2181 case Button5:
2089 { 2182 {
2090 int i; 2183 int i;
2092 2185
2093 v = ev.button == Button4 ? UP : DN; 2186 v = ev.button == Button4 ? UP : DN;
2094 2187
2095 if (ev.state & ShiftMask) 2188 if (ev.state & ShiftMask)
2096 i = 1; 2189 i = 1;
2097 else if (options & Opt_mouseWheelScrollPage) 2190 else if (option (Opt_mouseWheelScrollPage))
2098 i = nrow - 1; 2191 i = nrow - 1;
2099 else 2192 else
2100 i = 5; 2193 i = 5;
2101 2194
2102# ifdef MOUSE_SLIP_WHEELING 2195# ifdef MOUSE_SLIP_WHEELING
2104 { 2197 {
2105 mouse_slip_wheel_speed += v ? -1 : 1; 2198 mouse_slip_wheel_speed += v ? -1 : 1;
2106 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2199 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2107 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2200 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2108 2201
2109 if (slip_wheel_ev.at < NOW) 2202 if (!slip_wheel_ev.is_active ())
2110 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2203 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2111
2112 slip_wheel_ev.start ();
2113 } 2204 }
2114 else 2205 else
2206# endif
2115 { 2207 {
2116# endif
2117# ifdef JUMP_MOUSE_WHEEL
2118 scr_page (v, i); 2208 scr_page (v, i);
2119 scr_refresh (SMOOTH_REFRESH);
2120 scrollbar_show (1); 2209 scrollBar.show (1);
2121# else
2122 while (i--)
2123 {
2124 scr_page (v, 1);
2125 scr_refresh (SMOOTH_REFRESH);
2126 scrollbar_show (1);
2127 }
2128# endif
2129# ifdef MOUSE_SLIP_WHEELING
2130 } 2210 }
2131#endif
2132 } 2211 }
2133 break; 2212 break;
2134#endif 2213#endif
2135 } 2214 }
2136 } 2215 }
2137#ifdef MENUBAR
2138 else if (isMenuBarWindow (ev.window))
2139 menubar_control (ev);
2140#endif
2141} 2216}
2142
2143#ifdef TRANSPARENT
2144#if TINTING
2145/* taken from aterm-0.4.2 */
2146
2147typedef uint32_t RUINT32T;
2148
2149void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2150{
2151 int sh_r, sh_g, sh_b;
2152 RUINT32T mask_r, mask_g, mask_b;
2153 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2154 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2155 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2156 int i;
2157
2158 Visual *visual = display->visual;
2159
2160 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2161
2162 /* for convenience */
2163 mask_r = visual->red_mask;
2164 mask_g = visual->green_mask;
2165 mask_b = visual->blue_mask;
2166
2167 /* boring lookup table pre-initialization */
2168 switch (srcImage->bits_per_pixel) {
2169 case 15:
2170 if ((mask_r != 0x7c00) ||
2171 (mask_g != 0x03e0) ||
2172 (mask_b != 0x001f))
2173 return;
2174 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2175 lookup_r = lookup;
2176 lookup_g = lookup+32;
2177 lookup_b = lookup+32+32;
2178 sh_r = 10;
2179 sh_g = 5;
2180 sh_b = 0;
2181 break;
2182 case 16:
2183 if ((mask_r != 0xf800) ||
2184 (mask_g != 0x07e0) ||
2185 (mask_b != 0x001f))
2186 return;
2187 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2188 lookup_r = lookup;
2189 lookup_g = lookup+32;
2190 lookup_b = lookup+32+64;
2191 sh_r = 11;
2192 sh_g = 5;
2193 sh_b = 0;
2194 break;
2195 case 24:
2196 if ((mask_r != 0xff0000) ||
2197 (mask_g != 0x00ff00) ||
2198 (mask_b != 0x0000ff))
2199 return;
2200 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2201 lookup_r = lookup;
2202 lookup_g = lookup+256;
2203 lookup_b = lookup+256+256;
2204 sh_r = 16;
2205 sh_g = 8;
2206 sh_b = 0;
2207 break;
2208 case 32:
2209 if ((mask_r != 0xff0000) ||
2210 (mask_g != 0x00ff00) ||
2211 (mask_b != 0x0000ff))
2212 return;
2213 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2214 lookup_r = lookup;
2215 lookup_g = lookup+256;
2216 lookup_b = lookup+256+256;
2217 sh_r = 16;
2218 sh_g = 8;
2219 sh_b = 0;
2220 break;
2221 default:
2222 return; /* we do not support this color depth */
2223 }
2224
2225 /* prepare limits for color transformation (each channel is handled separately) */
2226 if (shade < 0) {
2227 shade = -shade;
2228 if (shade < 0) shade = 0;
2229 if (shade > 100) shade = 100;
2230
2231 lower_lim_r = 65535-rm;
2232 lower_lim_g = 65535-gm;
2233 lower_lim_b = 65535-bm;
2234
2235 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2236 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2237 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2238
2239 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2240 } else {
2241 if (shade < 0) shade = 0;
2242 if (shade > 100) shade = 100;
2243
2244 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2245
2246 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2247 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2248 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2249 }
2250
2251 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2252 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2253 {
2254 unsigned int tmp;
2255
2256 tmp = lower_lim_r;
2257 lower_lim_r = lower_lim_b;
2258 lower_lim_b = tmp;
2259
2260 tmp = upper_lim_r;
2261 upper_lim_r = upper_lim_b;
2262 upper_lim_b = tmp;
2263 }
2264
2265 /* fill our lookup tables */
2266 for (i = 0; i <= mask_r>>sh_r; i++)
2267 {
2268 RUINT32T tmp;
2269 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2270 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2271 lookup_r[i] = (tmp/65535)<<sh_r;
2272 }
2273 for (i = 0; i <= mask_g>>sh_g; i++)
2274 {
2275 RUINT32T tmp;
2276 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2277 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2278 lookup_g[i] = (tmp/65535)<<sh_g;
2279 }
2280 for (i = 0; i <= mask_b>>sh_b; i++)
2281 {
2282 RUINT32T tmp;
2283 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2284 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2285 lookup_b[i] = (tmp/65535)<<sh_b;
2286 }
2287
2288 /* apply table to input image (replacing colors by newly calculated ones) */
2289 switch (srcImage->bits_per_pixel)
2290 {
2291 case 15:
2292 {
2293 unsigned short *p1, *pf, *p, *pl;
2294 p1 = (unsigned short *) srcImage->data;
2295 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2296 while (p1 < pf)
2297 {
2298 p = p1;
2299 pl = p1 + srcImage->width;
2300 for (; p < pl; p++)
2301 {
2302 *p = lookup_r[(*p & 0x7c00)>>10] |
2303 lookup_g[(*p & 0x03e0)>> 5] |
2304 lookup_b[(*p & 0x001f)];
2305 }
2306 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2307 }
2308 break;
2309 }
2310 case 16:
2311 {
2312 unsigned short *p1, *pf, *p, *pl;
2313 p1 = (unsigned short *) srcImage->data;
2314 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2315 while (p1 < pf)
2316 {
2317 p = p1;
2318 pl = p1 + srcImage->width;
2319 for (; p < pl; p++)
2320 {
2321 *p = lookup_r[(*p & 0xf800)>>11] |
2322 lookup_g[(*p & 0x07e0)>> 5] |
2323 lookup_b[(*p & 0x001f)];
2324 }
2325 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2326 }
2327 break;
2328 }
2329 case 24:
2330 {
2331 unsigned char *p1, *pf, *p, *pl;
2332 p1 = (unsigned char *) srcImage->data;
2333 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2334 while (p1 < pf)
2335 {
2336 p = p1;
2337 pl = p1 + srcImage->width * 3;
2338 for (; p < pl; p += 3)
2339 {
2340 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2341 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2342 p[2] = lookup_r[(p[2] & 0x0000ff)];
2343 }
2344 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2345 }
2346 break;
2347 }
2348 case 32:
2349 {
2350 RUINT32T *p1, *pf, *p, *pl;
2351 p1 = (RUINT32T *) srcImage->data;
2352 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2353
2354 while (p1 < pf)
2355 {
2356 p = p1;
2357 pl = p1 + srcImage->width;
2358 for (; p < pl; p++)
2359 {
2360 *p = lookup_r[(*p & 0xff0000)>>16] |
2361 lookup_g[(*p & 0x00ff00)>> 8] |
2362 lookup_b[(*p & 0x0000ff)] |
2363 (*p & ~0xffffff);
2364 }
2365 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2366 }
2367 break;
2368 }
2369 }
2370
2371 free (lookup);
2372}
2373#endif
2374
2375/*
2376 * Check our parents are still who we think they are.
2377 * Do transparency updates if required
2378 */
2379int
2380rxvt_term::check_our_parents ()
2381{
2382 int i, pchanged, aformat, have_pixmap, rootdepth;
2383 unsigned long nitems, bytes_after;
2384 Atom atype;
2385 unsigned char *prop = NULL;
2386 Window root, oldp, *list;
2387 Pixmap rootpixmap = None;
2388 XWindowAttributes wattr, wrootattr;
2389 dDisp;
2390
2391 pchanged = 0;
2392
2393 if (!(options & Opt_transparent))
2394 return pchanged; /* Don't try any more */
2395
2396 XGetWindowAttributes (disp, display->root, &wrootattr);
2397 rootdepth = wrootattr.depth;
2398
2399 XGetWindowAttributes (disp, parent[0], &wattr);
2400
2401 if (rootdepth != wattr.depth)
2402 {
2403 if (am_transparent)
2404 {
2405 pchanged = 1;
2406 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2407 am_transparent = am_pixmap_trans = 0;
2408 }
2409
2410 return pchanged; /* Don't try any more */
2411 }
2412
2413 /* Get all X ops out of the queue so that our information is up-to-date. */
2414 XSync (disp, False);
2415
2416 /*
2417 * Make the frame window set by the window manager have
2418 * the root background. Some window managers put multiple nested frame
2419 * windows for each client, so we have to take care about that.
2420 */
2421 i = (xa[XA_XROOTPMAP_ID]
2422 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2423 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2424 &nitems, &bytes_after, &prop) == Success);
2425
2426 if (!i || prop == NULL)
2427 i = (xa[XA_ESETROOT_PMAP_ID]
2428 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2429 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2430 &nitems, &bytes_after, &prop) == Success);
2431
2432 if (!i || prop == NULL
2433#if TINTING
2434 || !rs[Rs_color + Color_tint]
2435#endif
2436 )
2437 have_pixmap = 0;
2438 else
2439 {
2440 have_pixmap = 1;
2441 rootpixmap = *(Pixmap *)prop;
2442 XFree (prop);
2443 }
2444
2445 if (have_pixmap)
2446 {
2447 /*
2448 * Copy display->root pixmap transparency
2449 */
2450 int sx, sy, nx, ny;
2451 unsigned int nw, nh;
2452 Window cr;
2453 XImage *image;
2454 GC gc;
2455 XGCValues gcvalue;
2456
2457 XTranslateCoordinates (disp, parent[0], display->root,
2458 0, 0, &sx, &sy, &cr);
2459 nw = (unsigned int)szHint.width;
2460 nh = (unsigned int)szHint.height;
2461 nx = ny = 0;
2462
2463 if (sx < 0)
2464 {
2465 nw += sx;
2466 nx = -sx;
2467 sx = 0;
2468 }
2469
2470 if (sy < 0)
2471 {
2472 nh += sy;
2473 ny = -sy;
2474 sy = 0;
2475 }
2476
2477 min_it (nw, (unsigned int) (wrootattr.width - sx));
2478 min_it (nh, (unsigned int) (wrootattr.height - sy));
2479
2480 XSync (disp, False);
2481 allowedxerror = -1;
2482 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2483
2484 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2485 /* XXX: may need a delay here? */
2486 allowedxerror = 0;
2487
2488 if (image == NULL)
2489 {
2490 if (am_transparent && am_pixmap_trans)
2491 {
2492 pchanged = 1;
2493 if (pixmap != None)
2494 {
2495 XFreePixmap (disp, pixmap);
2496 pixmap = None;
2497 }
2498 }
2499
2500 am_pixmap_trans = 0;
2501 }
2502 else
2503 {
2504 if (pixmap != None)
2505 XFreePixmap (disp, pixmap);
2506
2507#if TINTING
2508 if (ISSET_PIXCOLOR (Color_tint))
2509 {
2510 unsigned short rm, gm, bm;
2511 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2512
2513 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2514
2515 ShadeXImage (display, image, shade, rm, gm, bm);
2516 }
2517#endif
2518
2519 pixmap = XCreatePixmap (disp, vt,
2520 szHint.width, szHint.height, image->depth);
2521 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2522 XPutImage (disp, pixmap, gc, image, 0, 0,
2523 nx, ny, image->width, image->height);
2524 XFreeGC (disp, gc);
2525 XDestroyImage (image);
2526 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2527 XClearWindow (disp, parent[0]);
2528
2529 if (!am_transparent || !am_pixmap_trans)
2530 pchanged = 1;
2531
2532 am_transparent = am_pixmap_trans = 1;
2533 }
2534 }
2535
2536 if (am_pixmap_trans)
2537 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2538 else
2539 {
2540 unsigned int n;
2541 /*
2542 * InheritPixmap transparency
2543 */
2544 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2545 {
2546 oldp = parent[i];
2547 XQueryTree (disp, parent[i - 1], &root,
2548 &parent[i], &list, &n);
2549 XFree (list);
2550
2551 if (parent[i] == display->root)
2552 {
2553 if (oldp != None)
2554 pchanged = 1;
2555
2556 break;
2557 }
2558
2559 if (oldp != parent[i])
2560 pchanged = 1;
2561 }
2562
2563 n = 0;
2564
2565 if (pchanged)
2566 {
2567 for (; n < (unsigned int)i; n++)
2568 {
2569 XGetWindowAttributes (disp, parent[n], &wattr);
2570 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2571 {
2572 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2573 break;
2574 }
2575 }
2576 }
2577
2578 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2579 {
2580 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2581 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2582 am_transparent = 0;
2583 /* XXX: also turn off Opt_transparent? */
2584 }
2585 else
2586 {
2587#if WAIT_FOR_WM
2588 /* wait (an arbitrary period) for the WM to do its thing
2589 * needed for fvwm2.2.2 (and before?) */
2590 sleep (1);
2591#endif
2592 for (n = 0; n < (unsigned int)i; n++)
2593 {
2594 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2595 XClearWindow (disp, parent[n]);
2596 }
2597
2598 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2599 am_transparent = 1;
2600 }
2601
2602 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2603 parent[i] = None;
2604 }
2605
2606 if (scrollBar.win)
2607 {
2608 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2609 scrollBar.setIdle ();
2610 scrollbar_show (0);
2611 }
2612
2613 if (am_transparent)
2614 {
2615 want_refresh = want_full_refresh = 1;
2616 if (am_pixmap_trans)
2617 flush ();
2618 }
2619
2620 return pchanged;
2621}
2622#endif
2623 2217
2624/*}}} */ 2218/*}}} */
2625 2219
2626bool 2220void
2627rxvt_term::cmd_parse () 2221rxvt_term::cmd_parse ()
2628{ 2222{
2629 bool flag = false;
2630 unicode_t ch = NOCHAR; 2223 wchar_t ch = NOCHAR;
2631 unsigned char *seq_begin; // remember start of esc-sequence here 2224 char *seq_begin; // remember start of esc-sequence here
2632 2225
2633 for (;;) 2226 for (;;)
2634 { 2227 {
2635 if (ch == NOCHAR) 2228 if (ecb_unlikely (ch == NOCHAR))
2636 { 2229 {
2637 seq_begin = cmdbuf_ptr; 2230 seq_begin = cmdbuf_ptr;
2638 ch = next_char (); 2231 ch = next_char ();
2639 }
2640 2232
2641 if (ch == NOCHAR) // TODO: improve 2233 if (ch == NOCHAR)
2642 break; 2234 break;
2235 }
2643 2236
2644 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2237 if (ecb_likely (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2645 { 2238 {
2646 if (!seen_input) 2239 if (ecb_unlikely (!seen_input))
2647 { 2240 {
2648 seen_input = 1; 2241 seen_input = 1;
2649 // many badly-written programs (e.g. jed) contain a race condition: 2242 // many badly-written programs (e.g. jed) contain a race condition:
2650 // they first read the screensize and then install a SIGWINCH handler. 2243 // they first read the screensize and then install a SIGWINCH handler.
2651 // some window managers resize the window early, and these programs 2244 // some window managers resize the window early, and these programs
2656 if (seen_resize && cmd_pid) 2249 if (seen_resize && cmd_pid)
2657 kill (-cmd_pid, SIGWINCH); 2250 kill (-cmd_pid, SIGWINCH);
2658 } 2251 }
2659 2252
2660 /* Read a text string from the input buffer */ 2253 /* Read a text string from the input buffer */
2661 unicode_t buf[UBUFSIZ]; 2254 wchar_t buf[UBUFSIZ];
2662 bool refreshnow = false; 2255 bool refreshnow = false;
2663 int nlines = 0; 2256 int nlines = 0;
2664 unicode_t *str = buf; 2257 wchar_t *str = buf;
2665 unicode_t *eol = str + min (ncol, UBUFSIZ); 2258 wchar_t *eol = str + min (ncol, UBUFSIZ);
2666 2259
2667 for (;;) 2260 for (;;)
2668 { 2261 {
2669 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2262 if (ecb_unlikely (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2670 break; 2263 break;
2671 2264
2672 *str++ = ch; 2265 *str++ = ch;
2673 2266
2674 if (ch == C0_LF || str >= eol) 2267 if (ecb_unlikely (ch == C0_LF || str >= eol))
2675 { 2268 {
2676 if (ch == C0_LF) 2269 if (ch == C0_LF)
2677 nlines++; 2270 nlines++;
2678 2271
2679 refresh_count++; 2272 refresh_count++;
2680 2273
2681 if (!(options & Opt_jumpScroll) 2274 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2682 || (refresh_count >= refresh_limit * (nrow - 1)))
2683 { 2275 {
2276 refresh_count = 0;
2277
2278 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2279 {
2684 refreshnow = true; 2280 refreshnow = true;
2685 ch = NOCHAR; 2281 ch = NOCHAR;
2686 break; 2282 break;
2283 }
2687 } 2284 }
2688 2285
2689 // scr_add_lines only works for nlines <= nrow - 1. 2286 // scr_add_lines only works for nlines <= nrow - 1.
2690 if (nlines >= nrow - 1) 2287 if (nlines >= nrow - 1)
2691 { 2288 {
2289 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2290 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2692 scr_add_lines (buf, nlines, str - buf); 2291 scr_add_lines (buf, str - buf, nlines);
2292
2693 nlines = 0; 2293 nlines = 0;
2694 str = buf; 2294 str = buf;
2695 eol = str + min (ncol, UBUFSIZ); 2295 eol = str + min (ncol, UBUFSIZ);
2696 } 2296 }
2697 2297
2710 2310
2711 seq_begin = cmdbuf_ptr; 2311 seq_begin = cmdbuf_ptr;
2712 ch = next_char (); 2312 ch = next_char ();
2713 } 2313 }
2714 2314
2315 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2316 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2715 scr_add_lines (buf, nlines, str - buf); 2317 scr_add_lines (buf, str - buf, nlines);
2716 2318
2717 /* 2319 /*
2718 * If there have been a lot of new lines, then update the screen 2320 * If there have been a lot of new lines, then update the screen
2719 * What the heck I'll cheat and only refresh less than every page-full. 2321 * What the heck we'll cheat and only refresh less than every page-full.
2720 * the number of pages between refreshes is refresh_limit, which 2322 * if skipScroll is enabled.
2721 * is incremented here because we must be doing flat-out scrolling.
2722 */ 2323 */
2723 if (refreshnow) 2324 if (refreshnow)
2724 { 2325 {
2725 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2726 refresh_limit++;
2727 else
2728 {
2729 flag = true;
2730 scr_refresh (refresh_type); 2326 scr_refresh ();
2731 } 2327 want_refresh = 1;
2732 } 2328 }
2733
2734 } 2329 }
2735 else 2330 else
2736 { 2331 {
2737 try 2332 try
2738 { 2333 {
2746 } 2341 }
2747 2342
2748 ch = NOCHAR; 2343 ch = NOCHAR;
2749 } 2344 }
2750 } 2345 }
2751
2752 return flag;
2753}
2754
2755// read the next octet
2756unicode_t
2757rxvt_term::next_octet ()
2758{
2759 return cmdbuf_ptr < cmdbuf_endp
2760 ? *cmdbuf_ptr++
2761 : NOCHAR;
2762} 2346}
2763 2347
2764// read the next character 2348// read the next character
2765unicode_t 2349wchar_t
2766rxvt_term::next_char () 2350rxvt_term::next_char () NOTHROW
2767{ 2351{
2768 while (cmdbuf_ptr < cmdbuf_endp) 2352 while (cmdbuf_ptr < cmdbuf_endp)
2769 { 2353 {
2770 // assume 7-bit to be ascii ALWAYS 2354 // assume 7-bit to be ascii ALWAYS
2771 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2355 if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2772 return *cmdbuf_ptr++; 2356 return *cmdbuf_ptr++;
2773 2357
2774 wchar_t wc; 2358 wchar_t wc;
2775 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2359 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2776 2360
2777 if (len == (size_t)-2) 2361 if (len == (size_t)-2)
2778 { 2362 {
2779 // the mbstate stores incomplete sequences. didn't know this :/ 2363 // the mbstate stores incomplete sequences. didn't know this :/
2780 cmdbuf_ptr = cmdbuf_endp; 2364 cmdbuf_ptr = cmdbuf_endp;
2781 break; 2365 break;
2782 } 2366 }
2783 2367
2784 if (len == (size_t)-1) 2368 if (len == (size_t)-1)
2369 {
2370 mbstate.reset (); // reset now undefined conversion state
2785 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2371 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2372 }
2786 2373
2787 // assume wchar == unicode 2374 // assume wchar == unicode
2788 cmdbuf_ptr += len; 2375 cmdbuf_ptr += len;
2789 return wc & UNICODE_MASK; 2376 return wc & UNICODE_MASK;
2790 } 2377 }
2791 2378
2792 return NOCHAR; 2379 return NOCHAR;
2793} 2380}
2794 2381
2795/* rxvt_cmd_getc () - Return next input character */ 2382// read the next octet
2796/* 2383uint32_t
2797 * Return the next input character after first passing any keyboard input 2384rxvt_term::next_octet () NOTHROW
2798 * to the command.
2799 */
2800unicode_t
2801rxvt_term::cmd_getc ()
2802{ 2385{
2386 return cmdbuf_ptr < cmdbuf_endp
2387 ? (unsigned char)*cmdbuf_ptr++
2388 : NOCHAR;
2389}
2390
2391static class out_of_input out_of_input;
2392
2393wchar_t
2394rxvt_term::cmd_getc () THROW ((class out_of_input))
2395{
2803 unicode_t c = next_char (); 2396 wchar_t c = next_char ();
2804 2397
2805 if (c == NOCHAR) 2398 if (c == NOCHAR)
2806 throw out_of_input; 2399 throw out_of_input;
2807 2400
2808 return c; 2401 return c;
2809} 2402}
2810 2403
2811unicode_t 2404uint32_t
2812rxvt_term::cmd_get8 () 2405rxvt_term::cmd_get8 () THROW ((class out_of_input))
2813{ 2406{
2814 unicode_t c = next_octet (); 2407 uint32_t c = next_octet ();
2815 2408
2816 if (c == NOCHAR) 2409 if (c == NOCHAR)
2817 throw out_of_input; 2410 throw out_of_input;
2818 2411
2819 return c; 2412 return c;
2823/*----------------------------------------------------------------------*/ 2416/*----------------------------------------------------------------------*/
2824#ifdef PRINTPIPE 2417#ifdef PRINTPIPE
2825FILE * 2418FILE *
2826rxvt_term::popen_printer () 2419rxvt_term::popen_printer ()
2827{ 2420{
2828 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2421 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2829 2422
2830 if (stream == NULL) 2423 if (stream == NULL)
2831 rxvt_warn ("can't open printer pipe, not printing.\n"); 2424 rxvt_warn ("can't open printer pipe, not printing.\n");
2832 2425
2833 return stream; 2426 return stream;
2844 * simulate attached vt100 printer 2437 * simulate attached vt100 printer
2845 */ 2438 */
2846void 2439void
2847rxvt_term::process_print_pipe () 2440rxvt_term::process_print_pipe ()
2848{ 2441{
2849 int done; 2442 FILE *fd = popen_printer ();
2850 FILE *fd;
2851 2443
2852 if ((fd = popen_printer ()) == NULL) 2444 if (!fd)
2853 return; 2445 return;
2854 2446
2855 /* 2447 /*
2856 * Send all input to the printer until either ESC[4i or ESC[?4i 2448 * Send all input to the printer until either ESC[4i or ESC[?4i
2857 * is received. 2449 * is received.
2858 */ 2450 */
2859 for (done = 0; !done;) 2451 for (int done = 0; !done; )
2860 { 2452 {
2861 unsigned char buf[8]; 2453 unsigned char buf[8];
2862 unicode_t ch; 2454 unicode_t ch;
2863 unsigned int i, len; 2455 unsigned int i, len;
2864 2456
2883 { 2475 {
2884 if ((buf[len++] = cmd_getc ()) == 'i') 2476 if ((buf[len++] = cmd_getc ()) == 'i')
2885 break; /* done = 1 */ 2477 break; /* done = 1 */
2886 } 2478 }
2887 } 2479 }
2888 2480
2889 for (i = 0; i < len; i++) 2481 for (i = 0; i < len; i++)
2890 if (putc (buf[i], fd) == EOF) 2482 if (putc (buf[i], fd) == EOF)
2891 { 2483 {
2892 done = 1; 2484 done = 1;
2893 break; 2485 break;
2895 } 2487 }
2896 } 2488 }
2897 2489
2898 pclose_printer (fd); 2490 pclose_printer (fd);
2899} 2491}
2900#endif /* PRINTPIPE */ 2492#endif /* PRINTPIPE */
2901/*}}} */ 2493/*}}} */
2902 2494
2903/* *INDENT-OFF* */
2904enum { 2495enum {
2905 C1_40 = 0x40, 2496 C1_40 = 0x40,
2906 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, 2497 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2907 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, 2498 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2908 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, 2499 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2909 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, 2500 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2910}; 2501};
2911/* *INDENT-ON* */
2912 2502
2913/*{{{ process non-printing single characters */ 2503/*{{{ process non-printing single characters */
2914void 2504void
2915rxvt_term::process_nonprinting (unicode_t ch) 2505rxvt_term::process_nonprinting (unicode_t ch)
2916{ 2506{
2919 case C0_ESC: 2509 case C0_ESC:
2920 process_escape_seq (); 2510 process_escape_seq ();
2921 break; 2511 break;
2922 case C0_ENQ: /* terminal Status */ 2512 case C0_ENQ: /* terminal Status */
2923 if (rs[Rs_answerbackstring]) 2513 if (rs[Rs_answerbackstring])
2924 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2514 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2925 (unsigned int)strlen (rs[Rs_answerbackstring]));
2926 else 2515 else
2927 tt_write ((unsigned char *)VT100_ANS, 2516 tt_write (VT100_ANS, strlen (VT100_ANS));
2928 (unsigned int)strlen (VT100_ANS));
2929 break; 2517 break;
2930 case C0_BEL: /* bell */ 2518 case C0_BEL: /* bell */
2931 scr_bell (); 2519 scr_bell ();
2932 break; 2520 break;
2933 case C0_BS: /* backspace */ 2521 case C0_BS: /* backspace */
2957 process_dcs_seq (); 2545 process_dcs_seq ();
2958 break; 2546 break;
2959 case 0x9b: /* CSI */ 2547 case 0x9b: /* CSI */
2960 process_csi_seq (); 2548 process_csi_seq ();
2961 break; 2549 break;
2962 case 0x9d: /* CSI */ 2550 case 0x9d: /* OSC */
2963 process_osc_seq (); 2551 process_osc_seq ();
2964 break; 2552 break;
2965#endif 2553#endif
2966 } 2554 }
2967} 2555}
3011 break; 2599 break;
3012 case 'Z': /* identify the terminal type */ 2600 case 'Z': /* identify the terminal type */
3013 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2601 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3014 break; 2602 break;
3015 case '<': /* turn off VT52 mode */ 2603 case '<': /* turn off VT52 mode */
3016 PrivMode (0, PrivMode_vt52); 2604 priv_modes &= ~PrivMode_vt52;
3017 break; 2605 break;
3018 case 'F': /* use special graphics character set */ 2606 case 'F': /* use special graphics character set */
3019 case 'G': /* use regular character set */ 2607 case 'G': /* use regular character set */
3020 /* unimplemented */ 2608 /* unimplemented */
3021 break; 2609 break;
3040 return; 2628 return;
3041 } 2629 }
3042 2630
3043 switch (ch) 2631 switch (ch)
3044 { 2632 {
3045 /* case 1: do_tek_mode (); break; */
3046 case '#': 2633 case '#':
3047 if (cmd_getc () == '8') 2634 if (cmd_getc () == '8')
3048 scr_E (); 2635 scr_E ();
3049 break; 2636 break;
3050 case '(': 2637 case '(':
3057 scr_charset_set (2, (unsigned int)cmd_getc ()); 2644 scr_charset_set (2, (unsigned int)cmd_getc ());
3058 break; 2645 break;
3059 case '+': 2646 case '+':
3060 scr_charset_set (3, (unsigned int)cmd_getc ()); 2647 scr_charset_set (3, (unsigned int)cmd_getc ());
3061 break; 2648 break;
3062#if ENABLE_FRILLS 2649#if !ENABLE_MINIMAL
3063 case '6': 2650 case '6':
3064 scr_backindex (); 2651 scr_backindex ();
3065 break; 2652 break;
3066#endif 2653#endif
3067 case '7': 2654 case '7':
3068 scr_cursor (SAVE); 2655 scr_cursor (SAVE);
3069 break; 2656 break;
3070 case '8': 2657 case '8':
3071 scr_cursor (RESTORE); 2658 scr_cursor (RESTORE);
3072 break; 2659 break;
3073#if ENABLE_FRILLS 2660#if !ENABLE_MINIMAL
3074 case '9': 2661 case '9':
3075 scr_forwardindex (); 2662 scr_forwardindex ();
3076 break; 2663 break;
3077#endif 2664#endif
2665 // DECPAM/DECPNM
3078 case '=': 2666 case '=':
2667 priv_modes |= PrivMode_aplKP;
2668 break;
3079 case '>': 2669 case '>':
3080 PrivMode ((ch == '='), PrivMode_aplKP); 2670 priv_modes &= ~PrivMode_aplKP;
3081 break; 2671 break;
3082 2672
3083 case C1_40: 2673 case C1_40:
3084 cmd_getc (); 2674 cmd_getc ();
3085 break; 2675 break;
3088 break; 2678 break;
3089 2679
3090 /* 8.3.87: NEXT LINE */ 2680 /* 8.3.87: NEXT LINE */
3091 case C1_NEL: /* ESC E */ 2681 case C1_NEL: /* ESC E */
3092 { 2682 {
3093 unicode_t nlcr[] = { C0_LF, C0_CR }; 2683 wchar_t nlcr[] = { C0_LF, C0_CR };
3094 scr_add_lines (nlcr, 1, 2); 2684 scr_add_lines (nlcr, ecb_array_length (nlcr), 1);
3095 } 2685 }
3096 break; 2686 break;
3097 2687
3098 /* kidnapped escape sequence: Should be 8.3.48 */ 2688 /* kidnapped escape sequence: Should be 8.3.48 */
3099 case C1_ESA: /* ESC G */ 2689 case C1_ESA: /* ESC G */
3100 process_graphics (); 2690 // used by original rxvt for rob nations own graphics mode
2691 if (cmd_getc () == 'Q')
2692 tt_printf ("\033G0\012"); /* query graphics - no graphics */
3101 break; 2693 break;
3102 2694
3103 /* 8.3.63: CHARACTER TABULATION SET */ 2695 /* 8.3.63: CHARACTER TABULATION SET */
3104 case C1_HTS: /* ESC H */ 2696 case C1_HTS: /* ESC H */
3105 scr_set_tab (1); 2697 scr_set_tab (1);
3109 case C1_RI: /* ESC M */ 2701 case C1_RI: /* ESC M */
3110 scr_index (DN); 2702 scr_index (DN);
3111 break; 2703 break;
3112 2704
3113 /* 8.3.142: SINGLE-SHIFT TWO */ 2705 /* 8.3.142: SINGLE-SHIFT TWO */
3114 /*case C1_SS2: scr_single_shift (2); break; */ 2706 /* case C1_SS2: break; */
3115 2707
3116 /* 8.3.143: SINGLE-SHIFT THREE */ 2708 /* 8.3.143: SINGLE-SHIFT THREE */
3117 /*case C1_SS3: scr_single_shift (3); break; */ 2709 /* case C1_SS3: break; */
3118 2710
3119 /* 8.3.27: DEVICE CONTROL STRING */ 2711 /* 8.3.27: DEVICE CONTROL STRING */
3120 case C1_DCS: /* ESC P */ 2712 case C1_DCS: /* ESC P */
3121 process_dcs_seq (); 2713 process_dcs_seq ();
3122 break; 2714 break;
3123 2715
3124 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2716 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3125 case C1_SCI: /* ESC Z */ 2717 case C1_SCI: /* ESC Z */
3126 tt_write ((const unsigned char *)ESCZ_ANSWER, 2718 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3127 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3128 break; /* steal obsolete ESC [ c */ 2719 break; /* steal obsolete ESC [ c */
3129 2720
3130 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2721 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
3131 case C1_CSI: /* ESC [ */ 2722 case C1_CSI: /* ESC [ */
3132 process_csi_seq (); 2723 process_csi_seq ();
3133 break; 2724 break;
3134 2725
3135 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2726 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
3136 case C1_OSC: /* ESC ] */ 2727 case C1_OSC: /* ESC ] */
3137 process_osc_seq (); 2728 process_osc_seq ();
3138 break; 2729 break;
3139 2730
3140 /* 8.3.106: RESET TO INITIAL STATE */ 2731 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
3141 case 'c': 2732 case 'c':
3142 mbstate.reset (); 2733 mbstate.reset ();
3143 scr_poweron (); 2734 scr_poweron ();
3144 scrollbar_show (1); 2735 scrollBar.show (1);
3145 break; 2736 break;
3146 2737
3147 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2738 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3148 case 'n': 2739 case 'n':
3149 scr_charset_choose (2); 2740 scr_charset_choose (2);
3156 } 2747 }
3157} 2748}
3158/*}}} */ 2749/*}}} */
3159 2750
3160/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ 2751/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3161/* *INDENT-OFF* */
3162enum { 2752enum {
3163 CSI_ICH = 0x40, 2753 CSI_ICH = 0x40,
3164 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, 2754 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3165 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , 2755 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3166 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, 2756 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3169 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ, 2759 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3170 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 , 2760 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3171 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F 2761 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3172}; 2762};
3173 2763
3174#define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \ 2764#define make_byte(b0,b1,b2,b3,b4,b5,b6,b7) \
3175 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \ 2765 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3176 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0)) 2766 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3177#define get_byte_array_bit(array, bit) \ 2767#define get_byte_array_bit(array, bit) \
3178 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7)))) 2768 (!! ((array)[(bit) >> 3] & (1 << ((bit) & 7))))
3179 2769
3180const unsigned char csi_defaults[] = 2770static const unsigned char csi_defaults[] =
3181 { 2771 {
3182 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */ 2772 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3183 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */ 2773 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3184 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */ 2774 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3185 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */ 2775 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3186 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ 2776 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3187 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ 2777 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3188 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ 2778 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3189 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ 2779 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3190 }; 2780 };
3191/* *INDENT-ON* */
3192 2781
3193void 2782void
3194rxvt_term::process_csi_seq () 2783rxvt_term::process_csi_seq ()
3195{ 2784{
3196 unicode_t ch, priv, i; 2785 unicode_t ch, priv, i;
3197 unsigned int nargs, p; 2786 unsigned int nargs, p;
3198 int n, ndef; 2787 int n, ndef;
3199 int arg[ESC_ARGS]; 2788 int arg[ESC_ARGS] = { };
3200 2789
3201 for (nargs = ESC_ARGS; nargs > 0;) 2790 nargs = 0;
3202 arg[--nargs] = 0;
3203 2791
3204 priv = 0; 2792 priv = 0;
3205 ch = cmd_getc (); 2793 ch = cmd_getc ();
3206 if (ch >= '<' && ch <= '?') 2794 if ((ch >= '<' && ch <= '?') || ch == '!')
2795 {
3207 { /* '<' '=' '>' '?' */ 2796 /* '<' '=' '>' '?' '!' */
3208 priv = ch; 2797 priv = ch;
3209 ch = cmd_getc (); 2798 ch = cmd_getc ();
3210 } 2799 }
3211 2800
3212 /* read any numerical arguments */ 2801 /* read any numerical arguments */
3241 ndef = get_byte_array_bit (csi_defaults, i); 2830 ndef = get_byte_array_bit (csi_defaults, i);
3242 for (p = 0; p < nargs; p++) 2831 for (p = 0; p < nargs; p++)
3243 if (arg[p] == -1) 2832 if (arg[p] == -1)
3244 arg[p] = ndef; 2833 arg[p] = ndef;
3245 2834
3246#ifdef DEBUG_CMD
3247 fprintf (stderr, "CSI ");
3248 for (p = 0; p < nargs; p++)
3249 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3250 fprintf (stderr, "%c\n", ch);
3251#endif
3252
3253 /* 2835 /*
3254 * private mode handling 2836 * private mode handling
3255 */ 2837 */
3256 if (priv) 2838 if (priv)
3257 { 2839 {
3258 switch (priv) 2840 switch (priv)
3259 { 2841 {
3260 case '>': 2842 case '>':
3261 if (ch == CSI_DA) /* secondary device attributes */ 2843 if (ch == CSI_DA) /* secondary device attributes */
3262 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2844 {
2845 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2846 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2847 //
2848 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2849 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2850 // versions.
2851 //
2852 tt_printf ("\033[>%d;95;0c", 'U');
2853 }
3263 break; 2854 break;
2855
3264 case '?': 2856 case '?':
3265 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2857 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3266 process_terminal_mode (ch, priv, nargs, arg); 2858 process_terminal_mode (ch, priv, nargs, arg);
3267 break; 2859 break;
2860
2861 case '!':
2862 if (ch == CSI_70)
2863 {
2864 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2865 scr_soft_reset ();
2866
2867 static const int pm_h[] = { 7, 25 };
2868 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1015, 1049 };
2869
2870 process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h);
2871 process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l);
3268 } 2872 }
2873 break;
2874 }
2875
3269 return; 2876 return;
3270 } 2877 }
3271 2878
3272 switch (ch) 2879 switch (ch)
3273 { 2880 {
3287 } 2894 }
3288 break; 2895 break;
3289#endif 2896#endif
3290 2897
3291 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */ 2898 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3292 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ 2899 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3293 arg[0] = -arg[0]; 2900 arg[0] = -arg[0];
3294 /* FALLTHROUGH */ 2901 /* FALLTHROUGH */
3295 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */ 2902 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3296 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ 2903 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3297 scr_gotorc (arg[0], 0, RELATIVE); 2904 scr_gotorc (arg[0], 0, RELATIVE);
3298 break; 2905 break;
3299 2906
3300 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */ 2907 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3301 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ 2908 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3376 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2983 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3377 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); 2984 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3378 break; 2985 break;
3379 2986
3380 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 2987 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3381 tt_write ((const unsigned char *)VT100_ANS, 2988 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3382 (unsigned int) (sizeof (VT100_ANS) - 1));
3383 break; 2989 break;
3384 2990
3385 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 2991 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3386 process_sgr_mode (nargs, arg); 2992 process_sgr_mode (nargs, arg);
3387 break; 2993 break;
3394 break; 3000 break;
3395 case 6: /* CPR requested */ 3001 case 6: /* CPR requested */
3396 scr_report_position (); 3002 scr_report_position ();
3397 break; 3003 break;
3398 case 7: /* unofficial extension */ 3004 case 7: /* unofficial extension */
3399 if (options & Opt_insecure) 3005 if (option (Opt_insecure))
3400 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3006 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3401 break; 3007 break;
3402 case 8: /* unofficial extension */ 3008 case 8: /* unofficial extension */
3403 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3009 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3404 break; 3010 break;
3471 break; 3077 break;
3472 case CSI_75: 3078 case CSI_75:
3473 scr_cursor (RESTORE); 3079 scr_cursor (RESTORE);
3474 break; 3080 break;
3475 3081
3476#if ENABLE_FRILLS 3082#if !ENABLE_MINIMAL
3477 case CSI_74: 3083 case CSI_74:
3478 process_window_ops (arg, nargs); 3084 process_window_ops (arg, nargs);
3479 break; 3085 break;
3480#endif 3086#endif
3481 3087
3488 break; 3094 break;
3489 } 3095 }
3490} 3096}
3491/*}}} */ 3097/*}}} */
3492 3098
3493#if ENABLE_FRILLS 3099#if !ENABLE_MINIMAL
3494/* ARGSUSED */
3495void 3100void
3496rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3101rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3497{ 3102{
3498 int x, y; 3103 int x, y;
3499 XWindowAttributes wattr; 3104 XWindowAttributes wattr;
3500 Window wdummy; 3105 Window wdummy;
3501 dDisp; 3106
3107 dLocal (Display *, dpy);
3502 3108
3503 if (nargs == 0) 3109 if (nargs == 0)
3504 return; 3110 return;
3505 3111
3506 switch (args[0]) 3112 switch (args[0])
3507 { 3113 {
3508 /* 3114 /*
3509 * commands 3115 * commands
3510 */ 3116 */
3511 case 1: /* deiconify window */ 3117 case 1: /* deiconify window */
3512 XMapWindow (disp, parent[0]); 3118 XMapWindow (dpy, parent);
3513 break; 3119 break;
3514 case 2: /* iconify window */ 3120 case 2: /* iconify window */
3515 XIconifyWindow (disp, parent[0], display->screen); 3121 XIconifyWindow (dpy, parent, display->screen);
3516 break; 3122 break;
3517 case 3: /* set position (pixels) */ 3123 case 3: /* set position (pixels) */
3518 XMoveWindow (disp, parent[0], args[1], args[2]); 3124 XMoveWindow (dpy, parent, args[1], args[2]);
3519 break; 3125 break;
3520 case 4: /* set size (pixels) */ 3126 case 4: /* set size (pixels) */
3521 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3127 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3522 break; 3128 break;
3523 case 5: /* raise window */ 3129 case 5: /* raise window */
3524 XRaiseWindow (disp, parent[0]); 3130 XRaiseWindow (dpy, parent);
3525 break; 3131 break;
3526 case 6: /* lower window */ 3132 case 6: /* lower window */
3527 XLowerWindow (disp, parent[0]); 3133 XLowerWindow (dpy, parent);
3528 break; 3134 break;
3529 case 7: /* refresh window */ 3135 case 7: /* refresh window */
3530 scr_touch (true); 3136 scr_touch (true);
3531 break; 3137 break;
3532 case 8: /* set size (chars) */ 3138 case 8: /* set size (chars) */
3535 break; 3141 break;
3536 3142
3537 //case 9: NYI, TODO, restore maximized window or maximize window 3143 //case 9: NYI, TODO, restore maximized window or maximize window
3538 default: 3144 default:
3539 if (args[0] >= 24) /* set height (chars) */ 3145 if (args[0] >= 24) /* set height (chars) */
3540 set_widthheight ((unsigned int)width, 3146 set_widthheight ((unsigned int)vt_width,
3541 (unsigned int) (args[1] * fheight)); 3147 (unsigned int) (args[1] * fheight));
3542 break; 3148 break;
3543
3544 3149
3545 /* 3150 /*
3546 * reports - some output format copied from XTerm 3151 * reports - some output format copied from XTerm
3547 */ 3152 */
3548 case 11: /* report window state */ 3153 case 11: /* report window state */
3549 XGetWindowAttributes (disp, parent[0], &wattr); 3154 XGetWindowAttributes (dpy, parent, &wattr);
3550 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3155 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3551 break; 3156 break;
3552 case 13: /* report window position */ 3157 case 13: /* report window position */
3553 XGetWindowAttributes (disp, parent[0], &wattr); 3158 XGetWindowAttributes (dpy, parent, &wattr);
3554 XTranslateCoordinates (disp, parent[0], wattr.root, 3159 XTranslateCoordinates (dpy, parent, wattr.root,
3555 -wattr.border_width, -wattr.border_width, 3160 -wattr.border_width, -wattr.border_width,
3556 &x, &y, &wdummy); 3161 &x, &y, &wdummy);
3557 tt_printf ("\033[3;%d;%dt", x, y); 3162 tt_printf ("\033[3;%d;%dt", x, y);
3558 break; 3163 break;
3559 case 14: /* report window size (pixels) */ 3164 case 14: /* report window size (pixels) */
3560 XGetWindowAttributes (disp, parent[0], &wattr); 3165 XGetWindowAttributes (dpy, parent, &wattr);
3561 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3166 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3562 break; 3167 break;
3563 case 18: /* report text area size (chars) */ 3168 case 18: /* report text area size (chars) */
3564 tt_printf ("\033[8;%d;%dt", nrow, ncol); 3169 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3565 break; 3170 break;
3567 tt_printf ("\033[9;%d;%dt", nrow, ncol); 3172 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3568 break; 3173 break;
3569 case 20: /* report icon label */ 3174 case 20: /* report icon label */
3570 { 3175 {
3571 char *s; 3176 char *s;
3572 XGetIconName (disp, parent[0], &s); 3177 XGetIconName (dpy, parent, &s);
3573 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3178 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3574 XFree (s); 3179 XFree (s);
3575 } 3180 }
3576 break; 3181 break;
3577 case 21: /* report window title */ 3182 case 21: /* report window title */
3578 { 3183 {
3579 char *s; 3184 char *s;
3580 XFetchName (disp, parent[0], &s); 3185 XFetchName (dpy, parent, &s);
3581 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3186 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3582 XFree (s); 3187 XFree (s);
3583 } 3188 }
3584 break; 3189 break;
3585 } 3190 }
3586} 3191}
3589/*----------------------------------------------------------------------*/ 3194/*----------------------------------------------------------------------*/
3590/* 3195/*
3591 * get input up until STRING TERMINATOR (or BEL) 3196 * get input up until STRING TERMINATOR (or BEL)
3592 * ends_how is terminator used. returned input must be free()'d 3197 * ends_how is terminator used. returned input must be free()'d
3593 */ 3198 */
3594unsigned char * 3199char *
3595rxvt_term::get_to_st (unicode_t &ends_how) 3200rxvt_term::get_to_st (unicode_t &ends_how)
3596{ 3201{
3597 unicode_t ch; 3202 unicode_t ch;
3598 bool seen_esc = false; 3203 bool seen_esc = false;
3599 unsigned int n = 0; 3204 unsigned int n = 0;
3613 seen_esc = true; 3218 seen_esc = true;
3614 continue; 3219 continue;
3615 } 3220 }
3616 else if (ch == C0_BEL || ch == CHAR_ST) 3221 else if (ch == C0_BEL || ch == CHAR_ST)
3617 break; 3222 break;
3223 else if (ch == C0_SYN)
3224 ch = cmd_get8 ();
3618 else if (ch < 0x20) 3225 else if (ch < 0x20)
3619 return NULL; /* other control character - exit */ 3226 return NULL; /* other control character - exit */
3620 3227
3621 seen_esc = false; 3228 seen_esc = false;
3622 3229
3623 if (n >= STRING_MAX - 1) 3230 if (n >= STRING_MAX - 1)
3624 // stop at some sane length 3231 // stop at some sane length
3625 return NULL; 3232 return NULL;
3626 3233
3627 if (ch == C0_SYN)
3628 string[n++] = cmd_get8 ();
3629 else
3630 string[n++] = ch; 3234 string[n++] = ch;
3631 } 3235 }
3632 3236
3633 string[n++] = '\0'; 3237 string[n++] = '\0';
3634 3238
3635 ends_how = (ch == 0x5c ? C0_ESC : ch); 3239 ends_how = (ch == 0x5c ? C0_ESC : ch);
3636 3240
3637 return (unsigned char *)rxvt_wcstombs (string); 3241 return rxvt_wcstombs (string);
3638} 3242}
3639 3243
3640/*----------------------------------------------------------------------*/ 3244/*----------------------------------------------------------------------*/
3641/* 3245/*
3642 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3246 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3643 */ 3247 */
3644void 3248void
3645rxvt_term::process_dcs_seq () 3249rxvt_term::process_dcs_seq ()
3646{ 3250{
3647 unsigned char *s;
3648 unicode_t eh;
3649
3650 /* 3251 /*
3651 * Not handled yet 3252 * Not handled yet
3652 */ 3253 */
3254
3255 unicode_t eh;
3653 s = get_to_st (eh); 3256 char *s = get_to_st (eh);
3654 if (s) 3257 if (s)
3655 free (s); 3258 free (s);
3656 3259
3657 return; 3260 return;
3658} 3261}
3662 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 3265 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3663 */ 3266 */
3664void 3267void
3665rxvt_term::process_osc_seq () 3268rxvt_term::process_osc_seq ()
3666{ 3269{
3667 unicode_t ch, eh;
3668 int arg; 3270 int arg;
3669 3271
3670 ch = cmd_getc (); 3272 unicode_t ch = cmd_getc ();
3671 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3273 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3672 arg = arg * 10 + (ch - '0'); 3274 arg = arg * 10 + (ch - '0');
3673 3275
3674 if (ch == ';') 3276 if (ch == ';')
3675 { 3277 {
3278 unicode_t eh;
3676 unsigned char *s = get_to_st (eh); 3279 char *s = get_to_st (eh);
3677 3280
3678 if (s) 3281 if (s)
3679 { 3282 {
3680 process_xterm_seq (arg, (char *)s, eh); 3283 process_xterm_seq (arg, s, eh);
3681 free (s); 3284 free (s);
3682 } 3285 }
3683 } 3286 }
3684} 3287}
3685 3288
3686void 3289void
3687rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3290rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3688{ 3291{
3689 if (str[0] == '?' && !str[1]) 3292 if (str[0] == '?' && !str[1])
3690 { 3293 {
3691 unsigned short r, g, b; 3294 rgba c;
3692 pix_colors_focused[color].get (display, r, g, b); 3295 pix_colors_focused[color].get (c);
3296
3297#if XFT
3298 if (c.a != rgba::MAX_CC)
3299 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3300 else
3301#endif
3693 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3302 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3694 } 3303 }
3695 else 3304 else
3696 set_window_color (color, str); 3305 set_window_color (color, str);
3697} 3306}
3698 3307
3699/* 3308/*
3700 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3309 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3701 */ 3310 */
3702void 3311void
3703rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3312rxvt_term::process_xterm_seq (int op, char *str, char resp)
3704{ 3313{
3705 int changed = 0;
3706 int color; 3314 int color;
3707 char *buf, *name; 3315 char *buf, *name;
3708 bool query = str[0] == '?' && !str[1]; 3316 bool query = str[0] == '?' && !str[1];
3709 int saveop = op; 3317 int saveop = op;
3710 dDisp; 3318
3319 dLocal (Display *, dpy);
3711 3320
3712 assert (str != NULL); 3321 assert (str != NULL);
3322
3323 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3324 return;
3325
3713 switch (op) 3326 switch (op)
3714 { 3327 {
3715 case XTerm_name: 3328 case XTerm_name:
3716 set_title (str); 3329 set_title (str);
3717 /* FALLTHROUGH */ 3330 /* FALLTHROUGH */
3731 unsigned long bytes_after; 3344 unsigned long bytes_after;
3732 unsigned char *value = 0; 3345 unsigned char *value = 0;
3733 const char *str = ""; 3346 const char *str = "";
3734 3347
3735 if (prop 3348 if (prop
3736 && XGetWindowProperty (disp, parent[0], 3349 && XGetWindowProperty (dpy, parent,
3737 prop, 0, 1<<16, 0, AnyPropertyType, 3350 prop, 0, 1<<16, 0, AnyPropertyType,
3738 &actual_type, &actual_format, 3351 &actual_type, &actual_format,
3739 &nitems, &bytes_after, &value) == Success 3352 &nitems, &bytes_after, &value) == Success
3740 && actual_type != None 3353 && actual_type != None
3741 && actual_format == 8) 3354 && actual_format == 8)
3742 str = (const char *)(value); 3355 str = (const char *)(value);
3743 3356
3744 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3357 tt_printf ("\033]%d;%s%c", op, str, resp);
3745 3358
3746 XFree (value); 3359 XFree (value);
3747 } 3360 }
3748 else 3361 else
3749 { 3362 {
3750 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3363 char *eq = strchr (str, '=');
3751 3364
3752 if (eq) 3365 if (eq)
3753 { 3366 {
3754 *eq = 0; 3367 *eq = 0;
3755 set_utf8_property (display->atom (str), eq + 1); 3368 set_utf8_property (display->atom (str), eq + 1);
3756 } 3369 }
3757 else 3370 else
3758 XDeleteProperty (disp, parent[0], 3371 XDeleteProperty (dpy, parent,
3759 display->atom (str)); 3372 display->atom (str));
3760 } 3373 }
3761 break; 3374 break;
3762 3375
3763 case XTerm_Color: 3376 case XTerm_Color:
3765 { 3378 {
3766 if ((name = strchr (buf, ';')) == NULL) 3379 if ((name = strchr (buf, ';')) == NULL)
3767 break; 3380 break;
3768 3381
3769 *name++ = '\0'; 3382 *name++ = '\0';
3770 color = atoi (buf); 3383 color = atoi (buf) + minCOLOR;
3771 3384
3772 if (color < 0 || color >= TOTAL_COLORS) 3385 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3773 break; 3386 break;
3774 3387
3775 if ((buf = strchr (name, ';')) != NULL) 3388 if ((buf = strchr (name, ';')) != NULL)
3776 *buf++ = '\0'; 3389 *buf++ = '\0';
3777 3390
3778 if (name[0] == '?' && !name[1]) 3391 process_color_seq (op, color, name, resp);
3392 }
3393 break;
3394 case Rxvt_restoreFG:
3395 case XTerm_Color00:
3396 process_color_seq (op, Color_fg, str, resp);
3397 break;
3398 case Rxvt_restoreBG:
3399 case XTerm_Color01:
3400 process_color_seq (op, Color_bg, str, resp);
3401 break;
3402#ifndef NO_CURSORCOLOR
3403 case XTerm_Color_cursor:
3404 process_color_seq (op, Color_cursor, str, resp);
3405 break;
3406#endif
3407 case XTerm_Color_pointer_fg:
3408 process_color_seq (op, Color_pointer_fg, str, resp);
3409 break;
3410 case XTerm_Color_pointer_bg:
3411 process_color_seq (op, Color_pointer_bg, str, resp);
3412 break;
3413#ifdef OPTION_HC
3414 case XTerm_Color_HC:
3415 process_color_seq (op, Color_HC, str, resp);
3416 break;
3417 case XTerm_Color_HTC:
3418 process_color_seq (op, Color_HTC, str, resp);
3419 break;
3420#endif
3421#ifndef NO_BOLD_UNDERLINE_REVERSE
3422 case URxvt_Color_BD:
3423 process_color_seq (op, Color_BD, str, resp);
3424 break;
3425 case URxvt_Color_UL:
3426 process_color_seq (op, Color_UL, str, resp);
3427 break;
3428 case URxvt_Color_IT:
3429 process_color_seq (op, Color_IT, str, resp);
3430 break;
3431#endif
3432 case URxvt_Color_border:
3433 process_color_seq (op, Color_border, str, resp);
3434 break;
3435#if ENABLE_TRANSPARENCY
3436 case URxvt_Color_tint:
3437 process_color_seq (op, Color_tint, str, resp);
3438 {
3439 bool changed = false;
3440
3441 if (ISSET_PIXCOLOR (Color_tint))
3442 changed = bg_set_tint (pix_colors_focused [Color_tint]);
3443
3444 if (changed)
3445 update_background ();
3446 }
3447
3448 break;
3449#endif
3450
3451#if BG_IMAGE_FROM_FILE
3452 case Rxvt_Pixmap:
3453 if (!strcmp (str, "?"))
3454 {
3455 char str[256];
3456
3457 sprintf (str, "[%dx%d+%d+%d]",
3458 min (h_scale, 32767), min (v_scale, 32767),
3459 min (h_align, 32767), min (v_align, 32767));
3460 process_xterm_seq (XTerm_title, str, CHAR_ST);
3461 }
3462 else
3463 {
3464 bool changed = false;
3465
3466 if (*str != ';')
3779 { 3467 {
3780 unsigned short r, g, b; 3468 if (bg_set_file (str)) /* change pixmap */
3781 pix_colors_focused[color + minCOLOR].get (display, r, g, b); 3469 changed = true;
3782 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3783 } 3470 }
3784 else 3471 else
3785 set_window_color (color + minCOLOR, name); 3472 {
3473 str++;
3474 if (bg_set_geometry (str, true))
3475 changed = true;
3476 }
3477
3478 if (changed)
3479 {
3480 if (bg_window_position_sensitive ())
3481 {
3482 int x, y;
3483 get_window_origin (x, y);
3484 bg_set_position (x, y);
3485 }
3486 update_background ();
3487 }
3786 } 3488 }
3787 break; 3489 break;
3788 case XTerm_Color00:
3789 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3790 break;
3791 case XTerm_Color01:
3792 process_color_seq (XTerm_Color00, Color_bg, str, resp);
3793 break;
3794#ifndef NO_CURSORCOLOR
3795 case XTerm_Color_cursor:
3796 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3797 break;
3798#endif 3490#endif
3799 case XTerm_Color_pointer_fg:
3800 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp);
3801 break;
3802 case XTerm_Color_pointer_bg:
3803 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3804 break;
3805#ifndef NO_BOLD_UNDERLINE_REVERSE
3806 case XTerm_Color_BD:
3807 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3808 break;
3809 case XTerm_Color_UL:
3810 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3811 break;
3812 case XTerm_Color_RV:
3813 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3814 break;
3815 case URxvt_Color_IT:
3816 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3817 break;
3818#endif
3819#if TRANSPARENT && TINTING
3820 case URxvt_Color_tint:
3821 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3822 check_our_parents ();
3823 if (am_transparent)
3824 want_full_refresh = want_refresh = 1;
3825 break;
3826#endif
3827
3828 case XTerm_Pixmap:
3829 if (*str != ';')
3830 {
3831#if XPM_BACKGROUND
3832 scale_pixmap (""); /* reset to default scaling */
3833 set_bgPixmap (str); /* change pixmap */
3834#endif
3835 scr_touch (true);
3836 }
3837 while ((str = strchr (str, ';')) != NULL)
3838 {
3839 str++;
3840#if XPM_BACKGROUND
3841 changed += scale_pixmap (str);
3842#endif
3843 }
3844
3845 if (changed)
3846 {
3847#ifdef XPM_BACKGROUND
3848 resize_pixmap ();
3849#endif
3850 scr_touch (true);
3851 }
3852 break;
3853
3854 case XTerm_restoreFG:
3855 set_window_color (Color_fg, str);
3856 break;
3857 case XTerm_restoreBG:
3858 set_window_color (Color_bg, str);
3859 break;
3860 3491
3861 case XTerm_logfile: 3492 case XTerm_logfile:
3862 // TODO, when secure mode? 3493 // TODO, when secure mode?
3863 break; 3494 break;
3864 3495
3865#ifdef MENUBAR
3866 case URxvt_Menu:
3867 if (options & Opt_insecure)
3868 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3869 break;
3870#endif
3871#if 0 3496#if 0
3872 case XTerm_dumpscreen: /* no error notices */ 3497 case Rxvt_dumpscreen: /* no error notices */
3873 { 3498 {
3874 int fd; 3499 int fd;
3875 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3500 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3876 { 3501 {
3877 scr_dump (fd); 3502 scr_dump (fd);
3888 case URxvt_italicFont: 3513 case URxvt_italicFont:
3889 case URxvt_boldItalicFont: 3514 case URxvt_boldItalicFont:
3890#endif 3515#endif
3891 if (query) 3516 if (query)
3892 tt_printf ("\33]%d;%-.250s%c", saveop, 3517 tt_printf ("\33]%d;%-.250s%c", saveop,
3893 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3518 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3894 ? fontset[op - URxvt_font]->fontdesc : "", 3519 ? fontset[op - URxvt_font]->fontdesc : "",
3895 resp); 3520 resp);
3896 else 3521 else
3897 { 3522 {
3898 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3523 const char *&res = rs[Rs_font + (op - URxvt_font)];
3901 allocated.push_back ((void *)res); 3526 allocated.push_back ((void *)res);
3902 set_fonts (); 3527 set_fonts ();
3903 } 3528 }
3904 break; 3529 break;
3905 3530
3906#if ENABLE_FRILLS 3531 case URxvt_version:
3532 if (query)
3533 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3534 op,
3535 rs[Rs_name], VERSION[0], VERSION[2],
3536 resp);
3537 break;
3538
3539#if !ENABLE_MINIMAL
3907 case URxvt_locale: 3540 case URxvt_locale:
3908 if (query) 3541 if (query)
3909 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp); 3542 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3910 else 3543 else
3911 { 3544 {
3912 set_locale (str); 3545 set_locale (str);
3913 pty.set_utf8_mode (enc_utf8); 3546 pty->set_utf8_mode (enc_utf8);
3914 init_xlocale (); 3547 init_xlocale ();
3915 } 3548 }
3916 break; 3549 break;
3917 3550
3918 case URxvt_view_up: 3551 case URxvt_view_up:
3919 case URxvt_view_down: 3552 case URxvt_view_down:
3553 {
3920 int lines = atoi (str); 3554 int lines = atoi (str);
3921 3555
3922 if (lines) 3556 if (lines)
3923 scr_page (op == URxvt_view_up ? UP : DN, lines); 3557 scr_page (op == URxvt_view_up ? UP : DN, lines);
3924 else 3558 else
3925 {
3926 scr_erase_savelines (); 3559 scr_erase_savelines ();
3927 } 3560 }
3928 3561
3562 break;
3563#endif
3564
3565#if ENABLE_PERL
3566 case URxvt_perl:
3567 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3929 break; 3568 break;
3930#endif 3569#endif
3931 } 3570 }
3932} 3571}
3933/*----------------------------------------------------------------------*/ 3572/*----------------------------------------------------------------------*/
3947{ 3586{
3948 int state; 3587 int state;
3949 3588
3950 if (mode == 's') 3589 if (mode == 's')
3951 { 3590 {
3952 SavedModes |= (priv_modes & bit); 3591 if (priv_modes & bit)
3592 SavedModes |= bit;
3593 else
3594 SavedModes &= ~bit;
3953 return -1; 3595 return -1;
3954 } 3596 }
3955 else 3597 else
3956 { 3598 {
3957 if (mode == 'r') 3599 if (mode == 'r')
3958 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3600 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3959 else 3601 else
3960 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3602 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3961 PrivMode (state, bit); 3603
3604 if (state)
3605 priv_modes |= bit;
3606 else
3607 priv_modes &= ~bit;
3962 } 3608 }
3963 3609
3964 return state; 3610 return state;
3965} 3611}
3966 3612
3967/* we're not using priv _yet_ */ 3613/* we're not using priv _yet_ */
3968void 3614void
3969rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3615rxvt_term::process_terminal_mode (int mode, int priv ecb_unused, unsigned int nargs, const int *arg)
3970{ 3616{
3971 unsigned int i, j; 3617 unsigned int i, j;
3972 int state; 3618 int state;
3973 3619
3974 static const struct 3620 static const struct
3975 { 3621 {
3976 const int argval; 3622 const int argval;
3977 const unsigned long bit; 3623 const unsigned long bit;
3978 }
3979
3980 argtopriv[] = { 3624 } argtopriv[] = {
3981 { 1, PrivMode_aplCUR }, 3625 { 1, PrivMode_aplCUR }, // DECCKM
3982 { 2, PrivMode_vt52 }, 3626 { 2, PrivMode_vt52 }, // DECANM
3983 { 3, PrivMode_132 }, 3627 { 3, PrivMode_132 }, // DECCOLM
3984 { 4, PrivMode_smoothScroll }, 3628 { 4, PrivMode_smoothScroll }, // DECSCLM
3985 { 5, PrivMode_rVideo }, 3629 { 5, PrivMode_rVideo }, // DECSCNM
3986 { 6, PrivMode_relOrigin }, 3630 { 6, PrivMode_relOrigin }, // DECOM
3987 { 7, PrivMode_Autowrap }, 3631 { 7, PrivMode_Autowrap }, // DECAWM
3988 // 8, bi-directional support mode 3632 // 8, auto-repeat keys // DECARM
3989 { 9, PrivMode_MouseX10 }, 3633 { 9, PrivMode_MouseX10 },
3990#ifdef menuBar_esc 3634 // 18 end FF to printer after print screen
3991 { menuBar_esc, PrivMode_menuBar }, 3635 // 19 Print screen prints full screen/scroll region
3992#endif
3993 // 18, 19 printing-related
3994 { 25, PrivMode_VisibleCursor }, 3636 { 25, PrivMode_VisibleCursor }, // DECTCEM cnorm/cvvis/civis
3995#ifdef scrollBar_esc 3637#ifdef scrollBar_esc
3996 { scrollBar_esc, PrivMode_scrollBar }, 3638 { scrollBar_esc, PrivMode_scrollBar },
3997#endif 3639#endif
3998 { 35, PrivMode_ShiftKeys }, // rxvt extension 3640 { 35, PrivMode_ShiftKeys }, // rxvt extension
3641 // 38, tektronix mode // DECTEK
3999 { 40, PrivMode_132OK }, 3642 { 40, PrivMode_132OK },
4000 // 41 xterm more fixes NYI 3643 // 41 xterm more fixes NYI
4001 // 45 margin bell NYI 3644 // 45 margin bell NYI
4002 // 46 start logging 3645 // 46 start logging
4003 { 47, PrivMode_Screen }, 3646 { 47, PrivMode_Screen },
4004 { 66, PrivMode_aplKP }, 3647 { 66, PrivMode_aplKP }, // DECNKM
4005#ifndef NO_BACKSPACE_KEY 3648#ifndef NO_BACKSPACE_KEY
4006 { 67, PrivMode_BackSpace }, 3649 { 67, PrivMode_BackSpace }, // DECBKM
4007#endif 3650#endif
4008 { 1000, PrivMode_MouseX11 }, 3651 { 1000, PrivMode_MouseX11 },
4009 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3652 { 1002, PrivMode_MouseBtnEvent },
4010 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3653 { 1003, PrivMode_MouseAnyEvent },
4011 // 1003 Use All Motion Mouse Tracking. NYI, TODO 3654#if ENABLE_FRILLS
3655 { 1005, PrivMode_ExtModeMouse },
3656#endif
4012 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3657 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4013 { 1011, PrivMode_Keypress }, // rxvt extension 3658 { 1011, PrivMode_Keypress }, // rxvt extension
3659#if ENABLE_FRILLS
3660 { 1015, PrivMode_ExtMouseRight }, // urxvt extension of 1005
3661#endif
4014 // 1035 enable modifiers for alt, numlock NYI 3662 // 1035 enable modifiers for alt, numlock NYI
4015 // 1036 send ESC for meta keys NYI 3663 // 1036 send ESC for meta keys NYI
4016 // 1037 send DEL for keypad delete NYI 3664 // 1037 send DEL for keypad delete NYI
4017 { 1047, PrivMode_Screen }, 3665 { 1047, PrivMode_Screen },
4018 // 1048 save and restore cursor 3666 // 1048 save and restore cursor, implemented in code
4019 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3667 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4020 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3668 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3669 { 2004, PrivMode_BracketPaste },
4021 }; 3670 };
4022 3671
4023 if (nargs == 0) 3672 if (nargs == 0)
4024 return; 3673 return;
4025 3674
4032 for (i = 0; i < nargs; i++) 3681 for (i = 0; i < nargs; i++)
4033 { 3682 {
4034 state = -1; 3683 state = -1;
4035 3684
4036 /* basic handling */ 3685 /* basic handling */
4037 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++) 3686 for (j = 0; j < ecb_array_length (argtopriv); j++)
4038 if (argtopriv[j].argval == arg[i]) 3687 if (argtopriv[j].argval == arg[i])
4039 { 3688 {
4040 state = privcases (mode, argtopriv[j].bit); 3689 state = privcases (mode, argtopriv[j].bit);
4041 break; 3690 break;
4042 } 3691 }
4043 3692
4044 /* extra handling for values with state unkept */ 3693 /* extra handling for values with state unkept */
4045 switch (arg[i]) 3694 switch (arg[i])
4046 { 3695 {
3696#if ENABLE_STYLES
3697 case 1021:
3698 set_option (Opt_intensityStyles, mode);
3699
3700 scr_touch (true);
3701 break;
3702#endif
4047 case 1048: /* alternative cursor save */ 3703 case 1048: /* alternative cursor save */
4048 case 1049:
4049 if (options & Opt_secondaryScreen) 3704 if (option (Opt_secondaryScreen))
4050 if (mode == 0) 3705 if (mode == 0)
4051 scr_cursor (RESTORE); 3706 scr_cursor (RESTORE);
4052 else if (mode == 1) 3707 else if (mode == 1)
4053 scr_cursor (SAVE); 3708 scr_cursor (SAVE);
4054 break; 3709 break;
4062 case 2: /* VT52 mode */ 3717 case 2: /* VT52 mode */
4063 /* oddball mode. should be set regardless of set/reset 3718 /* oddball mode. should be set regardless of set/reset
4064 * parameter. Return from VT52 mode with an ESC < from 3719 * parameter. Return from VT52 mode with an ESC < from
4065 * within VT52 mode 3720 * within VT52 mode
4066 */ 3721 */
4067 PrivMode (1, PrivMode_vt52); 3722 priv_modes |= PrivMode_vt52;
4068 break; 3723 break;
4069 case 3: /* 80/132 */ 3724 case 3: /* 80/132 */
4070 if (priv_modes & PrivMode_132OK) 3725 if (priv_modes & PrivMode_132OK)
4071 set_widthheight (((state ? 132 : 80) * fwidth), height); 3726 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
4072 break; 3727 break;
4073 case 4: /* smooth scrolling */ 3728 case 4: /* smooth scrolling */
4074 if (state)
4075 options &= ~Opt_jumpScroll;
4076 else
4077 options |= Opt_jumpScroll; 3729 set_option (Opt_jumpScroll, !state);
4078 break; 3730 break;
4079 case 5: /* reverse video */ 3731 case 5: /* reverse video */
4080 scr_rvideo_mode (state); 3732 scr_rvideo_mode (state);
4081 break; 3733 break;
4082 case 6: /* relative/absolute origins */ 3734 case 6: /* relative/absolute origins */
4086 scr_autowrap (state); 3738 scr_autowrap (state);
4087 break; 3739 break;
4088 /* case 8: - auto repeat, can't do on a per window basis */ 3740 /* case 8: - auto repeat, can't do on a per window basis */
4089 case 9: /* X10 mouse reporting */ 3741 case 9: /* X10 mouse reporting */
4090 if (state) /* orthogonal */ 3742 if (state) /* orthogonal */
4091 priv_modes &= ~PrivMode_MouseX11; 3743 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4092 break; 3744 break;
4093#ifdef menuBar_esc
4094 case menuBar_esc:
4095#ifdef MENUBAR
4096 map_menuBar (state);
4097#endif
4098 break;
4099#endif
4100#ifdef scrollBar_esc 3745#ifdef scrollBar_esc
4101 case scrollBar_esc: 3746 case scrollBar_esc:
4102 if (scrollbar_mapping (state)) 3747 scrollBar.map (state);
4103 {
4104 resize_all_windows (0, 0, 0); 3748 resize_all_windows (0, 0, 0);
4105 scr_touch (true); 3749 scr_touch (true);
4106 }
4107 break; 3750 break;
4108#endif 3751#endif
4109 case 25: /* visible/invisible cursor */ 3752 case 25: /* visible/invisible cursor */
4110 scr_cursor_visible (state); 3753 scr_cursor_visible (state);
4111 break; 3754 break;
4116 break; 3759 break;
4117 /* case 66: - application key pad */ 3760 /* case 66: - application key pad */
4118 /* case 67: - backspace key */ 3761 /* case 67: - backspace key */
4119 case 1000: /* X11 mouse reporting */ 3762 case 1000: /* X11 mouse reporting */
4120 if (state) /* orthogonal */ 3763 if (state) /* orthogonal */
4121 priv_modes &= ~PrivMode_MouseX10; 3764 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4122 break; 3765 break;
4123#if 0
4124 case 1001: 3766 case 1002:
4125 break; /* X11 mouse highlighting */ 3767 case 1003:
4126#endif 3768 if (state)
3769 {
3770 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3771 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3772 mouse_row = mouse_col = 0;
3773 vt_emask_mouse = PointerMotionMask;
3774 }
3775 else
3776 vt_emask_mouse = NoEventMask;
3777
3778 vt_select_input ();
3779 break;
4127 case 1010: /* scroll to bottom on TTY output inhibit */ 3780 case 1010: /* scroll to bottom on TTY output inhibit */
4128 if (state)
4129 options &= ~Opt_scrollTtyOutput;
4130 else
4131 options |= Opt_scrollTtyOutput; 3781 set_option (Opt_scrollTtyOutput, !state);
4132 break; 3782 break;
4133 case 1011: /* scroll to bottom on key press */ 3783 case 1011: /* scroll to bottom on key press */
4134 if (state)
4135 options |= Opt_scrollTtyKeypress; 3784 set_option (Opt_scrollTtyKeypress, state);
4136 else
4137 options &= ~Opt_scrollTtyKeypress;
4138 break; 3785 break;
4139 case 1047: /* secondary screen w/ clearing last */ 3786 case 1047: /* secondary screen w/ clearing last */
4140 if (options & Opt_secondaryScreen) 3787 if (option (Opt_secondaryScreen))
4141 if (current_screen != PRIMARY) 3788 if (!state)
4142 scr_erase_screen (2); 3789 scr_erase_screen (2);
3790
4143 scr_change_screen (state); 3791 scr_change_screen (state);
4144 break; 3792 break;
4145 case 1049: /* secondary screen w/ clearing first */ 3793 case 1049: /* secondary screen w/ clearing first */
3794 if (option (Opt_secondaryScreen))
3795 if (state)
3796 scr_cursor (SAVE);
3797
4146 scr_change_screen (state); 3798 scr_change_screen (state);
3799
4147 if (options & Opt_secondaryScreen) 3800 if (option (Opt_secondaryScreen))
4148 if (current_screen != PRIMARY) 3801 if (state)
4149 scr_erase_screen (2); 3802 scr_erase_screen (2);
3803 else
3804 scr_cursor (RESTORE);
4150 break; 3805 break;
4151 default: 3806 default:
4152 break; 3807 break;
4153 } 3808 }
4154 } 3809 }
4280 scr_color (Color_bg, Color_bg); 3935 scr_color (Color_bg, Color_bg);
4281 break; 3936 break;
4282 3937
4283 //case 50: // not variable spacing 3938 //case 50: // not variable spacing
4284 3939
4285#ifndef NO_BRIGHTCOLOR 3940#if !ENABLE_MINIMAL
4286 case 90: 3941 case 90:
4287 case 91: /* set bright fg color */ 3942 case 91: /* set bright fg color */
4288 case 92: 3943 case 92:
4289 case 93: 3944 case 93:
4290 case 94: 3945 case 94:
4302 case 106: 3957 case 106:
4303 case 107: 3958 case 107:
4304 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 3959 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4305 break; 3960 break;
4306#endif 3961#endif
4307
4308 } 3962 }
4309 } 3963 }
4310}
4311/*}}} */
4312
4313/*{{{ (do not) process Rob Nation's own graphics mode sequences */
4314void
4315rxvt_term::process_graphics ()
4316{
4317 unicode_t ch, cmd = cmd_getc ();
4318
4319 if (cmd == 'Q')
4320 { /* query graphics */
4321 tt_printf ("\033G0\012"); /* no graphics */
4322 return;
4323 }
4324 /* swallow other graphics sequences until terminating ':' */
4325 do
4326 ch = cmd_getc ();
4327 while (ch != ':');
4328} 3964}
4329/*}}} */ 3965/*}}} */
4330 3966
4331/* ------------------------------------------------------------------------- */ 3967/* ------------------------------------------------------------------------- */
4332 3968
4336 */ 3972 */
4337void 3973void
4338rxvt_term::tt_printf (const char *fmt,...) 3974rxvt_term::tt_printf (const char *fmt,...)
4339{ 3975{
4340 va_list arg_ptr; 3976 va_list arg_ptr;
4341 unsigned char buf[256]; 3977 char buf[256];
4342 3978
4343 va_start (arg_ptr, fmt); 3979 va_start (arg_ptr, fmt);
4344 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 3980 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4345 va_end (arg_ptr); 3981 va_end (arg_ptr);
4346 tt_write (buf, strlen (buf)); 3982 tt_write (buf, strlen (buf));
4348 3984
4349/* ---------------------------------------------------------------------- */ 3985/* ---------------------------------------------------------------------- */
4350/* Write data to the pty as typed by the user, pasted with the mouse, 3986/* Write data to the pty as typed by the user, pasted with the mouse,
4351 * or generated by us in response to a query ESC sequence. 3987 * or generated by us in response to a query ESC sequence.
4352 */ 3988 */
4353const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 3989static const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4354 3990
4355void 3991void
4356rxvt_term::tt_write (const unsigned char *data, unsigned int len) 3992rxvt_term::tt_write (const char *data, unsigned int len)
4357{ 3993{
3994 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
3995 return;
3996
3997 if (pty->pty < 0)
3998 return;
3999
4358 if (v_buflen == 0) 4000 if (v_buflen == 0)
4359 { 4001 {
4360 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 4002 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4361 4003
4004 max_it (written, 0);
4005
4362 if ((unsigned int)written == len) 4006 if (written == len)
4363 return; 4007 return;
4364 4008
4365 data += written; 4009 data += written;
4366 len -= written; 4010 len -= written;
4367 } 4011 }
4368 4012
4369 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4013 v_buffer = (char *)rxvt_realloc (v_buffer, v_buflen + len);
4370 4014
4371 memcpy (v_buffer + v_buflen, data, len); 4015 memcpy (v_buffer + v_buflen, data, len);
4372 v_buflen += len; 4016 v_buflen += len;
4373 4017
4374 pty_ev.set (EVENT_READ | EVENT_WRITE); 4018 pty_ev.set (ev::READ | ev::WRITE);
4375} 4019}
4376 4020
4377void rxvt_term::pty_write () 4021void rxvt_term::pty_write ()
4378{ 4022{
4379 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4023 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4380 4024
4381 if (written > 0) 4025 if (written > 0)
4382 { 4026 {
4383 v_buflen -= written; 4027 v_buflen -= written;
4384 4028
4385 if (v_buflen == 0) 4029 if (v_buflen == 0)
4386 { 4030 {
4387 free (v_buffer); 4031 free (v_buffer);
4388 v_buffer = 0; 4032 v_buffer = 0;
4389 v_buflen = 0;
4390 4033
4391 pty_ev.set (EVENT_READ); 4034 pty_ev.set (ev::READ);
4392 return; 4035 return;
4393 } 4036 }
4394 4037
4395 memmove (v_buffer, v_buffer + written, v_buflen); 4038 memmove (v_buffer, v_buffer + written, v_buflen);
4396 } 4039 }
4397 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4040 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4398 pty_ev.set (EVENT_READ); 4041 pty_ev.set (ev::READ);
4399} 4042}
4400 4043
4401/*----------------------- end-of-file (C source) -----------------------*/ 4044/*----------------------- end-of-file (C source) -----------------------*/
4402 4045

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines