2
votes

I want to handle scroll with the mouse wheel using ncurses but I am having a problem similar to this issue :

http://lists.gnu.org/archive/html/bug-ncurses/2012-01/msg00011.html

Besides, mouse wheel-up event is only reported as mask 02000000
(BUTTON4_PRESSED) just one time, even if I scroll the wheel continuously.

I tried ncurses 5.7 to 5.9 on debian 5,6,7 and archlinux. Every single ncurses lib had NCURSES_MOUSE_VERSION 1, tried recompiling with --enable-ext-mouse.

Scrolling down works perfectly, ncurses reports multiple REPORT_MOUSE_POSITION 0x8000000 per scroll and a single BUTTON2_PRESSED 0x128.

Scrolling up causes only a single report of BUTTON4_PRESSED 0x80000

MEVENT event;

mousemask(BUTTON1_CLICKED|BUTTON4_PRESSED|BUTTON2_PRESSED, NULL); // Tried with REPORT_MOUSE_POSITION also

while(run)
{
  switch(in = getch())
  {
     case KEY_MOUSE:
         if(getmouse(&event) == OK)
         { 
           else if (event.bstate & BUTTON4_PRESSED)
             line_up();
           else if (event.bstate & BUTTON2_PRESSED || event.bstate == 0x8000000)
             line_down();
         }
         break;
   }
 }
2
If you try xev, wheel up is button 4 and wheel down is button 4, so wheel down is not working properly. Scrolling does not change the mouse position. On Debian, (mouse version 1) I get multiple button 4 pressed events scrolling up and multiple report mouse position events scrolling downparkydr
I will watch xev, activating terminal report showed multiple events in both cases, but inside ncurses context I can say that only a single button4 is reported when scrolling up, I am using readline aswell could that be an issue?Zild

2 Answers

4
votes

Add mouseinterval(0); somewhere outside of your main loop. (Perhaps right after keypad(stdscr, TRUE);)

This command causes there to be no delay with mouse events, so you won't be able to detect BUTTON1_CLICKED or BUTTON1_DOUBLE_CLICKED and similar things (though you can implement that yourself by keeping track of BUTTON1_PRESSED, BUTTON1_RELEASED, and the time between mouse events).

A small caveat though, when I tested this with C everything worked, except that getmouse returned ERR on scroll wheel down events. This could potentially still be useful though, as it was the only event which gave this result. When I tested the same code in Rust it worked perfectly though, so your mileage may vary.

4
votes

ncurses5 does not support wheel mouse, except as an optional feature. That is because the layout of bits in mousemask_t chose in the mid-1990s left insufficient space for a fifth mouse-button. At the time, some other devices (for playing games) seemed more important; this was before X provided a protocol for wheel mice.

The "extended mouse" is an optional feature (since it would change the application binary interface), and has not been incorporated in ncurses5 packages, although it has been available for some time.

For reference, see the discussion of --enable-ext-mouse in the ncurses changelog, starting in 2005.

ncurses6 does support wheel mouse (see release notes). Perhaps that will be standard in Debian 9.