From: Thorsten Wißmann Date: Sat, 12 May 2012 14:07:50 +0000 (+0200) Subject: Scroll whole list on mouse wheel action X-Git-Tag: upstream/0.6.1~2^2~19 X-Git-Url: https://git.deb.at/w?p=pkg%2Fabook.git;a=commitdiff_plain;h=775cf2c4526dce9048361498197a3522d648f74c Scroll whole list on mouse wheel action This lets the whole list scroll on mouse action (button 5 and 6) instead of just moving the selection. This also adds the scroll_speed option that sets the number of lines the list is scrolled by. --- diff --git a/abookrc.5 b/abookrc.5 index db382e6..ba12c7c 100644 --- a/abookrc.5 +++ b/abookrc.5 @@ -150,6 +150,11 @@ Defines if the cursor is visible in main display. Default is false. \fBuse_mouse\fP=[true|false] Defines if navigation via the mouse is activated. Default is false. Most terminals can also inhibit ncurses mouse events at runtime by holding the Shift key (restoring mouse-selection behavior). +.TP +\fBscroll_speed\fP=lines +Defines the number of lines the adress list is scrolled by on a mouse wheel +action. This option only takes effect if use_mouse is enabled. Default is 2. + .TP \fBuse_colors\fP=[true|false] Defines if the output of abook is colorized. Default is false. diff --git a/list.c b/list.c index ca4892b..7357467 100644 --- a/list.c +++ b/list.c @@ -24,6 +24,7 @@ int curitem = -1; int first_list_item = -1; +int scroll_speed = 2; char *selected = NULL; extern abook_field_list *fields_list; @@ -130,6 +131,7 @@ init_list() { list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); scrollok(list, TRUE); + scroll_speed = abs(opt_get_int(INT_SCROLL_SPEED)); } void @@ -352,6 +354,39 @@ scroll_down() refresh_list(); } +void +scroll_list_up() +{ + if(first_list_item <= 0) + return; + + first_list_item -= scroll_speed; + if(first_list_item < 0) { + first_list_item = 0; + } + if(curitem > LAST_LIST_ITEM) { + curitem = LAST_LIST_ITEM; + } + + refresh_list(); +} + +void +scroll_list_down() +{ + if(first_list_item > db_n_items() - 2) + return; + + first_list_item += scroll_speed; + if(first_list_item >= db_n_items()) { + first_list_item = db_n_items() - 1; + } + if(curitem < first_list_item) { + curitem = first_list_item; + } + + refresh_list(); +} void page_up() diff --git a/list.h b/list.h index 0cc3113..35befc5 100644 --- a/list.h +++ b/list.h @@ -34,6 +34,8 @@ void get_list_field(int item, struct index_elem *e, struct list_field *res); void list_headerline(); void scroll_up(); void scroll_down(); +void scroll_list_up(); +void scroll_list_down(); void page_up(); void page_down(); void select_none(); diff --git a/options.c b/options.c index 2c1303c..6f75a06 100644 --- a/options.c +++ b/options.c @@ -68,6 +68,7 @@ static struct option abook_vars[] = { { "sort_field", OT_STR, STR_SORT_FIELD, UL "nick" }, { "show_cursor", OT_BOOL, BOOL_SHOW_CURSOR, FALSE }, { "use_mouse", OT_BOOL, BOOL_USE_MOUSE, FALSE }, + { "scroll_speed", OT_INT, INT_SCROLL_SPEED, UL 2 }, { "use_colors", OT_BOOL, BOOL_USE_COLORS, FALSE }, { "color_header_fg", OT_STR, STR_COLOR_HEADER_FG, UL "blue" }, { "color_header_fg", OT_STR, STR_COLOR_HEADER_FG, UL "blue" }, diff --git a/options.h b/options.h index d2cc8c0..78515a9 100644 --- a/options.h +++ b/options.h @@ -38,6 +38,7 @@ enum bool_opts { enum int_opts { INT_EMAILPOS, INT_EXTRAPOS, + INT_SCROLL_SPEED, INT_MAXIMUM /* INT_MAX conflicts on some systems */ }; diff --git a/ui.c b/ui.c index 158f2ed..4efcf85 100644 --- a/ui.c +++ b/ui.c @@ -556,9 +556,9 @@ get_commands() refresh_list(); } } else if(event.bstate & BUTTON4_PRESSED) { - scroll_up(); + scroll_list_up(); } else if(event.bstate & BUTTON5_PRESSED) { - scroll_down(); + scroll_list_down(); } } }