From 35a182d79edb4dd1643141b8bfe6030a3483adfc Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 11 Nov 2009 00:31:03 +0100 Subject: [PATCH] add support for scrolling the list with mouse wheel by given number of lines --- doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/menu.h | 9 +++++++++ src/screen.h | 12 ++++++++++-- src/settings.cpp | 5 +++++ src/settings.h | 1 + 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/config b/doc/config index 9eb40bb8..7f6d72fb 100644 --- a/doc/config +++ b/doc/config @@ -284,6 +284,8 @@ # #mouse_support = "yes" # +#mouse_list_scroll_whole_page = "yes" +# #empty_tag_marker = "" # #enable_window_title = "yes" diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 5a37b0e2..c4907d63 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -153,6 +153,9 @@ If enabled, content of other columns will be updated immediately while scrolling .B cyclic_scrolling = yes/no If enabled, cyclic scrolling is used (e.g. if you press down arrow being at the end of list, it'll take you to the beginning) .TP +.B mouse_list_scroll_whole_page = yes/no +If enabled, mouse wheel will scroll the whole page of item list at a time, otherwise the number of lines specified by lines_scrolled variable. +.TP .B lines_scrolled = NUMBER Number of lines that are scrolled with mouse wheel. .TP diff --git a/src/menu.h b/src/menu.h index 41bf56d7..3bfd031a 100644 --- a/src/menu.h +++ b/src/menu.h @@ -52,6 +52,15 @@ namespace NCurses /// virtual void GetSelected(std::vector &v) const = 0; + /// Highlights given position + /// @param pos position to be highlighted + /// + virtual void Highlight(size_t pos) = 0; + + /// @return currently highlighted position + /// + virtual size_t Choice() const = 0; + /// @see Menu::Empty() /// virtual bool Empty() const = 0; diff --git a/src/screen.h b/src/screen.h index 31481c0a..b123f011 100644 --- a/src/screen.h +++ b/src/screen.h @@ -239,13 +239,21 @@ template void Screen::Scroll(Where where, cons template void Screen::MouseButtonPressed(MEVENT me) { + List *list = Config.mouse_list_scroll_whole_page ? 0 : dynamic_cast(w); + if (me.bstate & BUTTON2_PRESSED) { - Scroll(wPageDown); + if (list) + list->Highlight(list->Choice()+Config.lines_scrolled); + else + Scroll(wPageDown); } else if (me.bstate & BUTTON4_PRESSED) { - Scroll(wPageUp); + if (list) + list->Highlight(list->Choice() > Config.lines_scrolled ? list->Choice()-Config.lines_scrolled : 0); + else + Scroll(wPageUp); } } diff --git a/src/settings.cpp b/src/settings.cpp index 8e757bd3..b2d6a39a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -315,6 +315,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.allow_physical_directories_deletion = false; conf.ask_before_clearing_main_playlist = false; conf.mouse_support = true; + conf.mouse_list_scroll_whole_page = true; conf.new_design = false; conf.visualizer_use_wave = true; conf.browser_sort_by_mtime = false; @@ -839,6 +840,10 @@ void ReadConfiguration(ncmpcpp_config &conf) { conf.mouse_support = v == "yes"; } + else if (cl.find("mouse_list_scroll_whole_page") != std::string::npos) + { + conf.mouse_list_scroll_whole_page = v == "yes"; + } else if (cl.find("user_interface") != std::string::npos) { conf.new_design = v == "alternative"; diff --git a/src/settings.h b/src/settings.h index 01951d9c..89aa48dd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -208,6 +208,7 @@ struct ncmpcpp_config bool allow_physical_directories_deletion; bool ask_before_clearing_main_playlist; bool mouse_support; + bool mouse_list_scroll_whole_page; bool new_design; bool visualizer_use_wave; bool browser_sort_by_mtime;