… | |
… | |
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 | #include <wchar.h> |
|
|
54 | #include <signal.h> |
54 | |
55 | |
55 | /*----------------------------------------------------------------------*/ |
56 | /*----------------------------------------------------------------------*/ |
56 | |
57 | |
57 | #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) |
58 | #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) |
58 | |
59 | |
… | |
… | |
1057 | rxvt_term::pty_cb (io_watcher &w, short revents) |
1058 | rxvt_term::pty_cb (io_watcher &w, short revents) |
1058 | { |
1059 | { |
1059 | SET_R (this); |
1060 | SET_R (this); |
1060 | SET_LOCALE (locale); |
1061 | SET_LOCALE (locale); |
1061 | |
1062 | |
1062 | if (revents & EVENT_WRITE) |
|
|
1063 | tt_write (0, 0); |
|
|
1064 | else if (revents & EVENT_READ) |
1063 | if (revents & EVENT_READ) |
1065 | // loop, but don't allow a single term to monopolize us |
1064 | // loop, but don't allow a single term to monopolize us |
1066 | while (pty_fill ()) |
1065 | while (pty_fill ()) |
1067 | if (cmd_parse ()) |
1066 | if (cmd_parse ()) |
1068 | break; |
1067 | break; |
|
|
1068 | |
|
|
1069 | if (revents & EVENT_WRITE) |
|
|
1070 | pty_write (); |
1069 | } |
1071 | } |
1070 | |
1072 | |
1071 | void |
1073 | void |
1072 | rxvt_term::pointer_unblank () |
1074 | rxvt_term::pointer_unblank () |
1073 | { |
1075 | { |
… | |
… | |
1216 | if (ev.type == KeyPress && hidden_pointer == 0) |
1218 | if (ev.type == KeyPress && hidden_pointer == 0) |
1217 | pointer_blank (); |
1219 | pointer_blank (); |
1218 | } |
1220 | } |
1219 | #endif |
1221 | #endif |
1220 | |
1222 | |
1221 | Window unused_root, unused_child; |
1223 | Window unused_root, unused_child; |
1222 | int unused_root_x, unused_root_y; |
1224 | int unused_root_x, unused_root_y; |
1223 | unsigned int unused_mask; |
1225 | unsigned int unused_mask; |
1224 | |
1226 | |
1225 | switch (ev.type) |
1227 | switch (ev.type) |
1226 | { |
1228 | { |
1227 | case KeyPress: |
1229 | case KeyPress: |
1228 | #if ISO_14755 |
1230 | #if ISO_14755 |
… | |
… | |
1333 | 0L, 1000000L, |
1335 | 0L, 1000000L, |
1334 | False, AnyPropertyType, |
1336 | False, AnyPropertyType, |
1335 | &ActualType, &ActualFormat, |
1337 | &ActualType, &ActualFormat, |
1336 | &Size, &RemainingBytes, |
1338 | &Size, &RemainingBytes, |
1337 | &data); |
1339 | &data); |
1338 | XChangeProperty (display->display, display->root, |
1340 | set_string_property (XA_CUT_BUFFER0, data); |
1339 | XA_CUT_BUFFER0, XA_STRING, |
|
|
1340 | 8, PropModeReplace, |
|
|
1341 | data, strlen (data)); |
|
|
1342 | XFree (data); |
1341 | XFree (data); |
1343 | selection_paste (display->root, XA_CUT_BUFFER0, True); |
1342 | selection_paste (display->root, XA_CUT_BUFFER0, true); |
1344 | XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); |
1343 | XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); |
1345 | } |
1344 | } |
1346 | #endif /* OFFIX_DND */ |
1345 | #endif /* OFFIX_DND */ |
1347 | break; |
1346 | break; |
1348 | |
1347 | |
… | |
… | |
1452 | resize_all_windows (width, height, 1); |
1451 | resize_all_windows (width, height, 1); |
1453 | } |
1452 | } |
1454 | |
1453 | |
1455 | #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ |
1454 | #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ |
1456 | if (options & Opt_transparent) |
1455 | if (options & Opt_transparent) |
1457 | { |
|
|
1458 | check_our_parents (); |
1456 | check_our_parents (); |
1459 | if (am_transparent) |
|
|
1460 | want_refresh = want_full_refresh = 1; |
|
|
1461 | } |
|
|
1462 | #endif |
1457 | #endif |
1463 | } |
1458 | } |
1464 | break; |
1459 | break; |
1465 | |
1460 | |
1466 | case PropertyNotify: |
1461 | case PropertyNotify: |
… | |
… | |
1474 | selection_clear (); |
1469 | selection_clear (); |
1475 | break; |
1470 | break; |
1476 | |
1471 | |
1477 | case SelectionNotify: |
1472 | case SelectionNotify: |
1478 | if (selection_wait == Sel_normal) |
1473 | if (selection_wait == Sel_normal) |
1479 | selection_paste (ev.xselection.requestor, |
1474 | selection_paste (ev.xselection.requestor, ev.xselection.property, true); |
1480 | ev.xselection.property, True); |
|
|
1481 | break; |
1475 | break; |
1482 | |
1476 | |
1483 | case SelectionRequest: |
1477 | case SelectionRequest: |
1484 | selection_send (ev.xselectionrequest); |
1478 | selection_send (ev.xselectionrequest); |
1485 | break; |
1479 | break; |
… | |
… | |
1674 | case PropertyNotify: |
1668 | case PropertyNotify: |
1675 | /* |
1669 | /* |
1676 | * if user used some Esetroot compatible prog to set the root bg, |
1670 | * 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. |
1671 | * use the property to determine the pixmap. We use it later on. |
1678 | */ |
1672 | */ |
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]) |
1673 | if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] |
|
|
1674 | && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) |
1683 | return; |
1675 | return; |
1684 | |
1676 | |
1685 | /* FALLTHROUGH */ |
1677 | /* FALLTHROUGH */ |
1686 | case ReparentNotify: |
1678 | case ReparentNotify: |
1687 | if ((options & Opt_transparent) && check_our_parents () && am_transparent) |
1679 | if ((options & Opt_transparent) && check_our_parents () && am_transparent) |
… | |
… | |
2357 | /* |
2349 | /* |
2358 | * Make the frame window set by the window manager have |
2350 | * Make the frame window set by the window manager have |
2359 | * the root background. Some window managers put multiple nested frame |
2351 | * the root background. Some window managers put multiple nested frame |
2360 | * windows for each client, so we have to take care about that. |
2352 | * windows for each client, so we have to take care about that. |
2361 | */ |
2353 | */ |
2362 | i = (xa[XA_XROOTPMAPID] |
2354 | i = (xa[XA_XROOTPMAP_ID] |
2363 | && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], |
2355 | && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAP_ID], |
2364 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2356 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2365 | &nitems, &bytes_after, &prop) == Success); |
2357 | &nitems, &bytes_after, &prop) == Success); |
2366 | |
2358 | |
2367 | if (!i || prop == NULL) |
2359 | if (!i || prop == NULL) |
2368 | i = (xa[XA_XSETROOTID] |
2360 | i = (xa[XA_ESETROOT_PMAP_ID] |
2369 | && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], |
2361 | && XGetWindowProperty (display->display, display->root, xa[XA_ESETROOT_PMAP_ID], |
2370 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2362 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
2371 | &nitems, &bytes_after, &prop) == Success); |
2363 | &nitems, &bytes_after, &prop) == Success); |
2372 | |
2364 | |
2373 | if (!i || prop == NULL |
2365 | if (!i || prop == NULL |
2374 | #if TINTING |
2366 | #if TINTING |
… | |
… | |
2415 | sy = 0; |
2407 | sy = 0; |
2416 | } |
2408 | } |
2417 | |
2409 | |
2418 | MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); |
2410 | MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); |
2419 | MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); |
2411 | MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); |
|
|
2412 | |
|
|
2413 | XSync (display->display, False); |
2420 | allowedxerror = -1; |
2414 | allowedxerror = -1; |
2421 | image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); |
2415 | image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); |
2422 | |
2416 | |
2423 | /* XXX: handle BadMatch - usually because we're outside the pixmap */ |
2417 | /* XXX: handle BadMatch - usually because we're outside the pixmap */ |
2424 | /* XXX: may need a delay here? */ |
2418 | /* XXX: may need a delay here? */ |
… | |
… | |
2470 | |
2464 | |
2471 | am_transparent = am_pixmap_trans = 1; |
2465 | am_transparent = am_pixmap_trans = 1; |
2472 | } |
2466 | } |
2473 | } |
2467 | } |
2474 | |
2468 | |
2475 | if (!am_pixmap_trans) |
2469 | if (am_pixmap_trans) |
|
|
2470 | XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); |
|
|
2471 | else |
2476 | { |
2472 | { |
2477 | unsigned int n; |
2473 | unsigned int n; |
2478 | /* |
2474 | /* |
2479 | * InheritPixmap transparency |
2475 | * InheritPixmap transparency |
2480 | */ |
2476 | */ |
… | |
… | |
2543 | if (scrollBar.win) |
2539 | if (scrollBar.win) |
2544 | { |
2540 | { |
2545 | XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); |
2541 | XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); |
2546 | scrollBar.setIdle (); |
2542 | scrollBar.setIdle (); |
2547 | scrollbar_show (0); |
2543 | scrollbar_show (0); |
|
|
2544 | } |
|
|
2545 | |
|
|
2546 | if (am_transparent) |
|
|
2547 | { |
|
|
2548 | want_refresh = want_full_refresh = 1; |
|
|
2549 | if (am_pixmap_trans) |
|
|
2550 | flush (); |
2548 | } |
2551 | } |
2549 | |
2552 | |
2550 | return pchanged; |
2553 | return pchanged; |
2551 | } |
2554 | } |
2552 | #endif |
2555 | #endif |
… | |
… | |
3512 | * ends_how is terminator used. returned input must be free()'d |
3515 | * ends_how is terminator used. returned input must be free()'d |
3513 | */ |
3516 | */ |
3514 | unsigned char * |
3517 | unsigned char * |
3515 | rxvt_term::get_to_st (unicode_t &ends_how) |
3518 | rxvt_term::get_to_st (unicode_t &ends_how) |
3516 | { |
3519 | { |
3517 | unicode_t seen_esc = 0, ch; |
3520 | unicode_t ch; |
|
|
3521 | bool seen_esc = false; |
3518 | unsigned int n = 0; |
3522 | unsigned int n = 0; |
3519 | unsigned char *s; |
|
|
3520 | unsigned char string[STRING_MAX]; |
3523 | wchar_t string[STRING_MAX]; |
3521 | |
3524 | |
3522 | while ((ch = cmd_getc ()) != NOCHAR) |
3525 | while ((ch = cmd_getc ()) != NOCHAR) |
3523 | { |
3526 | { |
3524 | if (seen_esc) |
3527 | if (seen_esc) |
3525 | { |
3528 | { |
… | |
… | |
3528 | else |
3531 | else |
3529 | return NULL; |
3532 | return NULL; |
3530 | } |
3533 | } |
3531 | else if (ch == C0_ESC) |
3534 | else if (ch == C0_ESC) |
3532 | { |
3535 | { |
3533 | seen_esc = 1; |
3536 | seen_esc = true; |
3534 | continue; |
3537 | continue; |
3535 | } |
3538 | } |
3536 | else if (ch == C0_BEL || ch == CHAR_ST) |
3539 | else if (ch == C0_BEL || ch == CHAR_ST) |
3537 | break; |
3540 | break; |
3538 | else if (ch < 0x20) |
3541 | else if (ch < 0x20) |
3539 | return NULL; /* other control character - exit */ |
3542 | return NULL; /* other control character - exit */ |
3540 | |
3543 | |
3541 | seen_esc = 0; |
3544 | seen_esc = false; |
3542 | |
3545 | |
3543 | if (n >= sizeof (string) - 1) |
3546 | if (n >= sizeof (string) - 1) |
3544 | // stop at some sane length |
3547 | // stop at some sane length |
3545 | return NULL; |
3548 | return NULL; |
3546 | |
3549 | |
… | |
… | |
3550 | string[n++] = ch; |
3553 | string[n++] = ch; |
3551 | } |
3554 | } |
3552 | |
3555 | |
3553 | string[n++] = '\0'; |
3556 | string[n++] = '\0'; |
3554 | |
3557 | |
3555 | if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) |
|
|
3556 | return NULL; |
|
|
3557 | |
|
|
3558 | ends_how = (ch == 0x5c ? C0_ESC : ch); |
3558 | ends_how = (ch == 0x5c ? C0_ESC : ch); |
3559 | strncpy (s, string, n); |
3559 | |
3560 | return s; |
3560 | return (unsigned char *)rxvt_wcstombs (string); |
3561 | } |
3561 | } |
3562 | |
3562 | |
3563 | /*----------------------------------------------------------------------*/ |
3563 | /*----------------------------------------------------------------------*/ |
3564 | /* |
3564 | /* |
3565 | * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' |
3565 | * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' |
… | |
… | |
3666 | set_title (str); |
3666 | set_title (str); |
3667 | break; |
3667 | break; |
3668 | case XTerm_property: |
3668 | case XTerm_property: |
3669 | if (str[0] == '?') |
3669 | if (str[0] == '?') |
3670 | { |
3670 | { |
3671 | Atom prop = XInternAtom (display->display, str + 1, True); |
3671 | Atom prop = display->atom (str + 1); |
3672 | Atom actual_type; |
3672 | Atom actual_type; |
3673 | int actual_format; |
3673 | int actual_format; |
3674 | unsigned long nitems; |
3674 | unsigned long nitems; |
3675 | unsigned long bytes_after; |
3675 | unsigned long bytes_after; |
3676 | unsigned char *value = 0; |
3676 | unsigned char *value = 0; |
… | |
… | |
3694 | char *eq = strchr (str, '='); // constness lost, but verified to be ok |
3694 | char *eq = strchr (str, '='); // constness lost, but verified to be ok |
3695 | |
3695 | |
3696 | if (eq) |
3696 | if (eq) |
3697 | { |
3697 | { |
3698 | *eq = 0; |
3698 | *eq = 0; |
3699 | XChangeProperty (display->display, TermWin.parent[0], |
3699 | 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 | } |
3700 | } |
3704 | else |
3701 | else |
3705 | XDeleteProperty (display->display, TermWin.parent[0], |
3702 | XDeleteProperty (display->display, TermWin.parent[0], |
3706 | display->atom (str)); |
3703 | display->atom (str)); |
3707 | } |
3704 | } |
… | |
… | |
4284 | |
4281 | |
4285 | /* ---------------------------------------------------------------------- */ |
4282 | /* ---------------------------------------------------------------------- */ |
4286 | /* Write data to the pty as typed by the user, pasted with the mouse, |
4283 | /* 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. |
4284 | * or generated by us in response to a query ESC sequence. |
4288 | */ |
4285 | */ |
|
|
4286 | const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT |
|
|
4287 | |
4289 | void |
4288 | void |
4290 | rxvt_term::tt_write (const unsigned char *data, unsigned int len) |
4289 | rxvt_term::tt_write (const unsigned char *data, unsigned int len) |
4291 | { |
4290 | { |
4292 | const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT |
4291 | if (v_buflen == 0) |
|
|
4292 | { |
|
|
4293 | ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); |
4293 | |
4294 | |
4294 | if (len) |
4295 | if ((unsigned int)written == len) |
|
|
4296 | return; |
|
|
4297 | |
|
|
4298 | data += written; |
|
|
4299 | len -= written; |
4295 | { |
4300 | } |
|
|
4301 | |
|
|
4302 | v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); |
|
|
4303 | |
|
|
4304 | memcpy (v_buffer + v_buflen, data, len); |
|
|
4305 | v_buflen += len; |
|
|
4306 | |
|
|
4307 | pty_ev.set (EVENT_READ | EVENT_WRITE); |
|
|
4308 | } |
|
|
4309 | |
|
|
4310 | void rxvt_term::pty_write () |
|
|
4311 | { |
|
|
4312 | int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); |
|
|
4313 | |
|
|
4314 | if (written > 0) |
|
|
4315 | { |
|
|
4316 | v_buflen -= written; |
|
|
4317 | |
4296 | if (v_buflen == 0) |
4318 | if (v_buflen == 0) |
4297 | { |
4319 | { |
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); |
4320 | free (v_buffer); |
4325 | v_buffer = 0; |
4321 | v_buffer = 0; |
4326 | v_buflen = 0; |
4322 | v_buflen = 0; |
4327 | |
4323 | |
4328 | pty_ev.set (EVENT_READ); |
4324 | 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; |
4325 | return; |
4341 | } |
4326 | } |
|
|
4327 | |
|
|
4328 | memmove (v_buffer, v_buffer + written, v_buflen); |
4342 | } |
4329 | } |
|
|
4330 | else if (written != -1 || (errno != EAGAIN && errno != EINTR)) |
|
|
4331 | // original code just ignores this... |
|
|
4332 | destroy (); |
4343 | } |
4333 | } |
4344 | |
4334 | |
4345 | /*----------------------- end-of-file (C source) -----------------------*/ |
4335 | /*----------------------- end-of-file (C source) -----------------------*/ |
4346 | |
4336 | |