1
0
Fork 0
forked from wry/wry

seat: keep track of serials that are allowed to steal keyboard focus

This commit is contained in:
Julian Orth 2024-10-17 16:08:54 +02:00
parent 324540c41e
commit 18bddbc987
4 changed files with 21 additions and 1 deletions

View file

@ -175,6 +175,7 @@ impl Clients {
slf,
)),
wire_scale: Default::default(),
focus_stealing_serial: Default::default(),
});
track!(data, data);
let display = Rc::new(WlDisplay::new(&data));
@ -286,6 +287,7 @@ pub struct Client {
pub activation_tokens: RefCell<VecDeque<ActivationToken>>,
pub commit_timelines: Rc<CommitTimelines>,
pub wire_scale: Cell<Option<i32>>,
pub focus_stealing_serial: Cell<Option<u64>>,
}
pub const NUM_CACHED_SERIAL_RANGES: usize = 64;

View file

@ -1041,6 +1041,18 @@ impl WlSeatGlobal {
ei_seat.regions_changed();
});
}
#[expect(dead_code)]
pub fn handle_focus_request(self: &Rc<Self>, client: &Client, node: Rc<dyn Node>, serial: u64) {
let Some(max_serial) = client.focus_stealing_serial.get() else {
return;
};
let serial = serial.min(max_serial);
if serial <= self.keyboard_node_serial.get() {
return;
}
self.focus_node_with_serial(node, serial);
}
}
impl CursorUserOwner for WlSeatGlobal {

View file

@ -1150,7 +1150,10 @@ impl WlSeatGlobal {
) {
let (state, pressed) = match state {
KeyState::Released => (wl_pointer::RELEASED, false),
KeyState::Pressed => (wl_pointer::PRESSED, true),
KeyState::Pressed => {
surface.client.focus_stealing_serial.set(Some(serial));
(wl_pointer::PRESSED, true)
}
};
let time = (time_usec / 1000) as u32;
self.surface_pointer_event(Version::ALL, surface, |p| {
@ -1372,6 +1375,7 @@ impl WlSeatGlobal {
y: Fixed,
) {
let serial = surface.client.next_serial();
surface.client.focus_stealing_serial.set(Some(serial));
let time = (time_usec / 1000) as _;
self.surface_touch_event(Version::ALL, surface, |t| {
t.send_down(serial, time, surface.id, id, x, y)

View file

@ -211,6 +211,7 @@ impl TabletTool {
tool.send_frame(time);
});
if state == ToolButtonState::Pressed {
n.client.focus_stealing_serial.set(Some(serial.get()));
if let Some(node) = n.get_focus_node(self.tablet.seat.id) {
self.tablet.seat.focus_node_with_serial(node, serial.get());
}
@ -259,6 +260,7 @@ impl TabletTool {
});
if let Some(changes) = changes {
if changes.down == Some(true) {
n.client.focus_stealing_serial.set(Some(serial.get()));
if let Some(node) = n.get_focus_node(self.tablet.seat.id) {
self.tablet.seat.focus_node_with_serial(node, serial.get());
}