Skip to content

Commit

Permalink
macOS move impl details of platform into platform_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 1, 2021
1 parent 5eb9c95 commit 11a4408
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,10 @@ pub trait EventLoopWindowTargetExtMacOS {

impl<T> EventLoopWindowTargetExtMacOS for EventLoopWindowTarget<T> {
fn hide_application(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hide: 0] }
self.p.hide_application()
}

fn hide_other_applications(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hideOtherApplications: 0] }
self.p.hide_other_applications()
}
}
4 changes: 1 addition & 3 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ impl WindowExtWindows for Window {

#[inline]
fn set_enable(&self, enabled: bool) {
unsafe {
winapi::um::winuser::EnableWindow(self.hwnd() as _, enabled as _);
}
self.window.set_enable(enabled)
}

#[inline]
Expand Down
14 changes: 14 additions & 0 deletions src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ impl<T: 'static> EventLoopWindowTarget<T> {
}
}

impl<T> EventLoopWindowTarget<T> {
pub(crate) fn hide_application(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hide: 0] }
}

pub(crate) fn hide_other_applications(&self) {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
unsafe { msg_send![app, hideOtherApplications: 0] }
}
}

pub struct EventLoop<T: 'static> {
pub(crate) delegate: IdRef,

Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ impl Window {
self.window_state.lock().window_icon = window_icon;
}

#[inline]
pub fn set_enable(&self, enabled: bool) {
unsafe { winuser::EnableWindow(self.hwnd() as _, enabled as _) };
}

#[inline]
pub fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>) {
if let Some(ref taskbar_icon) = taskbar_icon {
Expand Down

0 comments on commit 11a4408

Please sign in to comment.