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.28 by pcg, Fri Jan 16 22:11:09 2004 UTC vs.
Revision 1.213 by root, Thu Dec 22 16:44:10 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines