From 2832a6e42b1911f3bbf3a132c3448a364c020be7 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Sun, 15 Jan 2023 09:09:12 +0100 Subject: [PATCH] mac: Fix layer scale not being updated when contents is updated and window is on a new screen cc #67 --- src/cg.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cg.rs b/src/cg.rs index 2910372..1309a43 100644 --- a/src/cg.rs +++ b/src/cg.rs @@ -16,6 +16,7 @@ use std::sync::Arc; pub struct CGImpl { layer: CALayer, + window: id, } impl CGImpl { @@ -27,14 +28,13 @@ impl CGImpl { let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view)); layer.set_contents_gravity(ContentsGravity::TopLeft); layer.set_needs_display_on_bounds_change(false); - layer.set_contents_scale(window.backingScaleFactor()); subview.setLayer(layer.id()); subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable); view.addSubview_(subview); // retains subview (+1) = 2 let _: () = msg_send![subview, release]; // releases subview (-1) = 1 } - Ok(Self { layer }) + Ok(Self { layer, window }) } pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) { @@ -62,7 +62,11 @@ impl CGImpl { transaction::begin(); transaction::set_disable_actions(true); - unsafe { self.layer.set_contents(image.as_ptr() as id) }; + unsafe { + self.layer + .set_contents_scale(self.window.backingScaleFactor()); + self.layer.set_contents(image.as_ptr() as id); + }; transaction::commit(); }