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 {