Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ncurses mouse wheel scroll up

Tags:

c

linux

ncurses

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;
   }
 }
like image 738
Zild Avatar asked Feb 14 '23 09:02

Zild


2 Answers

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.

like image 61
Thormme Avatar answered Feb 23 '23 11:02

Thormme


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.

like image 20
Thomas Dickey Avatar answered Feb 23 '23 09:02

Thomas Dickey