0

I tried to write code to use mouse movement and mouse wheel rotation. it turns out mouse dragging and wheel rotation produce exactly the same events - REPORT_MOUSE_POSITION(8000000)- and I cannot tell one from the other. Anything I'm missing?

    MEVENT e;
    mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
    while ( (c = getch()) != 27 ){   // 27 = ESC
        if (c == KEY_MOUSE){
            if (getmouse(&e) == OK){
                // e.bstate produces 8000000 for both wheel and mouse movement
Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
Nathan
  • 21
  • 2

1 Answers1

0

By convention, wheel mouse events are seen as button 4 and 5. The "all-events" flag includes that. If you use instead a combination of the flags for the buttons you are interested in, you will get the result you want.

The manual page lists the available flags (which you can also see in the ncurses.h header file), but there's no equivalent predefined symbol for all-events for just one button.

By the way, in ncurses5 (ncurses6 was released in August 2015), you cannot detect button 5 due to the way the bits were allocated. In the header file, this section is relevant to your question, because button 5 would have used the same section of the mask as the report-mouse-position:

/*                                                                              
 * In 32 bits the version-1 scheme does not provide enough space for a 5th      
 * button, unless we choose to change the ABI by omitting the reserved-events.  
 */                                                                             
#if NCURSES_MOUSE_VERSION > 1                                                   

#define BUTTON5_RELEASED        NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_RELEASED)  
#define BUTTON5_PRESSED         NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_PRESSED)   
#define BUTTON5_CLICKED         NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_CLICKED)   
#define BUTTON5_DOUBLE_CLICKED  NCURSES_MOUSE_MASK(5, NCURSES_DOUBLE_CLICKED)   
#define BUTTON5_TRIPLE_CLICKED  NCURSES_MOUSE_MASK(5, NCURSES_TRIPLE_CLICKED)   

#define BUTTON_CTRL             NCURSES_MOUSE_MASK(6, 0001L)                    
#define BUTTON_SHIFT            NCURSES_MOUSE_MASK(6, 0002L)                    
#define BUTTON_ALT              NCURSES_MOUSE_MASK(6, 0004L)                    
#define REPORT_MOUSE_POSITION   NCURSES_MOUSE_MASK(6, 0010L)                    

#else                                                                           

#define BUTTON1_RESERVED_EVENT  NCURSES_MOUSE_MASK(1, NCURSES_RESERVED_EVENT)   
#define BUTTON2_RESERVED_EVENT  NCURSES_MOUSE_MASK(2, NCURSES_RESERVED_EVENT)   
#define BUTTON3_RESERVED_EVENT  NCURSES_MOUSE_MASK(3, NCURSES_RESERVED_EVENT)   
#define BUTTON4_RESERVED_EVENT  NCURSES_MOUSE_MASK(4, NCURSES_RESERVED_EVENT)   

#define BUTTON_CTRL             NCURSES_MOUSE_MASK(5, 0001L)                    
#define BUTTON_SHIFT            NCURSES_MOUSE_MASK(5, 0002L)                    
#define BUTTON_ALT              NCURSES_MOUSE_MASK(5, 0004L)                    
#define REPORT_MOUSE_POSITION   NCURSES_MOUSE_MASK(5, 0010L)                    

#endif  

You'll get button 4 with ncurses5, but button 5 falls through the cracks (you may see some events from it, but there's no way to tell that it's button 5). The masks were set up before anyone had wheel mice to discuss (late 1995).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • I am using ncurses 5, so am I not supposed to get BUTTON4 event? I only get REPORT_MOUSE_POSITION event. – Nathan Dec 03 '17 at 05:21