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.168 by root, Sun Sep 5 09:32:59 2004 UTC vs.
Revision 1.202 by root, Sat Mar 12 23:35:14 2005 UTC

25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-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
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58 62
113 XK_Escape, 0x238b, 117 XK_Escape, 0x238b,
114 XK_Undo, 0x238c, 118 XK_Undo, 0x238c,
115 XK_Print, 0x2399, 119 XK_Print, 0x2399,
116 120
117 XK_space, 0x2423, 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,
118 XK_KP_Space, 0x2422, 129 XK_KP_Space, 0x2422,
130#endif
119 0, 131 0,
120}; 132};
121 133
122void 134void
123rxvt_term::iso14755_54 (int x, int y) 135rxvt_term::iso14755_54 (int x, int y)
272 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 284 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
273 * escape sequence to toggle the Keypad. 285 * escape sequence to toggle the Keypad.
274 * 286 *
275 * Always permit `shift' to override the current setting 287 * Always permit `shift' to override the current setting
276 */ 288 */
277 shft = (ev.state & ShiftMask); 289 shft = ev.state & ShiftMask;
278 ctrl = (ev.state & ControlMask); 290 ctrl = ev.state & ControlMask;
279 meta = (ev.state & ModMetaMask); 291 meta = ev.state & ModMetaMask;
280 292
281 if (numlock_state || (ev.state & ModNumLockMask)) 293 if (numlock_state || (ev.state & ModNumLockMask))
282 { 294 {
283 numlock_state = (ev.state & ModNumLockMask); 295 numlock_state = (ev.state & ModNumLockMask);
284 PrivMode ((!numlock_state), PrivMode_aplKP); 296 PrivMode ((!numlock_state), PrivMode_aplKP);
304 316
305 // the XOpenIM manpage lies about hardcoding the locale 317 // the XOpenIM manpage lies about hardcoding the locale
306 // at the point of XOpenIM, so temporarily switch locales 318 // at the point of XOpenIM, so temporarily switch locales
307 if (rs[Rs_imLocale]) 319 if (rs[Rs_imLocale])
308 SET_LOCALE (rs[Rs_imLocale]); 320 SET_LOCALE (rs[Rs_imLocale]);
321
309 // assume wchar_t == unicode or better 322 // assume wchar_t == unicode or better
310 len = XwcLookupString (Input_Context, &ev, wkbuf, 323 len = XwcLookupString (Input_Context, &ev, wkbuf,
311 KBUFSZ, &keysym, &status_return); 324 KBUFSZ, &keysym, &status_return);
325
312 if (rs[Rs_imLocale]) 326 if (rs[Rs_imLocale])
313 SET_LOCALE (locale); 327 SET_LOCALE (locale);
314 328
315 if (status_return == XLookupChars 329 if (status_return == XLookupChars
316 || status_return == XLookupBoth) 330 || status_return == XLookupBoth)
343 valid_keysym = keysym != NoSymbol; 357 valid_keysym = keysym != NoSymbol;
344 } 358 }
345 359
346 if (valid_keysym) 360 if (valid_keysym)
347 { 361 {
362#ifdef KEYSYM_RESOURCE
363 if (keyboard->dispatch (this, keysym, ev.state))
364 return;
365#endif
366
348 if (TermWin.saveLines) 367 if (TermWin.saveLines)
349 { 368 {
350#ifdef UNSHIFTED_SCROLLKEYS 369#ifdef UNSHIFTED_SCROLLKEYS
351 if (!ctrl && !meta) 370 if (!ctrl && !meta)
352#else 371#else
417 { 436 {
418 /* normal XTerm key bindings */ 437 /* normal XTerm key bindings */
419 case XK_Insert: /* Shift+Insert = paste mouse selection */ 438 case XK_Insert: /* Shift+Insert = paste mouse selection */
420 selection_request (ev.time, 0, 0); 439 selection_request (ev.time, 0, 0);
421 return; 440 return;
422#if TODO // TODO 441#if TODO
423 /* rxvt extras */ 442 /* rxvt extras */
424 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 443 case XK_KP_Add: /* Shift+KP_Add = bigger font */
425 change_font (FONT_UP); 444 change_font (FONT_UP);
426 return; 445 return;
427 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 446 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
486 } 505 }
487#endif 506#endif
488 507
489 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 508 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
490 { 509 {
491#ifdef KEYSYM_RESOURCE
492 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
493 {
494 unsigned int l;
495 const unsigned char *kbuf0;
496
497 kbuf0 = (Keysym_map[keysym & 0xFF]);
498 l = (unsigned int)*kbuf0++;
499
500 /* escape prefix */
501 if (meta
502# ifdef META8_OPTION
503 && meta_char == C0_ESC
504# endif
505 )
506 {
507 const unsigned char ch = C0_ESC;
508 tt_write (&ch, 1);
509 }
510
511 tt_write (kbuf0, l);
512 return;
513 }
514 else
515#endif
516 { 510 {
517 newlen = 1; 511 newlen = 1;
518 switch (keysym) 512 switch (keysym)
519 { 513 {
520#ifndef NO_BACKSPACE_KEY 514#ifndef NO_BACKSPACE_KEY
528 else 522 else
529 strcpy (kbuf, key_backspace); 523 strcpy (kbuf, key_backspace);
530 break; 524 break;
531#endif 525#endif
532#ifndef NO_DELETE_KEY 526#ifndef NO_DELETE_KEY
527# ifdef XK_KP_Prior
528 case XK_KP_Delete:
529 /* allow shift to override */
530 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
531 {
532 strcpy (kbuf, "\033On");
533 break;
534 }
535 /* FALLTHROUGH */
536# endif
533 case XK_Delete: 537 case XK_Delete:
534 strcpy (kbuf, key_delete); 538 strcpy (kbuf, key_delete);
535 break; 539 break;
536#endif 540#endif
537 case XK_Tab: 541 case XK_Tab:
640#ifdef XK_KP_Begin 644#ifdef XK_KP_Begin
641 case XK_KP_Begin: 645 case XK_KP_Begin:
642 strcpy (kbuf, "\033Ou"); 646 strcpy (kbuf, "\033Ou");
643 break; 647 break;
644 648
645 case XK_KP_Insert:
646 strcpy (kbuf, "\033Op");
647 break;
648
649 case XK_KP_Delete:
650 strcpy (kbuf, "\033On");
651 break;
652#endif 649#endif
653 case XK_KP_F1: /* "\033OP" */ 650 case XK_KP_F1: /* "\033OP" */
654 case XK_KP_F2: /* "\033OQ" */ 651 case XK_KP_F2: /* "\033OQ" */
655 case XK_KP_F3: /* "\033OR" */ 652 case XK_KP_F3: /* "\033OR" */
656 case XK_KP_F4: /* "\033OS" */ 653 case XK_KP_F4: /* "\033OS" */
688 break; 685 break;
689 686
690 case XK_Find: 687 case XK_Find:
691 strcpy (kbuf, "\033[1~"); 688 strcpy (kbuf, "\033[1~");
692 break; 689 break;
690
691#ifdef XK_KP_End
692 case XK_KP_Insert:
693 /* allow shift to override */
694 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
695 {
696 strcpy (kbuf, "\033Op");
697 break;
698 }
699 /* FALLTHROUGH */
700#endif
693 case XK_Insert: 701 case XK_Insert:
694 strcpy (kbuf, "\033[2~"); 702 strcpy (kbuf, "\033[2~");
695 break; 703 break;
696#ifdef DXK_Remove /* support for DEC remove like key */ 704#ifdef DXK_Remove /* support for DEC remove like key */
697 case DXK_Remove: 705 case DXK_Remove:
787#undef FKEY 795#undef FKEY
788 default: 796 default:
789 newlen = 0; 797 newlen = 0;
790 break; 798 break;
791 } 799 }
800
792 if (newlen) 801 if (newlen)
793 len = strlen (kbuf); 802 len = strlen (kbuf);
794 } 803 }
795 804
796 /* 805 /*
804 } 813 }
805 else if (ctrl && keysym == XK_minus) 814 else if (ctrl && keysym == XK_minus)
806 { 815 {
807 len = 1; 816 len = 1;
808 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 817 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
818 }
819 else if (keysym == XK_ISO_Left_Tab)
820 {
821 strcpy (kbuf, "\033[Z");
822 len = 3;
809 } 823 }
810 else 824 else
811 { 825 {
812#ifdef META8_OPTION 826#ifdef META8_OPTION
813 /* set 8-bit on */ 827 /* set 8-bit on */
872#endif /* DEBUG_CMD */ 886#endif /* DEBUG_CMD */
873 tt_write (kbuf, (unsigned int)len); 887 tt_write (kbuf, (unsigned int)len);
874} 888}
875/*}}} */ 889/*}}} */
876 890
877#if (MENUBAR_MAX) 891#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
878/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 892/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
879/* attempt to `write' count to the input buffer */ 893/* attempt to `write' count to the input buffer */
880unsigned int 894unsigned int
881rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 895rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
882{ 896{
905 919
906 cmd_parse (); 920 cmd_parse ();
907 921
908 return 0; 922 return 0;
909} 923}
910#endif /* MENUBAR_MAX */ 924#endif
911 925
912void 926void
913rxvt_term::flush () 927rxvt_term::flush ()
914{ 928{
915 flush_ev.stop (); 929 flush_ev.stop ();
1016{ 1030{
1017 if (mouse_slip_wheel_speed == 0 1031 if (mouse_slip_wheel_speed == 0
1018 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1032 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1019 : scr_page (UP, mouse_slip_wheel_speed)) 1033 : scr_page (UP, mouse_slip_wheel_speed))
1020 { 1034 {
1035 if (TermWin.view_start == TermWin.nscrolled ||
1036 TermWin.view_start == 0)
1037 mouse_slip_wheel_speed = 0;
1038
1021 refresh_type |= SMOOTH_REFRESH; 1039 refresh_type |= SMOOTH_REFRESH;
1022 want_refresh = 1; 1040 want_refresh = 1;
1023 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1041 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1024 } 1042 }
1025} 1043}
1057rxvt_term::pty_cb (io_watcher &w, short revents) 1075rxvt_term::pty_cb (io_watcher &w, short revents)
1058{ 1076{
1059 SET_R (this); 1077 SET_R (this);
1060 SET_LOCALE (locale); 1078 SET_LOCALE (locale);
1061 1079
1062 if (revents & EVENT_WRITE)
1063 tt_write (0, 0);
1064 else if (revents & EVENT_READ) 1080 if (revents & EVENT_READ)
1065 // loop, but don't allow a single term to monopolize us 1081 // loop, but don't allow a single term to monopolize us
1066 while (pty_fill ()) 1082 while (pty_fill ())
1067 if (cmd_parse ()) 1083 if (cmd_parse ())
1068 break; 1084 break;
1085
1086 if (revents & EVENT_WRITE)
1087 pty_write ();
1069} 1088}
1070 1089
1071void 1090void
1072rxvt_term::pointer_unblank () 1091rxvt_term::pointer_unblank ()
1073{ 1092{
1087rxvt_term::pointer_blank () 1106rxvt_term::pointer_blank ()
1088{ 1107{
1089 if (! (options & Opt_pointerBlank)) 1108 if (! (options & Opt_pointerBlank))
1090 return; 1109 return;
1091 1110
1092 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1111 XDefineCursor (display->display, TermWin.vt, display->blank_cursor);
1093 XFlush (display->display); 1112 XFlush (display->display);
1094 1113
1095 hidden_pointer = 1; 1114 hidden_pointer = 1;
1096} 1115}
1097 1116
1186 1205
1187/*{{{ process an X event */ 1206/*{{{ process an X event */
1188void 1207void
1189rxvt_term::x_cb (XEvent &ev) 1208rxvt_term::x_cb (XEvent &ev)
1190{ 1209{
1210 dDisp;
1211
1191 SET_R (this); 1212 SET_R (this);
1192 SET_LOCALE (locale); 1213 SET_LOCALE (locale);
1193 1214
1194#if defined(CURSOR_BLINK) 1215#if defined(CURSOR_BLINK)
1195 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1216 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1216 if (ev.type == KeyPress && hidden_pointer == 0) 1237 if (ev.type == KeyPress && hidden_pointer == 0)
1217 pointer_blank (); 1238 pointer_blank ();
1218 } 1239 }
1219#endif 1240#endif
1220 1241
1221 Window unused_root, unused_child; 1242 Window unused_root, unused_child;
1222 int unused_root_x, unused_root_y; 1243 int unused_root_x, unused_root_y;
1223 unsigned int unused_mask; 1244 unsigned int unused_mask;
1224 1245
1225 switch (ev.type) 1246 switch (ev.type)
1226 { 1247 {
1227 case KeyPress: 1248 case KeyPress:
1228#if ISO_14755 1249#if ISO_14755
1311 button_release (ev.xbutton); 1332 button_release (ev.xbutton);
1312 break; 1333 break;
1313 1334
1314 case ClientMessage: 1335 case ClientMessage:
1315 if (ev.xclient.format == 32 1336 if (ev.xclient.format == 32
1337 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1338 {
1316 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) 1339 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1317 destroy (); 1340 destroy ();
1341#if ENABLE_EWMH
1342 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1343 XSendEvent (disp, ev.xclient.window = display->root,
1344 False, SubstructureRedirectMask | SubstructureNotifyMask,
1345 &ev);
1346#endif
1347 }
1348#if ENABLE_XEMBED
1349 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1350 {
1351 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1352 focus_in ();
1353 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1354 focus_out ();
1355 }
1356#endif
1318#ifdef OFFIX_DND 1357#ifdef OFFIX_DND
1319 /* OffiX Dnd (drag 'n' drop) protocol */ 1358 /* OffiX Dnd (drag 'n' drop) protocol */
1320 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] 1359 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1321 && (ev.xclient.data.l[0] == DndFile 1360 && (ev.xclient.data.l[0] == DndFile
1322 || ev.xclient.data.l[0] == DndDir 1361 || ev.xclient.data.l[0] == DndDir
1323 || ev.xclient.data.l[0] == DndLink)) 1362 || ev.xclient.data.l[0] == DndLink))
1324 { 1363 {
1325 /* Get Dnd data */ 1364 /* Get Dnd data */
1326 Atom ActualType; 1365 Atom ActualType;
1327 int ActualFormat; 1366 int ActualFormat;
1328 unsigned char *data; 1367 unsigned char *data;
1329 unsigned long Size, RemainingBytes; 1368 unsigned long Size, RemainingBytes;
1330 1369
1331 XGetWindowProperty (display->display, display->root, 1370 XGetWindowProperty (disp, display->root,
1332 xa[XA_DNDSELECTION], 1371 xa[XA_DNDSELECTION],
1333 0L, 1000000L, 1372 0L, 1000000L,
1334 False, AnyPropertyType, 1373 False, AnyPropertyType,
1335 &ActualType, &ActualFormat, 1374 &ActualType, &ActualFormat,
1336 &Size, &RemainingBytes, 1375 &Size, &RemainingBytes,
1337 &data); 1376 &data);
1338 XChangeProperty (display->display, display->root, 1377 set_string_property (XA_CUT_BUFFER0, data);
1339 XA_CUT_BUFFER0, XA_STRING,
1340 8, PropModeReplace,
1341 data, strlen (data));
1342 XFree (data); 1378 XFree (data);
1343 selection_paste (display->root, XA_CUT_BUFFER0, True); 1379 selection_paste (display->root, XA_CUT_BUFFER0, true);
1344 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1380 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1345 } 1381 }
1346#endif /* OFFIX_DND */ 1382#endif /* OFFIX_DND */
1347 break; 1383 break;
1348 1384
1349 case MappingNotify: 1385 case MappingNotify:
1374 break; 1410 break;
1375 } 1411 }
1376 break; 1412 break;
1377 1413
1378 case FocusIn: 1414 case FocusIn:
1379 if (!TermWin.focus) 1415 focus_in ();
1380 {
1381 TermWin.focus = 1;
1382 want_refresh = 1;
1383#ifdef USE_XIM
1384 if (Input_Context != NULL)
1385 {
1386 IMSetStatusPosition ();
1387 XSetICFocus (Input_Context);
1388 }
1389#endif
1390#ifdef CURSOR_BLINK
1391 if (options & Opt_cursorBlink)
1392 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1393#endif
1394#ifdef OFF_FOCUS_FADING
1395 if (rs[Rs_fade])
1396 {
1397 pix_colors = pix_colors_focused;
1398 scr_recolour ();
1399 }
1400#endif
1401
1402 }
1403 break; 1416 break;
1404 1417
1405 case FocusOut: 1418 case FocusOut:
1406 if (TermWin.focus) 1419 focus_out ();
1407 {
1408 TermWin.focus = 0;
1409 want_refresh = 1;
1410
1411#if ENABLE_FRILLS || ISO_14755
1412 iso14755buf = 0;
1413#endif
1414#if ENABLE_OVERLAY
1415 scr_overlay_off ();
1416#endif
1417#ifdef USE_XIM
1418 if (Input_Context != NULL)
1419 XUnsetICFocus (Input_Context);
1420#endif
1421#ifdef CURSOR_BLINK
1422 if (options & Opt_cursorBlink)
1423 cursor_blink_ev.stop ();
1424 hidden_cursor = 0;
1425#endif
1426#ifdef OFF_FOCUS_FADING
1427 if (rs[Rs_fade])
1428 {
1429 pix_colors = pix_colors_unfocused;
1430 scr_recolour ();
1431 }
1432#endif
1433 }
1434 break; 1420 break;
1435 1421
1436 case ConfigureNotify: 1422 case ConfigureNotify:
1437 if (ev.xconfigure.window == TermWin.parent[0]) 1423 if (ev.xconfigure.window == TermWin.parent[0])
1438 { 1424 {
1442 { /* Wrap lots of configures into one */ 1428 { /* Wrap lots of configures into one */
1443 width = ev.xconfigure.width; 1429 width = ev.xconfigure.width;
1444 height = ev.xconfigure.height; 1430 height = ev.xconfigure.height;
1445 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); 1431 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1446 } 1432 }
1447 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); 1433 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev));
1448 1434
1449 if (szHint.width != width || szHint.height != height) 1435 if (szHint.width != width || szHint.height != height)
1450 { 1436 {
1451 seen_resize = 1; 1437 seen_resize = 1;
1452 resize_all_windows (width, height, 1); 1438 resize_all_windows (width, height, 1);
1453 } 1439 }
1454 1440
1455#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1441#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1456 if (options & Opt_transparent) 1442 if (options & Opt_transparent)
1457 {
1458 check_our_parents (); 1443 check_our_parents ();
1459 if (am_transparent)
1460 want_refresh = want_full_refresh = 1;
1461 }
1462#endif 1444#endif
1463 } 1445 }
1464 break; 1446 break;
1465 1447
1466 case PropertyNotify: 1448 case PropertyNotify:
1474 selection_clear (); 1456 selection_clear ();
1475 break; 1457 break;
1476 1458
1477 case SelectionNotify: 1459 case SelectionNotify:
1478 if (selection_wait == Sel_normal) 1460 if (selection_wait == Sel_normal)
1479 selection_paste (ev.xselection.requestor, 1461 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1480 ev.xselection.property, True);
1481 break; 1462 break;
1482 1463
1483 case SelectionRequest: 1464 case SelectionRequest:
1484 selection_send (ev.xselectionrequest); 1465 selection_send (ev.xselectionrequest);
1485 break; 1466 break;
1509 if (ev.xany.window == TermWin.vt) 1490 if (ev.xany.window == TermWin.vt)
1510 { 1491 {
1511 do 1492 do
1512 scr_expose (ev.xexpose.x, ev.xexpose.y, 1493 scr_expose (ev.xexpose.x, ev.xexpose.y,
1513 ev.xexpose.width, ev.xexpose.height, False); 1494 ev.xexpose.width, ev.xexpose.height, False);
1514 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1495 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev));
1515 1496
1516 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1497 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1517 1498
1518 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1499 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev))
1519 scr_expose (ev.xexpose.x, ev.xexpose.y, 1500 scr_expose (ev.xexpose.x, ev.xexpose.y,
1520 ev.xexpose.width, ev.xexpose.height, False); 1501 ev.xexpose.width, ev.xexpose.height, False);
1521 1502
1522 scr_refresh (refresh_type); 1503 scr_refresh (refresh_type);
1523 } 1504 }
1524 else 1505 else
1525 { 1506 {
1526 XEvent unused_event; 1507 XEvent unused_event;
1527 1508
1528 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1509 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1529 ; 1510 ;
1530 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1511 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1531 ; 1512 ;
1532 1513
1533 if (isScrollbarWindow (ev.xany.window)) 1514 if (isScrollbarWindow (ev.xany.window))
1534 { 1515 {
1535 scrollBar.setIdle (); 1516 scrollBar.setIdle ();
1540 menubar_expose (); 1521 menubar_expose ();
1541#endif 1522#endif
1542 1523
1543#ifdef TRANSPARENT 1524#ifdef TRANSPARENT
1544 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1525 if (am_transparent && ev.xany.window == TermWin.parent[0])
1545 XClearWindow (display->display, ev.xany.window); 1526 XClearWindow (disp, ev.xany.window);
1546#endif 1527#endif
1547 } 1528 }
1548 break; 1529 break;
1549 1530
1550 case MotionNotify: 1531 case MotionNotify:
1564 1545
1565 if (ev.xany.window == TermWin.vt) 1546 if (ev.xany.window == TermWin.vt)
1566 { 1547 {
1567 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1548 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1568 { 1549 {
1569 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1550 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev))
1570 ; 1551 ;
1571 1552
1572 XQueryPointer (display->display, TermWin.vt, 1553 XQueryPointer (disp, TermWin.vt,
1573 &unused_root, &unused_child, 1554 &unused_root, &unused_child,
1574 &unused_root_x, &unused_root_y, 1555 &unused_root_x, &unused_root_y,
1575 &ev.xbutton.x, &ev.xbutton.y, 1556 &ev.xbutton.x, &ev.xbutton.y,
1576 &ev.xbutton.state); 1557 &ev.xbutton.state);
1577#ifdef MOUSE_THRESHOLD 1558#ifdef MOUSE_THRESHOLD
1641#endif 1622#endif
1642 } 1623 }
1643 } 1624 }
1644 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1625 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1645 { 1626 {
1646 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1627 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1647 MotionNotify, &ev)) 1628 MotionNotify, &ev))
1648 ; 1629 ;
1649 1630
1650 XQueryPointer (display->display, scrollBar.win, 1631 XQueryPointer (disp, scrollBar.win,
1651 &unused_root, &unused_child, 1632 &unused_root, &unused_child,
1652 &unused_root_x, &unused_root_y, 1633 &unused_root_x, &unused_root_y,
1653 &ev.xbutton.x, &ev.xbutton.y, 1634 &ev.xbutton.x, &ev.xbutton.y,
1654 &unused_mask); 1635 &unused_mask);
1655 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1636 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1660 } 1641 }
1661 break; 1642 break;
1662 } 1643 }
1663} 1644}
1664 1645
1646void
1647rxvt_term::focus_in ()
1648{
1649 if (!TermWin.focus)
1650 {
1651 TermWin.focus = 1;
1652 want_refresh = 1;
1653#ifdef USE_XIM
1654 if (Input_Context != NULL)
1655 {
1656 IMSetStatusPosition ();
1657 XSetICFocus (Input_Context);
1658 }
1659#endif
1660#ifdef CURSOR_BLINK
1661 if (options & Opt_cursorBlink)
1662 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1663#endif
1664#ifdef OFF_FOCUS_FADING
1665 if (rs[Rs_fade])
1666 {
1667 pix_colors = pix_colors_focused;
1668 scr_recolour ();
1669 }
1670#endif
1671 }
1672}
1673
1674void
1675rxvt_term::focus_out ()
1676{
1677 if (TermWin.focus)
1678 {
1679 TermWin.focus = 0;
1680 want_refresh = 1;
1681
1682#if ENABLE_FRILLS || ISO_14755
1683 iso14755buf = 0;
1684#endif
1685#if ENABLE_OVERLAY
1686 scr_overlay_off ();
1687#endif
1688#ifdef USE_XIM
1689 if (Input_Context != NULL)
1690 XUnsetICFocus (Input_Context);
1691#endif
1692#ifdef CURSOR_BLINK
1693 if (options & Opt_cursorBlink)
1694 cursor_blink_ev.stop ();
1695 hidden_cursor = 0;
1696#endif
1697#ifdef OFF_FOCUS_FADING
1698 if (rs[Rs_fade])
1699 {
1700 pix_colors = pix_colors_unfocused;
1701 scr_recolour ();
1702 }
1703#endif
1704 }
1705}
1706
1665#if TRANSPARENT 1707#if TRANSPARENT
1666void 1708void
1667rxvt_term::rootwin_cb (XEvent &ev) 1709rxvt_term::rootwin_cb (XEvent &ev)
1668{ 1710{
1669 SET_R (this); 1711 SET_R (this);
1674 case PropertyNotify: 1716 case PropertyNotify:
1675 /* 1717 /*
1676 * if user used some Esetroot compatible prog to set the root bg, 1718 * if user used some Esetroot compatible prog to set the root bg,
1677 * use the property to determine the pixmap. We use it later on. 1719 * use the property to determine the pixmap. We use it later on.
1678 */ 1720 */
1679 if (xa[XA_XROOTPMAPID] == 0)
1680 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1681
1682 if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) 1721 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1722 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1683 return; 1723 return;
1684 1724
1685 /* FALLTHROUGH */ 1725 /* FALLTHROUGH */
1686 case ReparentNotify: 1726 case ReparentNotify:
1687 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1727 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1759 { 1799 {
1760 case Button1: 1800 case Button1:
1761 /* allow meta + click to select rectangular areas */ 1801 /* allow meta + click to select rectangular areas */
1762 /* should be done in screen.C */ 1802 /* should be done in screen.C */
1763#if ENABLE_FRILLS 1803#if ENABLE_FRILLS
1764 selection.rect = !! (ev.state & ModMetaMask); 1804 selection.rect = !!(ev.state & ModMetaMask);
1765#else 1805#else
1766 selection.rect = false; 1806 selection.rect = false;
1767#endif 1807#endif
1768 1808
1769 /* allow shift+left click to extend selection */ 1809 /* allow shift+left click to extend selection */
2095 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2135 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2096 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2136 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2097 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2137 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2098 int i; 2138 int i;
2099 2139
2100 Visual* visual = display->visual; 2140 Visual *visual = display->visual;
2101 2141
2102 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2142 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2103 2143
2104 /* for convenience */ 2144 /* for convenience */
2105 mask_r = visual->red_mask; 2145 mask_r = visual->red_mask;
2326 Atom atype; 2366 Atom atype;
2327 unsigned char *prop = NULL; 2367 unsigned char *prop = NULL;
2328 Window root, oldp, *list; 2368 Window root, oldp, *list;
2329 Pixmap rootpixmap = None; 2369 Pixmap rootpixmap = None;
2330 XWindowAttributes wattr, wrootattr; 2370 XWindowAttributes wattr, wrootattr;
2371 dDisp;
2331 2372
2332 pchanged = 0; 2373 pchanged = 0;
2333 2374
2334 if (!(options & Opt_transparent)) 2375 if (!(options & Opt_transparent))
2335 return pchanged; /* Don't try any more */ 2376 return pchanged; /* Don't try any more */
2336 2377
2337 XGetWindowAttributes (display->display, display->root, &wrootattr); 2378 XGetWindowAttributes (disp, display->root, &wrootattr);
2338 rootdepth = wrootattr.depth; 2379 rootdepth = wrootattr.depth;
2339 2380
2340 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2381 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2341 2382
2342 if (rootdepth != wattr.depth) 2383 if (rootdepth != wattr.depth)
2343 { 2384 {
2344 if (am_transparent) 2385 if (am_transparent)
2345 { 2386 {
2346 pchanged = 1; 2387 pchanged = 1;
2347 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2388 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2348 am_transparent = am_pixmap_trans = 0; 2389 am_transparent = am_pixmap_trans = 0;
2349 } 2390 }
2350 2391
2351 return pchanged; /* Don't try any more */ 2392 return pchanged; /* Don't try any more */
2352 } 2393 }
2353 2394
2354 /* Get all X ops out of the queue so that our information is up-to-date. */ 2395 /* Get all X ops out of the queue so that our information is up-to-date. */
2355 XSync (display->display, False); 2396 XSync (disp, False);
2356 2397
2357 /* 2398 /*
2358 * Make the frame window set by the window manager have 2399 * Make the frame window set by the window manager have
2359 * the root background. Some window managers put multiple nested frame 2400 * the root background. Some window managers put multiple nested frame
2360 * windows for each client, so we have to take care about that. 2401 * windows for each client, so we have to take care about that.
2361 */ 2402 */
2362 i = (xa[XA_XROOTPMAPID] 2403 i = (xa[XA_XROOTPMAP_ID]
2363 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2404 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2364 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2405 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2365 &nitems, &bytes_after, &prop) == Success); 2406 &nitems, &bytes_after, &prop) == Success);
2366 2407
2367 if (!i || prop == NULL) 2408 if (!i || prop == NULL)
2368 i = (xa[XA_XSETROOTID] 2409 i = (xa[XA_ESETROOT_PMAP_ID]
2369 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2410 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2370 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2411 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2371 &nitems, &bytes_after, &prop) == Success); 2412 &nitems, &bytes_after, &prop) == Success);
2372 2413
2373 if (!i || prop == NULL 2414 if (!i || prop == NULL
2374#if TINTING 2415#if TINTING
2393 Window cr; 2434 Window cr;
2394 XImage *image; 2435 XImage *image;
2395 GC gc; 2436 GC gc;
2396 XGCValues gcvalue; 2437 XGCValues gcvalue;
2397 2438
2398 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2439 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2399 0, 0, &sx, &sy, &cr); 2440 0, 0, &sx, &sy, &cr);
2400 nw = (unsigned int)szHint.width; 2441 nw = (unsigned int)szHint.width;
2401 nh = (unsigned int)szHint.height; 2442 nh = (unsigned int)szHint.height;
2402 nx = ny = 0; 2443 nx = ny = 0;
2403 2444
2415 sy = 0; 2456 sy = 0;
2416 } 2457 }
2417 2458
2418 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2459 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2419 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2460 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2461
2462 XSync (disp, False);
2420 allowedxerror = -1; 2463 allowedxerror = -1;
2421 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2464 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2422 2465
2423 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2466 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2424 /* XXX: may need a delay here? */ 2467 /* XXX: may need a delay here? */
2425 allowedxerror = 0; 2468 allowedxerror = 0;
2426 2469
2429 if (am_transparent && am_pixmap_trans) 2472 if (am_transparent && am_pixmap_trans)
2430 { 2473 {
2431 pchanged = 1; 2474 pchanged = 1;
2432 if (TermWin.pixmap != None) 2475 if (TermWin.pixmap != None)
2433 { 2476 {
2434 XFreePixmap (display->display, TermWin.pixmap); 2477 XFreePixmap (disp, TermWin.pixmap);
2435 TermWin.pixmap = None; 2478 TermWin.pixmap = None;
2436 } 2479 }
2437 } 2480 }
2438 2481
2439 am_pixmap_trans = 0; 2482 am_pixmap_trans = 0;
2440 } 2483 }
2441 else 2484 else
2442 { 2485 {
2443 if (TermWin.pixmap != None) 2486 if (TermWin.pixmap != None)
2444 XFreePixmap (display->display, TermWin.pixmap); 2487 XFreePixmap (disp, TermWin.pixmap);
2445 2488
2446#if TINTING 2489#if TINTING
2447 if (ISSET_PIXCOLOR (Color_tint)) 2490 if (ISSET_PIXCOLOR (Color_tint))
2448 { 2491 {
2449 unsigned short rm, gm, bm; 2492 unsigned short rm, gm, bm;
2453 2496
2454 ShadeXImage (display, image, shade, rm, gm, bm); 2497 ShadeXImage (display, image, shade, rm, gm, bm);
2455 } 2498 }
2456#endif 2499#endif
2457 2500
2458 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2501 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2459 szHint.width, szHint.height, image->depth); 2502 szHint.width, szHint.height, image->depth);
2460 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2503 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2461 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2504 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2462 nx, ny, image->width, image->height); 2505 nx, ny, image->width, image->height);
2463 XFreeGC (display->display, gc); 2506 XFreeGC (disp, gc);
2464 XDestroyImage (image); 2507 XDestroyImage (image);
2465 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2508 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2466 XClearWindow (display->display, TermWin.parent[0]); 2509 XClearWindow (disp, TermWin.parent[0]);
2467 2510
2468 if (!am_transparent || !am_pixmap_trans) 2511 if (!am_transparent || !am_pixmap_trans)
2469 pchanged = 1; 2512 pchanged = 1;
2470 2513
2471 am_transparent = am_pixmap_trans = 1; 2514 am_transparent = am_pixmap_trans = 1;
2472 } 2515 }
2473 } 2516 }
2474 2517
2475 if (!am_pixmap_trans) 2518 if (am_pixmap_trans)
2519 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2520 else
2476 { 2521 {
2477 unsigned int n; 2522 unsigned int n;
2478 /* 2523 /*
2479 * InheritPixmap transparency 2524 * InheritPixmap transparency
2480 */ 2525 */
2481 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2526 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2482 { 2527 {
2483 oldp = TermWin.parent[i]; 2528 oldp = TermWin.parent[i];
2484 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2529 XQueryTree (disp, TermWin.parent[i - 1], &root,
2485 &TermWin.parent[i], &list, &n); 2530 &TermWin.parent[i], &list, &n);
2486 XFree (list); 2531 XFree (list);
2487 2532
2488 if (TermWin.parent[i] == display->root) 2533 if (TermWin.parent[i] == display->root)
2489 { 2534 {
2501 2546
2502 if (pchanged) 2547 if (pchanged)
2503 { 2548 {
2504 for (; n < (unsigned int)i; n++) 2549 for (; n < (unsigned int)i; n++)
2505 { 2550 {
2506 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2551 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2507 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2552 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2508 { 2553 {
2509 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2554 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2510 break; 2555 break;
2511 } 2556 }
2512 } 2557 }
2513 } 2558 }
2514 2559
2515 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2560 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2516 { 2561 {
2517 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2562 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2518 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2563 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2519 am_transparent = 0; 2564 am_transparent = 0;
2520 /* XXX: also turn off Opt_transparent? */ 2565 /* XXX: also turn off Opt_transparent? */
2521 } 2566 }
2522 else 2567 else
2523 { 2568 {
2526 * needed for fvwm2.2.2 (and before?) */ 2571 * needed for fvwm2.2.2 (and before?) */
2527 sleep (1); 2572 sleep (1);
2528#endif 2573#endif
2529 for (n = 0; n < (unsigned int)i; n++) 2574 for (n = 0; n < (unsigned int)i; n++)
2530 { 2575 {
2531 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2576 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2532 XClearWindow (display->display, TermWin.parent[n]); 2577 XClearWindow (disp, TermWin.parent[n]);
2533 } 2578 }
2534 2579
2535 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2580 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2536 am_transparent = 1; 2581 am_transparent = 1;
2537 } 2582 }
2538 2583
2539 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2584 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2540 TermWin.parent[i] = None; 2585 TermWin.parent[i] = None;
2541 } 2586 }
2542 2587
2543 if (scrollBar.win) 2588 if (scrollBar.win)
2544 { 2589 {
2545 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2590 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2546 scrollBar.setIdle (); 2591 scrollBar.setIdle ();
2547 scrollbar_show (0); 2592 scrollbar_show (0);
2593 }
2594
2595 if (am_transparent)
2596 {
2597 want_refresh = want_full_refresh = 1;
2598 if (am_pixmap_trans)
2599 flush ();
2548 } 2600 }
2549 2601
2550 return pchanged; 2602 return pchanged;
2551} 2603}
2552#endif 2604#endif
2581 // some window managers resize the window early, and these programs 2633 // some window managers resize the window early, and these programs
2582 // then sometimes get the size wrong. 2634 // then sometimes get the size wrong.
2583 // unfortunately other programs are even more buggy and dislike 2635 // unfortunately other programs are even more buggy and dislike
2584 // being sent SIGWINCH, so only do it when we were in fact being 2636 // being sent SIGWINCH, so only do it when we were in fact being
2585 // resized. 2637 // resized.
2586 if (seen_resize) 2638 if (seen_resize && cmd_pid)
2587 kill (-cmd_pid, SIGWINCH); 2639 kill (-cmd_pid, SIGWINCH);
2588 } 2640 }
2589 2641
2590 /* Read a text string from the input buffer */ 2642 /* Read a text string from the input buffer */
2591 unicode_t buf[UBUFSIZ]; 2643 unicode_t buf[UBUFSIZ];
2704 if (len == (size_t)-1) 2756 if (len == (size_t)-1)
2705 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2757 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2706 2758
2707 // assume wchar == unicode 2759 // assume wchar == unicode
2708 cmdbuf_ptr += len; 2760 cmdbuf_ptr += len;
2709 return wc; 2761 return wc & UNICODE_MASK;
2710 } 2762 }
2711 2763
2712 return NOCHAR; 2764 return NOCHAR;
2713} 2765}
2714 2766
3177 { 3229 {
3178 switch (priv) 3230 switch (priv)
3179 { 3231 {
3180 case '>': 3232 case '>':
3181 if (ch == CSI_DA) /* secondary device attributes */ 3233 if (ch == CSI_DA) /* secondary device attributes */
3182 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING); 3234 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3183 break; 3235 break;
3184 case '?': 3236 case '?':
3185 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3237 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3186 process_terminal_mode (ch, priv, nargs, arg); 3238 process_terminal_mode (ch, priv, nargs, arg);
3187 break; 3239 break;
3416rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3468rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3417{ 3469{
3418 int x, y; 3470 int x, y;
3419 XWindowAttributes wattr; 3471 XWindowAttributes wattr;
3420 Window wdummy; 3472 Window wdummy;
3473 dDisp;
3421 3474
3422 if (nargs == 0) 3475 if (nargs == 0)
3423 return; 3476 return;
3424 3477
3425 switch (args[0]) 3478 switch (args[0])
3426 { 3479 {
3427 /* 3480 /*
3428 * commands 3481 * commands
3429 */ 3482 */
3430 case 1: /* deiconify window */ 3483 case 1: /* deiconify window */
3431 XMapWindow (display->display, TermWin.parent[0]); 3484 XMapWindow (disp, TermWin.parent[0]);
3432 break; 3485 break;
3433 case 2: /* iconify window */ 3486 case 2: /* iconify window */
3434 XIconifyWindow (display->display, TermWin.parent[0], 3487 XIconifyWindow (disp, TermWin.parent[0], display->screen);
3435 DefaultScreen (display->display));
3436 break; 3488 break;
3437 case 3: /* set position (pixels) */ 3489 case 3: /* set position (pixels) */
3438 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3490 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]);
3439 break; 3491 break;
3440 case 4: /* set size (pixels) */ 3492 case 4: /* set size (pixels) */
3441 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3493 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3442 break; 3494 break;
3443 case 5: /* raise window */ 3495 case 5: /* raise window */
3444 XRaiseWindow (display->display, TermWin.parent[0]); 3496 XRaiseWindow (disp, TermWin.parent[0]);
3445 break; 3497 break;
3446 case 6: /* lower window */ 3498 case 6: /* lower window */
3447 XLowerWindow (display->display, TermWin.parent[0]); 3499 XLowerWindow (disp, TermWin.parent[0]);
3448 break; 3500 break;
3449 case 7: /* refresh window */ 3501 case 7: /* refresh window */
3450 scr_touch (true); 3502 scr_touch (true);
3451 break; 3503 break;
3452 case 8: /* set size (chars) */ 3504 case 8: /* set size (chars) */
3464 3516
3465 /* 3517 /*
3466 * reports - some output format copied from XTerm 3518 * reports - some output format copied from XTerm
3467 */ 3519 */
3468 case 11: /* report window state */ 3520 case 11: /* report window state */
3469 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3521 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3470 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3522 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3471 break; 3523 break;
3472 case 13: /* report window position */ 3524 case 13: /* report window position */
3473 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3525 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3474 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3526 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root,
3475 -wattr.border_width, -wattr.border_width, 3527 -wattr.border_width, -wattr.border_width,
3476 &x, &y, &wdummy); 3528 &x, &y, &wdummy);
3477 tt_printf ("\033[3;%d;%dt", x, y); 3529 tt_printf ("\033[3;%d;%dt", x, y);
3478 break; 3530 break;
3479 case 14: /* report window size (pixels) */ 3531 case 14: /* report window size (pixels) */
3480 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3532 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3481 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3533 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3482 break; 3534 break;
3483 case 18: /* report text area size (chars) */ 3535 case 18: /* report text area size (chars) */
3484 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3536 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3485 break; 3537 break;
3487 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3539 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3488 break; 3540 break;
3489 case 20: /* report icon label */ 3541 case 20: /* report icon label */
3490 { 3542 {
3491 char *s; 3543 char *s;
3492 XGetIconName (display->display, TermWin.parent[0], &s); 3544 XGetIconName (disp, TermWin.parent[0], &s);
3493 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3545 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3494 XFree (s); 3546 XFree (s);
3495 } 3547 }
3496 break; 3548 break;
3497 case 21: /* report window title */ 3549 case 21: /* report window title */
3498 { 3550 {
3499 char *s; 3551 char *s;
3500 XFetchName (display->display, TermWin.parent[0], &s); 3552 XFetchName (disp, TermWin.parent[0], &s);
3501 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3553 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3502 XFree (s); 3554 XFree (s);
3503 } 3555 }
3504 break; 3556 break;
3505 } 3557 }
3512 * ends_how is terminator used. returned input must be free()'d 3564 * ends_how is terminator used. returned input must be free()'d
3513 */ 3565 */
3514unsigned char * 3566unsigned char *
3515rxvt_term::get_to_st (unicode_t &ends_how) 3567rxvt_term::get_to_st (unicode_t &ends_how)
3516{ 3568{
3517 unicode_t seen_esc = 0, ch; 3569 unicode_t ch;
3570 bool seen_esc = false;
3518 unsigned int n = 0; 3571 unsigned int n = 0;
3519 unsigned char *s;
3520 unsigned char string[STRING_MAX]; 3572 wchar_t string[STRING_MAX];
3521 3573
3522 while ((ch = cmd_getc ()) != NOCHAR) 3574 while ((ch = cmd_getc ()) != NOCHAR)
3523 { 3575 {
3524 if (seen_esc) 3576 if (seen_esc)
3525 { 3577 {
3528 else 3580 else
3529 return NULL; 3581 return NULL;
3530 } 3582 }
3531 else if (ch == C0_ESC) 3583 else if (ch == C0_ESC)
3532 { 3584 {
3533 seen_esc = 1; 3585 seen_esc = true;
3534 continue; 3586 continue;
3535 } 3587 }
3536 else if (ch == C0_BEL || ch == CHAR_ST) 3588 else if (ch == C0_BEL || ch == CHAR_ST)
3537 break; 3589 break;
3538 else if (ch < 0x20) 3590 else if (ch < 0x20)
3539 return NULL; /* other control character - exit */ 3591 return NULL; /* other control character - exit */
3540 3592
3541 seen_esc = 0; 3593 seen_esc = false;
3542 3594
3543 if (n >= sizeof (string) - 1) 3595 if (n >= STRING_MAX - 1)
3544 // stop at some sane length 3596 // stop at some sane length
3545 return NULL; 3597 return NULL;
3546 3598
3547 if (ch == C0_SYN) 3599 if (ch == C0_SYN)
3548 string[n++] = cmd_get8 (); 3600 string[n++] = cmd_get8 ();
3550 string[n++] = ch; 3602 string[n++] = ch;
3551 } 3603 }
3552 3604
3553 string[n++] = '\0'; 3605 string[n++] = '\0';
3554 3606
3555 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3556 return NULL;
3557
3558 ends_how = (ch == 0x5c ? C0_ESC : ch); 3607 ends_how = (ch == 0x5c ? C0_ESC : ch);
3559 strncpy (s, string, n); 3608
3560 return s; 3609 return (unsigned char *)rxvt_wcstombs (string);
3561} 3610}
3562 3611
3563/*----------------------------------------------------------------------*/ 3612/*----------------------------------------------------------------------*/
3564/* 3613/*
3565 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3614 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3619 set_window_color (color, str); 3668 set_window_color (color, str);
3620} 3669}
3621 3670
3622/* 3671/*
3623 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3672 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3624 * 0 = change iconName/title
3625 * 1 = change iconName
3626 * 2 = change title
3627 * 4 = change color
3628 * 10 = change fg color
3629 * 11 = change bg color
3630 * 12 = change text color
3631 * 13 = change mouse foreground color
3632 * 17 = change highlight character colour
3633 * 18 = change bold character color
3634 * 19 = change underlined character color
3635 * 46 = change logfile (not implemented)
3636 * 50 = change font
3637 *
3638 * rxvt extensions:
3639 * 20 = bg pixmap
3640 * 39 = change default fg color
3641 * 49 = change default bg color
3642 * 55 = dump scrollback buffer and all of screen
3643 * 701 = change locale
3644 * 702 = find font
3645 * 703 = menu
3646 */ 3673 */
3647void 3674void
3648rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3675rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3649{ 3676{
3650 int changed = 0; 3677 int changed = 0;
3651 int color; 3678 int color;
3652 char *buf, *name; 3679 char *buf, *name;
3653 bool query = str[0] == '?' && !str[1]; 3680 bool query = str[0] == '?' && !str[1];
3654 int saveop = op; 3681 int saveop = op;
3682 dDisp;
3655 3683
3656 assert (str != NULL); 3684 assert (str != NULL);
3657 switch (op) 3685 switch (op)
3658 { 3686 {
3659 case XTerm_name: 3687 case XTerm_name:
3666 set_title (str); 3694 set_title (str);
3667 break; 3695 break;
3668 case XTerm_property: 3696 case XTerm_property:
3669 if (str[0] == '?') 3697 if (str[0] == '?')
3670 { 3698 {
3671 Atom prop = XInternAtom (display->display, str + 1, True); 3699 Atom prop = display->atom (str + 1);
3672 Atom actual_type; 3700 Atom actual_type;
3673 int actual_format; 3701 int actual_format;
3674 unsigned long nitems; 3702 unsigned long nitems;
3675 unsigned long bytes_after; 3703 unsigned long bytes_after;
3676 unsigned char *value = 0; 3704 unsigned char *value = 0;
3677 const char *str = ""; 3705 const char *str = "";
3678 3706
3679 if (prop 3707 if (prop
3680 && XGetWindowProperty (display->display, TermWin.parent[0], 3708 && XGetWindowProperty (disp, TermWin.parent[0],
3681 prop, 0, 1<<16, 0, AnyPropertyType, 3709 prop, 0, 1<<16, 0, AnyPropertyType,
3682 &actual_type, &actual_format, 3710 &actual_type, &actual_format,
3683 &nitems, &bytes_after, &value) == Success 3711 &nitems, &bytes_after, &value) == Success
3684 && actual_type != None 3712 && actual_type != None
3685 && actual_format == 8) 3713 && actual_format == 8)
3694 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3722 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3695 3723
3696 if (eq) 3724 if (eq)
3697 { 3725 {
3698 *eq = 0; 3726 *eq = 0;
3699 XChangeProperty (display->display, TermWin.parent[0], 3727 set_utf8_property (display->atom (str), eq + 1);
3700 display->atom (str), XA_STRING, 8,
3701 PropModeReplace, (unsigned char *)eq + 1,
3702 strlen (eq + 1));
3703 } 3728 }
3704 else 3729 else
3705 XDeleteProperty (display->display, TermWin.parent[0], 3730 XDeleteProperty (disp, TermWin.parent[0],
3706 display->atom (str)); 3731 display->atom (str));
3707 } 3732 }
3708 break; 3733 break;
3709 3734
3710 case XTerm_Color: 3735 case XTerm_Color:
3751 break; 3776 break;
3752#ifndef NO_BOLD_UNDERLINE_REVERSE 3777#ifndef NO_BOLD_UNDERLINE_REVERSE
3753 case XTerm_Color_BD: 3778 case XTerm_Color_BD:
3754 process_color_seq (XTerm_Color_BD, Color_BD, str, resp); 3779 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3755 break; 3780 break;
3756 case XTerm_Color_IT:
3757 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3758 break;
3759 case XTerm_Color_UL: 3781 case XTerm_Color_UL:
3760 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3782 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3761 break; 3783 break;
3762 case XTerm_Color_RV: 3784 case XTerm_Color_RV:
3763 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3785 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3764 break; 3786 break;
3787 case URxvt_Color_IT:
3788 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3789 break;
3765#endif 3790#endif
3766#if TRANSPARENT || TINTING 3791#if TRANSPARENT && TINTING
3767 case XTerm_Color_tint: 3792 case URxvt_Color_tint:
3768 process_color_seq (XTerm_Color_tint, Color_tint, str, resp); 3793 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3769 check_our_parents (); 3794 check_our_parents ();
3770 if (am_transparent) 3795 if (am_transparent)
3771 want_full_refresh = want_refresh = 1; 3796 want_full_refresh = want_refresh = 1;
3772 break; 3797 break;
3773#endif 3798#endif
3785 { 3810 {
3786 str++; 3811 str++;
3787#if XPM_BACKGROUND 3812#if XPM_BACKGROUND
3788 changed += scale_pixmap (str); 3813 changed += scale_pixmap (str);
3789#endif 3814#endif
3790
3791 } 3815 }
3816
3792 if (changed) 3817 if (changed)
3793 { 3818 {
3794#ifdef XPM_BACKGROUND 3819#ifdef XPM_BACKGROUND
3795 resize_pixmap (); 3820 resize_pixmap ();
3796#endif 3821#endif
3807 3832
3808 case XTerm_logfile: 3833 case XTerm_logfile:
3809 // TODO, when secure mode? 3834 // TODO, when secure mode?
3810 break; 3835 break;
3811 3836
3837#ifdef MENUBAR
3838 case URxvt_Menu:
3839 if (options & Opt_insecure)
3840 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3841 break;
3842#endif
3843#if 0
3844 case XTerm_dumpscreen: /* no error notices */
3845 {
3846 int fd;
3847 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3848 {
3849 scr_dump (fd);
3850 close (fd);
3851 }
3852 }
3853 break;
3854#endif
3812 case XTerm_font: 3855 case XTerm_font:
3813 op = URxvt_font; 3856 op = URxvt_font;
3814 case URxvt_font: 3857 case URxvt_font:
3815#if ENABLE_STYLES 3858#if ENABLE_STYLES
3816 case URxvt_boldFont: 3859 case URxvt_boldFont:
3831 set_fonts (); 3874 set_fonts ();
3832 } 3875 }
3833 break; 3876 break;
3834 3877
3835#if ENABLE_FRILLS 3878#if ENABLE_FRILLS
3836 case XTerm_locale: 3879 case URxvt_locale:
3837 if (query) 3880 if (query)
3838 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3881 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp);
3839 else 3882 else
3840 { 3883 {
3841 set_locale (str); 3884 set_locale (str);
3842# ifdef USE_XIM 3885 pty.set_utf8_mode (enc_utf8);
3843 im_cb (); 3886 init_xlocale ();
3844# endif
3845 } 3887 }
3846 break; 3888 break;
3847#endif
3848 3889
3849#ifdef MENUBAR 3890 case URxvt_view_up:
3850 case XTerm_Menu: 3891 case URxvt_view_down:
3851 if (options & Opt_insecure) 3892 int lines = atoi (str);
3852 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3893
3853 break; 3894 if (lines)
3854#endif 3895 scr_page (op == URxvt_view_up ? UP : DN, lines);
3855#if 0
3856 case XTerm_dumpscreen: /* no error notices */
3857 { 3896 else
3858 int fd;
3859 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3860 { 3897 {
3861 scr_dump (fd); 3898 scr_erase_savelines ();
3862 close (fd);
3863 } 3899 }
3864 } 3900
3865 break; 3901 break;
3866#endif 3902#endif
3867 } 3903 }
3868} 3904}
3869/*----------------------------------------------------------------------*/ 3905/*----------------------------------------------------------------------*/
4284 4320
4285/* ---------------------------------------------------------------------- */ 4321/* ---------------------------------------------------------------------- */
4286/* Write data to the pty as typed by the user, pasted with the mouse, 4322/* Write data to the pty as typed by the user, pasted with the mouse,
4287 * or generated by us in response to a query ESC sequence. 4323 * or generated by us in response to a query ESC sequence.
4288 */ 4324 */
4325const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4326
4289void 4327void
4290rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4328rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4291{ 4329{
4292 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4330 if (v_buflen == 0)
4331 {
4332 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4293 4333
4294 if (len) 4334 if ((unsigned int)written == len)
4335 return;
4336
4337 data += written;
4338 len -= written;
4295 { 4339 }
4340
4341 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4342
4343 memcpy (v_buffer + v_buflen, data, len);
4344 v_buflen += len;
4345
4346 pty_ev.set (EVENT_READ | EVENT_WRITE);
4347}
4348
4349void rxvt_term::pty_write ()
4350{
4351 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4352
4353 if (written > 0)
4354 {
4355 v_buflen -= written;
4356
4296 if (v_buflen == 0) 4357 if (v_buflen == 0)
4297 { 4358 {
4298 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4299
4300 if ((unsigned int)written == len)
4301 return;
4302
4303 data += written;
4304 len -= written;
4305 }
4306
4307
4308 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4309
4310 memcpy (v_buffer + v_buflen, data, len);
4311 v_buflen += len;
4312 }
4313
4314 for (;;)
4315 {
4316 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4317
4318 if (written > 0)
4319 {
4320 v_buflen -= written;
4321
4322 if (v_buflen == 0)
4323 {
4324 free (v_buffer); 4359 free (v_buffer);
4325 v_buffer = 0; 4360 v_buffer = 0;
4326 v_buflen = 0; 4361 v_buflen = 0;
4327 4362
4328 pty_ev.set (EVENT_READ); 4363 pty_ev.set (EVENT_READ);
4329 return;
4330 }
4331
4332 memmove (v_buffer, v_buffer + written, v_buflen);
4333 }
4334 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4335 // original code just ignores this...
4336 destroy ();
4337 else
4338 {
4339 pty_ev.set (EVENT_READ | EVENT_WRITE);
4340 return; 4364 return;
4341 } 4365 }
4366
4367 memmove (v_buffer, v_buffer + written, v_buflen);
4342 } 4368 }
4369 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4370 // original code just ignores this...
4371 destroy ();
4343} 4372}
4344 4373
4345/*----------------------- end-of-file (C source) -----------------------*/ 4374/*----------------------- end-of-file (C source) -----------------------*/
4346 4375

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines