window: fix wheel scrolling if NCURSES_MOUSE_VERSION > 1

This commit is contained in:
Andrzej Rybczak
2014-11-05 21:07:39 +01:00
parent 0f254b164e
commit 60749ea4bd
5 changed files with 24 additions and 16 deletions

1
NEWS
View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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