@@ -13,9 +13,7 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
|
|||||||
Registry(const_mutex(None))
|
Registry(const_mutex(None))
|
||||||
}
|
}
|
||||||
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Weak<T>>> {
|
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Weak<T>>> {
|
||||||
MutexGuard::map(self.0.lock(), |r| {
|
MutexGuard::map(self.0.lock(), |r| r.get_or_insert_with(FxHashMap::default))
|
||||||
r.get_or_insert_with(FxHashMap::default)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
pub fn add(&self, t: T) -> Arc<T>
|
pub fn add(&self, t: T) -> Arc<T>
|
||||||
where
|
where
|
||||||
@@ -118,9 +116,7 @@ impl<T: Send + Sync + ?Sized> OwnedRegistry<T> {
|
|||||||
OwnedRegistry(const_mutex(None))
|
OwnedRegistry(const_mutex(None))
|
||||||
}
|
}
|
||||||
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Arc<T>>> {
|
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Arc<T>>> {
|
||||||
MutexGuard::map(self.0.lock(), |r| {
|
MutexGuard::map(self.0.lock(), |r| r.get_or_insert_with(FxHashMap::default))
|
||||||
r.get_or_insert_with(FxHashMap::default)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
pub fn add(&self, t: T) -> Arc<T>
|
pub fn add(&self, t: T) -> Arc<T>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -4,72 +4,95 @@ pub mod sk_controller;
|
|||||||
pub mod sk_hand;
|
pub mod sk_hand;
|
||||||
|
|
||||||
use crate::nodes::{
|
use crate::nodes::{
|
||||||
fields::{Field, FieldTrait, Ray}, input::{InputDataTrait, InputDataType, InputHandler, InputMethod, INPUT_HANDLER_REGISTRY}, spatial::Spatial
|
fields::{Field, FieldTrait, Ray},
|
||||||
|
input::{InputDataTrait, InputDataType, InputHandler, InputMethod, INPUT_HANDLER_REGISTRY},
|
||||||
|
spatial::Spatial,
|
||||||
};
|
};
|
||||||
use glam::vec3;
|
use glam::vec3;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CaptureManager {
|
pub struct CaptureManager {
|
||||||
pub capture: Option<Arc<InputHandler>>,
|
pub capture: Option<Arc<InputHandler>>,
|
||||||
}
|
}
|
||||||
impl CaptureManager {
|
impl CaptureManager {
|
||||||
pub fn update_capture(&mut self, pointer: &InputMethod) {
|
pub fn update_capture(&mut self, pointer: &InputMethod) {
|
||||||
if let Some(capture) = &self.capture {
|
if let Some(capture) = &self.capture {
|
||||||
if !pointer.internal_capture_requests.get_valid_contents().contains(capture) {
|
if !pointer
|
||||||
self.capture.take();
|
.internal_capture_requests
|
||||||
}
|
.get_valid_contents()
|
||||||
}
|
.contains(capture)
|
||||||
}
|
{
|
||||||
pub fn set_new_capture(&mut self, pointer: &InputMethod, distance_calculator: DistanceCalculator) {
|
self.capture.take();
|
||||||
if self.capture.is_none() {
|
}
|
||||||
self.capture = find_closest_capture(pointer, distance_calculator);
|
}
|
||||||
}
|
}
|
||||||
}
|
pub fn set_new_capture(
|
||||||
pub fn apply_capture(&self, method: &InputMethod) {
|
&mut self,
|
||||||
method.captures.clear();
|
pointer: &InputMethod,
|
||||||
if let Some(capture) = &self.capture {
|
distance_calculator: DistanceCalculator,
|
||||||
method.set_handler_order([capture].into_iter());
|
) {
|
||||||
method.captures.add_raw(capture);
|
if self.capture.is_none() {
|
||||||
}
|
self.capture = find_closest_capture(pointer, distance_calculator);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
pub fn apply_capture(&self, method: &InputMethod) {
|
||||||
|
method.captures.clear();
|
||||||
|
if let Some(capture) = &self.capture {
|
||||||
|
method.set_handler_order([capture].into_iter());
|
||||||
|
method.captures.add_raw(capture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type DistanceCalculator = fn(&Arc<Spatial>, &InputDataType, &Field) -> Option<f32>;
|
type DistanceCalculator = fn(&Arc<Spatial>, &InputDataType, &Field) -> Option<f32>;
|
||||||
|
|
||||||
pub fn find_closest_capture(method: &InputMethod, distance_calculator: DistanceCalculator) -> Option<Arc<InputHandler>> {
|
pub fn find_closest_capture(
|
||||||
method
|
method: &InputMethod,
|
||||||
.internal_capture_requests
|
distance_calculator: DistanceCalculator,
|
||||||
.get_valid_contents()
|
) -> Option<Arc<InputHandler>> {
|
||||||
.into_iter()
|
method
|
||||||
.filter_map(|h| distance_calculator(&method.spatial, &method.data.lock(), &h.field).map(|dist| (h.clone(), dist)))
|
.internal_capture_requests
|
||||||
.min_by(|(_, dist_a), (_, dist_b)| dist_a.partial_cmp(dist_b).unwrap())
|
.get_valid_contents()
|
||||||
.map(|(handler, _)| handler)
|
.into_iter()
|
||||||
|
.filter_map(|h| {
|
||||||
|
distance_calculator(&method.spatial, &method.data.lock(), &h.field)
|
||||||
|
.map(|dist| (h.clone(), dist))
|
||||||
|
})
|
||||||
|
.min_by(|(_, dist_a), (_, dist_b)| dist_a.partial_cmp(dist_b).unwrap())
|
||||||
|
.map(|(handler, _)| handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sorted_handlers(method: &InputMethod, distance_calculator: DistanceCalculator) -> Vec<Arc<InputHandler>> {
|
pub fn get_sorted_handlers(
|
||||||
INPUT_HANDLER_REGISTRY
|
method: &InputMethod,
|
||||||
.get_valid_contents()
|
distance_calculator: DistanceCalculator,
|
||||||
.into_iter()
|
) -> Vec<Arc<InputHandler>> {
|
||||||
.filter(|handler| handler.spatial.node().map_or(false, |node| node.enabled()))
|
INPUT_HANDLER_REGISTRY
|
||||||
.filter(|handler| handler.field.spatial.node().map_or(false, |node| node.enabled()))
|
.get_valid_contents()
|
||||||
.filter_map(|handler| {
|
.into_iter()
|
||||||
distance_calculator(&method.spatial, &method.data.lock(), &handler.field)
|
.filter(|handler| handler.spatial.node().map_or(false, |node| node.enabled()))
|
||||||
.map(|distance| (vec![handler], distance))
|
.filter(|handler| {
|
||||||
})
|
handler
|
||||||
.filter(|(_, distance)| *distance > 0.0)
|
.field
|
||||||
.reduce(|(mut handlers_a, distance_a), (handlers_b, distance_b)| {
|
.spatial
|
||||||
if (distance_a - distance_b).abs() < 0.001 {
|
.node()
|
||||||
handlers_a.extend(handlers_b);
|
.map_or(false, |node| node.enabled())
|
||||||
(handlers_a, distance_a)
|
})
|
||||||
} else if distance_a < distance_b {
|
.filter_map(|handler| {
|
||||||
(handlers_a, distance_a)
|
distance_calculator(&method.spatial, &method.data.lock(), &handler.field)
|
||||||
} else {
|
.map(|distance| (vec![handler], distance))
|
||||||
(handlers_b, distance_b)
|
})
|
||||||
}
|
.filter(|(_, distance)| *distance > 0.0)
|
||||||
})
|
.reduce(|(mut handlers_a, distance_a), (handlers_b, distance_b)| {
|
||||||
.map(|(handlers, _)| handlers)
|
if (distance_a - distance_b).abs() < 0.001 {
|
||||||
.unwrap_or_default()
|
handlers_a.extend(handlers_b);
|
||||||
|
(handlers_a, distance_a)
|
||||||
|
} else if distance_a < distance_b {
|
||||||
|
(handlers_a, distance_a)
|
||||||
|
} else {
|
||||||
|
(handlers_b, distance_b)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|(handlers, _)| handlers)
|
||||||
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ impl KdeDecorationHandler for WaylandState {
|
|||||||
decoration: &OrgKdeKwinServerDecoration,
|
decoration: &OrgKdeKwinServerDecoration,
|
||||||
mode: WEnum<KdeMode>,
|
mode: WEnum<KdeMode>,
|
||||||
) {
|
) {
|
||||||
let Ok(mode) = mode.into_result() else {return};
|
let Ok(mode) = mode.into_result() else { return };
|
||||||
decoration.mode(mode);
|
decoration.mode(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user