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
2 changes: 1 addition & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Clavy {
#[allow(clippy::too_many_lines)]
fn launch<S: AsRef<str>>(detect_popup: impl IntoIterator<Item = S>) -> Result<()> {
const NOTIF_NAME_LVL: Level = Level::DEBUG;
let activation_signal = |notif: &NSNotification, bundle_id: Retained<NSString>| unsafe {
let activation_signal = |notif: &NSNotification, bundle_id: Retained<NSString>| {
(
event_enabled!(NOTIF_NAME_LVL).then(|| notif.name().to_string()),
bundle_id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/observer/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use objc2_foundation::{NSNotification, NSNotificationCenter, NSNotificationName,
use tracing::trace;

pub static LOCAL_NOTIFICATION_CENTER: LazyLock<Retained<NSNotificationCenter>> =
LazyLock::new(|| unsafe { NSNotificationCenter::new() });
LazyLock::new(NSNotificationCenter::new);

pub const FOCUSED_WINDOW_CHANGED_NOTIFICATION: &str = "ClavyFocusedWindowsChangedNotification";
pub const APP_HIDDEN_NOTIFICATION: &str = "ClavyAppHiddenNotification";
Expand Down
11 changes: 5 additions & 6 deletions src/observer/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define_class![
#[unsafe(method_id(init))]
fn init(this: Allocated<Self>) -> Option<Retained<Self>> {
let this = this.set_ivars(WorkspaceObserverIvars {
workspace: unsafe { NSWorkspace::sharedWorkspace() },
workspace: NSWorkspace::sharedWorkspace(),
children: Mutex::default(),
allowed_app_ids: OnceLock::default(),
});
Expand Down Expand Up @@ -144,15 +144,14 @@ impl WorkspaceObserver {
key_path: Option<&NSString>,
_change: Option<&NSDictionary<NSKeyValueChangeKey, AnyObject>>,
) {
if !key_path.is_some_and(|p| unsafe { p.isEqualToString(ns_string!(RUNNING_APPLICATIONS)) })
{
if !key_path.is_some_and(|p| p.isEqualToString(ns_string!(RUNNING_APPLICATIONS))) {
warn!("received an unexpected change from key path `{key_path:?}`");
return;
}

let ivars = self.ivars();

let new = unsafe { ivars.workspace.runningApplications() };
let new = ivars.workspace.runningApplications();
let new_keys = self.window_change_pids(&new.to_vec());

let mut children = ivars.children.lock().expect("failed to lock children");
Expand Down Expand Up @@ -218,15 +217,15 @@ impl WorkspaceObserver {
running_apps
.iter()
.filter(|&app| {
unsafe { app.bundleIdentifier() }.is_some_and(|nss| {
app.bundleIdentifier().is_some_and(|nss| {
self.ivars()
.allowed_app_ids
.get()
.unwrap()
.contains(&nss.to_string())
})
})
.map(|app| unsafe { app.processIdentifier() })
.map(|app| app.processIdentifier())
.filter(|pid| windowed_pids.contains(pid))
.collect()
}
Expand Down
18 changes: 7 additions & 11 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ fn ax_ui_element_value(elem: AXUIElementRef, key: &str) -> Result<CFTypeRef, Acc
/// Converts a running application's PID to its Bundle ID.
#[must_use]
pub fn bundle_id_from_pid(pid: pid_t) -> Option<Retained<NSString>> {
unsafe {
NSWorkspace::sharedWorkspace()
.runningApplications()
.iter()
.find_map(|app| (app.processIdentifier() == pid).then(|| app.bundleIdentifier())?)
}
NSWorkspace::sharedWorkspace()
.runningApplications()
.iter()
.find_map(|app| (app.processIdentifier() == pid).then(|| app.bundleIdentifier())?)
}

/// Returns the PID of the frontmost application from a notification
Expand Down Expand Up @@ -110,11 +108,9 @@ pub fn pid_from_current_app() -> Result<pid_t, AccessibilityError> {
/// are ignored by this API.
#[must_use]
pub fn bundle_id_from_frontmost_app() -> Option<Retained<NSString>> {
unsafe {
NSWorkspace::sharedWorkspace()
.frontmostApplication()?
.bundleIdentifier()
}
NSWorkspace::sharedWorkspace()
.frontmostApplication()?
.bundleIdentifier()
}

/// Returns the Bundle ID of the currently focused application.
Expand Down