Added Topmost/Always on Top functionality to MacOS (#154)

* Added a topmost property to WindowOptons and initialized it to false in WindowOption's default method

* Added an mfb_topmost function that sets the window's floating level to NSFloatingWindowLevel so it will be topmost

* Added an extern definition of mfb_topmost and conditionally call it if WindowOptions.topmost is true

* changing mfb_topmost first arg name from win to window to staty consistent with rust extern declaration
This commit is contained in:
phillvancejr 2020-03-31 01:28:52 -04:00 committed by GitHub
parent e6514ba553
commit fbf1d54db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -185,6 +185,8 @@ pub struct WindowOptions {
pub scale: Scale, pub scale: Scale,
/// Adjust how the scaling of the buffer used with update_with_buffer should be done. /// Adjust how the scaling of the buffer used with update_with_buffer should be done.
pub scale_mode: ScaleMode, pub scale_mode: ScaleMode,
/// Should the window be the topmost window (default: false)
pub topmost: bool,
} }
impl Window { impl Window {
@ -995,6 +997,7 @@ impl Default for WindowOptions {
resize: false, resize: false,
scale: Scale::X1, scale: Scale::X1,
scale_mode: ScaleMode::Stretch, scale_mode: ScaleMode::Stretch,
topmost: false,
} }
} }
} }

View file

@ -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) static NSString* findAppName(void)
{ {
size_t i; size_t i;

View file

@ -192,6 +192,9 @@ extern "C" {
fn mfb_create_menu(name: *const c_char) -> *mut c_void; fn mfb_create_menu(name: *const c_char) -> *mut c_void;
fn mfb_remove_menu_at(window: *mut c_void, index: i32); 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( fn mfb_add_menu_item(
menu_item: *mut c_void, menu_item: *mut c_void,
menu_id: i32, menu_id: i32,
@ -288,6 +291,11 @@ impl Window {
&mut view_handle, &mut view_handle,
); );
if opts.topmost {
mfb_topmost(handle, true);
}
if handle == ptr::null_mut() { if handle == ptr::null_mut() {
return Err(Error::WindowCreate("Unable to open Window".to_owned())); return Err(Error::WindowCreate("Unable to open Window".to_owned()));
} }