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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines