Skip to content

Commit b8d96c3

Browse files
committed
Remove no longer needed unsafe blocks
1 parent 8c09108 commit b8d96c3

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

src/macos/mod.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,6 @@ fn get_preferences(
167167
preferences
168168
}
169169

170-
#[cfg(feature = "_macos-accessibility")]
171-
fn get_shared_workspace() -> Retained<NSWorkspace> {
172-
// SAFETY:
173-
// * `sharedWorkspace` is safe to access from any thread.
174-
// Source: <https://developer.apple.com/documentation/appkit/nsworkspace/1530344-sharedworkspace>
175-
// * Doesn't take any raw pointers.
176-
// * Has no documented preconditions.
177-
// * Has no documented exceptions.
178-
unsafe { NSWorkspace::sharedWorkspace() }
179-
}
180-
181170
#[cfg(feature = "color-scheme")]
182171
fn to_color_scheme(appearance: &NSAppearance) -> ColorScheme {
183172
let light = unsafe { NSAppearanceNameAqua };
@@ -193,9 +182,8 @@ fn to_color_scheme(appearance: &NSAppearance) -> ColorScheme {
193182

194183
#[cfg(feature = "contrast")]
195184
fn get_contrast() -> Contrast {
196-
let workspace = get_shared_workspace();
197-
// SAFETY: Similar as for `get_shared_workspace()`.
198-
let increase_contrast = unsafe { workspace.accessibilityDisplayShouldIncreaseContrast() };
185+
let workspace = NSWorkspace::sharedWorkspace();
186+
let increase_contrast = workspace.accessibilityDisplayShouldIncreaseContrast();
199187
if increase_contrast {
200188
Contrast::More
201189
} else {
@@ -205,9 +193,8 @@ fn get_contrast() -> Contrast {
205193

206194
#[cfg(feature = "reduced-motion")]
207195
fn get_reduced_motion() -> ReducedMotion {
208-
let workspace = get_shared_workspace();
209-
// SAFETY: Similar as for `get_shared_workspace()`.
210-
let reduce_motion = unsafe { workspace.accessibilityDisplayShouldReduceMotion() };
196+
let workspace = NSWorkspace::sharedWorkspace();
197+
let reduce_motion = workspace.accessibilityDisplayShouldReduceMotion();
211198
if reduce_motion {
212199
ReducedMotion::Reduce
213200
} else {
@@ -217,9 +204,8 @@ fn get_reduced_motion() -> ReducedMotion {
217204

218205
#[cfg(feature = "reduced-transparency")]
219206
fn get_reduced_transparency() -> ReducedTransparency {
220-
let workspace = get_shared_workspace();
221-
// SAFETY: Similar as for `get_shared_workspace()`.
222-
let reduce_motion = unsafe { workspace.accessibilityDisplayShouldReduceTransparency() };
207+
let workspace = NSWorkspace::sharedWorkspace();
208+
let reduce_motion = workspace.accessibilityDisplayShouldReduceTransparency();
223209
if reduce_motion {
224210
ReducedTransparency::Reduce
225211
} else {
@@ -229,26 +215,26 @@ fn get_reduced_transparency() -> ReducedTransparency {
229215

230216
#[cfg(feature = "accent-color")]
231217
fn get_accent_color() -> AccentColor {
232-
let color = unsafe { NSColor::controlAccentColor() };
218+
let color = NSColor::controlAccentColor();
233219
AccentColor(to_srgb(&color))
234220
}
235221

236222
#[cfg(feature = "accent-color")]
237223
fn to_srgb(color: &NSColor) -> Option<Srgba> {
238-
let srgb = unsafe { NSColorSpace::sRGBColorSpace() };
239-
let color_in_srgb = unsafe { color.colorUsingColorSpace(&srgb) }?;
224+
let srgb = NSColorSpace::sRGBColorSpace();
225+
let color_in_srgb = color.colorUsingColorSpace(&srgb)?;
240226
// We have to cast because on 32-bit platforms, `CGFloat` = f32.
241227
Some(Srgba {
242-
red: unsafe { color_in_srgb.redComponent() } as _,
243-
green: unsafe { color_in_srgb.greenComponent() } as _,
244-
blue: unsafe { color_in_srgb.blueComponent() } as _,
245-
alpha: unsafe { color_in_srgb.alphaComponent() } as _,
228+
red: color_in_srgb.redComponent() as _,
229+
green: color_in_srgb.greenComponent() as _,
230+
blue: color_in_srgb.blueComponent() as _,
231+
alpha: color_in_srgb.alphaComponent() as _,
246232
})
247233
}
248234

249235
#[cfg(feature = "double-click-interval")]
250236
fn get_double_click_interval() -> DoubleClickInterval {
251237
// NSTimeInterval: A number of seconds.
252-
let interval = unsafe { NSEvent::doubleClickInterval() };
238+
let interval = NSEvent::doubleClickInterval();
253239
DoubleClickInterval(Duration::try_from_secs_f64(interval).ok())
254240
}

src/macos/observer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ impl Observer {
7878
#[cfg(feature = "_macos-accessibility")]
7979
if interest.is(Interest::MacOSAccessibility) {
8080
let workspace = get_shared_workspace();
81-
// SAFETY: Similar as for `get_shared_workspace()`.
82-
let notification_center = unsafe { workspace.notificationCenter() };
81+
let notification_center = workspace.notificationCenter();
8382
// SAFETY: The observer is removed on drop.
8483
unsafe {
8584
notification_center.addObserver_selector_name_object(
@@ -137,8 +136,7 @@ impl Drop for ObserverRegistration {
137136
#[cfg(feature = "_macos-accessibility")]
138137
if self.interest.is(Interest::MacOSAccessibility) {
139138
let workspace = get_shared_workspace();
140-
// SAFETY: Similar as for `get_shared_workspace()`.
141-
let notification_center = unsafe { workspace.notificationCenter() };
139+
let notification_center = workspace.notificationCenter();
142140
unsafe {
143141
notification_center.removeObserver(&self.observer);
144142
}

0 commit comments

Comments
 (0)