Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Ncurses mouse wheel scroll up





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


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;


  switch(in = getch())
     case KEY_MOUSE:
         if(getmouse(&event) == OK)
           else if (event.bstate & BUTTON4_PRESSED)
           else if (event.bstate & BUTTON2_PRESSED || event.bstate == 0x8000000)
like image 738
Zild Avatar asked Feb 14 '23 09:02


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


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