wayland: implement ext-foreign-toplevel-list-v1
This commit is contained in:
parent
ccacdda03e
commit
3f7b1ddd49
15 changed files with 434 additions and 8 deletions
88
src/ifs/ext_foreign_toplevel_handle_v1.rs
Normal file
88
src/ifs/ext_foreign_toplevel_handle_v1.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
tree::ToplevelNode,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{ext_foreign_toplevel_handle_v1::*, ExtForeignToplevelHandleV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct ExtForeignToplevelHandleV1 {
|
||||
pub id: ExtForeignToplevelHandleV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub toplevel: Rc<dyn ToplevelNode>,
|
||||
}
|
||||
|
||||
impl ExtForeignToplevelHandleV1 {
|
||||
fn detach(&self) {
|
||||
self.toplevel
|
||||
.tl_data()
|
||||
.handles
|
||||
.remove(&(self.client.id, self.id));
|
||||
}
|
||||
|
||||
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), ExtSessionLockV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, msg)?;
|
||||
self.detach();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn send_closed(&self) {
|
||||
self.client.event(Closed { self_id: self.id });
|
||||
}
|
||||
|
||||
pub fn send_done(&self) {
|
||||
self.client.event(Done { self_id: self.id });
|
||||
}
|
||||
|
||||
pub fn send_title(&self, title: &str) {
|
||||
self.client.event(Title {
|
||||
self_id: self.id,
|
||||
title,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_app_id(&self, app_id: &str) {
|
||||
self.client.event(AppId {
|
||||
self_id: self.id,
|
||||
app_id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_identifier(&self, identifier: &str) {
|
||||
self.client.event(Identifier {
|
||||
self_id: self.id,
|
||||
identifier,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = ExtForeignToplevelHandleV1;
|
||||
|
||||
DESTROY => destroy,
|
||||
}
|
||||
|
||||
impl Object for ExtForeignToplevelHandleV1 {
|
||||
fn break_loops(&self) {
|
||||
self.detach();
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ExtForeignToplevelHandleV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ExtSessionLockV1Error {
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ExtSessionLockV1Error, MsgParserError);
|
||||
efrom!(ExtSessionLockV1Error, ClientError);
|
||||
172
src/ifs/ext_foreign_toplevel_list_v1.rs
Normal file
172
src/ifs/ext_foreign_toplevel_list_v1.rs
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::{
|
||||
ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
|
||||
wl_surface::{x_surface::xwindow::Xwindow, xdg_surface::xdg_toplevel::XdgToplevel},
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
tree::{NodeVisitorBase, ToplevelNode},
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{
|
||||
ext_foreign_toplevel_list_v1::*, ExtForeignToplevelHandleV1Id,
|
||||
ExtForeignToplevelListV1Id,
|
||||
},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct ExtForeignToplevelListV1Global {
|
||||
pub name: GlobalName,
|
||||
}
|
||||
|
||||
impl ExtForeignToplevelListV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ExtForeignToplevelListV1Id,
|
||||
client: &Rc<Client>,
|
||||
_version: u32,
|
||||
) -> Result<(), ExtForeignToplevelListV1Error> {
|
||||
let obj = Rc::new(ExtForeignToplevelListV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
ToplevelVisitor { list: &obj }.visit_display(&client.state.root);
|
||||
client.state.toplevel_lists.set((client.id, id), obj);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ToplevelVisitor<'a> {
|
||||
list: &'a ExtForeignToplevelListV1,
|
||||
}
|
||||
|
||||
impl NodeVisitorBase for ToplevelVisitor<'_> {
|
||||
fn visit_toplevel(&mut self, node: &Rc<XdgToplevel>) {
|
||||
node.send_to(self.list);
|
||||
}
|
||||
|
||||
fn visit_xwindow(&mut self, node: &Rc<Xwindow>) {
|
||||
node.toplevel_data.send(node.clone(), self.list);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExtForeignToplevelListV1 {
|
||||
pub id: ExtForeignToplevelListV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
}
|
||||
|
||||
impl ExtForeignToplevelListV1 {
|
||||
fn detach(&self) {
|
||||
self.client
|
||||
.state
|
||||
.toplevel_lists
|
||||
.remove(&(self.client.id, self.id));
|
||||
}
|
||||
|
||||
fn stop(&self, msg: MsgParser<'_, '_>) -> Result<(), ExtForeignToplevelListV1Error> {
|
||||
let _req: Stop = self.client.parse(self, msg)?;
|
||||
self.detach();
|
||||
self.send_finished();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), ExtForeignToplevelListV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, msg)?;
|
||||
self.detach();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send_finished(&self) {
|
||||
self.client.event(Finished { self_id: self.id })
|
||||
}
|
||||
|
||||
fn send_handle(&self, handle: &ExtForeignToplevelHandleV1) {
|
||||
self.client.event(Toplevel {
|
||||
self_id: self.id,
|
||||
toplevel: handle.id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn publish_toplevel(
|
||||
&self,
|
||||
tl: &Rc<dyn ToplevelNode>,
|
||||
) -> Option<Rc<ExtForeignToplevelHandleV1>> {
|
||||
let id: ExtForeignToplevelHandleV1Id = match self.client.new_id() {
|
||||
Ok(i) => i,
|
||||
Err(e) => {
|
||||
self.client.error(e);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let handle = Rc::new(ExtForeignToplevelHandleV1 {
|
||||
id,
|
||||
client: self.client.clone(),
|
||||
tracker: Default::default(),
|
||||
toplevel: tl.clone(),
|
||||
});
|
||||
track!(self.client, handle);
|
||||
self.client.add_server_obj(&handle);
|
||||
self.send_handle(&handle);
|
||||
Some(handle)
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(
|
||||
ExtForeignToplevelListV1Global,
|
||||
ExtForeignToplevelListV1,
|
||||
ExtForeignToplevelListV1Error
|
||||
);
|
||||
|
||||
impl Global for ExtForeignToplevelListV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn secure(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_global!(ExtForeignToplevelListV1Global);
|
||||
|
||||
object_base! {
|
||||
self = ExtForeignToplevelListV1;
|
||||
|
||||
STOP => stop,
|
||||
DESTROY => destroy,
|
||||
}
|
||||
|
||||
impl Object for ExtForeignToplevelListV1 {
|
||||
fn break_loops(&self) {
|
||||
self.detach();
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ExtForeignToplevelListV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ExtForeignToplevelListV1Error {
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ExtForeignToplevelListV1Error, MsgParserError);
|
||||
efrom!(ExtForeignToplevelListV1Error, ClientError);
|
||||
|
|
@ -283,7 +283,10 @@ impl Xwindow {
|
|||
}
|
||||
match map_change {
|
||||
Change::Unmap => self.tl_set_visible(false),
|
||||
Change::Map => self.tl_set_visible(true),
|
||||
Change::Map => {
|
||||
self.tl_set_visible(true);
|
||||
self.toplevel_data.broadcast(self.clone());
|
||||
}
|
||||
Change::None => {}
|
||||
}
|
||||
self.data.state.tree_changed();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use {
|
|||
cursor::KnownCursor,
|
||||
fixed::Fixed,
|
||||
ifs::{
|
||||
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
|
||||
wl_seat::{NodeSeatState, SeatId, WlSeatGlobal},
|
||||
wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt},
|
||||
},
|
||||
|
|
@ -134,6 +135,10 @@ impl XdgToplevel {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn send_to(self: &Rc<Self>, list: &ExtForeignToplevelListV1) {
|
||||
self.toplevel_data.send(self.clone(), list);
|
||||
}
|
||||
|
||||
pub fn send_current_configure(&self) {
|
||||
let rect = self.xdg.absolute_desired_extents.get();
|
||||
self.send_configure_checked(rect.width(), rect.height());
|
||||
|
|
@ -222,13 +227,14 @@ impl XdgToplevel {
|
|||
|
||||
fn set_title(&self, parser: MsgParser<'_, '_>) -> Result<(), XdgToplevelError> {
|
||||
let req: SetTitle = self.xdg.surface.client.parse(self, parser)?;
|
||||
*self.toplevel_data.title.borrow_mut() = req.title.to_string();
|
||||
self.toplevel_data.set_title(req.title);
|
||||
self.tl_title_changed();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_app_id(&self, parser: MsgParser<'_, '_>) -> Result<(), XdgToplevelError> {
|
||||
let req: SetAppId = self.xdg.surface.client.parse(self, parser)?;
|
||||
self.toplevel_data.set_app_id(req.app_id);
|
||||
self.bugs.set(bugs::get(req.app_id));
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -585,6 +591,7 @@ impl XdgSurfaceExt for XdgToplevel {
|
|||
// }
|
||||
// }
|
||||
self.state.tree_changed();
|
||||
self.toplevel_data.broadcast(self.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue