]> git.deb.at Git - pkg/abook.git/commitdiff
Scroll whole list on mouse wheel action
authorThorsten Wißmann <edu@thorsten-wissmann.de>
Sat, 12 May 2012 14:07:50 +0000 (16:07 +0200)
committerRaphaël Droz <raphael.droz+floss@gmail.com>
Thu, 18 Apr 2013 14:52:50 +0000 (16:52 +0200)
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.

abookrc.5
list.c
list.h
options.c
options.h
ui.c

index db382e668a6ffcb21794cead31428765410ce0ca..ba12c7c7786edabf5e9336596405e2610d8dd669 100644 (file)
--- 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 ca4892baea2e4f7bd495b225c0649c14f3052ac6..735746733777f07c854c438c3e929f1739b69000 100644 (file)
--- 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 0cc31137916c461bf92ef0bc4b3a2c755e0bca5c..35befc5aa632f219662872e6743caf3c68935b12 100644 (file)
--- 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();
index 2c1303c5b3e5baacee895709a13bc2b4a87496eb..6f75a06db368f215c85f6731b3415222badb2a41 100644 (file)
--- 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" },
index d2cc8c0b73b49e7e778395707bfb2716faa182c6..78515a9f2d6ae5beafcd951cc9a4f3bf006e2b31 100644 (file)
--- 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 158f2ed1f586552732c81ff3186b656d79ace4ed..4efcf85e1a3cde7ee45626a325e367c8c9300465 100644 (file)
--- 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();
                                }
                        }
                }