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>, 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 { impl AnvilInputHandler {
pub fn new( pub fn new(log: Logger, data: InputInitData) -> AnvilInputHandler {
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 {
AnvilInputHandler { AnvilInputHandler {
log, log,
pointer, pointer: data.pointer,
keyboard, keyboard: data.keyboard,
window_map, window_map: data.window_map,
screen_size, screen_size: data.screen_size,
running, running: data.running,
pointer_location, pointer_location: data.pointer_location,
#[cfg(feature = "udev")] #[cfg(feature = "udev")]
session: None, session: None,
} }
} }
#[cfg(feature = "udev")] #[cfg(feature = "udev")]
pub fn new_with_session( pub fn new_with_session(log: Logger, data: InputInitData, session: AutoSession) -> AnvilInputHandler {
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 {
AnvilInputHandler { AnvilInputHandler {
log, log,
pointer, pointer: data.pointer,
keyboard, keyboard: data.keyboard,
window_map, window_map: data.window_map,
screen_size, screen_size: data.screen_size,
running, running: data.running,
pointer_location, pointer_location: data.pointer_location,
session: Some(session), session: Some(session),
} }
} }

View File

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

View File

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