window: de-Future most of the WindowOps methods

This commit is contained in:
Wez Furlong committed 2021-07-10 17:30:19 -07:00
1 parent 4e99edf6f5
commit ad19b4f57b
6 files changed
+115 -169

No files matched your search

+13 -23
View File
@@ -108,7 +108,7 @@ pub struct GraphicsDriversLostContext {}
#[async_trait(?Send)]
pub trait WindowOps {
/// Show a hidden window
fn show(&self) -> Future<()>;
fn show(&self);
fn notify<T: Any + Send + Sync>(&self, t: T)
where
@@ -123,58 +123,48 @@ pub trait WindowOps {
}
/// Hide a visible window
fn hide(&self) -> Future<()>;
fn hide(&self);
/// Schedule the window to be closed
fn close(&self) -> Future<()>;
fn close(&self);
/// Change the cursor
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()>;
fn set_cursor(&self, cursor: Option<MouseCursor>);
/// Invalidate the window so that the entire client area will
/// be repainted shortly
fn invalidate(&self) -> Future<()>;
fn invalidate(&self);
/// Change the titlebar text for the window
fn set_title(&self, title: &str) -> Future<()>;
fn set_title(&self, title: &str);
fn default_key_processing(&self, _key: KeyEvent) {}
/// Resize the inner or client area of the window
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions>;
fn set_inner_size(&self, width: usize, height: usize);
/// Changes the location of the window on the screen.
/// The coordinates are of the top left pixel of the
/// client area.
fn set_window_position(&self, _coords: ScreenPoint) -> Future<()> {
Future::ok(())
}
fn set_window_position(&self, _coords: ScreenPoint) {}
/// inform the windowing system of the current textual
/// cursor input location. This is used primarily for
/// the platform specific input method editor
fn set_text_cursor_position(&self, _cursor: Rect) -> Future<()> {
Future::ok(())
}
fn set_text_cursor_position(&self, _cursor: Rect) {}
/// Initiate textual transfer from the clipboard
fn get_clipboard(&self, clipboard: Clipboard) -> Future<String>;
/// Set some text in the clipboard
fn set_clipboard(&self, clipboard: Clipboard, text: String) -> Future<()>;
fn set_clipboard(&self, clipboard: Clipboard, text: String);
/// Set the icon for the window.
/// Depending on the system this may be shown in its titlebar
/// and/or in the task manager/task switcher
fn set_icon(&self, _image: Image) -> Future<()> {
Future::ok(())
}
fn set_icon(&self, _image: Image) {}
fn toggle_fullscreen(&self) -> Future<()> {
Future::ok(())
}
fn toggle_fullscreen(&self) {}
fn config_did_change(&self, _config: &config::ConfigHandle) -> Future<()> {
Future::ok(())
}
fn config_did_change(&self, _config: &config::ConfigHandle) {}
}
+26 -28
View File
@@ -562,65 +562,65 @@ impl WindowOps for Window {
}
}
fn close(&self) -> Future<()> {
fn close(&self) {
Connection::with_window_inner(self.0, |inner| {
inner.close();
Ok(())
})
});
}
fn hide(&self) -> Future<()> {
fn hide(&self) {
Connection::with_window_inner(self.0, |inner| {
inner.hide();
Ok(())
})
});
}
fn show(&self) -> Future<()> {
fn show(&self) {
Connection::with_window_inner(self.0, |inner| {
inner.show();
Ok(())
})
});
}
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()> {
fn set_cursor(&self, cursor: Option<MouseCursor>) {
Connection::with_window_inner(self.0, move |inner| {
let _ = inner.set_cursor(cursor);
Ok(())
})
});
}
fn invalidate(&self) -> Future<()> {
fn invalidate(&self) {
Connection::with_window_inner(self.0, |inner| {
inner.invalidate();
Ok(())
})
});
}
fn set_title(&self, title: &str) -> Future<()> {
fn set_title(&self, title: &str) {
let title = title.to_owned();
Connection::with_window_inner(self.0, move |inner| {
inner.set_title(&title);
Ok(())
})
});
}
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions> {
Connection::with_window_inner(self.0, move |inner| Ok(inner.set_inner_size(width, height)))
fn set_inner_size(&self, width: usize, height: usize) {
Connection::with_window_inner(self.0, move |inner| Ok(inner.set_inner_size(width, height)));
}
fn set_window_position(&self, coords: ScreenPoint) -> Future<()> {
fn set_window_position(&self, coords: ScreenPoint) {
Connection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords);
Ok(())
})
});
}
fn set_text_cursor_position(&self, cursor: Rect) -> Future<()> {
fn set_text_cursor_position(&self, cursor: Rect) {
Connection::with_window_inner(self.0, move |inner| {
inner.set_text_cursor_position(cursor);
Ok(())
})
});
}
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
@@ -632,28 +632,26 @@ impl WindowOps for Window {
)
}
fn set_clipboard(&self, _clipboard: Clipboard, text: String) -> Future<()> {
fn set_clipboard(&self, _clipboard: Clipboard, text: String) {
use clipboard::ClipboardProvider;
Future::result(
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.set_contents(text))
.map_err(|e| anyhow!("Failed to set clipboard:{}", e)),
)
clipboard::ClipboardContext::new()
.and_then(|mut ctx| ctx.set_contents(text))
.ok();
}
fn toggle_fullscreen(&self) -> Future<()> {
fn toggle_fullscreen(&self) {
Connection::with_window_inner(self.0, move |inner| {
inner.toggle_fullscreen();
Ok(())
})
});
}
fn config_did_change(&self, config: &ConfigHandle) -> Future<()> {
fn config_did_change(&self, config: &ConfigHandle) {
let config = config.clone();
Connection::with_window_inner(self.0, move |inner| {
inner.config_did_change(&config);
Ok(())
})
});
}
}
+20 -20
View File
@@ -698,67 +698,67 @@ impl WindowOps for WaylandWindow {
}
}
fn close(&self) -> Future<()> {
fn close(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.close();
Ok(())
})
});
}
fn hide(&self) -> Future<()> {
fn hide(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.hide();
Ok(())
})
});
}
fn toggle_fullscreen(&self) -> Future<()> {
fn toggle_fullscreen(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.toggle_fullscreen();
Ok(())
})
});
}
fn show(&self) -> Future<()> {
fn show(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.show();
Ok(())
})
});
}
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()> {
fn set_cursor(&self, cursor: Option<MouseCursor>) {
WaylandConnection::with_window_inner(self.0, move |inner| {
inner.set_cursor(cursor);
Ok(())
})
});
}
fn invalidate(&self) -> Future<()> {
fn invalidate(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.invalidate();
Ok(())
})
});
}
fn set_title(&self, title: &str) -> Future<()> {
fn set_title(&self, title: &str) {
let title = title.to_owned();
WaylandConnection::with_window_inner(self.0, move |inner| {
inner.set_title(&title);
Ok(())
})
});
}
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions> {
fn set_inner_size(&self, width: usize, height: usize) {
WaylandConnection::with_window_inner(self.0, move |inner| {
Ok(inner.set_inner_size(width, height))
})
});
}
fn set_window_position(&self, coords: ScreenPoint) -> Future<()> {
fn set_window_position(&self, coords: ScreenPoint) {
WaylandConnection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords);
Ok(())
})
});
}
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
@@ -788,7 +788,7 @@ impl WindowOps for WaylandWindow {
future
}
fn set_clipboard(&self, _clipboard: Clipboard, text: String) -> Future<()> {
fn set_clipboard(&self, _clipboard: Clipboard, text: String) {
WaylandConnection::with_window_inner(self.0, move |inner| {
let text = text.clone();
let conn = Connection::get().unwrap().wayland();
@@ -810,7 +810,7 @@ impl WindowOps for WaylandWindow {
inner.copy_and_paste.lock().unwrap().set_selection(&source);
Ok(())
})
});
}
}
+20 -52
View File
@@ -603,74 +603,67 @@ impl WindowOps for Window {
}
}
fn close(&self) -> Future<()> {
fn close(&self) {
Connection::with_window_inner(self.0, |inner| {
inner.close();
Ok(())
})
});
}
fn show(&self) -> Future<()> {
fn show(&self) {
schedule_show_window(self.0, true);
Future::ok(()) // FIXME: this is a lie!
}
fn hide(&self) -> Future<()> {
fn hide(&self) {
schedule_show_window(self.0, false);
Future::ok(()) // FIXME: this is a lie!
}
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()> {
fn set_cursor(&self, cursor: Option<MouseCursor>) {
Connection::with_window_inner(self.0, move |inner| {
inner.set_cursor(cursor);
Ok(())
})
});
}
fn invalidate(&self) -> Future<()> {
fn invalidate(&self) {
let hwnd = self.0 .0;
log::trace!("WindowOps::invalidate calling InvalidateRect");
unsafe {
InvalidateRect(hwnd, null(), 0);
}
Future::ok(())
}
fn set_title(&self, title: &str) -> Future<()> {
fn set_title(&self, title: &str) {
let title = title.to_owned();
Connection::with_window_inner(self.0, move |inner| {
inner.set_title(&title);
Ok(())
})
});
}
fn toggle_fullscreen(&self) -> Future<()> {
fn toggle_fullscreen(&self) {
Connection::with_window_inner(self.0, move |inner| {
inner.toggle_fullscreen();
Ok(())
})
});
}
fn config_did_change(&self, config: &ConfigHandle) -> Future<()> {
fn config_did_change(&self, config: &ConfigHandle) {
let config = config.clone();
Connection::with_window_inner(self.0, move |inner| {
inner.config_did_change(&config);
Ok(())
})
});
}
fn set_text_cursor_position(&self, cursor: Rect) -> Future<()> {
fn set_text_cursor_position(&self, cursor: Rect) {
Connection::with_window_inner(self.0, move |inner| {
inner.set_text_cursor_position(cursor);
Ok(())
})
});
}
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions> {
let mut promise = Promise::new();
let future = promise.get_future().unwrap();
let mut promise = Some(promise);
fn set_inner_size(&self, width: usize, height: usize) {
Connection::with_window_inner(self.0, move |inner| {
let (width, height) = adjust_client_to_window_dimensions(
decorations_to_style(inner.config.window_decorations),
@@ -678,7 +671,6 @@ impl WindowOps for Window {
height,
);
let hwnd = inner.hwnd;
let mut promise = promise.take();
promise::spawn::spawn(async move {
unsafe {
SetWindowPos(
@@ -692,39 +684,17 @@ impl WindowOps for Window {
);
wm_paint(hwnd.0, 0, 0, 0);
}
let mut rect = RECT {
left: 0,
bottom: 0,
right: 0,
top: 0,
};
unsafe {
GetClientRect(hwnd.0, &mut rect);
}
let pixel_width = rect_width(&rect) as usize;
let pixel_height = rect_height(&rect) as usize;
if let Some(mut promise) = promise.take() {
promise.ok(Dimensions {
pixel_width,
pixel_height,
dpi: unsafe { GetDpiForWindow(hwnd.0) as usize },
});
}
})
.detach();
Ok(())
});
future
}
fn set_window_position(&self, coords: ScreenPoint) -> Future<()> {
fn set_window_position(&self, coords: ScreenPoint) {
Connection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords);
Ok(())
})
});
}
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
@@ -735,10 +705,8 @@ impl WindowOps for Window {
)
}
fn set_clipboard(&self, _clipboard: Clipboard, text: String) -> Future<()> {
Future::result(
clipboard_win::set_clipboard_string(&text).context("Error setting clipboard"),
)
fn set_clipboard(&self, _clipboard: Clipboard, text: String) {
clipboard_win::set_clipboard_string(&text).ok();
}
}
+23 -33
View File
@@ -919,74 +919,66 @@ impl WindowOps for XWindow {
}
}
fn close(&self) -> Future<()> {
fn close(&self) {
XConnection::with_window_inner(self.0, |inner| {
inner.close();
Ok(())
})
});
}
fn hide(&self) -> Future<()> {
fn hide(&self) {
XConnection::with_window_inner(self.0, |inner| {
inner.hide();
Ok(())
})
});
}
fn toggle_fullscreen(&self) -> Future<()> {
fn toggle_fullscreen(&self) {
XConnection::with_window_inner(self.0, |inner| {
inner.toggle_fullscreen();
Ok(())
})
});
}
fn config_did_change(&self, config: &ConfigHandle) -> Future<()> {
fn config_did_change(&self, config: &ConfigHandle) {
let config = config.clone();
XConnection::with_window_inner(self.0, move |inner| {
inner.config_did_change(&config);
Ok(())
})
});
}
fn show(&self) -> Future<()> {
fn show(&self) {
XConnection::with_window_inner(self.0, |inner| {
inner.show();
Ok(())
})
});
}
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()> {
fn set_cursor(&self, cursor: Option<MouseCursor>) {
XConnection::with_window_inner(self.0, move |inner| {
let _ = inner.set_cursor(cursor);
Ok(())
})
});
}
fn invalidate(&self) -> Future<()> {
fn invalidate(&self) {
XConnection::with_window_inner(self.0, |inner| {
inner.invalidate();
Ok(())
})
});
}
fn set_title(&self, title: &str) -> Future<()> {
fn set_title(&self, title: &str) {
let title = title.to_owned();
XConnection::with_window_inner(self.0, move |inner| {
inner.set_title(&title);
Ok(())
})
});
}
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions> {
let mut promise = Promise::new();
let future = promise.get_future().unwrap();
let mut promise = Some(promise);
fn set_inner_size(&self, width: usize, height: usize) {
XConnection::with_window_inner(self.0, move |inner| {
if let Some(promise) = promise.take() {
inner.resize_promises.push(promise);
}
xcb::configure_window(
inner.conn().conn(),
inner.window_id,
@@ -997,22 +989,20 @@ impl WindowOps for XWindow {
);
Ok(())
});
future
}
fn set_window_position(&self, coords: ScreenPoint) -> Future<()> {
fn set_window_position(&self, coords: ScreenPoint) {
XConnection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords);
Ok(())
})
});
}
fn set_icon(&self, image: Image) -> Future<()> {
fn set_icon(&self, image: Image) {
XConnection::with_window_inner(self.0, move |inner| {
inner.set_icon(&image);
Ok(())
})
});
}
/// Initiate textual transfer from the clipboard
@@ -1054,7 +1044,7 @@ impl WindowOps for XWindow {
}
/// Set some text in the clipboard
fn set_clipboard(&self, clipboard: Clipboard, text: String) -> Future<()> {
fn set_clipboard(&self, clipboard: Clipboard, text: String) {
XConnection::with_window_inner(self.0, move |inner| {
inner
.copy_and_paste
@@ -1062,6 +1052,6 @@ impl WindowOps for XWindow {
.replace(text.clone());
inner.update_selection_owner(clipboard);
Ok(())
})
});
}
}
+13 -13
View File
@@ -7,7 +7,7 @@ use crate::os::wayland::connection::WaylandConnection;
use crate::os::wayland::window::WaylandWindow;
use crate::os::x11::connection::XConnection;
use crate::os::x11::window::XWindow;
use crate::{Clipboard, Dimensions, MouseCursor, ScreenPoint, WindowEventReceiver, WindowOps};
use crate::{Clipboard, MouseCursor, ScreenPoint, WindowEventReceiver, WindowOps};
use async_trait::async_trait;
use config::ConfigHandle;
use promise::*;
@@ -146,7 +146,7 @@ impl WindowOps for Window {
}
}
fn close(&self) -> Future<()> {
fn close(&self) {
match self {
Self::X11(x) => x.close(),
#[cfg(feature = "wayland")]
@@ -164,7 +164,7 @@ impl WindowOps for Window {
}
}
fn hide(&self) -> Future<()> {
fn hide(&self) {
match self {
Self::X11(x) => x.hide(),
#[cfg(feature = "wayland")]
@@ -172,7 +172,7 @@ impl WindowOps for Window {
}
}
fn toggle_fullscreen(&self) -> Future<()> {
fn toggle_fullscreen(&self) {
match self {
Self::X11(x) => x.toggle_fullscreen(),
#[cfg(feature = "wayland")]
@@ -180,7 +180,7 @@ impl WindowOps for Window {
}
}
fn config_did_change(&self, config: &ConfigHandle) -> Future<()> {
fn config_did_change(&self, config: &ConfigHandle) {
match self {
Self::X11(x) => x.config_did_change(config),
#[cfg(feature = "wayland")]
@@ -188,7 +188,7 @@ impl WindowOps for Window {
}
}
fn show(&self) -> Future<()> {
fn show(&self) {
match self {
Self::X11(x) => x.show(),
#[cfg(feature = "wayland")]
@@ -196,7 +196,7 @@ impl WindowOps for Window {
}
}
fn set_cursor(&self, cursor: Option<MouseCursor>) -> Future<()> {
fn set_cursor(&self, cursor: Option<MouseCursor>) {
match self {
Self::X11(x) => x.set_cursor(cursor),
#[cfg(feature = "wayland")]
@@ -204,7 +204,7 @@ impl WindowOps for Window {
}
}
fn invalidate(&self) -> Future<()> {
fn invalidate(&self) {
match self {
Self::X11(x) => x.invalidate(),
#[cfg(feature = "wayland")]
@@ -212,7 +212,7 @@ impl WindowOps for Window {
}
}
fn set_title(&self, title: &str) -> Future<()> {
fn set_title(&self, title: &str) {
match self {
Self::X11(x) => x.set_title(title),
#[cfg(feature = "wayland")]
@@ -220,7 +220,7 @@ impl WindowOps for Window {
}
}
fn set_icon(&self, image: crate::bitmaps::Image) -> Future<()> {
fn set_icon(&self, image: crate::bitmaps::Image) {
match self {
Self::X11(x) => x.set_icon(image),
#[cfg(feature = "wayland")]
@@ -228,7 +228,7 @@ impl WindowOps for Window {
}
}
fn set_inner_size(&self, width: usize, height: usize) -> Future<Dimensions> {
fn set_inner_size(&self, width: usize, height: usize) {
match self {
Self::X11(x) => x.set_inner_size(width, height),
#[cfg(feature = "wayland")]
@@ -236,7 +236,7 @@ impl WindowOps for Window {
}
}
fn set_window_position(&self, coords: ScreenPoint) -> Future<()> {
fn set_window_position(&self, coords: ScreenPoint) {
match self {
Self::X11(x) => x.set_window_position(coords),
#[cfg(feature = "wayland")]
@@ -251,7 +251,7 @@ impl WindowOps for Window {
Self::Wayland(w) => w.get_clipboard(clipboard),
}
}
fn set_clipboard(&self, clipboard: Clipboard, text: String) -> Future<()> {
fn set_clipboard(&self, clipboard: Clipboard, text: String) {
match self {
Self::X11(x) => x.set_clipboard(clipboard, text),
#[cfg(feature = "wayland")]