fix(wayland): remove unwraps
This commit is contained in:
@@ -216,7 +216,9 @@ fn main() {
|
||||
);
|
||||
#[cfg(feature = "wayland")]
|
||||
{
|
||||
startup_command.env("WAYLAND_DISPLAY", &wayland.socket_name);
|
||||
if let Some(wayland_socket) = wayland.socket_name.as_ref() {
|
||||
startup_command.env("WAYLAND_DISPLAY", &wayland_socket);
|
||||
}
|
||||
#[cfg(feature = "xwayland")]
|
||||
startup_command.env("DISPLAY", format!(":{}", wayland.xwayland_state.display));
|
||||
startup_command.env("GDK_BACKEND", "wayland");
|
||||
|
||||
@@ -25,11 +25,9 @@ impl CompositorHandler for WaylandState {
|
||||
.data_map
|
||||
.insert_if_missing_threadsafe(|| AtomicU32::new(0));
|
||||
if !count_new {
|
||||
count = data
|
||||
.data_map
|
||||
.get::<AtomicU32>()
|
||||
.unwrap()
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
if let Some(stored_count) = data.data_map.get::<AtomicU32>() {
|
||||
count = stored_count.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
data.data_map.get::<Arc<CoreSurface>>().cloned()
|
||||
|
||||
@@ -90,7 +90,8 @@ impl KdeDecorationHandler for WaylandState {
|
||||
decoration: &OrgKdeKwinServerDecoration,
|
||||
mode: WEnum<KdeMode>,
|
||||
) {
|
||||
decoration.mode(mode.into_result().unwrap());
|
||||
let Ok(mode) = mode.into_result() else {return};
|
||||
decoration.mode(mode);
|
||||
}
|
||||
}
|
||||
delegate_kde_decoration!(WaylandState);
|
||||
|
||||
@@ -23,7 +23,8 @@ use smithay::backend::renderer::gles::GlesRenderer;
|
||||
use smithay::backend::renderer::ImportDma;
|
||||
use smithay::reexports::wayland_server::backend::ClientId;
|
||||
use smithay::reexports::wayland_server::DisplayHandle;
|
||||
use smithay::reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket};
|
||||
use smithay::reexports::wayland_server::{Display, ListeningSocket};
|
||||
use std::ffi::OsStr;
|
||||
use std::os::fd::OwnedFd;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
use std::{
|
||||
@@ -36,7 +37,7 @@ use tokio::sync::mpsc::UnboundedReceiver;
|
||||
use tokio::{
|
||||
io::unix::AsyncFd, net::UnixListener as AsyncUnixListener, sync::mpsc, task::JoinHandle,
|
||||
};
|
||||
use tracing::{debug, debug_span, info, instrument};
|
||||
use tracing::{debug_span, info, instrument};
|
||||
|
||||
pub static WAYLAND_DISPLAY: OnceCell<String> = OnceCell::new();
|
||||
pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0);
|
||||
@@ -62,8 +63,6 @@ fn get_sk_egl() -> Result<EGLRawHandles> {
|
||||
})
|
||||
}
|
||||
|
||||
static GLOBAL_DESTROY_QUEUE: OnceCell<mpsc::Sender<GlobalId>> = OnceCell::new();
|
||||
|
||||
pub struct DisplayWrapper(Mutex<Display<WaylandState>>, DisplayHandle);
|
||||
impl DisplayWrapper {
|
||||
pub fn handle(&self) -> DisplayHandle {
|
||||
@@ -84,7 +83,7 @@ impl DisplayWrapper {
|
||||
|
||||
pub struct Wayland {
|
||||
display: Arc<DisplayWrapper>,
|
||||
pub socket_name: String,
|
||||
pub socket_name: Option<String>,
|
||||
join_handle: JoinHandle<Result<()>>,
|
||||
renderer: GlesRenderer,
|
||||
dmabuf_rx: UnboundedReceiver<Dmabuf>,
|
||||
@@ -112,22 +111,17 @@ impl Wayland {
|
||||
let xwayland_state = xwayland::XWaylandState::create(&display_handle)?;
|
||||
let wayland_state = WaylandState::new(display_handle, &renderer, dmabuf_tx);
|
||||
|
||||
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
|
||||
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
|
||||
|
||||
let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
|
||||
let socket_name = socket.socket_name().unwrap().to_str().unwrap().to_string();
|
||||
WAYLAND_DISPLAY
|
||||
.set(socket_name.clone())
|
||||
.expect("seriously message nova this time they screwed up big time");
|
||||
let socket_name = socket
|
||||
.socket_name()
|
||||
.and_then(OsStr::to_str)
|
||||
.map(ToString::to_string);
|
||||
if let Some(socket_name) = &socket_name {
|
||||
let _ = WAYLAND_DISPLAY.set(socket_name.clone());
|
||||
}
|
||||
info!(socket_name, "Wayland active");
|
||||
|
||||
let join_handle = Wayland::start_loop(
|
||||
display.clone(),
|
||||
socket,
|
||||
wayland_state.clone(),
|
||||
global_destroy_queue,
|
||||
)?;
|
||||
let join_handle = Wayland::start_loop(display.clone(), socket, wayland_state.clone())?;
|
||||
|
||||
Ok(Wayland {
|
||||
display,
|
||||
@@ -145,7 +139,6 @@ impl Wayland {
|
||||
display: Arc<DisplayWrapper>,
|
||||
socket: ListeningSocket,
|
||||
state: Arc<Mutex<WaylandState>>,
|
||||
mut global_destroy_queue: mpsc::Receiver<GlobalId>,
|
||||
) -> Result<JoinHandle<Result<()>>> {
|
||||
let listen_async =
|
||||
AsyncUnixListener::from_std(unsafe { UnixListener::from_raw_fd(socket.as_raw_fd()) })?;
|
||||
@@ -160,10 +153,6 @@ impl Wayland {
|
||||
let _socket = socket; // Keep the socket alive
|
||||
loop {
|
||||
tokio::select! {
|
||||
e = global_destroy_queue.recv() => { // New global to destroy
|
||||
debug!(?e, "destroy global");
|
||||
dh1.remove_global::<WaylandState>(e.unwrap());
|
||||
}
|
||||
acc = listen_async.accept() => { // New client connected
|
||||
let (stream, _) = acc?;
|
||||
let client_state = Arc::new(ClientState {
|
||||
@@ -173,7 +162,7 @@ impl Wayland {
|
||||
seat: SeatData::new(&dh1)
|
||||
});
|
||||
let client = dh2.insert_client(stream.into_std()?, client_state.clone())?;
|
||||
client_state.seat.client.set(client.id()).unwrap();
|
||||
let _ = client_state.seat.client.set(client.id());
|
||||
}
|
||||
e = dispatch_poll_listener.readable() => { // Dispatch
|
||||
let mut guard = e?;
|
||||
@@ -211,7 +200,7 @@ impl Wayland {
|
||||
|
||||
pub fn make_context_current(&self) {
|
||||
unsafe {
|
||||
self.renderer.egl_context().make_current().unwrap();
|
||||
let _ = self.renderer.egl_context().make_current();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::{
|
||||
state::{ClientState, WaylandState},
|
||||
surface::CoreSurface,
|
||||
GLOBAL_DESTROY_QUEUE, SERIAL_COUNTER,
|
||||
SERIAL_COUNTER,
|
||||
};
|
||||
use crate::{
|
||||
core::task,
|
||||
@@ -290,10 +290,9 @@ impl SeatData {
|
||||
touch: OnceCell::new(),
|
||||
});
|
||||
|
||||
seat_data
|
||||
let _ = seat_data
|
||||
.global_id
|
||||
.set(dh.create_global::<WaylandState, _, _>(7, seat_data.clone()))
|
||||
.unwrap();
|
||||
.set(dh.create_global::<WaylandState, _, _>(7, seat_data.clone()));
|
||||
|
||||
seat_data
|
||||
}
|
||||
@@ -420,14 +419,6 @@ impl SeatData {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Drop for SeatData {
|
||||
fn drop(&mut self) {
|
||||
let id = self.global_id.take().unwrap();
|
||||
let _ = task::new(|| "global destroy queue garbage collection", async move {
|
||||
GLOBAL_DESTROY_QUEUE.get().unwrap().send(id).await
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CursorInfo {
|
||||
pub surface: WlWeak<WlSurface>,
|
||||
|
||||
@@ -95,13 +95,9 @@ impl WaylandState {
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let dmabuf_default_feedback = match render_node {
|
||||
Ok(Some(node)) => {
|
||||
let dmabuf_default_feedback =
|
||||
DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
Some(dmabuf_default_feedback)
|
||||
}
|
||||
Ok(Some(node)) => DmabufFeedbackBuilder::new(node.dev_id(), dmabuf_formats.clone())
|
||||
.build()
|
||||
.ok(),
|
||||
Ok(None) => {
|
||||
warn!("failed to query render node, dmabuf will use v3");
|
||||
None
|
||||
|
||||
@@ -18,10 +18,10 @@ use smithay::{
|
||||
reexports::wayland_server::{self, protocol::wl_surface::WlSurface, DisplayHandle, Resource},
|
||||
wayland::compositor::{self, SurfaceData},
|
||||
};
|
||||
use std::{ffi::c_void, sync::Arc, time::Duration};
|
||||
use std::{cell::RefCell, ffi::c_void, sync::Arc, time::Duration};
|
||||
use stereokit::{
|
||||
Material, StereoKitDraw, Tex, TextureAddress, TextureFormat, TextureSample, TextureType,
|
||||
Transparency,
|
||||
Material, Shader, StereoKitDraw, Tex, TextureAddress, TextureFormat, TextureSample,
|
||||
TextureType, Transparency,
|
||||
};
|
||||
|
||||
pub static CORE_SURFACES: Registry<CoreSurface> = Registry::new();
|
||||
@@ -89,12 +89,12 @@ impl CoreSurface {
|
||||
.sk_tex
|
||||
.get_or_init(|| sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32));
|
||||
self.sk_mat.get_or_init(|| {
|
||||
let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES).unwrap();
|
||||
let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES);
|
||||
// let _ = renderer.with_context(|c| unsafe {
|
||||
// shader_inject(c, &mut shader, SIMULA_VERT_STR, SIMULA_FRAG_STR)
|
||||
// });
|
||||
|
||||
let mat = sk.material_create(&shader);
|
||||
let mat = sk.material_create(shader.as_ref().unwrap_or(Shader::UI.as_ref()));
|
||||
sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref());
|
||||
sk.material_set_transparency(&mat, Transparency::Blend);
|
||||
Arc::new(mat)
|
||||
@@ -121,18 +121,16 @@ impl CoreSurface {
|
||||
let mut mapped_data = self.mapped_data.lock();
|
||||
let just_mapped = mapped_data.is_none();
|
||||
self.with_states(|data| {
|
||||
let renderer_surface_state = data
|
||||
let Some(renderer_surface_state) = data
|
||||
.data_map
|
||||
.get::<RendererSurfaceStateUserData>()
|
||||
.unwrap()
|
||||
.borrow();
|
||||
let smithay_tex = renderer_surface_state
|
||||
.map(RefCell::borrow) else {return};
|
||||
let Some(smithay_tex) = renderer_surface_state
|
||||
.texture::<GlesRenderer>(renderer.id())
|
||||
.unwrap()
|
||||
.clone();
|
||||
.cloned() else {return};
|
||||
|
||||
let sk_tex = self.sk_tex.get().unwrap();
|
||||
let sk_mat = self.sk_mat.get().unwrap();
|
||||
let Some(sk_tex) = self.sk_tex.get() else {return};
|
||||
let Some(sk_mat) = self.sk_mat.get() else {return};
|
||||
unsafe {
|
||||
sk.tex_set_surface(
|
||||
sk_tex.as_ref(),
|
||||
@@ -151,7 +149,7 @@ impl CoreSurface {
|
||||
sk.material_set_queue_offset(sk_mat.as_ref().as_ref(), *material_offset as i32);
|
||||
}
|
||||
|
||||
let surface_size = renderer_surface_state.surface_size().unwrap();
|
||||
let Some(surface_size) = renderer_surface_state.surface_size() else {return};
|
||||
let new_mapped_data = CoreSurfaceData {
|
||||
size: Vector2::from([surface_size.w as u32, surface_size.h as u32]),
|
||||
wl_tex: Some(SendWrapper::new(smithay_tex)),
|
||||
@@ -186,10 +184,12 @@ impl CoreSurface {
|
||||
}
|
||||
|
||||
fn apply_surface_materials(&self) {
|
||||
for model_node in self.pending_material_applications.get_valid_contents() {
|
||||
model_node.replace_material(self.sk_mat.clone().get().unwrap().clone());
|
||||
if let Some(sk_mat) = self.sk_mat.get() {
|
||||
for model_node in self.pending_material_applications.get_valid_contents() {
|
||||
model_node.replace_material(sk_mat.clone());
|
||||
}
|
||||
self.pending_material_applications.clear();
|
||||
}
|
||||
self.pending_material_applications.clear();
|
||||
}
|
||||
|
||||
pub fn wl_surface(&self) -> Option<WlSurface> {
|
||||
|
||||
@@ -267,8 +267,8 @@ impl Dispatch<XdgPositioner, Mutex<PositionerData>, WaylandState> for WaylandSta
|
||||
?positioner,
|
||||
constraint_adjustment, "Set positioner constraint adjustment"
|
||||
);
|
||||
data.lock().constraint_adjustment =
|
||||
ConstraintAdjustment::from_bits(constraint_adjustment).unwrap();
|
||||
let Some(constraint_adjustment) = ConstraintAdjustment::from_bits(constraint_adjustment) else {return};
|
||||
data.lock().constraint_adjustment = constraint_adjustment;
|
||||
}
|
||||
xdg_positioner::Request::SetOffset { x, y } => {
|
||||
debug!(?positioner, x, y, "Set positioner offset");
|
||||
@@ -372,7 +372,7 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
{
|
||||
let toplevel = toplevel.downgrade();
|
||||
move || {
|
||||
let toplevel = toplevel.upgrade().unwrap();
|
||||
let Ok(toplevel) = toplevel.upgrade() else {return};
|
||||
let toplevel_data = ToplevelData::get(&toplevel);
|
||||
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
||||
let Some(xdg_surface_data) = XdgSurfaceData::get(&xdg_surface) else {return};
|
||||
@@ -394,7 +394,7 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
{
|
||||
let toplevel = toplevel.downgrade();
|
||||
move |_| {
|
||||
let toplevel = toplevel.upgrade().unwrap();
|
||||
let Ok(toplevel) = toplevel.upgrade() else {return};
|
||||
let toplevel_data = ToplevelData::get(&toplevel);
|
||||
let Some(panel_item) = toplevel_data.lock().panel_item() else {
|
||||
let Some(xdg_surface) = toplevel_data.lock().xdg_surface() else {return};
|
||||
@@ -426,20 +426,10 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
parent,
|
||||
positioner,
|
||||
} => {
|
||||
let parent_clone = parent.clone().unwrap();
|
||||
let parent_data = parent_clone.data::<Mutex<XdgSurfaceData>>().unwrap().lock();
|
||||
// let positioner_data = positioner
|
||||
// .data::<Mutex<PositionerData>>()
|
||||
// .unwrap()
|
||||
// .lock()
|
||||
// .clone();
|
||||
// let parent = match &*parent_data {
|
||||
// XdgSurfaceType::Toplevel(_) => SurfaceID::Toplevel,
|
||||
// XdgSurfaceType::Popup(p) => {
|
||||
// SurfaceID::Popup(p.upgrade().unwrap().uid.clone())
|
||||
// }
|
||||
// XdgSurfaceType::Unknown => return,
|
||||
// };
|
||||
let Some(parent) = parent else {return};
|
||||
let Some(parent_data) = parent.data::<Mutex<XdgSurfaceData>>() else {return};
|
||||
let parent_data = parent_data.lock();
|
||||
|
||||
let uid = nanoid!();
|
||||
let popup_data = Mutex::new(PopupData::new(
|
||||
uid.clone(),
|
||||
@@ -447,13 +437,11 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
parent_data.surface_id.clone(),
|
||||
positioner,
|
||||
));
|
||||
let panel_item = parent_data.panel_item().unwrap();
|
||||
let Some(panel_item) = parent_data.panel_item() else {return};
|
||||
let Some(popup_wl_surface) = popup_data.lock().wl_surface() else {return};
|
||||
handle_cursor(
|
||||
&panel_item,
|
||||
panel_item
|
||||
.backend
|
||||
.seat
|
||||
.new_surface(&popup_data.lock().wl_surface().unwrap()),
|
||||
panel_item.backend.seat.new_surface(&popup_wl_surface),
|
||||
);
|
||||
let xdg_popup = data_init.init(id, popup_data);
|
||||
xdg_surface_data.lock().surface_id = SurfaceID::Child(uid);
|
||||
@@ -462,12 +450,13 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
debug!(?xdg_popup, ?xdg_surface, "Create XDG popup");
|
||||
|
||||
let xdg_surface = xdg_surface.downgrade();
|
||||
let xdg_popup = xdg_popup.downgrade();
|
||||
let xdg_popup: WlWeak<XdgPopup> = xdg_popup.downgrade();
|
||||
let Ok(wl_surface) = xdg_surface_data.lock().wl_surface.upgrade() else {return};
|
||||
CoreSurface::add_to(
|
||||
state.display_handle.clone(),
|
||||
&xdg_surface_data.lock().wl_surface.upgrade().unwrap(),
|
||||
&wl_surface,
|
||||
move || {
|
||||
let xdg_popup = xdg_popup.upgrade().unwrap();
|
||||
let Ok(xdg_popup) = xdg_popup.upgrade() else {return};
|
||||
let Some(popup_data) = PopupData::get(&xdg_popup) else {return};
|
||||
let popup_data = popup_data.lock();
|
||||
panel_item
|
||||
@@ -476,10 +465,9 @@ impl Dispatch<XdgSurface, Mutex<XdgSurfaceData>, WaylandState> for WaylandState
|
||||
},
|
||||
move |commit_count| {
|
||||
if commit_count == 0 {
|
||||
xdg_surface
|
||||
.upgrade()
|
||||
.unwrap()
|
||||
.configure(SERIAL_COUNTER.inc())
|
||||
if let Ok(xdg_surface) = xdg_surface.upgrade() {
|
||||
xdg_surface.configure(SERIAL_COUNTER.inc())
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -566,11 +554,9 @@ impl Dispatch<XdgToplevel, Mutex<ToplevelData>, WaylandState> for WaylandState {
|
||||
debug!(?xdg_toplevel, ?parent, "Set XDG Toplevel parent");
|
||||
data.lock().parent = parent.clone().map(|toplevel| toplevel.downgrade());
|
||||
let Some(panel_item) = data.lock().panel_item() else {return};
|
||||
if let Some(parent) = parent {
|
||||
panel_item.toplevel_parent_changed(
|
||||
&ToplevelData::get(&parent).lock().panel_item().unwrap().uid,
|
||||
);
|
||||
}
|
||||
let Some(parent) = parent else {return};
|
||||
let Some(parent_panel_item) = ToplevelData::get(&parent).lock().panel_item() else {return};
|
||||
panel_item.toplevel_parent_changed(&parent_panel_item.uid);
|
||||
}
|
||||
xdg_toplevel::Request::SetTitle { title } => {
|
||||
debug!(?xdg_toplevel, ?title, "Set XDG Toplevel title");
|
||||
@@ -943,11 +929,11 @@ impl Backend for XDGBackend {
|
||||
size,
|
||||
min_size: toplevel_data.min_size.clone(),
|
||||
max_size: toplevel_data.max_size.clone(),
|
||||
logical_rectangle: XdgSurfaceData::get(&self.toplevel_xdg_surface().unwrap())
|
||||
.unwrap()
|
||||
.lock()
|
||||
.geometry
|
||||
.clone()
|
||||
logical_rectangle: self
|
||||
.toplevel_xdg_surface()
|
||||
.as_ref()
|
||||
.and_then(XdgSurfaceData::get)
|
||||
.and_then(|d| d.lock().geometry.clone())
|
||||
.unwrap_or_else(|| Geometry {
|
||||
origin: [0, 0].into(),
|
||||
size,
|
||||
|
||||
Reference in New Issue
Block a user