From 1856b803f3041052af6f87530b28d3f1f9197186 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 13 May 2024 14:16:21 -0700 Subject: [PATCH] Update `smithay`, with xwayland shell, `Cow`, etc. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/backend/kms/mod.rs | 2 +- src/backend/render/element.rs | 4 +-- src/backend/render/mod.rs | 4 ++- src/input/mod.rs | 18 +++++++------ src/shell/element/mod.rs | 17 ++++++++----- src/shell/element/stack.rs | 22 +++++++++++----- src/shell/element/surface.rs | 5 ++-- src/shell/element/window.rs | 19 ++++++++------ src/shell/focus/mod.rs | 4 +-- src/shell/focus/target.rs | 26 ++++++++++--------- src/shell/grabs/menu/mod.rs | 2 +- src/shell/grabs/mod.rs | 28 ++++++++++++++++++++- src/shell/grabs/moving.rs | 20 +++++++++++++++ src/shell/layout/floating/grabs/resize.rs | 22 +++++++++++++++- src/shell/layout/floating/mod.rs | 2 +- src/shell/layout/tiling/grabs/resize.rs | 20 +++++++++++++++ src/shell/layout/tiling/mod.rs | 2 +- src/shell/mod.rs | 11 ++++---- src/shell/workspace.rs | 10 ++++---- src/state.rs | 4 +++ src/utils/iced.rs | 2 +- src/wayland/handlers/compositor.rs | 10 ++++---- src/wayland/handlers/decoration.rs | 8 +++--- src/wayland/handlers/mod.rs | 1 + src/wayland/handlers/pointer_constraints.rs | 4 +-- src/wayland/handlers/screencopy/render.rs | 6 ++--- src/wayland/handlers/xdg_shell/mod.rs | 12 ++++----- src/wayland/handlers/xdg_shell/popup.rs | 2 +- src/wayland/handlers/xwayland_shell.rs | 15 +++++++++++ src/xwayland.rs | 1 - 32 files changed, 220 insertions(+), 87 deletions(-) create mode 100644 src/wayland/handlers/xwayland_shell.rs diff --git a/Cargo.lock b/Cargo.lock index 2d836845..38fb8790 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4556,7 +4556,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/smithay//smithay?rev=64356be#64356be949f2ad5f70f601cd10255eafed2ce2ce" +source = "git+https://github.com/smithay//smithay?rev=8f132ec#8f132ecded5705e55fc1ce6cfa4b59850c6b038e" dependencies = [ "appendlist", "ash", diff --git a/Cargo.toml b/Cargo.toml index 17180f49..f010c106 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,4 +118,4 @@ inherits = "release" lto = "fat" [patch."https://github.com/Smithay/smithay.git"] -smithay = {git = "https://github.com/smithay//smithay", rev = "64356be"} +smithay = {git = "https://github.com/smithay//smithay", rev = "8f132ec"} diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index acce9bd0..6d684dce 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -1478,7 +1478,7 @@ impl Surface { let buffer = frame.buffer(); if let Ok(dmabuf) = get_dmabuf(&buffer) { renderer - .bind(dmabuf) + .bind(dmabuf.clone()) .map_err(RenderError::::Rendering)?; } else { let size = buffer_dimensions(&buffer).ok_or(RenderError::< diff --git a/src/backend/render/element.rs b/src/backend/render/element.rs index 7aeb0728..5093f332 100644 --- a/src/backend/render/element.rs +++ b/src/backend/render/element.rs @@ -10,7 +10,7 @@ use smithay::{ }, gles::GlesTexture, glow::{GlowFrame, GlowRenderer}, - utils::{CommitCounter, DamageSet}, + utils::{CommitCounter, DamageSet, OpaqueRegions}, Frame, ImportAll, ImportMem, Renderer, }, utils::{Buffer as BufferCoords, Logical, Physical, Point, Rectangle, Scale}, @@ -142,7 +142,7 @@ where } } - fn opaque_regions(&self, scale: Scale) -> Vec> { + fn opaque_regions(&self, scale: Scale) -> OpaqueRegions { match self { CosmicElement::Workspace(elem) => elem.opaque_regions(scale), CosmicElement::Cursor(elem) => elem.opaque_regions(scale), diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 7bae018a..1c2d44e0 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -1057,7 +1057,9 @@ where if let (Some(ref damage), _) = &res { if let Ok(dmabuf) = get_dmabuf(buffer) { - renderer.bind(dmabuf).map_err(RenderError::Rendering)?; + renderer + .bind(dmabuf.clone()) + .map_err(RenderError::Rendering)?; } else { let size = buffer_dimensions(buffer).unwrap(); let format = with_buffer_contents(buffer, |_, _, data| { diff --git a/src/input/mod.rs b/src/input/mod.rs index 28a8127a..b77e5050 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -72,6 +72,7 @@ use xkbcommon::xkb::{Keycode, Keysym}; use std::{ any::Any, + borrow::Cow, cell::RefCell, os::unix::process::CommandExt, thread, @@ -642,8 +643,8 @@ impl State { ptr.frame(self); // If pointer is now in a constraint region, activate it - if let Some((under, surface_location)) = - new_under.and_then(|(target, loc)| Some((target.wl_surface()?, loc))) + if let Some((under, surface_location)) = new_under + .and_then(|(target, loc)| Some((target.wl_surface()?.into_owned(), loc))) { with_pointer_constraint(&under, &ptr, |constraint| match constraint { Some(constraint) if !constraint.is_active() => { @@ -872,7 +873,9 @@ impl State { // These cases are handled by the XwaylandKeyboardGrab. if let Some(target) = shell.element_under(pos, &output) { if seat.get_keyboard().unwrap().modifier_state().logo { - if let Some(surface) = target.toplevel() { + if let Some(surface) = + target.toplevel().map(Cow::into_owned) + { let seat_clone = seat.clone(); self.common.event_loop_handle.insert_idle( move |state| { @@ -1523,7 +1526,8 @@ impl State { tool.motion( position.as_logical(), - under.and_then(|(f, loc)| f.wl_surface().map(|s| (s, loc))), + under + .and_then(|(f, loc)| f.wl_surface().map(|s| (s.into_owned(), loc))), &tablet, SERIAL_COUNTER.next_serial(), event.time_msec(), @@ -1573,9 +1577,9 @@ impl State { if let Some(tablet) = tablet { match event.state() { ProximityState::In => { - if let Some(under) = - under.and_then(|(f, loc)| f.wl_surface().map(|s| (s, loc))) - { + if let Some(under) = under.and_then(|(f, loc)| { + f.wl_surface().map(|s| (s.into_owned(), loc)) + }) { tool.proximity_in( position.as_logical(), under, diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index c5465c60..e9bbedfa 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -19,7 +19,7 @@ use smithay::{ }, gles::element::PixelShaderElement, glow::GlowRenderer, - utils::DamageSet, + utils::{DamageSet, OpaqueRegions}, ImportAll, ImportMem, Renderer, }, }, @@ -42,6 +42,7 @@ use smithay::{ }; use std::{ + borrow::Cow, collections::HashMap, fmt, hash::Hash, @@ -222,7 +223,7 @@ impl CosmicMapped { }; if surface_type.contains(WindowSurfaceType::TOPLEVEL) { - if toplevel == *surface { + if *toplevel == *surface { return true; } } @@ -936,10 +937,14 @@ impl KeyboardTarget for CosmicMapped { } impl WaylandFocus for CosmicMapped { - fn wl_surface(&self) -> Option { + fn wl_surface(&self) -> Option> { match &self.element { - CosmicMappedInternal::Window(w) => w.surface().wl_surface().clone(), - CosmicMappedInternal::Stack(s) => s.active().wl_surface().clone(), + CosmicMappedInternal::Window(w) => { + w.surface().wl_surface().map(|s| Cow::Owned(s.into_owned())) + } + CosmicMappedInternal::Stack(s) => { + s.active().wl_surface().map(|s| Cow::Owned(s.into_owned())) + } _ => None, } } @@ -1168,7 +1173,7 @@ where } } - fn opaque_regions(&self, scale: Scale) -> Vec> { + fn opaque_regions(&self, scale: Scale) -> OpaqueRegions { match self { CosmicMappedRenderElement::Stack(elem) => elem.opaque_regions(scale), CosmicMappedRenderElement::Window(elem) => elem.opaque_regions(scale), diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 9210c9e7..3ff15436 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -55,6 +55,7 @@ use smithay::{ wayland::seat::WaylandFocus, }; use std::{ + borrow::Cow, cell::RefCell, fmt, hash::Hash, @@ -609,7 +610,7 @@ impl CosmicStack { let seat = seat.clone(); surface.try_force_undecorated(false); surface.send_configure(); - if let Some(surface) = surface.wl_surface() { + if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { let _ = data.common.event_loop_handle.insert_idle(move |state| { let res = state.common.shell.write().unwrap().move_request( &surface, @@ -701,7 +702,10 @@ impl Program for CosmicStackInternal { Message::DragStart => { if let Some((seat, serial)) = self.last_seat.lock().unwrap().clone() { let active = self.active.load(Ordering::SeqCst); - if let Some(surface) = self.windows.lock().unwrap()[active].wl_surface() { + if let Some(surface) = self.windows.lock().unwrap()[active] + .wl_surface() + .map(Cow::into_owned) + { loop_handle.insert_idle(move |state| { let res = state.common.shell.write().unwrap().move_request( &surface, @@ -757,7 +761,10 @@ impl Program for CosmicStackInternal { Message::Menu => { if let Some((seat, serial)) = self.last_seat.lock().unwrap().clone() { let active = self.active.load(Ordering::SeqCst); - if let Some(surface) = self.windows.lock().unwrap()[active].wl_surface() { + if let Some(surface) = self.windows.lock().unwrap()[active] + .wl_surface() + .map(Cow::into_owned) + { loop_handle.insert_idle(move |state| { let shell = state.common.shell.read().unwrap(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { @@ -808,7 +815,10 @@ impl Program for CosmicStackInternal { } Message::TabMenu(idx) => { if let Some((seat, serial)) = self.last_seat.lock().unwrap().clone() { - if let Some(surface) = self.windows.lock().unwrap()[idx].wl_surface() { + if let Some(surface) = self.windows.lock().unwrap()[idx] + .wl_surface() + .map(Cow::into_owned) + { loop_handle.insert_idle(move |state| { let shell = state.common.shell.read().unwrap(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { @@ -1260,7 +1270,7 @@ impl PointerTarget for CosmicStack { let seat = seat.clone(); let Some(surface) = self.0.with_program(|p| { let window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]; - window.wl_surface() + window.wl_surface().map(Cow::into_owned) }) else { return; }; @@ -1330,7 +1340,7 @@ impl PointerTarget for CosmicStack { let seat = seat.clone(); surface.try_force_undecorated(false); surface.send_configure(); - if let Some(surface) = surface.wl_surface() { + if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { let _ = data.common.event_loop_handle.insert_idle(move |state| { let res = state.common.shell.write().unwrap().move_request( &surface, diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index a00dc311..68cc1697 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Cow, sync::atomic::{AtomicBool, Ordering}, time::Duration, }; @@ -69,7 +70,7 @@ impl From for CosmicSurface { impl PartialEq for CosmicSurface { fn eq(&self, other: &WlSurface) -> bool { - self.wl_surface().map_or(false, |s| &s == other) + self.wl_surface().map_or(false, |s| &*s == other) } } @@ -720,7 +721,7 @@ impl KeyboardTarget for CosmicSurface { } impl WaylandFocus for CosmicSurface { - fn wl_surface(&self) -> Option { + fn wl_surface(&self) -> Option> { self.0.wl_surface() } } diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 99732754..80d6b3df 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -45,6 +45,7 @@ use smithay::{ wayland::seat::WaylandFocus, }; use std::{ + borrow::Cow, cell::RefCell, fmt, hash::Hash, @@ -384,7 +385,7 @@ impl Program for CosmicWindowInternal { match message { Message::DragStart => { if let Some((seat, serial)) = self.last_seat.lock().unwrap().clone() { - if let Some(surface) = self.window.wl_surface() { + if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { let res = state.common.shell.write().unwrap().move_request( &surface, @@ -410,7 +411,7 @@ impl Program for CosmicWindowInternal { } } Message::Minimize => { - if let Some(surface) = self.window.wl_surface() { + if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { let mut shell = state.common.shell.write().unwrap(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { @@ -420,7 +421,7 @@ impl Program for CosmicWindowInternal { } } Message::Maximize => { - if let Some(surface) = self.window.wl_surface() { + if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { let mut shell = state.common.shell.write().unwrap(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { @@ -433,7 +434,7 @@ impl Program for CosmicWindowInternal { Message::Close => self.window.close(), Message::Menu => { if let Some((seat, serial)) = self.last_seat.lock().unwrap().clone() { - if let Some(surface) = self.window.wl_surface() { + if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { let shell = state.common.shell.read().unwrap(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { @@ -739,7 +740,7 @@ impl PointerTarget for CosmicWindow { Some(x) => { let serial = event.serial; let seat = seat.clone(); - let Some(surface) = self.wl_surface() else { + let Some(surface) = self.wl_surface().map(Cow::into_owned) else { return; }; self.0.loop_handle().insert_idle(move |state| { @@ -906,8 +907,12 @@ impl TouchTarget for CosmicWindow { } impl WaylandFocus for CosmicWindow { - fn wl_surface(&self) -> Option { - self.0.with_program(|p| p.window.wl_surface()) + fn wl_surface(&self) -> Option> { + self.0.with_program(|p| { + p.window + .wl_surface() + .map(|s| Cow::Owned(Cow::into_owned(s))) + }) } fn same_client_as(&self, object_id: &ObjectId) -> bool { diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index 2de9c8cb..29574728 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -15,7 +15,7 @@ use smithay::{ shell::wlr_layer::{KeyboardInteractivity, Layer}, }, }; -use std::cell::RefCell; +use std::{borrow::Cow, cell::RefCell}; use tracing::{debug, trace}; use self::target::{KeyboardFocusTarget, WindowGroup}; @@ -229,7 +229,7 @@ fn raise_with_children(floating_layer: &mut FloatingLayout, focused: &CosmicMapp .0 .toplevel() .and_then(|toplevel| toplevel.parent()); - parent == focused.active_window().wl_surface() + parent == focused.active_window().wl_surface().map(Cow::into_owned) }) .cloned() .collect::>() diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 03bcc3f7..9a24af3f 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -1,4 +1,4 @@ -use std::{sync::Weak, time::Duration}; +use std::{borrow::Cow, sync::Weak, time::Duration}; use crate::{ shell::{ @@ -79,12 +79,12 @@ impl From for PointerFocusTarget { let window = elem.active_window(); let surface = window.wl_surface().unwrap(); PointerFocusTarget::WlSurface { - surface, + surface: surface.into_owned(), toplevel: Some(window.into()), } } KeyboardFocusTarget::Fullscreen(elem) => PointerFocusTarget::WlSurface { - surface: elem.wl_surface().unwrap(), + surface: elem.wl_surface().unwrap().into_owned(), toplevel: Some(elem.into()), }, KeyboardFocusTarget::LayerSurface(layer) => PointerFocusTarget::WlSurface { @@ -145,7 +145,7 @@ impl PointerFocusTarget { .and_then(|s| shell.element_for_surface(&s).map(|mapped| (mapped, s))) .and_then(|(m, s)| { m.windows() - .find(|(w, _)| w.wl_surface().map(|s2| s == s2).unwrap_or(false)) + .find(|(w, _)| w.wl_surface().map(|s2| s == *s2).unwrap_or(false)) .map(|(s, _)| s) }), PointerFocusTarget::StackUI(stack) => Some(stack.active()), @@ -156,10 +156,12 @@ impl PointerFocusTarget { } impl KeyboardFocusTarget { - pub fn toplevel(&self) -> Option { + pub fn toplevel(&self) -> Option> { match self { KeyboardFocusTarget::Element(mapped) => mapped.wl_surface(), - KeyboardFocusTarget::Popup(PopupKind::Xdg(xdg)) => get_popup_toplevel(&xdg), + KeyboardFocusTarget::Popup(PopupKind::Xdg(xdg)) => { + get_popup_toplevel(&xdg).map(Cow::Owned) + } _ => None, } } @@ -686,14 +688,14 @@ impl KeyboardTarget for KeyboardFocusTarget { } impl WaylandFocus for KeyboardFocusTarget { - fn wl_surface(&self) -> Option { + fn wl_surface(&self) -> Option> { match self { KeyboardFocusTarget::Element(w) => WaylandFocus::wl_surface(w), KeyboardFocusTarget::Fullscreen(w) => WaylandFocus::wl_surface(w), KeyboardFocusTarget::Group(_) => None, - KeyboardFocusTarget::LayerSurface(l) => Some(l.wl_surface().clone()), - KeyboardFocusTarget::Popup(p) => Some(p.wl_surface().clone()), - KeyboardFocusTarget::LockSurface(l) => Some(l.wl_surface().clone()), + KeyboardFocusTarget::LayerSurface(l) => Some(Cow::Borrowed(l.wl_surface())), + KeyboardFocusTarget::Popup(p) => Some(Cow::Borrowed(p.wl_surface())), + KeyboardFocusTarget::LockSurface(l) => Some(Cow::Borrowed(l.wl_surface())), } } fn same_client_as(&self, object_id: &ObjectId) -> bool { @@ -709,9 +711,9 @@ impl WaylandFocus for KeyboardFocusTarget { } impl WaylandFocus for PointerFocusTarget { - fn wl_surface(&self) -> Option { + fn wl_surface(&self) -> Option> { Some(match self { - PointerFocusTarget::WlSurface { surface, .. } => surface.clone(), + PointerFocusTarget::WlSurface { surface, .. } => Cow::Borrowed(surface), PointerFocusTarget::ResizeFork(_) | PointerFocusTarget::StackUI(_) | PointerFocusTarget::WindowUI(_) => { diff --git a/src/shell/grabs/menu/mod.rs b/src/shell/grabs/menu/mod.rs index 0dbc6616..ec9080df 100644 --- a/src/shell/grabs/menu/mod.rs +++ b/src/shell/grabs/menu/mod.rs @@ -63,7 +63,7 @@ impl MenuGrabState { pub fn render(&self, renderer: &mut R, output: &Output) -> Vec where R: Renderer + ImportMem, - ::TextureId: 'static, + ::TextureId: Clone + 'static, I: From>, { let scale = output.current_scale().fractional_scale(); diff --git a/src/shell/grabs/mod.rs b/src/shell/grabs/mod.rs index a6f508e6..18744cda 100644 --- a/src/shell/grabs/mod.rs +++ b/src/shell/grabs/mod.rs @@ -9,7 +9,7 @@ use smithay::{ }, touch::{ DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - TouchGrab, TouchInnerHandle, UpEvent, + OrientationEvent, ShapeEvent, TouchGrab, TouchInnerHandle, UpEvent, }, }, reexports::wayland_protocols::xdg::shell::server::xdg_toplevel, @@ -387,6 +387,32 @@ impl TouchGrab for ResizeGrab { } } + fn shape( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &ShapeEvent, + seq: Serial, + ) { + match self { + ResizeGrab::Floating(grab) => TouchGrab::shape(grab, data, handle, event, seq), + ResizeGrab::Tiling(grab) => TouchGrab::shape(grab, data, handle, event, seq), + } + } + + fn orientation( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &OrientationEvent, + seq: Serial, + ) { + match self { + ResizeGrab::Floating(grab) => TouchGrab::orientation(grab, data, handle, event, seq), + ResizeGrab::Tiling(grab) => TouchGrab::orientation(grab, data, handle, event, seq), + } + } + fn start_data(&self) -> &TouchGrabStartData { match self { ResizeGrab::Floating(grab) => TouchGrab::start_data(grab), diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 8c7a84a0..45695cc7 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -633,6 +633,26 @@ impl TouchGrab for MoveGrab { handle.unset_grab(self, data); } + fn shape( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &touch::ShapeEvent, + seq: Serial, + ) { + handle.shape(data, event, seq) + } + + fn orientation( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &touch::OrientationEvent, + seq: Serial, + ) { + handle.orientation(data, event, seq) + } + fn start_data(&self) -> &TouchGrabStartData { match &self.start_data { GrabStartData::Touch(start_data) => start_data, diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index 7069f3b4..d5a40c6a 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -23,7 +23,7 @@ use smithay::{ }, touch::{ DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, - TouchGrab, TouchInnerHandle, UpEvent, + OrientationEvent, ShapeEvent, TouchGrab, TouchInnerHandle, UpEvent, }, Seat, }, @@ -328,6 +328,26 @@ impl TouchGrab for ResizeSurfaceGrab { handle.unset_grab(self, data); } + fn shape( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &ShapeEvent, + seq: Serial, + ) { + handle.shape(data, event, seq) + } + + fn orientation( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &OrientationEvent, + seq: Serial, + ) { + handle.orientation(data, event, seq) + } + fn start_data(&self) -> &TouchGrabStartData { match &self.start_data { GrabStartData::Touch(start_data) => start_data, diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index 8082f786..ac9ebdf4 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -1132,7 +1132,7 @@ impl FloatingLayout { }; self.space .elements() - .find(|elem| elem.wl_surface().as_ref() == Some(&toplevel_surface)) + .find(|elem| elem.wl_surface().as_deref() == Some(&toplevel_surface)) } KeyboardFocusTarget::Element(elem) => self.space.elements().find(|x| *x == &elem), _ => None, diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 58988d27..428f8682 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -525,6 +525,16 @@ impl TouchGrab for ResizeForkGrab { handle.unset_grab(self, data); } + fn shape( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &ShapeEvent, + seq: Serial, + ) { + handle.shape(data, event, seq) + } + fn start_data(&self) -> &TouchGrabStartData { match &self.start_data { GrabStartData::Touch(start_data) => start_data, @@ -532,5 +542,15 @@ impl TouchGrab for ResizeForkGrab { } } + fn orientation( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &OrientationEvent, + seq: Serial, + ) { + handle.orientation(data, event, seq) + } + fn unset(&mut self, _data: &mut State) {} } diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 91595500..d1ad81df 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -2791,7 +2791,7 @@ impl TilingLayout { .find(|node| match node.data() { Data::Mapped { mapped, .. } => mapped .windows() - .any(|(w, _)| w.wl_surface().as_ref() == Some(&toplevel_surface)), + .any(|(w, _)| w.wl_surface().as_deref() == Some(&toplevel_surface)), _ => false, })?; diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 035de883..ab123667 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2206,7 +2206,7 @@ impl Shell { let mapped = self.element_for_surface(surface).cloned()?; let (_, relative_loc) = mapped .windows() - .find(|(w, _)| w.wl_surface().as_ref() == Some(surface)) + .find(|(w, _)| w.wl_surface().as_deref() == Some(surface)) .unwrap(); let (global_position, edge, is_tiled, is_stacked, is_sticky, tiling_enabled) = @@ -2279,7 +2279,7 @@ impl Shell { } else { let (tab, _) = mapped .windows() - .find(|(s, _)| s.wl_surface().as_ref() == Some(surface)) + .find(|(s, _)| s.wl_surface().as_deref() == Some(surface)) .unwrap(); Box::new(tab_items(&mapped, &tab, is_tiled, &config.static_conf)) as Box> @@ -2320,7 +2320,7 @@ impl Shell { let (window, _) = old_mapped .windows() - .find(|(w, _)| w.wl_surface().as_ref() == Some(surface)) + .find(|(w, _)| w.wl_surface().as_deref() == Some(surface)) .unwrap(); let mapped = if move_out_of_stack { @@ -2502,7 +2502,7 @@ impl Shell { .space .elements() .chain(workspace.mapped()) - .find(|elem| elem.wl_surface().as_ref() == Some(&toplevel_surface)) + .find(|elem| elem.wl_surface().as_deref() == Some(&toplevel_surface)) } KeyboardFocusTarget::Element(elem) => sticky_layer .space @@ -2664,7 +2664,8 @@ impl Shell { ), (ResizeGrab, Focus), )> { - let surface = mapped.active_window().wl_surface()?; + let active_window = mapped.active_window(); + let surface = active_window.wl_surface()?; if mapped.is_fullscreen(true) || mapped.is_maximized(true) { return None; } diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index d5b18d3c..ac6dcb57 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -31,7 +31,7 @@ use smithay::{ }, gles::{GlesError, GlesTexture}, glow::{GlowFrame, GlowRenderer}, - utils::DamageSet, + utils::{DamageSet, OpaqueRegions}, ImportAll, ImportMem, Renderer, }, desktop::{layer_map_for_output, space::SpaceElement}, @@ -328,7 +328,7 @@ impl Workspace { if let Some(signal) = f.animation_signal.take() { signal.store(true, Ordering::SeqCst); if let Some(client) = - f.surface.wl_surface().as_ref().and_then(Resource::client) + f.surface.wl_surface().as_deref().and_then(Resource::client) { clients.insert(client.id(), client); } @@ -342,7 +342,7 @@ impl Workspace { if let Some(signal) = f.animation_signal.take() { signal.store(true, Ordering::SeqCst); if let Some(client) = - f.surface.wl_surface().as_ref().and_then(Resource::client) + f.surface.wl_surface().as_deref().and_then(Resource::client) { clients.insert(client.id(), client); } @@ -823,7 +823,7 @@ impl Workspace { if self .fullscreen .as_ref() - .is_some_and(|f| f.surface.wl_surface().as_ref() == Some(&toplevel)) + .is_some_and(|f| f.surface.wl_surface().as_deref() == Some(&toplevel)) { return false; } @@ -1332,7 +1332,7 @@ where } } - fn opaque_regions(&self, scale: Scale) -> Vec> { + fn opaque_regions(&self, scale: Scale) -> OpaqueRegions { match self { WorkspaceRenderElement::OverrideRedirect(elem) => elem.opaque_regions(scale), WorkspaceRenderElement::Fullscreen(elem) => elem.opaque_regions(scale), diff --git a/src/state.rs b/src/state.rs index 42ab4c11..0a6321cf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -93,6 +93,7 @@ use smithay::{ virtual_keyboard::VirtualKeyboardManagerState, xdg_activation::XdgActivationState, xwayland_keyboard_grab::XWaylandKeyboardGrabState, + xwayland_shell::XWaylandShellState, }, xwayland::XWaylandClientData, }; @@ -219,6 +220,7 @@ pub struct Common { pub xdg_activation_state: XdgActivationState, pub workspace_state: WorkspaceState, pub xwayland_state: Option, + pub xwayland_shell_state: XWaylandShellState, } #[derive(Debug)] @@ -427,6 +429,7 @@ impl State { let session_lock_manager_state = SessionLockManagerState::new::(&dh, client_is_privileged); XWaylandKeyboardGrabState::new::(&dh); + let xwayland_shell_state = XWaylandShellState::new::(&dh); PointerConstraintsState::new::(&dh); PointerGesturesState::new::(&dh); TabletManagerState::new::(&dh); @@ -533,6 +536,7 @@ impl State { xdg_activation_state, workspace_state, xwayland_state: None, + xwayland_shell_state, }, backend: BackendData::Unset, ready: Once::new(), diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 75e49941..d2dc706b 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -843,7 +843,7 @@ impl AsRenderElements for IcedElement

where P: Program + Send + 'static, R: Renderer + ImportMem, - ::TextureId: 'static, + ::TextureId: Clone + 'static, { type RenderElement = MemoryRenderBufferRenderElement; diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index f588dec8..d81149d2 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -107,7 +107,7 @@ impl CompositorHandler for State { .buffer .as_ref() .and_then(|assignment| match assignment { - BufferAssignment::NewBuffer(buffer) => get_dmabuf(buffer).ok(), + BufferAssignment::NewBuffer(buffer) => get_dmabuf(buffer).ok().cloned(), _ => None, }) }); @@ -134,7 +134,7 @@ impl CompositorHandler for State { } fn commit(&mut self, surface: &WlSurface) { - X11Wm::commit_hook::(surface); + X11Wm::commit_hook::(self, surface); // first load the buffer for various smithay helper functions (which also initializes the RendererSurfaceState) on_commit_buffer_handler::(surface); @@ -153,7 +153,7 @@ impl CompositorHandler for State { if let Some((window, _, _)) = shell .pending_windows .iter() - .find(|(window, _, _)| window.wl_surface().as_ref() == Some(surface)) + .find(|(window, _, _)| window.wl_surface().as_deref() == Some(surface)) .cloned() { if let Some(toplevel) = window.0.toplevel() { @@ -220,7 +220,7 @@ impl CompositorHandler for State { .windows() .any(|(s, _)| { s.wl_surface() - .as_ref() + .as_deref() .map(|s| s == surface) .unwrap_or(false) }) @@ -231,7 +231,7 @@ impl CompositorHandler for State { let stack = window.stack_ref_mut().unwrap(); if let Some(i) = stack.surfaces().position(|s| { s.wl_surface() - .as_ref() + .as_deref() .map(|s| s == surface) .unwrap_or(false) }) { diff --git a/src/wayland/handlers/decoration.rs b/src/wayland/handlers/decoration.rs index 4ca004ba..5c5e5a2f 100644 --- a/src/wayland/handlers/decoration.rs +++ b/src/wayland/handlers/decoration.rs @@ -58,7 +58,7 @@ pub fn new_decoration(mapped: &CosmicMapped, surface: &WlSurface) -> KdeMode { if mapped.is_stack() { if let Some((window, _)) = mapped .windows() - .find(|(window, _)| window.wl_surface().as_ref() == Some(surface)) + .find(|(window, _)| window.wl_surface().as_deref() == Some(surface)) { if let Some(toplevel) = window.0.toplevel() { toplevel @@ -70,7 +70,7 @@ pub fn new_decoration(mapped: &CosmicMapped, surface: &WlSurface) -> KdeMode { } else { if let Some((window, _)) = mapped .windows() - .find(|(window, _)| window.wl_surface().as_ref() == Some(surface)) + .find(|(window, _)| window.wl_surface().as_deref() == Some(surface)) { if let Some(toplevel) = window.0.toplevel() { toplevel @@ -85,7 +85,7 @@ pub fn new_decoration(mapped: &CosmicMapped, surface: &WlSurface) -> KdeMode { pub fn request_mode(mapped: &CosmicMapped, surface: &WlSurface, mode: XdgMode) { if let Some((window, _)) = mapped .windows() - .find(|(window, _)| window.wl_surface().as_ref() == Some(surface)) + .find(|(window, _)| window.wl_surface().as_deref() == Some(surface)) { if let Some(toplevel) = window.0.toplevel() { PreferredDecorationMode::update(&window.0, Some(mode)); @@ -100,7 +100,7 @@ pub fn request_mode(mapped: &CosmicMapped, surface: &WlSurface, mode: XdgMode) { pub fn unset_mode(mapped: &CosmicMapped, surface: &WlSurface) { if let Some((window, _)) = mapped .windows() - .find(|(window, _)| window.wl_surface().as_ref() == Some(surface)) + .find(|(window, _)| window.wl_surface().as_deref() == Some(surface)) { if let Some(toplevel) = window.0.toplevel() { PreferredDecorationMode::update(&window.0, None); diff --git a/src/wayland/handlers/mod.rs b/src/wayland/handlers/mod.rs index 6b9c7c2d..56971a96 100644 --- a/src/wayland/handlers/mod.rs +++ b/src/wayland/handlers/mod.rs @@ -38,3 +38,4 @@ pub mod workspace; pub mod xdg_activation; pub mod xdg_shell; pub mod xwayland_keyboard_grab; +pub mod xwayland_shell; diff --git a/src/wayland/handlers/pointer_constraints.rs b/src/wayland/handlers/pointer_constraints.rs index 33d48d50..85964d7e 100644 --- a/src/wayland/handlers/pointer_constraints.rs +++ b/src/wayland/handlers/pointer_constraints.rs @@ -16,9 +16,7 @@ impl PointerConstraintsHandler for State { // XXX region if pointer .current_focus() - .and_then(|x| x.wl_surface()) - .as_ref() - == Some(surface) + .map_or(false, |x| x.wl_surface().as_deref() == Some(surface)) { with_pointer_constraint(surface, pointer, |constraint| { constraint.unwrap().activate(); diff --git a/src/wayland/handlers/screencopy/render.rs b/src/wayland/handlers/screencopy/render.rs index 5f026229..f80afac6 100644 --- a/src/wayland/handlers/screencopy/render.rs +++ b/src/wayland/handlers/screencopy/render.rs @@ -280,7 +280,7 @@ pub fn render_workspace_to_buffer( render_workspace::<_, _, GlesRenderbuffer>( None, renderer, - dmabuf, + dmabuf.clone(), dt, age, additional_damage, @@ -581,7 +581,7 @@ pub fn render_window_to_buffer( } if let Ok(dmabuf) = get_dmabuf(buffer) { - renderer.bind(dmabuf).map_err(DTError::Rendering)?; + renderer.bind(dmabuf.clone()).map_err(DTError::Rendering)?; } else { let size = buffer_dimensions(buffer).unwrap(); let format = @@ -794,7 +794,7 @@ pub fn render_cursor_to_buffer( ); if let Ok(dmabuf) = get_dmabuf(buffer) { - renderer.bind(dmabuf).map_err(DTError::Rendering)?; + renderer.bind(dmabuf.clone()).map_err(DTError::Rendering)?; } else { let size = buffer_dimensions(buffer).unwrap(); let format = diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index 1731428b..e9fcb1be 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -200,7 +200,7 @@ impl XdgShellHandler for State { let mut shell = self.common.shell.write().unwrap(); if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() { if !mapped.is_stack() - || mapped.active_window().wl_surface().as_ref() == Some(surface.wl_surface()) + || mapped.active_window().wl_surface().as_deref() == Some(surface.wl_surface()) { shell.minimize_request(&mapped) } @@ -248,7 +248,7 @@ impl XdgShellHandler for State { let stack = mapped.stack_ref().unwrap(); let surface = stack .surfaces() - .find(|s| s.wl_surface().as_ref() == Some(surface.wl_surface())) + .find(|s| s.wl_surface().as_deref() == Some(surface.wl_surface())) .unwrap(); stack.remove_window(&surface); CosmicMapped::from(CosmicWindow::new( @@ -286,7 +286,7 @@ impl XdgShellHandler for State { let stack = mapped.stack_ref().unwrap(); let surface = stack .surfaces() - .find(|s| s.wl_surface().as_ref() == Some(surface.wl_surface())) + .find(|s| s.wl_surface().as_deref() == Some(surface.wl_surface())) .unwrap(); stack.remove_window(&surface); ( @@ -325,7 +325,7 @@ impl XdgShellHandler for State { } else { let (window, _) = mapped .windows() - .find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface())) + .find(|(w, _)| w.wl_surface().as_deref() == Some(surface.wl_surface())) .unwrap(); workspace.fullscreen_request(&window, None, from, &seat) } @@ -334,7 +334,7 @@ impl XdgShellHandler for State { if let Some(o) = shell .pending_windows .iter_mut() - .find(|(s, _, _)| s.wl_surface().as_ref() == Some(surface.wl_surface())) + .find(|(s, _, _)| s.wl_surface().as_deref() == Some(surface.wl_surface())) .map(|(_, _, o)| o) { *o = Some(output); @@ -348,7 +348,7 @@ impl XdgShellHandler for State { if let Some(workspace) = shell.space_for_mut(&mapped) { let (window, _) = mapped .windows() - .find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface())) + .find(|(w, _)| w.wl_surface().as_deref() == Some(surface.wl_surface())) .unwrap(); if let Some((layer, previous_workspace)) = workspace.unfullscreen_request(&window) { let old_handle = workspace.handle.clone(); diff --git a/src/wayland/handlers/xdg_shell/popup.rs b/src/wayland/handlers/xdg_shell/popup.rs index 9f54aa1a..f736b2cb 100644 --- a/src/wayland/handlers/xdg_shell/popup.rs +++ b/src/wayland/handlers/xdg_shell/popup.rs @@ -59,7 +59,7 @@ impl Shell { let (window, offset) = elem .windows() - .find(|(w, _)| w.wl_surface().as_ref() == Some(&parent)) + .find(|(w, _)| w.wl_surface().as_deref() == Some(&parent)) .unwrap(); let window_geo_offset = window.geometry().loc; let window_loc: Point = diff --git a/src/wayland/handlers/xwayland_shell.rs b/src/wayland/handlers/xwayland_shell.rs new file mode 100644 index 00000000..a710c708 --- /dev/null +++ b/src/wayland/handlers/xwayland_shell.rs @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use crate::state::State; +use smithay::{ + delegate_xwayland_shell, + wayland::xwayland_shell::{XWaylandShellHandler, XWaylandShellState}, +}; + +impl XWaylandShellHandler for State { + fn xwayland_shell_state(&mut self) -> &mut XWaylandShellState { + &mut self.common.xwayland_shell_state + } +} + +delegate_xwayland_shell!(State); diff --git a/src/xwayland.rs b/src/xwayland.rs index fe0f3838..3c5f32ea 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -83,7 +83,6 @@ impl State { let mut wm = match X11Wm::start_wm( data.common.event_loop_handle.clone(), - data.common.display_handle.clone(), x11_socket, client.clone(), ) {