Skip to content

Commit afed5c0

Browse files
committed
ncurses-style getmouse() (a.k.a. nc_getmouse()) fix to return an event once.
In ncurses, getmouse() delivers events from a queue, returning OK if there was an event on the queue, ERR if not. PDCursesMod (and PDCurses) return OK. (Reported by Robin Haberkorn as issue #357.) This patch causes getmouse() to deliver events from a queue of one event. ncurses queues up to eight events, and I hope to do something similar eventually. But this at least fixes the immediate problem, and may be part of the eventual solution.
1 parent d0f0324 commit afed5c0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

pdcurses/mouse.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ bool mouse_trafo(int *y, int *x, bool to_screen)
297297
#define BUTTON_MOVE_EVENTS (BUTTON1_MOVED | BUTTON2_MOVED | BUTTON3_MOVED \
298298
| BUTTON4_MOVED | BUTTON5_MOVED)
299299
#define ALL_MOVE_EVENTS (BUTTON_MOVE_EVENTS | REPORT_MOUSE_POSITION)
300+
#define NO_MOUSE_EVENT -42
300301

301302
mmask_t mousemask(mmask_t mask, mmask_t *oldmask)
302303
{
@@ -317,6 +318,7 @@ mmask_t mousemask(mmask_t mask, mmask_t *oldmask)
317318
#endif
318319

319320
mouse_set(mask);
321+
SP->mouse_status.x = NO_MOUSE_EVENT;
320322

321323
return SP->_trap_mbe;
322324
}
@@ -341,12 +343,13 @@ int nc_getmouse(MEVENT *event)
341343

342344
assert( SP);
343345
assert( event);
344-
if (!event || !SP)
346+
if (!event || !SP || SP->mouse_status.x == NO_MOUSE_EVENT)
345347
return ERR;
346348

347349
ungot = FALSE;
348350

349351
request_mouse_pos();
352+
SP->mouse_status.x = NO_MOUSE_EVENT;
350353

351354
event->id = 0;
352355

0 commit comments

Comments
 (0)