mirror of
https://github.com/Smithay/smithay.git
synced 2024-09-29 17:38:46 +02:00
Update wayland-rs to 0.30.0-alpha5
This commit is contained in:
parent
fb7a65ea68
commit
c5c0f91210
21 changed files with 276 additions and 269 deletions
14
Cargo.toml
14
Cargo.toml
|
@ -43,11 +43,11 @@ slog-stdlog = { version = "4", optional = true }
|
|||
tempfile = { version = "3.0", optional = true }
|
||||
thiserror = "1.0.25"
|
||||
udev = { version = "0.6", optional = true }
|
||||
# wayland-commons = { git = "https://github.com/Smithay/wayland-rs", branch="rework-317", optional = true }
|
||||
wayland-egl = { git = "https://github.com/Smithay/wayland-rs.git", optional = true }
|
||||
wayland-protocols = { git = "https://github.com/Smithay/wayland-rs.git", features = ["unstable_protocols", "server"], optional = true }
|
||||
wayland-server = { git = "https://github.com/Smithay/wayland-rs.git", optional = true }
|
||||
wayland-sys = { git = "https://github.com/Smithay/wayland-rs.git", optional = true }
|
||||
wayland-egl = { version = "0.30.0-alpha5", optional = true }
|
||||
wayland-protocols = { version = "0.30.0-alpha5", features = ["unstable_protocols", "server"], optional = true }
|
||||
wayland-server = { version = "0.30.0-alpha5", optional = true }
|
||||
wayland-sys = { version = "0.30.0-alpha5", optional = true }
|
||||
wayland-backend = { version = "0.1.0-alpha5", optional = true }
|
||||
winit = { version = "0.26", optional = true }
|
||||
x11rb = { version = "0.9.0", optional = true }
|
||||
xkbcommon = "0.4.0"
|
||||
|
@ -76,7 +76,7 @@ backend_session_libseat = ["backend_session", "libseat"]
|
|||
desktop = ["indexmap", "wayland_frontend"]
|
||||
renderer_gl = ["gl_generator", "backend_egl"]
|
||||
renderer_multi = ["backend_drm"]
|
||||
use_system_lib = ["wayland_frontend", "wayland-sys"]
|
||||
use_system_lib = ["wayland_frontend", "wayland-backend/server_system", "wayland-sys"]
|
||||
wayland_frontend = ["wayland-server", "wayland-protocols", "tempfile"]
|
||||
x11rb_event_source = ["x11rb"]
|
||||
xwayland = ["wayland_frontend"]
|
||||
|
@ -84,4 +84,4 @@ test_all_features = ["default"]
|
|||
|
||||
[[example]]
|
||||
name = "raw_drm"
|
||||
required-features = ["backend_drm"]
|
||||
required-features = ["backend_drm"]
|
|
@ -66,6 +66,12 @@ impl ClientData<App> for ClientState {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsMut<CompositorState> for App {
|
||||
fn as_mut(&mut self) -> &mut CompositorState {
|
||||
&mut self.compositor_state
|
||||
}
|
||||
}
|
||||
|
||||
delegate_global_dispatch!(App: [WlCompositor] => CompositorState);
|
||||
delegate_dispatch!(App: [WlCompositor, WlSurface, WlRegion, WlCallback] => CompositorState);
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ use smithay::{
|
|||
input::{InputEvent, KeyboardKeyEvent},
|
||||
renderer::{
|
||||
utils::{draw_surface_tree, on_commit_buffer_handler},
|
||||
Frame, Renderer, Transform,
|
||||
Frame, Renderer,
|
||||
},
|
||||
winit::{self, WinitEvent},
|
||||
},
|
||||
reexports::wayland_server::Display,
|
||||
utils::Rectangle,
|
||||
utils::{Rectangle, Transform},
|
||||
wayland::{
|
||||
compositor::{
|
||||
with_surface_tree_downward, CompositorHandler, CompositorState, SurfaceAttributes,
|
||||
|
@ -186,6 +186,7 @@ pub fn run_winit() -> Result<(), Box<dyn std::error::Error>> {
|
|||
1.0,
|
||||
(0, 0).into(),
|
||||
&[damage.to_logical(1)],
|
||||
&mut display.handle(),
|
||||
&log,
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -197,14 +198,11 @@ pub fn run_winit() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
backend.submit(Some(&[damage.to_logical(1)]), 1.0).unwrap();
|
||||
|
||||
match listener.accept()? {
|
||||
Some(stream) => {
|
||||
println!("Got a client: {:?}", stream);
|
||||
if let Some(stream) = listener.accept()? {
|
||||
println!("Got a client: {:?}", stream);
|
||||
|
||||
let client = display.insert_client(stream, Arc::new(ClientState)).unwrap();
|
||||
clients.push(client);
|
||||
}
|
||||
None => {}
|
||||
let client = display.insert_client(stream, Arc::new(ClientState)).unwrap();
|
||||
clients.push(client);
|
||||
}
|
||||
|
||||
display.dispatch_clients(&mut state)?;
|
||||
|
|
|
@ -614,15 +614,14 @@ impl EGLDisplay {
|
|||
/// This might return [`OtherEGLDisplayAlreadyBound`](Error::OtherEGLDisplayAlreadyBound)
|
||||
/// if called for the same [`Display`] multiple times, as only one egl display may be bound at any given time.
|
||||
#[cfg(all(feature = "use_system_lib", feature = "wayland_frontend"))]
|
||||
pub fn bind_wl_display(&self, display: &Display) -> Result<EGLBufferReader, Error> {
|
||||
pub fn bind_wl_display<D: 'static>(&self, display: &Display<D>) -> Result<EGLBufferReader, Error> {
|
||||
let display_ptr = display.backend().lock().unwrap().display_ptr();
|
||||
if !self.extensions.iter().any(|s| s == "EGL_WL_bind_wayland_display") {
|
||||
return Err(Error::EglExtensionNotSupported(&["EGL_WL_bind_wayland_display"]));
|
||||
}
|
||||
wrap_egl_call(|| unsafe {
|
||||
ffi::egl::BindWaylandDisplayWL(**self.display, display.c_ptr() as *mut _)
|
||||
})
|
||||
.map_err(Error::OtherEGLDisplayAlreadyBound)?;
|
||||
let reader = EGLBufferReader::new(self.display.clone(), display.c_ptr(), self.logger.clone());
|
||||
wrap_egl_call(|| unsafe { ffi::egl::BindWaylandDisplayWL(**self.display, display_ptr as *mut _) })
|
||||
.map_err(Error::OtherEGLDisplayAlreadyBound)?;
|
||||
let reader = EGLBufferReader::new(self.display.clone(), display_ptr, self.logger.clone());
|
||||
let mut global = BUFFER_READER.lock().unwrap();
|
||||
if global.as_ref().and_then(|x| x.upgrade()).is_some() {
|
||||
warn!(
|
||||
|
@ -802,9 +801,11 @@ impl EGLBufferReader {
|
|||
/// a [`BufferAccessError::NotManaged`](crate::backend::egl::BufferAccessError::NotManaged) is returned.
|
||||
pub fn egl_buffer_contents(
|
||||
&self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &WlBuffer,
|
||||
) -> ::std::result::Result<EGLBuffer, BufferAccessError> {
|
||||
if !buffer.as_ref().is_alive() {
|
||||
use wayland_server::Resource;
|
||||
if dh.get_object_data(buffer.id()).is_err() {
|
||||
debug!(self.logger, "Suplied buffer is no longer alive");
|
||||
return Err(BufferAccessError::NotManaged(EGLError::BadParameter));
|
||||
}
|
||||
|
@ -813,7 +814,7 @@ impl EGLBufferReader {
|
|||
let query = wrap_egl_call(|| unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::EGL_TEXTURE_FORMAT,
|
||||
&mut format,
|
||||
)
|
||||
|
@ -843,7 +844,7 @@ impl EGLBufferReader {
|
|||
wrap_egl_call(|| unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::WIDTH as i32,
|
||||
&mut width,
|
||||
)
|
||||
|
@ -854,7 +855,7 @@ impl EGLBufferReader {
|
|||
wrap_egl_call(|| unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::HEIGHT as i32,
|
||||
&mut height,
|
||||
)
|
||||
|
@ -875,7 +876,7 @@ impl EGLBufferReader {
|
|||
match wrap_egl_call(|| unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::WAYLAND_Y_INVERTED_WL,
|
||||
&mut inverted,
|
||||
)
|
||||
|
@ -898,7 +899,7 @@ impl EGLBufferReader {
|
|||
**self.display,
|
||||
ffi::egl::NO_CONTEXT,
|
||||
ffi::egl::WAYLAND_BUFFER_WL,
|
||||
buffer.as_ref().c_ptr() as *mut _,
|
||||
buffer.id().as_ptr() as *mut _,
|
||||
out.as_ptr(),
|
||||
)
|
||||
})
|
||||
|
@ -923,9 +924,11 @@ impl EGLBufferReader {
|
|||
/// context has been lost, `None` is returned.
|
||||
pub fn egl_buffer_dimensions(
|
||||
&self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &WlBuffer,
|
||||
) -> Option<crate::utils::Size<i32, crate::utils::Buffer>> {
|
||||
if !buffer.as_ref().is_alive() {
|
||||
use wayland_server::Resource;
|
||||
if dh.get_object_data(buffer.id()).is_err() {
|
||||
debug!(self.logger, "Suplied buffer is no longer alive");
|
||||
return None;
|
||||
}
|
||||
|
@ -934,7 +937,7 @@ impl EGLBufferReader {
|
|||
if unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::WIDTH as _,
|
||||
&mut width,
|
||||
) == 0
|
||||
|
@ -946,7 +949,7 @@ impl EGLBufferReader {
|
|||
if unsafe {
|
||||
ffi::egl::QueryWaylandBufferWL(
|
||||
**self.display,
|
||||
buffer.as_ref().c_ptr() as _,
|
||||
buffer.id().as_ptr() as _,
|
||||
ffi::egl::HEIGHT as _,
|
||||
&mut height,
|
||||
) == 0
|
||||
|
|
|
@ -1002,9 +1002,9 @@ impl ImportMem for Gles2Renderer {
|
|||
feature = "use_system_lib"
|
||||
))]
|
||||
impl ImportEgl for Gles2Renderer {
|
||||
fn bind_wl_display(
|
||||
fn bind_wl_display<D: 'static>(
|
||||
&mut self,
|
||||
display: &wayland_server::Display,
|
||||
display: &wayland_server::Display<D>,
|
||||
) -> Result<(), crate::backend::egl::Error> {
|
||||
self.egl_reader = Some(self.egl.display.bind_wl_display(display)?);
|
||||
Ok(())
|
||||
|
@ -1020,6 +1020,7 @@ impl ImportEgl for Gles2Renderer {
|
|||
|
||||
fn import_egl_buffer(
|
||||
&mut self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
_surface: Option<&crate::wayland::compositor::SurfaceData>,
|
||||
_damage: &[Rectangle<i32, Buffer>],
|
||||
|
@ -1045,7 +1046,7 @@ impl ImportEgl for Gles2Renderer {
|
|||
.egl_reader
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.egl_buffer_contents(buffer)
|
||||
.egl_buffer_contents(dh, buffer)
|
||||
.map_err(Gles2Error::EGLBufferAccessError)?;
|
||||
|
||||
let tex = self.import_egl_image(egl.image(0).unwrap(), egl.format == EGLFormat::External, None)?;
|
||||
|
|
|
@ -332,7 +332,7 @@ pub trait ImportEgl: Renderer {
|
|||
/// This might return [`OtherEGLDisplayAlreadyBound`](super::egl::Error::OtherEGLDisplayAlreadyBound)
|
||||
/// if called for the same [`Display`](wayland_server::Display) multiple times, as only one egl
|
||||
/// display may be bound at any given time.
|
||||
fn bind_wl_display(&mut self, display: &wayland_server::Display) -> Result<(), EglError>;
|
||||
fn bind_wl_display<D: 'static>(&mut self, display: &wayland_server::Display<D>) -> Result<(), EglError>;
|
||||
|
||||
/// Unbinds a previously bound egl display, if existing.
|
||||
///
|
||||
|
@ -361,6 +361,7 @@ pub trait ImportEgl: Renderer {
|
|||
/// to avoid relying on implementation details, keep the buffer alive, until you destroyed this texture again.
|
||||
fn import_egl_buffer(
|
||||
&mut self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
surface: Option<&crate::wayland::compositor::SurfaceData>,
|
||||
damage: &[Rectangle<i32, Buffer>],
|
||||
|
@ -446,6 +447,7 @@ pub trait ImportAll: Renderer {
|
|||
/// Returns `None`, if the buffer type cannot be determined.
|
||||
fn import_buffer(
|
||||
&mut self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
surface: Option<&crate::wayland::compositor::SurfaceData>,
|
||||
damage: &[Rectangle<i32, Buffer>],
|
||||
|
@ -461,13 +463,14 @@ pub trait ImportAll: Renderer {
|
|||
impl<R: Renderer + ImportMemWl + ImportEgl + ImportDmaWl> ImportAll for R {
|
||||
fn import_buffer(
|
||||
&mut self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
surface: Option<&SurfaceData>,
|
||||
damage: &[Rectangle<i32, Buffer>],
|
||||
) -> Option<Result<<Self as Renderer>::TextureId, <Self as Renderer>::Error>> {
|
||||
match buffer_type(buffer) {
|
||||
match buffer_type(dh, buffer) {
|
||||
Some(BufferType::Shm) => Some(self.import_shm_buffer(buffer, surface, damage)),
|
||||
Some(BufferType::Egl) => Some(self.import_egl_buffer(buffer, surface, damage)),
|
||||
Some(BufferType::Egl) => Some(self.import_egl_buffer(dh, buffer, surface, damage)),
|
||||
Some(BufferType::Dma) => Some(self.import_dma_buffer(buffer, surface, damage)),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -481,11 +484,12 @@ impl<R: Renderer + ImportMemWl + ImportEgl + ImportDmaWl> ImportAll for R {
|
|||
impl<R: Renderer + ImportMemWl + ImportDmaWl> ImportAll for R {
|
||||
fn import_buffer(
|
||||
&mut self,
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
surface: Option<&SurfaceData>,
|
||||
damage: &[Rectangle<i32, Buffer>],
|
||||
) -> Option<Result<<Self as Renderer>::TextureId, <Self as Renderer>::Error>> {
|
||||
match buffer_type(buffer) {
|
||||
match buffer_type(dh, buffer) {
|
||||
Some(BufferType::Shm) => Some(self.import_shm_buffer(buffer, surface, damage)),
|
||||
Some(BufferType::Dma) => Some(self.import_dma_buffer(buffer, surface, damage)),
|
||||
_ => None,
|
||||
|
@ -577,7 +581,10 @@ pub enum BufferType {
|
|||
/// Returns `None` if the type is not known to smithay
|
||||
/// or otherwise not supported (e.g. not initialized using one of smithays [`crate::wayland`]-handlers).
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
||||
pub fn buffer_type(
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
) -> Option<BufferType> {
|
||||
if buffer.data::<Dmabuf>().is_some() {
|
||||
return Some(BufferType::Dma);
|
||||
}
|
||||
|
@ -588,7 +595,7 @@ pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
|||
.unwrap()
|
||||
.as_ref()
|
||||
.and_then(|x| x.upgrade())
|
||||
.and_then(|x| x.egl_buffer_dimensions(buffer))
|
||||
.and_then(|x| x.egl_buffer_dimensions(dh, buffer))
|
||||
.is_some()
|
||||
{
|
||||
return Some(BufferType::Egl);
|
||||
|
@ -605,7 +612,10 @@ pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
|
|||
///
|
||||
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<Size<i32, Buffer>> {
|
||||
pub fn buffer_dimensions(
|
||||
dh: &mut wayland_server::DisplayHandle<'_>,
|
||||
buffer: &wl_buffer::WlBuffer,
|
||||
) -> Option<Size<i32, Buffer>> {
|
||||
use crate::backend::allocator::Buffer;
|
||||
|
||||
if let Some(buf) = buffer.data::<Dmabuf>() {
|
||||
|
@ -618,7 +628,7 @@ pub fn buffer_dimensions(buffer: &wl_buffer::WlBuffer) -> Option<Size<i32, Buffe
|
|||
.unwrap()
|
||||
.as_ref()
|
||||
.and_then(|x| x.upgrade())
|
||||
.and_then(|x| x.egl_buffer_dimensions(buffer))
|
||||
.and_then(|x| x.egl_buffer_dimensions(dh, buffer))
|
||||
{
|
||||
return Some(dim);
|
||||
}
|
||||
|
|
|
@ -231,6 +231,7 @@ impl SurfaceView {
|
|||
/// [`crate::backend::renderer::utils::on_commit_buffer_handler`]
|
||||
/// to let smithay handle buffer management.
|
||||
pub fn import_surface_tree<R>(
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
renderer: &mut R,
|
||||
surface: &WlSurface,
|
||||
log: &slog::Logger,
|
||||
|
@ -239,10 +240,11 @@ where
|
|||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
import_surface_tree_and(renderer, surface, 1.0, log, (0.0, 0.0).into(), |_, _, _| {})
|
||||
import_surface_tree_and(dh, renderer, surface, 1.0, log, (0.0, 0.0).into(), |_, _, _| {})
|
||||
}
|
||||
|
||||
fn import_surface_tree_and<F, R, S>(
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
renderer: &mut R,
|
||||
surface: &WlSurface,
|
||||
scale: S,
|
||||
|
@ -272,7 +274,7 @@ where
|
|||
let buffer_damage = data.damage_since(last_commit.copied());
|
||||
if let Entry::Vacant(e) = data.textures.entry(texture_id) {
|
||||
if let Some(buffer) = data.buffer.as_ref() {
|
||||
match renderer.import_buffer(buffer, Some(states), &buffer_damage) {
|
||||
match renderer.import_buffer(dh, buffer, Some(states), &buffer_damage) {
|
||||
Some(Ok(m)) => {
|
||||
e.insert(Box::new(m));
|
||||
data.renderer_seen.insert(texture_id, data.commit_count);
|
||||
|
@ -324,6 +326,7 @@ pub fn draw_surface_tree<R, S>(
|
|||
scale: S,
|
||||
location: Point<f64, Physical>,
|
||||
damage: &[Rectangle<i32, Physical>],
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
log: &slog::Logger,
|
||||
) -> Result<(), <R as Renderer>::Error>
|
||||
where
|
||||
|
@ -335,6 +338,7 @@ where
|
|||
let mut result = Ok(());
|
||||
let scale = scale.into();
|
||||
let _ = import_surface_tree_and(
|
||||
dh,
|
||||
renderer,
|
||||
surface,
|
||||
scale,
|
||||
|
|
|
@ -13,7 +13,7 @@ use wayland_server::{
|
|||
wl_surface::{self, WlSurface},
|
||||
},
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||
Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||
};
|
||||
|
||||
use crate::utils::{Logical, Point};
|
||||
|
@ -151,16 +151,6 @@ pub struct SurfaceUserData {
|
|||
pub(crate) inner: Mutex<PrivateSurfaceData>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for SurfaceUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
PrivateSurfaceData::cleanup(self, object_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlSurface> for CompositorState {
|
||||
type UserData = SurfaceUserData;
|
||||
}
|
||||
|
@ -281,6 +271,15 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
_state: &mut D,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
data: &Self::UserData,
|
||||
) {
|
||||
PrivateSurfaceData::cleanup(data, object_id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -293,15 +292,6 @@ pub struct RegionUserData {
|
|||
pub(crate) inner: Mutex<RegionAttributes>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for RegionUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
_object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlRegion> for CompositorState {
|
||||
type UserData = RegionUserData;
|
||||
}
|
||||
|
@ -424,20 +414,6 @@ where
|
|||
pub struct SubsurfaceUserData {
|
||||
surface: WlSurface,
|
||||
}
|
||||
|
||||
impl DestructionNotify for SubsurfaceUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
_object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
// TODO
|
||||
// if surface.as_ref().is_alive() {
|
||||
PrivateSurfaceData::unset_parent(&self.surface);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/// The cached state associated with a subsurface
|
||||
#[derive(Debug)]
|
||||
pub struct SubsurfaceCachedState {
|
||||
|
@ -562,6 +538,18 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
_state: &mut D,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
_object_id: wayland_server::backend::ObjectId,
|
||||
data: &Self::UserData,
|
||||
) {
|
||||
// TODO
|
||||
// if surface.as_ref().is_alive() {
|
||||
PrivateSurfaceData::unset_parent(&data.surface);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlCallback> for CompositorState {
|
||||
|
|
|
@ -5,8 +5,8 @@ use wayland_protocols::unstable::xdg_output::v1::server::{
|
|||
};
|
||||
use wayland_server::{
|
||||
protocol::wl_output::{self, Mode as WMode, WlOutput},
|
||||
DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, GlobalDispatch, Resource,
|
||||
DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase, Dispatch,
|
||||
GlobalDispatch, Resource,
|
||||
};
|
||||
|
||||
use super::{xdg::XdgOutput, Output, OutputGlobalData, OutputManagerState, OutputUserData};
|
||||
|
@ -93,6 +93,21 @@ where
|
|||
_data_init: &mut wayland_server::DataInit<'_, D>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
_state: &mut D,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
data: &Self::UserData,
|
||||
) {
|
||||
data.global_data
|
||||
.inner
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.instances
|
||||
.retain(|o| o.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -175,21 +190,6 @@ pub struct XdgOutputUserData {
|
|||
xdg_output: XdgOutput,
|
||||
}
|
||||
|
||||
impl DestructionNotify for XdgOutputUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
self.xdg_output
|
||||
.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.instances
|
||||
.retain(|o| o.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<ZxdgOutputV1> for OutputManagerState {
|
||||
type UserData = XdgOutputUserData;
|
||||
}
|
||||
|
@ -208,4 +208,18 @@ where
|
|||
_data_init: &mut wayland_server::DataInit<'_, D>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
_state: &mut D,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
data: &Self::UserData,
|
||||
) {
|
||||
data.xdg_output
|
||||
.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.instances
|
||||
.retain(|o| o.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ use wayland_server::{
|
|||
wl_output::{Subpixel, Transform},
|
||||
wl_surface,
|
||||
},
|
||||
DestructionNotify, DisplayHandle, GlobalDispatch, Resource,
|
||||
DisplayHandle, GlobalDispatch, Resource,
|
||||
};
|
||||
use wayland_server::{
|
||||
protocol::wl_output::{Mode as WMode, WlOutput},
|
||||
|
@ -222,22 +222,6 @@ pub struct OutputUserData {
|
|||
pub(crate) global_data: OutputData,
|
||||
}
|
||||
|
||||
impl DestructionNotify for OutputUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
self.global_data
|
||||
.inner
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.instances
|
||||
.retain(|o| o.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
fn send_geometry_to(&self, dh: &mut DisplayHandle<'_>, output: &WlOutput) {
|
||||
output.geometry(
|
||||
|
|
|
@ -16,7 +16,7 @@ use wayland_server::{
|
|||
wl_keyboard::{self, KeyState as WlKeyState, KeymapFormat, WlKeyboard},
|
||||
wl_surface::WlSurface,
|
||||
},
|
||||
Client, DelegateDispatch, DelegateDispatchBase, DestructionNotify, Dispatch, DisplayHandle, Resource,
|
||||
Client, DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle, Resource,
|
||||
};
|
||||
use xkbcommon::xkb;
|
||||
pub use xkbcommon::xkb::{keysyms, Keysym};
|
||||
|
@ -179,11 +179,14 @@ impl KbdInternal {
|
|||
GrabStatus::Active(_, ref mut handler) => {
|
||||
// If this grab is associated with a surface that is no longer alive, discard it
|
||||
if let Some(ref surface) = handler.start_data().focus {
|
||||
// TODO
|
||||
/*
|
||||
if !surface.as_ref().is_alive() {
|
||||
self.grab = GrabStatus::None;
|
||||
f(KeyboardInnerHandle { inner: self, logger }, &mut DefaultGrab);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
f(KeyboardInnerHandle { inner: self, logger }, &mut **handler);
|
||||
}
|
||||
|
@ -293,6 +296,7 @@ pub trait KeyboardGrab {
|
|||
/// An input was reported
|
||||
fn input(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
handle: &mut KeyboardInnerHandle<'_>,
|
||||
keycode: u32,
|
||||
key_state: WlKeyState,
|
||||
|
@ -302,7 +306,13 @@ pub trait KeyboardGrab {
|
|||
);
|
||||
|
||||
/// A focus change was requested
|
||||
fn set_focus(&mut self, handle: &mut KeyboardInnerHandle<'_>, focus: Option<&WlSurface>, serial: Serial);
|
||||
fn set_focus(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
handle: &mut KeyboardInnerHandle<'_>,
|
||||
focus: Option<&WlSurface>,
|
||||
serial: Serial,
|
||||
);
|
||||
|
||||
/// The data about the event that started the grab.
|
||||
fn start_data(&self) -> &GrabStartData;
|
||||
|
@ -364,17 +374,17 @@ impl KeyboardHandle {
|
|||
///
|
||||
/// Overwrites any current grab.
|
||||
pub fn set_grab<G: KeyboardGrab + 'static>(&self, grab: G, serial: Serial) {
|
||||
self.arc.internal.borrow_mut().grab = GrabStatus::Active(serial, Box::new(grab));
|
||||
self.arc.internal.lock().unwrap().grab = GrabStatus::Active(serial, Box::new(grab));
|
||||
}
|
||||
|
||||
/// Remove any current grab on this keyboard, resetting it to the default behavior
|
||||
pub fn unset_grab(&self) {
|
||||
self.arc.internal.borrow_mut().grab = GrabStatus::None;
|
||||
self.arc.internal.lock().unwrap().grab = GrabStatus::None;
|
||||
}
|
||||
|
||||
/// Check if this keyboard is currently grabbed with this serial
|
||||
pub fn has_grab(&self, serial: Serial) -> bool {
|
||||
let guard = self.arc.internal.borrow_mut();
|
||||
let guard = self.arc.internal.lock().unwrap();
|
||||
match guard.grab {
|
||||
GrabStatus::Active(s, _) => s == serial,
|
||||
_ => false,
|
||||
|
@ -383,13 +393,13 @@ impl KeyboardHandle {
|
|||
|
||||
/// Check if this keyboard is currently being grabbed
|
||||
pub fn is_grabbed(&self) -> bool {
|
||||
let guard = self.arc.internal.borrow_mut();
|
||||
let guard = self.arc.internal.lock().unwrap();
|
||||
!matches!(guard.grab, GrabStatus::None)
|
||||
}
|
||||
|
||||
/// Returns the start data for the grab, if any.
|
||||
pub fn grab_start_data(&self) -> Option<GrabStartData> {
|
||||
let guard = self.arc.internal.borrow();
|
||||
let guard = self.arc.internal.lock().unwrap();
|
||||
match &guard.grab {
|
||||
GrabStatus::Active(_, g) => Some(g.start_data().clone()),
|
||||
_ => None,
|
||||
|
@ -454,7 +464,7 @@ impl KeyboardHandle {
|
|||
};
|
||||
guard.with_grab(
|
||||
move |mut handle, grab| {
|
||||
grab.input(&mut handle, keycode, wl_state, modifiers, serial, time);
|
||||
grab.input(dh, &mut handle, keycode, wl_state, modifiers, serial, time);
|
||||
},
|
||||
self.arc.logger.clone(),
|
||||
);
|
||||
|
@ -473,12 +483,12 @@ impl KeyboardHandle {
|
|||
/// will be sent a [`wl_keyboard::Event::Leave`](wayland_server::protocol::wl_keyboard::Event::Leave)
|
||||
/// event, and if the new focus is not `None`,
|
||||
/// a [`wl_keyboard::Event::Enter`](wayland_server::protocol::wl_keyboard::Event::Enter) event will be sent.
|
||||
pub fn set_focus(&self, cx: &mut DisplayHandle<'_>, focus: Option<&WlSurface>, serial: Serial) {
|
||||
let mut guard = self.arc.internal.borrow_mut();
|
||||
pub fn set_focus(&self, dh: &mut DisplayHandle<'_>, focus: Option<&WlSurface>, serial: Serial) {
|
||||
let mut guard = self.arc.internal.lock().unwrap();
|
||||
guard.pending_focus = focus.cloned();
|
||||
guard.with_grab(
|
||||
move |mut handle, grab| {
|
||||
grab.set_focus(&mut handle, focus, serial);
|
||||
grab.set_focus(dh, &mut handle, focus, serial);
|
||||
},
|
||||
self.arc.logger.clone(),
|
||||
);
|
||||
|
@ -587,11 +597,9 @@ where
|
|||
_data_init: &mut wayland_server::DataInit<'_, D>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl DestructionNotify for KeyboardUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, object_id: ObjectId) {
|
||||
if let Some(ref handle) = self.handle {
|
||||
fn destroyed(_state: &mut D, _client_id: ClientId, object_id: ObjectId, data: &Self::UserData) {
|
||||
if let Some(ref handle) = data.handle {
|
||||
handle
|
||||
.arc
|
||||
.internal
|
||||
|
@ -623,12 +631,12 @@ impl<'a> KeyboardInnerHandle<'a> {
|
|||
///
|
||||
/// This will also restore the focus of the underlying keyboard if restore_focus
|
||||
/// is [`true`]
|
||||
pub fn unset_grab(&mut self, serial: Serial, restore_focus: bool) {
|
||||
pub fn unset_grab(&mut self, dh: &mut DisplayHandle<'_>, serial: Serial, restore_focus: bool) {
|
||||
self.inner.grab = GrabStatus::None;
|
||||
// restore the focus
|
||||
if restore_focus {
|
||||
let focus = self.inner.pending_focus.clone();
|
||||
self.set_focus(focus.as_ref(), serial);
|
||||
self.set_focus(dh, focus.as_ref(), serial);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,6 +648,7 @@ impl<'a> KeyboardInnerHandle<'a> {
|
|||
/// Send the input to the focused keyboards
|
||||
pub fn input(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
keycode: u32,
|
||||
key_state: WlKeyState,
|
||||
modifiers: Option<(u32, u32, u32, u32)>,
|
||||
|
@ -649,9 +658,9 @@ impl<'a> KeyboardInnerHandle<'a> {
|
|||
self.inner.with_focused_kbds(|kbd, _| {
|
||||
// key event must be sent before modifers event for libxkbcommon
|
||||
// to process them correctly
|
||||
kbd.key(serial.into(), time, keycode, key_state);
|
||||
kbd.key(dh, serial.into(), time, keycode, key_state);
|
||||
if let Some((dep, la, lo, gr)) = modifiers {
|
||||
kbd.modifiers(serial.into(), dep, la, lo, gr);
|
||||
kbd.modifiers(dh, serial.into(), dep, la, lo, gr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -662,18 +671,18 @@ impl<'a> KeyboardInnerHandle<'a> {
|
|||
/// will be sent a [`wl_keyboard::Event::Leave`](wayland_server::protocol::wl_keyboard::Event::Leave)
|
||||
/// event, and if the new focus is not `None`,
|
||||
/// a [`wl_keyboard::Event::Enter`](wayland_server::protocol::wl_keyboard::Event::Enter) event will be sent.
|
||||
pub fn set_focus(&mut self, focus: Option<&WlSurface>, serial: Serial) {
|
||||
pub fn set_focus(&mut self, dh: &mut DisplayHandle<'_>, focus: Option<&WlSurface>, serial: Serial) {
|
||||
let same = self
|
||||
.inner
|
||||
.focus
|
||||
.as_ref()
|
||||
.and_then(|f| focus.map(|s| s.as_ref().equals(f.0.as_ref())))
|
||||
.and_then(|f| focus.map(|s| s.equals(f.0)))
|
||||
.unwrap_or(false);
|
||||
|
||||
if !same {
|
||||
// unset old focus
|
||||
self.inner.with_focused_kbds(|kbd, s| {
|
||||
kbd.leave(serial.into(), s);
|
||||
kbd.leave(dh, serial.into(), s);
|
||||
});
|
||||
|
||||
// set new focus
|
||||
|
@ -681,9 +690,9 @@ impl<'a> KeyboardInnerHandle<'a> {
|
|||
let (dep, la, lo, gr) = self.inner.serialize_modifiers();
|
||||
let keys = self.inner.serialize_pressed_keys();
|
||||
self.inner.with_focused_kbds(|kbd, surface| {
|
||||
kbd.enter(serial.into(), surface, keys.clone());
|
||||
kbd.enter(dh, serial.into(), surface, keys.clone());
|
||||
// Modifiers must be send after enter event.
|
||||
kbd.modifiers(serial.into(), dep, la, lo, gr);
|
||||
kbd.modifiers(dh, serial.into(), dep, la, lo, gr);
|
||||
});
|
||||
{
|
||||
let KbdInternal {
|
||||
|
@ -710,6 +719,7 @@ struct DefaultGrab;
|
|||
impl KeyboardGrab for DefaultGrab {
|
||||
fn input(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
handle: &mut KeyboardInnerHandle<'_>,
|
||||
keycode: u32,
|
||||
key_state: WlKeyState,
|
||||
|
@ -717,11 +727,17 @@ impl KeyboardGrab for DefaultGrab {
|
|||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
handle.input(keycode, key_state, modifiers, serial, time)
|
||||
handle.input(dh, keycode, key_state, modifiers, serial, time)
|
||||
}
|
||||
|
||||
fn set_focus(&mut self, handle: &mut KeyboardInnerHandle<'_>, focus: Option<&WlSurface>, serial: Serial) {
|
||||
handle.set_focus(focus, serial)
|
||||
fn set_focus(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
handle: &mut KeyboardInnerHandle<'_>,
|
||||
focus: Option<&WlSurface>,
|
||||
serial: Serial,
|
||||
) {
|
||||
handle.set_focus(dh, focus, serial)
|
||||
}
|
||||
|
||||
fn start_data(&self) -> &GrabStartData {
|
||||
|
|
|
@ -64,7 +64,7 @@ use wayland_server::{
|
|||
wl_surface,
|
||||
},
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, Display, DisplayHandle, GlobalDispatch, New, Resource,
|
||||
Dispatch, Display, DisplayHandle, GlobalDispatch, New, Resource,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -390,19 +390,6 @@ impl ::std::cmp::PartialEq for SeatState {
|
|||
pub struct SeatUserData {
|
||||
seat: std::sync::Weak<SeatRc>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for SeatUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, object_id: ObjectId) {
|
||||
if let Some(seat) = self.seat.upgrade() {
|
||||
seat.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_seats
|
||||
.retain(|s| s.id() != object_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlSeat> for SeatState {
|
||||
type UserData = SeatUserData;
|
||||
}
|
||||
|
@ -471,6 +458,16 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(_state: &mut D, _: ClientId, object_id: ObjectId, data: &Self::UserData) {
|
||||
if let Some(seat) = data.seat.upgrade() {
|
||||
seat.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_seats
|
||||
.retain(|s| s.id() != object_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateGlobalDispatchBase<WlSeat> for SeatState {
|
||||
|
|
|
@ -9,7 +9,7 @@ use wayland_server::{
|
|||
wl_pointer::{self, Axis, ButtonState, Request, WlPointer},
|
||||
wl_surface::WlSurface,
|
||||
},
|
||||
DelegateDispatch, DelegateDispatchBase, DestructionNotify, Dispatch, DisplayHandle, Resource,
|
||||
DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle, Resource,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -67,24 +67,31 @@ impl PointerInternal {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_grab<G: PointerGrab + 'static>(&mut self, serial: Serial, grab: G, time: u32) {
|
||||
fn set_grab<G: PointerGrab + 'static>(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
serial: Serial,
|
||||
grab: G,
|
||||
time: u32,
|
||||
) {
|
||||
self.grab = GrabStatus::Active(serial, Box::new(grab));
|
||||
// generate a move to let the grab change the focus or move the pointer as result of its initialization
|
||||
let location = self.location;
|
||||
let focus = self.focus.clone();
|
||||
self.motion(location, focus, serial, time);
|
||||
self.motion(dh, location, focus, serial, time);
|
||||
}
|
||||
|
||||
fn unset_grab(&mut self, serial: Serial, time: u32) {
|
||||
fn unset_grab(&mut self, dh: &mut DisplayHandle<'_>, serial: Serial, time: u32) {
|
||||
self.grab = GrabStatus::None;
|
||||
// restore the focus
|
||||
let location = self.location;
|
||||
let focus = self.pending_focus.clone();
|
||||
self.motion(location, focus, serial, time);
|
||||
self.motion(dh, location, focus, serial, time);
|
||||
}
|
||||
|
||||
fn motion(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
location: Point<f64, Logical>,
|
||||
focus: Option<(WlSurface, Point<i32, Logical>)>,
|
||||
serial: Serial,
|
||||
|
@ -95,16 +102,16 @@ impl PointerInternal {
|
|||
self.location = location;
|
||||
if let Some((ref current_focus, _)) = self.focus {
|
||||
if let Some((ref surface, _)) = focus {
|
||||
if current_focus.as_ref().equals(surface.as_ref()) {
|
||||
if current_focus == surface {
|
||||
leave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if leave {
|
||||
self.with_focused_pointers(|pointer, surface| {
|
||||
pointer.leave(serial.into(), surface);
|
||||
if pointer.as_ref().version() >= 5 {
|
||||
pointer.frame();
|
||||
self.with_focused_pointers(dh, |dh, pointer, surface| {
|
||||
pointer.leave(dh, serial.into(), surface);
|
||||
if pointer.version() >= 5 {
|
||||
pointer.frame(dh);
|
||||
}
|
||||
});
|
||||
self.focus = None;
|
||||
|
@ -119,18 +126,18 @@ impl PointerInternal {
|
|||
self.focus = Some((surface, surface_location));
|
||||
let (x, y) = (location - surface_location.to_f64()).into();
|
||||
if entered {
|
||||
self.with_focused_pointers(|pointer, surface| {
|
||||
pointer.enter(serial.into(), surface, x, y);
|
||||
if pointer.as_ref().version() >= 5 {
|
||||
pointer.frame();
|
||||
self.with_focused_pointers(dh, |dh, pointer, surface| {
|
||||
pointer.enter(dh, serial.into(), surface, x, y);
|
||||
if pointer.version() >= 5 {
|
||||
pointer.frame(dh);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// we were on top of a surface and remained on it
|
||||
self.with_focused_pointers(|pointer, _| {
|
||||
pointer.motion(time, x, y);
|
||||
if pointer.as_ref().version() >= 5 {
|
||||
pointer.frame();
|
||||
self.with_focused_pointers(dh, |dh, pointer, _| {
|
||||
pointer.motion(dh, time, x, y);
|
||||
if pointer.version() >= 5 {
|
||||
pointer.frame(dh);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -226,13 +233,19 @@ impl PointerHandle {
|
|||
/// Change the current grab on this pointer to the provided grab
|
||||
///
|
||||
/// Overwrites any current grab.
|
||||
pub fn set_grab<G: PointerGrab + 'static>(&self, grab: G, serial: Serial, time: u32) {
|
||||
self.inner.lock().unwrap().set_grab(serial, grab, time);
|
||||
pub fn set_grab<G: PointerGrab + 'static>(
|
||||
&self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
grab: G,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
self.inner.lock().unwrap().set_grab(dh, serial, grab, time);
|
||||
}
|
||||
|
||||
/// Remove any current grab on this pointer, resetting it to the default behavior
|
||||
pub fn unset_grab(&self, serial: Serial, time: u32) {
|
||||
self.inner.lock().unwrap().unset_grab(serial, time);
|
||||
pub fn unset_grab(&self, dh: &mut DisplayHandle<'_>, serial: Serial, time: u32) {
|
||||
self.inner.lock().unwrap().unset_grab(dh, serial, time);
|
||||
}
|
||||
|
||||
/// Check if this pointer is currently grabbed with this serial
|
||||
|
@ -338,15 +351,21 @@ impl<'a> PointerInnerHandle<'a> {
|
|||
/// Change the current grab on this pointer to the provided grab
|
||||
///
|
||||
/// Overwrites any current grab.
|
||||
pub fn set_grab<G: PointerGrab + 'static>(&mut self, serial: Serial, time: u32, grab: G) {
|
||||
self.inner.set_grab(serial, grab, time);
|
||||
pub fn set_grab<G: PointerGrab + 'static>(
|
||||
&mut self,
|
||||
dh: &mut DisplayHandle<'_>,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
grab: G,
|
||||
) {
|
||||
self.inner.set_grab(dh, serial, grab, time);
|
||||
}
|
||||
|
||||
/// Remove any current grab on this pointer, resetting it to the default behavior
|
||||
///
|
||||
/// This will also restore the focus of the underlying pointer
|
||||
pub fn unset_grab(&mut self, dh: &mut DisplayHandle<'_>, serial: Serial, time: u32) {
|
||||
self.inner.unset_grab(serial, time);
|
||||
self.inner.unset_grab(dh, serial, time);
|
||||
}
|
||||
|
||||
/// Access the current focus of this pointer
|
||||
|
@ -386,7 +405,7 @@ impl<'a> PointerInnerHandle<'a> {
|
|||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
self.inner.motion(location, focus, serial, time);
|
||||
self.inner.motion(dh, location, focus, serial, time);
|
||||
}
|
||||
|
||||
/// Notify that a button was pressed
|
||||
|
@ -536,11 +555,9 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DestructionNotify for PointerUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, object_id: ObjectId) {
|
||||
if let Some(ref handle) = self.handle {
|
||||
fn destroyed(_state: &mut D, _: ClientId, object_id: ObjectId, data: &Self::UserData) {
|
||||
if let Some(ref handle) = data.handle {
|
||||
handle
|
||||
.inner
|
||||
.lock()
|
||||
|
|
|
@ -126,7 +126,9 @@ impl PointerGrab for DefaultGrab {
|
|||
) {
|
||||
handle.button(dh, button, state, serial, time);
|
||||
handle.set_grab(
|
||||
dh,
|
||||
serial,
|
||||
time,
|
||||
ClickGrab {
|
||||
start_data: GrabStartData {
|
||||
focus: handle.current_focus().cloned(),
|
||||
|
|
|
@ -7,8 +7,8 @@ use wayland_protocols::wlr::unstable::layer_shell::v1::server::zwlr_layer_surfac
|
|||
use wayland_protocols::wlr::unstable::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
|
||||
use wayland_server::protocol::wl_surface;
|
||||
use wayland_server::{
|
||||
DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, GlobalDispatch, Resource,
|
||||
DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase, Dispatch,
|
||||
GlobalDispatch, Resource,
|
||||
};
|
||||
|
||||
use crate::wayland::{compositor, shell::wlr_layer::Layer, Serial};
|
||||
|
@ -314,6 +314,20 @@ where
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
_state: &mut D,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
data: &Self::UserData,
|
||||
) {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
data.shell_data
|
||||
.known_layers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// User data for wlr layer surface
|
||||
|
@ -323,21 +337,6 @@ pub struct WlrLayerSurfaceUserData {
|
|||
wl_surface: wl_surface::WlSurface,
|
||||
}
|
||||
|
||||
impl DestructionNotify for WlrLayerSurfaceUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
self.shell_data
|
||||
.known_layers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn with_surface_pending_state<F, T>(layer_surface: &zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, f: F) -> T
|
||||
where
|
||||
F: FnOnce(&mut LayerSurfaceCachedState) -> T,
|
||||
|
|
|
@ -5,9 +5,7 @@ use crate::{utils::Rectangle, wayland::Serial};
|
|||
use wayland_protocols::xdg_shell::server::{xdg_positioner, xdg_positioner::XdgPositioner};
|
||||
|
||||
use wayland_server::{
|
||||
backend::{ClientId, ObjectId},
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DestructionNotify, Dispatch, DisplayHandle, Resource,
|
||||
WEnum,
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle, Resource, WEnum,
|
||||
};
|
||||
|
||||
use super::{PositionerState, XdgShellHandler, XdgShellState};
|
||||
|
@ -22,10 +20,6 @@ pub struct XdgPositionerUserData {
|
|||
pub(crate) inner: Mutex<PositionerState>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for XdgPositionerUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, _object_id: ObjectId) {}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<XdgPositioner> for XdgShellState {
|
||||
type UserData = XdgPositionerUserData;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use wayland_protocols::{
|
|||
use wayland_server::{
|
||||
backend::{ClientId, ObjectId},
|
||||
protocol::wl_surface,
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DestructionNotify, Dispatch, DisplayHandle, Resource,
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle, Resource,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -312,10 +312,8 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DestructionNotify for XdgSurfaceUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, _object_id: ObjectId) {
|
||||
fn destroyed(_state: &mut D, _client_id: ClientId, _object_id: ObjectId, data: &Self::UserData) {
|
||||
// if !self.wl_surface.as_ref().is_alive() {
|
||||
// // the wl_surface is destroyed, this means the client is not
|
||||
// // trying to change the role but it's a cleanup (possibly a
|
||||
|
@ -353,30 +351,3 @@ pub struct XdgShellSurfaceUserData {
|
|||
pub(crate) xdg_surface: xdg_surface::XdgSurface,
|
||||
pub(crate) decoration: Mutex<Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for XdgShellSurfaceUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, object_id: ObjectId) {
|
||||
if let Some(data) = self.xdg_surface.data::<XdgSurfaceUserData>() {
|
||||
data.has_active_role.store(false, Ordering::Release);
|
||||
}
|
||||
|
||||
match &self.kind {
|
||||
SurfaceKind::Toplevel => {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
self.shell_data
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_toplevels
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
SurfaceKind::Popup => {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
self.shell_data
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_popups
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
use std::sync::Mutex;
|
||||
use std::sync::{atomic::Ordering, Mutex};
|
||||
|
||||
use crate::wayland::{compositor, Serial};
|
||||
|
||||
use wayland_protocols::xdg_shell::server::xdg_toplevel::{self, XdgToplevel};
|
||||
|
||||
use wayland_server::{
|
||||
protocol::wl_surface, DataInit, DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle,
|
||||
Resource, WEnum,
|
||||
backend::{ClientId, ObjectId},
|
||||
protocol::wl_surface,
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, Dispatch, DisplayHandle, Resource, WEnum,
|
||||
};
|
||||
|
||||
use super::{
|
||||
SurfaceCachedState, ToplevelConfigure, XdgRequest, XdgShellHandler, XdgShellState,
|
||||
XdgShellSurfaceUserData, XdgToplevelSurfaceRoleAttributes,
|
||||
SurfaceCachedState, SurfaceKind, ToplevelConfigure, XdgRequest, XdgShellHandler, XdgShellState,
|
||||
XdgShellSurfaceUserData, XdgSurfaceUserData, XdgToplevelSurfaceRoleAttributes,
|
||||
};
|
||||
|
||||
impl DelegateDispatchBase<XdgToplevel> for XdgShellState {
|
||||
|
@ -152,6 +153,31 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(_state: &mut D, _client_id: ClientId, object_id: ObjectId, data: &Self::UserData) {
|
||||
if let Some(surface_data) = data.xdg_surface.data::<XdgSurfaceUserData>() {
|
||||
surface_data.has_active_role.store(false, Ordering::Release);
|
||||
}
|
||||
|
||||
match &data.kind {
|
||||
SurfaceKind::Toplevel => {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
data.shell_data
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_toplevels
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
SurfaceKind::Popup => {
|
||||
// remove this surface from the known ones (as well as any leftover dead surface)
|
||||
data.shell_data
|
||||
.lock()
|
||||
.unwrap()
|
||||
.known_popups
|
||||
.retain(|other| other.shell_surface.id() != object_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility functions allowing to factor out a lot of the upcoming logic
|
||||
|
|
|
@ -7,9 +7,8 @@ use wayland_protocols::xdg_shell::server::{
|
|||
};
|
||||
|
||||
use wayland_server::{
|
||||
backend::{ClientId, ObjectId},
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, DisplayHandle, GlobalDispatch, New,
|
||||
Dispatch, DisplayHandle, GlobalDispatch, New,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -126,7 +125,3 @@ where
|
|||
pub struct XdgWmBaseUserData {
|
||||
pub(crate) client_data: Mutex<ShellClientData>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for XdgWmBaseUserData {
|
||||
fn object_destroyed(&self, _client_id: ClientId, _object_id: ObjectId) {}
|
||||
}
|
||||
|
|
|
@ -1155,7 +1155,7 @@ impl ToplevelSurface {
|
|||
/// If the parent is `None`, the parent-child relationship is removed.
|
||||
pub fn set_parent(&self, dh: &mut DisplayHandle<'_>, parent: Option<&wl_surface::WlSurface>) -> bool {
|
||||
if let Some(parent) = parent {
|
||||
if !is_toplevel_equivalent(dh, parent) {
|
||||
if !is_toplevel_equivalent(parent) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use wayland_server::{
|
|||
wl_shm_pool::{self, WlShmPool},
|
||||
},
|
||||
DataInit, DelegateDispatch, DelegateDispatchBase, DelegateGlobalDispatch, DelegateGlobalDispatchBase,
|
||||
DestructionNotify, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||
Dispatch, DisplayHandle, GlobalDispatch, New, Resource, WEnum,
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -104,15 +104,6 @@ pub struct ShmPoolUserData {
|
|||
inner: Arc<Pool>,
|
||||
}
|
||||
|
||||
impl DestructionNotify for ShmPoolUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
_object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlShmPool> for ShmState {
|
||||
type UserData = ShmPoolUserData;
|
||||
}
|
||||
|
@ -225,15 +216,6 @@ pub struct ShmBufferUserData {
|
|||
pub(crate) data: BufferData,
|
||||
}
|
||||
|
||||
impl DestructionNotify for ShmBufferUserData {
|
||||
fn object_destroyed(
|
||||
&self,
|
||||
_client_id: wayland_server::backend::ClientId,
|
||||
_object_id: wayland_server::backend::ObjectId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl DelegateDispatchBase<WlBuffer> for ShmState {
|
||||
type UserData = ShmBufferUserData;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue