T46: Ely peeks over the main window's top edge from behind it, as the owner asked after the 0.1.3 film: her head and fingers from the icon's paths in a transparent window of her own, kept on the edge as each platform allows, macOS's child window, Windows' owned popup, X11's popup moved and stacked above the frame, Wayland's anchored popup; ten faces follow the most pressing of the sessions' marks, with hops, a shake and a rise; a press winks; Settings, Terminal, Ely turns her off
This commit is contained in:
22 files changed
+1090
-45
No files matched your search
@@ -0,0 +1,78 @@
|
||||
//! Ely's window on macOS: a child of the main window at its level, so it moves with it and keeps its layer and Space.
|
||||
|
||||
use anyhow::bail;
|
||||
use gpui::Window;
|
||||
use objc::{
|
||||
msg_send,
|
||||
runtime::{NO, Object},
|
||||
sel, sel_impl,
|
||||
};
|
||||
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
|
||||
|
||||
use super::LEFT;
|
||||
|
||||
/// AppKit's `NSWindowAbove`.
|
||||
const ABOVE: isize = 1;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
struct Point {
|
||||
x: f64,
|
||||
y: f64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
struct Rect {
|
||||
origin: Point,
|
||||
width: f64,
|
||||
height: f64,
|
||||
}
|
||||
|
||||
/// Her NSWindow and the main one's.
|
||||
pub struct Glue {
|
||||
pet: *mut Object,
|
||||
main: *mut Object,
|
||||
}
|
||||
|
||||
impl Glue {
|
||||
/// Makes her window the main window's child, at its level and in its Spaces, with no shadow.
|
||||
pub fn new(pet: &Window, main: &Window) -> anyhow::Result<Self> {
|
||||
let (pet, main) = (native(pet)?, native(main)?);
|
||||
unsafe {
|
||||
let level: isize = msg_send![main, level];
|
||||
let _: () = msg_send![pet, setLevel: level];
|
||||
let spaces: usize = msg_send![main, collectionBehavior];
|
||||
let _: () = msg_send![pet, setCollectionBehavior: spaces];
|
||||
let _: () = msg_send![pet, setHasShadow: NO];
|
||||
let _: () = msg_send![main, addChildWindow: pet ordered: ABOVE];
|
||||
}
|
||||
Ok(Self { pet, main })
|
||||
}
|
||||
|
||||
/// Stands her on the main window's top edge, `LEFT` points in from its left.
|
||||
pub fn place(&self, _: &Window) -> anyhow::Result<()> {
|
||||
unsafe {
|
||||
let frame: Rect = msg_send![self.main, frame];
|
||||
let at = Point {
|
||||
x: frame.origin.x + f64::from(LEFT),
|
||||
y: frame.origin.y + frame.height,
|
||||
};
|
||||
let _: () = msg_send![self.pet, setFrameOrigin: at];
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// The NSWindow gpui made for `window`.
|
||||
fn native(window: &Window) -> anyhow::Result<*mut Object> {
|
||||
let handle = HasWindowHandle::window_handle(window)
|
||||
.map_err(|error| anyhow::anyhow!("pet: no native handle: {error:?}"))?;
|
||||
let RawWindowHandle::AppKit(appkit) = handle.as_raw() else {
|
||||
bail!("pet: not an AppKit window");
|
||||
};
|
||||
let view = appkit.ns_view.as_ptr() as *mut Object;
|
||||
let native: *mut Object = unsafe { msg_send![view, window] };
|
||||
anyhow::ensure!(!native.is_null(), "pet: the view is in no window");
|
||||
Ok(native)
|
||||
}
|
||||
Reference in new issue
Block a user