Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ objc2-app-kit = { version = "0.3", default-features = false, features = [
objc2-quartz-core = { version = "0.3", default-features = false, features = [
"std",
"CALayer",
"CATransaction",
"objc2-core-foundation",
] }
objc2-core-foundation = { version = "0.3", default-features = false, features = [
Expand Down
27 changes: 19 additions & 8 deletions src-tauri/src/native_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use objc2_core_graphics::{
CGBitmapInfo, CGColorRenderingIntent, CGColorSpace, CGDataProvider, CGImage, CGImageAlphaInfo,
};
use objc2_foundation::{MainThreadMarker, NSString};
use objc2_quartz_core::{kCAGravityCenter, CALayer};
use objc2_quartz_core::{kCAGravityCenter, CALayer, CATransaction};
use tauri::{AppHandle, Runtime};

mod frames {
Expand Down Expand Up @@ -129,15 +129,15 @@ pub fn init() -> Result<(), &'static str> {
let base_y = ((bh - icon_pt) / 2.0).max(0.0);

let anim_layer = unsafe { CALayer::new() };
unsafe {
without_implicit_layer_actions(|| unsafe {
anim_layer.setFrame(CGRect::new(
CGPoint::new(ICON_X_OFFSET, base_y),
CGSize::new(icon_pt, icon_pt),
));
anim_layer.setContentsScale(2.0 as CGFloat);
anim_layer.setContentsGravity(kCAGravityCenter);
button_layer.insertSublayer_atIndex(&anim_layer, 0);
}
});

let frames_cat = pre_decode(ANIM_CAT2_LEN, anim_cat2_rgba);
let frames_parrot = pre_decode(ANIM_PARROT_LEN, anim_parrot_rgba);
Expand Down Expand Up @@ -250,10 +250,12 @@ pub fn set_y_offset<R: Runtime>(app: &AppHandle<R>, dy: f64) {
};
let _ = app.run_on_main_thread(move || unsafe {
let layer = &*(state.anim_layer_ptr as *const CALayer);
layer.setFrame(CGRect::new(
CGPoint::new(state.base_x, state.base_y + dy as CGFloat),
CGSize::new(state.icon_pt, state.icon_pt),
));
without_implicit_layer_actions(|| {
layer.setFrame(CGRect::new(
CGPoint::new(state.base_x, state.base_y + dy as CGFloat),
CGSize::new(state.icon_pt, state.icon_pt),
));
});
});
}

Expand Down Expand Up @@ -285,6 +287,15 @@ fn apply_frame(state: &'static NativeState, style: u32, idx: usize) {
unsafe {
let layer = &*(state.anim_layer_ptr as *const CALayer);
let cgimg_ptr = frames[idx] as *const AnyObject;
layer.setContents(Some(&*cgimg_ptr));
without_implicit_layer_actions(|| {
layer.setContents(Some(&*cgimg_ptr));
});
}
}

fn without_implicit_layer_actions(f: impl FnOnce()) {
CATransaction::begin();
CATransaction::setDisableActions(true);
f();
CATransaction::commit();
}
Loading