1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

egui-winit: fix unsafe API of Clipboard::new (#2765)

* egui-winit: fix unsafe API of Clipboard::new

The old API allowed passing an arbitrary pointer. The new
API still breaks safety by allowing the object to outlive
the input, but is at least safer.

* Update crates/egui-winit/src/clipboard.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* Fix typo

* Update crates/egui-winit/src/clipboard.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* cargo fmt

* egui-winit: fix init_smithay_clipboard

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Diggory Hardy
2023-03-30 09:21:07 +01:00
committed by GitHub
parent 9ddf7abeee
commit fb726aaabb
3 changed files with 36 additions and 42 deletions

View File

@@ -9,8 +9,6 @@
#![allow(clippy::manual_range_contains)]
use std::os::raw::c_void;
#[cfg(feature = "accesskit")]
pub use accesskit_winit;
pub use egui;
@@ -85,11 +83,12 @@ pub struct State {
}
impl State {
/// Construct a new instance
///
/// # Safety
///
/// The returned `State` must not outlive the input `_event_loop`.
pub fn new<T>(event_loop: &EventLoopWindowTarget<T>) -> Self {
Self::new_with_wayland_display(wayland_display(event_loop))
}
pub fn new_with_wayland_display(wayland_display: Option<*mut c_void>) -> Self {
let egui_input = egui::RawInput {
has_focus: false, // winit will tell us when we have focus
..Default::default()
@@ -103,7 +102,7 @@ impl State {
current_cursor_icon: None,
current_pixels_per_point: 1.0,
clipboard: clipboard::Clipboard::new(wayland_display),
clipboard: clipboard::Clipboard::new(event_loop),
simulate_touch_screen: false,
pointer_touch_id: None,
@@ -871,28 +870,6 @@ fn translate_cursor(cursor_icon: egui::CursorIcon) -> Option<winit::window::Curs
}
}
/// Returns a Wayland display handle if the target is running Wayland
fn wayland_display<T>(_event_loop: &EventLoopWindowTarget<T>) -> Option<*mut c_void> {
#[cfg(feature = "wayland")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
{
use winit::platform::wayland::EventLoopWindowTargetExtWayland as _;
return _event_loop.wayland_display();
}
#[allow(unreachable_code)]
{
let _ = _event_loop;
None
}
}
// ---------------------------------------------------------------------------
/// Profiling macro for feature "puffin"