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

Mouse coordinates are off in fullscreen, MacOS #319

Open
ljdoig opened this issue May 23, 2023 · 2 comments
Open

Mouse coordinates are off in fullscreen, MacOS #319

ljdoig opened this issue May 23, 2023 · 2 comments
Assignees
Labels

Comments

@ljdoig
Copy link

ljdoig commented May 23, 2023

It seems the mouse coordinates are off when you go into fullscreen mode on macOS (Ventura 13.1). It gets it right for any resized window and for any scale_mode, except when I go fullscreen the mouse is not where it thinks. This doesn't seem to affect Windows users.

Fullscreen:
fullscreen

Non fullscreen (regardless of scale mode, aspect ratio or size)
small2
small

code:

use minifb::*;

fn main() {
    let mut window = Window::new(
        "Fullscreen",
        800,
        500,
        WindowOptions {
            resize: true,
            scale_mode: ScaleMode::Center,
            ..WindowOptions::default()
        },
    )
    .unwrap();
    while window.is_open() && !window.is_key_down(Key::Escape) {
        assert_eq!(
            window.get_mouse_pos(MouseMode::Discard),
            window.get_unscaled_mouse_pos(MouseMode::Discard)
        );
        let (width, height) = window.get_size();
        let mut pixels = vec![0x00000000; width * height];
        // Paint the row and col of pixels that the mouse is hovering over
        window
            .get_mouse_pos(MouseMode::Discard)
            .map(|(mouse_x, mouse_y)| {
                for mouse_x in 0..width {
                    pixels[mouse_x as usize + mouse_y as usize * width] = 0x00FFFFFF;
                }
                for mouse_y in 0..height {
                    pixels[mouse_x as usize + mouse_y as usize * width] = 0x00FFFFFF;
                }
            });
        window.update_with_buffer(&pixels, width, height).unwrap();
    }
}

On a possibly unrelated note, should this work after resizing?

assert_eq!(
            window.get_mouse_pos(MouseMode::Discard),
            window.get_unscaled_mouse_pos(MouseMode::Discard)
        );

Thanks for your time

@emoon
Copy link
Owner

emoon commented May 23, 2023

Thanks for the report. My guess is that minifb needs to detect when the application enters fullscreen as I think it currently always includes the size of the titlebar currently.

@emoon emoon self-assigned this May 23, 2023
@emoon emoon added the macOS label May 23, 2023
@ljdoig
Copy link
Author

ljdoig commented May 23, 2023

This seems correct as I get the same behaviour with :

        WindowOptions {
            title: false,
            ..WindowOptions::default()
        }

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

No branches or pull requests

2 participants