1
0
Fork 0
forked from wry/wry

autocommit 2022-02-01 01:20:49 CET

This commit is contained in:
Julian Orth 2022-02-01 01:20:49 +01:00
parent f2117256b9
commit 7654e70f64
39 changed files with 830 additions and 761 deletions

View file

@ -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) => {

179
src/client/error.rs Normal file
View file

@ -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<ClientError>),
#[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<MsgParserError>),
#[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<WlDisplayError>),
#[error("An error occurred in a `wl_registry`")]
WlRegistryError(#[source] Box<WlRegistryError>),
#[error("Could not add object {0} to the client")]
AddObjectError(ObjectId, #[source] Box<ClientError>),
#[error("An error occurred in a `wl_surface`")]
WlSurfaceError(#[source] Box<WlSurfaceError>),
#[error("An error occurred in a `wl_compositor`")]
WlCompositorError(#[source] Box<WlCompositorError>),
#[error("An error occurred in a `wl_shm`")]
WlShmError(#[source] Box<WlShmError>),
#[error("An error occurred in a `wl_shm_pool`")]
WlShmPoolError(#[source] Box<WlShmPoolError>),
#[error("An error occurred in a `wl_region`")]
WlRegionError(#[source] Box<WlRegionError>),
#[error("An error occurred in a `wl_subsurface`")]
WlSubsurfaceError(#[source] Box<WlSubsurfaceError>),
#[error("An error occurred in a `wl_subcompositor`")]
WlSubcompositorError(#[source] Box<WlSubcompositorError>),
#[error("An error occurred in a `xdg_surface`")]
XdgSurfaceError(#[source] Box<XdgSurfaceError>),
#[error("An error occurred in a `xdg_positioner`")]
XdgPositionerError(#[source] Box<XdgPositionerError>),
#[error("An error occurred in a `xdg_popup`")]
XdgPopupError(#[source] Box<XdgPopupError>),
#[error("An error occurred in a `xdg_toplevel`")]
XdgToplevelError(#[source] Box<XdgToplevelError>),
#[error("An error occurred in a `xdg_wm_base`")]
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
#[error("An error occurred in a `wl_buffer`")]
WlBufferError(#[source] Box<WlBufferError>),
#[error("An error occurred in a `wl_output`")]
WlOutputError(#[source] Box<WlOutputError>),
#[error("An error occurred in a `wl_seat`")]
WlSeatError(#[source] Box<WlSeatError>),
#[error("An error occurred in a `wl_pointer`")]
WlPointerError(#[source] Box<WlPointerError>),
#[error("An error occurred in a `wl_keyboard`")]
WlKeyboardError(#[source] Box<WlKeyboardError>),
#[error("An error occurred in a `wl_touch`")]
WlTouchError(#[source] Box<WlTouchError>),
#[error("Object {0} is not a display")]
NotADisplay(ObjectId),
#[error("An error occurred in a `wl_data_device`")]
WlDataDeviceError(#[source] Box<WlDataDeviceError>),
#[error("An error occurred in a `wl_data_device_manager`")]
WlDataDeviceManagerError(#[source] Box<WlDataDeviceManagerError>),
#[error("An error occurred in a `wl_data_offer`")]
WlDataOfferError(#[source] Box<WlDataOfferError>),
#[error("An error occurred in a `wl_data_source`")]
WlDataSourceError(#[source] Box<WlDataSourceError>),
#[error("An error occurred in a `zwp_linx_dmabuf_v1`")]
ZwpLinuxDmabufV1Error(#[source] Box<ZwpLinuxDmabufV1Error>),
#[error("An error occurred in a `zwp_linx_buffer_params_v1`")]
ZwpLinuxBufferParamsV1Error(#[source] Box<ZwpLinuxBufferParamsV1Error>),
#[error("An error occurred in a `wl_drm`")]
WlDrmError(#[source] Box<WlDrmError>),
#[error("An error occurred in a `zxdg_decoration_manager_v1`")]
ZxdgDecorationManagerV1Error(#[source] Box<ZxdgDecorationManagerV1Error>),
#[error("An error occurred in a `zxdg_toplevel_decoration_v1`")]
ZxdgToplevelDecorationV1Error(#[source] Box<ZxdgToplevelDecorationV1Error>),
}
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))
}
}

View file

@ -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<ClientError>),
#[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<MsgParserError>),
#[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<WlDisplayError>),
#[error("An error occurred in a `wl_registry`")]
WlRegistryError(#[source] Box<WlRegistryError>),
#[error("Could not add object {0} to the client")]
AddObjectError(ObjectId, #[source] Box<ClientError>),
#[error("An error occurred in a `wl_surface`")]
WlSurfaceError(#[source] Box<WlSurfaceError>),
#[error("An error occurred in a `wl_compositor`")]
WlCompositorError(#[source] Box<WlCompositorError>),
#[error("An error occurred in a `wl_shm`")]
WlShmError(#[source] Box<WlShmError>),
#[error("An error occurred in a `wl_shm_pool`")]
WlShmPoolError(#[source] Box<WlShmPoolError>),
#[error("An error occurred in a `wl_region`")]
WlRegionError(#[source] Box<WlRegionError>),
#[error("An error occurred in a `wl_subsurface`")]
WlSubsurfaceError(#[source] Box<WlSubsurfaceError>),
#[error("An error occurred in a `wl_subcompositor`")]
WlSubcompositorError(#[source] Box<WlSubcompositorError>),
#[error("An error occurred in a `xdg_surface`")]
XdgSurfaceError(#[source] Box<XdgSurfaceError>),
#[error("An error occurred in a `xdg_positioner`")]
XdgPositionerError(#[source] Box<XdgPositionerError>),
#[error("An error occurred in a `xdg_popup`")]
XdgPopupError(#[source] Box<XdgPopupError>),
#[error("An error occurred in a `xdg_toplevel`")]
XdgToplevelError(#[source] Box<XdgToplevelError>),
#[error("An error occurred in a `xdg_wm_base`")]
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
#[error("An error occurred in a `wl_buffer`")]
WlBufferError(#[source] Box<WlBufferError>),
#[error("An error occurred in a `wl_output`")]
WlOutputError(#[source] Box<WlOutputError>),
#[error("An error occurred in a `wl_seat`")]
WlSeatError(#[source] Box<WlSeatError>),
#[error("An error occurred in a `wl_pointer`")]
WlPointerError(#[source] Box<WlPointerError>),
#[error("An error occurred in a `wl_keyboard`")]
WlKeyboardError(#[source] Box<WlKeyboardError>),
#[error("An error occurred in a `wl_touch`")]
WlTouchError(#[source] Box<WlTouchError>),
#[error("Object {0} is not a display")]
NotADisplay(ObjectId),
#[error("An error occurred in a `wl_data_device`")]
WlDataDeviceError(#[source] Box<WlDataDeviceError>),
#[error("An error occurred in a `wl_data_device_manager`")]
WlDataDeviceManagerError(#[source] Box<WlDataDeviceManagerError>),
#[error("An error occurred in a `wl_data_offer`")]
WlDataOfferError(#[source] Box<WlDataOfferError>),
#[error("An error occurred in a `wl_data_source`")]
WlDataSourceError(#[source] Box<WlDataSourceError>),
#[error("An error occurred in a `zwp_linx_dmabuf_v1`")]
ZwpLinuxDmabufV1Error(#[source] Box<ZwpLinuxDmabufV1Error>),
#[error("An error occurred in a `zwp_linx_buffer_params_v1`")]
ZwpLinuxBufferParamsV1Error(#[source] Box<ZwpLinuxBufferParamsV1Error>),
#[error("An error occurred in a `wl_drm`")]
WlDrmError(#[source] Box<WlDrmError>),
#[error("An error occurred in a `org_kde_kwin_server_decoration_manager`")]
OrgKdeKwinServerDecorationManagerError(#[source] Box<OrgKdeKwinServerDecorationManagerError>),
#[error("An error occurred in a `org_kde_kwin_server_decoration`")]
OrgKdeKwinServerDecorationError(#[source] Box<OrgKdeKwinServerDecorationError>),
}
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<Rc<XdgToplevel>, 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) => {

View file

@ -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<Option<Rc<WlDisplay>>>,

View file

@ -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<ZwpLinuxDmabufV1Error>),
#[error("An error occurred in a `wl_drm` global")]
WlDrmError(#[source] Box<WlDrmError>),
#[error("An error occurred in a `org_kde_kwin_server_decoration_manager` global")]
OrgKdeKwinServerDecorationManagerError(#[source] Box<OrgKdeKwinServerDecorationManagerError>),
#[error("An error occurred in a `zxdg_decoration_manager_v1` global")]
ZxdgDecorationManagerV1Error(#[source] Box<ZxdgDecorationManagerV1Error>),
}
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) => {

View file

@ -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;

View file

@ -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<Client>,
requested: Cell<bool>,
}
impl OrgKdeKwinServerDecoration {
pub fn new(id: OrgKdeKwinServerDecorationId, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
requested: Cell::new(false),
}
}
pub fn mode(self: &Rc<Self>, 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<Self>, 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<Self>,
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
}
}

View file

@ -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<ClientError>),
}
efrom!(OrgKdeKwinServerDecorationError, ClientError);
#[derive(Debug, Error)]
pub enum ReleaseError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
ParseError(#[source] Box<MsgParserError>),
}
efrom!(ReleaseError, ClientError);
efrom!(ReleaseError, ParseError, MsgParserError);
#[derive(Debug, Error)]
pub enum RequestModeError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
ParseError(#[source] Box<MsgParserError>),
#[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<Self, MsgParserError> {
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<Self, MsgParserError> {
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<OrgKdeKwinServerDecoration>,
pub mode: u32,
}
impl EventFormatter for Mode {
fn format(self: Box<Self>, 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)
}
}

View file

@ -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<Self>,
id: OrgKdeKwinServerDecorationManagerGlobalId,
client: &Rc<Client>,
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<Client>,
_version: u32,
}
impl OrgKdeKwinServerDecorationManagerObj {
fn default_mode(self: &Rc<Self>, 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<Self>,
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
}
}

View file

@ -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<ClientError>),
}
efrom!(
OrgKdeKwinServerDecorationManagerError,
ClientError,
ClientError
);
#[derive(Debug, Error)]
pub enum CreateError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
ParseError(#[source] Box<MsgParserError>),
}
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<Self, MsgParserError> {
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<OrgKdeKwinServerDecorationManagerObj>,
pub mode: u32,
}
impl EventFormatter for DefaultMode {
fn format(self: Box<Self>, 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)
}
}

View file

@ -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::*;

View file

@ -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<WlDataDeviceManagerObj>, seat: &Rc<WlSeatObj>) -> Self {
pub fn new(
id: WlDataDeviceId,
manager: &Rc<WlDataDeviceManagerObj>,
seat: &Rc<WlSeatObj>,
) -> Self {
Self {
id,
manager: manager.clone(),

View file

@ -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<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetDataDeviceError> {
fn get_data_device(
self: &Rc<Self>,
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));

View file

@ -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() {

View file

@ -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<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlSeatObj>),
where
C: FnMut(&Rc<WlSeatObj>),
{
let bindings = self.bindings.borrow();
if let Some(hm) = bindings.get(&client) {
@ -211,8 +211,8 @@ impl WlSeatGlobal {
}
fn for_each_pointer<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlPointer>),
where
C: FnMut(&Rc<WlPointer>),
{
self.for_each_seat(ver, client, |seat| {
let pointers = seat.pointers.lock();
@ -223,8 +223,8 @@ impl WlSeatGlobal {
}
fn for_each_kb<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlKeyboard>),
where
C: FnMut(&Rc<WlKeyboard>),
{
self.for_each_seat(ver, client, |seat| {
let keyboards = seat.keyboards.lock();
@ -235,8 +235,8 @@ impl WlSeatGlobal {
}
fn for_each_data_device<C>(&self, ver: u32, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlDataDevice>),
where
C: FnMut(&Rc<WlDataDevice>),
{
let dd = self.data_devices.borrow_mut();
if let Some(dd) = dd.get(&client) {
@ -253,8 +253,8 @@ impl WlSeatGlobal {
}
fn surface_pointer_event<F>(&self, ver: u32, surface: &WlSurface, mut f: F)
where
F: FnMut(&Rc<WlPointer>) -> DynEventFormatter,
where
F: FnMut(&Rc<WlPointer>) -> DynEventFormatter,
{
let client = &surface.client;
self.for_each_pointer(ver, client.id, |p| {
@ -264,8 +264,8 @@ impl WlSeatGlobal {
}
fn surface_kb_event<F>(&self, ver: u32, surface: &WlSurface, mut f: F)
where
F: FnMut(&Rc<WlKeyboard>) -> DynEventFormatter,
where
F: FnMut(&Rc<WlKeyboard>) -> DynEventFormatter,
{
let client = &surface.client;
self.for_each_kb(ver, client.id, |p| {
@ -275,8 +275,8 @@ impl WlSeatGlobal {
}
fn surface_data_device_event<F>(&self, ver: u32, surface: &WlSurface, mut f: F)
where
F: FnMut(&Rc<WlDataDevice>) -> DynEventFormatter,
where
F: FnMut(&Rc<WlDataDevice>) -> 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<ModifierState>) {
pub fn key_surface(
&self,
surface: &WlSurface,
key: u32,
state: u32,
mods: Option<ModifierState>,
) {
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);

View file

@ -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<State>,
@ -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<WlDataDevice>) {
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) {

View file

@ -160,7 +160,7 @@ impl WlPointer {
_ => {
// cannot happen
return Ok(());
},
}
};
if pointer_node.client_id() != Some(self.seat.client.id) {
return Ok(());

View file

@ -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<WlSeatGlobal>,
@ -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();
}

View file

@ -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<Self>, seat: &Rc<WlSeatGlobal>) -> Result<Rc<CursorSurface>, WlSurfaceError> {
pub fn get_cursor(
self: &Rc<Self>,
seat: &Rc<WlSeatGlobal>,
) -> Result<Rc<CursorSurface>, WlSurfaceError> {
if let Some(cursor) = self.cursors.get(&seat.id()) {
return Ok(cursor);
}

View file

@ -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 {

View file

@ -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<WlSurface> {
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,
}
}

View file

@ -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;

View file

@ -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 {

View file

@ -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<XdgSurface>,
@ -82,6 +89,7 @@ pub struct XdgToplevel {
states: RefCell<AHashSet<u32>>,
pub toplevel_history: SmallMap<SeatId, LinkedNode<Rc<XdgToplevel>>, 1>,
active_surfaces: NumCell<u32>,
pub decoration: Cell<Decoration>,
}
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<Self>) {
@ -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));
}
}
}

View file

@ -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<Self>,
id: ZxdgDecorationManagerV1Id,
client: &Rc<Client>,
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<Client>,
_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<Self>,
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
}
}

View file

@ -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<ClientError>),
}
efrom!(ZxdgDecorationManagerV1Error, ClientError);
#[derive(Debug, Error)]
pub enum DestroyError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(DestroyError, ClientError);
efrom!(DestroyError, MsgParserError);
#[derive(Debug, Error)]
pub enum GetToplevelDecorationError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(GetToplevelDecorationError, ClientError);
efrom!(GetToplevelDecorationError, MsgParserError);
pub(super) struct Destroy;
impl RequestParser<'_> for Destroy {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
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<Self, MsgParserError> {
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
)
}
}

View file

@ -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<Client>,
pub toplevel: Rc<XdgToplevel>,
}
impl ZxdgToplevelDecorationV1 {
pub fn new(
id: ZxdgToplevelDecorationV1Id,
client: &Rc<Client>,
toplevel: &Rc<XdgToplevel>,
) -> Self {
Self {
id,
client: client.clone(),
toplevel: toplevel.clone(),
}
}
fn configure(self: &Rc<Self>, mode: u32) -> DynEventFormatter {
Box::new(Configure {
obj: self.clone(),
mode,
})
}
pub fn send_configure(self: &Rc<Self>) {
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<Self>, parser: MsgParser<'_, '_>) -> Result<(), SetModeError> {
let _req: SetMode = self.client.parse(&**self, parser)?;
self.send_configure();
Ok(())
}
fn unset_mode(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), UnsetModeError> {
let _req: UnsetMode = self.client.parse(&**self, parser)?;
self.send_configure();
Ok(())
}
fn handle_request_(
self: &Rc<Self>,
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
}
}

View file

@ -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<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(DestroyError, ClientError);
efrom!(DestroyError, MsgParserError);
#[derive(Debug, Error)]
pub enum SetModeError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
}
efrom!(SetModeError, MsgParserError);
#[derive(Debug, Error)]
pub enum UnsetModeError {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
}
efrom!(UnsetModeError, MsgParserError);
pub(super) struct Destroy;
impl RequestParser<'_> for Destroy {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
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<Self, MsgParserError> {
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<Self, MsgParserError> {
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<ZxdgToplevelDecorationV1>,
pub mode: u32,
}
impl EventFormatter for Configure {
fn format(self: Box<Self>, 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)
}
}

View file

@ -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,

View file

@ -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",
}
}
}

View file

@ -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();

View file

@ -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<RenderContext>,

View file

@ -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 _);

View file

@ -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 {

View file

@ -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<WorkspaceNode>, parent: Rc<dyn Node>, child: Rc<dyn Node>) -> Self {
pub fn new(
state: &State,
workspace: &Rc<WorkspaceNode>,
parent: Rc<dyn Node>,
child: Rc<dyn Node>,
) -> 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<ContainerChild>| {
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);
}
};

View file

@ -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());
}
}

View file

@ -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);

View file

@ -22,9 +22,7 @@ impl<T: UnsafeCellCloneSafe> CloneCell<T> {
#[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)]

View file

@ -11,7 +11,7 @@ pub struct SmallMap<K, V, const N: usize> {
impl<K, V, const N: usize> Default for SmallMap<K, V, N> {
fn default() -> Self {
Self {
m: Default::default()
m: Default::default(),
}
}
}
@ -24,9 +24,7 @@ impl<K: Eq, V, const N: usize> SmallMap<K, V, N> {
}
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<V> {
@ -55,15 +53,11 @@ impl<K: Eq, V, const N: usize> SmallMap<K, V, N> {
}
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 }
}
}