Skip to content

Commit

Permalink
Update wayland-server to 0.31
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Sep 22, 2023
1 parent d3e1ef9 commit 5df2af0
Show file tree
Hide file tree
Showing 41 changed files with 256 additions and 203 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ calloop = "0.10.1"
cgmath = "0.18.0"
downcast-rs = "1.2.0"
drm-fourcc = "^2.2.0"
drm = { version = "0.9.0", optional = true }
drm-ffi = { version = "0.5.0", optional = true }
drm = { version = "0.10.0", optional = true }
drm-ffi = { version = "0.6.0", optional = true }

gbm = { version = "0.12.0", optional = true, default-features = false, features = ["drm-support"] }
gbm = { version = "0.13.0", optional = true, default-features = false, features = ["drm-support"] }
glow = { version = "0.12", optional = true }
input = { version = "0.8.2", default-features = false, features=["libinput_1_14"], optional = true }
indexmap = "1.9"
lazy_static = "1"
libc = "0.2.103"
libseat = { version = "0.2.1", optional = true, default_features = false }
libloading = { version="0.8.0", optional = true }
nix = "0.26.0"
nix = { version = "0.27.0", features = ["fs", "mman", "signal", "socket", "poll"] }
once_cell = "1.8.0"
rand = "0.8.4"
scopeguard = { version = "1.1.0", optional = true }
tracing = "0.1.37"
tempfile = { version = "3.0", optional = true }
thiserror = "1.0.25"
udev = { version = "0.7", optional = true }
wayland-egl = { version = "0.30.0", optional = true }
wayland-protocols = { version = "0.30.1", features = ["unstable", "staging", "server"], optional = true }
wayland-protocols-wlr = { version = "0.1.0", features = ["server"], optional = true }
wayland-protocols-misc = { version = "0.1.0", features = ["server"], optional = true }
wayland-server = { version = "0.30.0", optional = true }
wayland-sys = { version = "0.30.1", optional = true }
wayland-backend = { version = "0.1.0", optional = true }
wayland-egl = { version = "0.32.0", optional = true }
wayland-protocols = { version = "0.31.0", features = ["unstable", "staging", "server"], optional = true }
wayland-protocols-wlr = { version = "0.2.0", features = ["server"], optional = true }
wayland-protocols-misc = { version = "0.2.0", features = ["server"], optional = true }
wayland-server = { version = "0.31.0", optional = true }
wayland-sys = { version = "0.31", optional = true }
wayland-backend = { version = "0.3.0", optional = true }
winit = { version = "0.28.0", default-features = false, features = ["wayland", "wayland-dlopen", "x11"], optional = true }
x11rb = { version = "0.11.1", optional = true }
xkbcommon = { version = "0.5.0", features = ["wayland"]}
Expand Down
2 changes: 1 addition & 1 deletion smithay-drm-extras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
edid-rs = "0.1.0"
drm = { version = "0.9.0" }
drm = { version = "0.10.0" }

[features]
default = []
Expand Down
6 changes: 2 additions & 4 deletions src/backend/allocator/dmabuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,10 @@ impl DmabufSource {
Subsource::Empty,
];
for (idx, handle) in dmabuf.handles().enumerate() {
// SAFETY: This is stored together with the Dmabuf holding the owned file descriptors
let fd = handle.as_raw_fd();
if matches!(
poll::poll(
&mut [poll::PollFd::new(
fd,
&handle,
if interest.writable {
poll::PollFlags::POLLOUT
} else {
Expand All @@ -414,7 +412,7 @@ impl DmabufSource {
) {
continue;
}
sources[idx] = Subsource::Active(Generic::new(fd, interest, Mode::OneShot));
sources[idx] = Subsource::Active(Generic::new(handle.as_raw_fd(), interest, Mode::OneShot));
}
if sources
.iter()
Expand Down
95 changes: 40 additions & 55 deletions src/backend/drm/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thiserror::Error;

use drm::{
buffer::PlanarBuffer,
control::{framebuffer, Device},
control::{framebuffer, Device, FbCmd2Flags},
};
use drm_fourcc::DrmModifier;
use gbm::BufferObject;
Expand Down Expand Up @@ -256,6 +256,13 @@ impl<'a, T: 'static> PlanarBuffer for BufferObjectInternal<'a, T> {
PlanarBuffer::format(self.bo)
}

fn modifier(&self) -> Option<DrmModifier> {
match self.bo.modifier().unwrap() {
DrmModifier::Invalid => None,
x => Some(x),
}
}

fn pitches(&self) -> [u32; 4] {
self.pitches.unwrap_or_else(|| PlanarBuffer::pitches(self.bo))
}
Expand Down Expand Up @@ -283,6 +290,10 @@ where
get_opaque(fmt).unwrap_or(fmt)
}

fn modifier(&self) -> Option<DrmModifier> {
self.0.modifier()
}

fn pitches(&self) -> [u32; 4] {
self.0.pitches()
}
Expand Down Expand Up @@ -310,62 +321,36 @@ where
x => Some(x),
};

let (fb, format) = match if modifier.is_some() {
let num = bo.plane_count().unwrap();
let modifiers = [
modifier,
if num > 1 { modifier } else { None },
if num > 2 { modifier } else { None },
if num > 3 { modifier } else { None },
];
if use_opaque {
let opaque_wrapper = OpaqueBufferWrapper(&bo);
drm.add_planar_framebuffer(&opaque_wrapper, &modifiers, drm_ffi::DRM_MODE_FB_MODIFIERS)
.map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: opaque_wrapper.format(),
modifier: modifier.unwrap(),
},
)
})
} else {
drm.add_planar_framebuffer(&bo, &modifiers, drm_ffi::DRM_MODE_FB_MODIFIERS)
.map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: bo.format(),
modifier: modifier.unwrap(),
},
)
})
}
} else if use_opaque {
let flags = if bo.modifier().is_some() {
FbCmd2Flags::MODIFIERS
} else {
FbCmd2Flags::empty()
};

let ret = if use_opaque {
let opaque_wrapper = OpaqueBufferWrapper(&bo);
drm.add_planar_framebuffer(&opaque_wrapper, &[None, None, None, None], 0)
.map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: opaque_wrapper.format(),
modifier: drm_fourcc::DrmModifier::Invalid,
},
)
})
drm.add_planar_framebuffer(&opaque_wrapper, flags).map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: opaque_wrapper.format(),
modifier: modifier.unwrap_or(DrmModifier::Invalid),
},
)
})
} else {
drm.add_planar_framebuffer(&bo, &[None, None, None, None], 0)
.map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: bo.format(),
modifier: drm_fourcc::DrmModifier::Invalid,
},
)
})
} {
drm.add_planar_framebuffer(&bo, flags).map(|fb| {
(
fb,
drm_fourcc::DrmFormat {
code: bo.format(),
modifier: modifier.unwrap_or(DrmModifier::Invalid),
},
)
})
};

let (fb, format) = match ret {
Ok(fb) => fb,
Err(source) => {
// We only support this as a fallback of last resort like xf86-video-modesetting does.
Expand Down
10 changes: 5 additions & 5 deletions src/input/keyboard/keymap_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing::error;
use xkbcommon::xkb::{Keymap, KEYMAP_FORMAT_TEXT_V1};

use std::ffi::CString;
use std::os::unix::io::RawFd;
use std::os::unix::io::{AsFd, BorrowedFd};

/// Wraps an XKB keymap into a sealed file or stores as just a string for sending to WlKeyboard over an fd
#[derive(Debug)]
Expand Down Expand Up @@ -46,12 +46,12 @@ impl KeymapFile {
/// Run a closure with the file descriptor to ensure safety
pub fn with_fd<F>(&self, supports_sealed: bool, cb: F) -> Result<(), std::io::Error>
where
F: FnOnce(RawFd, usize),
F: FnOnce(BorrowedFd<'_>, usize),
{
use std::{io::Write, os::unix::io::AsRawFd, path::PathBuf};
use std::{io::Write, path::PathBuf};

if let Some(file) = supports_sealed.then_some(self.sealed.as_ref()).flatten() {
cb(file.as_raw_fd(), file.size());
cb(file.as_fd(), file.size());
} else {
let dir = std::env::var_os("XDG_RUNTIME_DIR")
.map(PathBuf::from)
Expand All @@ -61,7 +61,7 @@ impl KeymapFile {
file.write_all(self.keymap.as_bytes())?;
file.flush()?;

cb(file.as_raw_fd(), self.keymap.len());
cb(file.as_fd(), self.keymap.len());
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/input/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,13 @@ impl<D: SeatHandler + 'static> KeyboardHandle<D> {
let mut keymap_file = self.arc.keymap.lock().unwrap();
keymap_file.change_keymap(keymap);

use std::os::unix::io::AsRawFd;
use std::os::unix::io::AsFd;
use tracing::warn;
use wayland_server::{protocol::wl_keyboard::KeymapFormat, Resource};
let known_kbds = &self.arc.known_kbds;
for kbd in &*known_kbds.lock().unwrap() {
let res = keymap_file.with_fd(kbd.version() >= 7, |fd, size| {
kbd.keymap(KeymapFormat::XkbV1, fd.as_raw_fd(), size as u32)
kbd.keymap(KeymapFormat::XkbV1, fd.as_fd(), size as u32)
});
if let Err(e) = res {
warn!(
Expand Down
10 changes: 8 additions & 2 deletions src/utils/sealed_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
ffi::CString,
fs::File,
io::Write,
os::unix::io::{AsRawFd, FromRawFd, RawFd},
os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd},
};

#[derive(Debug)]
Expand All @@ -34,7 +34,7 @@ impl SealedFile {
MemFdCreateFlag::MFD_CLOEXEC | MemFdCreateFlag::MFD_ALLOW_SEALING,
)?;

let mut file = unsafe { File::from_raw_fd(fd) };
let mut file: File = fd.into();
file.write_all(data)?;
file.flush()?;

Expand Down Expand Up @@ -112,3 +112,9 @@ impl AsRawFd for SealedFile {
self.file.as_raw_fd()
}
}

impl AsFd for SealedFile {
fn as_fd(&self) -> BorrowedFd<'_> {
self.file.as_fd()
}
}
18 changes: 5 additions & 13 deletions src/wayland/compositor/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,20 @@ where
fn destroyed(
state: &mut D,
_client_id: wayland_server::backend::ClientId,
object_id: wayland_server::backend::ObjectId,
surface: &WlSurface,
data: &SurfaceUserData,
) {
let surface = state
.compositor_state()
.surfaces
.iter()
.find(|surface| surface.id() == object_id)
.cloned()
.unwrap();

// We let the destruction hooks run first and then tell the compositor handler the surface was
// destroyed.
data.alive_tracker.destroy_notify();
state.destroyed(&surface);
state.destroyed(surface);

// Remove the surface after the callback is invoked.
state
.compositor_state()
.surfaces
.retain(|surface| surface.id() != object_id);
PrivateSurfaceData::cleanup(state, data, object_id);
.retain(|s| s.id() != surface.id());
PrivateSurfaceData::cleanup(state, data, surface.id());
}
}

Expand Down Expand Up @@ -569,7 +561,7 @@ where
fn destroyed(
_state: &mut D,
_client_id: wayland_server::backend::ClientId,
_object_id: wayland_server::backend::ObjectId,
_object: &WlSubsurface,
data: &SubsurfaceUserData,
) {
PrivateSurfaceData::unset_parent(&data.surface);
Expand Down
5 changes: 2 additions & 3 deletions src/wayland/content_type/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use wayland_protocols::wp::content_type::v1::server::{
wp_content_type_v1::{self, WpContentTypeV1},
};
use wayland_server::{
backend::{ClientId, ObjectId},
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
backend::ClientId, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
};

use super::{ContentTypeState, ContentTypeSurfaceCachedState, ContentTypeSurfaceData, ContentTypeUserData};
Expand Down Expand Up @@ -131,7 +130,7 @@ where
}
}

fn destroyed(_state: &mut D, _client: ClientId, _object: ObjectId, _data: &ContentTypeUserData) {
fn destroyed(_state: &mut D, _client: ClientId, _object: &WpContentTypeV1, _data: &ContentTypeUserData) {
// Nothing to do here, graceful Destroy is already handled with double buffering
// and in case of client close WlSurface destroyed handler will clean up the data anyway,
// so there is no point in queuing new update
Expand Down
13 changes: 10 additions & 3 deletions src/wayland/data_device/dnd_grab.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::RefCell,
os::unix::io::{AsRawFd, OwnedFd},
os::unix::io::{AsFd, OwnedFd},
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -370,7 +370,14 @@ where
None
}

fn destroyed(&self, _data: &mut D, _client_id: ClientId, _object_id: ObjectId) {}
fn destroyed(
self: Arc<Self>,
_handle: &Handle,
_data: &mut D,
_client_id: ClientId,
_object_id: ObjectId,
) {
}
}

fn handle_dnd<D>(handler: &mut D, offer: &WlDataOffer, request: wl_data_offer::Request, data: &DndDataOffer)
Expand Down Expand Up @@ -400,7 +407,7 @@ where
&& source.alive()
&& data.active;
if valid {
source.send(mime_type, fd.as_raw_fd());
source.send(mime_type, fd.as_fd());
}
}
Request::Destroy => {}
Expand Down
4 changes: 2 additions & 2 deletions src/wayland/data_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

use std::{
cell::{Ref, RefCell},
os::unix::io::{AsRawFd, OwnedFd},
os::unix::io::{AsFd, OwnedFd},
};

use tracing::instrument;
Expand Down Expand Up @@ -335,7 +335,7 @@ where
{
Err(SelectionRequestError::InvalidMimetype)
} else {
source.send(mime_type, fd.as_raw_fd());
source.send(mime_type, fd.as_fd());
Ok(())
}
}
Expand Down
Loading

0 comments on commit 5df2af0

Please sign in to comment.