Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
cb160bf
docs(plans): access control PR 4c part 2, plan 1 (follow-ups and keyb…
ariel3259 Dec 1, 2026
4a23b09
docs(plans): 4c part 2 plan 1, review round 1
ariel3259 Dec 1, 2026
9a76534
docs(plans): 4c part 2 plan 1, review round 2
ariel3259 Dec 1, 2026
2ad6d22
docs(plans): 4c part 2 plan 1, review round 3 minors
ariel3259 Dec 1, 2026
882b592
docs(status): access control PR 4c part 1
ariel3259 Dec 1, 2026
3221d49
refactor(xi): one XI2 event description constructor
ariel3259 Dec 1, 2026
4520e41
refactor(xi): drop the test-only slave DeviceChanged emitter
ariel3259 Dec 1, 2026
05fa519
test(access): 4c part 1 review minors
ariel3259 Dec 1, 2026
0f902e7
test(access): regrab doc names ALLOWED's selections
ariel3259 Dec 1, 2026
cee27ad
feat(access): Receive decides the focused key walk and form shadowing
ariel3259 Dec 1, 2026
d0d7308
fix(access): key stop predicate and grab owner writer (review r1)
ariel3259 Dec 1, 2026
4a4aa74
docs(plans): 4c part 2 plan 1, Task 3 expectations after Task 2
ariel3259 Dec 1, 2026
8cfdf64
feat(access): Receive decides grabbed key delivery
ariel3259 Dec 1, 2026
59986f3
fix(access): grabbed key review r1
ariel3259 Dec 1, 2026
301e35e
feat(access): Receive checks raw key copies and the grab leg
ariel3259 Dec 1, 2026
aa8338c
fix(access): raw key review minors
ariel3259 Dec 1, 2026
bc63b3f
docs(plan): access control PR 4c part 2, plan 2 (pointer and XI1)
ariel3259 Dec 1, 2026
fc18f10
docs(plan): number plan 2 rows consecutively
ariel3259 Dec 1, 2026
bb83841
docs(plan): plan 2 review round 1
ariel3259 Dec 1, 2026
879bd45
docs(plan): plan 2 review round 2
ariel3259 Dec 1, 2026
fc67b4d
docs(plan): plan 2 review round 3
ariel3259 Dec 1, 2026
e2f903f
test(access): share the input scenario helpers
ariel3259 Dec 1, 2026
d59964f
test(access): generalise the input harness for pointer and XI1 batches
ariel3259 Dec 1, 2026
e996e21
test(access): pointer natural-walk scenarios (red)
ariel3259 Dec 1, 2026
f1f44b2
test(access): review round 1 for the pointer harness
ariel3259 Dec 1, 2026
fdbb326
test(access): review round 2 for the pointer harness
ariel3259 Dec 1, 2026
10f26b9
feat(access): Receive decides the natural pointer walks
ariel3259 Dec 1, 2026
209fc06
test(access): pointer copies are now checked
ariel3259 Dec 1, 2026
a606997
fix(access): review round 1 for the natural pointer walks
ariel3259 Dec 1, 2026
bdd0d75
feat(access): Receive decides grabbed pointer delivery
ariel3259 Dec 1, 2026
5737176
fix(access): review round 1 for grabbed pointer delivery
ariel3259 Dec 1, 2026
0b7befd
feat(access): Receive decides the slave press protocol
ariel3259 Dec 1, 2026
6ad091b
fix(access): review round 1 for the slave press protocol
ariel3259 Dec 1, 2026
8ead2ac
feat(access): Receive checks raw pointer and scroll copies
ariel3259 Dec 1, 2026
565cb28
feat(access): Receive decides XI1 device event delivery
ariel3259 Dec 1, 2026
d707d62
test(access): XI1 grab foreign rejection and filter route window
ariel3259 Dec 1, 2026
44f7dfb
refactor(access): final review clean-ups for pointer delivery
ariel3259 Dec 2, 2026
a7d795d
docs(plan): compact the input Receive tests
ariel3259 Dec 2, 2026
0f4e0e3
docs(plan): input tests plan review round 1
ariel3259 Dec 2, 2026
19e6b4d
docs(plan): input tests plan review round 2
ariel3259 Dec 2, 2026
535775a
docs(plan): input tests plan review round 3
ariel3259 Dec 2, 2026
bbf53ae
docs(plan): input tests plan review round 4
ariel3259 Dec 2, 2026
680660d
test(access): input rows runner and key table
ariel3259 Dec 2, 2026
d7bf89a
test(access): input runner keeps queued-event variants and per-step a…
ariel3259 Dec 2, 2026
86b42cf
test(access): pointer table
ariel3259 Dec 2, 2026
af7d993
test(access): pointer table states the deferred master part, shares o…
ariel3259 Dec 2, 2026
246634d
test(access): input runner attributes request steps and decodes XI1 r…
ariel3259 Dec 2, 2026
b4052e1
docs(plan): access control PR 4c part 2, plan 3 (replay, thaw, freeze)
ariel3259 Dec 2, 2026
b005cb1
docs(plan): plan 3 names the lavapipe env script
ariel3259 Dec 2, 2026
2081a90
docs(plan): plan 3 review round 1
ariel3259 Dec 2, 2026
0a88563
docs(plan): plan 3 review round 2 minors
ariel3259 Dec 2, 2026
2497c21
test(access): input runner states request bytes and hooks; shadow and…
ariel3259 Dec 2, 2026
8041510
test(access): input runner checks replies from every client, full dis…
ariel3259 Dec 2, 2026
cbed31a
test(access): input runner matches each frame's detail to its own event
ariel3259 Dec 2, 2026
91d5f37
fix(access): the XI1 thaw filter asks no XI2 copy
ariel3259 Dec 2, 2026
bb724b1
test(access): the XI1 thaw row pins the queued entry and its playback
ariel3259 Dec 2, 2026
0bae742
test(access): replay, thaw and freeze rows
ariel3259 Dec 3, 2026
0f15036
test(access): replay rows cover equal-key thaw entries and key replay
ariel3259 Dec 3, 2026
161fa5a
docs(status): access control PR 4c part 2
ariel3259 Dec 3, 2026
151fa96
test(access): final review round for the replay rows
ariel3259 Dec 3, 2026
279e928
refactor(input): move the XI1 router into pointer_fanout/xi1.rs
ariel3259 Dec 3, 2026
3ed4f9a
docs(plan): access control PR 4c part 2, plan 4 (#396 review)
ariel3259 Dec 3, 2026
fdf53f5
docs(plan): plan 4 review round 1
ariel3259 Dec 3, 2026
b06dbf8
docs(plan): plan 4 review round 2
ariel3259 Dec 3, 2026
4a64ddd
perf(access): no-policy pointer walks allocate as before
ariel3259 Dec 3, 2026
5b4b526
perf(access): Task 1 review round, owner-events legs on the stack
ariel3259 Dec 3, 2026
28cfd5c
perf(access): no-policy keyboard and XI1 walks allocate as before
ariel3259 Dec 3, 2026
7d1b37e
perf(access): Task 2 review round, smaller key planning
ariel3259 Dec 3, 2026
d4cee92
test(access): compact the input row tables
ariel3259 Dec 3, 2026
1f92752
test(access): prune input rows to the ones that pin a distinct decision
ariel3259 Dec 3, 2026
442b8f4
test(access): Task 3 review round, restore the rows that pin a distin…
ariel3259 Dec 3, 2026
f82fcd1
test(access): final review round, pin the decisions only pruned rows …
ariel3259 Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 141 additions & 117 deletions crates/yserver-core/src/core_loop/fanout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
host_x11::{HostExposeEvent, HostXidMap},
resources::{MapState, ROOT_WINDOW},
server::ServerState,
xinput::XI2_DEVICE_CHANGED_MASK,
};

/// Wire-frame classes emitted to clients while loop telemetry is enabled.
Expand Down Expand Up @@ -130,18 +129,20 @@ pub(crate) fn record_outbound_telemetry(client: ClientId, order: ClientByteOrder
/// follows `HashMap` iteration — already non-deterministic in the old
/// path, so wire ordering is unchanged.
pub fn subscribers_by_id(state: &ServerState, window: ResourceId, mask_bits: u32) -> Vec<ClientId> {
state
.clients
.iter()
.filter_map(|(id, c)| {
let mask = c.event_masks.get(&window).copied().unwrap_or(0);
if mask & mask_bits != 0 {
Some(ClientId(*id))
} else {
None
}
})
.collect()
subscribers_by_id_iter(state, window, mask_bits).collect()
}

/// Iterate, in client-map order, over clients that selected one of the bits
/// in `mask_bits` on `window`.
pub(crate) fn subscribers_by_id_iter(
state: &ServerState,
window: ResourceId,
mask_bits: u32,
) -> impl Iterator<Item = ClientId> + '_ {
state.clients.iter().filter_map(move |(id, client)| {
let mask = client.event_masks.get(&window).copied().unwrap_or(0);
(mask & mask_bits != 0).then_some(ClientId(*id))
})
}

/// XI2 device ids whose selection ABSORBS a core pointer event: the
Expand Down Expand Up @@ -198,13 +199,14 @@ fn xi2_pointer_selected_on(state: &ServerState, window: ResourceId, evtype: u16)
/// instead). Without an accurate `child`, fvwm3's `Mouse 1 R A Menu`
/// binding fires on every click anywhere in the screen.
#[must_use]
pub fn pointer_propagation_target_by_id(
pub(crate) fn pointer_propagation_target_by_id(
state: &ServerState,
start: ResourceId,
start_x: i16,
start_y: i16,
mask_bits: u32,
xi2_evtype: Option<u16>,
mut walk: Option<CoreWalk<'_>>,
) -> Option<(ResourceId, i16, i16, Vec<ClientId>, ResourceId)> {
let mut current = start;
let mut x = start_x;
Expand All @@ -218,14 +220,44 @@ pub fn pointer_propagation_target_by_id(
// frame, handing the WM a press Xorg never sends. That armed
// OpenBox's drag state, so a later bare MotionNotify started a
// Move/Resize with no button held (#141).
if let Some(evtype) = xi2_evtype
&& xi2_pointer_selected_on(state, current, evtype)
{
return None;
//
// Under Receive the absorbing window is the master form's route
// window, the first window whose XI2 copy is allowed.
if let Some(evtype) = xi2_evtype {
let absorbs = match &walk {
Some(walk) => walk.absorbing_window == Some(current),
None => xi2_pointer_selected_on(state, current, evtype),
};
if absorbs {
return None;
}
}
let subs = subscribers_by_id(state, current, mask_bits);
let mut subs = subscribers_by_id(state, current, mask_bits);
if !subs.is_empty() {
return Some((current, x, y, subs, child.unwrap_or(ResourceId(0))));
let Some(walk) = walk.as_mut() else {
return Some((current, x, y, subs, child.unwrap_or(ResourceId(0))));
};
// A shadowed subscriber stops the walk with no check. The others
// are checked; an allowed one stops the walk too, and a denied
// copy is a non-delivery that lets it continue.
let description = EventDescription::core(walk.event_type);
let batch = EventBatch::new(std::slice::from_ref(&description));
let mut stops = false;
subs.retain(|sub| {
if walk.shadowed.contains(sub) {
stops = true;
false
} else {
let allowed =
walk.memo
.allows(state, *sub, EventSubject::Window(current), &batch);
stops |= allowed;
allowed
}
});
if stops {
return Some((current, x, y, subs, child.unwrap_or(ResourceId(0))));
}
}
let window = state.resources.window(current)?;
if window.parent == current {
Expand Down Expand Up @@ -293,6 +325,87 @@ where
fanout_event_to_clients_inner(state, client_ids, Some((subject, events)), encode)
}

/// Whether `client` may receive `events` for `subject`. Without an installed
/// policy the answer is `true` and no policy is asked.
pub(crate) fn receive_allows(
state: &ServerState,
client: ClientId,
subject: EventSubject,
events: &EventBatch<'_>,
) -> bool {
!matches!(
state.check_receive(client, subject, events, state.receive_request),
Decision::Deny(_)
)
}

/// The Receive results of one input dispatch, one per (client, subject,
/// batch). A routing decision and the write that follows it share the result,
/// so a client is asked once per attempt. With no policy installed nothing is
/// asked and nothing is stored.
///
/// The access types derive `Eq` but not `Hash`, so the entries are a small
/// `Vec` compared by equality.
pub(crate) struct ReceiveMemo {
entries: Vec<(ClientId, EventSubject, Vec<EventDescription>, bool)>,
}

impl ReceiveMemo {
pub(crate) fn new() -> Self {
Self {
entries: Vec::new(),
}
}

/// Return a result already recorded for this (client, subject, batch),
/// without asking the policy when the dispatch has no such entry.
pub(crate) fn known(
&self,
client: ClientId,
subject: EventSubject,
events: &EventBatch<'_>,
) -> Option<bool> {
self.entries
.iter()
.find(|(c, s, e, _)| *c == client && *s == subject && e.as_slice() == events.events())
.map(|(.., allowed)| *allowed)
}

/// First call per (client, subject, batch) asks `receive_allows`; later
/// calls return the stored result without asking.
pub(crate) fn allows(
&mut self,
state: &ServerState,
client: ClientId,
subject: EventSubject,
events: &EventBatch<'_>,
) -> bool {
if !state.policies_installed() {
return true;
}
if let Some(allowed) = self.known(client, subject, events) {
return allowed;
}
let allowed = receive_allows(state, client, subject, events);
self.entries
.push((client, subject, events.events().to_vec(), allowed));
allowed
}
}

/// How the core propagation walk of one pointer dispatch uses Receive.
pub(crate) struct CoreWalk<'a> {
pub(crate) memo: &'a mut ReceiveMemo,
/// The master XI2 form's route window: the one window where an XI2
/// selection absorbs the core copy.
pub(crate) absorbing_window: Option<ResourceId>,
/// Clients whose core copy the allowed master XI2 copy shadows.
pub(crate) shadowed: &'a [ClientId],
/// The core event code of the copy (ButtonPress 4, ButtonRelease 5,
/// MotionNotify 6).
pub(crate) event_type: u8,
}

fn fanout_event_to_clients_inner<F>(
state: &mut ServerState,
client_ids: &[ClientId],
Expand Down Expand Up @@ -431,7 +544,10 @@ pub fn emit_xi2_focus_event_to_state(
let (origin_x, origin_y) = state.resources.window_absolute_position(window);
let event_x = i16::try_from(i32::from(root_x).saturating_sub(origin_x)).unwrap_or(i16::MAX);
let event_y = i16::try_from(i32::from(root_y).saturating_sub(origin_y)).unwrap_or(i16::MAX);
let events = [EventDescription::extension(35, xi2_major_opcode, evtype)];
let events = [crate::xinput::xi2_event_description_with_opcode(
xi2_major_opcode,
evtype,
)];
let batch = EventBatch::new(&events);
fanout_event_to_clients_with_receive(
state,
Expand Down Expand Up @@ -459,100 +575,6 @@ pub fn emit_xi2_focus_event_to_state(
)
}

/// `XIDeviceChange` reason (XI2.h:108) — the device's own classes/name
/// changed (as opposed to `XISlaveSwitch`, which reports a master's
/// active slave swap).
const XI_REASON_DEVICE_CHANGE: u8 = 2;

/// Emit an XI2 `XI_DeviceChanged` for the bootstrapped virtual XTEST
/// pointer to clients that selected that device or `XIAllDevices`.
/// Physical registry facets are never represented by device 4 here.
/// The carried class set keeps the query-compatible button + 4 valuator
/// + 2 scroll shape.
///
/// `XIAllMasterDevices` does not select this slave event. If no client
/// selected, this is a no-op. Returns clients whose outbound
/// buffer overflowed (for `ClientDisconnected` reporting).
///
/// `xi2_major_opcode` is the XI extension's runtime-assigned major
/// opcode (137 in the current build).
pub fn emit_xi2_device_changed_slave_pointer(
state: &mut ServerState,
xi2_major_opcode: u8,
) -> Vec<ClientId> {
const XTEST_POINTER: u16 = crate::xinput::DEVICEID_XTEST_POINTER;

// Clients select on (window, deviceid). DeviceChanged is a
// hierarchy-wide event clients select on the ROOT window (the same
// window `process_request`'s XISelectEvents bootstrap requires before
// it sends the initial DeviceChanged). Match the root window only —
// matching any window would spuriously deliver to a client that
// selected DeviceChanged on some unrelated child. The XTEST device
// matches its exact selector and XIAllDevices(0); it is not a master,
// so XIAllMasterDevices(1) does not match.
let targets: Vec<ClientId> = state
.clients
.iter()
.filter_map(|(id, client)| {
let selected = client.xi2_masks.iter().any(|(&(window, dev), &mask)| {
window == ROOT_WINDOW
&& matches!(dev, XTEST_POINTER | 0)
&& (mask & u64::from(XI2_DEVICE_CHANGED_MASK)) != 0
});
selected.then_some(ClientId(*id))
})
.collect();
if targets.is_empty() {
return Vec::new();
}

let (classes, num_classes) = build_slave_pointer_class_block(state);
let time = state.timestamp_now();
let event_description = crate::xinput::xi2_event_description(1);
let events = EventBatch::new(std::slice::from_ref(&event_description));
fanout_event_to_clients_with_receive(
state,
&targets,
EventSubject::Window(ROOT_WINDOW),
&events,
|buf, seq, order| {
x11::encode_xi2_device_changed_event(
buf,
order,
seq,
xi2_major_opcode,
XTEST_POINTER,
time,
num_classes,
XTEST_POINTER, // sourceid = the XTEST device itself
XI_REASON_DEVICE_CHANGE,
&classes,
);
},
)
}

/// Build the XI2 device-class block for the virtual XTEST pointer.
///
/// The query encoder owns the shared button/valuator/scroll class layout;
/// both XIQueryDevice and DeviceChanged use it so their class blocks remain
/// byte-identical for little-endian clients.
pub(crate) fn build_slave_pointer_class_block(state: &mut ServerState) -> (Vec<u8>, u16) {
build_pointer_class_block_for_device(state, crate::xinput::DEVICEID_XTEST_POINTER)
}

pub(crate) fn build_pointer_class_block_for_device(
state: &mut ServerState,
device_id: u16,
) -> (Vec<u8>, u16) {
let class_data = pointer_class_data_for_device(state, device_id);
crate::xinput::query::build_pointer_classes(
ClientByteOrder::LittleEndian,
device_id,
class_data,
)
}

pub(crate) fn pointer_class_data_for_device(
state: &mut ServerState,
device_id: u16,
Expand Down Expand Up @@ -964,7 +986,8 @@ mod tests {
5,
5,
0x0000_0004,
Some(XI_BUTTON_PRESS)
Some(XI_BUTTON_PRESS),
None,
)
.is_none(),
"an XI2 master-device selection must absorb the core press, \
Expand All @@ -980,6 +1003,7 @@ mod tests {
5,
0x0000_0004,
Some(XI_BUTTON_PRESS),
None,
)
.expect("a slave-device XI2 selection must not absorb the core press");
assert_eq!(win, FRAME);
Expand All @@ -989,7 +1013,7 @@ mod tests {
// unchanged: Enter/Leave are not routed by the flavour-ordered loop.
let state = build(1);
let (win, _, _, _, _) =
pointer_propagation_target_by_id(&state, CHILD, 5, 5, 0x0000_0004, None)
pointer_propagation_target_by_id(&state, CHILD, 5, 5, 0x0000_0004, None, None)
.expect("without an absorbing evtype the walk still finds the frame");
assert_eq!(win, FRAME);
}
Expand Down
Loading
Loading