[BUG] Mouse coordinates wrong in windowed mode

Started by Evert B, April 14, 2011, 19:13:34

Previous topic - Next topic

Evert B

The mouse Y-coordinate appears to be off when retrieving it with Mouse.getEventY() in windowed mode, at least on Windows (XP). This seems to occur when the window is (slightly) higher than the screen resolution minus the height of the task bar. The problem can be reproduced with the code below. When you run this and click right below the top of the window you'll see the Y-coordinate is wrong (should be near 3000). It seems like it's limited somehow by the actual screen height minus that of the task bar.

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.PixelFormat;

public class App 
{
    public static void main( String[] args ) throws LWJGLException
    {
        Display.setTitle("MouseProb");
        Display.setFullscreen(false);

        Display.setDisplayMode(new DisplayMode(600, 3000));

        Display.setInitialBackground(0, 0, 0);
        PixelFormat pixelFormat = new PixelFormat(24, 8, 16, 0, 0); // bpp, alfa, dep, sten, fsaa
        Display.create(pixelFormat);

        for(;;)
        {
            // Draw stuff here

            Display.update(false);

            Display.sync(30);

            Display.processMessages();
            if(Display.isCloseRequested()) break;

            while(Mouse.next())
            {
                if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState())
                {
                    int x = Mouse.getEventX();
                    int y = Mouse.getEventY();

                    System.out.println("Mouse clicked at X=" + x + " Y=" + y);
                }
            }
        }
        
        Display.destroy();
    }
}


Matzon

On my windows 7 machine, the window created is: 616x1050

That is, 600 width as you specify + 2x8px border.

The height is cropped to 1050, since that is my max resolution. That 1050 is including a 30 px top border and a 8 px bottom border, which leaves 1012 px left.

The max value I can select is: 1037, meaning 1038 pixels is "selectable".

I am not sure why these values don't add up, but I can't see anything wrong in the LWJGL code. It seems to be the window manager in windows that does some magic.

I tried using org.lwjgl.opengl.Window.undecorated that allowed me to create a window with absolute size (ie. bigger than screen) and that gives back correct values.

kappa

Not too familiar with the Win API but some googling on this issue found this article.

Seems that there is a function that returns the client area (GetClientRect) and another which returns window area (GetWindowRect), a quick look at the native part of the LWJGL windows implementation shows that GetClientRect is used but didn't find any references to GetWindowRect, so might be that we need to incorporate that method somehow to calculate and compensate for title/border when running the Display in decorated windowed mode.

Evert B