WIP - adds platform APIs for checking the top most window
This commit is contained in:
@@ -37,6 +37,7 @@ use objc::{
|
||||
runtime::{Class, Object, Sel},
|
||||
sel, sel_impl,
|
||||
};
|
||||
use pathfinder_geometry::vector::Vector2F;
|
||||
use postage::oneshot;
|
||||
use ptr::null_mut;
|
||||
use std::{
|
||||
@@ -695,7 +696,19 @@ impl platform::Platform for MacPlatform {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_cursor_style(&self, style: CursorStyle) {
|
||||
fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F) {
|
||||
let top_most = Window::window_id_under(screen_position);
|
||||
if top_most.is_none() {
|
||||
return;
|
||||
}
|
||||
if top_most.unwrap() != window_id {
|
||||
return;
|
||||
}
|
||||
|
||||
dbg!(top_most.unwrap(), window_id);
|
||||
|
||||
dbg!(style);
|
||||
|
||||
unsafe {
|
||||
let cursor: id = match style {
|
||||
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
|
||||
|
||||
@@ -258,6 +258,10 @@ impl platform::Window for StatusItem {
|
||||
crate::Appearance::from_native(appearance)
|
||||
}
|
||||
}
|
||||
|
||||
fn screen_position(&self, _view_position: &Vector2F) -> Vector2F {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl StatusItemState {
|
||||
|
||||
@@ -559,6 +559,26 @@ impl Window {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_id_under(screen_position: &Vector2F) -> Option<usize> {
|
||||
unsafe {
|
||||
let app = NSApplication::sharedApplication(nil);
|
||||
|
||||
let point = NSPoint::new(screen_position.x() as f64, screen_position.y() as f64);
|
||||
let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0 as NSInteger];
|
||||
// For some reason this API doesn't work when our two windows are on top of each other
|
||||
let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number];
|
||||
dbg!(top_most_window);
|
||||
let is_panel: BOOL = msg_send![top_most_window, isKindOfClass: PANEL_CLASS];
|
||||
let is_window: BOOL = msg_send![top_most_window, isKindOfClass: WINDOW_CLASS];
|
||||
if is_panel | is_window {
|
||||
let id = get_window_state(&*top_most_window).borrow().id;
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Window {
|
||||
@@ -755,6 +775,16 @@ impl platform::Window for Window {
|
||||
fn on_appearance_changed(&mut self, callback: Box<dyn FnMut()>) {
|
||||
self.0.borrow_mut().appearance_changed_callback = Some(callback);
|
||||
}
|
||||
|
||||
fn screen_position(&self, view_position: &Vector2F) -> Vector2F {
|
||||
let self_borrow = self.0.borrow_mut();
|
||||
unsafe {
|
||||
let point = NSPoint::new(view_position.x() as f64, view_position.y() as f64);
|
||||
let screen_point: NSPoint =
|
||||
msg_send![self_borrow.native_window, convertPointToScreen: point];
|
||||
vec2f(screen_point.x as f32, screen_point.y as f32)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowState {
|
||||
|
||||
@@ -178,7 +178,7 @@ impl super::Platform for Platform {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_cursor_style(&self, style: CursorStyle) {
|
||||
fn set_cursor_style(&self, style: CursorStyle, _window_id: usize, _position: &Vector2F) {
|
||||
*self.cursor.lock() = style;
|
||||
}
|
||||
|
||||
@@ -332,6 +332,10 @@ impl super::Window for Window {
|
||||
}
|
||||
|
||||
fn on_appearance_changed(&mut self, _: Box<dyn FnMut()>) {}
|
||||
|
||||
fn screen_position(&self, view_position: &Vector2F) -> Vector2F {
|
||||
view_position.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn platform() -> Platform {
|
||||
|
||||
Reference in New Issue
Block a user