Update smithay, with xwayland shell, Cow, etc.

This commit is contained in:
Ian Douglas Scott 2024-05-13 14:16:21 -07:00 committed by Victoria Brekenfeld
parent dfb3bea595
commit 4f076e0753
32 changed files with 220 additions and 87 deletions

View file

@ -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<State> for CosmicMapped {
}
impl WaylandFocus for CosmicMapped {
fn wl_surface(&self) -> Option<WlSurface> {
fn wl_surface(&self) -> Option<Cow<'_, WlSurface>> {
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<f64>) -> Vec<Rectangle<i32, Physical>> {
fn opaque_regions(&self, scale: Scale<f64>) -> OpaqueRegions<i32, Physical> {
match self {
CosmicMappedRenderElement::Stack(elem) => elem.opaque_regions(scale),
CosmicMappedRenderElement::Window(elem) => elem.opaque_regions(scale),

View file

@ -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<State> 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<State> 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,

View file

@ -1,4 +1,5 @@
use std::{
borrow::Cow,
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
@ -69,7 +70,7 @@ impl From<X11Surface> for CosmicSurface {
impl PartialEq<WlSurface> 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<State> for CosmicSurface {
}
impl WaylandFocus for CosmicSurface {
fn wl_surface(&self) -> Option<WlSurface> {
fn wl_surface(&self) -> Option<Cow<'_, WlSurface>> {
self.0.wl_surface()
}
}

View file

@ -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<State> 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<State> for CosmicWindow {
}
impl WaylandFocus for CosmicWindow {
fn wl_surface(&self) -> Option<WlSurface> {
self.0.with_program(|p| p.window.wl_surface())
fn wl_surface(&self) -> Option<Cow<'_, WlSurface>> {
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 {

View file

@ -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::<Vec<_>>()

View file

@ -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<KeyboardFocusTarget> 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<WlSurface> {
pub fn toplevel(&self) -> Option<Cow<'_, WlSurface>> {
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<State> for KeyboardFocusTarget {
}
impl WaylandFocus for KeyboardFocusTarget {
fn wl_surface(&self) -> Option<WlSurface> {
fn wl_surface(&self) -> Option<Cow<'_, WlSurface>> {
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<WlSurface> {
fn wl_surface(&self) -> Option<Cow<'_, WlSurface>> {
Some(match self {
PointerFocusTarget::WlSurface { surface, .. } => surface.clone(),
PointerFocusTarget::WlSurface { surface, .. } => Cow::Borrowed(surface),
PointerFocusTarget::ResizeFork(_)
| PointerFocusTarget::StackUI(_)
| PointerFocusTarget::WindowUI(_) => {

View file

@ -63,7 +63,7 @@ impl MenuGrabState {
pub fn render<I, R>(&self, renderer: &mut R, output: &Output) -> Vec<I>
where
R: Renderer + ImportMem,
<R as Renderer>::TextureId: 'static,
<R as Renderer>::TextureId: Clone + 'static,
I: From<MemoryRenderBufferRenderElement<R>>,
{
let scale = output.current_scale().fractional_scale();

View file

@ -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<State> 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<State> {
match self {
ResizeGrab::Floating(grab) => TouchGrab::start_data(grab),

View file

@ -633,6 +633,26 @@ impl TouchGrab<State> 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<State> {
match &self.start_data {
GrabStartData::Touch(start_data) => start_data,

View file

@ -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<State> 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<State> {
match &self.start_data {
GrabStartData::Touch(start_data) => start_data,

View file

@ -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,

View file

@ -525,6 +525,16 @@ impl TouchGrab<State> 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<State> {
match &self.start_data {
GrabStartData::Touch(start_data) => start_data,
@ -532,5 +542,15 @@ impl TouchGrab<State> 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) {}
}

View file

@ -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,
})?;

View file

@ -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<dyn Iterator<Item = Item>>
@ -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;
}

View file

@ -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<f64>) -> Vec<Rectangle<i32, smithay::utils::Physical>> {
fn opaque_regions(&self, scale: Scale<f64>) -> OpaqueRegions<i32, smithay::utils::Physical> {
match self {
WorkspaceRenderElement::OverrideRedirect(elem) => elem.opaque_regions(scale),
WorkspaceRenderElement::Fullscreen(elem) => elem.opaque_regions(scale),