With ncurses 6.6, mouseinterval(0) causes getmouse errors in Termux,
as shown by the following example:

#include <curses.h>
#include <stdio.h>

int main()
{
  initscr();
  cbreak();
  noecho();

  // Enables keypad mode. This makes (at least for me) mouse events getting
  // reported as KEY_MOUSE, instead as of random letters.
  keypad(stdscr, TRUE);

  // See https://github.com/termux/termux-packages/issues/28372
  mouseinterval(0);

  // Don't mask any mouse events
  mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);

  printf("\033[?1003h\n"); // Makes the terminal report mouse movement events

  for (;;) {
    int c = wgetch(stdscr);

    // Exit the program on new line fed
    if (c == '\n')
      break;

    char buffer[512];
    size_t max_size = sizeof(buffer);
    if (c == ERR) {
      snprintf(buffer, max_size, "Nothing happened.");
    }
    else if (c == KEY_MOUSE) {
      MEVENT event;
      if (getmouse(&event) == OK) {
        snprintf(buffer, max_size, "Mouse at row=%d, column=%d bstate=0x%08lx",
                 event.y, event.x, (unsigned long) event.bstate);
      }
      else {
        snprintf(buffer, max_size, "Got bad mouse event.");
      }
    }
    else {
      snprintf(buffer, max_size, "Pressed key %d (%s)", c, keyname(c));
    }

    move(0, 0);
    insertln();
    addstr(buffer);
    clrtoeol();
    move(0, 0);
  }

  printf("\033[?1003l\n"); // Disable mouse movement events, as l = low

  endwin();

  return 0;
}

This is the program from

  https://gist.github.com/sylt/93d3f7b77e7f3a881603

where "mouseinterval(0);" has been added as instructed at

  https://github.com/termux/termux-packages/issues/28372

To reproduce the error, run this program directly in the Termux
terminal (no ssh), and tap (click) several times on the screen.
In my case, a "Got bad mouse event." message appears at the 7th
time (periodically). Note: make sure that they correspond to
clicks, i.e. do not generate mouse movements (the problem still
seems to be reproducible if there are mouse movements between
the clicks, though).

In the above termux-packages issue, Robert Kirkman bisected it to

  
https://github.com/ThomasDickey/ncurses-snapshots/commit/04b97b07ab93bac2ba9ab92a2c3776ddae75bfaa#r169954711

There is a mention of a problem in htop

  https://github.com/htop-dev/htop/issues/1769

due to this commit, but I cannot reproduce it, even though I get
"Got bad mouse event." messages with the above test program.

-- 
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)

Reply via email to