1
0
Fork 0
forked from wry/wry

config: add warp-mouse-to-focus action

This commit is contained in:
Nicolaus Jacobsen 2026-03-10 09:36:13 +01:00 committed by Julian Orth
parent 107245d877
commit aaf02dc4e1
13 changed files with 74 additions and 2 deletions

View file

@ -38,7 +38,7 @@ use {
},
jay_screencast::{perform_screencast_realloc, perform_toplevel_screencasts},
wl_output::{BlendSpace, OutputId, PersistentOutputState, WlOutputGlobal},
wl_seat::handle_position_hint_requests,
wl_seat::{handle_position_hint_requests, handle_warp_mouse_to_focus},
wl_surface::{
NoneSurfaceExt, xdg_surface::handle_xdg_surface_configure_events,
zwp_input_popup_surface_v2::input_popup_positioning,
@ -377,6 +377,7 @@ fn start_compositor2(
toplevel_managers: Default::default(),
node_at_tree: Default::default(),
position_hint_requests: Default::default(),
pending_warp_mouse_to_focus: Default::default(),
backend_connector_state_serials: Default::default(),
head_names: Default::default(),
head_managers: Default::default(),
@ -605,6 +606,10 @@ fn start_global_event_handlers(state: &Rc<State>) -> Vec<SpawnedFuture<()>> {
"redraw control centers",
redraw_control_centers(state.clone()),
),
eng.spawn(
"warp mouse to focus",
handle_warp_mouse_to_focus(state.clone()),
),
]
}

View file

@ -2415,6 +2415,12 @@ impl ConfigProxyHandler {
Ok(())
}
fn handle_seat_warp_mouse_to_focus(&self, seat: Seat) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
seat.schedule_warp_mouse_to_focus();
Ok(())
}
fn get_sized(&self, sized: Resizable) -> Result<ThemeSized, CphError> {
use jay_config::theme::sized::*;
let sized = match sized {
@ -3329,6 +3335,9 @@ impl ConfigProxyHandler {
ClientMessage::SeatEnableUnicodeInput { seat } => self
.handle_seat_enable_unicode_input(seat)
.wrn("seat_enable_unicode_input")?,
ClientMessage::SeatWarpMouseToFocus { seat } => self
.handle_seat_warp_mouse_to_focus(seat)
.wrn("seat_warp_mouse_to_focus")?,
ClientMessage::ConnectorSetUseNativeGamut {
connector,
use_native_gamut,

View file

@ -258,6 +258,7 @@ pub struct WlSeatGlobal {
modifiers_forward: EventSource<dyn LedsListener>,
simple_im: CloneCell<Option<Rc<SimpleIm>>>,
simple_im_enabled: Cell<bool>,
warp_mouse_to_focus_scheduled: Cell<bool>,
}
impl PartialEq for WlSeatGlobal {
@ -400,6 +401,7 @@ impl WlSeatGlobal {
modifiers_forward: Default::default(),
simple_im: CloneCell::new(simple_im),
simple_im_enabled: Cell::new(true),
warp_mouse_to_focus_scheduled: Cell::new(false),
});
slf.pointer_cursor.set_owner(slf.clone());
slf.modifiers_listener
@ -820,6 +822,12 @@ impl WlSeatGlobal {
}
}
pub fn schedule_warp_mouse_to_focus(self: &Rc<Self>) {
if !self.warp_mouse_to_focus_scheduled.replace(true) {
self.state.pending_warp_mouse_to_focus.push(self.clone());
}
}
pub fn move_focused(self: &Rc<Self>, direction: Direction) {
let kb_node = self.keyboard_node.get();
let Some(tl) = kb_node.node_toplevel() else {
@ -2007,3 +2015,25 @@ pub async fn handle_position_hint_requests(state: Rc<State>) {
req.seat.motion_event_abs(state.now_usec(), x, y);
}
}
pub async fn handle_warp_mouse_to_focus(state: Rc<State>) {
loop {
state.pending_warp_mouse_to_focus.non_empty().await;
state.eng.yield_now().await;
while let Some(seat) = state.pending_warp_mouse_to_focus.try_pop() {
seat.warp_mouse_to_focus_scheduled.set(false);
let Some(tl) = seat.keyboard_node.get().node_toplevel() else {
continue;
};
let (x, y) = tl.node_absolute_position().center();
let Some(target) = state.node_at(x, y).node.node_toplevel() else {
continue;
};
if target.node_id() != tl.node_id() {
continue;
}
let (x, y) = (Fixed::from_int(x), Fixed::from_int(y));
seat.motion_event_abs(state.now_usec(), x, y);
}
}
}

View file

@ -284,6 +284,7 @@ pub struct State {
pub caps_thread: Option<PrCapsThread>,
pub node_at_tree: RefCell<Vec<FoundNode>>,
pub position_hint_requests: AsyncQueue<PositionHintRequest>,
pub pending_warp_mouse_to_focus: AsyncQueue<Rc<WlSeatGlobal>>,
pub backend_connector_state_serials: BackendConnectorStateSerials,
pub head_names: HeadNames,
pub head_managers:
@ -1175,6 +1176,7 @@ impl State {
self.tl_matcher_manager.clear();
self.node_at_tree.borrow_mut().clear();
self.position_hint_requests.clear();
self.pending_warp_mouse_to_focus.clear();
self.head_managers.clear();
self.head_managers_async.clear();
self.const_40hz_latch.clear();