From e1c33310afdcfaee2c7d708b8dd91a5e369ba832 Mon Sep 17 00:00:00 2001 From: Jack Hogan Date: Sun, 15 Sep 2024 12:09:24 -0400 Subject: [PATCH 1/3] Added more helper functions --- src/appkit/app/mod.rs | 6 ++++++ src/appkit/window/mod.rs | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index a266d925..c43ea471 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -224,6 +224,12 @@ impl App { }); } + pub fn update_windows() { + shared_application(|app| unsafe { + let _: () = msg_send![app, updateWindows]; + }); + } + /// Unregisters for remote notifications from APNS. pub fn unregister_for_remote_notifications() { shared_application(|app| unsafe { diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index e25b5661..23c3ee3e 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -20,6 +20,7 @@ use objc::{class, msg_send, msg_send_id, sel}; use crate::appkit::toolbar::{Toolbar, ToolbarDelegate}; use crate::color::Color; use crate::foundation::{id, nil, to_bool, NSInteger, NSString, NSUInteger, NO, YES}; +use crate::geometry::Rect; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::{os, Controller}; @@ -338,6 +339,49 @@ impl Window { } } + pub fn set_scale(&self, rect: Rect) { + let rect: CGRect = rect.into(); + unsafe { + let _: () = msg_send![&*self.objc, setFrame:rect display:YES]; + } + } + + pub fn set_ignores_mouse_events(&self, ignore: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setIgnoresMouseEvents:match ignore { + true => YES, + false => NO, + }]; + } + } + + pub fn set_accepts_mouse_moved_events(&self, accept: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setAcceptsMouseMovedEvents:match accept { + true => YES, + false => NO, + }]; + } + } + + pub fn set_is_visible(&self, visible: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setIsVisible:match visible { + true => YES, + false => NO, + }]; + } + } + + pub fn set_has_shadow(&self, shadow: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setHasShadow:match shadow { + true => YES, + false => NO, + }]; + } + } + /// Return the objc ContentView from the window pub(crate) unsafe fn content_view(&self) -> id { let id: *mut Object = msg_send![&*self.objc, contentView]; From df5709986d3a7766ba32230a8dc9dde524a28a63 Mon Sep 17 00:00:00 2001 From: Jack Hogan Date: Mon, 16 Sep 2024 16:42:22 -0400 Subject: [PATCH 2/3] Add docs --- src/appkit/app/mod.rs | 1 + src/appkit/window/mod.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index c43ea471..8b57f576 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -224,6 +224,7 @@ impl App { }); } + /// Sends an update() message to each onscreen window. pub fn update_windows() { shared_application(|app| unsafe { let _: () = msg_send![app, updateWindows]; diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index 23c3ee3e..e555d499 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -339,13 +339,16 @@ impl Window { } } - pub fn set_scale(&self, rect: Rect) { + /// Sets the origin and size of the window’s frame rectangle according to a given frame rectangle, + /// thereby setting its position and size onscreen. + pub fn set_frame(&self, rect: Rect) { let rect: CGRect = rect.into(); unsafe { let _: () = msg_send![&*self.objc, setFrame:rect display:YES]; } } + /// Sets whether the window is transparent to mouse events. pub fn set_ignores_mouse_events(&self, ignore: bool) { unsafe { let _: () = msg_send![&*self.objc, setIgnoresMouseEvents:match ignore { @@ -355,6 +358,7 @@ impl Window { } } + /// Sets whether the window accepts mouse-moved events. pub fn set_accepts_mouse_moved_events(&self, accept: bool) { unsafe { let _: () = msg_send![&*self.objc, setAcceptsMouseMovedEvents:match accept { @@ -364,6 +368,7 @@ impl Window { } } + /// Sets the window’s visible state to the value you specify. pub fn set_is_visible(&self, visible: bool) { unsafe { let _: () = msg_send![&*self.objc, setIsVisible:match visible { @@ -373,6 +378,7 @@ impl Window { } } + /// Sets whether the window has a shadow. pub fn set_has_shadow(&self, shadow: bool) { unsafe { let _: () = msg_send![&*self.objc, setHasShadow:match shadow { From 60cd402813da44c9736c90dd7263f84930603b39 Mon Sep 17 00:00:00 2001 From: Jack Hogan Date: Fri, 20 Sep 2024 23:14:24 -0400 Subject: [PATCH 3/3] Added window activation options --- Cargo.toml | 1 + src/appkit/app/mod.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 639e96c1..9b0a8194 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ libc = "0.2" os_info = "3.0.1" url = "2.1.1" uuid = { version = "1.1", features = ["v4"], optional = true } +bitflags = "2.6.0" [dev-dependencies] eval = "0.4" diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index 8b57f576..4ba533d9 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -216,6 +216,15 @@ where } } +bitflags::bitflags! { + /// Flags for window activation + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + pub struct ApplicationActivationOptions: u8 { + const ActivateAllWindows = 1 << 0; + const ActivateIgnoringOtherApps = 1 << 1; + } +} + impl App { /// Registers for remote notifications from APNS. pub fn register_for_remote_notifications() { @@ -294,13 +303,12 @@ impl App { /// For nib-less applications (which, if you're here, this is) need to call the activation /// routines after the NSMenu has been set, otherwise it won't be interact-able without /// switching away from the app and then coming back. - /// - /// @TODO: Accept an ActivationPolicy enum or something. - pub fn activate() { + pub fn activate(options: ApplicationActivationOptions) { + let options = options.bits(); shared_application(|app| unsafe { let _: () = msg_send![app, setActivationPolicy:0]; let current_app: id = msg_send![class!(NSRunningApplication), currentApplication]; - let _: () = msg_send![current_app, activateWithOptions:1<<1]; + let _: () = msg_send![current_app, activateWithOptions:options]; }); }