Merge pull request #174 from Smithay/reformat

Reformat codebase
This commit is contained in:
Victor Brekenfeld 2020-04-11 13:46:37 +02:00 committed by GitHub
commit cd25b1d222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 567 additions and 457 deletions

View File

@ -8,7 +8,10 @@ extern crate slog;
extern crate smithay; extern crate smithay;
use slog::Drain; use slog::Drain;
use smithay::reexports::{calloop::{EventLoop, generic::Generic, mio::Interest}, wayland_server::Display}; use smithay::reexports::{
calloop::{generic::Generic, mio::Interest, EventLoop},
wayland_server::Display,
};
#[macro_use] #[macro_use]
mod shaders; mod shaders;
@ -57,10 +60,12 @@ fn main() {
// Glue for event dispatching // Glue for event dispatching
let mut wayland_event_source = Generic::from_raw_fd(display.get_poll_fd()); let mut wayland_event_source = Generic::from_raw_fd(display.get_poll_fd());
wayland_event_source.set_interest(Interest::READABLE); wayland_event_source.set_interest(Interest::READABLE);
let _wayland_source = event_loop.handle().insert_source( let _wayland_source =
wayland_event_source, event_loop
|_, state: &mut AnvilState| { state.need_wayland_dispatch = true; } .handle()
); .insert_source(wayland_event_source, |_, state: &mut AnvilState| {
state.need_wayland_dispatch = true;
});
let arg = ::std::env::args().nth(1); let arg = ::std::env::args().nth(1);
match arg.as_ref().map(|s| &s[..]) { match arg.as_ref().map(|s| &s[..]) {

View File

@ -245,7 +245,11 @@ impl PointerGrab for ResizeSurfaceGrab {
self.ctoken self.ctoken
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| { .with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
let mut data = attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut(); let mut data = attrs
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow_mut();
if let ResizeState::Resizing(resize_data) = data.resize_state { if let ResizeState::Resizing(resize_data) = data.resize_state {
data.resize_state = ResizeState::WaitingForFinalAck(resize_data, serial); data.resize_state = ResizeState::WaitingForFinalAck(resize_data, serial);
} else { } else {
@ -255,7 +259,11 @@ impl PointerGrab for ResizeSurfaceGrab {
} else { } else {
self.ctoken self.ctoken
.with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| { .with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| {
let mut data = attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut(); let mut data = attrs
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow_mut();
if let ResizeState::Resizing(resize_data) = data.resize_state { if let ResizeState::Resizing(resize_data) = data.resize_state {
data.resize_state = ResizeState::WaitingForCommit(resize_data); data.resize_state = ResizeState::WaitingForCommit(resize_data);
} else { } else {
@ -414,12 +422,16 @@ pub fn init_shell(
let initial_window_size = (geometry.width, geometry.height); let initial_window_size = (geometry.width, geometry.height);
compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| { compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| {
attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut().resize_state = attrs
ResizeState::Resizing(ResizeData { .user_data
edges: edges.into(), .get::<RefCell<SurfaceData>>()
initial_window_location, .unwrap()
initial_window_size, .borrow_mut()
}); .resize_state = ResizeState::Resizing(ResizeData {
edges: edges.into(),
initial_window_location,
initial_window_size,
});
}); });
let grab = ResizeSurfaceGrab { let grab = ResizeSurfaceGrab {
@ -453,7 +465,11 @@ pub fn init_shell(
if acked { if acked {
compositor_token.with_surface_data(&surface, |attrs| { compositor_token.with_surface_data(&surface, |attrs| {
let mut data = attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut(); let mut data = attrs
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow_mut();
if let ResizeState::WaitingForFinalAck(resize_data, _) = data.resize_state { if let ResizeState::WaitingForFinalAck(resize_data, _) = data.resize_state {
data.resize_state = ResizeState::WaitingForCommit(resize_data); data.resize_state = ResizeState::WaitingForCommit(resize_data);
} else { } else {
@ -566,12 +582,16 @@ pub fn init_shell(
let initial_window_size = (geometry.width, geometry.height); let initial_window_size = (geometry.width, geometry.height);
compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| { compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| {
attrs.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut().resize_state = attrs
ResizeState::Resizing(ResizeData { .user_data
edges: edges.into(), .get::<RefCell<SurfaceData>>()
initial_window_location, .unwrap()
initial_window_size, .borrow_mut()
}); .resize_state = ResizeState::Resizing(ResizeData {
edges: edges.into(),
initial_window_location,
initial_window_size,
});
}); });
let grab = ResizeSurfaceGrab { let grab = ResizeSurfaceGrab {
@ -698,8 +718,14 @@ fn surface_commit(
}); });
let refresh = token.with_surface_data(surface, |attributes| { let refresh = token.with_surface_data(surface, |attributes| {
attributes.user_data.insert_if_missing(|| RefCell::new(SurfaceData::default())); attributes
let mut data = attributes.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut(); .user_data
.insert_if_missing(|| RefCell::new(SurfaceData::default()));
let mut data = attributes
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow_mut();
data.geometry = geometry; data.geometry = geometry;
data.input_region = attributes.input_region.clone(); data.input_region = attributes.input_region.clone();
@ -739,7 +765,11 @@ fn surface_commit(
let Rectangle { width, height, .. } = window_map.geometry(&toplevel).unwrap(); let Rectangle { width, height, .. } = window_map.geometry(&toplevel).unwrap();
let new_location = token.with_surface_data(surface, |attributes| { let new_location = token.with_surface_data(surface, |attributes| {
let mut data = attributes.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow_mut(); let mut data = attributes
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow_mut();
let mut new_location = None; let mut new_location = None;

View File

@ -36,7 +36,7 @@ use smithay::{
}, },
reexports::{ reexports::{
calloop::{ calloop::{
generic::{SourceFd, Generic}, generic::{Generic, SourceFd},
EventLoop, LoopHandle, Source, EventLoop, LoopHandle, Source,
}, },
drm::control::{ drm::control::{
@ -264,7 +264,9 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
running.store(false, Ordering::SeqCst); running.store(false, Ordering::SeqCst);
} else { } else {
if state.need_wayland_dispatch { if state.need_wayland_dispatch {
display.borrow_mut().dispatch(std::time::Duration::from_millis(0), &mut state); display
.borrow_mut()
.dispatch(std::time::Duration::from_millis(0), &mut state);
} }
display.borrow_mut().flush_clients(&mut state); display.borrow_mut().flush_clients(&mut state);
window_map.borrow_mut().refresh(); window_map.borrow_mut().refresh();

View File

@ -160,7 +160,12 @@ where
// It's the set geometry with the full bounding box as the fallback. // It's the set geometry with the full bounding box as the fallback.
ctoken ctoken
.with_surface_data(self.toplevel.get_surface().unwrap(), |attributes| { .with_surface_data(self.toplevel.get_surface().unwrap(), |attributes| {
attributes.user_data.get::<RefCell<SurfaceData>>().unwrap().borrow().geometry attributes
.user_data
.get::<RefCell<SurfaceData>>()
.unwrap()
.borrow()
.geometry
}) })
.unwrap_or(self.bbox) .unwrap_or(self.bbox)
} }

View File

@ -29,7 +29,11 @@ use crate::input_handler::AnvilInputHandler;
use crate::shell::init_shell; use crate::shell::init_shell;
use crate::AnvilState; use crate::AnvilState;
pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<AnvilState>, log: Logger) -> Result<(), ()> { pub fn run_winit(
display: &mut Display,
event_loop: &mut EventLoop<AnvilState>,
log: Logger,
) -> Result<(), ()> {
let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?; let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?;
#[cfg(feature = "egl")] #[cfg(feature = "egl")]

View File

@ -55,7 +55,12 @@ fn main() {
.unwrap(); .unwrap();
// Use the first encoder // Use the first encoder
let encoder = connector_info.encoders().iter().filter_map(|&e| e).next().unwrap(); let encoder = connector_info
.encoders()
.iter()
.filter_map(|&e| e)
.next()
.unwrap();
let encoder_info = device.get_encoder_info(encoder).unwrap(); let encoder_info = device.get_encoder_info(encoder).unwrap();
// use the connected crtc if any // use the connected crtc if any
@ -90,9 +95,13 @@ fn main() {
* But they are very slow, this is just for demonstration purposes. * But they are very slow, this is just for demonstration purposes.
*/ */
let (w, h) = mode.size(); let (w, h) = mode.size();
let front_buffer = device.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888).unwrap(); let front_buffer = device
.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888)
.unwrap();
let front_framebuffer = device.add_framebuffer(&front_buffer).unwrap(); let front_framebuffer = device.add_framebuffer(&front_buffer).unwrap();
let back_buffer = device.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888).unwrap(); let back_buffer = device
.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888)
.unwrap();
let back_framebuffer = device.add_framebuffer(&back_buffer).unwrap(); let back_framebuffer = device.add_framebuffer(&back_buffer).unwrap();
device.set_handler(DrmHandlerImpl { device.set_handler(DrmHandlerImpl {

View File

@ -8,7 +8,7 @@
//! Take a look at `anvil`s source code for an example of this. //! Take a look at `anvil`s source code for an example of this.
//! //!
use drm::control::{crtc, connector, encoder, framebuffer, plane, ResourceHandles}; use drm::control::{connector, crtc, encoder, framebuffer, plane, ResourceHandles};
use drm::SystemError as DrmError; use drm::SystemError as DrmError;
use nix::libc::dev_t; use nix::libc::dev_t;
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
@ -183,7 +183,10 @@ where
fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> { fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> {
self.dev.borrow().get_encoder_info(enc) self.dev.borrow().get_encoder_info(enc)
} }
fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result<framebuffer::Info, DrmError> { fn get_framebuffer_info(
&self,
fb: framebuffer::Handle,
) -> std::result::Result<framebuffer::Info, DrmError> {
self.dev.borrow().get_framebuffer_info(fb) self.dev.borrow().get_framebuffer_info(fb)
} }
fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> { fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> {

View File

@ -11,7 +11,7 @@
use super::{Device, DeviceHandler, RawDevice, ResourceHandles, Surface}; use super::{Device, DeviceHandler, RawDevice, ResourceHandles, Surface};
use drm::control::{crtc, connector, encoder, framebuffer, plane, Device as ControlDevice}; use drm::control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice};
use drm::SystemError as DrmError; use drm::SystemError as DrmError;
use failure::ResultExt as FailureResultExt; use failure::ResultExt as FailureResultExt;
use gbm::{self, BufferObjectFlags, Format as GbmFormat}; use gbm::{self, BufferObjectFlags, Format as GbmFormat};
@ -194,7 +194,7 @@ impl<D: RawDevice + ControlDevice + 'static> Device for GbmDevice<D> {
.compat() .compat()
.chain_err(|| ErrorKind::UnderlyingBackendError) .chain_err(|| ErrorKind::UnderlyingBackendError)
} }
fn get_connector_info(&self, conn: connector::Handle) -> std::result::Result<connector::Info, DrmError> { fn get_connector_info(&self, conn: connector::Handle) -> std::result::Result<connector::Info, DrmError> {
self.dev.borrow().get_connector_info(conn) self.dev.borrow().get_connector_info(conn)
} }
@ -204,7 +204,10 @@ impl<D: RawDevice + ControlDevice + 'static> Device for GbmDevice<D> {
fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> { fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> {
self.dev.borrow().get_encoder_info(enc) self.dev.borrow().get_encoder_info(enc)
} }
fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result<framebuffer::Info, DrmError> { fn get_framebuffer_info(
&self,
fb: framebuffer::Handle,
) -> std::result::Result<framebuffer::Info, DrmError> {
self.dev.borrow().get_framebuffer_info(fb) self.dev.borrow().get_framebuffer_info(fb)
} }
fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> { fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> {

View File

@ -26,8 +26,10 @@ pub struct GbmDeviceObserver<
logger: ::slog::Logger, logger: ::slog::Logger,
} }
impl<S: SessionObserver + 'static, D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static> impl<
AsSessionObserver<GbmDeviceObserver<S, D>> for GbmDevice<D> S: SessionObserver + 'static,
D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static,
> AsSessionObserver<GbmDeviceObserver<S, D>> for GbmDevice<D>
{ {
fn observer(&mut self) -> GbmDeviceObserver<S, D> { fn observer(&mut self) -> GbmDeviceObserver<S, D> {
GbmDeviceObserver { GbmDeviceObserver {
@ -38,8 +40,10 @@ impl<S: SessionObserver + 'static, D: RawDevice + ::drm::control::Device + AsSes
} }
} }
impl<S: SessionObserver + 'static, D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static> impl<
SessionObserver for GbmDeviceObserver<S, D> S: SessionObserver + 'static,
D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static,
> SessionObserver for GbmDeviceObserver<S, D>
{ {
fn pause(&mut self, devnum: Option<(u32, u32)>) { fn pause(&mut self, devnum: Option<(u32, u32)>) {
self.observer.pause(devnum); self.observer.pause(devnum);
@ -65,12 +69,11 @@ impl<S: SessionObserver + 'static, D: RawDevice + ::drm::control::Device + AsSes
let &(ref cursor, ref hotspot): &(BufferObject<()>, (u32, u32)) = let &(ref cursor, ref hotspot): &(BufferObject<()>, (u32, u32)) =
unsafe { &*backend.cursor.as_ptr() }; unsafe { &*backend.cursor.as_ptr() };
if backend.dev.borrow().set_cursor2( if backend
*crtc, .dev
Some(cursor), .borrow()
((*hotspot).0 as i32, (*hotspot).1 as i32), .set_cursor2(*crtc, Some(cursor), ((*hotspot).0 as i32, (*hotspot).1 as i32))
) .is_err()
.is_err()
{ {
if let Err(err) = backend.dev.borrow().set_cursor(*crtc, Some(cursor)) { if let Err(err) = backend.dev.borrow().set_cursor(*crtc, Some(cursor)) {
error!(self.logger, "Failed to reset cursor. Error: {}", err); error!(self.logger, "Failed to reset cursor. Error: {}", err);

View File

@ -1,7 +1,7 @@
use super::super::{Device, RawDevice, RawSurface, Surface}; use super::super::{Device, RawDevice, RawSurface, Surface};
use super::error::*; use super::error::*;
use drm::control::{connector, crtc, framebuffer, Mode, Device as ControlDevice}; use drm::control::{connector, crtc, framebuffer, Device as ControlDevice, Mode};
use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBufferHandle}; use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBufferHandle};
use image::{ImageBuffer, Rgba}; use image::{ImageBuffer, Rgba};
@ -67,7 +67,9 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
let fb = if let Some(info) = maybe_fb { let fb = if let Some(info) = maybe_fb {
info info
} else { } else {
let fb = self.crtc.add_planar_framebuffer(&*next_bo, &[0; 4], 0) let fb = self
.crtc
.add_planar_framebuffer(&*next_bo, &[0; 4], 0)
.map_err(|_| SwapBuffersError::ContextLost)?; .map_err(|_| SwapBuffersError::ContextLost)?;
next_bo.set_userdata(fb).unwrap(); next_bo.set_userdata(fb).unwrap();
fb fb
@ -76,9 +78,7 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
if self.recreated.get() { if self.recreated.get() {
debug!(self.logger, "Commiting new state"); debug!(self.logger, "Commiting new state");
self.crtc self.crtc.commit(fb).map_err(|_| SwapBuffersError::ContextLost)?;
.commit(fb)
.map_err(|_| SwapBuffersError::ContextLost)?;
self.recreated.set(false); self.recreated.set(false);
} }

View File

@ -10,7 +10,9 @@
use super::{DevPath, Device, DeviceHandler, RawDevice}; use super::{DevPath, Device, DeviceHandler, RawDevice};
use drm::control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, ResourceHandles}; use drm::control::{
connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, ResourceHandles,
};
use drm::{Device as BasicDevice, SystemError as DrmError}; use drm::{Device as BasicDevice, SystemError as DrmError};
use failure::ResultExt as FailureResultExt; use failure::ResultExt as FailureResultExt;
use nix::libc::dev_t; use nix::libc::dev_t;
@ -187,7 +189,9 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
// Try to enumarate the current state to set the initial state variable correctly // Try to enumarate the current state to set the initial state variable correctly
let crtc_info = self.get_crtc(crtc).compat() let crtc_info = self
.get_crtc(crtc)
.compat()
.chain_err(|| ErrorKind::DrmDev(format!("Error loading crtc info on {:?}", self.dev_path())))?; .chain_err(|| ErrorKind::DrmDev(format!("Error loading crtc info on {:?}", self.dev_path())))?;
let mode = crtc_info.mode(); let mode = crtc_info.mode();
@ -265,7 +269,8 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
} }
fn resource_handles(&self) -> Result<ResourceHandles> { fn resource_handles(&self) -> Result<ResourceHandles> {
ControlDevice::resource_handles(self).compat() ControlDevice::resource_handles(self)
.compat()
.chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path()))) .chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path())))
} }
@ -278,7 +283,10 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> { fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result<encoder::Info, DrmError> {
self.get_encoder(enc) self.get_encoder(enc)
} }
fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result<framebuffer::Info, DrmError> { fn get_framebuffer_info(
&self,
fb: framebuffer::Handle,
) -> std::result::Result<framebuffer::Info, DrmError> {
self.get_framebuffer(fb) self.get_framebuffer(fb)
} }
fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> { fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result<plane::Info, DrmError> {

View File

@ -54,7 +54,10 @@ impl<A: AsRawFd + 'static> SessionObserver for LegacyDrmDeviceObserver<A> {
for surface in backends.borrow().values().filter_map(Weak::upgrade) { for surface in backends.borrow().values().filter_map(Weak::upgrade) {
// other ttys that use no cursor, might not clear it themselves. // other ttys that use no cursor, might not clear it themselves.
// This makes sure our cursor won't stay visible. // This makes sure our cursor won't stay visible.
let _ = (*device).set_cursor(surface.crtc, Option::<&drm::control::dumbbuffer::DumbBuffer>::None); let _ = (*device).set_cursor(
surface.crtc,
Option::<&drm::control::dumbbuffer::DumbBuffer>::None,
);
} }
} }
} }

View File

@ -1,5 +1,8 @@
use drm::buffer::Buffer; use drm::buffer::Buffer;
use drm::control::{connector, crtc, dumbbuffer::DumbBuffer, encoder, framebuffer, Device as ControlDevice, Mode, PageFlipFlags}; use drm::control::{
connector, crtc, dumbbuffer::DumbBuffer, encoder, framebuffer, Device as ControlDevice, Mode,
PageFlipFlags,
};
use drm::Device as BasicDevice; use drm::Device as BasicDevice;
use failure::ResultExt as FailureResultExt; use failure::ResultExt as FailureResultExt;
@ -54,7 +57,10 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal<A>
{ {
trace!(self.logger, "Setting the new imported cursor"); trace!(self.logger, "Setting the new imported cursor");
if self.set_cursor2(self.crtc, Some(buffer), (hotspot.0 as i32, hotspot.1 as i32)).is_err() { if self
.set_cursor2(self.crtc, Some(buffer), (hotspot.0 as i32, hotspot.1 as i32))
.is_err()
{
self.set_cursor(self.crtc, Some(buffer)) self.set_cursor(self.crtc, Some(buffer))
.compat() .compat()
.chain_err(|| ErrorKind::DrmDev(format!("Failed to set cursor on {:?}", self.dev_path())))?; .chain_err(|| ErrorKind::DrmDev(format!("Failed to set cursor on {:?}", self.dev_path())))?;
@ -140,7 +146,8 @@ impl<A: AsRawFd + 'static> Surface for LegacyDrmSurfaceInternal<A> {
// check the connectors to see if this mode is supported // check the connectors to see if this mode is supported
if let Some(mode) = mode { if let Some(mode) = mode {
for connector in &pending.connectors { for connector in &pending.connectors {
if !self.get_connector(*connector) if !self
.get_connector(*connector)
.compat() .compat()
.chain_err(|| { .chain_err(|| {
ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path()))

View File

@ -36,9 +36,8 @@
//! //!
use drm::{ use drm::{
control::{connector, crtc, encoder, plane, framebuffer, Device as ControlDevice, Mode, ResourceHandles}, control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Mode, ResourceHandles},
Device as BasicDevice, Device as BasicDevice, SystemError as DrmError,
SystemError as DrmError,
}; };
use nix::libc::dev_t; use nix::libc::dev_t;
@ -47,7 +46,7 @@ use std::iter::IntoIterator;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::path::PathBuf; use std::path::PathBuf;
use calloop::generic::{SourceFd, Generic}; use calloop::generic::{Generic, SourceFd};
use calloop::mio::Interest; use calloop::mio::Interest;
use calloop::InsertError; use calloop::InsertError;
use calloop::{LoopHandle, Source}; use calloop::{LoopHandle, Source};

View File

@ -16,7 +16,7 @@ use std::{
}; };
use calloop::{ use calloop::{
generic::{SourceFd, Generic}, generic::{Generic, SourceFd},
mio::Interest, mio::Interest,
InsertError, LoopHandle, Source, InsertError, LoopHandle, Source,
}; };
@ -315,7 +315,12 @@ impl InputBackend for LibinputInputBackend {
}; };
let device_seat = added.seat(); let device_seat = added.seat();
info!(self.logger, "New device {:?} on seat {:?}", added.sysname(), device_seat.logical_name()); info!(
self.logger,
"New device {:?} on seat {:?}",
added.sysname(),
device_seat.logical_name()
);
self.devices.push(added); self.devices.push(added);
match self.seats.entry(device_seat.clone()) { match self.seats.entry(device_seat.clone()) {
@ -358,7 +363,12 @@ impl InputBackend for LibinputInputBackend {
self.devices.retain(|dev| *dev != removed); self.devices.retain(|dev| *dev != removed);
let device_seat = removed.seat(); let device_seat = removed.seat();
info!(self.logger, "Removed device {:?} on seat {:?}", removed.sysname(), device_seat.logical_name()); info!(
self.logger,
"Removed device {:?} on seat {:?}",
removed.sysname(),
device_seat.logical_name()
);
// update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`. // update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`.
if let Some(seat) = self.seats.get_mut(&device_seat) { if let Some(seat) = self.seats.get_mut(&device_seat) {
@ -387,7 +397,11 @@ impl InputBackend for LibinputInputBackend {
if !self.devices.iter().any(|x| x.seat() == device_seat) { if !self.devices.iter().any(|x| x.seat() == device_seat) {
// it has not, lets destroy it // it has not, lets destroy it
if let Some(seat) = self.seats.remove(&device_seat) { if let Some(seat) = self.seats.remove(&device_seat) {
info!(self.logger, "Removing seat {} which no longer has any device", device_seat.logical_name()); info!(
self.logger,
"Removing seat {} which no longer has any device",
device_seat.logical_name()
);
if let Some(ref mut handler) = self.handler { if let Some(ref mut handler) = self.handler {
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat); trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
handler.on_seat_destroyed(&seat); handler.on_seat_destroyed(&seat);

View File

@ -53,7 +53,7 @@ use std::{
use systemd::login; use systemd::login;
use calloop::{ use calloop::{
generic::{Event, SourceRawFd, Generic}, generic::{Event, Generic, SourceRawFd},
mio::Interest, mio::Interest,
InsertError, LoopHandle, Source, InsertError, LoopHandle, Source,
}; };

View File

@ -19,7 +19,7 @@ use std::{
use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result as UdevResult}; use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result as UdevResult};
use calloop::{ use calloop::{
generic::{SourceFd, Generic}, generic::{Generic, SourceFd},
mio::Interest, mio::Interest,
InsertError, LoopHandle, Source, InsertError, LoopHandle, Source,
}; };

View File

@ -25,8 +25,8 @@ use wayland_server::Display;
use winit::{ use winit::{
dpi::{LogicalPosition, LogicalSize, PhysicalSize}, dpi::{LogicalPosition, LogicalSize, PhysicalSize},
event::{ event::{
ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton, ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton, MouseScrollDelta, Touch,
MouseScrollDelta, Touch, TouchPhase, WindowEvent TouchPhase, WindowEvent,
}, },
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
platform::desktop::EventLoopExtDesktop, platform::desktop::EventLoopExtDesktop,
@ -390,7 +390,8 @@ impl BackendEvent for WinitMouseMovedEvent {
} }
} }
impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { // TODO: maybe use {Logical, Physical}Position from winit? impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
// TODO: maybe use {Logical, Physical}Position from winit?
fn x(&self) -> f64 { fn x(&self) -> f64 {
let wsize = self.size.borrow(); let wsize = self.size.borrow();
self.logical_position.x * wsize.scale_factor self.logical_position.x * wsize.scale_factor
@ -509,19 +510,13 @@ impl TouchDownEvent for WinitTouchStartedEvent {
fn x_transformed(&self, width: u32) -> u32 { fn x_transformed(&self, width: u32) -> u32 {
let wsize = self.size.borrow(); let wsize = self.size.borrow();
let w_width = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).width; let w_width = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).width;
cmp::min( cmp::min(self.location.0 as i32 * width as i32 / w_width, 0) as u32
self.location.0 as i32 * width as i32 / w_width,
0,
) as u32
} }
fn y_transformed(&self, height: u32) -> u32 { fn y_transformed(&self, height: u32) -> u32 {
let wsize = self.size.borrow(); let wsize = self.size.borrow();
let w_height = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).height; let w_height = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).height;
cmp::min( cmp::min(self.location.1 as i32 * height as i32 / w_height, 0) as u32
self.location.1 as i32 * height as i32 / w_height,
0,
) as u32
} }
} }
@ -700,17 +695,17 @@ impl InputBackend for WinitInputBackend {
let mut events_handler = self.events_handler.as_mut(); let mut events_handler = self.events_handler.as_mut();
let logger = &self.logger; let logger = &self.logger;
let window_size = &self.size; let window_size = &self.size;
self.events_loop.run_return(move |event, _target, control_flow| { self.events_loop
match event { .run_return(move |event, _target, control_flow| match event {
Event::RedrawEventsCleared => { Event::RedrawEventsCleared => {
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
}, }
Event::RedrawRequested(_id) => { Event::RedrawRequested(_id) => {
if let Some(events_handler) = events_handler.as_mut() { if let Some(events_handler) = events_handler.as_mut() {
events_handler.refresh(); events_handler.refresh();
} }
}, }
Event::WindowEvent { event, .. } => { Event::WindowEvent { event, .. } => {
let duration = Instant::now().duration_since(*time); let duration = Instant::now().duration_since(*time);
let nanos = duration.subsec_nanos() as u64; let nanos = duration.subsec_nanos() as u64;
@ -732,14 +727,22 @@ impl InputBackend for WinitInputBackend {
(WindowEvent::Focused(focus), _, Some(events_handler)) => { (WindowEvent::Focused(focus), _, Some(events_handler)) => {
events_handler.focus_changed(focus) events_handler.focus_changed(focus)
} }
(WindowEvent::ScaleFactorChanged { scale_factor, new_inner_size: new_psize }, _, events_handler) => { (
WindowEvent::ScaleFactorChanged {
scale_factor,
new_inner_size: new_psize,
},
_,
events_handler,
) => {
let mut wsize = window_size.borrow_mut(); let mut wsize = window_size.borrow_mut();
wsize.scale_factor = scale_factor; wsize.scale_factor = scale_factor;
if let Window::Wayland { ref surface, .. } = **window { if let Window::Wayland { ref surface, .. } = **window {
surface.resize(new_psize.width as i32, new_psize.height as i32, 0, 0); surface.resize(new_psize.width as i32, new_psize.height as i32, 0, 0);
} }
if let Some(events_handler) = events_handler { if let Some(events_handler) = events_handler {
let psize_f64: (f64, f64) = (new_psize.width.into(), new_psize.height.into()); let psize_f64: (f64, f64) =
(new_psize.width.into(), new_psize.height.into());
events_handler.resized(psize_f64, wsize.scale_factor); events_handler.resized(psize_f64, wsize.scale_factor);
} }
} }
@ -869,13 +872,12 @@ impl InputBackend for WinitInputBackend {
(WindowEvent::CloseRequested, _, _) | (WindowEvent::Destroyed, _, _) => { (WindowEvent::CloseRequested, _, _) | (WindowEvent::Destroyed, _, _) => {
warn!(logger, "Window closed"); warn!(logger, "Window closed");
*closed_ptr = true; *closed_ptr = true;
}, }
_ => {}, _ => {}
} }
}, }
_ => {}, _ => {}
} });
});
} }
if closed { if closed {

View File

@ -73,7 +73,7 @@ use wayland_protocols::unstable::linux_dmabuf::v1::server::{
}, },
zwp_linux_dmabuf_v1, zwp_linux_dmabuf_v1,
}; };
use wayland_server::{protocol::wl_buffer, Display, Global, Main, Filter}; use wayland_server::{protocol::wl_buffer, Display, Filter, Global, Main};
/// Representation of a Dmabuf format, as advertized to the client /// Representation of a Dmabuf format, as advertized to the client
pub struct Format { pub struct Format {
@ -194,45 +194,62 @@ where
formats.len() formats.len()
); );
display.create_global(3, Filter::new(move |(dmabuf, version): (Main<zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1>, u32), _, _| { display.create_global(
let dma_formats = formats.clone(); 3,
let dma_handler = handler.clone(); Filter::new(
let dma_log = log.clone(); move |(dmabuf, version): (Main<zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1>, u32), _, _| {
dmabuf.quick_assign( let dma_formats = formats.clone();
move |_, req, _| { let dma_handler = handler.clone();
if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req { let dma_log = log.clone();
let mut handler = ParamsHandler { dmabuf.quick_assign(move |_, req, _| {
pending_planes: Vec::new(), if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req {
max_planes, let mut handler = ParamsHandler {
used: false, pending_planes: Vec::new(),
formats: dma_formats.clone(), max_planes,
handler: dma_handler.clone(), used: false,
log: dma_log.clone(), formats: dma_formats.clone(),
}; handler: dma_handler.clone(),
params_id.quick_assign(move |params, req, _| match req { log: dma_log.clone(),
ParamsRequest::Add { fd, plane_idx, offset, stride, modifier_hi, modifier_lo } => { };
handler.add(&*params, fd, plane_idx, offset, stride, modifier_hi, modifier_lo) params_id.quick_assign(move |params, req, _| match req {
}, ParamsRequest::Add {
ParamsRequest::Create { width, height, format, flags } => { fd,
handler.create(&*params, width, height, format, flags) plane_idx,
}, offset,
ParamsRequest::CreateImmed { buffer_id, width, height, format, flags } => { stride,
handler.create_immed(&*params, buffer_id, width, height, format, flags) modifier_hi,
} modifier_lo,
_ => {} } => {
}); handler.add(&*params, fd, plane_idx, offset, stride, modifier_hi, modifier_lo)
} }
} ParamsRequest::Create {
); width,
height,
format,
flags,
} => handler.create(&*params, width, height, format, flags),
ParamsRequest::CreateImmed {
buffer_id,
width,
height,
format,
flags,
} => handler.create_immed(&*params, buffer_id, width, height, format, flags),
_ => {}
});
}
});
// send the supported formats // send the supported formats
for f in &*formats { for f in &*formats {
dmabuf.format(f.format.as_raw()); dmabuf.format(f.format.as_raw());
if version >= 3 { if version >= 3 {
dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32); dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32);
} }
} }
})) },
),
)
} }
struct ParamsHandler<H: DmabufHandler> { struct ParamsHandler<H: DmabufHandler> {

View File

@ -314,9 +314,12 @@ where
})); }));
let state2 = state.clone(); let state2 = state.clone();
let global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { let global = display.create_global(
self::wl_handlers::implement_shell(shell, ctoken, implementation.clone(), state2.clone()); 1,
})); Filter::new(move |(shell, _version), _, _data| {
self::wl_handlers::implement_shell(shell, ctoken, implementation.clone(), state2.clone());
}),
);
(state, global) (state, global)
} }

View File

@ -23,36 +23,34 @@ pub(crate) fn implement_shell<R, Impl>(
R: Role<ShellSurfaceRole> + 'static, R: Role<ShellSurfaceRole> + 'static,
Impl: FnMut(ShellRequest<R>) + 'static, Impl: FnMut(ShellRequest<R>) + 'static,
{ {
shell.quick_assign( shell.quick_assign(move |shell, req, _data| {
move |shell, req, _data| { let (id, surface) = match req {
let (id, surface) = match req { wl_shell::Request::GetShellSurface { id, surface } => (id, surface),
wl_shell::Request::GetShellSurface { id, surface } => (id, surface), _ => unreachable!(),
_ => unreachable!(), };
}; let role_data = ShellSurfaceRole {
let role_data = ShellSurfaceRole { title: "".into(),
title: "".into(), class: "".into(),
class: "".into(), pending_ping: 0,
pending_ping: 0, };
}; if ctoken.give_role_with(&surface, role_data).is_err() {
if ctoken.give_role_with(&surface, role_data).is_err() { shell
shell .as_ref()
.as_ref() .post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into());
.post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into()); return;
return; }
} let shell_surface =
let shell_surface = implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone());
implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone()); state
state .lock()
.lock() .unwrap()
.unwrap() .known_surfaces
.known_surfaces .push(make_handle(&shell_surface, ctoken));
.push(make_handle(&shell_surface, ctoken)); let mut imp = implementation.borrow_mut();
let mut imp = implementation.borrow_mut(); (&mut *imp)(ShellRequest::NewShellSurface {
(&mut *imp)(ShellRequest::NewShellSurface { surface: make_handle(&shell_surface, ctoken),
surface: make_handle(&shell_surface, ctoken), });
}); });
},
);
} }
fn make_handle<R>( fn make_handle<R>(
@ -91,113 +89,116 @@ where
Impl: FnMut(ShellRequest<R>) + 'static, Impl: FnMut(ShellRequest<R>) + 'static,
{ {
use self::wl_shell_surface::Request; use self::wl_shell_surface::Request;
shell_surface.quick_assign( shell_surface.quick_assign(move |shell_surface, req, _data| {
move |shell_surface, req, _data| {
let data = shell_surface
.as_ref()
.user_data()
.get::<ShellSurfaceUserData<R>>()
.unwrap();
let mut user_impl = implementation.borrow_mut();
match req {
Request::Pong { serial } => {
let valid = ctoken
.with_role_data(&data.surface, |data| {
if data.pending_ping == serial {
data.pending_ping = 0;
true
} else {
false
}
})
.expect("wl_shell_surface exists but surface has not the right role?");
if valid {
(&mut *user_impl)(ShellRequest::Pong {
surface: make_handle(&shell_surface, ctoken),
});
}
}
Request::Move { seat, serial } => (&mut *user_impl)(ShellRequest::Move {
surface: make_handle(&shell_surface, ctoken),
serial,
seat,
}),
Request::Resize { seat, serial, edges } => (&mut *user_impl)(ShellRequest::Resize {
surface: make_handle(&shell_surface, ctoken),
serial,
seat,
edges,
}),
Request::SetToplevel => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Toplevel,
}),
Request::SetTransient { parent, x, y, flags } => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Transient {
parent,
location: (x, y),
inactive: flags.contains(wl_shell_surface::Transient::Inactive),
},
}),
Request::SetFullscreen {
method,
framerate,
output,
} => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Fullscreen {
method,
framerate,
output,
},
}),
Request::SetPopup {
seat,
serial,
parent,
x,
y,
flags,
} => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Popup {
parent,
serial,
seat,
location: (x, y),
inactive: flags.contains(wl_shell_surface::Transient::Inactive),
},
}),
Request::SetMaximized { output } => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Maximized { output },
}),
Request::SetTitle { title } => {
ctoken
.with_role_data(&data.surface, |data| data.title = title)
.expect("wl_shell_surface exists but surface has not shell_surface role?!");
}
Request::SetClass { class_ } => {
ctoken
.with_role_data(&data.surface, |data| data.class = class_)
.expect("wl_shell_surface exists but surface has not shell_surface role?!");
}
_ => unreachable!(),
}
},
);
shell_surface.assign_destructor(Filter::new(|shell_surface: wl_shell_surface::WlShellSurface, _, _data| {
let data = shell_surface let data = shell_surface
.as_ref() .as_ref()
.user_data() .user_data()
.get::<ShellSurfaceUserData<R>>() .get::<ShellSurfaceUserData<R>>()
.unwrap(); .unwrap();
data.state.lock().unwrap().cleanup_surfaces(); let mut user_impl = implementation.borrow_mut();
})); match req {
Request::Pong { serial } => {
let valid = ctoken
.with_role_data(&data.surface, |data| {
if data.pending_ping == serial {
data.pending_ping = 0;
true
} else {
false
}
})
.expect("wl_shell_surface exists but surface has not the right role?");
if valid {
(&mut *user_impl)(ShellRequest::Pong {
surface: make_handle(&shell_surface, ctoken),
});
}
}
Request::Move { seat, serial } => (&mut *user_impl)(ShellRequest::Move {
surface: make_handle(&shell_surface, ctoken),
serial,
seat,
}),
Request::Resize { seat, serial, edges } => (&mut *user_impl)(ShellRequest::Resize {
surface: make_handle(&shell_surface, ctoken),
serial,
seat,
edges,
}),
Request::SetToplevel => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Toplevel,
}),
Request::SetTransient { parent, x, y, flags } => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Transient {
parent,
location: (x, y),
inactive: flags.contains(wl_shell_surface::Transient::Inactive),
},
}),
Request::SetFullscreen {
method,
framerate,
output,
} => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Fullscreen {
method,
framerate,
output,
},
}),
Request::SetPopup {
seat,
serial,
parent,
x,
y,
flags,
} => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Popup {
parent,
serial,
seat,
location: (x, y),
inactive: flags.contains(wl_shell_surface::Transient::Inactive),
},
}),
Request::SetMaximized { output } => (&mut *user_impl)(ShellRequest::SetKind {
surface: make_handle(&shell_surface, ctoken),
kind: ShellSurfaceKind::Maximized { output },
}),
Request::SetTitle { title } => {
ctoken
.with_role_data(&data.surface, |data| data.title = title)
.expect("wl_shell_surface exists but surface has not shell_surface role?!");
}
Request::SetClass { class_ } => {
ctoken
.with_role_data(&data.surface, |data| data.class = class_)
.expect("wl_shell_surface exists but surface has not shell_surface role?!");
}
_ => unreachable!(),
}
});
shell_surface.as_ref().user_data().set_threadsafe(|| ShellSurfaceUserData { surface, state }); shell_surface.assign_destructor(Filter::new(
|shell_surface: wl_shell_surface::WlShellSurface, _, _data| {
let data = shell_surface
.as_ref()
.user_data()
.get::<ShellSurfaceUserData<R>>()
.unwrap();
data.state.lock().unwrap().cleanup_surfaces();
},
));
shell_surface
.as_ref()
.user_data()
.set_threadsafe(|| ShellSurfaceUserData { surface, state });
shell_surface.deref().clone() shell_surface.deref().clone()
} }

View File

@ -304,13 +304,19 @@ where
let shell_data_z = shell_data.clone(); let shell_data_z = shell_data.clone();
let xdg_shell_global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { let xdg_shell_global = display.create_global(
self::xdg_handlers::implement_wm_base(shell, &shell_data); 1,
})); Filter::new(move |(shell, _version), _, _data| {
self::xdg_handlers::implement_wm_base(shell, &shell_data);
}),
);
let zxdgv6_shell_global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { let zxdgv6_shell_global = display.create_global(
self::zxdgv6_handlers::implement_shell(shell, &shell_data_z); 1,
})); Filter::new(move |(shell, _version), _, _data| {
self::zxdgv6_handlers::implement_shell(shell, &shell_data_z);
}),
);
(shell_state, xdg_shell_global, zxdgv6_shell_global) (shell_state, xdg_shell_global, zxdgv6_shell_global)
} }

View File

@ -22,12 +22,10 @@ where
R: Role<XdgSurfaceRole> + 'static, R: Role<XdgSurfaceRole> + 'static,
{ {
shell.quick_assign(|shell, req, _data| wm_implementation::<R>(req, shell.deref().clone())); shell.quick_assign(|shell, req, _data| wm_implementation::<R>(req, shell.deref().clone()));
shell.as_ref().user_data().set(|| shell.as_ref().user_data().set(|| ShellUserData {
ShellUserData { shell_data: shell_data.clone(),
shell_data: shell_data.clone(), client_data: Mutex::new(make_shell_client_data()),
client_data: Mutex::new(make_shell_client_data()), });
},
);
let mut user_impl = shell_data.user_impl.borrow_mut(); let mut user_impl = shell_data.user_impl.borrow_mut();
(&mut *user_impl)(XdgRequest::NewClient { (&mut *user_impl)(XdgRequest::NewClient {
client: make_shell_client(&shell, shell_data.compositor_token), client: make_shell_client(&shell, shell_data.compositor_token),
@ -89,13 +87,11 @@ where
xdg_surface_implementation::<R>(req, surface.deref().clone()) xdg_surface_implementation::<R>(req, surface.deref().clone())
}); });
id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::<R>(surface))); id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::<R>(surface)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| XdgSurfaceUserData {
XdgSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: surface,
wl_surface: surface, wm_base: shell.clone(),
wm_base: shell.clone(), });
},
);
} }
xdg_wm_base::Request::Pong { serial } => { xdg_wm_base::Request::Pong { serial } => {
let valid = { let valid = {
@ -123,61 +119,60 @@ where
*/ */
fn implement_positioner(positioner: Main<xdg_positioner::XdgPositioner>) -> xdg_positioner::XdgPositioner { fn implement_positioner(positioner: Main<xdg_positioner::XdgPositioner>) -> xdg_positioner::XdgPositioner {
positioner.quick_assign( positioner.quick_assign(|positioner, request, _data| {
|positioner, request, _data| { let mutex = positioner
let mutex = positioner .as_ref()
.as_ref() .user_data()
.user_data() .get::<RefCell<PositionerState>>()
.get::<RefCell<PositionerState>>() .unwrap();
.unwrap(); let mut state = mutex.borrow_mut();
let mut state = mutex.borrow_mut(); match request {
match request { xdg_positioner::Request::Destroy => {
xdg_positioner::Request::Destroy => { // handled by destructor
// handled by destructor
}
xdg_positioner::Request::SetSize { width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
xdg_positioner::Error::InvalidInput as u32,
"Invalid size for positioner.".into(),
);
} else {
state.rect_size = (width, height);
}
}
xdg_positioner::Request::SetAnchorRect { x, y, width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
xdg_positioner::Error::InvalidInput as u32,
"Invalid size for positioner's anchor rectangle.".into(),
);
} else {
state.anchor_rect = Rectangle { x, y, width, height };
}
}
xdg_positioner::Request::SetAnchor { anchor } => {
state.anchor_edges = anchor;
}
xdg_positioner::Request::SetGravity { gravity } => {
state.gravity = gravity;
}
xdg_positioner::Request::SetConstraintAdjustment {
constraint_adjustment,
} => {
let constraint_adjustment =
xdg_positioner::ConstraintAdjustment::from_bits_truncate(constraint_adjustment);
state.constraint_adjustment = constraint_adjustment;
}
xdg_positioner::Request::SetOffset { x, y } => {
state.offset = (x, y);
}
_ => unreachable!(),
} }
}, xdg_positioner::Request::SetSize { width, height } => {
); if width < 1 || height < 1 {
positioner.as_ref().user_data().set(|| positioner.as_ref().post_error(
RefCell::new(PositionerState::new()), xdg_positioner::Error::InvalidInput as u32,
); "Invalid size for positioner.".into(),
);
} else {
state.rect_size = (width, height);
}
}
xdg_positioner::Request::SetAnchorRect { x, y, width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
xdg_positioner::Error::InvalidInput as u32,
"Invalid size for positioner's anchor rectangle.".into(),
);
} else {
state.anchor_rect = Rectangle { x, y, width, height };
}
}
xdg_positioner::Request::SetAnchor { anchor } => {
state.anchor_edges = anchor;
}
xdg_positioner::Request::SetGravity { gravity } => {
state.gravity = gravity;
}
xdg_positioner::Request::SetConstraintAdjustment {
constraint_adjustment,
} => {
let constraint_adjustment =
xdg_positioner::ConstraintAdjustment::from_bits_truncate(constraint_adjustment);
state.constraint_adjustment = constraint_adjustment;
}
xdg_positioner::Request::SetOffset { x, y } => {
state.offset = (x, y);
}
_ => unreachable!(),
}
});
positioner
.as_ref()
.user_data()
.set(|| RefCell::new(PositionerState::new()));
positioner.deref().clone() positioner.deref().clone()
} }
@ -248,18 +243,16 @@ where
}); });
}) })
.expect("xdg_surface exists but surface has not shell_surface role?!"); .expect("xdg_surface exists but surface has not shell_surface role?!");
id.quick_assign( id.quick_assign(|toplevel, req, _data| {
|toplevel, req, _data| toplevel_implementation::<R>(req, toplevel.deref().clone()), toplevel_implementation::<R>(req, toplevel.deref().clone())
); });
id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::<R>(toplevel))); id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::<R>(toplevel)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| ShellSurfaceUserData {
ShellSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(),
wl_surface: data.wl_surface.clone(), xdg_surface: xdg_surface.clone(),
xdg_surface: xdg_surface.clone(), wm_base: data.wm_base.clone(),
wm_base: data.wm_base.clone(), });
},
);
data.shell_data data.shell_data
.shell_state .shell_state
@ -302,14 +295,12 @@ where
.expect("xdg_surface exists but surface has not shell_surface role?!"); .expect("xdg_surface exists but surface has not shell_surface role?!");
id.quick_assign(|popup, req, _data| xg_popup_implementation::<R>(req, popup.deref().clone())); id.quick_assign(|popup, req, _data| xg_popup_implementation::<R>(req, popup.deref().clone()));
id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup))); id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| ShellSurfaceUserData {
ShellSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(),
wl_surface: data.wl_surface.clone(), xdg_surface: xdg_surface.clone(),
xdg_surface: xdg_surface.clone(), wm_base: data.wm_base.clone(),
wm_base: data.wm_base.clone(), });
},
);
data.shell_data data.shell_data
.shell_state .shell_state

View File

@ -25,12 +25,10 @@ where
R: Role<XdgSurfaceRole> + 'static, R: Role<XdgSurfaceRole> + 'static,
{ {
shell.quick_assign(|shell, req, _data| shell_implementation::<R>(req, shell.deref().clone())); shell.quick_assign(|shell, req, _data| shell_implementation::<R>(req, shell.deref().clone()));
shell.as_ref().user_data().set(|| shell.as_ref().user_data().set(|| ShellUserData {
ShellUserData { shell_data: shell_data.clone(),
shell_data: shell_data.clone(), client_data: Mutex::new(make_shell_client_data()),
client_data: Mutex::new(make_shell_client_data()), });
},
);
let mut user_impl = shell_data.user_impl.borrow_mut(); let mut user_impl = shell_data.user_impl.borrow_mut();
(&mut *user_impl)(XdgRequest::NewClient { (&mut *user_impl)(XdgRequest::NewClient {
client: make_shell_client(&shell, shell_data.compositor_token), client: make_shell_client(&shell, shell_data.compositor_token),
@ -88,15 +86,15 @@ where
); );
return; return;
} }
id.quick_assign(|surface, req, _data| xdg_surface_implementation::<R>(req, surface.deref().clone())); id.quick_assign(|surface, req, _data| {
xdg_surface_implementation::<R>(req, surface.deref().clone())
});
id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::<R>(surface))); id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::<R>(surface)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| XdgSurfaceUserData {
XdgSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: surface,
wl_surface: surface, shell: shell.clone(),
shell: shell.clone(), });
},
);
} }
zxdg_shell_v6::Request::Pong { serial } => { zxdg_shell_v6::Request::Pong { serial } => {
let valid = { let valid = {
@ -126,75 +124,74 @@ where
fn implement_positioner( fn implement_positioner(
positioner: Main<zxdg_positioner_v6::ZxdgPositionerV6>, positioner: Main<zxdg_positioner_v6::ZxdgPositionerV6>,
) -> zxdg_positioner_v6::ZxdgPositionerV6 { ) -> zxdg_positioner_v6::ZxdgPositionerV6 {
positioner.quick_assign( positioner.quick_assign(|positioner, request, _data| {
|positioner, request, _data| { let mutex = positioner
let mutex = positioner .as_ref()
.as_ref() .user_data()
.user_data() .get::<RefCell<PositionerState>>()
.get::<RefCell<PositionerState>>() .unwrap();
.unwrap(); let mut state = mutex.borrow_mut();
let mut state = mutex.borrow_mut(); match request {
match request { zxdg_positioner_v6::Request::Destroy => {
zxdg_positioner_v6::Request::Destroy => { // handled by destructor
// handled by destructor
}
zxdg_positioner_v6::Request::SetSize { width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid size for positioner.".into(),
);
} else {
state.rect_size = (width, height);
}
}
zxdg_positioner_v6::Request::SetAnchorRect { x, y, width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid size for positioner's anchor rectangle.".into(),
);
} else {
state.anchor_rect = Rectangle { x, y, width, height };
}
}
zxdg_positioner_v6::Request::SetAnchor { anchor } => {
if let Some(anchor) = zxdg_anchor_to_xdg(anchor) {
state.anchor_edges = anchor;
} else {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid anchor for positioner.".into(),
);
}
}
zxdg_positioner_v6::Request::SetGravity { gravity } => {
if let Some(gravity) = zxdg_gravity_to_xdg(gravity) {
state.gravity = gravity;
} else {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid gravity for positioner.".into(),
);
}
}
zxdg_positioner_v6::Request::SetConstraintAdjustment {
constraint_adjustment,
} => {
let constraint_adjustment =
zxdg_positioner_v6::ConstraintAdjustment::from_bits_truncate(constraint_adjustment);
state.constraint_adjustment = zxdg_constraints_adg_to_xdg(constraint_adjustment);
}
zxdg_positioner_v6::Request::SetOffset { x, y } => {
state.offset = (x, y);
}
_ => unreachable!(),
} }
}, zxdg_positioner_v6::Request::SetSize { width, height } => {
); if width < 1 || height < 1 {
positioner.as_ref().user_data().set(|| positioner.as_ref().post_error(
RefCell::new(PositionerState::new()), zxdg_positioner_v6::Error::InvalidInput as u32,
); "Invalid size for positioner.".into(),
);
} else {
state.rect_size = (width, height);
}
}
zxdg_positioner_v6::Request::SetAnchorRect { x, y, width, height } => {
if width < 1 || height < 1 {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid size for positioner's anchor rectangle.".into(),
);
} else {
state.anchor_rect = Rectangle { x, y, width, height };
}
}
zxdg_positioner_v6::Request::SetAnchor { anchor } => {
if let Some(anchor) = zxdg_anchor_to_xdg(anchor) {
state.anchor_edges = anchor;
} else {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid anchor for positioner.".into(),
);
}
}
zxdg_positioner_v6::Request::SetGravity { gravity } => {
if let Some(gravity) = zxdg_gravity_to_xdg(gravity) {
state.gravity = gravity;
} else {
positioner.as_ref().post_error(
zxdg_positioner_v6::Error::InvalidInput as u32,
"Invalid gravity for positioner.".into(),
);
}
}
zxdg_positioner_v6::Request::SetConstraintAdjustment {
constraint_adjustment,
} => {
let constraint_adjustment =
zxdg_positioner_v6::ConstraintAdjustment::from_bits_truncate(constraint_adjustment);
state.constraint_adjustment = zxdg_constraints_adg_to_xdg(constraint_adjustment);
}
zxdg_positioner_v6::Request::SetOffset { x, y } => {
state.offset = (x, y);
}
_ => unreachable!(),
}
});
positioner
.as_ref()
.user_data()
.set(|| RefCell::new(PositionerState::new()));
positioner.deref().clone() positioner.deref().clone()
} }
@ -267,16 +264,16 @@ fn xdg_surface_implementation<R>(
}); });
}) })
.expect("xdg_surface exists but surface has not shell_surface role?!"); .expect("xdg_surface exists but surface has not shell_surface role?!");
id.quick_assign(|toplevel, req, _data| toplevel_implementation::<R>(req, toplevel.deref().clone())); id.quick_assign(|toplevel, req, _data| {
toplevel_implementation::<R>(req, toplevel.deref().clone())
});
id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::<R>(toplevel))); id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::<R>(toplevel)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| ShellSurfaceUserData {
ShellSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(),
wl_surface: data.wl_surface.clone(), shell: data.shell.clone(),
shell: data.shell.clone(), xdg_surface: xdg_surface.clone(),
xdg_surface: xdg_surface.clone(), });
},
);
data.shell_data data.shell_data
.shell_state .shell_state
@ -316,14 +313,12 @@ fn xdg_surface_implementation<R>(
.expect("xdg_surface exists but surface has not shell_surface role?!"); .expect("xdg_surface exists but surface has not shell_surface role?!");
id.quick_assign(|popup, req, _data| popup_implementation::<R>(req, popup.deref().clone())); id.quick_assign(|popup, req, _data| popup_implementation::<R>(req, popup.deref().clone()));
id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup))); id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup)));
id.as_ref().user_data().set(|| id.as_ref().user_data().set(|| ShellSurfaceUserData {
ShellSurfaceUserData { shell_data: data.shell_data.clone(),
shell_data: data.shell_data.clone(), wl_surface: data.wl_surface.clone(),
wl_surface: data.wl_surface.clone(), shell: data.shell.clone(),
shell: data.shell.clone(), xdg_surface: xdg_surface.clone(),
xdg_surface: xdg_surface.clone(), });
},
);
data.shell_data data.shell_data
.shell_state .shell_state

View File

@ -266,7 +266,7 @@ impl ShmGlobalData {
format, format,
}, },
}; };
buffer.quick_assign(|_,_,_| {}); buffer.quick_assign(|_, _, _| {});
buffer.as_ref().user_data().set(|| data); buffer.as_ref().user_data().set(|| data);
} }
Request::Resize { size } => match arc_pool.resize(size) { Request::Resize { size } => match arc_pool.resize(size) {