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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines