2022-07-04 15:26:26 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
use crate::{
|
2024-03-05 21:31:33 -08:00
|
|
|
input::Devices,
|
2022-09-28 12:01:29 +02:00
|
|
|
shell::focus::target::{KeyboardFocusTarget, PointerFocusTarget},
|
|
|
|
|
state::State,
|
|
|
|
|
};
|
2022-07-04 15:26:26 +02:00
|
|
|
use smithay::{
|
|
|
|
|
delegate_seat,
|
2024-03-05 21:31:33 -08:00
|
|
|
input::{keyboard::LedState, pointer::CursorImageStatus, SeatHandler, SeatState},
|
2022-09-28 12:01:29 +02:00
|
|
|
reexports::wayland_server::Resource,
|
|
|
|
|
wayland::{
|
2023-10-10 13:28:30 -07:00
|
|
|
seat::WaylandFocus, selection::data_device::set_data_device_focus,
|
|
|
|
|
selection::primary_selection::set_primary_focus,
|
2022-09-28 12:01:29 +02:00
|
|
|
},
|
2022-07-04 15:26:26 +02:00
|
|
|
};
|
2022-08-31 13:01:23 +02:00
|
|
|
use std::cell::RefCell;
|
2022-07-04 15:26:26 +02:00
|
|
|
|
|
|
|
|
impl SeatHandler for State {
|
2022-09-28 12:01:29 +02:00
|
|
|
type KeyboardFocus = KeyboardFocusTarget;
|
|
|
|
|
type PointerFocus = PointerFocusTarget;
|
2024-03-26 16:45:30 +01:00
|
|
|
type TouchFocus = PointerFocusTarget;
|
2022-08-31 13:01:23 +02:00
|
|
|
|
2022-07-04 15:26:26 +02:00
|
|
|
fn seat_state(&mut self) -> &mut SeatState<Self> {
|
|
|
|
|
&mut self.common.seat_state
|
|
|
|
|
}
|
2022-08-31 13:01:23 +02:00
|
|
|
|
|
|
|
|
fn cursor_image(
|
|
|
|
|
&mut self,
|
|
|
|
|
seat: &smithay::input::Seat<Self>,
|
|
|
|
|
image: smithay::input::pointer::CursorImageStatus,
|
|
|
|
|
) {
|
|
|
|
|
*seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<RefCell<CursorImageStatus>>()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.borrow_mut() = image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn focus_changed(
|
|
|
|
|
&mut self,
|
|
|
|
|
seat: &smithay::input::Seat<Self>,
|
|
|
|
|
focused: Option<&Self::KeyboardFocus>,
|
|
|
|
|
) {
|
|
|
|
|
let dh = &self.common.display_handle;
|
2022-09-28 12:01:29 +02:00
|
|
|
if let Some(client) = focused
|
|
|
|
|
.and_then(|t| t.wl_surface())
|
|
|
|
|
.and_then(|s| dh.get_client(s.id()).ok())
|
|
|
|
|
{
|
|
|
|
|
set_data_device_focus(dh, seat, Some(client.clone()));
|
|
|
|
|
set_primary_focus(dh, seat, Some(client))
|
2022-08-31 13:01:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-05 21:31:33 -08:00
|
|
|
|
|
|
|
|
fn led_state_changed(&mut self, seat: &smithay::input::Seat<Self>, led_state: LedState) {
|
|
|
|
|
let userdata = seat.user_data();
|
|
|
|
|
let devices = userdata.get::<Devices>().unwrap();
|
|
|
|
|
devices.update_led_state(led_state);
|
|
|
|
|
}
|
2022-07-04 15:26:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate_seat!(State);
|