Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
72 changes: 72 additions & 0 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ use smithay::{
text_input::TextInputManagerState,
viewporter::ViewporterState,
virtual_keyboard::VirtualKeyboardManagerState,
virtual_pointer::{VirtualPointerHandler, VirtualPointerManagerState},
xdg_activation::{
XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData,
},
Expand Down Expand Up @@ -352,6 +353,76 @@ impl<BackendData: Backend> InputMethodHandler for AnvilState<BackendData> {
}
}

impl<BackendData: Backend> VirtualPointerHandler for AnvilState<BackendData> {
fn virtual_pointer_get_default_seat(&self) -> Option<Seat<Self>> {
Some(self.seat.clone())
}

fn virtual_pointer_motion(
&mut self,
_seat: Option<&Seat<Self>>,
time: u32,
delta: Point<f64, Logical>,
) {
let pointer = self.pointer.clone();
let location = (pointer.current_location() + delta).constrain(
self.space
.outputs()
.filter_map(|o| self.space.output_geometry(o))
.fold(Rectangle::default(), |acc, r| acc.merge(r))
.to_f64(),
);
let under = self.surface_under(location);
pointer.motion(
self,
under,
&smithay::input::pointer::MotionEvent {
location,
serial: smithay::utils::SERIAL_COUNTER.next_serial(),
time,
},
);
pointer.frame(self);
}

fn virtual_pointer_motion_absolute(
&mut self,
_seat: Option<&Seat<Self>>,
time: u32,
x: u32,
y: u32,
x_extent: u32,
y_extent: u32,
) {
if x_extent == 0 || y_extent == 0 {
return;
}
let output_geo = self
.space
.outputs()
.next()
.and_then(|o| self.space.output_geometry(o))
.unwrap_or_default()
.to_f64();
let location = Point::from((
output_geo.loc.x + (x as f64 / x_extent as f64) * output_geo.size.w,
output_geo.loc.y + (y as f64 / y_extent as f64) * output_geo.size.h,
));
let under = self.surface_under(location);
let pointer = self.pointer.clone();
pointer.motion(
self,
under,
&smithay::input::pointer::MotionEvent {
location,
serial: smithay::utils::SERIAL_COUNTER.next_serial(),
time,
},
);
pointer.frame(self);
}
}

impl<BackendData: Backend> KeyboardShortcutsInhibitHandler for AnvilState<BackendData> {
fn keyboard_shortcuts_inhibit_state(&mut self) -> &mut KeyboardShortcutsInhibitState {
&mut self.keyboard_shortcuts_inhibit_state
Expand Down Expand Up @@ -676,6 +747,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
TextInputManagerState::new::<Self>(&dh);
InputMethodManagerState::new::<Self, _>(&dh, |_client| true);
VirtualKeyboardManagerState::new::<Self, _>(&dh, |_client| true);
VirtualPointerManagerState::new::<Self, _>(&dh, |_client| true);
// Expose global only if backend supports relative motion events
if BackendData::HAS_RELATIVE_MOTION {
RelativePointerManagerState::new::<Self>(&dh);
Expand Down
1 change: 1 addition & 0 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub mod tablet_manager;
pub mod text_input;
pub mod viewporter;
pub mod virtual_keyboard;
pub mod virtual_pointer;
pub mod xdg_activation;
pub mod xdg_foreign;
pub mod xdg_system_bell;
Expand Down
Loading