wayland: implement wl_seat v8
This commit is contained in:
parent
145e4dbc24
commit
50c87d6da7
10 changed files with 111 additions and 80 deletions
|
|
@ -1,27 +1,45 @@
|
|||
use {
|
||||
crate::ifs::wl_seat::{
|
||||
wl_pointer::{PendingScroll, VERTICAL_SCROLL},
|
||||
PX_PER_SCROLL,
|
||||
crate::{
|
||||
backend::AXIS_120,
|
||||
ifs::wl_seat::{
|
||||
wl_pointer::{PendingScroll, VERTICAL_SCROLL},
|
||||
PX_PER_SCROLL,
|
||||
},
|
||||
},
|
||||
std::cell::Cell,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Scroller {
|
||||
scroll: Cell<f64>,
|
||||
v120: Cell<i32>,
|
||||
smooth: Cell<f64>,
|
||||
}
|
||||
|
||||
impl Scroller {
|
||||
pub fn handle(&self, scroll: &PendingScroll) -> Option<i32> {
|
||||
if let Some(d) = scroll.discrete[VERTICAL_SCROLL as usize].get() {
|
||||
self.scroll.set(0.0);
|
||||
Some(d)
|
||||
} else if let Some(scroll) = scroll.axis[VERTICAL_SCROLL as usize].get() {
|
||||
let mut scroll = self.scroll.get() + scroll.to_f64();
|
||||
let discrete = (scroll / PX_PER_SCROLL).trunc();
|
||||
scroll -= discrete * PX_PER_SCROLL;
|
||||
self.scroll.set(scroll);
|
||||
Some(discrete as i32)
|
||||
let n = if let Some(d) = scroll.v120[VERTICAL_SCROLL as usize].get() {
|
||||
self.smooth.set(0.0);
|
||||
let mut v120 = self.v120.get() + d;
|
||||
let discrete = v120 / AXIS_120;
|
||||
v120 -= discrete * AXIS_120;
|
||||
self.v120.set(v120);
|
||||
discrete
|
||||
} else if let Some(smooth) = scroll.smooth[VERTICAL_SCROLL as usize].get() {
|
||||
self.v120.set(0);
|
||||
let mut smooth = self.smooth.get() + smooth.to_f64();
|
||||
let discrete = (smooth / PX_PER_SCROLL).trunc();
|
||||
smooth -= discrete * PX_PER_SCROLL;
|
||||
self.smooth.set(smooth);
|
||||
discrete as _
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if scroll.stop[VERTICAL_SCROLL as usize].get() {
|
||||
self.v120.set(0);
|
||||
self.smooth.set(0.0);
|
||||
}
|
||||
if n != 0 {
|
||||
Some(n)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue