1
0
Fork 0
forked from wry/wry

Merge pull request #86 from mahkoh/jorth/ftl

wayland: implement ext-foreign-toplevel-list-v1
This commit is contained in:
mahkoh 2024-02-14 21:26:28 +01:00 committed by GitHub
commit 2f1e22851c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 434 additions and 8 deletions

View file

@ -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);

View file

@ -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,
@ -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>) {

View file

@ -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;

View 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);

View 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);

View file

@ -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();

View file

@ -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());
}
}

View file

@ -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,
@ -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},
@ -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 {
@ -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();

View file

@ -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(),

View file

@ -1,11 +1,22 @@
use {
crate::{
client::Client,
ifs::wl_seat::{collect_kb_foci, collect_kb_foci2, NodeSeatState, SeatId},
client::{Client, ClientId},
ifs::{
ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
wl_seat::{collect_kb_foci, collect_kb_foci2, NodeSeatState, SeatId},
},
rect::Rect,
state::State,
tree::{ContainingNode, Direction, Node, OutputNode, PlaceholderNode, WorkspaceNode},
utils::{clonecell::CloneCell, smallmap::SmallMap, threshold_counter::ThresholdCounter},
utils::{
clonecell::CloneCell,
copyhashmap::CopyHashMap,
smallmap::SmallMap,
threshold_counter::ThresholdCounter,
toplevel_identifier::{toplevel_identifier, ToplevelIdentifier},
},
wire::ExtForeignToplevelHandleV1Id,
},
std::{
cell::{Cell, RefCell},
@ -176,6 +187,10 @@ pub struct ToplevelData {
pub seat_state: NodeSeatState,
pub wants_attention: Cell<bool>,
pub requested_attention: Cell<bool>,
pub app_id: RefCell<String>,
pub identifier: Cell<ToplevelIdentifier>,
pub handles:
CopyHashMap<(ClientId, ExtForeignToplevelHandleV1Id), Rc<ExtForeignToplevelHandleV1>>,
}
impl ToplevelData {
@ -199,6 +214,9 @@ impl ToplevelData {
seat_state: Default::default(),
wants_attention: Cell::new(false),
requested_attention: Cell::new(false),
app_id: Default::default(),
identifier: Cell::new(toplevel_identifier()),
handles: Default::default(),
}
}
@ -216,6 +234,13 @@ impl ToplevelData {
}
pub fn destroy_node(&self, node: &dyn Node) {
self.identifier.set(toplevel_identifier());
{
let mut handles = self.handles.lock();
for (_, handle) in handles.drain() {
handle.send_closed();
}
}
if let Some(fd) = self.fullscrceen_data.borrow_mut().take() {
fd.placeholder.tl_destroy();
}
@ -227,6 +252,58 @@ impl ToplevelData {
self.focus_node.clear();
}
pub fn broadcast(&self, toplevel: Rc<dyn ToplevelNode>) {
let id = self.identifier.get().to_string();
let title = self.title.borrow();
let app_id = self.app_id.borrow();
for list in self.state.toplevel_lists.lock().values() {
self.send_once(&toplevel, list, &id, &title, &app_id);
}
}
pub fn send(&self, toplevel: Rc<dyn ToplevelNode>, list: &ExtForeignToplevelListV1) {
let id = self.identifier.get().to_string();
let title = self.title.borrow();
let app_id = self.app_id.borrow();
self.send_once(&toplevel, list, &id, &title, &app_id);
}
fn send_once(
&self,
toplevel: &Rc<dyn ToplevelNode>,
list: &ExtForeignToplevelListV1,
id: &str,
title: &str,
app_id: &str,
) {
let handle = match list.publish_toplevel(toplevel) {
None => return,
Some(handle) => handle,
};
handle.send_identifier(id);
handle.send_title(title);
handle.send_app_id(app_id);
handle.send_done();
self.handles
.set((handle.client.id, handle.id), handle.clone());
}
pub fn set_title(&self, title: &str) {
*self.title.borrow_mut() = title.to_string();
for handle in self.handles.lock().values() {
handle.send_title(title);
handle.send_done();
}
}
pub fn set_app_id(&self, app_id: &str) {
*self.app_id.borrow_mut() = app_id.to_string();
for handle in self.handles.lock().values() {
handle.send_app_id(app_id);
handle.send_done();
}
}
pub fn set_fullscreen(
&self,
state: &Rc<State>,

View file

@ -34,6 +34,7 @@ pub mod stack;
pub mod syncqueue;
pub mod threshold_counter;
pub mod timer;
pub mod toplevel_identifier;
pub mod tri;
pub mod trim;
pub mod unlink_on_drop;

View file

@ -0,0 +1,28 @@
use {
crate::utils::opaque::{opaque, Opaque, OpaqueError},
std::{
fmt::{Display, Formatter},
str::FromStr,
},
};
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
pub struct ToplevelIdentifier(Opaque);
pub fn toplevel_identifier() -> ToplevelIdentifier {
ToplevelIdentifier(opaque())
}
impl Display for ToplevelIdentifier {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl FromStr for ToplevelIdentifier {
type Err = OpaqueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}

View file

@ -1102,7 +1102,7 @@ impl Wm {
}
let title = buf.as_bstr().to_string();
if let Some(window) = data.window.get() {
*window.toplevel_data.title.borrow_mut() = title.clone();
window.toplevel_data.set_title(&title);
window.tl_title_changed();
}
*data.info.title.borrow_mut() = Some(title);

View file

@ -0,0 +1,24 @@
# requests
msg destroy = 0 {
}
# events
msg closed = 0 {
}
msg done = 1 {
}
msg title = 2 {
title: str,
}
msg app_id = 3 {
app_id: str,
}
msg identifier = 4 {
identifier: str,
}

View file

@ -0,0 +1,16 @@
# requests
msg stop = 0 {
}
msg destroy = 1 {
}
# events
msg toplevel = 0 {
toplevel: id(ext_foreign_toplevel_handle_v1),
}
msg finished = 1 {
}