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

Portable window example error #321

Closed
Filipp-Druan opened this issue Aug 7, 2023 · 8 comments
Closed

Portable window example error #321

Filipp-Druan opened this issue Aug 7, 2023 · 8 comments

Comments

@Filipp-Druan
Copy link

When I run the portable window example and try to drag the window, it start to twitching and flay away from under cursor.
I would by happy to add a gif record, but I can't.

@raysan5
Copy link
Owner

raysan5 commented Aug 7, 2023

@Filipp-Druan It seems a platform-dependant issue, it works as expected on Windows and Linux with X-Window system, afaik.

What platform are you trying it?

@Filipp-Druan
Copy link
Author

Manjaro Linux XFCE.

@raysan5
Copy link
Owner

raysan5 commented Aug 7, 2023

Manjaro Linux XFCE.

I'm afraid this issue could be related to XFCE desktop environment. There is not much I can do.

@raysan5 raysan5 closed this as completed Aug 29, 2023
@AnasASK
Copy link

AnasASK commented Sep 7, 2023

I noticed the same issue in Pop!_OS Gnome. So it is not only related to xfce.

@Lecrapouille
Copy link

Lecrapouille commented Oct 9, 2023

I noticed the same issue with Debian 11, running with XFCE. I'll check at the code.
Quick investigation: not an OS issue (reproduced on LXDE, Enlightment) !

portable_window.c:

        if (dragWindow)
        {
            windowPosition.x += (mousePosition.x - panOffset.x);
            windowPosition.y += (mousePosition.y - panOffset.y);

           // I added this
            printf("mousePosition: %f, %f. panOffset: %f, %f ==> windowPosition: %f, %f\n",
              mousePosition.x, mousePosition.y, panOffset.x, panOffset.y,
              windowPosition.x, windowPosition.y);

Just clicking on the windows and make a light move, will make the windows sliding while the mouse is pressed:

mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 714.000000, 310.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 716.000000, 311.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 718.000000, 312.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 720.000000, 313.000000
mousePosition: 195.000000, 7.000000. panOffset: 193.000000, 6.000000 ==> windowPosition: 722.000000, 314.000000

I tried to investigate on windowPosition += mousePosition - panOffset:

  • when not gradding the windows the mouse position, relative to windows top-let border is never negative since when outside the windows, glfw callbacks for refreshing the mouse position are never called. You can add a printf() inside the main loop: it will stop printing. But when grabbed, I can see negative values. Weird!
  • the += does not seem good, shall be = because 1/ panOffset is never modified and 2/ mousePosition is used to displace the windows, so windowPosition will increase.

My attempt:

    Vector2 w;

    while (!exitWindow && !WindowShouldClose())    // Detect window close button or ESC key
    {
        mousePosition = GetMousePosition();
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !dragWindow)
        {
            if (CheckCollisionPointRec(mousePosition, (Rectangle){ 0, 0, screenWidth, 20 }))
            {
                dragWindow = true;
                panOffset = mousePosition;
                w = GetWindowPosition();
            }
        }

        if (dragWindow)
        {
            windowPosition.x = w.x + (mousePosition.x - panOffset.x);
            windowPosition.y = w.y + (mousePosition.y - panOffset.y);
            SetWindowPosition((int)windowPosition.x, (int)windowPosition.y);
            if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) dragWindow = false;
        }

The sliding effect is gone but flickering effect is present since the windows seems moving slower than the mouse which finally escape. I guess this issue comes from the mouse position is "reseted" when the windows has moved because relative and never < 0. @raysan5 I think the are some remaining issues on the mouse management.

@raysan5
Copy link
Owner

raysan5 commented Oct 10, 2023

@Lecrapouille If the problem is on mouse, why does is work as expected on Windows?

@Lecrapouille
Copy link

@raysan5 I should try on Windows, but I'm noob with Windows. I do not know why on Windows it works, it should not work. When I tried to make my 1st example, I got issue with scrolling the list widget (I forget the name) it was the single widget I add: the scroll was also erratic (while with your example full of widget the scroll worked).

@jepe-ryhe
Copy link

Hi @raysan5 , I meet the same issue.
After some investigation, I found that when the window position is updated in raylib, the mouse position does not get updated accordingly.
I made this change and it works good on my computer with glfw:

static void WindowPosCallback(GLFWwindow* window, int x, int y)
{
    // Set current window position
    CORE.Window.position.x = x;
    CORE.Window.position.y = y;
    double mouseX, mouseY;
    glfwGetCursorPos(window, &mouseX, &mouseY);
    MouseCursorPosCallback(window, mouseX, mouseY);
}

Is this the intended behavior? Perhaps we need a mechanism to ensure the mouse position is updated.

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

5 participants