From b7144fff6c8ab013addd3f0c7b17babe62925bc2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 5 Apr 2015 18:43:27 +0100 Subject: [PATCH] Make ncurses wheel scroll button configurable --- src/ncurses_ui.cc | 19 +++++++++++++++++-- src/ncurses_ui.hh | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 7d94d08c1..628ccd8ba 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -453,11 +453,14 @@ Key NCursesUI::get_key() MEVENT ev; if (getmouse(&ev) == OK) { + auto wheel_down_mask = NCURSES_MOUSE_MASK(m_wheel_down_button, NCURSES_BUTTON_PRESSED); + auto wheel_up_mask = NCURSES_MOUSE_MASK(m_wheel_up_button, NCURSES_BUTTON_PRESSED); + CharCoord pos{ ev.y, ev.x }; if ((ev.bstate & BUTTON1_PRESSED) == BUTTON1_PRESSED) return mouse_press(pos); if ((ev.bstate & BUTTON1_RELEASED) == BUTTON1_RELEASED) return mouse_release(pos); - if ((ev.bstate & BUTTON2_PRESSED) == BUTTON2_PRESSED) return mouse_wheel_down(pos); - if ((ev.bstate & BUTTON4_PRESSED) == BUTTON4_PRESSED) return mouse_wheel_up(pos); + if ((ev.bstate & wheel_down_mask) == wheel_down_mask) return mouse_wheel_down(pos); + if ((ev.bstate & wheel_up_mask) == wheel_up_mask) return mouse_wheel_up(pos); else return mouse_pos(pos); } } @@ -880,6 +883,18 @@ void NCursesUI::set_ui_options(const Options& options) if (it != options.end()) m_status_on_top = it->second == "yes" or it->second == "true"; } + + { + auto wheel_down_it = options.find("ncurses_wheel_down_button"); + if (wheel_down_it != options.end()) try { + m_wheel_down_button = str_to_int(wheel_down_it->second);; + } catch(...) {} + + auto wheel_up_it = options.find("ncurses_wheel_up_button"); + if (wheel_up_it != options.end()) try { + m_wheel_up_button = str_to_int(wheel_up_it->second);; + } catch(...) {} + } } } diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 411cab584..2f992d2ea 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -75,6 +75,9 @@ private: bool m_status_on_top = false; ConstArrayView m_assistant; + int m_wheel_down_button = 2; + int m_wheel_up_button = 4; + bool m_dirty = false; };