1
0
Fork 0
forked from wry/wry

autocommit 2022-01-08 16:57:40 CET

This commit is contained in:
Julian Orth 2022-01-08 16:57:40 +01:00
parent f8e7557d1d
commit 33549184d4
42 changed files with 2072 additions and 190 deletions

View file

@ -1,6 +1,9 @@
pub mod wl_buffer;
pub mod wl_callback;
pub mod wl_compositor;
pub mod wl_data_device;
pub mod wl_data_device_manager;
pub mod wl_data_source;
pub mod wl_display;
pub mod wl_output;
pub mod wl_region;
@ -12,3 +15,4 @@ pub mod wl_subcompositor;
pub mod wl_surface;
pub mod xdg_positioner;
pub mod xdg_wm_base;
pub mod wl_data_offer;

View file

@ -83,6 +83,10 @@ impl Global for WlCompositorGlobal {
self.name
}
fn singleton(&self) -> bool {
true
}
fn interface(&self) -> Interface {
Interface::WlCompositor
}

View file

@ -0,0 +1,82 @@
mod types;
use crate::client::{AddObj, Client};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
const START_DRAG: u32 = 0;
const SET_SELECTION: u32 = 1;
const RELEASE: u32 = 2;
const DATA_OFFER: u32 = 0;
const ENTER: u32 = 1;
const LEAVE: u32 = 2;
const MOTION: u32 = 4;
const DROP: u32 = 5;
const SELECTION: u32 = 5;
const ROLE: u32 = 0;
id!(WlDataDeviceId);
pub struct WlDataDevice {
id: WlDataDeviceId,
client: Rc<Client>,
}
impl WlDataDevice {
pub fn new(id: WlDataDeviceId, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
}
}
async fn start_drag(&self, parser: MsgParser<'_, '_>) -> Result<(), StartDragError> {
let _req: StartDrag = self.client.parse(self, parser)?;
Ok(())
}
async fn set_selection(&self, parser: MsgParser<'_, '_>) -> Result<(), SetSelectionError> {
let _req: SetSelection = self.client.parse(self, parser)?;
Ok(())
}
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.client.parse(self, parser)?;
self.client.remove_obj(self).await?;
Ok(())
}
async fn handle_request_(
self: &Rc<Self>,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlDataDeviceError> {
match request {
START_DRAG => self.start_drag(parser).await?,
SET_SELECTION => self.set_selection(parser).await?,
RELEASE => self.release(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(WlDataDevice);
impl Object for WlDataDevice {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlDataDevice
}
fn num_requests(&self) -> u32 {
RELEASE + 1
}
}

View file

@ -0,0 +1,242 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::fixed::Fixed;
use crate::ifs::wl_data_device::{WlDataDevice, DATA_OFFER, DROP, ENTER, LEAVE, MOTION, SELECTION};
use crate::ifs::wl_data_source::WlDataSourceId;
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;
use crate::ifs::wl_data_offer::WlDataOfferId;
#[derive(Debug, Error)]
pub enum WlDataDeviceError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Could not process `start_drag` request")]
StartDragError(#[from] StartDragError),
#[error("Could not process `set_selection` request")]
SetSelectionError(#[from] SetSelectionError),
#[error("Could not process `release` request")]
ReleaseError(#[from] ReleaseError),
}
efrom!(WlDataDeviceError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum StartDragError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(StartDragError, ParseFailed, MsgParserError);
efrom!(StartDragError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum SetSelectionError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(SetSelectionError, ParseFailed, MsgParserError);
efrom!(SetSelectionError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum ReleaseError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(ReleaseError, ParseFailed, MsgParserError);
efrom!(ReleaseError, ClientError, ClientError);
pub(super) struct StartDrag {
pub source: WlDataSourceId,
pub origin: WlSurfaceId,
pub icon: WlSurfaceId,
pub serial: u32,
}
impl RequestParser<'_> for StartDrag {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
source: parser.object()?,
origin: parser.object()?,
icon: parser.object()?,
serial: parser.uint()?,
})
}
}
impl Debug for StartDrag {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"start_drag(source: {}, origin: {}, icon: {}, serial: {})",
self.source, self.origin, self.icon, self.serial
)
}
}
pub(super) struct SetSelection {
pub source: WlDataSourceId,
pub serial: u32,
}
impl RequestParser<'_> for SetSelection {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
source: parser.object()?,
serial: parser.uint()?,
})
}
}
impl Debug for SetSelection {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"set_selection(source: {}, serial: {})",
self.source, self.serial,
)
}
}
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 DataOffer {
pub obj: Rc<WlDataDevice>,
pub id: WlDataOfferId,
}
impl EventFormatter for DataOffer {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, DATA_OFFER).object(self.id);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for DataOffer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "data_offer(id: {})", self.id)
}
}
pub(super) struct Enter {
pub obj: Rc<WlDataDevice>,
pub serial: u32,
pub surface: WlSurfaceId,
pub x: Fixed,
pub y: Fixed,
pub id: WlDataOfferId,
}
impl EventFormatter for Enter {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, ENTER)
.uint(self.serial)
.object(self.surface)
.fixed(self.x)
.fixed(self.y)
.object(self.id);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Enter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"enter(serial: {}, surface: {}, x: {}, y: {}, id: {})",
self.serial, self.surface, self.x, self.y, self.id
)
}
}
pub(super) struct Leave {
pub obj: Rc<WlDataDevice>,
}
impl EventFormatter for Leave {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, LEAVE);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Leave {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "leave()")
}
}
pub(super) struct Motion {
pub obj: Rc<WlDataDevice>,
pub time: u32,
pub x: Fixed,
pub y: Fixed,
}
impl EventFormatter for Motion {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, MOTION)
.uint(self.time)
.fixed(self.x)
.fixed(self.y);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Motion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"motion(time: {}, x: {}, y: {})",
self.time, self.x, self.y
)
}
}
pub(super) struct Drop {
pub obj: Rc<WlDataDevice>,
}
impl EventFormatter for Drop {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, DROP);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Drop {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "drop()")
}
}
pub(super) struct Selection {
pub obj: Rc<WlDataDevice>,
pub id: WlDataOfferId,
}
impl EventFormatter for Selection {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, SELECTION).object(self.id);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Selection {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "selection(id: {})", self.id)
}
}

View file

@ -0,0 +1,121 @@
mod types;
use crate::client::{AddObj, Client};
use crate::globals::{Global, GlobalName};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
use crate::ifs::wl_data_device::WlDataDevice;
use crate::ifs::wl_data_source::WlDataSource;
const CREATE_DATA_SOURCE: u32 = 0;
const GET_DATA_DEVICE: u32 = 1;
const DND_NONE: u32 = 0;
const DND_COPY: u32 = 1;
const DND_MOVE: u32 = 2;
const DND_ASK: u32 = 4;
id!(WlDataDeviceManagerId);
pub struct WlDataDeviceManagerGlobal {
name: GlobalName,
}
pub struct WlDataDeviceManagerObj {
id: WlDataDeviceManagerId,
client: Rc<Client>,
}
impl WlDataDeviceManagerGlobal {
pub fn new(name: GlobalName) -> Self {
Self { name }
}
async fn bind_(
self: Rc<Self>,
id: WlDataDeviceManagerId,
client: &Rc<Client>,
_version: u32,
) -> Result<(), WlDataDeviceManagerError> {
let obj = Rc::new(WlDataDeviceManagerObj {
id,
client: client.clone(),
});
client.add_client_obj(&obj)?;
Ok(())
}
}
impl WlDataDeviceManagerObj {
async fn create_data_source(
&self,
parser: MsgParser<'_, '_>,
) -> Result<(), CreateDataSourceError> {
let req: CreateDataSource = self.client.parse(self, parser)?;
let res = Rc::new(WlDataSource::new(req.id, &self.client));
self.client.add_client_obj(&res)?;
Ok(())
}
async fn get_data_device(&self, parser: MsgParser<'_, '_>) -> Result<(), GetDataDeviceError> {
let req: GetDataDevice = self.client.parse(self, parser)?;
let res = Rc::new(WlDataDevice::new(req.id, &self.client));
self.client.add_client_obj(&res)?;
Ok(())
}
async fn handle_request_(
self: &Rc<Self>,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlDataDeviceManagerError> {
match request {
CREATE_DATA_SOURCE => self.create_data_source(parser).await?,
GET_DATA_DEVICE => self.get_data_device(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
bind!(WlDataDeviceManagerGlobal);
impl Global for WlDataDeviceManagerGlobal {
fn name(&self) -> GlobalName {
self.name
}
fn singleton(&self) -> bool {
true
}
fn interface(&self) -> Interface {
Interface::WlDataDeviceManager
}
fn version(&self) -> u32 {
3
}
fn pre_remove(&self) {
unreachable!()
}
}
handle_request!(WlDataDeviceManagerObj);
impl Object for WlDataDeviceManagerObj {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlDataDeviceManager
}
fn num_requests(&self) -> u32 {
GET_DATA_DEVICE + 1
}
}

View file

@ -0,0 +1,72 @@
use crate::client::{ClientError, RequestParser};
use crate::ifs::wl_data_source::WlDataSourceId;
use crate::ifs::wl_seat::WlSeatId;
use crate::utils::buffd::{MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use thiserror::Error;
use crate::ifs::wl_data_device::WlDataDeviceId;
#[derive(Debug, Error)]
pub enum WlDataDeviceManagerError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Could not process `create_data_source` request")]
CreateDataSourceError(#[from] CreateDataSourceError),
#[error("Could not process `get_data_device` request")]
GetDataDeviceError(#[from] GetDataDeviceError),
}
efrom!(WlDataDeviceManagerError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum CreateDataSourceError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(CreateDataSourceError, ParseFailed, MsgParserError);
efrom!(CreateDataSourceError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum GetDataDeviceError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(GetDataDeviceError, ParseFailed, MsgParserError);
efrom!(GetDataDeviceError, ClientError, ClientError);
pub(super) struct CreateDataSource {
pub id: WlDataSourceId,
}
impl RequestParser<'_> for CreateDataSource {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
id: parser.object()?,
})
}
}
impl Debug for CreateDataSource {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "create_data_source(id: {})", self.id)
}
}
pub(super) struct GetDataDevice {
pub id: WlDataDeviceId,
pub seat: WlSeatId,
}
impl RequestParser<'_> for GetDataDevice {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
id: parser.object()?,
seat: parser.object()?,
})
}
}
impl Debug for GetDataDevice {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "get_data_device(id: {}, seat: {})", self.id, self.seat,)
}
}

View file

@ -0,0 +1,89 @@
mod types;
use crate::client::{AddObj, Client};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
const ACCEPT: u32 = 0;
const RECEIVE: u32 = 1;
const DESTROY: u32 = 2;
const FINISH: u32 = 3;
const SET_ACTIONS: u32 = 4;
const OFFER: u32 = 0;
const SOURCE_ACTIONS: u32 = 1;
const ACTION: u32 = 2;
const INVALID_FINISH: u32 = 0;
const INVALID_ACTION_MASK: u32 = 1;
const INVALID_ACTION: u32 = 2;
const INVALID_OFFER: u32 = 3;
id!(WlDataOfferId);
pub struct WlDataOffer {
id: WlDataOfferId,
client: Rc<Client>,
}
impl WlDataOffer {
async fn accept(&self, parser: MsgParser<'_, '_>) -> Result<(), AcceptError> {
let _req: Accept = self.client.parse(self, parser)?;
Ok(())
}
async fn receive(&self, parser: MsgParser<'_, '_>) -> Result<(), ReceiveError> {
let _req: Receive = self.client.parse(self, parser)?;
Ok(())
}
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.client.parse(self, parser)?;
self.client.remove_obj(self).await?;
Ok(())
}
async fn finish(&self, parser: MsgParser<'_, '_>) -> Result<(), FinishError> {
let _req: Finish = self.client.parse(self, parser)?;
Ok(())
}
async fn set_actions(&self, parser: MsgParser<'_, '_>) -> Result<(), SetActionsError> {
let _req: SetActions = self.client.parse(self, parser)?;
Ok(())
}
async fn handle_request_(
self: &Rc<Self>,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlDataOfferError> {
match request {
ACCEPT => self.accept(parser).await?,
RECEIVE => self.receive(parser).await?,
DESTROY => self.destroy(parser).await?,
FINISH => self.finish(parser).await?,
SET_ACTIONS => self.set_actions(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(WlDataOffer);
impl Object for WlDataOffer {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlDataSource
}
fn num_requests(&self) -> u32 {
SET_ACTIONS + 1
}
}

View file

@ -0,0 +1,218 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use bstr::{BStr, BString};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
use uapi::OwnedFd;
use crate::ifs::wl_data_offer::{ACTION, OFFER, SOURCE_ACTIONS, WlDataOffer};
#[derive(Debug, Error)]
pub enum WlDataOfferError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Could not process `accept` request")]
AcceptError(#[from] AcceptError),
#[error("Could not process `receive` request")]
ReceiveError(#[from] ReceiveError),
#[error("Could not process `destroy` request")]
DestroyError(#[from] DestroyError),
#[error("Could not process `finish` request")]
FinishError(#[from] FinishError),
#[error("Could not process `set_actions` request")]
SetActionsError(#[from] SetActionsError),
}
efrom!(WlDataOfferError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum AcceptError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(AcceptError, ParseFailed, MsgParserError);
efrom!(AcceptError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum ReceiveError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(ReceiveError, ParseFailed, MsgParserError);
efrom!(ReceiveError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum DestroyError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(DestroyError, ParseFailed, MsgParserError);
efrom!(DestroyError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum FinishError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(FinishError, ParseFailed, MsgParserError);
efrom!(FinishError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum SetActionsError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(SetActionsError, ParseFailed, MsgParserError);
efrom!(SetActionsError, ClientError, ClientError);
pub(super) struct Accept<'a> {
pub serial: u32,
pub mime_type: &'a BStr,
}
impl<'a> RequestParser<'a> for Accept<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self {
serial: parser.uint()?,
mime_type: parser.string()?,
})
}
}
impl Debug for Accept<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "accept(serial: {}, mime_type: {:?})", self.serial, self.mime_type)
}
}
pub(super) struct Receive<'a> {
pub mime_type: &'a BStr,
pub fd: OwnedFd,
}
impl<'a> RequestParser<'a> for Receive<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self {
mime_type: parser.string()?,
fd: parser.fd()?,
})
}
}
impl Debug for Receive<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "receive(mime_type: {:?}, fd: {})", self.mime_type, self.fd.raw())
}
}
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 Finish;
impl RequestParser<'_> for Finish {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
}
}
impl Debug for Finish {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "finish()")
}
}
pub(super) struct SetActions {
pub dnd_actions: u32,
pub preferred_action: u32,
}
impl<'a> RequestParser<'a> for SetActions {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self {
dnd_actions: parser.uint()?,
preferred_action: parser.uint()?,
})
}
}
impl Debug for SetActions {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "set_actions(dnd_actions: {}, preferred_action: {})", self.dnd_actions, self.preferred_action)
}
}
pub(super) struct Offer {
pub obj: Rc<WlDataOffer>,
pub mime_type: BString,
}
impl EventFormatter for Offer {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, OFFER).string(&self.mime_type);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Offer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "target(mime_type: {:?})", self.mime_type)
}
}
pub(super) struct SourceActions {
pub obj: Rc<WlDataOffer>,
pub source_actions: u32,
}
impl EventFormatter for SourceActions {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, SOURCE_ACTIONS)
.uint(self.source_actions);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for SourceActions {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"source_actions(source_actions: {})",
self.source_actions,
)
}
}
pub(super) struct Action {
pub obj: Rc<WlDataOffer>,
pub dnd_action: u32,
}
impl EventFormatter for Action {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, ACTION)
.uint(self.dnd_action);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Action {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"action(dnd_action: {})",
self.dnd_action,
)
}
}

View file

@ -0,0 +1,83 @@
mod types;
use crate::client::{AddObj, Client};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
const OFFER: u32 = 0;
const DESTROY: u32 = 1;
const SET_ACTIONS: u32 = 2;
const TARGET: u32 = 0;
const SEND: u32 = 1;
const CANCELLED: u32 = 2;
const DND_DROP_PERFORMED: u32 = 4;
const DND_FINISHED: u32 = 5;
const ACTION: u32 = 5;
const INVALID_ACTION_MASK: u32 = 0;
const INVALID_SOURCE: u32 = 1;
id!(WlDataSourceId);
pub struct WlDataSource {
id: WlDataSourceId,
client: Rc<Client>,
}
impl WlDataSource {
pub fn new(id: WlDataSourceId, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
}
}
async fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), OfferError> {
let _req: Offer = self.client.parse(self, parser)?;
Ok(())
}
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.client.parse(self, parser)?;
self.client.remove_obj(self).await?;
Ok(())
}
async fn set_actions(&self, parser: MsgParser<'_, '_>) -> Result<(), SetActionsError> {
let _req: SetActions = self.client.parse(self, parser)?;
Ok(())
}
async fn handle_request_(
self: &Rc<Self>,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlDataSourceError> {
match request {
OFFER => self.offer(parser).await?,
DESTROY => self.destroy(parser).await?,
SET_ACTIONS => self.set_actions(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(WlDataSource);
impl Object for WlDataSource {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlDataSource
}
fn num_requests(&self) -> u32 {
SET_ACTIONS + 1
}
}

View file

@ -0,0 +1,211 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_data_source::{
WlDataSource, ACTION, CANCELLED, DND_DROP_PERFORMED, DND_FINISHED, SEND, TARGET,
};
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use bstr::{BStr, BString};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
use uapi::OwnedFd;
#[derive(Debug, Error)]
pub enum WlDataSourceError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Could not process `offer` request")]
OfferError(#[from] OfferError),
#[error("Could not process `destroy` request")]
DestroyError(#[from] DestroyError),
#[error("Could not process `set_actions` request")]
SetActionsError(#[from] SetActionsError),
}
efrom!(WlDataSourceError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum OfferError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(OfferError, ParseFailed, MsgParserError);
efrom!(OfferError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum DestroyError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(DestroyError, ParseFailed, MsgParserError);
efrom!(DestroyError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum SetActionsError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(SetActionsError, ParseFailed, MsgParserError);
efrom!(SetActionsError, ClientError, ClientError);
pub(super) struct Offer<'a> {
pub mime_type: &'a BStr,
}
impl<'a> RequestParser<'a> for Offer<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self {
mime_type: parser.string()?,
})
}
}
impl Debug for Offer<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "offer(mime_type: {:?})", self.mime_type)
}
}
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 SetActions {
pub actions: u32,
}
impl RequestParser<'_> for SetActions {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
actions: parser.uint()?,
})
}
}
impl Debug for SetActions {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "set_actions(actions: {})", self.actions)
}
}
pub(super) struct Target {
pub obj: Rc<WlDataSource>,
pub mime_type: BString,
}
impl EventFormatter for Target {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, TARGET).string(&self.mime_type);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Target {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "target(mime_type: {:?})", self.mime_type)
}
}
pub(super) struct Send {
pub obj: Rc<WlDataSource>,
pub mime_type: BString,
pub fd: Rc<OwnedFd>,
}
impl EventFormatter for Send {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, SEND)
.string(&self.mime_type)
.fd(self.fd);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Send {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"send(mime_type: {:?}, fd: {})",
self.mime_type,
self.fd.raw()
)
}
}
pub(super) struct Cancelled {
pub obj: Rc<WlDataSource>,
}
impl EventFormatter for Cancelled {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, CANCELLED);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Cancelled {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "cancelled()")
}
}
pub(super) struct DndDropPerformed {
pub obj: Rc<WlDataSource>,
}
impl EventFormatter for DndDropPerformed {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, DND_DROP_PERFORMED);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for DndDropPerformed {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "dnd_drop_performed()")
}
}
pub(super) struct DndFinished {
pub obj: Rc<WlDataSource>,
}
impl EventFormatter for DndFinished {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, DND_FINISHED);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for DndFinished {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "dnd_finished()")
}
}
pub(super) struct Action {
pub obj: Rc<WlDataSource>,
pub dnd_action: u32,
}
impl EventFormatter for Action {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, ACTION).uint(self.dnd_action);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Action {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "action(dnd_action: {})", self.dnd_action)
}
}

View file

@ -43,6 +43,8 @@ const MODE_PREFERRED: u32 = 2;
pub struct WlOutputGlobal {
name: GlobalName,
output: Rc<dyn Output>,
pub x: Cell<i32>,
pub y: Cell<i32>,
width: Cell<u32>,
height: Cell<u32>,
bindings: CopyHashMap<(ClientId, WlOutputId), Rc<WlOutputObj>>,
@ -53,6 +55,8 @@ impl WlOutputGlobal {
Self {
name,
output: output.clone(),
x: Cell::new(0),
y: Cell::new(0),
width: Cell::new(output.width()),
height: Cell::new(output.height()),
bindings: Default::default(),
@ -123,6 +127,10 @@ impl Global for WlOutputGlobal {
self.name
}
fn singleton(&self) -> bool {
false
}
fn interface(&self) -> Interface {
Interface::WlOutput
}

View file

@ -3,17 +3,26 @@ pub mod wl_keyboard;
pub mod wl_pointer;
pub mod wl_touch;
use crate::backend::{Seat, SeatEvent};
use crate::backend::{KeyState, OutputId, ScrollAxis, Seat, SeatEvent};
use crate::client::{AddObj, Client, ClientId, DynEventFormatter};
use crate::fixed::Fixed;
use crate::globals::{Global, GlobalName};
use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardId};
use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerId};
use crate::ifs::wl_seat::wl_touch::WlTouch;
use crate::object::{Interface, Object, ObjectId};
use crate::tree::{Node, NodeBase, NodeKind, ToplevelNode};
use crate::utils::buffd::MsgParser;
use crate::utils::copyhashmap::CopyHashMap;
use crate::xkbcommon::XkbContext;
use crate::State;
use ahash::AHashMap;
use bstr::ByteSlice;
use std::cell::{Cell, RefCell};
use std::io::Write;
use std::rc::Rc;
pub use types::*;
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 uapi::{c, OwnedFd};
id!(WlSeatId);
@ -33,23 +42,183 @@ const MISSING_CAPABILITY: u32 = 0;
pub struct WlSeatGlobal {
name: GlobalName,
state: Rc<State>,
seat: Rc<dyn Seat>,
bindings: CopyHashMap<(ClientId, WlSeatId), Rc<WlSeatObj>>,
move_: Cell<bool>,
move_start_pos: Cell<(Fixed, Fixed)>,
extents_start_pos: Cell<(i32, i32)>,
pos: Cell<(Fixed, Fixed)>,
cursor_node: RefCell<Rc<dyn Node>>,
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeatObj>>>>,
layout: Rc<OwnedFd>,
layout_size: u32,
}
impl WlSeatGlobal {
pub fn new(name: GlobalName, seat: &Rc<dyn Seat>) -> Self {
pub fn new(name: GlobalName, state: &Rc<State>, seat: &Rc<dyn Seat>) -> Self {
let (layout, layout_size) = {
let ctx = XkbContext::new().unwrap();
let keymap = ctx.default_keymap().unwrap();
let string = keymap.as_str().unwrap();
let mut memfd =
uapi::memfd_create("keymap", c::MFD_CLOEXEC | c::MFD_ALLOW_SEALING).unwrap();
memfd.write_all(string.as_bytes()).unwrap();
memfd.write_all(&[0]).unwrap();
uapi::lseek(memfd.raw(), 0, c::SEEK_SET).unwrap();
uapi::fcntl_add_seals(
memfd.raw(),
c::F_SEAL_SEAL | c::F_SEAL_GROW | c::F_SEAL_SHRINK | c::F_SEAL_WRITE,
)
.unwrap();
(Rc::new(memfd), (string.len() + 1) as _)
};
Self {
name,
state: state.clone(),
seat: seat.clone(),
move_: Cell::new(false),
move_start_pos: Cell::new((Fixed(0), Fixed(0))),
extents_start_pos: Cell::new((0, 0)),
pos: Cell::new((Fixed(0), Fixed(0))),
cursor_node: RefCell::new(state.root.clone()),
bindings: Default::default(),
layout,
layout_size,
}
}
pub fn move_(&self, node: &Rc<ToplevelNode>) {
let cursor = self.cursor_node.borrow().clone();
if cursor.id() == node.id() {
self.move_.set(true);
self.move_start_pos.set(self.pos.get());
let ex = node.common.extents.get();
self.extents_start_pos.set((ex.x, ex.y));
}
}
pub async fn event(&self, event: SeatEvent) {
log::debug!("se: {:?}", event);
match event {
SeatEvent::OutputPosition(o, x, y) => self.output_position_event(o, x, y).await,
SeatEvent::Motion(dx, dy) => self.motion_event(dx, dy).await,
SeatEvent::Button(b, s) => self.button_event(b, s).await,
SeatEvent::Scroll(d, a) => self.scroll_event(d, a).await,
SeatEvent::Key(k, s) => self.key_event(k, s).await,
}
}
async fn output_position_event(&self, output: OutputId, mut x: Fixed, mut y: Fixed) {
let output = match self.state.outputs.get(&output) {
Some(o) => o,
_ => return,
};
x += Fixed::from_int(output.x.get());
y += Fixed::from_int(output.y.get());
self.handle_new_position(x, y).await;
}
fn for_each_pointer<C>(&self, client: ClientId, mut f: C)
where
C: FnMut(&Rc<WlPointer>),
{
let bindings = self.bindings.borrow();
if let Some(hm) = bindings.get(&client) {
for seat in hm.values() {
let pointers = seat.pointers.lock();
for pointer in pointers.values() {
f(pointer);
}
}
}
}
async fn tl_pointer_event<F>(&self, tl: &ToplevelNode, mut f: F)
where
F: FnMut(&Rc<WlPointer>) -> DynEventFormatter,
{
let client = &tl.surface.surface.surface.client;
self.for_each_pointer(client.id, |p| {
client.event_locked(f(p));
});
let _ = client.flush().await;
}
async fn handle_new_position(&self, x: Fixed, y: Fixed) {
self.pos.set((x, y));
let cur_node = self.cursor_node.borrow().clone();
if self.move_.get() {
if let NodeKind::Toplevel(tn) = cur_node.into_kind() {
let (move_start_x, move_start_y) = self.move_start_pos.get();
let (move_start_ex, move_start_ey) = self.extents_start_pos.get();
let mut ex = tn.common.extents.get();
ex.x = (x - move_start_x).round_down() + move_start_ex;
ex.y = (y - move_start_y).round_down() + move_start_ey;
tn.common.extents.set(ex);
}
return;
}
let x_int = x.round_down();
let y_int = y.round_down();
let (node_dyn, x_int, y_int) = self.state.root.clone().find_node_at(x_int, y_int);
let mut x = x.apply_fract(x_int);
let mut y = x.apply_fract(y_int);
let node = node_dyn.clone().into_kind();
let mut enter = false;
if node_dyn.id() != cur_node.id() {
if let NodeKind::Toplevel(tl) = cur_node.into_kind() {
self.tl_pointer_event(&tl, |p| p.leave(0, tl.surface.surface.surface.id))
.await;
}
enter = true;
*self.cursor_node.borrow_mut() = node_dyn;
}
if let NodeKind::Toplevel(tl) = &node {
let ee = tl.surface.surface.surface.effective_extents.get();
// log::trace!("{} {}", Fixed::from_int(ee.x1), Fixed::from_int(ee.y1));
x += Fixed::from_int(ee.x1);
y += Fixed::from_int(ee.y1);
if enter {
self.tl_pointer_event(&tl, |p| p.enter(0, tl.surface.surface.surface.id, x, y))
.await;
}
self.tl_pointer_event(&tl, |p| p.motion(0, x, y)).await;
}
}
async fn motion_event(&self, dx: Fixed, dy: Fixed) {
let (x, y) = self.pos.get();
self.handle_new_position(x + dx, y + dy).await;
}
async fn button_event(&self, button: u32, state: KeyState) {
if state == KeyState::Released {
self.move_.set(false);
}
let node = self.cursor_node.borrow().clone().into_kind();
if let NodeKind::Toplevel(node) = node {
let state = match state {
KeyState::Released => wl_pointer::RELEASED,
KeyState::Pressed => wl_pointer::PRESSED,
};
self.tl_pointer_event(&node, |p| p.button(0, 0, button, state))
.await;
}
}
async fn scroll_event(&self, delta: i32, axis: ScrollAxis) {
let node = self.cursor_node.borrow().clone().into_kind();
if let NodeKind::Toplevel(node) = node {
let axis = match axis {
ScrollAxis::Horizontal => wl_pointer::HORIZONTAL_SCROLL,
ScrollAxis::Vertical => wl_pointer::VERTICAL_SCROLL,
};
self.tl_pointer_event(&node, |p| p.axis(0, axis, Fixed::from_int(delta)))
.await;
}
}
async fn key_event(&self, key: u32, state: KeyState) {}
async fn bind_(
self: Rc<Self>,
id: WlSeatId,
@ -60,10 +229,18 @@ impl WlSeatGlobal {
global: self.clone(),
id,
client: client.clone(),
pointers: Default::default(),
keyboards: Default::default(),
});
client.add_client_obj(&obj)?;
client.event(obj.capabilities()).await?;
self.bindings.set((client.id, id), obj.clone());
{
let mut bindings = self.bindings.borrow_mut();
let bindings = bindings
.entry(client.id)
.or_insert_with(|| Default::default());
bindings.insert(id, obj.clone());
}
Ok(())
}
}
@ -75,6 +252,10 @@ impl Global for WlSeatGlobal {
self.name
}
fn singleton(&self) -> bool {
false
}
fn interface(&self) -> Interface {
Interface::WlSeat
}
@ -88,7 +269,7 @@ impl Global for WlSeatGlobal {
}
fn break_loops(&self) {
self.bindings.clear();
self.bindings.borrow_mut().clear();
}
}
@ -96,6 +277,8 @@ pub struct WlSeatObj {
global: Rc<WlSeatGlobal>,
id: WlSeatId,
client: Rc<Client>,
pointers: CopyHashMap<WlPointerId, Rc<WlPointer>>,
keyboards: CopyHashMap<WlKeyboardId, Rc<WlKeyboard>>,
}
impl WlSeatObj {
@ -106,17 +289,36 @@ impl WlSeatObj {
})
}
async fn get_pointer(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPointerError> {
pub fn move_(&self, node: &Rc<ToplevelNode>) {
self.global.move_(node);
}
async fn get_pointer(
self: &Rc<Self>,
parser: MsgParser<'_, '_>,
) -> Result<(), GetPointerError> {
let req: GetPointer = self.client.parse(&**self, parser)?;
let p = Rc::new(WlPointer::new(req.id, self));
self.client.add_client_obj(&p)?;
self.pointers.set(req.id, p);
Ok(())
}
async fn get_keyboard(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetKeyboardError> {
async fn get_keyboard(
self: &Rc<Self>,
parser: MsgParser<'_, '_>,
) -> Result<(), GetKeyboardError> {
let req: GetKeyboard = self.client.parse(&**self, parser)?;
let p = Rc::new(WlKeyboard::new(req.id, self));
self.client.add_client_obj(&p)?;
self.keyboards.set(req.id, p.clone());
self.client
.event(p.keymap(
wl_keyboard::XKB_V1,
self.global.layout.clone(),
self.global.layout_size,
))
.await?;
Ok(())
}
@ -129,7 +331,12 @@ impl WlSeatObj {
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.client.parse(self, parser)?;
self.global.bindings.remove(&(self.client.id, self.id));
{
let mut bindings = self.global.bindings.borrow_mut();
if let Some(hm) = bindings.get_mut(&self.client.id) {
hm.remove(&self.id);
}
}
self.client.remove_obj(self).await?;
Ok(())
}
@ -166,6 +373,13 @@ impl Object for WlSeatObj {
}
fn break_loops(&self) {
self.global.bindings.remove(&(self.client.id, self.id));
{
let mut bindings = self.global.bindings.borrow_mut();
if let Some(hm) = bindings.get_mut(&self.client.id) {
hm.remove(&self.id);
}
}
self.pointers.clear();
self.keyboards.clear();
}
}

View file

@ -1,4 +1,6 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_seat::wl_keyboard::WlKeyboardId;
use crate::ifs::wl_seat::wl_pointer::WlPointerId;
use crate::ifs::wl_seat::wl_touch::WlTouchId;
use crate::ifs::wl_seat::{WlSeatObj, CAPABILITIES, NAME};
use crate::object::Object;
@ -6,8 +8,6 @@ use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
use crate::ifs::wl_seat::wl_keyboard::WlKeyboardId;
use crate::ifs::wl_seat::wl_pointer::WlPointerId;
#[derive(Debug, Error)]
pub enum WlSeatError {

View file

@ -19,7 +19,7 @@ const MODIFIERS: u32 = 4;
const REPEAT_INFO: u32 = 5;
const NO_KEYMAP: u32 = 0;
const XKB_V1: u32 = 1;
pub(super) const XKB_V1: u32 = 1;
const RELEASED: u32 = 0;
const PRESSED: u32 = 1;
@ -108,6 +108,7 @@ impl WlKeyboard {
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.seat.client.parse(self, parser)?;
self.seat.keyboards.remove(&self.id);
self.seat.client.remove_obj(self).await?;
Ok(())
}

View file

@ -24,11 +24,11 @@ const AXIS_DISCRETE: u32 = 8;
const ROLE: u32 = 0;
const RELEASED: u32 = 0;
const PRESSED: u32 = 1;
pub(super) const RELEASED: u32 = 0;
pub(super) const PRESSED: u32 = 1;
const VERTICAL_SCROLL: u32 = 0;
const HORIZONTAL_SCROLL: u32 = 1;
pub(super) const VERTICAL_SCROLL: u32 = 0;
pub(super) const HORIZONTAL_SCROLL: u32 = 1;
const WHEEL: u32 = 0;
const FINGER: u32 = 1;
@ -136,13 +136,13 @@ impl WlPointer {
}
async fn set_cursor(&self, parser: MsgParser<'_, '_>) -> Result<(), SetCursorError> {
let _req: Release = self.seat.client.parse(self, parser)?;
self.seat.client.remove_obj(self).await?;
let _req: SetCursor = self.seat.client.parse(self, parser)?;
Ok(())
}
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.seat.client.parse(self, parser)?;
self.seat.pointers.remove(&self.id);
self.seat.client.remove_obj(self).await?;
Ok(())
}
@ -153,6 +153,7 @@ impl WlPointer {
parser: MsgParser<'_, '_>,
) -> Result<(), WlPointerError> {
match request {
SET_CURSOR => self.set_cursor(parser).await?,
RELEASE => self.release(parser).await?,
_ => unreachable!(),
}

View file

@ -184,7 +184,7 @@ impl Debug for Button {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"button(serial: {}, time: {}, button: {}, state: {})",
"button(serial: {}, time: {}, button: 0x{:x}, state: {})",
self.serial, self.time, self.button, self.state
)
}

View file

@ -1,6 +1,6 @@
mod types;
use crate::client::{AddObj};
use crate::client::AddObj;
use crate::ifs::wl_seat::WlSeatObj;
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;

View file

@ -89,6 +89,10 @@ impl Global for WlShmGlobal {
self.name
}
fn singleton(&self) -> bool {
true
}
fn interface(&self) -> Interface {
Interface::WlShm
}

View file

@ -84,6 +84,10 @@ impl Global for WlSubcompositorGlobal {
self.name
}
fn singleton(&self) -> bool {
true
}
fn interface(&self) -> Interface {
Interface::WlSubcompositor
}

View file

@ -60,13 +60,14 @@ impl SurfaceRole {
}
pub struct WlSurface {
id: WlSurfaceId,
pub id: WlSurfaceId,
pub client: Rc<Client>,
role: Cell<SurfaceRole>,
pending: PendingState,
input_region: Cell<Option<Region>>,
opaque_region: Cell<Option<Region>>,
pub extents: Cell<SurfaceExtents>,
pub effective_extents: Cell<SurfaceExtents>,
pub buffer: RefCell<Option<Rc<WlBuffer>>>,
pub children: RefCell<Option<Box<ParentData>>>,
role_data: RefCell<RoleData>,
@ -105,8 +106,15 @@ struct XdgSurfaceData {
requested_serial: u32,
acked_serial: Option<u32>,
role: XdgSurfaceRole,
extents: Option<SurfaceExtents>,
role_data: XdgSurfaceRoleData,
popups: CopyHashMap<WlSurfaceId, Rc<XdgPopup>>,
pending: PendingXdgSurfaceData,
}
#[derive(Default)]
struct PendingXdgSurfaceData {
extents: Cell<Option<SurfaceExtents>>,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -193,6 +201,7 @@ impl WlSurface {
input_region: Cell::new(None),
opaque_region: Cell::new(None),
extents: Default::default(),
effective_extents: Default::default(),
buffer: RefCell::new(None),
children: Default::default(),
role_data: RefCell::new(RoleData::None),
@ -350,7 +359,7 @@ impl WlSurface {
surface: td.toplevel.clone(),
});
td.node = Some(ToplevelNodeHolder { node: node.clone() });
let link = output.floating.append(node.clone());
let link = output.floating.add_last(node.clone());
node.common
.floating_outputs
.borrow_mut()
@ -402,6 +411,8 @@ impl WlSurface {
}
fn do_commit(&self) {
let mut xdg_extents = None;
let mut td_node = None;
{
let mut rd = self.role_data.borrow_mut();
match &mut *rd {
@ -416,7 +427,15 @@ impl WlSurface {
ss.y = y;
}
}
RoleData::XdgSurface(xdg) => {}
RoleData::XdgSurface(xdg) => {
if let Some(extents) = xdg.pending.extents.take() {
xdg.extents = Some(extents);
}
xdg_extents = xdg.extents;
if let XdgSurfaceRoleData::Toplevel(tl) = &xdg.role_data {
td_node = tl.node.as_ref().map(|n| n.node.clone());
}
}
}
}
{
@ -444,6 +463,28 @@ impl WlSurface {
if !committed_any_children {
self.calculate_extents();
}
let mut effective_extents = self.extents.get();
if let Some(extents) = xdg_extents {
effective_extents.x1 = effective_extents.x1.max(extents.x1);
effective_extents.y1 = effective_extents.y1.max(extents.y1);
effective_extents.x2 = effective_extents.x2.min(extents.x2);
effective_extents.y2 = effective_extents.y2.min(extents.y2);
if effective_extents.x1 > effective_extents.x2 {
effective_extents.x1 = 0;
effective_extents.x2 = 0;
}
if effective_extents.y1 > effective_extents.y2 {
effective_extents.y1 = 0;
effective_extents.y2 = 0;
}
}
if let Some(node) = td_node {
let mut td_extents = node.common.extents.get();
td_extents.width = (effective_extents.x2 - effective_extents.x1) as u32;
td_extents.height = (effective_extents.y2 - effective_extents.y1) as u32;
node.common.extents.set(td_extents);
}
self.effective_extents.set(effective_extents);
}
async fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {

View file

@ -112,7 +112,7 @@ impl WlSubsurface {
let data = data.get_or_insert_with(|| Default::default());
data.subsurfaces
.insert(self.surface.id, self.surface.clone());
data.above.prepend(StackElement {
data.above.add_first(StackElement {
pending: Cell::new(true),
surface: self.surface.clone(),
})
@ -168,8 +168,8 @@ impl WlSubsurface {
};
if sibling == self.parent.id {
let node = match above {
true => pdata.above.prepend(element),
_ => pdata.below.append(element),
true => pdata.above.add_first(element),
_ => pdata.below.add_last(element),
};
data.pending.node = Some(node);
} else {

View file

@ -6,7 +6,7 @@ use crate::client::{AddObj, DynEventFormatter};
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::{
RoleData, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
RoleData, SurfaceExtents, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
XdgSurfaceRoleData, XdgToplevelData,
};
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
@ -73,8 +73,10 @@ impl XdgSurface {
requested_serial: 0,
acked_serial: None,
role: XdgSurfaceRole::None,
extents: None,
role_data: XdgSurfaceRoleData::None,
popups: Default::default(),
pending: Default::default(),
}));
Ok(())
}
@ -176,7 +178,20 @@ impl XdgSurface {
&self,
parser: MsgParser<'_, '_>,
) -> Result<(), SetWindowGeometryError> {
let _req: SetWindowGeometry = self.surface.client.parse(self, parser)?;
let req: SetWindowGeometry = self.surface.client.parse(self, parser)?;
if req.height <= 0 || req.width <= 0 {
return Err(SetWindowGeometryError::NonPositiveWidthHeight);
}
let mut rd = self.surface.role_data.borrow_mut();
if let RoleData::XdgSurface(xdg) = rd.deref_mut() {
let extents = SurfaceExtents {
x1: req.x,
y1: req.y,
x2: req.x + req.width,
y2: req.y + req.height,
};
xdg.pending.extents.set(Some(extents));
}
Ok(())
}

View file

@ -74,6 +74,8 @@ pub enum SetWindowGeometryError {
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Tried no set a non-positive width/height")]
NonPositiveWidthHeight,
}
efrom!(SetWindowGeometryError, ParseFailed, MsgParserError);
efrom!(SetWindowGeometryError, ClientError, ClientError);

View file

@ -5,6 +5,7 @@ use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use num_derive::FromPrimitive;
use std::ops::Deref;
use std::rc::Rc;
pub use types::*;
@ -97,7 +98,16 @@ impl XdgToplevel {
}
async fn move_(&self, parser: MsgParser<'_, '_>) -> Result<(), MoveError> {
let _req: Move = self.surface.surface.client.parse(self, parser)?;
let req: Move = self.surface.surface.client.parse(self, parser)?;
let rd = self.surface.surface.role_data.borrow();
if let RoleData::XdgSurface(xdg) = rd.deref() {
if let XdgSurfaceRoleData::Toplevel(tl) = &xdg.role_data {
if let Some(node) = tl.node.as_ref() {
let seat = self.surface.surface.client.get_wl_seat(req.seat)?;
seat.move_(&node.node);
}
}
}
Ok(())
}

View file

@ -130,6 +130,10 @@ impl Global for XdgWmBaseGlobal {
self.name
}
fn singleton(&self) -> bool {
true
}
fn interface(&self) -> Interface {
Interface::XdgWmBase
}