From f08bf446705c74cd05c4345e4f22e77cd0adf9ba Mon Sep 17 00:00:00 2001 From: Joe Moon Date: Tue, 10 Apr 2018 18:42:22 -0700 Subject: [PATCH] [macOS] implement HiDPIFactorChanged event on relevant events: (#443) * moving window to another screen * changing resolution of screen --- CHANGELOG.md | 1 + src/platform/macos/window.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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:),