--- rxvt-unicode/src/command.C 2003/12/18 02:07:12 1.18 +++ rxvt-unicode/src/command.C 2003/12/19 06:17:03 1.24 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.18 2003/12/18 02:07:12 pcg Exp $ + * $Id: command.C,v 1.24 2003/12/19 06:17:03 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -50,6 +50,8 @@ #include "version.h" #include "command.h" +#include + /*----------------------------------------------------------------------*/ /*{{{ Convert the keypress event into a string */ @@ -90,24 +92,36 @@ Status status_return; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, - KBUFSZ, &keysym, &status_return); -#else - wchar_t wkbuf[KBUFSZ + 1]; + if (R->enc_utf8 && 0) + len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, + KBUFSZ, &keysym, &status_return); + else +#endif + { + wchar_t wkbuf[KBUFSZ + 1]; - // assume wchar_t == unicode or better - len = XwcLookupString (R->Input_Context, ev, wkbuf, - KBUFSZ, &keysym, &status_return); + // the XOpenIM manpage lies about hardcoding the locale + // at the point of XOpenIM, so temporarily switch locales + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->rs[Rs_imLocale]); + // assume wchar_t == unicode or better + len = XwcLookupString (R->Input_Context, ev, wkbuf, + KBUFSZ, &keysym, &status_return); + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->locale); - if (status_return == XLookupChars - || status_return == XLookupBoth) - { - wkbuf[len] = 0; - len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (status_return == XLookupChars + || status_return == XLookupBoth) + { + wkbuf[len] = 0; + len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (len < 0) + len = 0; + } + else + len = 0; } - else - len = 0; -#endif + valid_keysym = status_return == XLookupKeySym || status_return == XLookupBoth; } @@ -623,7 +637,7 @@ fprintf(stderr, "'\n"); } #endif /* DEBUG_CMD */ - R->tt_write(kbuf, (unsigned int)len); + R->tt_write (kbuf, (unsigned int)len); } /*}}} */ @@ -667,15 +681,15 @@ if (want_full_refresh) { want_full_refresh = 0; - rxvt_scr_clear (this); - rxvt_scr_touch (this, False); + scr_clear (); + scr_touch (false); want_refresh = 1; } #endif if (want_refresh) { - rxvt_scr_refresh (this, refresh_type); + scr_refresh (refresh_type); rxvt_scrollbar_show (this, 1); #ifdef USE_XIM rxvt_IMSendSpot (this); @@ -683,16 +697,13 @@ } XFlush (Xdisplay); -#if 0 - if (XPending (Xdisplay)) process_x_events (); - if (XPending (Xdisplay)) process_x_events (); -#endif } void rxvt_term::check_cb (check_watcher &w) { SET_R (this); + SET_LOCALE (locale); flush (); } @@ -746,8 +757,6 @@ void rxvt_term::blink_cb (time_watcher &w) { - SET_R (this); - w.at += BLINK_INTERVAL; hidden_cursor = !hidden_cursor; want_refresh = 1; @@ -757,6 +766,7 @@ rxvt_term::x_cb (io_watcher &w, short revents) { SET_R (this); + SET_LOCALE (locale); process_x_events (); } @@ -787,6 +797,7 @@ rxvt_term::pty_cb (io_watcher &w, short revents) { SET_R (this); + SET_LOCALE (locale); if (revents & EVENT_WRITE) tt_write (0, 0); @@ -874,7 +885,7 @@ if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) refresh_limit++; - rxvt_scr_refresh (this, refresh_type); + scr_refresh (refresh_type); } } @@ -904,51 +915,23 @@ uint32_t rxvt_term::next_char () { - struct mbstate &s = mbstate; - while (cmdbuf_ptr < cmdbuf_endp) { - uint8_t ch = *cmdbuf_ptr; - - if (s.cnt) - { - if ((ch & 0xc0) == 0x80) - { - cmdbuf_ptr++; + if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh + return *cmdbuf_ptr++; - /* continuation */ - s.reg = (s.reg << 6) | (ch & 0x7f); + wchar_t wc; + int len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, &mbstate.mbs); - if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */ - return s.reg; + if (len == (size_t)-2) + return NOCHAR; - continue; - } - else - { - s.cnt = 0; - return s.orig; /* the _occasional_ non-utf-8 character may slip through... */ - } - } - - if ((ch & 0xc0) == 0xc0) - { - cmdbuf_ptr++; + if (len == (size_t)-1) + return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through - /* first byte */ - s.orig = ch; /* for broken encodings */ - s.reg = ch; - if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; } - if ((ch & 0xf0) == 0xe0) { s.reg &= 0x0f; s.cnt = 2; } - if ((ch & 0xf8) == 0xf0) { s.reg &= 0x07; s.cnt = 3; } - if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; } - if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; } - } - else - { - cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ - return ch; - } + // assume wchar == unicode + cmdbuf_ptr += len; + return wc; } return NOCHAR; @@ -1010,7 +993,7 @@ if (!R->scroll_selection_delay-- && rxvt_scr_page(aR_ R->scroll_selection_dir, R->scroll_selection_lines)) { - rxvt_selection_extend(aR_ R->selection_save_x, + R->selection_extend (R->selection_save_x, R->selection_save_y, R->selection_save_state); R->scroll_selection_delay = SCROLLBAR_CONTINUOUS_DELAY; R->refresh_type |= SMOOTH_REFRESH; @@ -1040,7 +1023,7 @@ rxvt_term::pointer_unblank () { XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor); - rxvt_recolour_cursor (this); + recolour_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; @@ -1069,6 +1052,7 @@ rxvt_term::pointer_cb (time_watcher &w) { SET_R (this); + SET_LOCALE (locale); pointer_blank (); } @@ -1083,7 +1067,7 @@ x = ev->x; y = ev->y; - rxvt_pixel_position(aR_ &x, &y); + R->pixel_position (&x, &y); if (R->MEvent.button == AnyButton) { button_number = 3; @@ -1344,8 +1328,7 @@ ConfigureNotify, ev)); if (R->szHint.width != width || R->szHint.height != height) { D_SIZE((stderr, "Size: Resizing from: %4d x %4d", R->szHint.width, R->szHint.height)); - rxvt_resize_all_windows(aR_ (unsigned int)width, - (unsigned int)height, 1); + R->resize_all_windows (width, height, 1); } #ifdef DEBUG_SIZE else { @@ -1414,12 +1397,12 @@ case Expose: if (ev->xany.window == R->TermWin.vt) { #ifdef NO_SLOW_LINK_SUPPORT - rxvt_scr_expose(aR_ ev->xexpose.x, ev->xexpose.y, - ev->xexpose.width, ev->xexpose.height, False); + R->scr_expose (ev->xexpose.x, ev->xexpose.y, + ev->xexpose.width, ev->xexpose.height, False); #else // don't understand this, so commented it out - rxvt_scr_expose(aR_ ev->xexpose.x, ev->xexpose.y, - ev->xexpose.width, ev->xexpose.height, False); + R->scr_expose (ev->xexpose.x, ev->xexpose.y, + ev->xexpose.width, ev->xexpose.height, False); //rxvt_scr_expose(aR_ ev->xexpose.x, 0, // ev->xexpose.width, R->TermWin.height, False); #endif @@ -1434,7 +1417,7 @@ GraphicsExpose, &unused_xevent)) ; if (isScrollbarWindow(ev->xany.window)) { - scrollbar_setIdle(); + R->scrollBar.setIdle(); rxvt_scrollbar_show(aR_ 0); } #ifdef MENUBAR @@ -1474,7 +1457,7 @@ /* deal with a `jumpy' mouse */ if ((ev->xmotion.time - R->MEvent.time) > MOUSE_THRESHOLD) { #endif - rxvt_selection_extend(aR_ (ev->xbutton.x), (ev->xbutton.y), + R->selection_extend ((ev->xbutton.x), (ev->xbutton.y), (ev->xbutton.state & Button3Mask) ? 2 : 0); #ifdef SELECTION_SCROLLING if (ev->xbutton.yTermWin.int_bwidth || @@ -1533,7 +1516,7 @@ &unused_mask); rxvt_scr_move_to(aR_ scrollbar_position(ev->xbutton.y) - R->csrO, scrollbar_size()); - rxvt_scr_refresh(aR_ R->refresh_type); + R->scr_refresh (R->refresh_type); R->refresh_limit = 0; rxvt_scrollbar_show(aR_ 1); } @@ -1602,19 +1585,32 @@ switch (ev->button) { case Button1: - if (R->MEvent.button == Button1 && clickintime) - R->MEvent.clicks++; + /* allow shift+left click to extend selection */ + if (ev->state & ShiftMask) + { + if (R->MEvent.button == Button1 && clickintime) + R->selection_rotate (ev->x, ev->y); + else + R->selection_extend (ev->x, ev->y, 1); + } else - R->MEvent.clicks = 1; - rxvt_selection_click(aR_ R->MEvent.clicks, ev->x, ev->y); + { + if (R->MEvent.button == Button1 && clickintime) + R->MEvent.clicks++; + else + R->MEvent.clicks = 1; + + R->selection_click (R->MEvent.clicks, ev->x, ev->y); + } + R->MEvent.button = Button1; break; case Button3: if (R->MEvent.button == Button3 && clickintime) - rxvt_selection_rotate(aR_ ev->x, ev->y); + R->selection_rotate (ev->x, ev->y); else - rxvt_selection_extend(aR_ ev->x, ev->y, 1); + R->selection_extend (ev->x, ev->y, 1); R->MEvent.button = Button3; break; } @@ -1629,7 +1625,7 @@ */ if (isScrollbarWindow(ev->window)) { - scrollbar_setIdle(); + R->scrollBar.setIdle (); /* * Rxvt-style scrollbar: * move up if mouse is above slider @@ -1692,9 +1688,9 @@ #endif if (rxvt_scr_page(aR_ upordown < 0 ? UP : DN, 1)) { if (upordown < 0) - scrollbar_setUp(); + R->scrollBar.setUp (); else - scrollbar_setDn(); + R->scrollBar.setDn (); } } else switch (ev->button) { @@ -1716,7 +1712,7 @@ rxvt_scr_move_to(aR_ scrollbar_position(ev->y) - R->csrO, scrollbar_size()); - scrollbar_setMotion(); + R->scrollBar.setMotion (); break; case Button1: @@ -1739,7 +1735,7 @@ rxvt_scr_page(aR_ DN, R->TermWin.nrow / 4); # endif else - scrollbar_setMotion(); + R->scrollBar.setMotion (); } else { rxvt_scr_page(aR_ (ev->button == Button1 ? DN : UP), (R->TermWin.nrow @@ -1771,7 +1767,7 @@ reportmode = !!(R->PrivateModes & PrivMode_mouse_report); if (scrollbar_isUpDn()) { - scrollbar_setIdle(); + R->scrollBar.setIdle (); rxvt_scrollbar_show(aR_ 0); #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING R->refresh_type &= ~SMOOTH_REFRESH; @@ -1818,7 +1814,7 @@ if (R->PrivateModes & PrivMode_mouse_report && R->bypass_keystate && ev->button == Button1 && R->MEvent.clicks <= 1) - rxvt_selection_extend(aR_ ev->x, ev->y, 0); + R->selection_extend (ev->x, ev->y, 0); switch (ev->button) { case Button1: @@ -1851,13 +1847,13 @@ # endif # ifdef JUMP_MOUSE_WHEEL rxvt_scr_page(aR_ v, i); - rxvt_scr_refresh(aR_ SMOOTH_REFRESH); + R->scr_refresh (SMOOTH_REFRESH); rxvt_scrollbar_show(aR_ 1); # else - for (; i--;) + while (i--) { rxvt_scr_page(aR_ v, 1); - rxvt_scr_refresh(aR_ SMOOTH_REFRESH); + R->scr_refresh (SMOOTH_REFRESH); rxvt_scrollbar_show(aR_ 1); } # endif @@ -2221,7 +2217,7 @@ rxvt_scr_index(aR_ DN); break; case 'J': /* erase to end of screen */ - rxvt_scr_erase_screen(aR_ 0); + R->scr_erase_screen (0); break; case 'K': /* erase to end of line */ rxvt_scr_erase_line(aR_ 0); @@ -2566,7 +2562,7 @@ break; case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */ - rxvt_scr_erase_screen(aR_ arg[0]); + R->scr_erase_screen (arg[0]); break; case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */ @@ -2746,7 +2742,7 @@ XLowerWindow(R->Xdisplay, R->TermWin.parent[0]); break; case 7: /* refresh window */ - rxvt_scr_touch(aR_ True); + R->scr_touch (true); break; case 8: /* set size (chars) */ rxvt_set_widthheight(aR_ (unsigned int)(args[2] * R->TermWin.fwidth), @@ -2967,7 +2963,7 @@ rxvt_scale_pixmap(aR_ ""); /* reset to default scaling */ rxvt_set_bgPixmap(aR_ str); /* change pixmap */ #endif - rxvt_scr_touch(aR_ True); + R->scr_touch (true); } while ((str = STRCHR(str, ';')) != NULL) { str++; @@ -2979,7 +2975,7 @@ #ifdef XPM_BACKGROUND rxvt_resize_pixmap(aR); #endif - rxvt_scr_touch(aR_ True); + R->scr_touch (true); } break; @@ -3155,8 +3151,8 @@ #ifdef scrollBar_esc case scrollBar_esc: if (rxvt_scrollbar_mapping(aR_ state)) { - rxvt_resize_all_windows(aR_ 0, 0, 0); - rxvt_scr_touch(aR_ True); + R->resize_all_windows (0, 0, 0); + R->scr_touch (true); } break; #endif @@ -3192,7 +3188,7 @@ break; case 1047: /* secondary screen w/ clearing */ if (R->current_screen != PRIMARY) - rxvt_scr_erase_screen(aR_ 2); + R->scr_erase_screen (2); rxvt_scr_change_screen(aR_ state); /* FALLTHROUGH */ default: