diff --git a/src/lib.rs b/src/lib.rs index 6c44046..ac49be4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,6 +185,8 @@ pub struct WindowOptions { pub scale: Scale, /// Adjust how the scaling of the buffer used with update_with_buffer should be done. pub scale_mode: ScaleMode, + /// Should the window be the topmost window (default: false) + pub topmost: bool, } impl Window { @@ -995,6 +997,7 @@ impl Default for WindowOptions { resize: false, scale: Scale::X1, scale_mode: ScaleMode::Stretch, + topmost: false, } } } diff --git a/src/native/macosx/MacMiniFB.m b/src/native/macosx/MacMiniFB.m index a3d93ef..3848a42 100644 --- a/src/native/macosx/MacMiniFB.m +++ b/src/native/macosx/MacMiniFB.m @@ -292,6 +292,23 @@ void* mfb_open(const char* name, int width, int height, uint32_t flags, int scal /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Sets whether window is the topmost window +void mfb_topmost(void* window, bool topmost) +{ + + OSXWindow* win = (OSXWindow*)window; + + if(topmost) + { + win.level = NSFloatingWindowLevel; // set level to floating + } else + { + win.level = 0; // set to default/normal + } + +} +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static NSString* findAppName(void) { size_t i; diff --git a/src/os/macos/mod.rs b/src/os/macos/mod.rs index 3e5b16b..0c6dfca 100644 --- a/src/os/macos/mod.rs +++ b/src/os/macos/mod.rs @@ -192,6 +192,9 @@ extern "C" { fn mfb_create_menu(name: *const c_char) -> *mut c_void; fn mfb_remove_menu_at(window: *mut c_void, index: i32); + /// Sets the whether or not the window is the topmost window + fn mfb_topmost(window: *mut c_void, topmost: bool); + fn mfb_add_menu_item( menu_item: *mut c_void, menu_id: i32, @@ -288,6 +291,11 @@ impl Window { &mut view_handle, ); + + if opts.topmost { + mfb_topmost(handle, true); + } + if handle == ptr::null_mut() { return Err(Error::WindowCreate("Unable to open Window".to_owned())); }