implement zwlr_foreign_toplevel_management protocol (#452)
* implement zwlr_foreign_toplevel_management protocol * check if initial id is empty
This commit is contained in:
parent
3be8534683
commit
0930f00356
18 changed files with 636 additions and 24 deletions
|
|
@ -474,7 +474,7 @@ impl WlSeatGlobal {
|
|||
|
||||
pub fn set_fullscreen(&self, fullscreen: bool) {
|
||||
if let Some(tl) = self.keyboard_node.get().node_toplevel() {
|
||||
tl.tl_set_fullscreen(fullscreen);
|
||||
tl.tl_set_fullscreen(fullscreen, None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ impl Xwindow {
|
|||
Change::Map => {
|
||||
self.data.state.map_tiled(self.clone());
|
||||
if self.data.info.fullscreen.get() {
|
||||
self.clone().tl_set_fullscreen(true);
|
||||
self.clone().tl_set_fullscreen(true, None);
|
||||
}
|
||||
self.data.title_changed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use {
|
|||
},
|
||||
},
|
||||
xdg_toplevel_drag_v1::XdgToplevelDragV1,
|
||||
zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1,
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
|
|
@ -180,6 +181,10 @@ impl XdgToplevel {
|
|||
self.toplevel_data.send(self.clone(), list);
|
||||
}
|
||||
|
||||
pub fn manager_send_to(self: &Rc<Self>, manager: &ZwlrForeignToplevelManagerV1) {
|
||||
self.toplevel_data.manager_send(self.clone(), manager);
|
||||
}
|
||||
|
||||
pub fn send_current_configure(&self) {
|
||||
if self.drag.is_none() {
|
||||
let rect = self.xdg.absolute_desired_extents.get();
|
||||
|
|
|
|||
207
src/ifs/zwlr_foreign_toplevel_handle_v1.rs
Normal file
207
src/ifs/zwlr_foreign_toplevel_handle_v1.rs
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
ifs::wl_output::WlOutput,
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
tree::{Direction, OutputNode, ToplevelOpt},
|
||||
wire::{ZwlrForeignToplevelHandleV1Id, zwlr_foreign_toplevel_handle_v1::*},
|
||||
},
|
||||
arrayvec::ArrayVec,
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
const STATE_ACTIVATED: u32 = 2;
|
||||
const STATE_FULLSCREEN: u32 = 3;
|
||||
|
||||
const FULLSCREEN_SINCE: Version = Version(2);
|
||||
|
||||
pub struct ZwlrForeignToplevelHandleV1 {
|
||||
pub id: ZwlrForeignToplevelHandleV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub toplevel: ToplevelOpt,
|
||||
pub version: Version,
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelHandleV1 {
|
||||
fn detach(&self) {
|
||||
if let Some(tl) = self.toplevel.get() {
|
||||
tl.tl_data()
|
||||
.manager_handles
|
||||
.remove(&(self.client.id, self.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelHandleV1RequestHandler for ZwlrForeignToplevelHandleV1 {
|
||||
type Error = ZwlrForeignToplevelHandleV1Error;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.detach();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_maximized(&self, _req: SetMaximized, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unset_maximized(&self, _req: UnsetMaximized, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_minimized(&self, _req: SetMinimized, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unset_minimized(&self, _req: UnsetMinimized, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn activate(&self, req: Activate, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(toplevel) = self.toplevel.get() {
|
||||
if !toplevel.node_visible() {
|
||||
return Ok(());
|
||||
}
|
||||
let seat = self.client.lookup(req.seat)?;
|
||||
toplevel.node_do_focus(&seat.global, Direction::Unspecified);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn close(&self, _req: Close, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(toplevel) = self.toplevel.get() {
|
||||
toplevel.tl_close();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_rectangle(&self, _req: SetRectangle, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_fullscreen(&self, req: SetFullscreen, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(toplevel) = self.toplevel.get() {
|
||||
let ws = if req.output.is_some() {
|
||||
self.client
|
||||
.lookup(req.output)?
|
||||
.global
|
||||
.node()
|
||||
.map(|node| node.ensure_workspace())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
toplevel.tl_set_fullscreen(true, ws);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unset_fullscreen(&self, _req: UnsetFullscreen, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(toplevel) = self.toplevel.get() {
|
||||
toplevel.tl_set_fullscreen(false, None);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelHandleV1 {
|
||||
pub fn leave_output(&self, output: &Rc<OutputNode>) {
|
||||
let bindings = output.global.bindings.borrow();
|
||||
if let Some(bindings) = bindings.get(&self.client.id) {
|
||||
for binding in bindings.values() {
|
||||
self.send_output_leave(binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_output(&self, output: &Rc<OutputNode>) {
|
||||
let bindings = output.global.bindings.borrow();
|
||||
if let Some(bindings) = bindings.get(&self.client.id) {
|
||||
for binding in bindings.values() {
|
||||
self.send_output_enter(binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_state(&self, activated: bool, fullscreen: bool) {
|
||||
let mut state: ArrayVec<u32, 2> = ArrayVec::new();
|
||||
if activated {
|
||||
state.push(STATE_ACTIVATED);
|
||||
}
|
||||
if self.version >= FULLSCREEN_SINCE {
|
||||
if fullscreen {
|
||||
state.push(STATE_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
self.client.event(State {
|
||||
self_id: self.id,
|
||||
state: &state,
|
||||
});
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn send_parent(&self, parent: &Rc<ZwlrForeignToplevelHandleV1>) {
|
||||
self.client.event(Parent {
|
||||
self_id: self.id,
|
||||
parent: parent.id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_output_enter(&self, output: &Rc<WlOutput>) {
|
||||
self.client.event(OutputEnter {
|
||||
self_id: self.id,
|
||||
output: output.id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_output_leave(&self, output: &Rc<WlOutput>) {
|
||||
self.client.event(OutputLeave {
|
||||
self_id: self.id,
|
||||
output: output.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = ZwlrForeignToplevelHandleV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for ZwlrForeignToplevelHandleV1 {
|
||||
fn break_loops(&self) {
|
||||
self.detach();
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ZwlrForeignToplevelHandleV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ZwlrForeignToplevelHandleV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ZwlrForeignToplevelHandleV1Error, ClientError);
|
||||
162
src/ifs/zwlr_foreign_toplevel_manager_v1.rs
Normal file
162
src/ifs/zwlr_foreign_toplevel_manager_v1.rs
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{CAP_FOREIGN_TOPLEVEL_MANAGER, Client, ClientCaps, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::{
|
||||
wl_surface::{x_surface::xwindow::Xwindow, xdg_surface::xdg_toplevel::XdgToplevel},
|
||||
zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1,
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
tree::{NodeVisitorBase, ToplevelOpt},
|
||||
wire::{ZwlrForeignToplevelManagerV1Id, zwlr_foreign_toplevel_manager_v1::*},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct ZwlrForeignToplevelManagerV1Global {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelManagerV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ZwlrForeignToplevelManagerV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: Version,
|
||||
) -> Result<(), ZwlrForeignToplevelManagerV1Error> {
|
||||
let obj = Rc::new(ZwlrForeignToplevelManagerV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
version,
|
||||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
ZwlrToplevelVisitor { manager: &obj }.visit_display(&client.state.root);
|
||||
client.state.toplevel_managers.set((client.id, id), obj);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ZwlrToplevelVisitor<'a> {
|
||||
manager: &'a ZwlrForeignToplevelManagerV1,
|
||||
}
|
||||
|
||||
impl NodeVisitorBase for ZwlrToplevelVisitor<'_> {
|
||||
fn visit_toplevel(&mut self, node: &Rc<XdgToplevel>) {
|
||||
node.manager_send_to(self.manager);
|
||||
}
|
||||
|
||||
fn visit_xwindow(&mut self, node: &Rc<Xwindow>) {
|
||||
node.toplevel_data.manager_send(node.clone(), self.manager);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ZwlrForeignToplevelManagerV1 {
|
||||
pub id: ZwlrForeignToplevelManagerV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub version: Version,
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelManagerV1 {
|
||||
pub fn detach(&self) {
|
||||
self.client
|
||||
.state
|
||||
.toplevel_managers
|
||||
.remove(&(self.client.id, self.id));
|
||||
}
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelManagerV1RequestHandler for ZwlrForeignToplevelManagerV1 {
|
||||
type Error = ZwlrForeignToplevelManagerV1Error;
|
||||
|
||||
fn stop(&self, _req: Stop, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.detach();
|
||||
self.send_finished();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ZwlrForeignToplevelManagerV1 {
|
||||
pub fn send_finished(&self) {
|
||||
self.client.event(Finished { self_id: self.id });
|
||||
}
|
||||
|
||||
pub fn send_handle(&self, handle: &ZwlrForeignToplevelHandleV1) {
|
||||
self.client.event(Toplevel {
|
||||
self_id: self.id,
|
||||
toplevel: handle.id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn publish_toplevel(&self, tl: ToplevelOpt) -> Option<Rc<ZwlrForeignToplevelHandleV1>> {
|
||||
let id = match self.client.new_id() {
|
||||
Ok(id) => id,
|
||||
Err(e) => {
|
||||
self.client.error(e);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let handle = Rc::new(ZwlrForeignToplevelHandleV1 {
|
||||
id,
|
||||
client: self.client.clone(),
|
||||
tracker: Default::default(),
|
||||
version: self.version,
|
||||
toplevel: tl,
|
||||
});
|
||||
track!(self.client, handle);
|
||||
self.client.add_server_obj(&handle);
|
||||
self.send_handle(&handle);
|
||||
Some(handle)
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(
|
||||
ZwlrForeignToplevelManagerV1Global,
|
||||
ZwlrForeignToplevelManagerV1,
|
||||
ZwlrForeignToplevelManagerV1Error
|
||||
);
|
||||
|
||||
impl Global for ZwlrForeignToplevelManagerV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
3
|
||||
}
|
||||
|
||||
fn required_caps(&self) -> ClientCaps {
|
||||
CAP_FOREIGN_TOPLEVEL_MANAGER
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_global!(ZwlrForeignToplevelManagerV1Global);
|
||||
|
||||
object_base! {
|
||||
self = ZwlrForeignToplevelManagerV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for ZwlrForeignToplevelManagerV1 {
|
||||
fn break_loops(&self) {
|
||||
self.detach();
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ZwlrForeignToplevelManagerV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ZwlrForeignToplevelManagerV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(ZwlrForeignToplevelManagerV1Error, ClientError);
|
||||
Loading…
Add table
Add a link
Reference in a new issue