1
0
Fork 0
forked from wry/wry

keyboard: move KeyboardState to dedicated module

This commit is contained in:
Julian Orth 2025-01-07 11:48:10 +01:00
parent 1a35ba3909
commit e7d5a23af3
16 changed files with 60 additions and 43 deletions

View file

@ -6,6 +6,7 @@ use {
ei_ifs::ei_device::{EiDevice, EiDeviceInterface}, ei_ifs::ei_device::{EiDevice, EiDeviceInterface},
ei_object::{EiObject, EiVersion}, ei_object::{EiObject, EiVersion},
}, },
keyboard::KeyboardState,
leaks::Tracker, leaks::Tracker,
wire_ei::{ wire_ei::{
ei_keyboard::{ ei_keyboard::{
@ -13,7 +14,6 @@ use {
}, },
EiKeyboardId, EiKeyboardId,
}, },
xkbcommon::KeyboardState,
}, },
std::rc::Rc, std::rc::Rc,
thiserror::Error, thiserror::Error,

View file

@ -17,6 +17,7 @@ use {
}, },
fixed::Fixed, fixed::Fixed,
ifs::wl_seat::{wl_pointer::PendingScroll, WlSeatGlobal}, ifs::wl_seat::{wl_pointer::PendingScroll, WlSeatGlobal},
keyboard::{DynKeyboardState, KeyboardState, KeyboardStateId},
leaks::Tracker, leaks::Tracker,
tree::Node, tree::Node,
utils::{array, bitflags::BitflagsExt, clonecell::CloneCell}, utils::{array, bitflags::BitflagsExt, clonecell::CloneCell},
@ -26,7 +27,6 @@ use {
}, },
EiSeatId, EiSeatId,
}, },
xkbcommon::{DynKeyboardState, KeyboardState, KeyboardStateId},
}, },
std::{cell::Cell, rc::Rc}, std::{cell::Cell, rc::Rc},
thiserror::Error, thiserror::Error,

View file

@ -11,10 +11,10 @@ use {
wl_pointer::PendingScroll, wl_pointer::PendingScroll,
SeatId, SeatId,
}, },
keyboard::ModifierState,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
wire::{jay_seat_events::*, JaySeatEventsId}, wire::{jay_seat_events::*, JaySeatEventsId},
xkbcommon::ModifierState,
}, },
std::{convert::Infallible, rc::Rc}, std::{convert::Infallible, rc::Rc},
}; };

View file

@ -72,6 +72,7 @@ use {
}, },
xdg_toplevel_drag_v1::XdgToplevelDragV1, xdg_toplevel_drag_v1::XdgToplevelDragV1,
}, },
keyboard::{DynKeyboardState, KeyboardState},
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
rect::Rect, rect::Rect,
@ -91,7 +92,7 @@ use {
ZwpTextInputV3Id, ZwpTextInputV3Id,
}, },
wire_ei::EiSeatId, wire_ei::EiSeatId,
xkbcommon::{DynKeyboardState, KeyboardState, KeymapId, XkbKeymap, XkbState}, xkbcommon::{KeymapId, XkbKeymap, XkbState},
}, },
ahash::AHashMap, ahash::AHashMap,
smallvec::SmallVec, smallvec::SmallVec,

View file

@ -33,13 +33,14 @@ use {
}, },
wl_surface::{xdg_surface::xdg_popup::XdgPopup, WlSurface}, wl_surface::{xdg_surface::xdg_popup::XdgPopup, WlSurface},
}, },
keyboard::KeyboardState,
object::Version, object::Version,
rect::Rect, rect::Rect,
state::DeviceHandlerData, state::DeviceHandlerData,
tree::{Direction, Node, ToplevelNode}, tree::{Direction, Node, ToplevelNode},
utils::{bitflags::BitflagsExt, hash_map_ext::HashMapExt, smallmap::SmallMap}, utils::{bitflags::BitflagsExt, hash_map_ext::HashMapExt, smallmap::SmallMap},
wire::WlDataOfferId, wire::WlDataOfferId,
xkbcommon::{KeyboardState, XkbState, XKB_KEY_DOWN, XKB_KEY_UP}, xkbcommon::{XkbState, XKB_KEY_DOWN, XKB_KEY_UP},
}, },
isnt::std_1::primitive::{IsntSlice2Ext, IsntSliceExt}, isnt::std_1::primitive::{IsntSlice2Ext, IsntSliceExt},
jay_config::{ jay_config::{

View file

@ -2,11 +2,11 @@ use {
crate::{ crate::{
client::{Client, ClientError}, client::{Client, ClientError},
ifs::wl_seat::{text_input::zwp_input_method_v2::ZwpInputMethodV2, wl_keyboard}, ifs::wl_seat::{text_input::zwp_input_method_v2::ZwpInputMethodV2, wl_keyboard},
keyboard::{KeyboardState, KeyboardStateId},
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
utils::errorfmt::ErrorFmt, utils::errorfmt::ErrorFmt,
wire::{zwp_input_method_keyboard_grab_v2::*, ZwpInputMethodKeyboardGrabV2Id}, wire::{zwp_input_method_keyboard_grab_v2::*, ZwpInputMethodKeyboardGrabV2Id},
xkbcommon::{KeyboardState, KeyboardStateId},
}, },
std::{cell::Cell, rc::Rc}, std::{cell::Cell, rc::Rc},
thiserror::Error, thiserror::Error,

View file

@ -13,11 +13,11 @@ use {
ZwpInputPopupSurfaceV2, ZwpInputPopupSurfaceV2Error, ZwpInputPopupSurfaceV2, ZwpInputPopupSurfaceV2Error,
}, },
}, },
keyboard::KeyboardStateId,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
utils::{clonecell::CloneCell, numcell::NumCell, smallmap::SmallMap}, utils::{clonecell::CloneCell, numcell::NumCell, smallmap::SmallMap},
wire::{zwp_input_method_v2::*, ZwpInputMethodV2Id, ZwpInputPopupSurfaceV2Id}, wire::{zwp_input_method_v2::*, ZwpInputMethodV2Id, ZwpInputPopupSurfaceV2Id},
xkbcommon::KeyboardStateId,
}, },
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},

View file

@ -2,11 +2,12 @@ use {
crate::{ crate::{
client::ClientError, client::ClientError,
ifs::wl_seat::WlSeat, ifs::wl_seat::WlSeat,
keyboard::{KeyboardState, KeyboardStateId, ModifierState},
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
utils::errorfmt::ErrorFmt, utils::errorfmt::ErrorFmt,
wire::{wl_keyboard::*, WlKeyboardId, WlSurfaceId}, wire::{wl_keyboard::*, WlKeyboardId, WlSurfaceId},
xkbcommon::{KeyboardState, KeyboardStateId, ModifierState, XkbCommonError}, xkbcommon::XkbCommonError,
}, },
std::{cell::Cell, rc::Rc}, std::{cell::Cell, rc::Rc},
thiserror::Error, thiserror::Error,

View file

@ -3,10 +3,10 @@ use {
client::{Client, ClientCaps, ClientError, CAP_VIRTUAL_KEYBOARD_MANAGER}, client::{Client, ClientCaps, ClientError, CAP_VIRTUAL_KEYBOARD_MANAGER},
globals::{Global, GlobalName}, globals::{Global, GlobalName},
ifs::wl_seat::zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1, ifs::wl_seat::zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1,
keyboard::KeyboardState,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
wire::{zwp_virtual_keyboard_manager_v1::*, ZwpVirtualKeyboardManagerV1Id}, wire::{zwp_virtual_keyboard_manager_v1::*, ZwpVirtualKeyboardManagerV1Id},
xkbcommon::KeyboardState,
}, },
std::{cell::RefCell, rc::Rc}, std::{cell::RefCell, rc::Rc},
thiserror::Error, thiserror::Error,

View file

@ -9,10 +9,11 @@ use {
}, },
wl_surface::WlSurface, wl_surface::WlSurface,
}, },
keyboard::KeyboardState,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
wire::{zwp_virtual_keyboard_v1::*, ZwpVirtualKeyboardV1Id}, wire::{zwp_virtual_keyboard_v1::*, ZwpVirtualKeyboardV1Id},
xkbcommon::{KeyboardState, XkbCommonError}, xkbcommon::XkbCommonError,
}, },
std::{cell::RefCell, rc::Rc}, std::{cell::RefCell, rc::Rc},
thiserror::Error, thiserror::Error,

View file

@ -65,6 +65,7 @@ use {
zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1, zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1,
}, },
io_uring::IoUringError, io_uring::IoUringError,
keyboard::KeyboardState,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
rect::{DamageQueue, Rect, Region}, rect::{DamageQueue, Rect, Region},
@ -88,7 +89,6 @@ use {
wl_surface::*, WlOutputId, WlSurfaceId, ZwpIdleInhibitorV1Id, wl_surface::*, WlOutputId, WlSurfaceId, ZwpIdleInhibitorV1Id,
ZwpLinuxDmabufFeedbackV1Id, ZwpLinuxDmabufFeedbackV1Id,
}, },
xkbcommon::KeyboardState,
xwayland::XWaylandEvent, xwayland::XWaylandEvent,
}, },
ahash::AHashMap, ahash::AHashMap,

37
src/keyboard.rs Normal file
View file

@ -0,0 +1,37 @@
use {
crate::utils::vecset::VecSet,
std::{
cell::{Ref, RefCell},
rc::Rc,
},
uapi::OwnedFd,
};
#[derive(Copy, Clone, Debug, Default)]
pub struct ModifierState {
pub mods_depressed: u32,
pub mods_latched: u32,
pub mods_locked: u32,
pub mods_effective: u32,
pub group: u32,
}
linear_ids!(KeyboardStateIds, KeyboardStateId, u64);
pub struct KeyboardState {
pub id: KeyboardStateId,
pub map: Rc<OwnedFd>,
pub map_len: usize,
pub pressed_keys: VecSet<u32>,
pub mods: ModifierState,
}
pub trait DynKeyboardState {
fn borrow(&self) -> Ref<'_, KeyboardState>;
}
impl DynKeyboardState for RefCell<KeyboardState> {
fn borrow(&self) -> Ref<'_, KeyboardState> {
self.borrow()
}
}

View file

@ -74,6 +74,7 @@ mod ifs;
mod io_uring; mod io_uring;
#[cfg(feature = "it")] #[cfg(feature = "it")]
mod it; mod it;
mod keyboard;
mod libinput; mod libinput;
mod logger; mod logger;
mod logind; mod logind;

View file

@ -66,6 +66,7 @@ use {
zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Global, zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Global,
}, },
io_uring::IoUring, io_uring::IoUring,
keyboard::KeyboardStateIds,
leaks::Tracker, leaks::Tracker,
logger::Logger, logger::Logger,
rect::{Rect, Region}, rect::{Rect, Region},
@ -99,7 +100,7 @@ use {
ExtForeignToplevelListV1Id, ExtIdleNotificationV1Id, JayRenderCtxId, JaySeatEventsId, ExtForeignToplevelListV1Id, ExtIdleNotificationV1Id, JayRenderCtxId, JaySeatEventsId,
JayWorkspaceWatcherId, ZwpLinuxDmabufFeedbackV1Id, JayWorkspaceWatcherId, ZwpLinuxDmabufFeedbackV1Id,
}, },
xkbcommon::{KeyboardStateIds, XkbContext, XkbKeymap, XkbState}, xkbcommon::{XkbContext, XkbKeymap, XkbState},
xwayland::{self, XWaylandEvent}, xwayland::{self, XWaylandEvent},
}, },
ahash::{AHashMap, AHashSet}, ahash::{AHashMap, AHashSet},

View file

@ -15,10 +15,10 @@ use {
}, },
wl_surface::{tray::TrayItemId, WlSurface}, wl_surface::{tray::TrayItemId, WlSurface},
}, },
keyboard::KeyboardState,
rect::Rect, rect::Rect,
renderer::Renderer, renderer::Renderer,
utils::numcell::NumCell, utils::numcell::NumCell,
xkbcommon::KeyboardState,
}, },
jay_config::Direction as JayDirection, jay_config::Direction as JayDirection,
std::{ std::{

View file

@ -6,7 +6,10 @@ include!(concat!(env!("OUT_DIR"), "/xkbcommon_tys.rs"));
pub use consts::*; pub use consts::*;
use { use {
crate::utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, vecset::VecSet}, crate::{
keyboard::{DynKeyboardState, KeyboardState, KeyboardStateId, ModifierState},
utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt},
},
bstr::{BStr, ByteSlice}, bstr::{BStr, ByteSlice},
isnt::std_1::primitive::IsntConstPtrExt, isnt::std_1::primitive::IsntConstPtrExt,
std::{ std::{
@ -252,35 +255,6 @@ impl Drop for XkbKeymapStr {
} }
} }
#[derive(Copy, Clone, Debug, Default)]
pub struct ModifierState {
pub mods_depressed: u32,
pub mods_latched: u32,
pub mods_locked: u32,
pub mods_effective: u32,
pub group: u32,
}
linear_ids!(KeyboardStateIds, KeyboardStateId, u64);
pub struct KeyboardState {
pub id: KeyboardStateId,
pub map: Rc<OwnedFd>,
pub map_len: usize,
pub pressed_keys: VecSet<u32>,
pub mods: ModifierState,
}
pub trait DynKeyboardState {
fn borrow(&self) -> Ref<'_, KeyboardState>;
}
impl DynKeyboardState for RefCell<KeyboardState> {
fn borrow(&self) -> Ref<'_, KeyboardState> {
self.borrow()
}
}
pub struct XkbState { pub struct XkbState {
map: Rc<XkbKeymap>, map: Rc<XkbKeymap>,
state: *mut xkb_state, state: *mut xkb_state,