PDCurses
PDCurses copied to clipboard
Unable to get mouse position when hovering
Althought I'm able to get an MEVENT
when clicking or scrolling (on a windows terminal), I'm unable when just hovering\moving my mouse around, any idea why? wgetch
doesn't return anything... and it baffles me a while now... I've looked into the source code but i couldn't figure out if i did something wrong or there is any issue
PDC_MOUSE_POSITION
and MOUSE_POS_REPORT
don't actually do anything. Both are #defined in curses.h
and never used after that; pay no attention to them. Use MOUSE_MOVED
and PDC_MOUSE_MOVED
.
You also have to set the REPORT_MOUSE_POSITION
flag in mousemask()
.
It may also be worth trying the SDL1 or SDL2 platform. I have a vague memory that mouse movements were not supported in WinCon unless you had a button pressed (an issue that apparently neither I nor William was able to work around). If your program works on SDL2 but not with WinCon, that'd be a significant clue.
@Bill-Gray
I have a vague memory that mouse movements were not supported in WinCon unless you had a button pressed
Exactly!
It may also be worth trying the SDL1 or SDL2 platform ...
I tried SDL, same thing... but! finally I found where the issue is and made a fix:
for (i = 0; i < 3; i++)
{
if (old_mouse_status.button[i] != SP->mouse_status.button[i])
SP->mouse_status.changes |= (1 << i);
/* Discard non-moved "moves" */
if (SP->mouse_status.x == old_mouse_status.x &&
SP->mouse_status.y == old_mouse_status.y)
continue;
/* Motion events always flag the button as changed */
SP->mouse_status.changes |= (1 << i);
SP->mouse_status.changes |= PDC_MOUSE_MOVED;
SP->mouse_status.button[i] = BUTTON_MOVED; // <--- to report same value as ncurses when hovering
break;
}
So... from what i understand: It appears that the buttons are never set to the BUTTON_MOVED
state, and so they never pass the condition of SP->mouse_status.button[i] == BUTTON_MOVED
[...] + return -1;
ignores the rest of the code afterwords
Regarding this fix, although everything appears to work fine, when using the mousemask(...)
function with the ALL_MOUSE_EVENTS
flag, it includes hover events without requiring the REPORT_MOUSE_POSITION
flag. In contrast, in ncurses, if you don't pass REPORT_MOUSE_POSITION
and hover around, getmouse()
returns -1
which I'm not 100% sure how to solve yet ([I guess it's not that much of a big deal but] I might dive deep into the source later), any idea?
(Here's the minimal example I used to test both pdcurses and ncurses)
⚠️ Update
I was wrong about the fix
Ok, a condition like if !(SP->_trap_mbe &=REPORT_MOUSE_POSITION){return -1;}
should work (althought I am a bit unaware of what might be the effect on the rest of the code...), lets seeee....
Ah... the fix, actually doesn't work us expected... and without SP->mouse_status.button[i] = BUTTON_MOVED;
it reports 0x00000001
when it should report 0x00000000
If i won't change the code besides this line to if (action == BUTTON_MOVED)
it works, BUT it shouldn't report 0x00000001
, it should report 0x00000000
and this baffles me
Another Failed (but closer to the solution) fix
for (i = 0; i < 3; i++)
{
if (old_mouse_status.button[i] != SP->mouse_status.button[i])
SP->mouse_status.changes |= (1 << i);
if (action == BUTTON_MOVED)
{
/* Discard non-moved "moves" */
if (SP->mouse_status.x == old_mouse_status.x &&
SP->mouse_status.y == old_mouse_status.y)
return -1;
/* Motion events always flag the button as changed */
SP->mouse_status.changes |= (1 << i);
SP->mouse_status.changes |= PDC_MOUSE_MOVED;
SP->mouse_status.button[i] = BUTTON_MOVED;
break;
}
}
Now the issue with this is, is that whenever i move the mouse and right click, it adds a release too or something
Anyways, I'm out for now, I need to do other things... something wrong with this and\or this. (button_mask
?)
the faild fix 2 in gif