egui-winit: Use RawDisplayHandle for smithay clipboard init (#2914)
This commit is contained in:
parent
b8e798777d
commit
ede3ded977
|
|
@ -1242,6 +1242,7 @@ dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
"log",
|
"log",
|
||||||
"puffin",
|
"puffin",
|
||||||
|
"raw-window-handle",
|
||||||
"serde",
|
"serde",
|
||||||
"smithay-clipboard",
|
"smithay-clipboard",
|
||||||
"webbrowser",
|
"webbrowser",
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ webbrowser = { version = "0.8.3", optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
|
||||||
instant = { version = "0.1" }
|
instant = { version = "0.1" }
|
||||||
|
raw-window-handle = "0.5.0"
|
||||||
|
|
||||||
[target.'cfg(target_arch="wasm32")'.dependencies]
|
[target.'cfg(target_arch="wasm32")'.dependencies]
|
||||||
instant = { version = "0.1", features = [
|
instant = { version = "0.1", features = [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use winit::event_loop::EventLoopWindowTarget;
|
use raw_window_handle::HasRawDisplayHandle;
|
||||||
|
|
||||||
/// Handles interfacing with the OS clipboard.
|
/// Handles interfacing with the OS clipboard.
|
||||||
///
|
///
|
||||||
|
|
@ -29,8 +29,8 @@ impl Clipboard {
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The returned `Clipboard` must not outlive the input `_event_loop`.
|
/// The returned `Clipboard` must not outlive the input `_display_target`.
|
||||||
pub fn new<T>(_event_loop: &EventLoopWindowTarget<T>) -> Self {
|
pub fn new(_display_target: &dyn HasRawDisplayHandle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
#[cfg(all(feature = "arboard", not(target_os = "android")))]
|
#[cfg(all(feature = "arboard", not(target_os = "android")))]
|
||||||
arboard: init_arboard(),
|
arboard: init_arboard(),
|
||||||
|
|
@ -45,7 +45,7 @@ impl Clipboard {
|
||||||
),
|
),
|
||||||
feature = "smithay-clipboard"
|
feature = "smithay-clipboard"
|
||||||
))]
|
))]
|
||||||
smithay: init_smithay_clipboard(_event_loop),
|
smithay: init_smithay_clipboard(_display_target),
|
||||||
|
|
||||||
clipboard: Default::default(),
|
clipboard: Default::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -136,27 +136,20 @@ fn init_arboard() -> Option<arboard::Clipboard> {
|
||||||
),
|
),
|
||||||
feature = "smithay-clipboard"
|
feature = "smithay-clipboard"
|
||||||
))]
|
))]
|
||||||
fn init_smithay_clipboard<T>(
|
fn init_smithay_clipboard(
|
||||||
_event_loop: &EventLoopWindowTarget<T>,
|
_display_target: &dyn HasRawDisplayHandle,
|
||||||
) -> Option<smithay_clipboard::Clipboard> {
|
) -> Option<smithay_clipboard::Clipboard> {
|
||||||
// Note: ideally "smithay-clipboard" would imply "wayland", but it doesn't.
|
use raw_window_handle::RawDisplayHandle;
|
||||||
#[cfg(feature = "wayland")]
|
if let RawDisplayHandle::Wayland(display) = _display_target.raw_display_handle() {
|
||||||
{
|
log::debug!("Initializing smithay clipboard…");
|
||||||
use winit::platform::wayland::EventLoopWindowTargetExtWayland as _;
|
#[allow(unsafe_code)]
|
||||||
if let Some(display) = _event_loop.wayland_display() {
|
Some(unsafe { smithay_clipboard::Clipboard::new(display.display) })
|
||||||
log::debug!("Initializing smithay clipboard…");
|
} else {
|
||||||
#[allow(unsafe_code)]
|
#[cfg(feature = "wayland")]
|
||||||
Some(unsafe { smithay_clipboard::Clipboard::new(display) })
|
log::debug!("Cannot init smithay clipboard without a Wayland display handle");
|
||||||
} else {
|
#[cfg(not(feature = "wayland"))]
|
||||||
log::debug!("Cannot initialize smithay clipboard without a display handle");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "wayland"))]
|
|
||||||
{
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"You need to enable the 'wayland' feature of 'egui-winit' to get a working clipboard"
|
"Cannot init smithay clipboard: the 'wayland' feature of 'egui-winit' is not enabled"
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ mod window_settings;
|
||||||
|
|
||||||
pub use window_settings::WindowSettings;
|
pub use window_settings::WindowSettings;
|
||||||
|
|
||||||
use winit::event_loop::EventLoopWindowTarget;
|
use raw_window_handle::HasRawDisplayHandle;
|
||||||
|
|
||||||
pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
|
pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
|
||||||
window.scale_factor() as f32
|
window.scale_factor() as f32
|
||||||
|
|
@ -87,8 +87,8 @@ impl State {
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The returned `State` must not outlive the input `_event_loop`.
|
/// The returned `State` must not outlive the input `display_target`.
|
||||||
pub fn new<T>(event_loop: &EventLoopWindowTarget<T>) -> Self {
|
pub fn new(display_target: &dyn HasRawDisplayHandle) -> Self {
|
||||||
let egui_input = egui::RawInput {
|
let egui_input = egui::RawInput {
|
||||||
has_focus: false, // winit will tell us when we have focus
|
has_focus: false, // winit will tell us when we have focus
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
@ -102,7 +102,7 @@ impl State {
|
||||||
current_cursor_icon: None,
|
current_cursor_icon: None,
|
||||||
current_pixels_per_point: 1.0,
|
current_pixels_per_point: 1.0,
|
||||||
|
|
||||||
clipboard: clipboard::Clipboard::new(event_loop),
|
clipboard: clipboard::Clipboard::new(display_target),
|
||||||
|
|
||||||
simulate_touch_screen: false,
|
simulate_touch_screen: false,
|
||||||
pointer_touch_id: None,
|
pointer_touch_id: None,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue