Skip to content

Commit

Permalink
Update calloop and wayland-rs to the latest versions
Browse files Browse the repository at this point in the history
Suggested-by: Ian Douglas Scott <[email protected]>
Fixes #402.
  • Loading branch information
kchibisov committed Sep 20, 2023
1 parent f49df45 commit ce68a13
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 70 deletions.
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ features = ["calloop", "xkbcommon"]
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
bitflags = "1.0"
bitflags = "2.4"
bytemuck = { version = "1.13.0", optional = true }
cursor-icon = "1.0.0"
dlib = "0.5"
log = "0.4"
memmap2 = "0.7.0"
nix = { version = "0.26.1", default-features = false, features = ["fs", "mman"] }
thiserror = "1.0.30"
wayland-backend = "0.1.0"
wayland-client = "0.30.2"
wayland-cursor = "0.30.0"
wayland-protocols = { version = "0.30.1", features = ["client", "staging", "unstable"] }
wayland-protocols-wlr = { version = "0.1.0", features = ["client"] }
wayland-scanner = "0.30.0"
wayland-csd-frame = { version = "0.2.2", default-features = false, features = ["wayland-backend_0_1"] }
wayland-backend = "0.3.0"
wayland-client = "0.31.1"
wayland-cursor = "0.31.0"
wayland-protocols = { version = "0.31.0", features = ["client", "staging", "unstable"] }
wayland-protocols-wlr = { version = "0.2.0", features = ["client"] }
wayland-scanner = "0.31.0"
wayland-csd-frame = "0.3.0"

xkbcommon = { version = "0.5.0", optional = true, features = ["wayland"] }
calloop = { version = "0.10.5", optional = true }
xkeysym = "0.2.0"

calloop = { version = "0.12.1", optional = true }
calloop-wayland-source = { version = "0.2.0", optional = true}

[features]
default = ["calloop", "xkbcommon"]
calloop = ["dep:calloop", "wayland-client/calloop"]
calloop = ["dep:calloop", "calloop-wayland-source"]
xkbcommon = ["dep:xkbcommon", "bytemuck", "pkg-config", "xkeysym/bytemuck"]

[build-dependencies]
Expand Down
17 changes: 12 additions & 5 deletions examples/data_device.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{
convert::TryInto,
fs::File,
fs::{self, File},
io::{BufRead, BufReader, Write},
os::unix::io::OwnedFd,
time::Duration,
};

use calloop::{EventLoop, LoopHandle, RegistrationToken};
use smithay_client_toolkit::reexports::calloop::{EventLoop, LoopHandle, RegistrationToken};
use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
data_device_manager::{
Expand Down Expand Up @@ -43,7 +45,6 @@ use smithay_client_toolkit::{
Shm, ShmHandler,
},
};
use wayland_backend::io_lifetimes::OwnedFd;
use wayland_client::{
globals::registry_queue_init,
protocol::{
Expand All @@ -55,7 +56,7 @@ use wayland_client::{
wl_seat::{self, WlSeat},
wl_shm, wl_surface,
},
Connection, QueueHandle, WaylandSource,
Connection, QueueHandle,
};
use wayland_protocols::wp::primary_selection::zv1::client::{
zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1,
Expand All @@ -78,7 +79,7 @@ fn main() {
let mut event_loop: EventLoop<DataDeviceWindow> =
EventLoop::try_new().expect("Failed to initialize the event loop!");
let loop_handle = event_loop.handle();
WaylandSource::new(event_queue).unwrap().insert(loop_handle).unwrap();
WaylandSource::new(conn.clone(), event_queue).insert(loop_handle).unwrap();

// The compositor (not to be confused with the server which is commonly called the compositor) allows
// configuring surfaces to be presented.
Expand Down Expand Up @@ -652,6 +653,8 @@ impl DataDeviceHandler for DataDeviceWindow {
(o, d, Some(t)) => (o, d, t),
_ => return,
};
// SAFETY: it's safe as long as we don't close the underlying file.
let f: &mut fs::File = unsafe { f.get_mut() };
let mut reader = BufReader::new(f);
let consumed = match reader.fill_buf() {
Ok(buf) => {
Expand Down Expand Up @@ -727,6 +730,8 @@ impl DataDeviceHandler for DataDeviceWindow {
(o, d, Some(t)) => (o, d, t),
_ => return,
};
// SAFETY: it's safe as long as we don't close the underlying file.
let f: &mut fs::File = unsafe { f.get_mut() };
let mut reader = BufReader::new(f);
let consumed = match reader.fill_buf() {
Ok(buf) => {
Expand Down Expand Up @@ -921,6 +926,8 @@ impl PrimarySelectionDeviceHandler for DataDeviceWindow {
(o, d, Some(t)) => (o, d, t),
_ => return,
};
// SAFETY: it's safe as long as we don't close the underlying file.
let f: &mut fs::File = unsafe { f.get_mut() };
let mut reader = BufReader::new(f);
let consumed = match reader.fill_buf() {
Ok(buf) => {
Expand Down
7 changes: 4 additions & 3 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{convert::TryInto, time::Duration};

use calloop::{EventLoop, LoopHandle};
use smithay_client_toolkit::reexports::calloop::{EventLoop, LoopHandle};
use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer, delegate_registry,
Expand Down Expand Up @@ -28,7 +29,7 @@ use smithay_client_toolkit::{
use wayland_client::{
globals::registry_queue_init,
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, QueueHandle, WaylandSource,
Connection, QueueHandle,
};

fn main() {
Expand All @@ -43,7 +44,7 @@ fn main() {
let mut event_loop: EventLoop<SimpleWindow> =
EventLoop::try_new().expect("Failed to initialize the event loop!");
let loop_handle = event_loop.handle();
WaylandSource::new(event_queue).unwrap().insert(loop_handle).unwrap();
WaylandSource::new(conn.clone(), event_queue).insert(loop_handle).unwrap();

// The compositor (not to be confused with the server which is commonly called the compositor) allows
// configuring surfaces to be presented.
Expand Down
6 changes: 2 additions & 4 deletions src/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::mem;
use std::os::unix::io::OwnedFd;
use std::sync::MutexGuard;
use std::sync::{
atomic::{AtomicI32, Ordering},
Expand Down Expand Up @@ -421,10 +422,7 @@ impl wayland_client::backend::ObjectData for RegionData {
fn event(
self: Arc<Self>,
_: &wayland_client::backend::Backend,
_: wayland_client::backend::protocol::Message<
wayland_client::backend::ObjectId,
wayland_backend::io_lifetimes::OwnedFd,
>,
_: wayland_client::backend::protocol::Message<wayland_client::backend::ObjectId, OwnedFd>,
) -> Option<Arc<(dyn wayland_client::backend::ObjectData + 'static)>> {
unreachable!("wl_region has no events");
}
Expand Down
6 changes: 3 additions & 3 deletions src/data_device_manager/data_offer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
ops::{Deref, DerefMut},
os::unix::prelude::{FromRawFd, RawFd},
os::unix::prelude::{BorrowedFd, FromRawFd, RawFd},
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -407,7 +407,7 @@ pub fn receive(offer: &WlDataOffer, mime_type: String) -> std::io::Result<ReadPi
// create a pipe
let (readfd, writefd) = pipe2(OFlag::O_CLOEXEC)?;

offer.receive(mime_type, writefd);
offer.receive(mime_type, unsafe { BorrowedFd::borrow_raw(writefd) });

if let Err(err) = close(writefd) {
log::warn!("Failed to close write pipe: {}", err);
Expand All @@ -434,7 +434,7 @@ pub fn receive(offer: &WlDataOffer, mime_type: String) -> std::io::Result<ReadPi
pub unsafe fn receive_to_fd(offer: &WlDataOffer, mime_type: String, writefd: RawFd) {
use nix::unistd::close;

offer.receive(mime_type, writefd);
offer.receive(mime_type, unsafe { BorrowedFd::borrow_raw(writefd) });

if let Err(err) = close(writefd) {
log::warn!("Failed to close write pipe: {}", err);
Expand Down
21 changes: 10 additions & 11 deletions src/data_device_manager/read_pipe.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{
fs, io,
os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd},
};
use wayland_backend::io_lifetimes::{AsFd, OwnedFd};

/// If the `calloop` cargo feature is enabled, this can be used
/// as an `EventSource` in a calloop event loop.
Expand All @@ -18,7 +17,7 @@ pub struct ReadPipe {
#[cfg(feature = "calloop")]
impl io::Read for ReadPipe {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.file.file.read(buf)
unsafe { self.file.get_mut().read(buf) }
}
}

Expand Down Expand Up @@ -72,14 +71,14 @@ impl From<OwnedFd> for ReadPipe {
#[cfg(feature = "calloop")]
impl AsRawFd for ReadPipe {
fn as_raw_fd(&self) -> RawFd {
self.file.file.as_raw_fd()
self.file.get_ref().as_raw_fd()
}
}

#[cfg(feature = "calloop")]
impl AsFd for ReadPipe {
fn as_fd(&self) -> wayland_backend::io_lifetimes::BorrowedFd<'_> {
self.file.file.as_fd()
fn as_fd(&self) -> BorrowedFd<'_> {
self.file.get_ref().as_fd()
}
}

Expand All @@ -92,22 +91,22 @@ impl AsRawFd for ReadPipe {
#[cfg(not(feature = "calloop"))]

impl AsFd for ReadPipe {
fn as_fd(&self) -> wayland_backend::io_lifetimes::BorrowedFd<'_> {
fn as_fd(&self) -> BorrowedFd<'_> {
self.file.as_fd()
}
}

#[cfg(feature = "calloop")]
impl IntoRawFd for ReadPipe {
fn into_raw_fd(self) -> RawFd {
self.file.file.into_raw_fd()
self.file.unwrap().as_raw_fd()
}
}

#[cfg(feature = "calloop")]
impl From<ReadPipe> for OwnedFd {
fn from(read_pipe: ReadPipe) -> Self {
read_pipe.file.file.into()
read_pipe.file.unwrap().into()
}
}

Expand All @@ -129,7 +128,7 @@ impl From<ReadPipe> for OwnedFd {
impl calloop::EventSource for ReadPipe {
type Event = ();
type Error = std::io::Error;
type Metadata = fs::File;
type Metadata = calloop::generic::NoIoDrop<fs::File>;
type Ret = ();

fn process_events<F>(
Expand All @@ -139,7 +138,7 @@ impl calloop::EventSource for ReadPipe {
mut callback: F,
) -> std::io::Result<calloop::PostAction>
where
F: FnMut((), &mut fs::File),
F: FnMut((), &mut calloop::generic::NoIoDrop<fs::File>),
{
self.file.process_events(readiness, token, |_, file| {
callback((), file);
Expand Down
23 changes: 11 additions & 12 deletions src/data_device_manager/write_pipe.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{
fs, io,
os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd},
};
use wayland_backend::io_lifetimes::{AsFd, OwnedFd};

/// If the `calloop` cargo feature is enabled, this can be used
/// as an `EventSource` in a calloop event loop.
Expand All @@ -18,11 +17,11 @@ pub struct WritePipe {
#[cfg(feature = "calloop")]
impl io::Write for WritePipe {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.file.file.write(buf)
unsafe { self.file.get_mut().write(buf) }
}

fn flush(&mut self) -> io::Result<()> {
self.file.file.flush()
unsafe { self.file.get_mut().flush() }
}
}

Expand Down Expand Up @@ -80,14 +79,14 @@ impl From<OwnedFd> for WritePipe {
#[cfg(feature = "calloop")]
impl AsRawFd for WritePipe {
fn as_raw_fd(&self) -> RawFd {
self.file.file.as_raw_fd()
self.file.get_ref().as_raw_fd()
}
}

#[cfg(feature = "calloop")]
impl AsFd for WritePipe {
fn as_fd(&self) -> wayland_backend::io_lifetimes::BorrowedFd<'_> {
self.file.file.as_fd()
fn as_fd(&self) -> BorrowedFd {
self.file.get_ref().as_fd()
}
}

Expand All @@ -100,22 +99,22 @@ impl AsRawFd for WritePipe {
#[cfg(not(feature = "calloop"))]

impl AsFd for WritePipe {
fn as_fd(&self) -> wayland_backend::io_lifetimes::BorrowedFd<'_> {
fn as_fd(&self) -> BorrowedFd<'_> {
self.file.as_fd()
}
}

#[cfg(feature = "calloop")]
impl IntoRawFd for WritePipe {
fn into_raw_fd(self) -> RawFd {
self.file.file.into_raw_fd()
self.file.unwrap().into_raw_fd()
}
}

#[cfg(feature = "calloop")]
impl From<WritePipe> for OwnedFd {
fn from(write_pipe: WritePipe) -> Self {
write_pipe.file.file.into()
write_pipe.file.unwrap().into()
}
}

Expand All @@ -137,7 +136,7 @@ impl From<WritePipe> for OwnedFd {
impl calloop::EventSource for WritePipe {
type Event = ();
type Error = std::io::Error;
type Metadata = fs::File;
type Metadata = calloop::generic::NoIoDrop<fs::File>;
type Ret = ();

fn process_events<F>(
Expand All @@ -147,7 +146,7 @@ impl calloop::EventSource for WritePipe {
mut callback: F,
) -> std::io::Result<calloop::PostAction>
where
F: FnMut((), &mut fs::File),
F: FnMut((), &mut calloop::generic::NoIoDrop<fs::File>),
{
self.file.process_events(readiness, token, |_, file| {
callback((), file);
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
pub mod reexports {
#[cfg(feature = "calloop")]
pub use calloop;
#[cfg(feature = "calloop")]
pub use calloop_wayland_source;
pub use wayland_client as client;
pub use wayland_csd_frame as csd_frame;
pub use wayland_protocols as protocols;
Expand Down
6 changes: 3 additions & 3 deletions src/primary_selection/offer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
os::unix::io::{FromRawFd, RawFd},
os::unix::io::{BorrowedFd, FromRawFd, RawFd},
sync::Mutex,
};

Expand Down Expand Up @@ -41,7 +41,7 @@ impl PrimarySelectionOffer {
// create a pipe
let (readfd, writefd) = pipe2(OFlag::O_CLOEXEC)?;

self.offer.receive(mime_type, writefd);
self.offer.receive(mime_type, unsafe { BorrowedFd::borrow_raw(writefd) });

if let Err(err) = close(writefd) {
log::warn!("Failed to close write pipe: {}", err);
Expand All @@ -57,7 +57,7 @@ impl PrimarySelectionOffer {
pub unsafe fn receive_to_fd(&self, mime_type: String, writefd: RawFd) {
use nix::unistd::close;

self.offer.receive(mime_type, writefd);
self.offer.receive(mime_type, unsafe { BorrowedFd::borrow_raw(writefd) });

if let Err(err) = close(writefd) {
log::warn!("Failed to close write pipe: {}", err);
Expand Down
1 change: 1 addition & 0 deletions src/shell/wlr_layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bitflags! {
/// A combination of two orthogonal edges will cause the layer's anchor point to be the intersection of
/// the edges. For example [`Anchor::TOP`] and [`Anchor::LEFT`] will result in an anchor point in the top
/// left of the anchor rectangle.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Anchor: u32 {
/// Top edge of the anchor rectangle.
const TOP = 1;
Expand Down
Loading

0 comments on commit ce68a13

Please sign in to comment.