diff --git a/CHANGELOG.md b/CHANGELOG.md index 435f0614..a6311072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Overhauled X11 window geometry calculations. `get_position` and `set_position` are more universally accurate across different window managers, and `get_outer_size` actually works now. - Fixed SIGSEGV/SIGILL crashes on macOS caused by stabilization of the `!` (never) type. +- Implement `WindowEvent::HiDPIFactorChanged` for macOS # Version 0.12.0 (2018-04-06) diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index 9ade104b..2d6f31ae 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -95,6 +95,17 @@ impl WindowDelegate { let state: *mut c_void = *this.get_ivar("winitState"); let state = &mut *(state as *mut DelegateState); emit_resize_event(state); + let scale_factor = NSWindow::backingScaleFactor(*state.window) as f32; + emit_event(state, WindowEvent::HiDPIFactorChanged(scale_factor)); + } + } + + extern fn window_did_change_backing_properties(this: &Object, _:Sel, _:id) { + unsafe { + let state: *mut c_void = *this.get_ivar("winitState"); + let state = &mut *(state as *mut DelegateState); + let scale_factor = NSWindow::backingScaleFactor(*state.window) as f32; + emit_event(state, WindowEvent::HiDPIFactorChanged(scale_factor)); } } @@ -198,7 +209,8 @@ impl WindowDelegate { window_did_resize as extern fn(&Object, Sel, id)); decl.add_method(sel!(windowDidChangeScreen:), window_did_change_screen as extern fn(&Object, Sel, id)); - + decl.add_method(sel!(windowDidChangeBackingProperties:), + window_did_change_backing_properties as extern fn(&Object, Sel, id)); decl.add_method(sel!(windowDidBecomeKey:), window_did_become_key as extern fn(&Object, Sel, id)); decl.add_method(sel!(windowDidResignKey:),