autocommit 2022-02-05 18:14:24 CET
This commit is contained in:
parent
2d8b3a200e
commit
3a4ae99b9a
71 changed files with 1626 additions and 1306 deletions
|
|
@ -2,16 +2,17 @@ use crate::backend::{KeyState, OutputId, ScrollAxis, SeatEvent, SeatId};
|
|||
use crate::client::{ClientId, DynEventFormatter};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_data_device::WlDataDevice;
|
||||
use crate::ifs::wl_data_offer::{WlDataOfferId};
|
||||
use crate::ifs::wl_data_offer::WlDataOfferId;
|
||||
use crate::ifs::wl_seat::wl_keyboard::WlKeyboard;
|
||||
use crate::ifs::wl_seat::wl_pointer::{WlPointer, POINTER_FRAME_SINCE_VERSION};
|
||||
use crate::ifs::wl_seat::{
|
||||
wl_keyboard, wl_pointer, PointerGrab, PointerGrabber, WlSeatGlobal, WlSeatObj,
|
||||
wl_keyboard, wl_pointer, PointerGrab, PointerGrabber, WlSeat, WlSeatGlobal,
|
||||
};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
use crate::ifs::wl_surface::WlSurface;
|
||||
use crate::ifs::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1;
|
||||
use crate::tree::{FloatNode, FoundNode, Node};
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
use crate::xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP};
|
||||
|
|
@ -257,7 +258,7 @@ impl WlSeatGlobal {
|
|||
|
||||
fn for_each_seat<C>(&self, ver: u32, client: ClientId, mut f: C)
|
||||
where
|
||||
C: FnMut(&Rc<WlSeatObj>),
|
||||
C: FnMut(&Rc<WlSeat>),
|
||||
{
|
||||
let bindings = self.bindings.borrow();
|
||||
if let Some(hm) = bindings.get(&client) {
|
||||
|
|
@ -307,6 +308,20 @@ impl WlSeatGlobal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn for_each_primary_selection_device<C>(&self, ver: u32, client: ClientId, mut f: C)
|
||||
where
|
||||
C: FnMut(&Rc<ZwpPrimarySelectionDeviceV1>),
|
||||
{
|
||||
let dd = self.primary_selection_devices.borrow_mut();
|
||||
if let Some(dd) = dd.get(&client) {
|
||||
for dd in dd.values() {
|
||||
if dd.manager.version >= ver {
|
||||
f(dd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn surface_pointer_frame(&self, surface: &WlSurface) {
|
||||
self.surface_pointer_event(POINTER_FRAME_SINCE_VERSION, surface, |p| p.frame());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,14 @@ use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardId, REPEAT_INFO_SIN
|
|||
use crate::ifs::wl_seat::wl_pointer::{WlPointer, WlPointerId};
|
||||
use crate::ifs::wl_seat::wl_touch::WlTouch;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::ifs::zwp_primary_selection_device_v1::{
|
||||
ZwpPrimarySelectionDeviceV1, ZwpPrimarySelectionDeviceV1Id,
|
||||
};
|
||||
use crate::ifs::zwp_primary_selection_offer_v1::ZwpPrimarySelectionOfferV1Id;
|
||||
use crate::ifs::zwp_primary_selection_source_v1::{
|
||||
ZwpPrimarySelectionSourceV1, ZwpPrimarySelectionSourceV1Error,
|
||||
};
|
||||
use crate::object::{Interface, Object};
|
||||
use crate::tree::{FloatNode, FoundNode, Node};
|
||||
use crate::utils::asyncevent::AsyncEvent;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
|
|
@ -88,8 +95,14 @@ pub struct WlSeatGlobal {
|
|||
toplevel_focus_history: LinkedList<Rc<XdgToplevel>>,
|
||||
keyboard_node: CloneCell<Rc<dyn Node>>,
|
||||
pressed_keys: RefCell<AHashSet<u32>>,
|
||||
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeatObj>>>>,
|
||||
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeat>>>>,
|
||||
data_devices: RefCell<AHashMap<ClientId, AHashMap<WlDataDeviceId, Rc<WlDataDevice>>>>,
|
||||
primary_selection_devices: RefCell<
|
||||
AHashMap<
|
||||
ClientId,
|
||||
AHashMap<ZwpPrimarySelectionDeviceV1Id, Rc<ZwpPrimarySelectionDeviceV1>>,
|
||||
>,
|
||||
>,
|
||||
kb_state: RefCell<XkbState>,
|
||||
layout: Rc<OwnedFd>,
|
||||
layout_size: u32,
|
||||
|
|
@ -98,6 +111,7 @@ pub struct WlSeatGlobal {
|
|||
grabber: RefCell<Option<PointerGrabber>>,
|
||||
tree_changed: Rc<AsyncEvent>,
|
||||
selection: CloneCell<Option<Rc<WlDataSource>>>,
|
||||
primary_selection: CloneCell<Option<Rc<ZwpPrimarySelectionSourceV1>>>,
|
||||
}
|
||||
|
||||
impl WlSeatGlobal {
|
||||
|
|
@ -140,6 +154,7 @@ impl WlSeatGlobal {
|
|||
pressed_keys: RefCell::new(Default::default()),
|
||||
bindings: Default::default(),
|
||||
data_devices: RefCell::new(Default::default()),
|
||||
primary_selection_devices: RefCell::new(Default::default()),
|
||||
kb_state: RefCell::new(kb_state),
|
||||
layout,
|
||||
layout_size,
|
||||
|
|
@ -148,10 +163,14 @@ impl WlSeatGlobal {
|
|||
grabber: RefCell::new(None),
|
||||
tree_changed: tree_changed.clone(),
|
||||
selection: Default::default(),
|
||||
primary_selection: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_selection(self: &Rc<Self>, selection: Option<Rc<WlDataSource>>) -> Result<(), WlDataSourceError> {
|
||||
pub fn set_selection(
|
||||
self: &Rc<Self>,
|
||||
selection: Option<Rc<WlDataSource>>,
|
||||
) -> Result<(), WlDataSourceError> {
|
||||
if let Some(new) = &selection {
|
||||
new.attach(self, DataOfferRole::Selection)?;
|
||||
}
|
||||
|
|
@ -169,6 +188,33 @@ impl WlSeatGlobal {
|
|||
});
|
||||
}
|
||||
}
|
||||
client.flush();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_primary_selection(
|
||||
self: &Rc<Self>,
|
||||
selection: Option<Rc<ZwpPrimarySelectionSourceV1>>,
|
||||
) -> Result<(), ZwpPrimarySelectionSourceV1Error> {
|
||||
if let Some(new) = &selection {
|
||||
new.attach(self)?;
|
||||
}
|
||||
if let Some(old) = self.primary_selection.set(selection.clone()) {
|
||||
old.detach();
|
||||
}
|
||||
if let Some(client) = self.keyboard_node.get().client() {
|
||||
match selection {
|
||||
Some(sel) => {
|
||||
sel.create_offer(&client);
|
||||
}
|
||||
_ => {
|
||||
self.for_each_primary_selection_device(0, client.id, |device| {
|
||||
client.event(device.selection(ZwpPrimarySelectionOfferV1Id::NONE));
|
||||
});
|
||||
}
|
||||
}
|
||||
client.flush();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -219,7 +265,7 @@ impl WlSeatGlobal {
|
|||
client: &Rc<Client>,
|
||||
version: u32,
|
||||
) -> Result<(), WlSeatError> {
|
||||
let obj = Rc::new(WlSeatObj {
|
||||
let obj = Rc::new(WlSeat {
|
||||
global: self.clone(),
|
||||
id,
|
||||
client: client.clone(),
|
||||
|
|
@ -265,7 +311,9 @@ impl Global for WlSeatGlobal {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct WlSeatObj {
|
||||
dedicated_add_global!(WlSeatGlobal, seats);
|
||||
|
||||
pub struct WlSeat {
|
||||
pub global: Rc<WlSeatGlobal>,
|
||||
id: WlSeatId,
|
||||
client: Rc<Client>,
|
||||
|
|
@ -274,7 +322,7 @@ pub struct WlSeatObj {
|
|||
version: u32,
|
||||
}
|
||||
|
||||
impl WlSeatObj {
|
||||
impl WlSeat {
|
||||
fn capabilities(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(Capabilities {
|
||||
obj: self.clone(),
|
||||
|
|
@ -306,6 +354,23 @@ impl WlSeatObj {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_primary_selection_device(&self, device: &Rc<ZwpPrimarySelectionDeviceV1>) {
|
||||
let mut dd = self.global.primary_selection_devices.borrow_mut();
|
||||
dd.entry(self.client.id)
|
||||
.or_default()
|
||||
.insert(device.id, device.clone());
|
||||
}
|
||||
|
||||
pub fn remove_primary_selection_device(&self, device: &ZwpPrimarySelectionDeviceV1) {
|
||||
let mut dd = self.global.primary_selection_devices.borrow_mut();
|
||||
if let Entry::Occupied(mut e) = dd.entry(self.client.id) {
|
||||
e.get_mut().remove(&device.id);
|
||||
if e.get().is_empty() {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_(&self, node: &Rc<FloatNode>) {
|
||||
self.global.move_(node);
|
||||
}
|
||||
|
|
@ -349,34 +414,18 @@ impl WlSeatObj {
|
|||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_request_(
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSeatError> {
|
||||
match request {
|
||||
GET_POINTER => self.get_pointer(parser)?,
|
||||
GET_KEYBOARD => self.get_keyboard(parser)?,
|
||||
GET_TOUCH => self.get_touch(parser)?,
|
||||
RELEASE => self.release(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlSeatObj);
|
||||
object_base! {
|
||||
WlSeat, WlSeatError;
|
||||
|
||||
impl Object for WlSeatObj {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlSeat
|
||||
}
|
||||
GET_POINTER => get_pointer,
|
||||
GET_KEYBOARD => get_keyboard,
|
||||
GET_TOUCH => get_touch,
|
||||
RELEASE => release,
|
||||
}
|
||||
|
||||
impl Object for WlSeat {
|
||||
fn num_requests(&self) -> u32 {
|
||||
if self.version < 5 {
|
||||
GET_TOUCH + 1
|
||||
|
|
@ -396,3 +445,5 @@ impl Object for WlSeatObj {
|
|||
self.keyboards.clear();
|
||||
}
|
||||
}
|
||||
|
||||
dedicated_add_obj!(WlSeat, WlSeatId, seats);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client::{ClientError, EventFormatter, RequestParser};
|
|||
use crate::ifs::wl_seat::wl_keyboard::{WlKeyboardError, WlKeyboardId};
|
||||
use crate::ifs::wl_seat::wl_pointer::WlPointerId;
|
||||
use crate::ifs::wl_seat::wl_touch::WlTouchId;
|
||||
use crate::ifs::wl_seat::{WlSeatObj, CAPABILITIES, NAME};
|
||||
use crate::ifs::wl_seat::{WlSeat, CAPABILITIES, NAME};
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
|
@ -128,7 +128,7 @@ impl Debug for Release {
|
|||
}
|
||||
|
||||
pub(super) struct Capabilities {
|
||||
pub obj: Rc<WlSeatObj>,
|
||||
pub obj: Rc<WlSeat>,
|
||||
pub capabilities: u32,
|
||||
}
|
||||
impl EventFormatter for Capabilities {
|
||||
|
|
@ -147,7 +147,7 @@ impl Debug for Capabilities {
|
|||
}
|
||||
|
||||
pub(super) struct Name {
|
||||
pub obj: Rc<WlSeatObj>,
|
||||
pub obj: Rc<WlSeat>,
|
||||
pub name: Rc<String>,
|
||||
}
|
||||
impl EventFormatter for Name {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::ifs::wl_seat::WlSeat;
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -33,11 +33,11 @@ id!(WlKeyboardId);
|
|||
|
||||
pub struct WlKeyboard {
|
||||
id: WlKeyboardId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
seat: Rc<WlSeat>,
|
||||
}
|
||||
|
||||
impl WlKeyboard {
|
||||
pub fn new(id: WlKeyboardId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
pub fn new(id: WlKeyboardId, seat: &Rc<WlSeat>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
|
|
@ -152,32 +152,18 @@ impl WlKeyboard {
|
|||
self.seat.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlKeyboardError> {
|
||||
match request {
|
||||
RELEASE => self.release(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlKeyboard);
|
||||
object_base! {
|
||||
WlKeyboard, WlKeyboardError;
|
||||
|
||||
RELEASE => release,
|
||||
}
|
||||
|
||||
impl Object for WlKeyboard {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlKeyboard
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(WlKeyboard);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ mod types;
|
|||
use crate::client::DynEventFormatter;
|
||||
use crate::cursor::Cursor;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::ifs::wl_seat::WlSeat;
|
||||
use crate::ifs::wl_surface::WlSurfaceId;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -47,11 +47,11 @@ id!(WlPointerId);
|
|||
|
||||
pub struct WlPointer {
|
||||
id: WlPointerId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
seat: Rc<WlSeat>,
|
||||
}
|
||||
|
||||
impl WlPointer {
|
||||
pub fn new(id: WlPointerId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
pub fn new(id: WlPointerId, seat: &Rc<WlSeat>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
|
|
@ -151,7 +151,7 @@ impl WlPointer {
|
|||
let req: SetCursor = self.seat.client.parse(self, parser)?;
|
||||
let mut cursor_opt = None;
|
||||
if req.surface.is_some() {
|
||||
let surface = self.seat.client.get_surface(req.surface)?;
|
||||
let surface = self.seat.client.lookup(req.surface)?;
|
||||
let cursor = surface.get_cursor(&self.seat.global)?;
|
||||
cursor.set_hotspot(req.hotspot_x, req.hotspot_y);
|
||||
cursor_opt = Some(cursor as Rc<dyn Cursor>);
|
||||
|
|
@ -176,33 +176,19 @@ impl WlPointer {
|
|||
self.seat.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlPointerError> {
|
||||
match request {
|
||||
SET_CURSOR => self.set_cursor(parser)?,
|
||||
RELEASE => self.release(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlPointer);
|
||||
object_base! {
|
||||
WlPointer, WlPointerError;
|
||||
|
||||
SET_CURSOR => set_cursor,
|
||||
RELEASE => release,
|
||||
}
|
||||
|
||||
impl Object for WlPointer {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlPointer
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(WlPointer);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_seat::WlSeatObj;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::ifs::wl_seat::WlSeat;
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -27,11 +27,11 @@ id!(WlTouchId);
|
|||
|
||||
pub struct WlTouch {
|
||||
id: WlTouchId,
|
||||
seat: Rc<WlSeatObj>,
|
||||
seat: Rc<WlSeat>,
|
||||
}
|
||||
|
||||
impl WlTouch {
|
||||
pub fn new(id: WlTouchId, seat: &Rc<WlSeatObj>) -> Self {
|
||||
pub fn new(id: WlTouchId, seat: &Rc<WlSeat>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
seat: seat.clone(),
|
||||
|
|
@ -43,28 +43,18 @@ impl WlTouch {
|
|||
self.seat.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_request_(&self, request: u32, parser: MsgParser<'_, '_>) -> Result<(), WlTouchError> {
|
||||
match request {
|
||||
RELEASE => self.release(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlTouch);
|
||||
object_base! {
|
||||
WlTouch, WlTouchError;
|
||||
|
||||
RELEASE => release,
|
||||
}
|
||||
|
||||
impl Object for WlTouch {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id.into()
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlTouch
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RELEASE + 1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(WlTouch);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue