) -> Opt
fn get_parent_id(parent: &P) -> Parent
where
- P: WinitWindow,
+ P: DesktopWindow,
{
// Check window type.
let parent = parent.handle();
diff --git a/gui/src/ui/linux/mod.rs b/gui/src/ui/linux/mod.rs
index 34cd2bc4..e4b7b132 100644
--- a/gui/src/ui/linux/mod.rs
+++ b/gui/src/ui/linux/mod.rs
@@ -1,8 +1,8 @@
pub use self::dialogs::*;
use self::modal::Modal;
-use super::{DesktopWindow, SlintBackend};
-use crate::rt::{global, WinitWindow};
+use super::{DesktopExt, DesktopWindow, SlintBackend};
+use crate::rt::global;
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use thiserror::Error;
@@ -10,11 +10,11 @@ mod dialogs;
mod modal;
mod wayland;
-impl DesktopWindow for T {
+impl DesktopExt for T {
type Modal<'a, P>
= Modal<'a, Self, P>
where
- P: WinitWindow + 'a;
+ P: DesktopWindow + 'a;
fn set_center(&self) -> Result<(), PlatformError> {
let win = self.handle();
@@ -33,7 +33,7 @@ impl DesktopWindow for T {
fn set_modal(self, parent: &P) -> Result, PlatformError>
where
- P: WinitWindow,
+ P: DesktopWindow,
Self: Sized,
{
let back = global::().unwrap();
@@ -49,7 +49,7 @@ impl DesktopWindow for T {
}
}
-/// Linux-specific error for [`PlatformExt`].
+/// Linux-specific error for [`DesktopExt`].
#[derive(Debug, Error)]
pub enum PlatformError {
#[error("couldn't create xdg_dialog_v1")]
diff --git a/gui/src/ui/linux/modal.rs b/gui/src/ui/linux/modal.rs
index 8f1982da..f545afe8 100644
--- a/gui/src/ui/linux/modal.rs
+++ b/gui/src/ui/linux/modal.rs
@@ -1,18 +1,19 @@
-use crate::rt::{block, Blocker, WinitWindow};
+use crate::rt::{block, Blocker};
+use crate::ui::DesktopWindow;
use std::ops::Deref;
use wayland_protocols::xdg::dialog::v1::client::xdg_dialog_v1::XdgDialogV1;
/// Encapsulates a modal window and its parent.
///
/// This struct forces the modal window to be dropped before its parent.
-pub struct Modal<'a, W, P: WinitWindow> {
+pub struct Modal<'a, W, P: DesktopWindow> {
window: W,
wayland: Option,
#[allow(dead_code)]
blocker: Blocker<'a, P>,
}
-impl<'a, W, P: WinitWindow> Modal<'a, W, P> {
+impl<'a, W, P: DesktopWindow> Modal<'a, W, P> {
pub fn new(window: W, parent: &'a P, wayland: Option) -> Self {
Self {
window,
@@ -22,7 +23,7 @@ impl<'a, W, P: WinitWindow> Modal<'a, W, P> {
}
}
-impl<'a, W, P: WinitWindow> Drop for Modal<'a, W, P> {
+impl<'a, W, P: DesktopWindow> Drop for Modal<'a, W, P> {
fn drop(&mut self) {
if let Some(v) = self.wayland.take() {
v.destroy();
@@ -30,7 +31,7 @@ impl<'a, W, P: WinitWindow> Drop for Modal<'a, W, P> {
}
}
-impl<'a, W, P: WinitWindow> Deref for Modal<'a, W, P> {
+impl<'a, W, P: DesktopWindow> Deref for Modal<'a, W, P> {
type Target = W;
fn deref(&self) -> &Self::Target {
diff --git a/gui/src/ui/linux/wayland.rs b/gui/src/ui/linux/wayland.rs
index d8ced4b8..45974702 100644
--- a/gui/src/ui/linux/wayland.rs
+++ b/gui/src/ui/linux/wayland.rs
@@ -1,6 +1,5 @@
use super::PlatformError;
-use crate::rt::WinitWindow;
-use crate::ui::Wayland;
+use crate::ui::{DesktopWindow, Wayland};
use wayland_backend::sys::client::ObjectId;
use wayland_client::Proxy;
use wayland_protocols::xdg::dialog::v1::client::xdg_dialog_v1::XdgDialogV1;
@@ -10,8 +9,8 @@ use wayland_protocols::xdg::shell::client::xdg_toplevel::XdgToplevel;
/// `parent` must outlive `target`.
pub unsafe fn set_modal(
wayland: &Wayland,
- target: &impl WinitWindow,
- parent: &impl WinitWindow,
+ target: &impl DesktopWindow,
+ parent: &impl DesktopWindow,
) -> Result {
// Get xdg_toplevel for parent.
let mut queue = wayland.queue().borrow_mut();
@@ -40,7 +39,7 @@ pub unsafe fn set_modal(
/// # Safety
/// `win` must outlive the returned [`XdgToplevel`].
-unsafe fn get_xdg_toplevel(wayland: &Wayland, win: &impl WinitWindow) -> XdgToplevel {
+unsafe fn get_xdg_toplevel(wayland: &Wayland, win: &impl DesktopWindow) -> XdgToplevel {
let obj = win.xdg_toplevel();
let obj = ObjectId::from_ptr(XdgToplevel::interface(), obj.cast()).unwrap();
diff --git a/gui/src/ui/macos/dialogs.rs b/gui/src/ui/macos/dialogs.rs
index 21af9f2b..c26ea801 100644
--- a/gui/src/ui/macos/dialogs.rs
+++ b/gui/src/ui/macos/dialogs.rs
@@ -1,8 +1,7 @@
-use crate::rt::WinitWindow;
-use crate::ui::FileType;
+use crate::ui::{DesktopWindow, FileType};
use std::path::PathBuf;
-pub async fn open_file(
+pub async fn open_file(
parent: &T,
title: impl AsRef,
ty: FileType,
@@ -10,6 +9,6 @@ pub async fn open_file(
todo!();
}
-pub async fn open_dir(parent: &T, title: impl AsRef) -> Option {
+pub async fn open_dir(parent: &T, title: impl AsRef) -> Option {
todo!()
}
diff --git a/gui/src/ui/macos/mod.rs b/gui/src/ui/macos/mod.rs
index 952dcee5..d142bd68 100644
--- a/gui/src/ui/macos/mod.rs
+++ b/gui/src/ui/macos/mod.rs
@@ -2,8 +2,7 @@ pub use self::dialogs::*;
use self::modal::Modal;
use self::view::with_window;
-use super::DesktopWindow;
-use crate::rt::WinitWindow;
+use super::{DesktopExt, DesktopWindow};
use block::ConcreteBlock;
use objc::{msg_send, sel, sel_impl};
use std::ffi::c_long;
@@ -14,11 +13,11 @@ mod dialogs;
mod modal;
mod view;
-impl DesktopWindow for T {
+impl DesktopExt for T {
type Modal<'a, P>
= Modal<'a, Self, P>
where
- P: WinitWindow + 'a;
+ P: DesktopWindow + 'a;
fn set_center(&self) -> Result<(), PlatformError> {
with_window::<()>(self.handle(), |win| unsafe { msg_send![win, center] });
@@ -28,7 +27,7 @@ impl DesktopWindow for T {
fn set_modal(self, parent: &P) -> Result, PlatformError>
where
- P: WinitWindow,
+ P: DesktopWindow,
Self: Sized,
{
// Setup completionHandler.
@@ -45,6 +44,6 @@ impl DesktopWindow for T {
}
}
-/// macOS-specific error for [`DesktopWindow`].
+/// macOS-specific error for [`DesktopExt`].
#[derive(Debug, Error)]
pub enum PlatformError {}
diff --git a/gui/src/ui/macos/modal.rs b/gui/src/ui/macos/modal.rs
index c6d43a6a..3d19a26f 100644
--- a/gui/src/ui/macos/modal.rs
+++ b/gui/src/ui/macos/modal.rs
@@ -1,16 +1,17 @@
-use crate::rt::{block, Blocker, WinitWindow};
+use crate::rt::{block, Blocker};
+use crate::ui::DesktopWindow;
use std::ops::Deref;
/// Encapsulates a modal window and its parent.
///
/// This struct forces the modal window to be dropped before its parent.
-pub struct Modal<'a, W, P: WinitWindow> {
+pub struct Modal<'a, W, P: DesktopWindow> {
window: W,
#[allow(dead_code)]
blocker: Blocker<'a, P>,
}
-impl<'a, W, P: WinitWindow> Modal<'a, W, P> {
+impl<'a, W, P: DesktopWindow> Modal<'a, W, P> {
pub(super) fn new(window: W, parent: &'a P) -> Self {
Self {
window,
@@ -19,7 +20,7 @@ impl<'a, W, P: WinitWindow> Modal<'a, W, P> {
}
}
-impl<'a, W, P: WinitWindow> Deref for Modal<'a, W, P> {
+impl<'a, W, P: DesktopWindow> Deref for Modal<'a, W, P> {
type Target = W;
fn deref(&self) -> &Self::Target {
diff --git a/gui/src/ui/mod.rs b/gui/src/ui/mod.rs
index 59d367ee..9a1116f7 100644
--- a/gui/src/ui/mod.rs
+++ b/gui/src/ui/mod.rs
@@ -31,7 +31,7 @@ where
spawn_blocker(w, f);
}
-pub async fn error(parent: Option<&P>, msg: impl Into) {
+pub async fn error(parent: Option<&P>, msg: impl Into) {
let win = ErrorWindow::new().unwrap();
win.set_message(msg.into());
@@ -55,27 +55,40 @@ pub async fn error(parent: Option<&P>, msg: impl Into WinitWindow for T {
fn id(&self) -> WindowId {
let win = WindowInner::from_pub(self.window()).window_adapter();
+ let win = Window::from_adapter(win.as_ref());
- Window::from_adapter(win.as_ref()).id()
+ win.id()
}
+}
+impl DesktopWindow for T {
fn handle(&self) -> impl HasWindowHandle + '_ {
self.window().window_handle()
}
#[cfg(target_os = "linux")]
fn xdg_toplevel(&self) -> *mut std::ffi::c_void {
- let win = WindowInner::from_pub(self.window()).window_adapter();
+ use winit::platform::wayland::WindowExtWayland;
- Window::from_adapter(win.as_ref()).xdg_toplevel()
+ let win = WindowInner::from_pub(self.window()).window_adapter();
+ let win = Window::from_adapter(win.as_ref());
+
+ win.winit().xdg_toplevel()
}
}
-/// Provides methods to operate on a desktop window.
+/// Provides methods to return platform-specific handle for a desktop window.
pub trait DesktopWindow: WinitWindow {
+ fn handle(&self) -> impl HasWindowHandle + '_;
+ #[cfg(target_os = "linux")]
+ fn xdg_toplevel(&self) -> *mut std::ffi::c_void;
+}
+
+/// Provides methods to operate on a [`DesktopWindow`].
+pub trait DesktopExt: DesktopWindow {
type Modal<'a, P>: Deref
where
- P: WinitWindow + 'a;
+ P: DesktopWindow + 'a;
/// Center window on the screen.
///
@@ -84,7 +97,7 @@ pub trait DesktopWindow: WinitWindow {
fn set_center(&self) -> Result<(), PlatformError>;
fn set_modal(self, parent: &P) -> Result, PlatformError>
where
- P: WinitWindow,
+ P: DesktopWindow,
Self: Sized;
}
diff --git a/gui/src/ui/windows/dialogs.rs b/gui/src/ui/windows/dialogs.rs
index 976ad8fb..a93675d1 100644
--- a/gui/src/ui/windows/dialogs.rs
+++ b/gui/src/ui/windows/dialogs.rs
@@ -1,5 +1,4 @@
-use crate::rt::WinitWindow;
-use crate::ui::FileType;
+use crate::ui::{DesktopWindow, FileType};
use futures::channel::oneshot;
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use std::future::Future;
@@ -11,31 +10,7 @@ use windows_sys::Win32::UI::Shell::{
SHBrowseForFolderW, SHGetPathFromIDListW, BIF_NEWDIALOGSTYLE, BIF_RETURNONLYFSDIRS, BROWSEINFOW,
};
-fn get_hwnd(parent: &T) -> NonZero {
- let parent = parent.handle();
- let parent = parent.window_handle().unwrap();
- let RawWindowHandle::Win32(win) = parent.as_ref() else {
- unreachable!();
- };
-
- win.hwnd
-}
-
-fn spawn_dialog(dialog_fn: F) -> impl Future