Skip to content

Commit

Permalink
Update smithay, with xwayland shell, Cow, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed May 21, 2024
1 parent dfb3bea commit 1856b80
Show file tree
Hide file tree
Showing 32 changed files with 220 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
2 changes: 1 addition & 1 deletion src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<GlMultiRenderer>::Rendering)?;
} else {
let size = buffer_dimensions(&buffer).ok_or(RenderError::<
Expand Down
4 changes: 2 additions & 2 deletions src/backend/render/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -142,7 +142,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 {
CosmicElement::Workspace(elem) => elem.opaque_regions(scale),
CosmicElement::Cursor(elem) => elem.opaque_regions(scale),
Expand Down
4 changes: 3 additions & 1 deletion src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
18 changes: 11 additions & 7 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use xkbcommon::xkb::{Keycode, Keysym};

use std::{
any::Any,
borrow::Cow,
cell::RefCell,
os::unix::process::CommandExt,
thread,
Expand Down Expand Up @@ -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() => {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use smithay::{
},
gles::element::PixelShaderElement,
glow::GlowRenderer,
utils::DamageSet,
utils::{DamageSet, OpaqueRegions},
ImportAll, ImportMem, Renderer,
},
},
Expand All @@ -42,6 +42,7 @@ use smithay::{
};

use std::{
borrow::Cow,
collections::HashMap,
fmt,
hash::Hash,
Expand Down Expand Up @@ -222,7 +223,7 @@ impl CosmicMapped {
};

if surface_type.contains(WindowSurfaceType::TOPLEVEL) {
if toplevel == *surface {
if *toplevel == *surface {
return true;
}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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),
Expand Down
22 changes: 16 additions & 6 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use smithay::{
wayland::seat::WaylandFocus,
};
use std::{
borrow::Cow,
cell::RefCell,
fmt,
hash::Hash,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/shell/element/surface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
borrow::Cow,
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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()
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use smithay::{
wayland::seat::WaylandFocus,
};
use std::{
borrow::Cow,
cell::RefCell,
fmt,
hash::Hash,
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<_>>()
Expand Down
Loading

0 comments on commit 1856b80

Please sign in to comment.