From 474515c05006585d810c936d7202fbf05b46a661 Mon Sep 17 00:00:00 2001 From: Jeron Aldaron Lau Date: Tue, 1 Mar 2022 18:59:50 -0600 Subject: [PATCH] Make `Controller` and `Listener` impl `Send` --- stick/src/ctlr.rs | 16 ++++++++++------ stick/src/raw.rs | 4 ++-- stick/src/raw/windows.rs | 15 +++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/stick/src/ctlr.rs b/stick/src/ctlr.rs index a57f59a..38e21ca 100644 --- a/stick/src/ctlr.rs +++ b/stick/src/ctlr.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; use std::fmt::Debug; use std::future::Future; use std::pin::Pin; -use std::rc::Rc; +use std::sync::Arc; use std::task::{Context, Poll}; use crate::Event; @@ -150,7 +150,7 @@ impl Default for Info { /// Controller remapping information #[derive(Debug)] -pub struct Remap(HashMap>); +pub struct Remap(HashMap>); impl Default for Remap { fn default() -> Self { @@ -260,7 +260,7 @@ impl Remap { ); } - self.0.insert(id, Rc::new(Info { name, maps, type_ })); + self.0.insert(id, Arc::new(Info { name, maps, type_ })); } Some(self) @@ -270,7 +270,7 @@ impl Remap { /// A gamepad, flightstick, or other controller. pub struct Controller { // Shared remapping. - remap: Rc, + remap: Arc, // raw: Box, // Button states @@ -557,8 +557,12 @@ impl Controller { TrimDown(p) => self.button(Btn::TrimDown, TrimDown, p), TrimLeft(p) => self.button(Btn::TrimLeft, TrimLeft, p), TrimRight(p) => self.button(Btn::TrimRight, TrimRight, p), - ActionWheelX(v) => self.axis(ev, Axs::ActionWheelX, ActionWheelX, v), - ActionWheelY(v) => self.axis(ev, Axs::ActionWheelY, ActionWheelY, v), + ActionWheelX(v) => { + self.axis(ev, Axs::ActionWheelX, ActionWheelX, v) + } + ActionWheelY(v) => { + self.axis(ev, Axs::ActionWheelY, ActionWheelY, v) + } } } } diff --git a/stick/src/raw.rs b/stick/src/raw.rs index a678ca6..0ef2d60 100644 --- a/stick/src/raw.rs +++ b/stick/src/raw.rs @@ -59,13 +59,13 @@ impl Listener for FakeListener { } /// Controller Listener Implementation -pub(crate) trait Listener { +pub(crate) trait Listener: Send { /// Poll for controllers. fn poll(&mut self, cx: &mut Context<'_>) -> Poll; } /// Controller Implementation -pub(crate) trait Controller { +pub(crate) trait Controller: Send { /// The hardware identifier for this controller. fn id(&self) -> u64 { 0 diff --git a/stick/src/raw/windows.rs b/stick/src/raw/windows.rs index 737f0c1..ff97a72 100644 --- a/stick/src/raw/windows.rs +++ b/stick/src/raw/windows.rs @@ -14,7 +14,6 @@ use crate::{Event, Remap}; use std::fmt::{self, Debug, Formatter}; -use std::rc::Rc; use std::sync::Arc; use std::task::Waker; use std::task::{Context, Poll}; @@ -159,7 +158,7 @@ impl XInputHandle { /// * `xinput1_1.dll` /// * `xinput9_1_0.dll` pub(crate) fn load_default( - ) -> Result, XInputLoadingFailure> { + ) -> Result, XInputLoadingFailure> { let xinput14 = "xinput1_4.dll"; let xinput13 = "xinput1_3.dll"; let xinput12 = "xinput1_2.dll"; @@ -170,7 +169,7 @@ impl XInputHandle { [xinput14, xinput13, xinput12, xinput11, xinput91].iter() { if let Ok(handle) = XInputHandle::load(lib_name) { - return Ok(Rc::new(handle)); + return Ok(Arc::new(handle)); } } @@ -633,7 +632,7 @@ fn register_wake_timeout(delay: u32, waker: &Waker) { //////////////////////////////////////////////////////////////////////////////// pub(crate) struct Controller { - xinput: Rc, + xinput: Arc, device_id: u8, pending_events: Vec, last_packet: DWORD, @@ -641,7 +640,7 @@ pub(crate) struct Controller { impl Controller { #[allow(unused)] - fn new(device_id: u8, xinput: Rc) -> Self { + fn new(device_id: u8, xinput: Arc) -> Self { Self { xinput, device_id, @@ -792,14 +791,14 @@ impl super::Controller for Controller { } pub(crate) struct Listener { - xinput: Rc, + xinput: Arc, connected: u64, to_check: u8, remap: Remap, } impl Listener { - fn new(remap: Remap, xinput: Rc) -> Self { + fn new(remap: Remap, xinput: Arc) -> Self { Self { xinput, connected: 0, @@ -842,7 +841,7 @@ impl super::Listener for Listener { } struct Global { - xinput: Rc, + xinput: Arc, } impl super::Global for Global {