1
0
Fork 0
forked from wry/wry

config: add client window criteria

This commit is contained in:
Julian Orth 2025-05-02 23:46:11 +02:00
parent 59f8acdfde
commit 2b5be7fbd9
19 changed files with 205 additions and 14 deletions

View file

@ -230,6 +230,7 @@ fn start_compositor2(
ipc_device_ids: Default::default(),
use_wire_scale: Default::default(),
wire_scale: Default::default(),
windows: Default::default(),
},
acceptor: Default::default(),
serial: Default::default(),

View file

@ -1991,6 +1991,10 @@ impl ConfigProxyHandler {
match *field {}
}
WindowCriterionIpc::Types(t) => mgr.kind(*t),
WindowCriterionIpc::Client(c) => {
self.state.cl_matcher_manager.rematch_all(&self.state);
mgr.client(&self.state, &self.get_client_matcher(*c)?.node)
}
};
let cached = Rc::new(CachedCriterion {
crit: criterion.clone(),

View file

@ -12,5 +12,7 @@ pub use {
CritRootFixed,
},
crit_target::{CritMgr, CritTarget, CritTargetOwner, WeakCritTargetOwner},
crit_upstream::{CritUpstreamData, CritUpstreamNode},
crit_upstream::{
CritUpstreamData, CritUpstreamNode, CritUpstreamNodeBase, CritUpstreamNodeData,
},
};

View file

@ -55,7 +55,6 @@ where
fn detach(&self, id: CritMatcherId);
fn not(&self, mgr: &Target::Mgr) -> Rc<dyn CritUpstreamNode<Target>>;
fn pull(&self, target: &Target) -> bool;
#[expect(dead_code)]
fn get(&self, target: &Target) -> bool;
}

View file

@ -5,10 +5,11 @@ use {
criteria::{
CritDestroyListener, CritMatcherId, CritMatcherIds, CritMgrExt, CritUpstreamNode,
FixedRootMatcher, RootMatcherMap,
clm::ClmUpstreamNode,
crit_graph::{CritMgr, CritTarget, CritTargetOwner, WeakCritTargetOwner},
crit_leaf::{CritLeafEvent, CritLeafMatcher},
crit_matchers::critm_constant::CritMatchConstant,
tlm::tlm_matchers::tlmm_kind::TlmMatchKind,
tlm::tlm_matchers::{tlmm_client::TlmMatchClient, tlmm_kind::TlmMatchKind},
},
state::State,
tree::{NodeId, ToplevelData, ToplevelNode},
@ -42,6 +43,7 @@ type TlmRootMatcherMap<T> = RootMatcherMap<ToplevelData, T>;
#[derive(Default)]
pub struct RootMatchers {
kinds: TlmRootMatcherMap<TlmMatchKind>,
clients: CopyHashMap<CritMatcherId, Weak<TlmMatchClient>>,
}
pub async fn handle_tl_changes(state: Rc<State>) {
@ -115,6 +117,7 @@ impl TlMatcherManager {
};
}
unconditional!(kinds);
unconditional!(clients);
if self.constant[true].has_downstream() {
return true;
}
@ -182,6 +185,7 @@ impl TlMatcherManager {
};
}
unconditional!(kinds);
unconditional!(clients);
self.constant[true].handle(data);
}
#[expect(unused_macros)]
@ -207,6 +211,10 @@ impl TlMatcherManager {
pub fn kind(&self, kind: WindowType) -> Rc<TlmUpstreamNode> {
self.root(TlmMatchKind::new(kind))
}
pub fn client(&self, state: &Rc<State>, client: &Rc<ClmUpstreamNode>) -> Rc<TlmUpstreamNode> {
TlmMatchClient::new(state, client)
}
}
impl CritTarget for ToplevelData {

View file

@ -18,4 +18,5 @@ macro_rules! fixed_root_criterion {
};
}
pub mod tlmm_client;
pub mod tlmm_kind;

View file

@ -0,0 +1,117 @@
use {
crate::{
client::Client,
criteria::{
CritMatcherId, CritUpstreamNode,
clm::ClmUpstreamNode,
crit_graph::{
CritDownstream, CritDownstreamData, CritMgr, CritUpstreamData,
CritUpstreamNodeBase, CritUpstreamNodeData,
},
crit_per_target_data::{CritDestroyListenerBase, CritPerTargetData},
tlm::TlMatcherManager,
},
state::State,
tree::{ToplevelData, ToplevelNodeBase},
},
std::rc::Rc,
};
pub struct TlmMatchClient {
id: CritMatcherId,
state: Rc<State>,
node: Rc<ClmUpstreamNode>,
upstream: CritDownstreamData<Rc<Client>>,
downstream: CritUpstreamData<ToplevelData, ()>,
}
impl TlmMatchClient {
pub fn new(state: &Rc<State>, node: &Rc<ClmUpstreamNode>) -> Rc<TlmMatchClient> {
let id = state.tl_matcher_manager.id();
let slf = Rc::new_cyclic(|slf| Self {
id,
state: state.clone(),
node: node.clone(),
upstream: CritDownstreamData::new(id, &[node.clone()]),
downstream: CritUpstreamData::new(slf, id),
});
slf.upstream.attach(&slf);
state
.tl_matcher_manager
.matchers
.clients
.set(id, Rc::downgrade(&slf));
slf
}
pub fn handle(&self, node: &ToplevelData) {
if let Some(client) = &node.client {
if self.node.get(client) {
let data = self.downstream.get_or_create(node);
self.downstream.update_matched(node, data, true, false);
}
}
}
}
impl CritUpstreamNodeBase<ToplevelData> for TlmMatchClient {
type Data = ();
fn data(&self) -> &CritUpstreamData<ToplevelData, Self::Data> {
&self.downstream
}
fn not(&self, _mgr: &TlMatcherManager) -> Rc<dyn CritUpstreamNode<ToplevelData>> {
Self::new(&self.state, &self.node.not(&self.state.cl_matcher_manager))
}
fn pull(&self, target: &ToplevelData) -> bool {
if let Some(client) = &target.client {
return self.node.pull(client);
}
false
}
}
impl CritDownstream<Rc<Client>> for TlmMatchClient {
fn update_matched(self: Rc<Self>, target: &Rc<Client>, matched: bool) {
let handle = |data: &ToplevelData| {
let node = match matched {
true => self.downstream.get_or_create(data),
false => match self.downstream.get(data) {
Some(n) => n,
None => return,
},
};
self.downstream
.update_matched(data, node, matched, !matched);
};
if target.is_xwayland {
for tl in self.state.xwayland.windows.lock().values() {
handle(tl.tl_data());
}
} else {
for tl in target.objects.xdg_toplevel.lock().values() {
handle(tl.tl_data());
}
}
}
}
impl CritDestroyListenerBase<ToplevelData> for TlmMatchClient {
type Data = CritUpstreamNodeData<ToplevelData, ()>;
fn data(&self) -> &CritPerTargetData<ToplevelData, Self::Data> {
&self.downstream.nodes
}
}
impl Drop for TlmMatchClient {
fn drop(&mut self) {
self.state
.tl_matcher_manager
.matchers
.clients
.remove(&self.id);
}
}

View file

@ -238,6 +238,13 @@ impl Xwindow {
self.tl_destroy();
self.x.surface.set_toplevel(None);
self.x.xwindow.set(None);
self.x
.surface
.client
.state
.xwayland
.windows
.remove(&self.id);
}
pub fn is_mapped(&self) -> bool {

View file

@ -57,6 +57,7 @@ use {
NoneSurfaceExt,
tray::TrayItemIds,
wl_subsurface::SubsurfaceIds,
x_surface::xwindow::{Xwindow, XwindowId},
zwp_idle_inhibitor_v1::{IdleInhibitorId, IdleInhibitorIds, ZwpIdleInhibitorV1},
zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2,
},
@ -271,6 +272,7 @@ pub struct XWaylandState {
pub ipc_device_ids: XIpcDeviceIds,
pub use_wire_scale: Cell<bool>,
pub wire_scale: Cell<Option<i32>>,
pub windows: CopyHashMap<XwindowId, Rc<Xwindow>>,
}
pub struct IdleState {

View file

@ -1459,6 +1459,7 @@ impl Wm {
return;
}
};
self.state.xwayland.windows.set(window.id, window.clone());
data.window.set(Some(window.clone()));
{
self.load_window_wm_class(data).await;