Mouse coordinates are off in fullscreen, MacOS
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:
Non fullscreen (regardless of scale mode, aspect ratio or size)
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
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.
This seems correct as I get the same behaviour with :
WindowOptions {
title: false,
..WindowOptions::default()
}