anvil: Introduce InputInitData to simplify function prototypes

This commit is contained in:
Victor Berger 2020-05-02 12:54:05 +02:00 committed by Victor Berger
parent 35d8cea547
commit 5552c81a32
3 changed files with 41 additions and 45 deletions

View File

@ -38,48 +38,40 @@ pub struct AnvilInputHandler {
running: Arc<AtomicBool>,
}
pub struct InputInitData {
pub pointer: PointerHandle,
pub keyboard: KeyboardHandle,
pub window_map: Rc<RefCell<MyWindowMap>>,
pub screen_size: (u32, u32),
pub running: Arc<AtomicBool>,
pub pointer_location: Rc<RefCell<(f64, f64)>>,
}
impl AnvilInputHandler {
pub fn new(
log: Logger,
pointer: PointerHandle,
keyboard: KeyboardHandle,
window_map: Rc<RefCell<MyWindowMap>>,
screen_size: (u32, u32),
running: Arc<AtomicBool>,
pointer_location: Rc<RefCell<(f64, f64)>>,
) -> AnvilInputHandler {
pub fn new(log: Logger, data: InputInitData) -> AnvilInputHandler {
AnvilInputHandler {
log,
pointer,
keyboard,
window_map,
screen_size,
running,
pointer_location,
pointer: data.pointer,
keyboard: data.keyboard,
window_map: data.window_map,
screen_size: data.screen_size,
running: data.running,
pointer_location: data.pointer_location,
#[cfg(feature = "udev")]
session: None,
}
}
#[cfg(feature = "udev")]
pub fn new_with_session(
log: Logger,
pointer: PointerHandle,
keyboard: KeyboardHandle,
window_map: Rc<RefCell<MyWindowMap>>,
screen_size: (u32, u32),
running: Arc<AtomicBool>,
pointer_location: Rc<RefCell<(f64, f64)>>,
session: AutoSession,
) -> AnvilInputHandler {
pub fn new_with_session(log: Logger, data: InputInitData, session: AutoSession) -> AnvilInputHandler {
AnvilInputHandler {
log,
pointer,
keyboard,
window_map,
screen_size,
running,
pointer_location,
pointer: data.pointer,
keyboard: data.keyboard,
window_map: data.window_map,
screen_size: data.screen_size,
running: data.running,
pointer_location: data.pointer_location,
session: Some(session),
}
}

View File

@ -60,7 +60,7 @@ use smithay::{
use crate::buffer_utils::BufferUtils;
use crate::glium_drawer::GliumDrawer;
use crate::input_handler::AnvilInputHandler;
use crate::input_handler::{AnvilInputHandler, InputInitData};
use crate::shell::{MyWindowMap, Roles};
use crate::state::AnvilState;
@ -205,12 +205,14 @@ pub fn run_udev(
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
libinput_backend.set_handler(AnvilInputHandler::new_with_session(
log.clone(),
pointer,
keyboard,
state.window_map.clone(),
(w, h),
state.running.clone(),
pointer_location,
InputInitData {
pointer,
keyboard,
window_map: state.window_map.clone(),
screen_size: (w, h),
running: state.running.clone(),
pointer_location,
},
session,
));

View File

@ -23,7 +23,7 @@ use slog::Logger;
use crate::buffer_utils::BufferUtils;
use crate::glium_drawer::GliumDrawer;
use crate::input_handler::AnvilInputHandler;
use crate::input_handler::{AnvilInputHandler, InputInitData};
use crate::state::AnvilState;
pub fn run_winit(
@ -113,12 +113,14 @@ pub fn run_winit(
input.set_handler(AnvilInputHandler::new(
log.clone(),
pointer,
keyboard,
state.window_map.clone(),
(0, 0),
state.running.clone(),
pointer_location.clone(),
InputInitData {
pointer,
keyboard,
window_map: state.window_map.clone(),
screen_size: (0, 0),
running: state.running.clone(),
pointer_location: pointer_location.clone(),
},
));
info!(log, "Initialization completed, starting the main loop.");