autocommit 2022-04-28 19:49:51 CEST
This commit is contained in:
parent
bd63f3f5f1
commit
1242a6c1e1
31 changed files with 707 additions and 64 deletions
|
|
@ -56,7 +56,10 @@ impl WlDataDeviceManagerGlobal {
|
|||
}
|
||||
|
||||
impl WlDataDeviceManager {
|
||||
fn create_data_source(&self, parser: MsgParser<'_, '_>) -> Result<(), WlDataDeviceManagerError> {
|
||||
fn create_data_source(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlDataDeviceManagerError> {
|
||||
let req: CreateDataSource = self.client.parse(self, parser)?;
|
||||
let res = Rc::new(WlDataSource::new(req.id, &self.client));
|
||||
track!(self.client, res);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,10 @@ impl ZwpPrimarySelectionDeviceManagerV1Global {
|
|||
}
|
||||
|
||||
impl ZwpPrimarySelectionDeviceManagerV1 {
|
||||
fn create_source(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
fn create_source(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
let req: CreateSource = self.client.parse(self, parser)?;
|
||||
let res = Rc::new(ZwpPrimarySelectionSourceV1::new(req.id, &self.client));
|
||||
track!(self.client, res);
|
||||
|
|
@ -58,7 +61,10 @@ impl ZwpPrimarySelectionDeviceManagerV1 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_data_device(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
fn get_data_device(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
let req: GetDevice = self.client.parse(&**self, parser)?;
|
||||
let seat = self.client.lookup(req.seat)?;
|
||||
let dev = Rc::new(ZwpPrimarySelectionDeviceV1::new(req.id, self, &seat));
|
||||
|
|
@ -68,7 +74,10 @@ impl ZwpPrimarySelectionDeviceManagerV1 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
fn destroy(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -61,7 +61,10 @@ impl ZwpPrimarySelectionDeviceV1 {
|
|||
})
|
||||
}
|
||||
|
||||
fn set_selection(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionDeviceV1Error> {
|
||||
fn set_selection(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpPrimarySelectionDeviceV1Error> {
|
||||
let req: SetSelection = self.manager.client.parse(self, parser)?;
|
||||
if !self.manager.client.valid_serial(req.serial) {
|
||||
log::warn!("Client tried to set_selection with an invalid serial");
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ impl OrgKdeKwinServerDecoration {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn request_mode(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), OrgKdeKwinServerDecorationError> {
|
||||
fn request_mode(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), OrgKdeKwinServerDecorationError> {
|
||||
let req: RequestMode = self.client.parse(&**self, parser)?;
|
||||
if req.mode > SERVER {
|
||||
return Err(OrgKdeKwinServerDecorationError::InvalidMode(req.mode));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ use {
|
|||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration,
|
||||
ifs::org_kde_kwin_server_decoration::{
|
||||
OrgKdeKwinServerDecoration, OrgKdeKwinServerDecorationError,
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
|
|
@ -11,7 +13,6 @@ use {
|
|||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecorationError;
|
||||
|
||||
#[allow(dead_code)]
|
||||
const NONE: u32 = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use {
|
|||
leaks::Tracker,
|
||||
object::Object,
|
||||
rect::Rect,
|
||||
render::{Image, RenderError, Texture},
|
||||
render::{Framebuffer, Image, RenderError, Texture},
|
||||
utils::{
|
||||
buffd::{MsgParser, MsgParserError},
|
||||
clonecell::CloneCell,
|
||||
|
|
@ -28,8 +28,9 @@ pub struct WlBuffer {
|
|||
pub client: Rc<Client>,
|
||||
pub rect: Rect,
|
||||
pub format: &'static Format,
|
||||
storage: WlBufferStorage,
|
||||
pub storage: WlBufferStorage,
|
||||
pub texture: CloneCell<Option<Rc<Texture>>>,
|
||||
pub famebuffer: CloneCell<Option<Rc<Framebuffer>>>,
|
||||
width: i32,
|
||||
height: i32,
|
||||
pub tracker: Tracker<Self>,
|
||||
|
|
@ -58,6 +59,7 @@ impl WlBuffer {
|
|||
width,
|
||||
height,
|
||||
texture: CloneCell::new(None),
|
||||
famebuffer: Default::default(),
|
||||
storage: WlBufferStorage::Dmabuf(img.clone()),
|
||||
tracker: Default::default(),
|
||||
}
|
||||
|
|
@ -95,6 +97,7 @@ impl WlBuffer {
|
|||
height,
|
||||
texture: CloneCell::new(None),
|
||||
tracker: Default::default(),
|
||||
famebuffer: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +121,20 @@ impl WlBuffer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_framebuffer(&self) -> Result<(), WlBufferError> {
|
||||
match &self.storage {
|
||||
WlBufferStorage::Shm { .. } => {
|
||||
// nothing
|
||||
}
|
||||
WlBufferStorage::Dmabuf(img) => {
|
||||
if self.famebuffer.get().is_none() {
|
||||
self.famebuffer.set(Some(img.to_framebuffer()?));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), WlBufferError> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self)?;
|
||||
|
|
|
|||
|
|
@ -102,18 +102,12 @@ impl WlDrm {
|
|||
Err(WlDrmError::Unsupported)
|
||||
}
|
||||
|
||||
fn create_planar_buffer(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlDrmError> {
|
||||
fn create_planar_buffer(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), WlDrmError> {
|
||||
let _req: CreatePlanarBuffer = self.client.parse(&**self, parser)?;
|
||||
Err(WlDrmError::Unsupported)
|
||||
}
|
||||
|
||||
fn create_prime_buffer(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlDrmError> {
|
||||
fn create_prime_buffer(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), WlDrmError> {
|
||||
let req: CreatePrimeBuffer = self.client.parse(&**self, parser)?;
|
||||
let ctx = match self.client.state.render_ctx.get() {
|
||||
Some(ctx) => ctx,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use {
|
|||
backend,
|
||||
client::{Client, ClientError, ClientId},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::zxdg_output_v1::ZxdgOutputV1,
|
||||
ifs::{zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1, zxdg_output_v1::ZxdgOutputV1},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
rect::Rect,
|
||||
|
|
@ -13,6 +13,7 @@ use {
|
|||
buffd::{MsgParser, MsgParserError},
|
||||
clonecell::CloneCell,
|
||||
copyhashmap::CopyHashMap,
|
||||
linkedlist::LinkedList,
|
||||
},
|
||||
wire::{wl_output::*, WlOutputId, ZxdgOutputV1Id},
|
||||
},
|
||||
|
|
@ -68,6 +69,8 @@ pub struct WlOutputGlobal {
|
|||
pub width_mm: i32,
|
||||
pub height_mm: i32,
|
||||
pub bindings: RefCell<AHashMap<ClientId, AHashMap<WlOutputId, Rc<WlOutput>>>>,
|
||||
pub unused_captures: LinkedList<Rc<ZwlrScreencopyFrameV1>>,
|
||||
pub pending_captures: LinkedList<Rc<ZwlrScreencopyFrameV1>>,
|
||||
}
|
||||
|
||||
impl WlOutputGlobal {
|
||||
|
|
@ -92,6 +95,8 @@ impl WlOutputGlobal {
|
|||
width_mm,
|
||||
height_mm,
|
||||
bindings: Default::default(),
|
||||
unused_captures: Default::default(),
|
||||
pending_captures: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@ use {
|
|||
ifs::wl_seat::WlSeat,
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
utils::{
|
||||
buffd::{MsgParser, MsgParserError},
|
||||
oserror::OsError,
|
||||
},
|
||||
wire::{wl_keyboard::*, WlKeyboardId, WlSurfaceId},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
use crate::utils::oserror::OsError;
|
||||
|
||||
pub const REPEAT_INFO_SINCE: u32 = 4;
|
||||
|
||||
|
|
|
|||
|
|
@ -539,10 +539,7 @@ impl WlSurface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_buffer_transform(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSurfaceError> {
|
||||
fn set_buffer_transform(&self, parser: MsgParser<'_, '_>) -> Result<(), WlSurfaceError> {
|
||||
let _req: SetBufferTransform = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,10 +283,7 @@ impl XdgToplevel {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_fullscreen(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgToplevelError> {
|
||||
fn set_fullscreen(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), XdgToplevelError> {
|
||||
let client = &self.xdg.surface.client;
|
||||
let req: SetFullscreen = client.parse(self.deref(), parser)?;
|
||||
self.states.borrow_mut().insert(STATE_FULLSCREEN);
|
||||
|
|
|
|||
|
|
@ -221,11 +221,7 @@ impl XdgPositioner {
|
|||
let req: SetConstraintAdjustment = self.client.parse(self, parser)?;
|
||||
let ca = match CA::from_bits(req.constraint_adjustment) {
|
||||
Some(c) => c,
|
||||
_ => {
|
||||
return Err(XdgPositionerError::UnknownCa(
|
||||
req.constraint_adjustment,
|
||||
))
|
||||
}
|
||||
_ => return Err(XdgPositionerError::UnknownCa(req.constraint_adjustment)),
|
||||
};
|
||||
self.position.borrow_mut().ca = ca;
|
||||
Ok(())
|
||||
|
|
@ -261,10 +257,7 @@ impl XdgPositioner {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_parent_configure(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgPositionerError> {
|
||||
fn set_parent_configure(&self, parser: MsgParser<'_, '_>) -> Result<(), XdgPositionerError> {
|
||||
let req: SetParentConfigure = self.client.parse(self, parser)?;
|
||||
self.position.borrow_mut().parent_serial = req.serial;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -84,10 +84,7 @@ impl XdgWmBase {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn create_positioner(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgWmBaseError> {
|
||||
fn create_positioner(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), XdgWmBaseError> {
|
||||
let req: CreatePositioner = self.client.parse(&**self, parser)?;
|
||||
let pos = Rc::new(XdgPositioner::new(self, req.id, &self.client));
|
||||
track!(self.client, pos);
|
||||
|
|
@ -95,10 +92,7 @@ impl XdgWmBase {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_xdg_surface(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgWmBaseError> {
|
||||
fn get_xdg_surface(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), XdgWmBaseError> {
|
||||
let req: GetXdgSurface = self.client.parse(&**self, parser)?;
|
||||
let surface = self.client.lookup(req.surface)?;
|
||||
let xdg_surface = Rc::new(XdgSurface::new(self, req.id, &surface));
|
||||
|
|
|
|||
196
src/ifs/zwlr_screencopy_frame_v1.rs
Normal file
196
src/ifs/zwlr_screencopy_frame_v1.rs
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
format::XRGB8888,
|
||||
ifs::{
|
||||
wl_buffer::{WlBuffer, WlBufferError, WlBufferStorage},
|
||||
wl_output::WlOutputGlobal,
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
rect::Rect,
|
||||
utils::{
|
||||
buffd::{MsgParser, MsgParserError},
|
||||
linkedlist::LinkedNode,
|
||||
},
|
||||
wire::{zwlr_screencopy_frame_v1::*, WlBufferId, ZwlrScreencopyFrameV1Id},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const FLAGS_Y_INVERT: u32 = 1;
|
||||
|
||||
pub struct ZwlrScreencopyFrameV1 {
|
||||
pub id: ZwlrScreencopyFrameV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub output: Rc<WlOutputGlobal>,
|
||||
pub rect: Rect,
|
||||
pub overlay_cursor: bool,
|
||||
pub used: Cell<bool>,
|
||||
pub with_damage: Cell<bool>,
|
||||
pub output_link: Cell<Option<LinkedNode<Rc<Self>>>>,
|
||||
pub buffer: Cell<Option<Rc<WlBuffer>>>,
|
||||
pub version: u32,
|
||||
}
|
||||
|
||||
impl ZwlrScreencopyFrameV1 {
|
||||
pub fn send_ready(&self, tv_sec: u64, tv_nsec: u32) {
|
||||
self.client.event(Ready {
|
||||
self_id: self.id,
|
||||
tv_sec_hi: (tv_sec >> 32) as u32,
|
||||
tv_sec_lo: tv_sec as u32,
|
||||
tv_nsec,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_failed(&self) {
|
||||
self.client.event(Failed { self_id: self.id });
|
||||
}
|
||||
|
||||
pub fn send_damage(&self) {
|
||||
self.client.event(Damage {
|
||||
self_id: self.id,
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: self.rect.width() as _,
|
||||
height: self.rect.height() as _,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_buffer(&self) {
|
||||
self.client.event(Buffer {
|
||||
self_id: self.id,
|
||||
format: XRGB8888.wl_id.unwrap(),
|
||||
width: self.rect.width() as _,
|
||||
height: self.rect.height() as _,
|
||||
stride: self.rect.width() as u32 * 4, // TODO
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_linux_dmabuf(&self) {
|
||||
self.client.event(LinuxDmabuf {
|
||||
self_id: self.id,
|
||||
format: XRGB8888.drm,
|
||||
width: self.rect.width() as _,
|
||||
height: self.rect.height() as _,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_buffer_done(&self) {
|
||||
self.client.event(BufferDone { self_id: self.id })
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn send_flags(&self, flags: u32) {
|
||||
self.client.event(Flags {
|
||||
self_id: self.id,
|
||||
flags,
|
||||
})
|
||||
}
|
||||
|
||||
fn do_copy(
|
||||
&self,
|
||||
buffer_id: WlBufferId,
|
||||
with_damage: bool,
|
||||
) -> Result<(), ZwlrScreencopyFrameV1Error> {
|
||||
if self.used.replace(true) {
|
||||
return Err(ZwlrScreencopyFrameV1Error::AlreadyUsed);
|
||||
}
|
||||
let link = match self.output_link.take() {
|
||||
Some(l) => l,
|
||||
_ => {
|
||||
self.send_failed();
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let buffer = self.client.lookup(buffer_id)?;
|
||||
if (buffer.rect.width(), buffer.rect.height()) != (self.rect.width(), self.rect.height()) {
|
||||
return Err(ZwlrScreencopyFrameV1Error::InvalidBufferSize);
|
||||
}
|
||||
if buffer.format != XRGB8888 {
|
||||
return Err(ZwlrScreencopyFrameV1Error::InvalidBufferFormat);
|
||||
}
|
||||
buffer.update_framebuffer()?;
|
||||
if let WlBufferStorage::Shm { stride, .. } = &buffer.storage {
|
||||
if *stride != self.rect.width() * 4 {
|
||||
return Err(ZwlrScreencopyFrameV1Error::InvalidBufferStride);
|
||||
}
|
||||
}
|
||||
self.buffer.set(Some(buffer));
|
||||
if !with_damage {
|
||||
self.output.connector.connector.damage();
|
||||
}
|
||||
self.with_damage.set(with_damage);
|
||||
self.output.pending_captures.add_last_existing(&link);
|
||||
self.output_link.set(Some(link));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn copy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwlrScreencopyFrameV1Error> {
|
||||
let req: Copy = self.client.parse(self, parser)?;
|
||||
self.do_copy(req.buffer, false)
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwlrScreencopyFrameV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self)?;
|
||||
self.output_link.take();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn copy_with_damage(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwlrScreencopyFrameV1Error> {
|
||||
let req: CopyWithDamage = self.client.parse(self, parser)?;
|
||||
self.do_copy(req.buffer, true)
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
ZwlrScreencopyFrameV1;
|
||||
|
||||
COPY => copy,
|
||||
DESTROY => destroy,
|
||||
COPY_WITH_DAMAGE => copy_with_damage,
|
||||
}
|
||||
|
||||
simple_add_obj!(ZwlrScreencopyFrameV1);
|
||||
|
||||
impl Object for ZwlrScreencopyFrameV1 {
|
||||
fn num_requests(&self) -> u32 {
|
||||
if self.version >= 2 {
|
||||
COPY_WITH_DAMAGE + 1
|
||||
} else {
|
||||
DESTROY + 1
|
||||
}
|
||||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.output_link.take();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ZwlrScreencopyFrameV1Error {
|
||||
#[error("This frame has already been used")]
|
||||
AlreadyUsed,
|
||||
#[error("The buffer has an invalid size for the frame")]
|
||||
InvalidBufferSize,
|
||||
#[error("The buffer has an invalid stride for the frame")]
|
||||
InvalidBufferStride,
|
||||
#[error("The buffer has an invalid format")]
|
||||
InvalidBufferFormat,
|
||||
#[error(transparent)]
|
||||
WlBufferError(Box<WlBufferError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error(transparent)]
|
||||
MsgParserError(Box<MsgParserError>),
|
||||
}
|
||||
efrom!(ZwlrScreencopyFrameV1Error, WlBufferError);
|
||||
efrom!(ZwlrScreencopyFrameV1Error, ClientError);
|
||||
efrom!(ZwlrScreencopyFrameV1Error, MsgParserError);
|
||||
163
src/ifs/zwlr_screencopy_manager_v1.rs
Normal file
163
src/ifs/zwlr_screencopy_manager_v1.rs
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1,
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
rect::Rect,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{
|
||||
zwlr_screencopy_manager_v1::*, WlOutputId, ZwlrScreencopyFrameV1Id,
|
||||
ZwlrScreencopyManagerV1Id,
|
||||
},
|
||||
},
|
||||
std::{cell::Cell, rc::Rc},
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct ZwlrScreencopyManagerV1Global {
|
||||
pub name: GlobalName,
|
||||
}
|
||||
|
||||
impl ZwlrScreencopyManagerV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ZwlrScreencopyManagerV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: u32,
|
||||
) -> Result<(), ZwlrScreencopyManagerV1Error> {
|
||||
let mgr = Rc::new(ZwlrScreencopyManagerV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
version,
|
||||
});
|
||||
track!(client, mgr);
|
||||
client.add_client_obj(&mgr)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(
|
||||
ZwlrScreencopyManagerV1Global,
|
||||
ZwlrScreencopyManagerV1,
|
||||
ZwlrScreencopyManagerV1Error
|
||||
);
|
||||
|
||||
simple_add_global!(ZwlrScreencopyManagerV1Global);
|
||||
|
||||
impl Global for ZwlrScreencopyManagerV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
3
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ZwlrScreencopyManagerV1 {
|
||||
pub id: ZwlrScreencopyManagerV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub version: u32,
|
||||
}
|
||||
|
||||
impl ZwlrScreencopyManagerV1 {
|
||||
fn capture_output(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwlrScreencopyManagerV1Error> {
|
||||
let req: CaptureOutput = self.client.parse(self, parser)?;
|
||||
self.do_capture_output(req.output, req.overlay_cursor != 0, req.frame, None)
|
||||
}
|
||||
|
||||
fn capture_output_region(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwlrScreencopyManagerV1Error> {
|
||||
let req: CaptureOutputRegion = self.client.parse(self, parser)?;
|
||||
let region = match Rect::new_sized(req.x, req.y, req.width, req.height) {
|
||||
Some(r) => r,
|
||||
_ => return Err(ZwlrScreencopyManagerV1Error::InvalidRegion),
|
||||
};
|
||||
self.do_capture_output(req.output, req.overlay_cursor != 0, req.frame, Some(region))
|
||||
}
|
||||
|
||||
fn do_capture_output(
|
||||
&self,
|
||||
output: WlOutputId,
|
||||
overlay_cursor: bool,
|
||||
frame: ZwlrScreencopyFrameV1Id,
|
||||
region: Option<Rect>,
|
||||
) -> Result<(), ZwlrScreencopyManagerV1Error> {
|
||||
let output = self.client.lookup(output)?;
|
||||
let mut rect = output.global.position().at_point(0, 0);
|
||||
if let Some(region) = region {
|
||||
rect = rect.intersect(region);
|
||||
}
|
||||
let frame = Rc::new(ZwlrScreencopyFrameV1 {
|
||||
id: frame,
|
||||
client: self.client.clone(),
|
||||
tracker: Default::default(),
|
||||
output: output.global.clone(),
|
||||
rect,
|
||||
overlay_cursor,
|
||||
used: Cell::new(false),
|
||||
with_damage: Cell::new(false),
|
||||
output_link: Cell::new(None),
|
||||
buffer: Cell::new(None),
|
||||
version: self.version,
|
||||
});
|
||||
track!(self.client, frame);
|
||||
self.client.add_client_obj(&frame)?;
|
||||
frame.send_buffer();
|
||||
if self.version >= 3 {
|
||||
frame.send_linux_dmabuf();
|
||||
frame.send_buffer_done();
|
||||
}
|
||||
frame
|
||||
.output_link
|
||||
.set(Some(output.global.unused_captures.add_last(frame.clone())));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwlrScreencopyManagerV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
ZwlrScreencopyManagerV1;
|
||||
|
||||
CAPTURE_OUTPUT => capture_output,
|
||||
CAPTURE_OUTPUT_REGION => capture_output_region,
|
||||
DESTROY => destroy,
|
||||
}
|
||||
|
||||
impl Object for ZwlrScreencopyManagerV1 {
|
||||
fn num_requests(&self) -> u32 {
|
||||
DESTROY + 1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ZwlrScreencopyManagerV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ZwlrScreencopyManagerV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error("The passed region is invalid")]
|
||||
InvalidRegion,
|
||||
}
|
||||
efrom!(ZwlrScreencopyManagerV1Error, ClientError);
|
||||
efrom!(ZwlrScreencopyManagerV1Error, MsgParserError);
|
||||
|
|
@ -61,7 +61,10 @@ impl ZwpLinuxBufferParamsV1 {
|
|||
self.parent.client.event(Failed { self_id: self.id })
|
||||
}
|
||||
|
||||
fn destroy(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZwpLinuxBufferParamsV1Error> {
|
||||
fn destroy(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpLinuxBufferParamsV1Error> {
|
||||
let _req: Destroy = self.parent.client.parse(&**self, parser)?;
|
||||
self.parent.client.remove_obj(&**self)?;
|
||||
Ok(())
|
||||
|
|
@ -71,7 +74,9 @@ impl ZwpLinuxBufferParamsV1 {
|
|||
let req: Add = self.parent.client.parse(&**self, parser)?;
|
||||
let modifier = ((req.modifier_hi as u64) << 32) | req.modifier_lo as u64;
|
||||
match self.modifier.get() {
|
||||
Some(m) if m != modifier => return Err(ZwpLinuxBufferParamsV1Error::MixedModifiers(modifier, m)),
|
||||
Some(m) if m != modifier => {
|
||||
return Err(ZwpLinuxBufferParamsV1Error::MixedModifiers(modifier, m))
|
||||
}
|
||||
_ => self.modifier.set(Some(modifier)),
|
||||
}
|
||||
let plane = req.plane_idx;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,10 @@ impl ZwpLinuxDmabufV1 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn create_params(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZwpLinuxDmabufV1Error> {
|
||||
fn create_params(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpLinuxDmabufV1Error> {
|
||||
let req: CreateParams = self.client.parse(&**self, parser)?;
|
||||
let params = Rc::new(ZwpLinuxBufferParamsV1::new(req.params_id, self));
|
||||
track!(self.client, params);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,10 @@ impl ZxdgOutputManagerV1 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_xdg_output(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZxdgOutputManagerV1Error> {
|
||||
fn get_xdg_output(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZxdgOutputManagerV1Error> {
|
||||
let req: GetXdgOutput = self.client.parse(&**self, parser)?;
|
||||
let output = self.client.lookup(req.output)?;
|
||||
let xdg_output = Rc::new(ZxdgOutputV1 {
|
||||
|
|
|
|||
|
|
@ -67,8 +67,10 @@ impl ZxdgOutputV1 {
|
|||
if self.version >= NAME_SINCE {
|
||||
self.send_name(&self.output.global.connector.name);
|
||||
}
|
||||
if self.version >= NO_DONE_SINCE && self.output.version >= SEND_DONE_SINCE {
|
||||
self.output.send_done();
|
||||
if self.version >= NO_DONE_SINCE {
|
||||
if self.output.version >= SEND_DONE_SINCE {
|
||||
self.output.send_done();
|
||||
}
|
||||
} else {
|
||||
self.send_done();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,13 +57,19 @@ impl ZxdgToplevelDecorationV1 {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_mode(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZxdgToplevelDecorationV1Error> {
|
||||
fn set_mode(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZxdgToplevelDecorationV1Error> {
|
||||
let _req: SetMode = self.client.parse(&**self, parser)?;
|
||||
self.do_send_configure();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unset_mode(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), ZxdgToplevelDecorationV1Error> {
|
||||
fn unset_mode(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZxdgToplevelDecorationV1Error> {
|
||||
let _req: UnsetMode = self.client.parse(&**self, parser)?;
|
||||
self.do_send_configure();
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue