From 7654e70f643f0b545a4bf8a7a40b2e6b81cb9194 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Tue, 1 Feb 2022 01:20:49 +0100 Subject: [PATCH] autocommit 2022-02-01 01:20:49 CET --- src/backends/xorg/mod.rs | 5 +- src/client/error.rs | 179 +++++++++++++ src/client/mod.rs | 239 +++--------------- src/client/objects.rs | 4 +- src/globals.rs | 34 ++- src/ifs/mod.rs | 4 +- src/ifs/org_kde_kwin_server_decoration/mod.rs | 93 ------- .../org_kde_kwin_server_decoration/types.rs | 86 ------- .../mod.rs | 119 --------- .../types.rs | 70 ----- src/ifs/wl_buffer/mod.rs | 2 +- src/ifs/wl_data_device/mod.rs | 12 +- src/ifs/wl_data_device_manager/mod.rs | 7 +- src/ifs/wl_output/mod.rs | 8 +- src/ifs/wl_seat/handling.rs | 53 ++-- src/ifs/wl_seat/mod.rs | 24 +- src/ifs/wl_seat/wl_pointer/mod.rs | 2 +- src/ifs/wl_surface/cursor.rs | 21 +- src/ifs/wl_surface/mod.rs | 19 +- src/ifs/wl_surface/types.rs | 6 +- src/ifs/wl_surface/xdg_surface/mod.rs | 20 +- src/ifs/wl_surface/xdg_surface/types.rs | 2 +- .../wl_surface/xdg_surface/xdg_popup/mod.rs | 9 +- .../xdg_surface/xdg_toplevel/mod.rs | 52 ++-- src/ifs/zxdg_decoration_manager_v1/mod.rs | 113 +++++++++ src/ifs/zxdg_decoration_manager_v1/types.rs | 71 ++++++ src/ifs/zxdg_toplevel_decoration_v1/mod.rs | 103 ++++++++ src/ifs/zxdg_toplevel_decoration_v1/types.rs | 100 ++++++++ src/main.rs | 25 +- src/object.rs | 10 +- src/render/gl/sys.rs | 8 +- src/render/renderer/framebuffer.rs | 6 +- src/render/renderer/renderer.rs | 19 +- src/tasks/seat.rs | 9 +- src/tree/container.rs | 21 +- src/tree/mod.rs | 11 +- src/tree/workspace.rs | 2 +- src/utils/clonecell.rs | 4 +- src/utils/smallmap.rs | 19 +- 39 files changed, 830 insertions(+), 761 deletions(-) create mode 100644 src/client/error.rs delete mode 100644 src/ifs/org_kde_kwin_server_decoration/mod.rs delete mode 100644 src/ifs/org_kde_kwin_server_decoration/types.rs delete mode 100644 src/ifs/org_kde_kwin_server_decoration_manager/mod.rs delete mode 100644 src/ifs/org_kde_kwin_server_decoration_manager/types.rs create mode 100644 src/ifs/zxdg_decoration_manager_v1/mod.rs create mode 100644 src/ifs/zxdg_decoration_manager_v1/types.rs create mode 100644 src/ifs/zxdg_toplevel_decoration_v1/mod.rs create mode 100644 src/ifs/zxdg_toplevel_decoration_v1/types.rs diff --git a/src/backends/xorg/mod.rs b/src/backends/xorg/mod.rs index 33c248fd..76a303aa 100644 --- a/src/backends/xorg/mod.rs +++ b/src/backends/xorg/mod.rs @@ -19,8 +19,8 @@ use rand::Rng; use std::cell::{Cell, RefCell}; use std::collections::VecDeque; use std::error::Error; -use std::{ptr, slice}; use std::rc::Rc; +use std::{ptr, slice}; use thiserror::Error; use uapi::{c, OwnedFd}; use xcb_dl::{ffi, Xcb, XcbDri3, XcbPresent, XcbRender, XcbXinput, XcbXkb}; @@ -256,8 +256,7 @@ impl XorgBackend { pixels: vec![0], ..Default::default() }; - let cursor = - ctx.create_cursor(&con.xcb, &con.render, slice::from_ref(&image)); + let cursor = ctx.create_cursor(&con.xcb, &con.render, slice::from_ref(&image)); match cursor { Ok(c) => c, Err(e) => { diff --git a/src/client/error.rs b/src/client/error.rs new file mode 100644 index 00000000..3cf3cf9c --- /dev/null +++ b/src/client/error.rs @@ -0,0 +1,179 @@ +use crate::client::ClientId; +use crate::ifs::wl_buffer::{WlBufferError, WlBufferId}; +use crate::ifs::wl_compositor::WlCompositorError; +use crate::ifs::wl_data_device::WlDataDeviceError; +use crate::ifs::wl_data_device_manager::WlDataDeviceManagerError; +use crate::ifs::wl_data_offer::WlDataOfferError; +use crate::ifs::wl_data_source::WlDataSourceError; +use crate::ifs::wl_display::WlDisplayError; +use crate::ifs::wl_drm::WlDrmError; +use crate::ifs::wl_output::WlOutputError; +use crate::ifs::wl_region::{WlRegionError, WlRegionId}; +use crate::ifs::wl_registry::WlRegistryError; +use crate::ifs::wl_seat::wl_keyboard::WlKeyboardError; +use crate::ifs::wl_seat::wl_pointer::WlPointerError; +use crate::ifs::wl_seat::wl_touch::WlTouchError; +use crate::ifs::wl_seat::{WlSeatError, WlSeatId}; +use crate::ifs::wl_shm::WlShmError; +use crate::ifs::wl_shm_pool::WlShmPoolError; +use crate::ifs::wl_subcompositor::WlSubcompositorError; +use crate::ifs::wl_surface::wl_subsurface::WlSubsurfaceError; +use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupError; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevelError, XdgToplevelId}; +use crate::ifs::wl_surface::xdg_surface::{XdgSurfaceError, XdgSurfaceId}; +use crate::ifs::wl_surface::{WlSurfaceError, WlSurfaceId}; +use crate::ifs::xdg_positioner::{XdgPositionerError, XdgPositionerId}; +use crate::ifs::xdg_wm_base::XdgWmBaseError; +use crate::ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1Error; +use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Error; +use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Error; +use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1Error; +use crate::object::ObjectId; +use crate::utils::buffd::{BufFdError, MsgParserError}; +use crate::AsyncError; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum ClientError { + #[error("An error occurred in the async engine")] + Async(#[from] AsyncError), + #[error("An error occurred reading from/writing to the client")] + Io(#[from] BufFdError), + #[error("An error occurred while processing a request")] + RequestError(#[source] Box), + #[error("Client tried to invoke a non-existent method")] + InvalidMethod, + #[error("Client tried to access non-existent object {0}")] + InvalidObject(ObjectId), + #[error("The message size is < 8")] + MessageSizeTooSmall, + #[error("The size of the message is not a multiple of 4")] + UnalignedMessage, + #[error("The requested client {0} does not exist")] + ClientDoesNotExist(ClientId), + #[error("There is no wl_region with id {0}")] + RegionDoesNotExist(WlRegionId), + #[error("There is no wl_buffer with id {0}")] + BufferDoesNotExist(WlBufferId), + #[error("There is no wl_surface with id {0}")] + SurfaceDoesNotExist(WlSurfaceId), + #[error("There is no xdg_surface with id {0}")] + XdgSurfaceDoesNotExist(XdgSurfaceId), + #[error("There is no xdg_toplevel with id {0}")] + XdgToplevelDoesNotExist(XdgToplevelId), + #[error("There is no xdg_positioner with id {0}")] + XdgPositionerDoesNotExist(XdgPositionerId), + #[error("There is no wl_seat with id {0}")] + WlSeatDoesNotExist(WlSeatId), + #[error("Cannot parse the message")] + ParserError(#[source] Box), + #[error("Server tried to allocate more than 0x1_00_00_00 ids")] + TooManyIds, + #[error("The server object id is out of bounds")] + ServerIdOutOfBounds, + #[error("The object id is unknown")] + UnknownId, + #[error("The id is already in use")] + IdAlreadyInUse, + #[error("The client object id is out of bounds")] + ClientIdOutOfBounds, + #[error("An error occurred in a `wl_display`")] + WlDisplayError(#[source] Box), + #[error("An error occurred in a `wl_registry`")] + WlRegistryError(#[source] Box), + #[error("Could not add object {0} to the client")] + AddObjectError(ObjectId, #[source] Box), + #[error("An error occurred in a `wl_surface`")] + WlSurfaceError(#[source] Box), + #[error("An error occurred in a `wl_compositor`")] + WlCompositorError(#[source] Box), + #[error("An error occurred in a `wl_shm`")] + WlShmError(#[source] Box), + #[error("An error occurred in a `wl_shm_pool`")] + WlShmPoolError(#[source] Box), + #[error("An error occurred in a `wl_region`")] + WlRegionError(#[source] Box), + #[error("An error occurred in a `wl_subsurface`")] + WlSubsurfaceError(#[source] Box), + #[error("An error occurred in a `wl_subcompositor`")] + WlSubcompositorError(#[source] Box), + #[error("An error occurred in a `xdg_surface`")] + XdgSurfaceError(#[source] Box), + #[error("An error occurred in a `xdg_positioner`")] + XdgPositionerError(#[source] Box), + #[error("An error occurred in a `xdg_popup`")] + XdgPopupError(#[source] Box), + #[error("An error occurred in a `xdg_toplevel`")] + XdgToplevelError(#[source] Box), + #[error("An error occurred in a `xdg_wm_base`")] + XdgWmBaseError(#[source] Box), + #[error("An error occurred in a `wl_buffer`")] + WlBufferError(#[source] Box), + #[error("An error occurred in a `wl_output`")] + WlOutputError(#[source] Box), + #[error("An error occurred in a `wl_seat`")] + WlSeatError(#[source] Box), + #[error("An error occurred in a `wl_pointer`")] + WlPointerError(#[source] Box), + #[error("An error occurred in a `wl_keyboard`")] + WlKeyboardError(#[source] Box), + #[error("An error occurred in a `wl_touch`")] + WlTouchError(#[source] Box), + #[error("Object {0} is not a display")] + NotADisplay(ObjectId), + #[error("An error occurred in a `wl_data_device`")] + WlDataDeviceError(#[source] Box), + #[error("An error occurred in a `wl_data_device_manager`")] + WlDataDeviceManagerError(#[source] Box), + #[error("An error occurred in a `wl_data_offer`")] + WlDataOfferError(#[source] Box), + #[error("An error occurred in a `wl_data_source`")] + WlDataSourceError(#[source] Box), + #[error("An error occurred in a `zwp_linx_dmabuf_v1`")] + ZwpLinuxDmabufV1Error(#[source] Box), + #[error("An error occurred in a `zwp_linx_buffer_params_v1`")] + ZwpLinuxBufferParamsV1Error(#[source] Box), + #[error("An error occurred in a `wl_drm`")] + WlDrmError(#[source] Box), + #[error("An error occurred in a `zxdg_decoration_manager_v1`")] + ZxdgDecorationManagerV1Error(#[source] Box), + #[error("An error occurred in a `zxdg_toplevel_decoration_v1`")] + ZxdgToplevelDecorationV1Error(#[source] Box), +} + +efrom!(ClientError, ParserError, MsgParserError); +efrom!(ClientError, WlDisplayError); +efrom!(ClientError, WlRegistryError); +efrom!(ClientError, WlSurfaceError); +efrom!(ClientError, WlCompositorError); +efrom!(ClientError, WlShmError); +efrom!(ClientError, WlShmPoolError); +efrom!(ClientError, WlRegionError); +efrom!(ClientError, WlSubsurfaceError); +efrom!(ClientError, WlSubcompositorError); +efrom!(ClientError, XdgSurfaceError); +efrom!(ClientError, XdgPositionerError); +efrom!(ClientError, XdgWmBaseError); +efrom!(ClientError, XdgToplevelError); +efrom!(ClientError, XdgPopupError); +efrom!(ClientError, WlBufferError); +efrom!(ClientError, WlOutputError); +efrom!(ClientError, WlSeatError); +efrom!(ClientError, WlTouchError); +efrom!(ClientError, WlPointerError); +efrom!(ClientError, WlKeyboardError); +efrom!(ClientError, WlDataDeviceManagerError); +efrom!(ClientError, WlDataDeviceError); +efrom!(ClientError, WlDataSourceError); +efrom!(ClientError, WlDataOfferError); +efrom!(ClientError, ZwpLinuxDmabufV1Error); +efrom!(ClientError, ZwpLinuxBufferParamsV1Error); +efrom!(ClientError, WlDrmError); +efrom!(ClientError, ZxdgDecorationManagerV1Error); +efrom!(ClientError, ZxdgToplevelDecorationV1Error); + +impl ClientError { + pub fn peer_closed(&self) -> bool { + matches!(self, ClientError::Io(BufFdError::Closed)) + } +} diff --git a/src/client/mod.rs b/src/client/mod.rs index 00b72ea6..87099d3d 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,216 +1,54 @@ -use crate::async_engine::{AsyncError, AsyncFd, SpawnedFuture}; +use crate::async_engine::{AsyncFd, SpawnedFuture}; use crate::client::objects::Objects; -use crate::ifs::org_kde_kwin_server_decoration::{ - OrgKdeKwinServerDecoration, OrgKdeKwinServerDecorationError, -}; -use crate::ifs::org_kde_kwin_server_decoration_manager::{ - OrgKdeKwinServerDecorationManagerError, OrgKdeKwinServerDecorationManagerObj, -}; -use crate::ifs::wl_buffer::{WlBuffer, WlBufferError, WlBufferId}; +use crate::ifs::wl_buffer::{WlBuffer, WlBufferId}; use crate::ifs::wl_callback::WlCallback; -use crate::ifs::wl_compositor::{WlCompositorError, WlCompositorObj}; -use crate::ifs::wl_data_device::{WlDataDevice, WlDataDeviceError}; -use crate::ifs::wl_data_device_manager::{WlDataDeviceManagerError, WlDataDeviceManagerObj}; -use crate::ifs::wl_data_offer::{WlDataOffer, WlDataOfferError}; -use crate::ifs::wl_data_source::{WlDataSource, WlDataSourceError}; -use crate::ifs::wl_display::{WlDisplay, WlDisplayError}; -use crate::ifs::wl_drm::{WlDrmError, WlDrmObj}; -use crate::ifs::wl_output::{WlOutputError, WlOutputObj}; -use crate::ifs::wl_region::{WlRegion, WlRegionError, WlRegionId}; -use crate::ifs::wl_registry::{WlRegistry, WlRegistryError, WlRegistryId}; -use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardError}; -use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerError}; -use crate::ifs::wl_seat::wl_touch::{WlTouch, WlTouchError}; -use crate::ifs::wl_seat::{WlSeatError, WlSeatId, WlSeatObj}; -use crate::ifs::wl_shm::{WlShmError, WlShmObj}; -use crate::ifs::wl_shm_pool::{WlShmPool, WlShmPoolError}; -use crate::ifs::wl_subcompositor::{WlSubcompositorError, WlSubcompositorObj}; -use crate::ifs::wl_surface::wl_subsurface::{WlSubsurface, WlSubsurfaceError}; -use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupError}; -use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelError}; -use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceId}; -use crate::ifs::wl_surface::{WlSurface, WlSurfaceError, WlSurfaceId}; -use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerError, XdgPositionerId}; -use crate::ifs::xdg_wm_base::{XdgWmBaseError, XdgWmBaseObj}; -use crate::ifs::zwp_linux_buffer_params_v1::{ZwpLinuxBufferParamsV1, ZwpLinuxBufferParamsV1Error}; -use crate::ifs::zwp_linux_dmabuf_v1::{ZwpLinuxDmabufV1Error, ZwpLinuxDmabufV1Obj}; +use crate::ifs::wl_compositor::WlCompositorObj; +use crate::ifs::wl_data_device::WlDataDevice; +use crate::ifs::wl_data_device_manager::WlDataDeviceManagerObj; +use crate::ifs::wl_data_offer::WlDataOffer; +use crate::ifs::wl_data_source::WlDataSource; +use crate::ifs::wl_display::WlDisplay; +use crate::ifs::wl_drm::WlDrmObj; +use crate::ifs::wl_output::WlOutputObj; +use crate::ifs::wl_region::{WlRegion, WlRegionId}; +use crate::ifs::wl_registry::{WlRegistry, WlRegistryId}; +use crate::ifs::wl_seat::wl_keyboard::WlKeyboard; +use crate::ifs::wl_seat::wl_pointer::WlPointer; +use crate::ifs::wl_seat::wl_touch::WlTouch; +use crate::ifs::wl_seat::{WlSeatId, WlSeatObj}; +use crate::ifs::wl_shm::WlShmObj; +use crate::ifs::wl_shm_pool::WlShmPool; +use crate::ifs::wl_subcompositor::WlSubcompositorObj; +use crate::ifs::wl_surface::wl_subsurface::WlSubsurface; +use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId}; +use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId}; +use crate::ifs::wl_surface::{WlSurface, WlSurfaceId}; +use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerId}; +use crate::ifs::xdg_wm_base::XdgWmBaseObj; +use crate::ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1; +use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Obj; +use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Obj; +use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1; use crate::object::{Object, ObjectId, WL_DISPLAY_ID}; use crate::state::State; -use crate::utils::buffd::{BufFdError, MsgFormatter, MsgParser, MsgParserError}; +use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; use crate::utils::numcell::NumCell; use crate::utils::oneshot::{oneshot, OneshotTx}; use crate::utils::queue::AsyncQueue; use crate::ErrorFmt; use ahash::AHashMap; +pub use error::ClientError; use std::cell::{Cell, RefCell, RefMut}; use std::fmt::{Debug, Display, Formatter}; use std::mem; use std::rc::Rc; -use thiserror::Error; use uapi::{c, OwnedFd}; +mod error; mod objects; mod tasks; -#[derive(Debug, Error)] -pub enum ClientError { - #[error("An error occurred in the async engine")] - Async(#[from] AsyncError), - #[error("An error occurred reading from/writing to the client")] - Io(#[from] BufFdError), - #[error("An error occurred while processing a request")] - RequestError(#[source] Box), - #[error("Client tried to invoke a non-existent method")] - InvalidMethod, - #[error("Client tried to access non-existent object {0}")] - InvalidObject(ObjectId), - #[error("The message size is < 8")] - MessageSizeTooSmall, - #[error("The size of the message is not a multiple of 4")] - UnalignedMessage, - #[error("The requested client {0} does not exist")] - ClientDoesNotExist(ClientId), - #[error("There is no wl_region with id {0}")] - RegionDoesNotExist(WlRegionId), - #[error("There is no wl_buffer with id {0}")] - BufferDoesNotExist(WlBufferId), - #[error("There is no wl_surface with id {0}")] - SurfaceDoesNotExist(WlSurfaceId), - #[error("There is no xdg_surface with id {0}")] - XdgSurfaceDoesNotExist(XdgSurfaceId), - #[error("There is no xdg_positioner with id {0}")] - XdgPositionerDoesNotExist(XdgPositionerId), - #[error("There is no wl_seat with id {0}")] - WlSeatDoesNotExist(WlSeatId), - #[error("Cannot parse the message")] - ParserError(#[source] Box), - #[error("Server tried to allocate more than 0x1_00_00_00 ids")] - TooManyIds, - #[error("The server object id is out of bounds")] - ServerIdOutOfBounds, - #[error("The object id is unknown")] - UnknownId, - #[error("The id is already in use")] - IdAlreadyInUse, - #[error("The client object id is out of bounds")] - ClientIdOutOfBounds, - #[error("An error occurred in a `wl_display`")] - WlDisplayError(#[source] Box), - #[error("An error occurred in a `wl_registry`")] - WlRegistryError(#[source] Box), - #[error("Could not add object {0} to the client")] - AddObjectError(ObjectId, #[source] Box), - #[error("An error occurred in a `wl_surface`")] - WlSurfaceError(#[source] Box), - #[error("An error occurred in a `wl_compositor`")] - WlCompositorError(#[source] Box), - #[error("An error occurred in a `wl_shm`")] - WlShmError(#[source] Box), - #[error("An error occurred in a `wl_shm_pool`")] - WlShmPoolError(#[source] Box), - #[error("An error occurred in a `wl_region`")] - WlRegionError(#[source] Box), - #[error("An error occurred in a `wl_subsurface`")] - WlSubsurfaceError(#[source] Box), - #[error("An error occurred in a `wl_subcompositor`")] - WlSubcompositorError(#[source] Box), - #[error("An error occurred in a `xdg_surface`")] - XdgSurfaceError(#[source] Box), - #[error("An error occurred in a `xdg_positioner`")] - XdgPositionerError(#[source] Box), - #[error("An error occurred in a `xdg_popup`")] - XdgPopupError(#[source] Box), - #[error("An error occurred in a `xdg_toplevel`")] - XdgToplevelError(#[source] Box), - #[error("An error occurred in a `xdg_wm_base`")] - XdgWmBaseError(#[source] Box), - #[error("An error occurred in a `wl_buffer`")] - WlBufferError(#[source] Box), - #[error("An error occurred in a `wl_output`")] - WlOutputError(#[source] Box), - #[error("An error occurred in a `wl_seat`")] - WlSeatError(#[source] Box), - #[error("An error occurred in a `wl_pointer`")] - WlPointerError(#[source] Box), - #[error("An error occurred in a `wl_keyboard`")] - WlKeyboardError(#[source] Box), - #[error("An error occurred in a `wl_touch`")] - WlTouchError(#[source] Box), - #[error("Object {0} is not a display")] - NotADisplay(ObjectId), - #[error("An error occurred in a `wl_data_device`")] - WlDataDeviceError(#[source] Box), - #[error("An error occurred in a `wl_data_device_manager`")] - WlDataDeviceManagerError(#[source] Box), - #[error("An error occurred in a `wl_data_offer`")] - WlDataOfferError(#[source] Box), - #[error("An error occurred in a `wl_data_source`")] - WlDataSourceError(#[source] Box), - #[error("An error occurred in a `zwp_linx_dmabuf_v1`")] - ZwpLinuxDmabufV1Error(#[source] Box), - #[error("An error occurred in a `zwp_linx_buffer_params_v1`")] - ZwpLinuxBufferParamsV1Error(#[source] Box), - #[error("An error occurred in a `wl_drm`")] - WlDrmError(#[source] Box), - #[error("An error occurred in a `org_kde_kwin_server_decoration_manager`")] - OrgKdeKwinServerDecorationManagerError(#[source] Box), - #[error("An error occurred in a `org_kde_kwin_server_decoration`")] - OrgKdeKwinServerDecorationError(#[source] Box), -} - -efrom!(ClientError, ParserError, MsgParserError); -efrom!(ClientError, WlDisplayError); -efrom!(ClientError, WlRegistryError); -efrom!(ClientError, WlSurfaceError); -efrom!(ClientError, WlCompositorError); -efrom!(ClientError, WlShmError); -efrom!(ClientError, WlShmPoolError); -efrom!(ClientError, WlRegionError); -efrom!(ClientError, WlSubsurfaceError); -efrom!(ClientError, WlSubcompositorError); -efrom!(ClientError, XdgSurfaceError); -efrom!(ClientError, XdgPositionerError); -efrom!(ClientError, XdgWmBaseError); -efrom!(ClientError, XdgToplevelError); -efrom!(ClientError, XdgPopupError); -efrom!(ClientError, WlBufferError); -efrom!(ClientError, WlOutputError); -efrom!(ClientError, WlSeatError); -efrom!(ClientError, WlTouchError); -efrom!(ClientError, WlPointerError); -efrom!(ClientError, WlKeyboardError); -efrom!( - ClientError, - WlDataDeviceManagerError, - WlDataDeviceManagerError -); -efrom!(ClientError, WlDataDeviceError); -efrom!(ClientError, WlDataSourceError); -efrom!(ClientError, WlDataOfferError); -efrom!(ClientError, ZwpLinuxDmabufV1Error); -efrom!( - ClientError, - ZwpLinuxBufferParamsV1Error, - ZwpLinuxBufferParamsV1Error -); -efrom!(ClientError, WlDrmError, WlDrmError); -efrom!( - ClientError, - OrgKdeKwinServerDecorationManagerError, - OrgKdeKwinServerDecorationManagerError -); -efrom!( - ClientError, - OrgKdeKwinServerDecorationError, - OrgKdeKwinServerDecorationError -); - -impl ClientError { - fn peer_closed(&self) -> bool { - matches!(self, ClientError::Io(BufFdError::Closed)) - } -} - #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] pub struct ClientId(u64); @@ -503,6 +341,13 @@ impl Client { } } + pub fn get_xdg_toplevel(&self, id: XdgToplevelId) -> Result, ClientError> { + match self.objects.xdg_toplevel.get(&id) { + Some(r) => Ok(r), + _ => Err(ClientError::XdgToplevelDoesNotExist(id)), + } + } + pub fn get_xdg_positioner( &self, id: XdgPositionerId, @@ -597,8 +442,8 @@ simple_add_obj!(WlDataSource); simple_add_obj!(ZwpLinuxDmabufV1Obj); simple_add_obj!(ZwpLinuxBufferParamsV1); simple_add_obj!(WlDrmObj); -simple_add_obj!(OrgKdeKwinServerDecorationManagerObj); -simple_add_obj!(OrgKdeKwinServerDecoration); +simple_add_obj!(ZxdgToplevelDecorationV1); +simple_add_obj!(ZxdgDecorationManagerV1Obj); macro_rules! dedicated_add_obj { ($ty:ty, $field:ident) => { diff --git a/src/client/objects.rs b/src/client/objects.rs index 2eabe45d..d74ecd71 100644 --- a/src/client/objects.rs +++ b/src/client/objects.rs @@ -4,19 +4,19 @@ use crate::ifs::wl_display::WlDisplay; use crate::ifs::wl_region::{WlRegion, WlRegionId}; use crate::ifs::wl_registry::{WlRegistry, WlRegistryId}; use crate::ifs::wl_seat::{WlSeatId, WlSeatObj}; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId}; use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId}; use crate::ifs::wl_surface::{WlSurface, WlSurfaceId}; use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerId}; use crate::ifs::xdg_wm_base::{XdgWmBaseId, XdgWmBaseObj}; use crate::object::{Object, ObjectId}; +use crate::tree::Node; use crate::utils::clonecell::CloneCell; use crate::utils::copyhashmap::CopyHashMap; use ahash::AHashMap; use std::cell::{RefCell, RefMut}; use std::mem; use std::rc::Rc; -use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId}; -use crate::tree::Node; pub struct Objects { pub display: CloneCell>>, diff --git a/src/globals.rs b/src/globals.rs index 93c0803b..dd750944 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -1,8 +1,4 @@ -use std::cell::{RefMut}; use crate::client::{Client, DynEventFormatter}; -use crate::ifs::org_kde_kwin_server_decoration_manager::{ - OrgKdeKwinServerDecorationManagerError, OrgKdeKwinServerDecorationManagerGlobal, -}; use crate::ifs::wl_compositor::WlCompositorError; use crate::ifs::wl_data_device_manager::WlDataDeviceManagerError; use crate::ifs::wl_drm::{WlDrmError, WlDrmGlobal}; @@ -13,15 +9,17 @@ use crate::ifs::wl_shm::WlShmError; use crate::ifs::wl_subcompositor::WlSubcompositorError; use crate::ifs::xdg_wm_base::XdgWmBaseError; use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Error; +use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Error; use crate::object::{Interface, ObjectId}; use crate::utils::copyhashmap::CopyHashMap; use crate::{ NumCell, State, WlCompositorGlobal, WlDataDeviceManagerGlobal, WlShmGlobal, - WlSubcompositorGlobal, XdgWmBaseGlobal, ZwpLinuxDmabufV1Global, + WlSubcompositorGlobal, XdgWmBaseGlobal, ZwpLinuxDmabufV1Global, ZxdgDecorationManagerV1Global, }; +use ahash::AHashMap; +use std::cell::RefMut; use std::fmt::{Display, Formatter}; use std::rc::Rc; -use ahash::AHashMap; use thiserror::Error; #[derive(Debug, Error)] @@ -48,8 +46,8 @@ pub enum GlobalError { ZwpLinuxDmabufV1Error(#[source] Box), #[error("An error occurred in a `wl_drm` global")] WlDrmError(#[source] Box), - #[error("An error occurred in a `org_kde_kwin_server_decoration_manager` global")] - OrgKdeKwinServerDecorationManagerError(#[source] Box), + #[error("An error occurred in a `zxdg_decoration_manager_v1` global")] + ZxdgDecorationManagerV1Error(#[source] Box), } efrom!(GlobalError, WlCompositorError); @@ -61,7 +59,7 @@ efrom!(GlobalError, WlSeatError); efrom!(GlobalError, ZwpLinuxDmabufV1Error); efrom!(GlobalError, WlDrmError); efrom!(GlobalError, WlDataDeviceManagerError); -efrom!(GlobalError, OrgKdeKwinServerDecorationManagerError); +efrom!(GlobalError, ZxdgDecorationManagerV1Error); #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalName(u32); @@ -108,12 +106,26 @@ pub struct Globals { impl Globals { pub fn new() -> Self { - Self { + let slf = Self { next_name: NumCell::new(1), registry: CopyHashMap::new(), outputs: Default::default(), seats: Default::default(), + }; + macro_rules! add_singleton { + ($name:ident) => { + slf.add_global_no_broadcast(&Rc::new($name::new(slf.name()))); + }; } + add_singleton!(WlCompositorGlobal); + add_singleton!(WlShmGlobal); + add_singleton!(WlSubcompositorGlobal); + add_singleton!(XdgWmBaseGlobal); + add_singleton!(WlDataDeviceManagerGlobal); + add_singleton!(ZwpLinuxDmabufV1Global); + add_singleton!(WlDrmGlobal); + add_singleton!(ZxdgDecorationManagerV1Global); + slf } pub fn name(&self) -> GlobalName { @@ -230,7 +242,7 @@ simple_add_global!(XdgWmBaseGlobal); simple_add_global!(WlDataDeviceManagerGlobal); simple_add_global!(ZwpLinuxDmabufV1Global); simple_add_global!(WlDrmGlobal); -simple_add_global!(OrgKdeKwinServerDecorationManagerGlobal); +simple_add_global!(ZxdgDecorationManagerV1Global); macro_rules! dedicated_add_global { ($ty:ty, $field:ident) => { diff --git a/src/ifs/mod.rs b/src/ifs/mod.rs index 4876ff27..c466ad75 100644 --- a/src/ifs/mod.rs +++ b/src/ifs/mod.rs @@ -1,5 +1,3 @@ -pub mod org_kde_kwin_server_decoration; -pub mod org_kde_kwin_server_decoration_manager; pub mod wl_buffer; pub mod wl_callback; pub mod wl_compositor; @@ -21,3 +19,5 @@ pub mod xdg_positioner; pub mod xdg_wm_base; pub mod zwp_linux_buffer_params_v1; pub mod zwp_linux_dmabuf_v1; +pub mod zxdg_decoration_manager_v1; +pub mod zxdg_toplevel_decoration_v1; diff --git a/src/ifs/org_kde_kwin_server_decoration/mod.rs b/src/ifs/org_kde_kwin_server_decoration/mod.rs deleted file mode 100644 index e488ac75..00000000 --- a/src/ifs/org_kde_kwin_server_decoration/mod.rs +++ /dev/null @@ -1,93 +0,0 @@ -use crate::client::{Client, DynEventFormatter}; -use crate::object::{Interface, Object, ObjectId}; -use crate::utils::buffd::MsgParser; -use std::cell::Cell; -use std::rc::Rc; -pub use types::*; - -mod types; - -const RELEASE: u32 = 0; -const REQUEST_MODE: u32 = 1; - -const MODE: u32 = 0; - -#[allow(dead_code)] -const NONE: u32 = 0; -#[allow(dead_code)] -const CLIENT: u32 = 1; -const SERVER: u32 = 2; - -id!(OrgKdeKwinServerDecorationId); - -pub struct OrgKdeKwinServerDecoration { - id: OrgKdeKwinServerDecorationId, - client: Rc, - requested: Cell, -} - -impl OrgKdeKwinServerDecoration { - pub fn new(id: OrgKdeKwinServerDecorationId, client: &Rc) -> Self { - Self { - id, - client: client.clone(), - requested: Cell::new(false), - } - } - - pub fn mode(self: &Rc, mode: u32) -> DynEventFormatter { - Box::new(Mode { - obj: self.clone(), - mode, - }) - } - - fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> { - let _req: Release = self.client.parse(self, parser)?; - self.client.remove_obj(self)?; - Ok(()) - } - - fn request_mode(self: &Rc, parser: MsgParser<'_, '_>) -> Result<(), RequestModeError> { - let req: RequestMode = self.client.parse(&**self, parser)?; - if req.mode > SERVER { - return Err(RequestModeError::InvalidMode(req.mode)); - } - let mode = if self.requested.replace(true) { - req.mode - } else { - SERVER - }; - self.client.event(self.mode(mode)); - Ok(()) - } - - fn handle_request_( - self: &Rc, - request: u32, - parser: MsgParser<'_, '_>, - ) -> Result<(), OrgKdeKwinServerDecorationError> { - match request { - RELEASE => self.release(parser)?, - REQUEST_MODE => self.request_mode(parser)?, - _ => unreachable!(), - } - Ok(()) - } -} - -handle_request!(OrgKdeKwinServerDecoration); - -impl Object for OrgKdeKwinServerDecoration { - fn id(&self) -> ObjectId { - self.id.into() - } - - fn interface(&self) -> Interface { - Interface::OrgKdeKwinServerDecoration - } - - fn num_requests(&self) -> u32 { - REQUEST_MODE + 1 - } -} diff --git a/src/ifs/org_kde_kwin_server_decoration/types.rs b/src/ifs/org_kde_kwin_server_decoration/types.rs deleted file mode 100644 index 3c8d4092..00000000 --- a/src/ifs/org_kde_kwin_server_decoration/types.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::client::{ClientError, EventFormatter, RequestParser}; -use crate::ifs::org_kde_kwin_server_decoration::{OrgKdeKwinServerDecoration, MODE}; -use crate::object::Object; -use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; -use std::fmt::{Debug, Formatter}; -use std::rc::Rc; -use thiserror::Error; - -#[derive(Debug, Error)] -pub enum OrgKdeKwinServerDecorationError { - #[error("Could not process a `release` request")] - ReleaseError(#[from] ReleaseError), - #[error("Could not process a `request_mode` request")] - RequestModeError(#[from] RequestModeError), - #[error(transparent)] - ClientError(Box), -} -efrom!(OrgKdeKwinServerDecorationError, ClientError); - -#[derive(Debug, Error)] -pub enum ReleaseError { - #[error(transparent)] - ClientError(Box), - #[error("Parsing failed")] - ParseError(#[source] Box), -} -efrom!(ReleaseError, ClientError); -efrom!(ReleaseError, ParseError, MsgParserError); - -#[derive(Debug, Error)] -pub enum RequestModeError { - #[error(transparent)] - ClientError(Box), - #[error("Parsing failed")] - ParseError(#[source] Box), - #[error("Mode {0} does not exist")] - InvalidMode(u32), -} -efrom!(RequestModeError, ClientError); -efrom!(RequestModeError, ParseError, MsgParserError); - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} - -pub(super) struct RequestMode { - pub mode: u32, -} -impl RequestParser<'_> for RequestMode { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - mode: parser.uint()?, - }) - } -} -impl Debug for RequestMode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "request_mode(mode: {})", self.mode) - } -} - -pub(super) struct Mode { - pub obj: Rc, - pub mode: u32, -} -impl EventFormatter for Mode { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MODE).uint(self.mode); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Mode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "mode(mode: {})", self.mode) - } -} diff --git a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs b/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs deleted file mode 100644 index fc483f29..00000000 --- a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs +++ /dev/null @@ -1,119 +0,0 @@ -use crate::client::{Client, DynEventFormatter}; -use crate::globals::{Global, GlobalName}; -use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration; -use crate::object::{Interface, Object, ObjectId}; -use crate::utils::buffd::MsgParser; -use std::rc::Rc; -pub use types::*; - -mod types; - -const CREATE: u32 = 0; - -const DEFAULT_MODE: u32 = 0; - -#[allow(dead_code)] -const NONE: u32 = 0; -#[allow(dead_code)] -const CLIENT: u32 = 1; -const SERVER: u32 = 2; - -id!(OrgKdeKwinServerDecorationManagerGlobalId); - -pub struct OrgKdeKwinServerDecorationManagerGlobal { - name: GlobalName, -} -impl OrgKdeKwinServerDecorationManagerGlobal { - pub fn new(name: GlobalName) -> Self { - Self { name } - } - - fn bind_( - self: Rc, - id: OrgKdeKwinServerDecorationManagerGlobalId, - client: &Rc, - version: u32, - ) -> Result<(), OrgKdeKwinServerDecorationManagerError> { - let obj = Rc::new(OrgKdeKwinServerDecorationManagerObj { - id, - client: client.clone(), - _version: version, - }); - client.add_client_obj(&obj)?; - client.event(obj.default_mode(SERVER)); - Ok(()) - } -} - -bind!(OrgKdeKwinServerDecorationManagerGlobal); - -impl Global for OrgKdeKwinServerDecorationManagerGlobal { - fn name(&self) -> GlobalName { - self.name - } - - fn singleton(&self) -> bool { - true - } - - fn interface(&self) -> Interface { - Interface::OrgKdeKwinServerDecorationManager - } - - fn version(&self) -> u32 { - 1 - } -} - -pub struct OrgKdeKwinServerDecorationManagerObj { - id: OrgKdeKwinServerDecorationManagerGlobalId, - client: Rc, - _version: u32, -} - -impl OrgKdeKwinServerDecorationManagerObj { - fn default_mode(self: &Rc, mode: u32) -> DynEventFormatter { - Box::new(DefaultMode { - obj: self.clone(), - mode, - }) - } - - fn create(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateError> { - let req: Create = self.client.parse(self, parser)?; - let _ = self.client.get_surface(req.surface)?; - let obj = Rc::new(OrgKdeKwinServerDecoration::new(req.id, &self.client)); - self.client.add_client_obj(&obj)?; - self.client.event(obj.mode(SERVER)); - log::info!("ayo"); - Ok(()) - } - - fn handle_request_( - self: &Rc, - request: u32, - parser: MsgParser<'_, '_>, - ) -> Result<(), OrgKdeKwinServerDecorationManagerError> { - match request { - CREATE => self.create(parser)?, - _ => unreachable!(), - } - Ok(()) - } -} - -handle_request!(OrgKdeKwinServerDecorationManagerObj); - -impl Object for OrgKdeKwinServerDecorationManagerObj { - fn id(&self) -> ObjectId { - self.id.into() - } - - fn interface(&self) -> Interface { - Interface::OrgKdeKwinServerDecorationManager - } - - fn num_requests(&self) -> u32 { - CREATE + 1 - } -} diff --git a/src/ifs/org_kde_kwin_server_decoration_manager/types.rs b/src/ifs/org_kde_kwin_server_decoration_manager/types.rs deleted file mode 100644 index d9b61139..00000000 --- a/src/ifs/org_kde_kwin_server_decoration_manager/types.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::client::{ClientError, EventFormatter, RequestParser}; -use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecorationId; -use crate::ifs::org_kde_kwin_server_decoration_manager::{ - OrgKdeKwinServerDecorationManagerObj, DEFAULT_MODE, -}; -use crate::ifs::wl_surface::WlSurfaceId; -use crate::object::Object; -use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; -use std::fmt::{Debug, Formatter}; -use std::rc::Rc; -use thiserror::Error; - -#[derive(Debug, Error)] -pub enum OrgKdeKwinServerDecorationManagerError { - #[error("Could not process a `create` request")] - CreateError(#[from] CreateError), - #[error(transparent)] - ClientError(Box), -} -efrom!( - OrgKdeKwinServerDecorationManagerError, - ClientError, - ClientError -); - -#[derive(Debug, Error)] -pub enum CreateError { - #[error(transparent)] - ClientError(Box), - #[error("Parsing failed")] - ParseError(#[source] Box), -} -efrom!(CreateError, ClientError); -efrom!(CreateError, ParseError, MsgParserError); - -pub(super) struct Create { - pub id: OrgKdeKwinServerDecorationId, - pub surface: WlSurfaceId, -} -impl RequestParser<'_> for Create { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - surface: parser.object()?, - }) - } -} -impl Debug for Create { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create(id: {}, surface: {})", self.id, self.surface) - } -} - -pub(super) struct DefaultMode { - pub obj: Rc, - pub mode: u32, -} -impl EventFormatter for DefaultMode { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DEFAULT_MODE).uint(self.mode); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DefaultMode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "default_mode(mode: {})", self.mode) - } -} diff --git a/src/ifs/wl_buffer/mod.rs b/src/ifs/wl_buffer/mod.rs index a2eeae47..216a0bab 100644 --- a/src/ifs/wl_buffer/mod.rs +++ b/src/ifs/wl_buffer/mod.rs @@ -1,6 +1,5 @@ mod types; -use std::cell::Cell; use crate::client::{Client, DynEventFormatter}; use crate::clientmem::{ClientMem, ClientMemOffset}; use crate::format::Format; @@ -9,6 +8,7 @@ use crate::rect::Rect; use crate::render::{Image, Texture}; use crate::utils::buffd::MsgParser; use crate::utils::clonecell::CloneCell; +use std::cell::Cell; use std::rc::Rc; pub use types::*; diff --git a/src/ifs/wl_data_device/mod.rs b/src/ifs/wl_data_device/mod.rs index fc6df22e..6e2bc562 100644 --- a/src/ifs/wl_data_device/mod.rs +++ b/src/ifs/wl_data_device/mod.rs @@ -1,13 +1,13 @@ mod types; use crate::client::{Client, DynEventFormatter}; +use crate::ifs::wl_data_device_manager::WlDataDeviceManagerObj; +use crate::ifs::wl_data_offer::WlDataOfferId; +use crate::ifs::wl_seat::WlSeatObj; use crate::object::{Interface, Object, ObjectId}; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; -use crate::ifs::wl_data_device_manager::WlDataDeviceManagerObj; -use crate::ifs::wl_data_offer::WlDataOfferId; -use crate::ifs::wl_seat::WlSeatObj; const START_DRAG: u32 = 0; const SET_SELECTION: u32 = 1; @@ -33,7 +33,11 @@ pub struct WlDataDevice { } impl WlDataDevice { - pub fn new(id: WlDataDeviceId, manager: &Rc, seat: &Rc) -> Self { + pub fn new( + id: WlDataDeviceId, + manager: &Rc, + seat: &Rc, + ) -> Self { Self { id, manager: manager.clone(), diff --git a/src/ifs/wl_data_device_manager/mod.rs b/src/ifs/wl_data_device_manager/mod.rs index ec284920..90f91175 100644 --- a/src/ifs/wl_data_device_manager/mod.rs +++ b/src/ifs/wl_data_device_manager/mod.rs @@ -47,7 +47,7 @@ impl WlDataDeviceManagerGlobal { let obj = Rc::new(WlDataDeviceManagerObj { id, client: client.clone(), - version + version, }); client.add_client_obj(&obj)?; Ok(()) @@ -62,7 +62,10 @@ impl WlDataDeviceManagerObj { Ok(()) } - fn get_data_device(self: &Rc, parser: MsgParser<'_, '_>) -> Result<(), GetDataDeviceError> { + fn get_data_device( + self: &Rc, + parser: MsgParser<'_, '_>, + ) -> Result<(), GetDataDeviceError> { let req: GetDataDevice = self.client.parse(&**self, parser)?; let seat = self.client.get_wl_seat(req.seat)?; let dev = Rc::new(WlDataDevice::new(req.id, self, &seat)); diff --git a/src/ifs/wl_output/mod.rs b/src/ifs/wl_output/mod.rs index fce0565c..f4eac7b8 100644 --- a/src/ifs/wl_output/mod.rs +++ b/src/ifs/wl_output/mod.rs @@ -5,11 +5,11 @@ use crate::client::{Client, ClientId, DynEventFormatter, WlEvent}; use crate::globals::{Global, GlobalName}; use crate::object::{Interface, Object, ObjectId}; use crate::utils::buffd::MsgParser; +use ahash::AHashMap; use std::cell::{Cell, RefCell}; use std::collections::hash_map::Entry; use std::iter; use std::rc::Rc; -use ahash::AHashMap; pub use types::*; id!(WlOutputId); @@ -119,7 +119,11 @@ impl WlOutputGlobal { version, }); client.add_client_obj(&obj)?; - self.bindings.borrow_mut().entry(client.id).or_default().insert(id, obj.clone()); + self.bindings + .borrow_mut() + .entry(client.id) + .or_default() + .insert(id, obj.clone()); client.event(obj.geometry()); client.event(obj.mode()); if obj.send_scale() { diff --git a/src/ifs/wl_seat/handling.rs b/src/ifs/wl_seat/handling.rs index ae9c517d..629e0a35 100644 --- a/src/ifs/wl_seat/handling.rs +++ b/src/ifs/wl_seat/handling.rs @@ -1,20 +1,20 @@ -use std::ops::Deref; -use std::rc::Rc; use crate::backend::{KeyState, OutputId, ScrollAxis, SeatEvent, SeatId}; use crate::client::{ClientId, DynEventFormatter}; use crate::fixed::Fixed; use crate::ifs::wl_data_device::WlDataDevice; use crate::ifs::wl_data_offer::WlDataOfferId; -use crate::ifs::wl_seat::{wl_keyboard, wl_pointer, WlSeatGlobal, WlSeatObj}; use crate::ifs::wl_seat::wl_keyboard::WlKeyboard; -use crate::ifs::wl_seat::wl_pointer::{POINTER_FRAME_SINCE_VERSION, WlPointer}; -use crate::ifs::wl_surface::WlSurface; +use crate::ifs::wl_seat::wl_pointer::{WlPointer, POINTER_FRAME_SINCE_VERSION}; +use crate::ifs::wl_seat::{wl_keyboard, wl_pointer, WlSeatGlobal, WlSeatObj}; use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup; use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel; use crate::ifs::wl_surface::xdg_surface::XdgSurface; +use crate::ifs::wl_surface::WlSurface; use crate::tree::{FloatNode, FoundNode, Node}; use crate::utils::smallmap::SmallMap; use crate::xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP}; +use std::ops::Deref; +use std::rc::Rc; #[derive(Default)] pub struct NodeSeatState { @@ -197,8 +197,8 @@ impl WlSeatGlobal { } fn for_each_seat(&self, ver: u32, client: ClientId, mut f: C) - where - C: FnMut(&Rc), + where + C: FnMut(&Rc), { let bindings = self.bindings.borrow(); if let Some(hm) = bindings.get(&client) { @@ -211,8 +211,8 @@ impl WlSeatGlobal { } fn for_each_pointer(&self, ver: u32, client: ClientId, mut f: C) - where - C: FnMut(&Rc), + where + C: FnMut(&Rc), { self.for_each_seat(ver, client, |seat| { let pointers = seat.pointers.lock(); @@ -223,8 +223,8 @@ impl WlSeatGlobal { } fn for_each_kb(&self, ver: u32, client: ClientId, mut f: C) - where - C: FnMut(&Rc), + where + C: FnMut(&Rc), { self.for_each_seat(ver, client, |seat| { let keyboards = seat.keyboards.lock(); @@ -235,8 +235,8 @@ impl WlSeatGlobal { } fn for_each_data_device(&self, ver: u32, client: ClientId, mut f: C) - where - C: FnMut(&Rc), + where + C: FnMut(&Rc), { let dd = self.data_devices.borrow_mut(); if let Some(dd) = dd.get(&client) { @@ -253,8 +253,8 @@ impl WlSeatGlobal { } fn surface_pointer_event(&self, ver: u32, surface: &WlSurface, mut f: F) - where - F: FnMut(&Rc) -> DynEventFormatter, + where + F: FnMut(&Rc) -> DynEventFormatter, { let client = &surface.client; self.for_each_pointer(ver, client.id, |p| { @@ -264,8 +264,8 @@ impl WlSeatGlobal { } fn surface_kb_event(&self, ver: u32, surface: &WlSurface, mut f: F) - where - F: FnMut(&Rc) -> DynEventFormatter, + where + F: FnMut(&Rc) -> DynEventFormatter, { let client = &surface.client; self.for_each_kb(ver, client.id, |p| { @@ -275,8 +275,8 @@ impl WlSeatGlobal { } fn surface_data_device_event(&self, ver: u32, surface: &WlSurface, mut f: F) - where - F: FnMut(&Rc) -> DynEventFormatter, + where + F: FnMut(&Rc) -> DynEventFormatter, { let client = &surface.client; self.for_each_data_device(ver, client.id, |p| { @@ -334,7 +334,8 @@ impl WlSeatGlobal { if (stack.len(), found_tree.len()) == (divergence, divergence) { if changed { if let Some(node) = found_tree.last() { - node.node.motion(self, x.apply_fract(node.x), y.apply_fract(node.y)); + node.node + .motion(self, x.apply_fract(node.x), y.apply_fract(node.y)); } } } else { @@ -344,7 +345,9 @@ impl WlSeatGlobal { } for new in found_tree.drain(divergence..) { new.node.seat_state().enter(self); - new.node.clone().enter(self, x.apply_fract(new.x), y.apply_fract(new.y)); + new.node + .clone() + .enter(self, x.apply_fract(new.x), y.apply_fract(new.y)); stack.push(new.node); } } @@ -423,7 +426,13 @@ impl WlSeatGlobal { // Key callbacks impl WlSeatGlobal { - pub fn key_surface(&self, surface: &WlSurface, key: u32, state: u32, mods: Option) { + pub fn key_surface( + &self, + surface: &WlSurface, + key: u32, + state: u32, + mods: Option, + ) { let serial = self.serial.fetch_add(1); self.surface_kb_event(0, surface, |k| k.key(serial, 0, key, state)); let serial = self.serial.fetch_add(1); diff --git a/src/ifs/wl_seat/mod.rs b/src/ifs/wl_seat/mod.rs index 495c5258..b317b33d 100644 --- a/src/ifs/wl_seat/mod.rs +++ b/src/ifs/wl_seat/mod.rs @@ -1,36 +1,36 @@ +mod handling; mod types; pub mod wl_keyboard; pub mod wl_pointer; pub mod wl_touch; -mod handling; use crate::backend::{Seat, SeatId}; use crate::client::{Client, ClientId, DynEventFormatter}; use crate::fixed::Fixed; use crate::globals::{Global, GlobalName}; +use crate::ifs::wl_data_device::{WlDataDevice, WlDataDeviceId}; use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardId, REPEAT_INFO_SINCE}; use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerId}; use crate::ifs::wl_seat::wl_touch::WlTouch; -use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel}; +use crate::ifs::wl_surface::cursor::CursorSurface; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel; use crate::object::{Interface, Object, ObjectId}; use crate::tree::{FloatNode, FoundNode, Node}; use crate::utils::buffd::MsgParser; use crate::utils::clonecell::CloneCell; use crate::utils::copyhashmap::CopyHashMap; -use crate::utils::linkedlist::{LinkedList}; +use crate::utils::linkedlist::LinkedList; use crate::xkbcommon::{XkbContext, XkbState}; use crate::{NumCell, State}; use ahash::{AHashMap, AHashSet}; use bstr::ByteSlice; +pub use handling::NodeSeatState; use std::cell::{Cell, RefCell}; use std::collections::hash_map::Entry; use std::io::Write; use std::rc::Rc; pub use types::*; use uapi::{c, OwnedFd}; -pub use handling::NodeSeatState; -use crate::ifs::wl_data_device::{WlDataDevice, WlDataDeviceId}; -use crate::ifs::wl_surface::cursor::CursorSurface; id!(WlSeatId); @@ -53,6 +53,8 @@ const MISSING_CAPABILITY: u32 = 0; #[allow(dead_code)] const BTN_LEFT: u32 = 0x110; +pub const SEAT_NAME_SINCE: u32 = 2; + pub struct WlSeatGlobal { name: GlobalName, state: Rc, @@ -92,7 +94,7 @@ impl WlSeatGlobal { memfd.raw(), c::F_SEAL_SEAL | c::F_SEAL_GROW | c::F_SEAL_SHRINK | c::F_SEAL_WRITE, ) - .unwrap(); + .unwrap(); (state, Rc::new(memfd), (string.len() + 1) as _) }; Self { @@ -155,7 +157,9 @@ impl WlSeatGlobal { }); client.add_client_obj(&obj)?; client.event(obj.capabilities()); - client.event(obj.name(&self.seat_name)); + if version >= SEAT_NAME_SINCE { + client.event(obj.name(&self.seat_name)); + } { let mut bindings = self.bindings.borrow_mut(); let bindings = bindings.entry(client.id).or_insert_with(Default::default); @@ -215,7 +219,9 @@ impl WlSeatObj { pub fn add_data_device(&self, device: &Rc) { let mut dd = self.global.data_devices.borrow_mut(); - dd.entry(self.client.id).or_default().insert(device.id, device.clone()); + dd.entry(self.client.id) + .or_default() + .insert(device.id, device.clone()); } pub fn remove_data_device(&self, device: &WlDataDevice) { diff --git a/src/ifs/wl_seat/wl_pointer/mod.rs b/src/ifs/wl_seat/wl_pointer/mod.rs index 7c64cd44..63cb8fe3 100644 --- a/src/ifs/wl_seat/wl_pointer/mod.rs +++ b/src/ifs/wl_seat/wl_pointer/mod.rs @@ -160,7 +160,7 @@ impl WlPointer { _ => { // cannot happen return Ok(()); - }, + } }; if pointer_node.client_id() != Some(self.seat.client.id) { return Ok(()); diff --git a/src/ifs/wl_surface/cursor.rs b/src/ifs/wl_surface/cursor.rs index c6f68237..6ee611d2 100644 --- a/src/ifs/wl_surface/cursor.rs +++ b/src/ifs/wl_surface/cursor.rs @@ -1,8 +1,8 @@ +use crate::ifs::wl_seat::WlSeatGlobal; +use crate::ifs::wl_surface::WlSurface; +use crate::rect::Rect; use std::cell::Cell; use std::rc::Rc; -use crate::ifs::wl_seat::{WlSeatGlobal}; -use crate::ifs::wl_surface::{WlSurface}; -use crate::rect::Rect; pub struct CursorSurface { seat: Rc, @@ -19,7 +19,7 @@ impl CursorSurface { surface: surface.clone(), hotspot: Cell::new((0, 0)), pos: Cell::new((0, 0)), - extents: Cell::new(Default::default()) + extents: Cell::new(Default::default()), } } @@ -27,7 +27,15 @@ impl CursorSurface { let (pos_x, pos_y) = self.pos.get(); let extents = self.extents.get(); let (hot_x, hot_y) = self.hotspot.get(); - self.extents.set(Rect::new_sized(pos_x - hot_x, pos_y - hot_y, extents.width(), extents.height()).unwrap()); + self.extents.set( + Rect::new_sized( + pos_x - hot_x, + pos_y - hot_y, + extents.width(), + extents.height(), + ) + .unwrap(), + ); } pub fn set_position(&self, x: i32, y: i32) { @@ -48,7 +56,8 @@ impl CursorSurface { Some(b) => (b.rect.width(), b.rect.height()), _ => (0, 0), }; - self.extents.set(Rect::new_sized(0, 0, width, height).unwrap()); + self.extents + .set(Rect::new_sized(0, 0, width, height).unwrap()); self.update_extents(); } diff --git a/src/ifs/wl_surface/mod.rs b/src/ifs/wl_surface/mod.rs index 86fadb88..92344d43 100644 --- a/src/ifs/wl_surface/mod.rs +++ b/src/ifs/wl_surface/mod.rs @@ -1,22 +1,28 @@ +pub mod cursor; mod types; pub mod wl_subsurface; pub mod xdg_surface; -pub mod cursor; use crate::backend::{KeyState, ScrollAxis, SeatId}; use crate::client::{Client, ClientId, DynEventFormatter, RequestParser}; use crate::fixed::Fixed; use crate::ifs::wl_buffer::WlBuffer; use crate::ifs::wl_callback::WlCallback; +use crate::ifs::wl_output::WlOutputId; use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; +use crate::ifs::wl_surface::cursor::CursorSurface; use crate::ifs::wl_surface::wl_subsurface::WlSubsurface; +use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceRole}; use crate::object::{Interface, Object, ObjectId}; use crate::pixman::Region; use crate::rect::Rect; +use crate::render::Renderer; use crate::tree::{Node, NodeId}; use crate::utils::buffd::{MsgParser, MsgParserError}; use crate::utils::clonecell::CloneCell; use crate::utils::linkedlist::LinkedList; +use crate::utils::smallmap::SmallMap; +use crate::xkbcommon::ModifierState; use crate::NumCell; use ahash::AHashMap; use std::cell::{Cell, RefCell}; @@ -24,12 +30,6 @@ use std::mem; use std::ops::{Deref, DerefMut}; use std::rc::Rc; pub use types::*; -use crate::ifs::wl_output::WlOutputId; -use crate::ifs::wl_surface::cursor::CursorSurface; -use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceRole}; -use crate::render::Renderer; -use crate::utils::smallmap::SmallMap; -use crate::xkbcommon::ModifierState; const DESTROY: u32 = 0; const ATTACH: u32 = 1; @@ -197,7 +197,10 @@ impl WlSurface { self.role.get() == SurfaceRole::Cursor } - pub fn get_cursor(self: &Rc, seat: &Rc) -> Result, WlSurfaceError> { + pub fn get_cursor( + self: &Rc, + seat: &Rc, + ) -> Result, WlSurfaceError> { if let Some(cursor) = self.cursors.get(&seat.id()) { return Ok(cursor); } diff --git a/src/ifs/wl_surface/types.rs b/src/ifs/wl_surface/types.rs index ac0af193..66532e42 100644 --- a/src/ifs/wl_surface/types.rs +++ b/src/ifs/wl_surface/types.rs @@ -1,15 +1,15 @@ use crate::client::{ClientError, EventFormatter, RequestParser}; use crate::ifs::wl_callback::WlCallbackId; +use crate::ifs::wl_output::WlOutputId; use crate::ifs::wl_region::WlRegionId; use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError; -use crate::ifs::wl_surface::{ENTER, SurfaceRole, WlSurface, WlSurfaceId}; +use crate::ifs::wl_surface::{SurfaceRole, WlSurface, WlSurfaceId, ENTER}; +use crate::object::Object; use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; use std::fmt::{Debug, Formatter}; use std::ops::Deref; use std::rc::Rc; use thiserror::Error; -use crate::ifs::wl_output::WlOutputId; -use crate::object::Object; #[derive(Debug, Error)] pub enum WlSurfaceError { diff --git a/src/ifs/wl_surface/xdg_surface/mod.rs b/src/ifs/wl_surface/xdg_surface/mod.rs index 288c85e2..46361a3e 100644 --- a/src/ifs/wl_surface/xdg_surface/mod.rs +++ b/src/ifs/wl_surface/xdg_surface/mod.rs @@ -2,7 +2,9 @@ mod types; pub mod xdg_popup; pub mod xdg_toplevel; +use crate::backend::SeatId; use crate::client::DynEventFormatter; +use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupId}; use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel; use crate::ifs::wl_surface::{ @@ -15,13 +17,11 @@ use crate::tree::{FindTreeResult, FoundNode, Node, WorkspaceNode}; use crate::utils::buffd::MsgParser; use crate::utils::clonecell::CloneCell; use crate::utils::copyhashmap::CopyHashMap; +use crate::utils::smallmap::SmallMap; use crate::NumCell; use std::cell::Cell; use std::rc::Rc; pub use types::*; -use crate::backend::SeatId; -use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; -use crate::utils::smallmap::SmallMap; const DESTROY: u32 = 0; const GET_TOPLEVEL: u32 = 1; @@ -158,7 +158,9 @@ impl XdgSurface { } pub fn focus_surface(&self, seat: &WlSeatGlobal) -> Rc { - self.focus_surface.get(&seat.id()).unwrap_or_else(|| self.surface.clone()) + self.focus_surface + .get(&seat.id()) + .unwrap_or_else(|| self.surface.clone()) } fn destroy_node(&self) { @@ -318,16 +320,10 @@ impl XdgSurface { } match self.surface.find_surface_at(x, y) { Some((node, x, y)) => { - tree.push(FoundNode { - node, - x, - y, - }); + tree.push(FoundNode { node, x, y }); FindTreeResult::AcceptsInput - }, - _ => { - FindTreeResult::Other } + _ => FindTreeResult::Other, } } diff --git a/src/ifs/wl_surface/xdg_surface/types.rs b/src/ifs/wl_surface/xdg_surface/types.rs index 93337b67..e1a243d6 100644 --- a/src/ifs/wl_surface/xdg_surface/types.rs +++ b/src/ifs/wl_surface/xdg_surface/types.rs @@ -1,7 +1,7 @@ use crate::client::{ClientError, EventFormatter, RequestParser}; use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopupError, XdgPopupId}; use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelId; -use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId, CONFIGURE, XdgSurfaceRole}; +use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId, XdgSurfaceRole, CONFIGURE}; use crate::ifs::wl_surface::{WlSurfaceError, WlSurfaceId}; use crate::ifs::xdg_positioner::XdgPositionerId; use crate::object::Object; diff --git a/src/ifs/wl_surface/xdg_surface/xdg_popup/mod.rs b/src/ifs/wl_surface/xdg_surface/xdg_popup/mod.rs index 49afed64..ade8c4e7 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_popup/mod.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_popup/mod.rs @@ -268,7 +268,7 @@ impl XdgSurfaceExt for XdgPopup { _ => { log::info!("no ws"); return; - }, + } }; let surface = &self.xdg.surface; let state = &surface.client.state; @@ -276,12 +276,7 @@ impl XdgSurfaceExt for XdgPopup { if wl.is_none() { self.xdg.set_workspace(&ws); *wl = Some(ws.stacked.add_last(self.clone())); - *dl = Some( - state - .root - .stacked - .add_last(self.clone()), - ); + *dl = Some(state.root.stacked.add_last(self.clone())); state.tree_changed(); } } else { diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel/mod.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel/mod.rs index 1a414bbb..40266caa 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel/mod.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel/mod.rs @@ -1,5 +1,6 @@ mod types; +use crate::backend::SeatId; use crate::client::{ClientId, DynEventFormatter}; use crate::fixed::Fixed; use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; @@ -11,16 +12,15 @@ use crate::tree::{ContainerNode, FindTreeResult}; use crate::tree::{FloatNode, FoundNode, Node, NodeId, ToplevelNodeId, WorkspaceNode}; use crate::utils::buffd::MsgParser; use crate::utils::clonecell::CloneCell; +use crate::utils::linkedlist::LinkedNode; +use crate::utils::smallmap::SmallMap; +use crate::NumCell; use ahash::{AHashMap, AHashSet}; use num_derive::FromPrimitive; use std::cell::{Cell, RefCell}; use std::mem; use std::rc::Rc; pub use types::*; -use crate::backend::{SeatId}; -use crate::NumCell; -use crate::utils::linkedlist::LinkedNode; -use crate::utils::smallmap::SmallMap; const DESTROY: u32 = 0; const SET_PARENT: u32 = 1; @@ -72,6 +72,13 @@ const STATE_TILED_BOTTOM: u32 = 8; id!(XdgToplevelId); +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Decoration { + #[allow(dead_code)] + Client, + Server, +} + pub struct XdgToplevel { pub id: XdgToplevelId, pub xdg: Rc, @@ -82,6 +89,7 @@ pub struct XdgToplevel { states: RefCell>, pub toplevel_history: SmallMap>, 1>, active_surfaces: NumCell, + pub decoration: Cell, } impl XdgToplevel { @@ -101,6 +109,7 @@ impl XdgToplevel { states: RefCell::new(states), toplevel_history: Default::default(), active_surfaces: Default::default(), + decoration: Cell::new(Decoration::Server), } } @@ -114,7 +123,10 @@ impl XdgToplevel { }; if changed { let rect = self.xdg.absolute_desired_extents.get(); - self.xdg.surface.client.event(self.configure(rect.width(), rect.height())); + self.xdg + .surface + .client + .event(self.configure(rect.width(), rect.height())); self.xdg.send_configure(); } } @@ -282,17 +294,12 @@ impl XdgToplevel { seat_state: Default::default(), }); self.parent_node.set(Some(floater.clone())); - floater.display_link.set(Some( - state - .root - .stacked - .add_last(floater.clone()), - )); - floater.workspace_link.set(Some( - workspace - .stacked - .add_last(floater.clone()), - )); + floater + .display_link + .set(Some(state.root.stacked.add_last(floater.clone()))); + floater + .workspace_link + .set(Some(workspace.stacked.add_last(floater.clone()))); } fn map_tiled(self: &Rc) { @@ -319,8 +326,12 @@ impl XdgToplevel { container.append_child(self.clone()); self.parent_node.set(Some(container)); } else { - let container = - Rc::new(ContainerNode::new(state, &workspace, workspace.clone(), self.clone())); + let container = Rc::new(ContainerNode::new( + state, + &workspace, + workspace.clone(), + self.clone(), + )); workspace.set_container(&container); self.parent_node.set(Some(container)); }; @@ -444,7 +455,10 @@ impl XdgSurfaceExt for XdgToplevel { let bindings = output.global.bindings.borrow_mut(); for binding in bindings.get(&self.xdg.surface.client.id) { for binding in binding.values() { - self.xdg.surface.client.event(self.xdg.surface.enter_event(binding.id)); + self.xdg + .surface + .client + .event(self.xdg.surface.enter_event(binding.id)); } } } diff --git a/src/ifs/zxdg_decoration_manager_v1/mod.rs b/src/ifs/zxdg_decoration_manager_v1/mod.rs new file mode 100644 index 00000000..498563ad --- /dev/null +++ b/src/ifs/zxdg_decoration_manager_v1/mod.rs @@ -0,0 +1,113 @@ +use crate::client::Client; +use crate::globals::{Global, GlobalName}; +use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1; +use crate::object::{Interface, Object, ObjectId}; +use crate::utils::buffd::MsgParser; +use std::rc::Rc; +pub use types::*; + +mod types; + +const DESTROY: u32 = 0; +const GET_TOPLEVEL_DECORATION: u32 = 1; + +id!(ZxdgDecorationManagerV1Id); + +pub struct ZxdgDecorationManagerV1Global { + name: GlobalName, +} +impl ZxdgDecorationManagerV1Global { + pub fn new(name: GlobalName) -> Self { + Self { name } + } + + fn bind_( + self: Rc, + id: ZxdgDecorationManagerV1Id, + client: &Rc, + version: u32, + ) -> Result<(), ZxdgDecorationManagerV1Error> { + let obj = Rc::new(ZxdgDecorationManagerV1Obj { + id, + client: client.clone(), + _version: version, + }); + client.add_client_obj(&obj)?; + Ok(()) + } +} + +bind!(ZxdgDecorationManagerV1Global); + +impl Global for ZxdgDecorationManagerV1Global { + fn name(&self) -> GlobalName { + self.name + } + + fn singleton(&self) -> bool { + true + } + + fn interface(&self) -> Interface { + Interface::ZxdgDecorationManagerV1 + } + + fn version(&self) -> u32 { + 1 + } +} + +pub struct ZxdgDecorationManagerV1Obj { + id: ZxdgDecorationManagerV1Id, + client: Rc, + _version: u32, +} + +impl ZxdgDecorationManagerV1Obj { + fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> { + let _req: Destroy = self.client.parse(self, parser)?; + self.client.remove_obj(self)?; + Ok(()) + } + + fn get_toplevel_decoration( + &self, + parser: MsgParser<'_, '_>, + ) -> Result<(), GetToplevelDecorationError> { + let req: GetToplevelDecoration = self.client.parse(self, parser)?; + let tl = self.client.get_xdg_toplevel(req.toplevel)?; + let obj = Rc::new(ZxdgToplevelDecorationV1::new(req.id, &self.client, &tl)); + self.client.add_client_obj(&obj)?; + obj.send_configure(); + Ok(()) + } + + fn handle_request_( + self: &Rc, + request: u32, + parser: MsgParser<'_, '_>, + ) -> Result<(), ZxdgDecorationManagerV1Error> { + match request { + DESTROY => self.destroy(parser)?, + GET_TOPLEVEL_DECORATION => self.get_toplevel_decoration(parser)?, + _ => unreachable!(), + } + Ok(()) + } +} + +handle_request!(ZxdgDecorationManagerV1Obj); + +impl Object for ZxdgDecorationManagerV1Obj { + fn id(&self) -> ObjectId { + self.id.into() + } + + fn interface(&self) -> Interface { + Interface::ZxdgDecorationManagerV1 + } + + fn num_requests(&self) -> u32 { + GET_TOPLEVEL_DECORATION + 1 + } +} diff --git a/src/ifs/zxdg_decoration_manager_v1/types.rs b/src/ifs/zxdg_decoration_manager_v1/types.rs new file mode 100644 index 00000000..39cf5847 --- /dev/null +++ b/src/ifs/zxdg_decoration_manager_v1/types.rs @@ -0,0 +1,71 @@ +use crate::client::{ClientError, RequestParser}; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelId; +use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1Id; +use crate::utils::buffd::{MsgParser, MsgParserError}; +use std::fmt::{Debug, Formatter}; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum ZxdgDecorationManagerV1Error { + #[error("Could not process a `destroy` request")] + DestroyError(#[from] DestroyError), + #[error("Could not process a `get_toplevel_decoration` request")] + GetToplevelDecorationError(#[from] GetToplevelDecorationError), + #[error(transparent)] + ClientError(Box), +} +efrom!(ZxdgDecorationManagerV1Error, ClientError); + +#[derive(Debug, Error)] +pub enum DestroyError { + #[error("Parsing failed")] + MsgParserError(#[source] Box), + #[error(transparent)] + ClientError(Box), +} +efrom!(DestroyError, ClientError); +efrom!(DestroyError, MsgParserError); + +#[derive(Debug, Error)] +pub enum GetToplevelDecorationError { + #[error("Parsing failed")] + MsgParserError(#[source] Box), + #[error(transparent)] + ClientError(Box), +} +efrom!(GetToplevelDecorationError, ClientError); +efrom!(GetToplevelDecorationError, MsgParserError); + +pub(super) struct Destroy; +impl RequestParser<'_> for Destroy { + fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { + Ok(Self) + } +} +impl Debug for Destroy { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "destroy()") + } +} + +pub(super) struct GetToplevelDecoration { + pub id: ZxdgToplevelDecorationV1Id, + pub toplevel: XdgToplevelId, +} +impl RequestParser<'_> for GetToplevelDecoration { + fn parse(parser: &mut MsgParser<'_, '_>) -> Result { + Ok(Self { + id: parser.object()?, + toplevel: parser.object()?, + }) + } +} +impl Debug for GetToplevelDecoration { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!( + f, + "get_toplevel_decoration(id: {}, toplevel: {})", + self.id, self.toplevel + ) + } +} diff --git a/src/ifs/zxdg_toplevel_decoration_v1/mod.rs b/src/ifs/zxdg_toplevel_decoration_v1/mod.rs new file mode 100644 index 00000000..829edbea --- /dev/null +++ b/src/ifs/zxdg_toplevel_decoration_v1/mod.rs @@ -0,0 +1,103 @@ +mod types; + +use crate::client::{Client, DynEventFormatter}; +use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{Decoration, XdgToplevel}; +use crate::object::{Interface, Object, ObjectId}; +use crate::utils::buffd::MsgParser; +use std::rc::Rc; +pub use types::*; + +const DESTROY: u32 = 0; +const SET_MODE: u32 = 1; +const UNSET_MODE: u32 = 2; + +const CONFIGURE: u32 = 0; + +const CLIENT_SIDE: u32 = 1; +const SERVER_SIDE: u32 = 2; + +id!(ZxdgToplevelDecorationV1Id); + +pub struct ZxdgToplevelDecorationV1 { + pub id: ZxdgToplevelDecorationV1Id, + pub client: Rc, + pub toplevel: Rc, +} + +impl ZxdgToplevelDecorationV1 { + pub fn new( + id: ZxdgToplevelDecorationV1Id, + client: &Rc, + toplevel: &Rc, + ) -> Self { + Self { + id, + client: client.clone(), + toplevel: toplevel.clone(), + } + } + + fn configure(self: &Rc, mode: u32) -> DynEventFormatter { + Box::new(Configure { + obj: self.clone(), + mode, + }) + } + + pub fn send_configure(self: &Rc) { + let mode = match self.toplevel.decoration.get() { + Decoration::Client => CLIENT_SIDE, + Decoration::Server => SERVER_SIDE, + }; + self.client.event(self.configure(mode)); + self.toplevel.xdg.send_configure(); + } + + fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> { + let _req: Destroy = self.client.parse(self, parser)?; + self.client.remove_obj(self)?; + Ok(()) + } + + fn set_mode(self: &Rc, parser: MsgParser<'_, '_>) -> Result<(), SetModeError> { + let _req: SetMode = self.client.parse(&**self, parser)?; + self.send_configure(); + Ok(()) + } + + fn unset_mode(self: &Rc, parser: MsgParser<'_, '_>) -> Result<(), UnsetModeError> { + let _req: UnsetMode = self.client.parse(&**self, parser)?; + self.send_configure(); + Ok(()) + } + + fn handle_request_( + self: &Rc, + request: u32, + parser: MsgParser<'_, '_>, + ) -> Result<(), ZxdgToplevelDecorationV1Error> { + match request { + DESTROY => self.destroy(parser)?, + SET_MODE => self.set_mode(parser)?, + UNSET_MODE => self.unset_mode(parser)?, + _ => unreachable!(), + } + Ok(()) + } +} + +handle_request!(ZxdgToplevelDecorationV1); + +impl Object for ZxdgToplevelDecorationV1 { + fn id(&self) -> ObjectId { + self.id.into() + } + + fn interface(&self) -> Interface { + Interface::ZxdgToplevelDecorationV1 + } + + fn num_requests(&self) -> u32 { + UNSET_MODE + 1 + } +} diff --git a/src/ifs/zxdg_toplevel_decoration_v1/types.rs b/src/ifs/zxdg_toplevel_decoration_v1/types.rs new file mode 100644 index 00000000..6d93375d --- /dev/null +++ b/src/ifs/zxdg_toplevel_decoration_v1/types.rs @@ -0,0 +1,100 @@ +use crate::client::{ClientError, EventFormatter, RequestParser}; +use crate::ifs::zxdg_toplevel_decoration_v1::{ZxdgToplevelDecorationV1, CONFIGURE}; +use crate::object::Object; +use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; +use std::fmt::{Debug, Formatter}; +use std::ops::Deref; +use std::rc::Rc; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum ZxdgToplevelDecorationV1Error { + #[error("Could not process a `destroy` request")] + DestoryError(#[from] DestroyError), + #[error("Could not process a `set_mode` request")] + SetModeError(#[from] SetModeError), + #[error("Could not process a `unset_mode` request")] + UnsetModeError(#[from] UnsetModeError), +} + +#[derive(Debug, Error)] +pub enum DestroyError { + #[error("Parsing failed")] + MsgParserError(#[source] Box), + #[error(transparent)] + ClientError(Box), +} +efrom!(DestroyError, ClientError); +efrom!(DestroyError, MsgParserError); + +#[derive(Debug, Error)] +pub enum SetModeError { + #[error("Parsing failed")] + MsgParserError(#[source] Box), +} +efrom!(SetModeError, MsgParserError); + +#[derive(Debug, Error)] +pub enum UnsetModeError { + #[error("Parsing failed")] + MsgParserError(#[source] Box), +} +efrom!(UnsetModeError, MsgParserError); + +pub(super) struct Destroy; +impl RequestParser<'_> for Destroy { + fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { + Ok(Self) + } +} +impl Debug for Destroy { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "destroy()") + } +} + +pub(super) struct SetMode { + pub mode: u32, +} +impl RequestParser<'_> for SetMode { + fn parse(parser: &mut MsgParser<'_, '_>) -> Result { + Ok(Self { + mode: parser.uint()?, + }) + } +} +impl Debug for SetMode { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "set_mode(mode: {})", self.mode) + } +} + +pub(super) struct UnsetMode; +impl RequestParser<'_> for UnsetMode { + fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { + Ok(Self) + } +} +impl Debug for UnsetMode { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "unset_mode()") + } +} + +pub(super) struct Configure { + pub obj: Rc, + pub mode: u32, +} +impl EventFormatter for Configure { + fn format(self: Box, fmt: &mut MsgFormatter<'_>) { + fmt.header(self.obj.id, CONFIGURE).uint(self.mode); + } + fn obj(&self) -> &dyn Object { + self.obj.deref() + } +} +impl Debug for Configure { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "configure(mode: {})", self.mode) + } +} diff --git a/src/main.rs b/src/main.rs index 9cae4f51..6c2cf001 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,23 +13,21 @@ clippy::redundant_clone )] -use std::cell::Cell; use crate::acceptor::AcceptorError; use crate::async_engine::AsyncError; use crate::backends::xorg::{XorgBackend, XorgBackendError}; use crate::client::Clients; use crate::clientmem::ClientMemError; use crate::event_loop::EventLoopError; -use crate::globals::{AddGlobal, Globals}; -use crate::ifs::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerGlobal; +use crate::globals::Globals; use crate::ifs::wl_compositor::WlCompositorGlobal; use crate::ifs::wl_data_device_manager::WlDataDeviceManagerGlobal; -use crate::ifs::wl_drm::WlDrmGlobal; use crate::ifs::wl_shm::WlShmGlobal; use crate::ifs::wl_subcompositor::WlSubcompositorGlobal; use crate::ifs::wl_surface::NoneSurfaceExt; use crate::ifs::xdg_wm_base::XdgWmBaseGlobal; use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Global; +use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Global; use crate::render::RenderError; use crate::sighand::SighandError; use crate::state::State; @@ -42,6 +40,7 @@ use acceptor::Acceptor; use async_engine::AsyncEngine; use event_loop::EventLoop; use log::LevelFilter; +use std::cell::Cell; use std::rc::Rc; use thiserror::Error; use wheel::Wheel; @@ -76,8 +75,8 @@ mod xkbcommon; fn main() { env_logger::builder() - .filter_level(LevelFilter::Inf) - // .filter_level(LevelFilter::Trace) + .filter_level(LevelFilter::Info) + .filter_level(LevelFilter::Trace) .init(); if let Err(e) = main_() { log::error!("A fatal error occurred: {}", ErrorFmt(e)); @@ -107,23 +106,11 @@ enum MainError { fn main_() -> Result<(), MainError> { render::init()?; - clientmem::init()?; let el = EventLoop::new()?; sighand::install(&el)?; let wheel = Wheel::install(&el)?; let engine = AsyncEngine::install(&el, &wheel)?; - let globals = Globals::new(); - globals.add_global_no_broadcast(&Rc::new(WlCompositorGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(WlShmGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(WlSubcompositorGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(XdgWmBaseGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(WlDataDeviceManagerGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(ZwpLinuxDmabufV1Global::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(WlDrmGlobal::new(globals.name()))); - globals.add_global_no_broadcast(&Rc::new(OrgKdeKwinServerDecorationManagerGlobal::new( - globals.name(), - ))); let node_ids = NodeIds::default(); let state = Rc::new(State { eng: engine.clone(), @@ -132,7 +119,7 @@ fn main_() -> Result<(), MainError> { wheel, clients: Clients::new(), next_name: NumCell::new(1), - globals, + globals: Globals::new(), output_ids: Default::default(), root: Rc::new(DisplayNode::new(node_ids.next())), node_ids, diff --git a/src/object.rs b/src/object.rs index a5680a7d..7945316c 100644 --- a/src/object.rs +++ b/src/object.rs @@ -69,8 +69,8 @@ pub enum Interface { WlDrm, ZwpLinuxDmabufV1, ZwpLinuxBufferParamsV1, - OrgKdeKwinServerDecorationManager, - OrgKdeKwinServerDecoration, + ZxdgDecorationManagerV1, + ZxdgToplevelDecorationV1, } impl Interface { @@ -104,10 +104,8 @@ impl Interface { Interface::ZwpLinuxDmabufV1 => "zwp_linux_dmabuf_v1", Interface::ZwpLinuxBufferParamsV1 => "zwp_linux_buffer_params_v1", Interface::WlDrm => "wl_drm", - Interface::OrgKdeKwinServerDecorationManager => { - "org_kde_kwin_server_decoration_manager" - } - Interface::OrgKdeKwinServerDecoration => "org_kde_kwin_server_decoration", + Interface::ZxdgDecorationManagerV1 => "zxdg_decoration_manager_v1", + Interface::ZxdgToplevelDecorationV1 => "zxdg_toplevel_decoration_v1", } } } diff --git a/src/render/gl/sys.rs b/src/render/gl/sys.rs index 32c1dfad..63bc3e6b 100644 --- a/src/render/gl/sys.rs +++ b/src/render/gl/sys.rs @@ -40,9 +40,9 @@ pub const GL_TRIANGLES: GLenum = 0x0004; pub const GL_UNPACK_ROW_LENGTH_EXT: GLenum = 0x0CF2; pub const GL_UNSIGNED_BYTE: GLint = 0x1401; pub const GL_VERTEX_SHADER: GLenum = 0x8B31; -pub const GL_BLEND : GLenum = 0x0BE2; -pub const GL_ONE : GLenum = 1; -pub const GL_ONE_MINUS_SRC_ALPHA : GLenum = 0x0303; +pub const GL_BLEND: GLenum = 0x0BE2; +pub const GL_ONE: GLenum = 1; +pub const GL_ONE_MINUS_SRC_ALPHA: GLenum = 0x0303; #[link(name = "GLESv2")] extern "C" { @@ -69,7 +69,7 @@ extern "C" { ); pub fn glCheckFramebufferStatus(target: GLenum) -> GLenum; pub fn glClear(mask: GLbitfield); - pub fn glBlendFunc (sfactor: GLenum, dfactor: GLenum); + pub fn glBlendFunc(sfactor: GLenum, dfactor: GLenum); pub fn glClearColor(red: GLfloat, green: GLfloat, blue: GLfloat, alpha: GLfloat); #[allow(dead_code)] pub fn glFlush(); diff --git a/src/render/renderer/framebuffer.rs b/src/render/renderer/framebuffer.rs index 1a6a6b27..1822d846 100644 --- a/src/render/renderer/framebuffer.rs +++ b/src/render/renderer/framebuffer.rs @@ -1,15 +1,15 @@ +use crate::rect::Rect; use crate::render::gl::frame_buffer::GlFrameBuffer; use crate::render::gl::sys::{ glBindFramebuffer, glClear, glClearColor, glViewport, GL_COLOR_BUFFER_BIT, GL_FRAMEBUFFER, }; use crate::render::renderer::context::RenderContext; use crate::render::renderer::renderer::Renderer; +use crate::render::sys::{glBlendFunc, GL_ONE, GL_ONE_MINUS_SRC_ALPHA}; use crate::tree::Node; +use crate::State; use std::ptr; use std::rc::Rc; -use crate::rect::Rect; -use crate::render::sys::{GL_ONE, GL_ONE_MINUS_SRC_ALPHA, glBlendFunc}; -use crate::State; pub struct Framebuffer { pub(super) ctx: Rc, diff --git a/src/render/renderer/renderer.rs b/src/render/renderer/renderer.rs index e392caf6..7c9b3c43 100644 --- a/src/render/renderer/renderer.rs +++ b/src/render/renderer/renderer.rs @@ -10,14 +10,14 @@ use crate::render::gl::sys::{ GL_TEXTURE_MIN_FILTER, GL_TRIANGLES, GL_TRIANGLE_STRIP, }; use crate::render::renderer::context::RenderContext; +use crate::render::sys::{glDisable, glEnable, GL_BLEND}; use crate::tree::{ - ContainerFocus, ContainerNode, ContainerSplit, FloatNode, OutputNode, - WorkspaceNode, CONTAINER_BORDER, CONTAINER_TITLE_HEIGHT, + ContainerFocus, ContainerNode, ContainerSplit, FloatNode, OutputNode, WorkspaceNode, + CONTAINER_BORDER, CONTAINER_TITLE_HEIGHT, }; use std::ops::Deref; use std::rc::Rc; use std::slice; -use crate::render::sys::{GL_BLEND, glDisable, glEnable}; const NON_COLOR: (f32, f32, f32) = (0.2, 0.2, 0.2); const CHILD_COLOR: (f32, f32, f32) = (0.8, 0.8, 0.8); @@ -233,11 +233,11 @@ impl Renderer<'_> { true => { glEnable(GL_BLEND); &self.ctx.tex_alpha_prog - }, + } false => { glDisable(GL_BLEND); &self.ctx.tex_prog - }, + } }; glUseProgram(prog.prog.prog); @@ -269,14 +269,7 @@ impl Renderer<'_> { 0, texcoord.as_ptr() as _, ); - glVertexAttribPointer( - prog.pos as _, - 2, - GL_FLOAT, - GL_FALSE, - 0, - pos.as_ptr() as _, - ); + glVertexAttribPointer(prog.pos as _, 2, GL_FLOAT, GL_FALSE, 0, pos.as_ptr() as _); glEnableVertexAttribArray(prog.texcoord as _); glEnableVertexAttribArray(prog.pos as _); diff --git a/src/tasks/seat.rs b/src/tasks/seat.rs index aaf01a10..066f6a46 100644 --- a/src/tasks/seat.rs +++ b/src/tasks/seat.rs @@ -19,10 +19,11 @@ impl SeatHandler { } let name = self.state.globals.name(); let global = Rc::new(WlSeatGlobal::new(name, &self.state, &self.seat)); - let _tree_changed = self - .state - .eng - .spawn(tree_changed(self.state.clone(), global.clone(), self.tree_changed.clone())); + let _tree_changed = self.state.eng.spawn(tree_changed( + self.state.clone(), + global.clone(), + self.tree_changed.clone(), + )); let mut _node = self.state.seat_queue.add_last(global.clone()); self.state.add_global(&global); loop { diff --git a/src/tree/container.rs b/src/tree/container.rs index 43ed2e29..58e993ce 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -1,3 +1,4 @@ +use crate::ifs::wl_seat::NodeSeatState; use crate::rect::Rect; use crate::render::Renderer; use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode}; @@ -7,7 +8,6 @@ use crate::{NumCell, State}; use ahash::AHashMap; use std::cell::{Cell, RefCell}; use std::rc::Rc; -use crate::ifs::wl_seat::{NodeSeatState}; #[allow(dead_code)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -75,7 +75,12 @@ impl ContainerChild { } impl ContainerNode { - pub fn new(state: &State, workspace: &Rc, parent: Rc, child: Rc) -> Self { + pub fn new( + state: &State, + workspace: &Rc, + parent: Rc, + child: Rc, + ) -> Self { child.clone().set_workspace(workspace); let children = LinkedList::new(); let mut child_nodes = AHashMap::new(); @@ -290,13 +295,11 @@ impl Node for ContainerNode { let mut recurse = |content: Rect, child: NodeRef| { if content.contains(x, y) { let (x, y) = content.translate(x, y); - tree.push( - FoundNode { - node: child.node.clone(), - x, - y, - } - ); + tree.push(FoundNode { + node: child.node.clone(), + x, + y, + }); child.node.find_tree_at(x, y, tree); } }; diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 2d74fc82..ec3032ff 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -1,11 +1,14 @@ use crate::backend::{KeyState, OutputId, ScrollAxis}; +use crate::client::ClientId; use crate::fixed::Fixed; +use crate::ifs::wl_output::WlOutputGlobal; use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal}; use crate::rect::Rect; use crate::render::Renderer; use crate::utils::clonecell::CloneCell; use crate::utils::copyhashmap::CopyHashMap; use crate::utils::linkedlist::{LinkedList, LinkedNode}; +use crate::xkbcommon::ModifierState; use crate::NumCell; pub use container::*; use std::cell::{Cell, RefCell}; @@ -13,9 +16,6 @@ use std::fmt::Display; use std::ops::Deref; use std::rc::Rc; pub use workspace::*; -use crate::client::ClientId; -use crate::ifs::wl_output::WlOutputGlobal; -use crate::xkbcommon::ModifierState; mod container; mod workspace; @@ -227,7 +227,7 @@ impl Node for DisplayNode { match stacked.find_tree_at(x, y, tree) { FindTreeResult::AcceptsInput => { return FindTreeResult::AcceptsInput; - }, + } FindTreeResult::Other => { tree.drain(idx..); } @@ -398,7 +398,8 @@ impl Node for FloatNode { if let Some(c) = self.child.get() { c.set_workspace(ws); } - self.workspace_link.set(Some(ws.stacked.add_last(self.clone()))); + self.workspace_link + .set(Some(ws.stacked.add_last(self.clone()))); self.workspace.set(ws.clone()); } } diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index 24ce2fd6..05cc32dc 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -1,3 +1,4 @@ +use crate::ifs::wl_seat::NodeSeatState; use crate::rect::Rect; use crate::render::Renderer; use crate::tree::container::ContainerNode; @@ -5,7 +6,6 @@ use crate::tree::{AbsoluteNode, FindTreeResult, FoundNode, Node, NodeId, OutputN use crate::utils::clonecell::CloneCell; use crate::utils::linkedlist::LinkedList; use std::rc::Rc; -use crate::ifs::wl_seat::NodeSeatState; tree_id!(WorkspaceNodeId); diff --git a/src/utils/clonecell.rs b/src/utils/clonecell.rs index b9e0ad00..ad635d66 100644 --- a/src/utils/clonecell.rs +++ b/src/utils/clonecell.rs @@ -22,9 +22,7 @@ impl CloneCell { #[inline(always)] pub fn set(&self, t: T) -> T { - unsafe { - mem::replace(self.data.get().deref_mut(), t) - } + unsafe { mem::replace(self.data.get().deref_mut(), t) } } #[inline(always)] diff --git a/src/utils/smallmap.rs b/src/utils/smallmap.rs index 49745bc1..22faa641 100644 --- a/src/utils/smallmap.rs +++ b/src/utils/smallmap.rs @@ -11,7 +11,7 @@ pub struct SmallMap { impl Default for SmallMap { fn default() -> Self { Self { - m: Default::default() + m: Default::default(), } } } @@ -24,9 +24,7 @@ impl SmallMap { } pub fn len(&self) -> usize { - unsafe { - self.m.get().deref().len() - } + unsafe { self.m.get().deref().len() } } pub fn insert(&self, k: K, v: V) -> Option { @@ -55,15 +53,11 @@ impl SmallMap { } pub fn take(&self) -> SmallVec<[(K, V); N]> { - unsafe { - mem::take(self.m.get().deref_mut()) - } + unsafe { mem::take(self.m.get().deref_mut()) } } pub fn pop(&self) -> Option<(K, V)> { - unsafe { - self.m.get().deref_mut().pop() - } + unsafe { self.m.get().deref_mut().pop() } } } @@ -86,10 +80,7 @@ impl<'a, K: Copy, V: UnsafeCellCloneSafe, const N: usize> IntoIterator for &'a S type IntoIter = SmallMapIter<'a, K, V, N>; fn into_iter(self) -> Self::IntoIter { - SmallMapIter { - pos: 0, - map: self, - } + SmallMapIter { pos: 0, map: self } } }