Set contents scale and drawable size when creating status metal layer

This commit is contained in:
Antonio Scandurra 2022-09-13 12:08:56 +02:00
parent 2acd215bb8
commit a9c2881831
2 changed files with 16 additions and 9 deletions

View File

@ -187,15 +187,11 @@ impl Renderer {
pub fn render(&mut self, scene: &Scene) {
let layer = self.layer.clone();
let drawable_size = layer.drawable_size();
let drawable = layer.next_drawable().unwrap();
let command_queue = self.command_queue.clone();
let command_buffer = command_queue.new_command_buffer();
let frame: NSRect = unsafe { msg_send![self.layer(), frame] };
let scale_factor: CGFloat = unsafe { msg_send![self.layer(), contentsScale] };
let drawable_size =
vec2f(frame.size.width as f32, frame.size.height as f32) * scale_factor as f32;
self.sprite_cache.set_scale_factor(scene.scale_factor());
self.image_cache.set_scale_factor(scene.scale_factor());
@ -206,7 +202,7 @@ impl Renderer {
scene,
path_sprites,
&mut offset,
drawable_size,
vec2f(drawable_size.width as f32, drawable_size.height as f32),
command_buffer,
drawable.texture(),
);

View File

@ -1,7 +1,7 @@
use crate::{
geometry::vector::{vec2f, Vector2F},
platform::{self, mac::renderer::Renderer},
Event, FontSystem, Scene,
Event, FontSystem, Scene, Window,
};
use cocoa::{
appkit::{
@ -75,7 +75,7 @@ impl StatusItem {
button.setWantsBestResolutionOpenGLSurface_(YES);
button.setLayer(renderer.layer().as_ptr() as id);
Self(Rc::new_cyclic(|state| {
let item = Self(Rc::new_cyclic(|state| {
let event_handler = StrongPtr::new(msg_send![HANDLER_CLASS, alloc]);
let _: () = msg_send![*event_handler, init];
(**event_handler)
@ -90,7 +90,18 @@ impl StatusItem {
event_callback: None,
_event_handler: event_handler,
})
}))
}));
{
let item = item.0.borrow();
let layer = item.renderer.layer();
let scale_factor = item.scale_factor();
let size = item.size() * scale_factor;
layer.set_contents_scale(scale_factor.into());
layer.set_drawable_size(metal::CGSize::new(size.x().into(), size.y().into()));
}
item
}
}
}