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

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