Skip to content

Commit bd560b1

Browse files
committed
fix(cocoa): deprecated warnings
1 parent c43b1e6 commit bd560b1

2 files changed

Lines changed: 29 additions & 34 deletions

File tree

src/runtime/mac.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use compio::driver::AsRawFd;
44
use objc2::rc::Retained;
55
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSEventMask};
66
use objc2_core_foundation::{
7-
CFFileDescriptor, CFFileDescriptorCreate, CFFileDescriptorCreateRunLoopSource,
8-
CFFileDescriptorEnableCallBacks, CFRetained, CFRunLoopAddSource, CFRunLoopGetCurrent,
9-
CFRunLoopRunInMode, kCFAllocatorDefault, kCFFileDescriptorReadCallBack, kCFRunLoopDefaultMode,
7+
CFFileDescriptor, CFRetained, CFRunLoop, kCFAllocatorDefault, kCFFileDescriptorReadCallBack,
8+
kCFRunLoopDefaultMode,
109
};
1110
use objc2_foundation::{MainThreadMarker, NSDate, NSDefaultRunLoopMode};
1211

@@ -28,7 +27,7 @@ impl Runtime {
2827
}
2928

3029
let fd_source = unsafe {
31-
CFFileDescriptorCreate(
30+
CFFileDescriptor::new(
3231
kCFAllocatorDefault,
3332
runtime.as_raw_fd(),
3433
false,
@@ -38,13 +37,13 @@ impl Runtime {
3837
}
3938
.unwrap();
4039
let source = unsafe {
41-
CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, Some(&fd_source), 0)
40+
CFFileDescriptor::new_run_loop_source(kCFAllocatorDefault, Some(&fd_source), 0)
4241
}
4342
.unwrap();
4443

4544
unsafe {
46-
let run_loop = CFRunLoopGetCurrent().unwrap();
47-
CFRunLoopAddSource(&run_loop, Some(&source), kCFRunLoopDefaultMode);
45+
let run_loop = CFRunLoop::current().unwrap();
46+
run_loop.add_source(Some(&source), kCFRunLoopDefaultMode);
4847
}
4948

5049
let ns_app = NSApplication::sharedApplication(MainThreadMarker::new().unwrap());
@@ -87,14 +86,13 @@ impl Runtime {
8786
} else {
8887
self.runtime.current_timeout()
8988
};
90-
unsafe {
91-
CFFileDescriptorEnableCallBacks(&self.fd_source, kCFFileDescriptorReadCallBack);
92-
CFRunLoopRunInMode(
93-
kCFRunLoopDefaultMode,
94-
timeout.unwrap_or(Duration::MAX).as_secs_f64(),
95-
true,
96-
);
97-
}
89+
self.fd_source
90+
.enable_call_backs(kCFFileDescriptorReadCallBack);
91+
CFRunLoop::run_in_mode(
92+
unsafe { kCFRunLoopDefaultMode },
93+
timeout.unwrap_or(Duration::MAX).as_secs_f64(),
94+
true,
95+
);
9896
unsafe {
9997
loop {
10098
let event = self.ns_app.nextEventMatchingMask_untilDate_inMode_dequeue(

src/ui/mac/canvas.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use objc2_app_kit::{
1414
};
1515
use objc2_core_foundation::{CFRetained, CFString, CGAffineTransform};
1616
use objc2_core_graphics::{
17-
CGAffineTransformMake, CGColor, CGColorCreateGenericRGB, CGColorGetConstantColor, CGPath,
18-
CGPathAddArc, CGPathAddCurveToPoint, CGPathAddLineToPoint, CGPathCloseSubpath,
19-
CGPathCreateMutable, CGPathCreateWithEllipseInRect, CGPathCreateWithRect,
20-
CGPathCreateWithRoundedRect, CGPathGetBoundingBox, CGPathMoveToPoint, kCGColorClear,
17+
CGAffineTransformMake, CGColor, CGMutablePath as CGMutablePathRaw, CGPath, kCGColorClear,
2118
kCGColorWhite,
2219
};
2320
use objc2_foundation::{
@@ -329,7 +326,7 @@ impl DrawingContext<'_> {
329326
if let Some(clip) = clip {
330327
let mask_layer = CALayer::new();
331328
mask_layer.setFrame(transform_rect(image_rep.size(), clip));
332-
let white = CGColorGetConstantColor(Some(kCGColorWhite));
329+
let white = CGColor::constant_color(Some(kCGColorWhite));
333330
mask_layer.setBackgroundColor(white.as_deref());
334331
source_layer.setMask(Some(&mask_layer));
335332
}
@@ -347,7 +344,7 @@ pub struct DrawingPath(CFRetained<objc2_core_graphics::CGMutablePath>);
347344

348345
impl DrawingPath {
349346
fn bounding(&self) -> NSRect {
350-
unsafe { CGPathGetBoundingBox(Some(&self.0)) }
347+
unsafe { CGPath::bounding_box(Some(&self.0)) }
351348
}
352349
}
353350

@@ -414,22 +411,22 @@ fn to_ptr<T>(v: Option<&T>) -> *const T {
414411
}
415412

416413
#[repr(transparent)]
417-
struct CGMutablePath(CFRetained<objc2_core_graphics::CGMutablePath>);
414+
struct CGMutablePath(CFRetained<CGMutablePathRaw>);
418415

419416
impl CGMutablePath {
420417
pub fn new() -> Self {
421-
Self(unsafe { CGPathCreateMutable() })
418+
Self(unsafe { CGMutablePathRaw::new() })
422419
}
423420

424421
pub fn move_to_point(&mut self, transform: Option<&CGAffineTransform>, p: NSPoint) {
425422
unsafe {
426-
CGPathMoveToPoint(Some(&self.0), to_ptr(transform), p.x, p.y);
423+
CGMutablePathRaw::move_to_point(Some(&self.0), to_ptr(transform), p.x, p.y);
427424
}
428425
}
429426

430427
pub fn line_to_point(&mut self, transform: Option<&CGAffineTransform>, p: NSPoint) {
431428
unsafe {
432-
CGPathAddLineToPoint(Some(&self.0), to_ptr(transform), p.x, p.y);
429+
CGMutablePathRaw::add_line_to_point(Some(&self.0), to_ptr(transform), p.x, p.y);
433430
}
434431
}
435432

@@ -443,7 +440,7 @@ impl CGMutablePath {
443440
clockwise: bool,
444441
) {
445442
unsafe {
446-
CGPathAddArc(
443+
CGMutablePathRaw::add_arc(
447444
Some(&self.0),
448445
to_ptr(transform),
449446
center.x,
@@ -464,7 +461,7 @@ impl CGMutablePath {
464461
p3: NSPoint,
465462
) {
466463
unsafe {
467-
CGPathAddCurveToPoint(
464+
CGMutablePathRaw::add_curve_to_point(
468465
Some(&self.0),
469466
to_ptr(transform),
470467
p1.x,
@@ -479,7 +476,7 @@ impl CGMutablePath {
479476

480477
pub fn close(&mut self) {
481478
unsafe {
482-
CGPathCloseSubpath(Some(&self.0));
479+
CGMutablePathRaw::close_subpath(Some(&self.0));
483480
}
484481
}
485482
}
@@ -532,7 +529,7 @@ fn path_arc(s: Size, rect: Rect, start: f64, end: f64, pie: bool) -> CGMutablePa
532529

533530
fn path_ellipse(s: Size, rect: Rect) -> CFRetained<CGPath> {
534531
let rect = transform_rect(s, rect);
535-
unsafe { CGPathCreateWithEllipseInRect(rect, null()) }
532+
unsafe { CGPath::with_ellipse_in_rect(rect, null()) }
536533
}
537534

538535
fn path_line(s: Size, start: Point, end: Point) -> CGMutablePath {
@@ -544,12 +541,12 @@ fn path_line(s: Size, start: Point, end: Point) -> CGMutablePath {
544541

545542
fn path_rect(s: Size, rect: Rect) -> CFRetained<CGPath> {
546543
let rect = transform_rect(s, rect);
547-
unsafe { CGPathCreateWithRect(rect, null()) }
544+
unsafe { CGPath::with_rect(rect, null()) }
548545
}
549546

550547
fn path_round_rect(s: Size, rect: Rect, round: Size) -> CFRetained<CGPath> {
551548
let rect = transform_rect(s, rect);
552-
unsafe { CGPathCreateWithRoundedRect(rect, round.width, round.height, null()) }
549+
unsafe { CGPath::with_rounded_rect(rect, round.width, round.height, null()) }
553550
}
554551

555552
fn measure_str(font: DrawingFont, pos: Point, text: &str) -> (Retained<NSAttributedString>, Rect) {
@@ -604,7 +601,7 @@ fn create_attr_str(font: &DrawingFont, text: &str) -> Retained<NSAttributedStrin
604601

605602
fn to_cgcolor(c: Color) -> CFRetained<CGColor> {
606603
unsafe {
607-
CGColorCreateGenericRGB(
604+
CGColor::new_generic_rgb(
608605
c.r as f64 / 255.0,
609606
c.g as f64 / 255.0,
610607
c.b as f64 / 255.0,
@@ -623,9 +620,9 @@ unsafe fn make_layer(
623620
stroke: &CFString,
624621
) -> Retained<CALayer> {
625622
let mask_layer = to_layer(path);
626-
let fill = CGColorGetConstantColor(Some(fill));
623+
let fill = CGColor::constant_color(Some(fill));
627624
mask_layer.setFillColor(fill.as_deref());
628-
let stroke = CGColorGetConstantColor(Some(stroke));
625+
let stroke = CGColor::constant_color(Some(stroke));
629626
mask_layer.setStrokeColor(stroke.as_deref());
630627
mask_layer.setLineWidth(width);
631628
let mut brush_rect = transform_rect(size, rect);

0 commit comments

Comments
 (0)