From b82bcbe5c50b17d08a6d57a7198a0aa4fa65788e Mon Sep 17 00:00:00 2001 From: "Rob.Gowin" Date: Tue, 22 Sep 2015 22:34:31 -0500 Subject: [PATCH 1/3] Added NSRunningApplication and two associated functions. Added ability to call [[NSRunningApplication currentApplication] activateWithOptions: NSApplicationActivateIgnoringOtherApps] which is used in the example to fix the missing menu bar when the example app starts. --- src/appkit.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index b7afaf6..b4cf9a0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -18,6 +18,7 @@ pub use core_graphics::base::CGFloat; pub use core_graphics::geometry::CGPoint; pub use self::NSApplicationActivationPolicy::*; +pub use self::NSApplicationActivationOptions::*; pub use self::NSWindowMask::*; pub use self::NSBackingStoreType::*; pub use self::NSOpenGLPixelFormatAttribute::*; @@ -69,6 +70,12 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1 } +#[repr(u64)] +pub enum NSApplicationActivationOptions { + NSApplicationActivateAllWindows = 1 << 0, + NSApplicationActivateIgnoringOtherApps = 1 << 1 +} + #[repr(u64)] pub enum NSApplicationTerminateReply { NSTerminateCancel = 0, @@ -287,6 +294,19 @@ impl NSApplication for id { } } +pub trait NSRunningApplication { + unsafe fn currentApplication(_: Self) -> id { + msg_send![class("NSRunningApplication"), currentApplication] + } + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL; +} + +impl NSRunningApplication for id { + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL { + msg_send![self, activateWithOptions:options as NSUInteger] + } +} + pub trait NSMenu { unsafe fn new(_: Self) -> id { msg_send![class("NSMenu"), new] From d56b150d2d5fafba71055880cd50cd7e84180248 Mon Sep 17 00:00:00 2001 From: "Rob.Gowin" Date: Tue, 22 Sep 2015 22:35:20 -0500 Subject: [PATCH 2/3] Activate the example app via NSRunningApplication This fixes #98, at least on my Yosemite machine. --- examples/hello_world.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 3af32d6..6c6124e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,12 +1,13 @@ extern crate cocoa; -use cocoa::base::{selector, nil, YES, NO}; +use cocoa::base::{selector, nil, /*YES, */ NO}; use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, - NSMenu, NSMenuItem}; + NSMenu, NSMenuItem, NSRunningApplication, + NSApplicationActivateIgnoringOtherApps}; fn main() { unsafe { @@ -49,8 +50,8 @@ fn main() { let title = NSString::alloc(nil).init_str("Hello World!"); window.setTitle_(title); window.makeKeyAndOrderFront_(nil); - - app.activateIgnoringOtherApps_(YES); + let current_app = NSRunningApplication::currentApplication(nil); + current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); app.run(); } } From d694e3b80105f48bd715e0770ceaee983bf66ae2 Mon Sep 17 00:00:00 2001 From: Rob Gowin Date: Wed, 23 Sep 2015 07:05:29 -0500 Subject: [PATCH 3/3] Delete no longer used value --- examples/hello_world.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 6c6124e..831e43f 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{selector, nil, /*YES, */ NO}; +use cocoa::base::{selector, nil, NO}; use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp,