cosmic-comp/src/wayland/handlers/seat.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
2022-07-04 16:00:29 +02:00
use crate::state::State;
use smithay::{
delegate_seat,
2022-08-31 13:01:23 +02:00
input::{pointer::CursorImageStatus, SeatHandler, SeatState},
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
wayland::{data_device::set_data_device_focus, primary_selection::set_primary_focus},
};
2022-08-31 13:01:23 +02:00
use std::cell::RefCell;
impl SeatHandler for State {
2022-08-31 13:01:23 +02:00
type KeyboardFocus = WlSurface;
type PointerFocus = WlSurface;
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;
if let Some(client) = focused.and_then(|s| dh.get_client(s.id()).ok()) {
set_data_device_focus(dh, seat, Some(client));
let client2 = focused.and_then(|s| dh.get_client(s.id()).ok()).unwrap();
set_primary_focus(dh, seat, Some(client2))
}
}
}
delegate_seat!(State);