From 60749ea4bd83f991c1c967f25b8410ac9aeacf71 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 5 Nov 2014 21:07:39 +0100 Subject: [PATCH] window: fix wheel scrolling if NCURSES_MOUSE_VERSION > 1 --- NEWS | 1 + src/actions.cpp | 16 ++++++++++------ src/actions.h | 6 +++++- src/screen.cpp | 4 ++-- src/window.h | 13 ++++++------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 79a15928..fe5e9af2 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ncmpcpp-0.6.1 (????-??-??) * Comment tag is now properly written to mp3 files. * Only ID3v2.4 tags are now saved to mp3 files. +* Mouse scrolling with newer ncurses API now works properly. ncmpcpp-0.6 (2014-10-25) diff --git a/src/actions.cpp b/src/actions.cpp index 270d52f7..a1c9c678 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -318,15 +318,19 @@ void MouseEvent::run() m_old_mouse_event = m_mouse_event; getmouse(&m_mouse_event); + +# if NCURSES_MOUSE_VERSION == 1 // workaround shitty ncurses behavior introduced in >=5.8, when we mysteriously get // a few times after ncmpcpp startup 2^27 code instead of BUTTON{1,3}_RELEASED. since that // 2^27 thing shows constantly instead of BUTTON2_PRESSED, it was redefined to be recognized - // as BUTTON2_PRESSED. but clearly we don't want to trigger behavior bound to BUTTON2 + // as BUTTON5_PRESSED. but clearly we don't want to trigger behavior bound to BUTTON5 // after BUTTON{1,3} was pressed. so, here is the workaround: if last event was BUTTON{1,3}_PRESSED, - // we MUST get BUTTON{1,3}_RELEASED afterwards. if we get BUTTON2_PRESSED, erroneus behavior + // we MUST get BUTTON{1,3}_RELEASED afterwards. if we get BUTTON5_PRESSED, erroneus behavior // is about to occur and we need to prevent that. - if (m_old_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED) && m_mouse_event.bstate & BUTTON2_PRESSED) + if (m_old_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED) && m_mouse_event.bstate & BUTTON5_PRESSED) return; +# endif // NCURSES_MOUSE_VERSION == 1 + if (m_mouse_event.bstate & BUTTON1_PRESSED && m_mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1) ) // progressbar @@ -345,17 +349,17 @@ void MouseEvent::run() { Mpd.Toggle(); } - else if ((m_mouse_event.bstate & BUTTON2_PRESSED || m_mouse_event.bstate & BUTTON4_PRESSED) + else if ((m_mouse_event.bstate & BUTTON5_PRESSED || m_mouse_event.bstate & BUTTON4_PRESSED) && (Config.header_visibility || Config.design == Design::Alternative) && m_mouse_event.y == 0 && size_t(m_mouse_event.x) > COLS-VolumeState.length() ) // volume { - if (m_mouse_event.bstate & BUTTON2_PRESSED) + if (m_mouse_event.bstate & BUTTON5_PRESSED) get(Type::VolumeDown).execute(); else get(Type::VolumeUp).execute(); } - else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED)) + else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED)) myScreen->mouseButtonPressed(m_mouse_event); } diff --git a/src/actions.h b/src/actions.h index d828c2eb..b6437a43 100644 --- a/src/actions.h +++ b/src/actions.h @@ -122,7 +122,11 @@ protected: struct MouseEvent : public BaseAction { - MouseEvent() : BaseAction(Type::MouseEvent, "mouse_event") { } + MouseEvent() : BaseAction(Type::MouseEvent, "mouse_event") + { + m_old_mouse_event.bstate = 0; + m_mouse_event.bstate = 0; + } protected: virtual bool canBeRun() const; diff --git a/src/screen.cpp b/src/screen.cpp index 36c82930..f370d9e8 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -38,7 +38,7 @@ void drawSeparator(int x) void genericMouseButtonPressed(NC::Window &w, MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) + if (me.bstate & BUTTON5_PRESSED) { if (Config.mouse_list_scroll_whole_page) w.scroll(NC::Scroll::PageDown); @@ -58,7 +58,7 @@ void genericMouseButtonPressed(NC::Window &w, MEVENT me) void scrollpadMouseButtonPressed(NC::Scrollpad &w, MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) + if (me.bstate & BUTTON5_PRESSED) { for (size_t i = 0; i < Config.lines_scrolled; ++i) w.scroll(NC::Scroll::Down); diff --git a/src/window.h b/src/window.h index b769e16f..7f751056 100644 --- a/src/window.h +++ b/src/window.h @@ -95,13 +95,12 @@ // undefine scroll macro as it collides with Window::scroll #undef scroll -#ifndef USE_PDCURSES -// NOTICE: redefine BUTTON2_PRESSED as it doesn't always work, I noticed -// that it sometimes returns 134217728 (2^27) instead of expected mask, so the -// modified define does it right but is rather experimental. -# undef BUTTON2_PRESSED -# define BUTTON2_PRESSED (NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED) | (1U << 27)) -#endif // USE_PDCURSES +#if !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1 +// NOTICE: define BUTTON5_PRESSED to be BUTTON2_PRESSED with additional mask +// (I noticed that it sometimes returns 134217728 (2^27) instead of expected +// mask, so the modified define does it right. +# define BUTTON5_PRESSED (BUTTON2_PRESSED | (1U << 27)) +#endif // !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1 // workaraund for win32 #ifdef WIN32