--- rxvt-unicode/src/scrollbar.C 2008/02/17 11:37:21 1.52 +++ rxvt-unicode/src/scrollbar.C 2008/02/18 11:42:23 1.58 @@ -63,48 +63,12 @@ rxvt_term::resize_scrollbar () { int delayed_init = 0; + int window_sb_x = 0; -#define R_SCROLLBEG_XTERM 0 -#define R_SCROLLEND_XTERM szHint.height -#define R_SCROLLBEG_NEXT 0 -#define R_SCROLLEND_NEXT szHint.height - (SB_BUTTON_TOTAL_HEIGHT + \ - SB_PADDING) -#define R_SCROLLBEG_RXVT (scrollBar.width + 1) + scrollBar.shadow -#define R_SCROLLEND_RXVT szHint.height - R_SCROLLBEG_RXVT - \ - (2 * scrollBar.shadow) + if (option (Opt_scrollBar_right)) + window_sb_x = szHint.width - scrollBar.total_width (); -#if defined(PLAIN_SCROLLBAR) - if (scrollBar.style == R_SB_PLAIN) - { - scrollBar.beg = R_SCROLLBEG_XTERM; - scrollBar.end = R_SCROLLEND_XTERM; - scrollBar.update = &rxvt_term::scrollbar_show_plain; - } -#endif -#if defined(XTERM_SCROLLBAR) - if (scrollBar.style == R_SB_XTERM) - { - scrollBar.beg = R_SCROLLBEG_XTERM; - scrollBar.end = R_SCROLLEND_XTERM; - scrollBar.update = &rxvt_term::scrollbar_show_xterm; - } -#endif -#if defined(NEXT_SCROLLBAR) - if (scrollBar.style == R_SB_NEXT) - { - scrollBar.beg = R_SCROLLBEG_NEXT; - scrollBar.end = R_SCROLLEND_NEXT; - scrollBar.update = &rxvt_term::scrollbar_show_next; - } -#endif -#if defined(RXVT_SCROLLBAR) - if (scrollBar.style == R_SB_RXVT) - { - scrollBar.beg = R_SCROLLBEG_RXVT; - scrollBar.end = R_SCROLLEND_RXVT; - scrollBar.update = &rxvt_term::scrollbar_show_rxvt; - } -#endif + scrollBar.update_data (); if (!scrollBar.win) { @@ -127,6 +91,10 @@ delayed_init = 1; } + else + XMoveResizeWindow (dpy, scrollBar.win, + window_sb_x, 0, + scrollBar.total_width (), szHint.height); scrollbar_show (1); @@ -138,24 +106,22 @@ * Update current scrollbar view w.r.t. slider heights, etc. */ int -rxvt_term::scrollbar_show (int update) +rxvt_term::scrollbar_show (int refresh) { int ret = 0; - int top, bot, len, adj; if (!scrollBar.state) return 0; - if (update) + if (refresh) { - top = view_start - top_row; - bot = top + (nrow - 1); - len = max (nrow - 1 - top_row, 1); - adj = (((bot - top) * scrollbar_size ()) % len) > 0 ? 1 : 0; - - scrollBar.top = (scrollBar.beg + (top * scrollbar_size ()) / len); - scrollBar.len = ((bot - top) * scrollbar_size ()) / len + - scrollbar_minheight () + adj; + int sb_top = view_start - top_row; + int sb_bot = sb_top + (nrow - 1); + int sb_len = max (nrow - 1 - top_row, 1); + int sb_size = (sb_bot - sb_top) * scrollBar.size (); + + scrollBar.top = (scrollBar.beg + (sb_top * scrollBar.size ()) / sb_len); + scrollBar.len = sb_size / sb_len + scrollBar.min_height () + (sb_size % sb_len > 0); scrollBar.bot = (scrollBar.top + scrollBar.len); /* no change */ if (scrollBar.top == scrollBar.last_top @@ -165,7 +131,7 @@ return 0; } - ret = (this->*scrollBar.update) (update, scrollBar.last_top, scrollBar.last_bot, scrollBar.len); + ret = (this->*scrollBar.update) (refresh, scrollBar.last_top, scrollBar.last_bot, scrollBar.len); scrollBar.last_top = scrollBar.top; scrollBar.last_bot = scrollBar.bot; @@ -250,5 +216,42 @@ leftptr_cursor = XCreateFontCursor (term->dpy, XC_left_ptr); } +void +scrollBar_t::update_data () +{ +#if defined(PLAIN_SCROLLBAR) + if (style == R_SB_PLAIN) + { + beg = 0; + end = term->szHint.height; + update = &rxvt_term::scrollbar_show_plain; + } +#endif +#if defined(XTERM_SCROLLBAR) + if (style == R_SB_XTERM) + { + beg = 0; + end = term->szHint.height; + update = &rxvt_term::scrollbar_show_xterm; + } +#endif +#if defined(NEXT_SCROLLBAR) + if (style == R_SB_NEXT) + { + beg = 0; + end = term->szHint.height - (SB_BUTTON_TOTAL_HEIGHT + SB_PADDING); + update = &rxvt_term::scrollbar_show_next; + } +#endif +#if defined(RXVT_SCROLLBAR) + if (style == R_SB_RXVT) + { + beg = (width + 1) + shadow; + end = term->szHint.height - beg - (2 * shadow); + update = &rxvt_term::scrollbar_show_rxvt; + } +#endif +} + /*----------------------- end-of-file (C source) -----------------------*/