Merge pull request #68 from slint-ui/simon/macos-scale-on-setbuffer
mac: Fix layer scale not being updated when contents is updated and window is on a new screen
This commit is contained in:
commit
787958b2a6
2 changed files with 20 additions and 3 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
# UNRELEASED
|
||||||
|
|
||||||
|
* On MacOS, the contents scale is updated when set_buffer() is called, to adapt when the window is on a new screen.
|
||||||
|
|
||||||
# 0.2.0
|
# 0.2.0
|
||||||
|
|
||||||
* Add support for Redox/Orbital.
|
* Add support for Redox/Orbital.
|
||||||
|
|
|
||||||
19
src/cg.rs
19
src/cg.rs
|
|
@ -16,25 +16,26 @@ use std::sync::Arc;
|
||||||
|
|
||||||
pub struct CGImpl {
|
pub struct CGImpl {
|
||||||
layer: CALayer,
|
layer: CALayer,
|
||||||
|
window: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CGImpl {
|
impl CGImpl {
|
||||||
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError> {
|
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError> {
|
||||||
let window = handle.ns_window as id;
|
let window = handle.ns_window as id;
|
||||||
|
let window: id = msg_send![window, retain];
|
||||||
let view = handle.ns_view as id;
|
let view = handle.ns_view as id;
|
||||||
let layer = CALayer::new();
|
let layer = CALayer::new();
|
||||||
unsafe {
|
unsafe {
|
||||||
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
|
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
|
||||||
layer.set_contents_gravity(ContentsGravity::TopLeft);
|
layer.set_contents_gravity(ContentsGravity::TopLeft);
|
||||||
layer.set_needs_display_on_bounds_change(false);
|
layer.set_needs_display_on_bounds_change(false);
|
||||||
layer.set_contents_scale(window.backingScaleFactor());
|
|
||||||
subview.setLayer(layer.id());
|
subview.setLayer(layer.id());
|
||||||
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
|
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
|
||||||
|
|
||||||
view.addSubview_(subview); // retains subview (+1) = 2
|
view.addSubview_(subview); // retains subview (+1) = 2
|
||||||
let _: () = msg_send![subview, release]; // releases subview (-1) = 1
|
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) {
|
pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
|
||||||
|
|
@ -62,8 +63,20 @@ impl CGImpl {
|
||||||
transaction::begin();
|
transaction::begin();
|
||||||
transaction::set_disable_actions(true);
|
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();
|
transaction::commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for CGImpl {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
let _: () = msg_send![self.window, release];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue