Skip to content

Commit 2832a6e

Browse files
committed
mac: Fix layer scale not being updated when contents is updated and window is on a new screen
cc #67
1 parent 33a4c37 commit 2832a6e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/cg.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::sync::Arc;
1616

1717
pub struct CGImpl {
1818
layer: CALayer,
19+
window: id,
1920
}
2021

2122
impl CGImpl {
@@ -27,14 +28,13 @@ impl CGImpl {
2728
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
2829
layer.set_contents_gravity(ContentsGravity::TopLeft);
2930
layer.set_needs_display_on_bounds_change(false);
30-
layer.set_contents_scale(window.backingScaleFactor());
3131
subview.setLayer(layer.id());
3232
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
3333

3434
view.addSubview_(subview); // retains subview (+1) = 2
3535
let _: () = msg_send![subview, release]; // releases subview (-1) = 1
3636
}
37-
Ok(Self { layer })
37+
Ok(Self { layer, window })
3838
}
3939

4040
pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
@@ -62,7 +62,11 @@ impl CGImpl {
6262
transaction::begin();
6363
transaction::set_disable_actions(true);
6464

65-
unsafe { self.layer.set_contents(image.as_ptr() as id) };
65+
unsafe {
66+
self.layer
67+
.set_contents_scale(self.window.backingScaleFactor());
68+
self.layer.set_contents(image.as_ptr() as id);
69+
};
6670

6771
transaction::commit();
6872
}

0 commit comments

Comments
 (0)