Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get mouse position when hovering #154

Open
GiorgosXou opened this issue Sep 28, 2023 · 9 comments
Open

Unable to get mouse position when hovering #154

GiorgosXou opened this issue Sep 28, 2023 · 9 comments

Comments

@GiorgosXou
Copy link
Contributor

GiorgosXou commented Sep 28, 2023

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

@GiorgosXou GiorgosXou changed the title Unable to get live mouse position Unable to get mouse position when hovering Sep 28, 2023
@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Sep 28, 2023

@Bill-Gray
Copy link
Contributor

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.

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 3, 2023

@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

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 4, 2023

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....

@GiorgosXou
Copy link
Contributor Author

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

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 4, 2023

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

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 4, 2023

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

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 4, 2023

Anyways, I'm out for now, I need to do other things... something wrong with this and\or this. (button_mask?)

@GiorgosXou
Copy link
Contributor Author

GiorgosXou commented Oct 4, 2023

the faild fix 2 in gif
PDCURSESMOUSEHOVERissue0 gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants