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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines