1
0
Fork 0
forked from wry/wry

autocommit 2022-04-10 01:54:16 CEST

This commit is contained in:
Julian Orth 2022-04-10 01:54:16 +02:00
parent befd5e99b2
commit af152f7f3e
6 changed files with 49 additions and 5 deletions

View file

@ -14,6 +14,7 @@ use {
},
std::rc::Rc,
};
use crate::ifs::wl_seat::PX_PER_SCROLL;
macro_rules! unpack {
($slf:expr, $ev:expr) => {{
@ -121,7 +122,6 @@ impl MetalBackend {
}
fn handle_pointer_axis(self: &Rc<Self>, event: LibInputEvent, source: AxisSource) {
const PX_PER_SCROLL: f64 = 15.0;
const ONE_TWENTRY: f64 = 120.0;
let (event, dev) = unpack!(self, event, pointer_event);
let axes = [

View file

@ -54,6 +54,7 @@ use {
},
thiserror::Error,
};
use crate::ifs::wl_seat::PX_PER_SCROLL;
#[derive(Debug, Error)]
pub enum XBackendError {
@ -729,7 +730,7 @@ impl XBackendData {
};
seat.mouse_event(InputEvent::AxisSource(AxisSource::Wheel));
seat.mouse_event(InputEvent::AxisDiscrete(val, axis));
seat.mouse_event(InputEvent::Axis(Fixed::from_int(val * 15), axis));
seat.mouse_event(InputEvent::Axis((val as f64 * PX_PER_SCROLL).into(), axis));
seat.mouse_event(InputEvent::Frame);
}
} else {

View file

@ -74,6 +74,8 @@ pub const BTN_LEFT: u32 = 0x110;
pub const SEAT_NAME_SINCE: u32 = 2;
pub const PX_PER_SCROLL: f64 = 15.0;
#[derive(Clone)]
pub struct Dnd {
pub seat: Rc<WlSeatGlobal>,

View file

@ -799,8 +799,8 @@ impl Node for WlSurface {
seat.button_surface(&self, button, state);
}
fn axis_event(&self, seat: &WlSeatGlobal, event: &PendingScroll) {
seat.scroll_surface(self, event);
fn axis_event(self: Rc<Self>, seat: &WlSeatGlobal, event: &PendingScroll) {
seat.scroll_surface(&*self, event);
}
fn focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>) {

View file

@ -197,7 +197,7 @@ pub trait Node {
let _ = state;
}
fn axis_event(&self, seat: &WlSeatGlobal, event: &PendingScroll) {
fn axis_event(self: Rc<Self>, seat: &WlSeatGlobal, event: &PendingScroll) {
let _ = seat;
let _ = event;
}

View file

@ -32,6 +32,8 @@ use {
rc::Rc,
},
};
use crate::ifs::wl_seat::PX_PER_SCROLL;
use crate::ifs::wl_seat::wl_pointer::{PendingScroll, VERTICAL_SCROLL};
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -111,6 +113,7 @@ pub struct ContainerNode {
state: Rc<State>,
pub render_data: RefCell<ContainerRenderData>,
visible: Cell<bool>,
scroll: Cell<f64>,
}
impl Debug for ContainerNode {
@ -209,6 +212,7 @@ impl ContainerNode {
state: state.clone(),
render_data: Default::default(),
visible: Cell::new(false),
scroll: Cell::new(0.0),
});
child.set_parent(slf.clone());
slf
@ -1044,6 +1048,43 @@ impl Node for ContainerNode {
}
}
fn axis_event(self: Rc<Self>, seat: &WlSeatGlobal, event: &PendingScroll) {
let mut seat_datas = self.seats.borrow_mut();
let seat_data = match seat_datas.get_mut(&seat.id()) {
Some(s) => s,
_ => return,
};
if seat_data.y > self.state.theme.title_height.get() {
return;
}
let cur_mc = match self.mono_child.get() {
Some(mc) => mc,
_ => return,
};
let scroll = match event.axis[VERTICAL_SCROLL as usize].get() {
Some(s) => s,
_ => return,
};
let mut scroll = self.scroll.get() + f64::from(scroll);
let discrete = (scroll / PX_PER_SCROLL).round();
scroll -= discrete * PX_PER_SCROLL;
self.scroll.set(scroll);
let discrete = discrete as i32;
let mut new_mc = cur_mc.clone();
for _ in 0..discrete.abs() {
let new = if discrete < 0 {
new_mc.prev()
} else {
new_mc.next()
};
new_mc = match new {
Some(n) => n,
None => break,
};
}
self.activate_child(&new_mc);
}
fn focus_parent(&self, seat: &Rc<WlSeatGlobal>) {
self.parent.get().focus_self(seat);
}