rust_minifb icon indicating copy to clipboard operation
rust_minifb copied to clipboard

Mouse coordinates are off in fullscreen, MacOS

Open ljdoig opened this issue 2 years ago • 2 comments

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

ljdoig avatar May 23 '23 05:05 ljdoig

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 avatar May 23 '23 06:05 emoon

This seems correct as I get the same behaviour with :

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

ljdoig avatar May 23 '23 06:05 ljdoig