Skip to content

Commit

Permalink
Merge pull request #86 from mahkoh/jorth/ftl
Browse files Browse the repository at this point in the history
wayland: implement ext-foreign-toplevel-list-v1
  • Loading branch information
mahkoh authored Feb 14, 2024
2 parents ccacdda + 3f7b1dd commit 2f1e228
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ fn start_compositor2(
default_workspace_capture: Cell::new(true),
default_gfx_api: Cell::new(GfxApi::OpenGl),
activation_tokens: Default::default(),
toplevel_lists: Default::default(),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);
Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
backend::Backend,
client::Client,
ifs::{
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1Global,
ext_session_lock_manager_v1::ExtSessionLockManagerV1Global,
ipc::{
wl_data_device_manager::WlDataDeviceManagerGlobal,
Expand Down Expand Up @@ -164,6 +165,7 @@ impl Globals {
add_singleton!(WpCursorShapeManagerV1Global);
add_singleton!(WpContentTypeManagerV1Global);
add_singleton!(XdgActivationV1Global);
add_singleton!(ExtForeignToplevelListV1Global);
}

pub fn add_backend_singletons(&self, backend: &Rc<dyn Backend>) {
Expand Down
2 changes: 2 additions & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod ext_foreign_toplevel_handle_v1;
pub mod ext_foreign_toplevel_list_v1;
pub mod ext_session_lock_manager_v1;
pub mod ext_session_lock_v1;
pub mod ipc;
Expand Down
88 changes: 88 additions & 0 deletions src/ifs/ext_foreign_toplevel_handle_v1.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 172 additions & 0 deletions src/ifs/ext_foreign_toplevel_list_v1.rs
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 4 additions & 1 deletion src/ifs/wl_surface/x_surface/xwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -585,6 +591,7 @@ impl XdgSurfaceExt for XdgToplevel {
// }
// }
self.state.tree_changed();
self.toplevel_data.broadcast(self.clone());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use {
gfx_apis::create_gfx_context,
globals::{Globals, GlobalsError, WaylandGlobal},
ifs::{
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
ext_session_lock_v1::ExtSessionLockV1,
jay_render_ctx::JayRenderCtx,
jay_seat_events::JaySeatEvents,
Expand Down Expand Up @@ -50,7 +51,8 @@ use {
video::drm::Drm,
wheel::Wheel,
wire::{
JayRenderCtxId, JaySeatEventsId, JayWorkspaceWatcherId, ZwpLinuxDmabufFeedbackV1Id,
ExtForeignToplevelListV1Id, JayRenderCtxId, JaySeatEventsId, JayWorkspaceWatcherId,
ZwpLinuxDmabufFeedbackV1Id,
},
xkbcommon::{XkbContext, XkbKeymap},
xwayland::{self, XWaylandEvent},
Expand Down Expand Up @@ -136,6 +138,8 @@ pub struct State {
pub default_workspace_capture: Cell<bool>,
pub default_gfx_api: Cell<GfxApi>,
pub activation_tokens: CopyHashMap<ActivationToken, ()>,
pub toplevel_lists:
CopyHashMap<(ClientId, ExtForeignToplevelListV1Id), Rc<ExtForeignToplevelListV1>>,
}

// impl Drop for State {
Expand Down Expand Up @@ -670,6 +674,7 @@ impl State {
self.pending_float_titles.clear();
self.render_ctx_watchers.clear();
self.workspace_watchers.clear();
self.toplevel_lists.clear();
self.slow_clients.clear();
for (_, h) in self.input_device_handlers.borrow_mut().drain() {
h.async_event.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/tree/placeholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl PlaceholderNode {
id: state.node_ids.next(),
toplevel: ToplevelData::new(
state,
node.tl_data().title.borrow_mut().clone(),
node.tl_data().title.borrow().clone(),
node.node_client(),
),
destroyed: Default::default(),
Expand Down
Loading

0 comments on commit 2f1e228

Please sign in to comment.