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;
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]
mod shaders;
@ -57,10 +60,12 @@ fn main() {
// Glue for event dispatching
let mut wayland_event_source = Generic::from_raw_fd(display.get_poll_fd());
wayland_event_source.set_interest(Interest::READABLE);
let _wayland_source = event_loop.handle().insert_source(
wayland_event_source,
|_, state: &mut AnvilState| { state.need_wayland_dispatch = true; }
);
let _wayland_source =
event_loop
.handle()
.insert_source(wayland_event_source, |_, state: &mut AnvilState| {
state.need_wayland_dispatch = true;
});
let arg = ::std::env::args().nth(1);
match arg.as_ref().map(|s| &s[..]) {

View File

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

View File

@ -36,7 +36,7 @@ use smithay::{
},
reexports::{
calloop::{
generic::{SourceFd, Generic},
generic::{Generic, SourceFd},
EventLoop, LoopHandle, Source,
},
drm::control::{
@ -264,7 +264,9 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
running.store(false, Ordering::SeqCst);
} else {
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);
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.
ctoken
.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)
}

View File

@ -29,7 +29,11 @@ use crate::input_handler::AnvilInputHandler;
use crate::shell::init_shell;
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(|_| ())?;
#[cfg(feature = "egl")]

View File

@ -55,7 +55,12 @@ fn main() {
.unwrap();
// 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();
// use the connected crtc if any
@ -90,9 +95,13 @@ fn main() {
* But they are very slow, this is just for demonstration purposes.
*/
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 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();
device.set_handler(DrmHandlerImpl {

View File

@ -8,7 +8,7 @@
//! 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 nix::libc::dev_t;
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> {
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)
}
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 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 failure::ResultExt as FailureResultExt;
use gbm::{self, BufferObjectFlags, Format as GbmFormat};
@ -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> {
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)
}
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,
}
impl<S: SessionObserver + 'static, D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static>
AsSessionObserver<GbmDeviceObserver<S, D>> for GbmDevice<D>
impl<
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> {
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>
SessionObserver for GbmDeviceObserver<S, D>
impl<
S: SessionObserver + 'static,
D: RawDevice + ::drm::control::Device + AsSessionObserver<S> + 'static,
> SessionObserver for GbmDeviceObserver<S, D>
{
fn pause(&mut self, devnum: Option<(u32, u32)>) {
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)) =
unsafe { &*backend.cursor.as_ptr() };
if backend.dev.borrow().set_cursor2(
*crtc,
Some(cursor),
((*hotspot).0 as i32, (*hotspot).1 as i32),
)
.is_err()
if backend
.dev
.borrow()
.set_cursor2(*crtc, Some(cursor), ((*hotspot).0 as i32, (*hotspot).1 as i32))
.is_err()
{
if let Err(err) = backend.dev.borrow().set_cursor(*crtc, Some(cursor)) {
error!(self.logger, "Failed to reset cursor. Error: {}", err);

View File

@ -1,7 +1,7 @@
use super::super::{Device, RawDevice, RawSurface, Surface};
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 image::{ImageBuffer, Rgba};
@ -67,7 +67,9 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
let fb = if let Some(info) = maybe_fb {
info
} 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)?;
next_bo.set_userdata(fb).unwrap();
fb
@ -76,9 +78,7 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
if self.recreated.get() {
debug!(self.logger, "Commiting new state");
self.crtc
.commit(fb)
.map_err(|_| SwapBuffersError::ContextLost)?;
self.crtc.commit(fb).map_err(|_| SwapBuffersError::ContextLost)?;
self.recreated.set(false);
}

View File

@ -10,7 +10,9 @@
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 failure::ResultExt as FailureResultExt;
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
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())))?;
let mode = crtc_info.mode();
@ -265,7 +269,8 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
}
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())))
}
@ -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> {
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)
}
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) {
// other ttys that use no cursor, might not clear it themselves.
// 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::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 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");
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))
.compat()
.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
if let Some(mode) = mode {
for connector in &pending.connectors {
if !self.get_connector(*connector)
if !self
.get_connector(*connector)
.compat()
.chain_err(|| {
ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path()))

View File

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

View File

@ -16,7 +16,7 @@ use std::{
};
use calloop::{
generic::{SourceFd, Generic},
generic::{Generic, SourceFd},
mio::Interest,
InsertError, LoopHandle, Source,
};
@ -315,7 +315,12 @@ impl InputBackend for LibinputInputBackend {
};
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);
match self.seats.entry(device_seat.clone()) {
@ -358,7 +363,12 @@ impl InputBackend for LibinputInputBackend {
self.devices.retain(|dev| *dev != removed);
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`.
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) {
// it has not, lets destroy it
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 {
trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat);
handler.on_seat_destroyed(&seat);

View File

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

View File

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

View File

@ -25,8 +25,8 @@ use wayland_server::Display;
use winit::{
dpi::{LogicalPosition, LogicalSize, PhysicalSize},
event::{
ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton,
MouseScrollDelta, Touch, TouchPhase, WindowEvent
ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton, MouseScrollDelta, Touch,
TouchPhase, WindowEvent,
},
event_loop::{ControlFlow, EventLoop},
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 {
let wsize = self.size.borrow();
self.logical_position.x * wsize.scale_factor
@ -509,19 +510,13 @@ impl TouchDownEvent for WinitTouchStartedEvent {
fn x_transformed(&self, width: u32) -> u32 {
let wsize = self.size.borrow();
let w_width = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).width;
cmp::min(
self.location.0 as i32 * width as i32 / w_width,
0,
) as u32
cmp::min(self.location.0 as i32 * width as i32 / w_width, 0) as u32
}
fn y_transformed(&self, height: u32) -> u32 {
let wsize = self.size.borrow();
let w_height = wsize.physical_size.to_logical::<i32>(wsize.scale_factor).height;
cmp::min(
self.location.1 as i32 * height as i32 / w_height,
0,
) as u32
cmp::min(self.location.1 as i32 * height as i32 / w_height, 0) as u32
}
}
@ -701,16 +696,16 @@ impl InputBackend for WinitInputBackend {
let logger = &self.logger;
let window_size = &self.size;
self.events_loop.run_return(move |event, _target, control_flow| {
match event {
self.events_loop
.run_return(move |event, _target, control_flow| match event {
Event::RedrawEventsCleared => {
*control_flow = ControlFlow::Exit;
},
}
Event::RedrawRequested(_id) => {
if let Some(events_handler) = events_handler.as_mut() {
events_handler.refresh();
}
},
}
Event::WindowEvent { event, .. } => {
let duration = Instant::now().duration_since(*time);
let nanos = duration.subsec_nanos() as u64;
@ -732,14 +727,22 @@ impl InputBackend for WinitInputBackend {
(WindowEvent::Focused(focus), _, Some(events_handler)) => {
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();
wsize.scale_factor = scale_factor;
if let Window::Wayland { ref surface, .. } = **window {
surface.resize(new_psize.width as i32, new_psize.height as i32, 0, 0);
}
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);
}
}
@ -869,13 +872,12 @@ impl InputBackend for WinitInputBackend {
(WindowEvent::CloseRequested, _, _) | (WindowEvent::Destroyed, _, _) => {
warn!(logger, "Window closed");
*closed_ptr = true;
},
_ => {},
}
_ => {}
}
},
_ => {},
}
});
}
_ => {}
});
}
if closed {

View File

@ -73,7 +73,7 @@ use wayland_protocols::unstable::linux_dmabuf::v1::server::{
},
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
pub struct Format {
@ -194,45 +194,62 @@ where
formats.len()
);
display.create_global(3, Filter::new(move |(dmabuf, version): (Main<zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1>, u32), _, _| {
let dma_formats = formats.clone();
let dma_handler = handler.clone();
let dma_log = log.clone();
dmabuf.quick_assign(
move |_, req, _| {
if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req {
let mut handler = ParamsHandler {
pending_planes: Vec::new(),
max_planes,
used: false,
formats: dma_formats.clone(),
handler: dma_handler.clone(),
log: dma_log.clone(),
};
params_id.quick_assign(move |params, req, _| match req {
ParamsRequest::Add { fd, plane_idx, offset, stride, 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)
}
_ => {}
});
}
}
);
display.create_global(
3,
Filter::new(
move |(dmabuf, version): (Main<zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1>, u32), _, _| {
let dma_formats = formats.clone();
let dma_handler = handler.clone();
let dma_log = log.clone();
dmabuf.quick_assign(move |_, req, _| {
if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req {
let mut handler = ParamsHandler {
pending_planes: Vec::new(),
max_planes,
used: false,
formats: dma_formats.clone(),
handler: dma_handler.clone(),
log: dma_log.clone(),
};
params_id.quick_assign(move |params, req, _| match req {
ParamsRequest::Add {
fd,
plane_idx,
offset,
stride,
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
for f in &*formats {
dmabuf.format(f.format.as_raw());
if version >= 3 {
dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32);
}
}
}))
// send the supported formats
for f in &*formats {
dmabuf.format(f.format.as_raw());
if version >= 3 {
dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32);
}
}
},
),
)
}
struct ParamsHandler<H: DmabufHandler> {

View File

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

View File

@ -23,36 +23,34 @@ pub(crate) fn implement_shell<R, Impl>(
R: Role<ShellSurfaceRole> + 'static,
Impl: FnMut(ShellRequest<R>) + 'static,
{
shell.quick_assign(
move |shell, req, _data| {
let (id, surface) = match req {
wl_shell::Request::GetShellSurface { id, surface } => (id, surface),
_ => unreachable!(),
};
let role_data = ShellSurfaceRole {
title: "".into(),
class: "".into(),
pending_ping: 0,
};
if ctoken.give_role_with(&surface, role_data).is_err() {
shell
.as_ref()
.post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into());
return;
}
let shell_surface =
implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone());
state
.lock()
.unwrap()
.known_surfaces
.push(make_handle(&shell_surface, ctoken));
let mut imp = implementation.borrow_mut();
(&mut *imp)(ShellRequest::NewShellSurface {
surface: make_handle(&shell_surface, ctoken),
});
},
);
shell.quick_assign(move |shell, req, _data| {
let (id, surface) = match req {
wl_shell::Request::GetShellSurface { id, surface } => (id, surface),
_ => unreachable!(),
};
let role_data = ShellSurfaceRole {
title: "".into(),
class: "".into(),
pending_ping: 0,
};
if ctoken.give_role_with(&surface, role_data).is_err() {
shell
.as_ref()
.post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into());
return;
}
let shell_surface =
implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone());
state
.lock()
.unwrap()
.known_surfaces
.push(make_handle(&shell_surface, ctoken));
let mut imp = implementation.borrow_mut();
(&mut *imp)(ShellRequest::NewShellSurface {
surface: make_handle(&shell_surface, ctoken),
});
});
}
fn make_handle<R>(
@ -91,113 +89,116 @@ where
Impl: FnMut(ShellRequest<R>) + 'static,
{
use self::wl_shell_surface::Request;
shell_surface.quick_assign(
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| {
shell_surface.quick_assign(move |shell_surface, req, _data| {
let data = shell_surface
.as_ref()
.user_data()
.get::<ShellSurfaceUserData<R>>()
.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()
}

View File

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

View File

@ -22,12 +22,10 @@ where
R: Role<XdgSurfaceRole> + 'static,
{
shell.quick_assign(|shell, req, _data| wm_implementation::<R>(req, shell.deref().clone()));
shell.as_ref().user_data().set(||
ShellUserData {
shell_data: shell_data.clone(),
client_data: Mutex::new(make_shell_client_data()),
},
);
shell.as_ref().user_data().set(|| ShellUserData {
shell_data: shell_data.clone(),
client_data: Mutex::new(make_shell_client_data()),
});
let mut user_impl = shell_data.user_impl.borrow_mut();
(&mut *user_impl)(XdgRequest::NewClient {
client: make_shell_client(&shell, shell_data.compositor_token),
@ -89,13 +87,11 @@ where
xdg_surface_implementation::<R>(req, surface.deref().clone())
});
id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::<R>(surface)));
id.as_ref().user_data().set(||
XdgSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: surface,
wm_base: shell.clone(),
},
);
id.as_ref().user_data().set(|| XdgSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: surface,
wm_base: shell.clone(),
});
}
xdg_wm_base::Request::Pong { serial } => {
let valid = {
@ -123,61 +119,60 @@ where
*/
fn implement_positioner(positioner: Main<xdg_positioner::XdgPositioner>) -> xdg_positioner::XdgPositioner {
positioner.quick_assign(
|positioner, request, _data| {
let mutex = positioner
.as_ref()
.user_data()
.get::<RefCell<PositionerState>>()
.unwrap();
let mut state = mutex.borrow_mut();
match request {
xdg_positioner::Request::Destroy => {
// 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!(),
positioner.quick_assign(|positioner, request, _data| {
let mutex = positioner
.as_ref()
.user_data()
.get::<RefCell<PositionerState>>()
.unwrap();
let mut state = mutex.borrow_mut();
match request {
xdg_positioner::Request::Destroy => {
// handled by destructor
}
},
);
positioner.as_ref().user_data().set(||
RefCell::new(PositionerState::new()),
);
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!(),
}
});
positioner
.as_ref()
.user_data()
.set(|| RefCell::new(PositionerState::new()));
positioner.deref().clone()
}
@ -248,18 +243,16 @@ where
});
})
.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.as_ref().user_data().set(||
ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
xdg_surface: xdg_surface.clone(),
wm_base: data.wm_base.clone(),
},
);
id.as_ref().user_data().set(|| ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
xdg_surface: xdg_surface.clone(),
wm_base: data.wm_base.clone(),
});
data.shell_data
.shell_state
@ -302,14 +295,12 @@ where
.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.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup)));
id.as_ref().user_data().set(||
ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
xdg_surface: xdg_surface.clone(),
wm_base: data.wm_base.clone(),
},
);
id.as_ref().user_data().set(|| ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
xdg_surface: xdg_surface.clone(),
wm_base: data.wm_base.clone(),
});
data.shell_data
.shell_state

View File

@ -25,12 +25,10 @@ where
R: Role<XdgSurfaceRole> + 'static,
{
shell.quick_assign(|shell, req, _data| shell_implementation::<R>(req, shell.deref().clone()));
shell.as_ref().user_data().set(||
ShellUserData {
shell_data: shell_data.clone(),
client_data: Mutex::new(make_shell_client_data()),
},
);
shell.as_ref().user_data().set(|| ShellUserData {
shell_data: shell_data.clone(),
client_data: Mutex::new(make_shell_client_data()),
});
let mut user_impl = shell_data.user_impl.borrow_mut();
(&mut *user_impl)(XdgRequest::NewClient {
client: make_shell_client(&shell, shell_data.compositor_token),
@ -88,15 +86,15 @@ where
);
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.as_ref().user_data().set(||
XdgSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: surface,
shell: shell.clone(),
},
);
id.as_ref().user_data().set(|| XdgSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: surface,
shell: shell.clone(),
});
}
zxdg_shell_v6::Request::Pong { serial } => {
let valid = {
@ -126,75 +124,74 @@ where
fn implement_positioner(
positioner: Main<zxdg_positioner_v6::ZxdgPositionerV6>,
) -> zxdg_positioner_v6::ZxdgPositionerV6 {
positioner.quick_assign(
|positioner, request, _data| {
let mutex = positioner
.as_ref()
.user_data()
.get::<RefCell<PositionerState>>()
.unwrap();
let mut state = mutex.borrow_mut();
match request {
zxdg_positioner_v6::Request::Destroy => {
// 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!(),
positioner.quick_assign(|positioner, request, _data| {
let mutex = positioner
.as_ref()
.user_data()
.get::<RefCell<PositionerState>>()
.unwrap();
let mut state = mutex.borrow_mut();
match request {
zxdg_positioner_v6::Request::Destroy => {
// handled by destructor
}
},
);
positioner.as_ref().user_data().set(||
RefCell::new(PositionerState::new()),
);
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!(),
}
});
positioner
.as_ref()
.user_data()
.set(|| RefCell::new(PositionerState::new()));
positioner.deref().clone()
}
@ -267,16 +264,16 @@ fn xdg_surface_implementation<R>(
});
})
.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.as_ref().user_data().set(||
ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
shell: data.shell.clone(),
xdg_surface: xdg_surface.clone(),
},
);
id.as_ref().user_data().set(|| ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
shell: data.shell.clone(),
xdg_surface: xdg_surface.clone(),
});
data.shell_data
.shell_state
@ -316,14 +313,12 @@ fn xdg_surface_implementation<R>(
.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.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::<R>(popup)));
id.as_ref().user_data().set(||
ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
shell: data.shell.clone(),
xdg_surface: xdg_surface.clone(),
},
);
id.as_ref().user_data().set(|| ShellSurfaceUserData {
shell_data: data.shell_data.clone(),
wl_surface: data.wl_surface.clone(),
shell: data.shell.clone(),
xdg_surface: xdg_surface.clone(),
});
data.shell_data
.shell_state

View File

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