cleanup + crossbeam-channel feature

main
isark 5 days ago
parent 60f3bf7bf3
commit 434c0f68e6

@ -13,10 +13,17 @@ path = "src/lib.rs"
name = "test"
path = "src/examples/main.rs"
[features]
default = []
crossbeam = ["crossbeam-channel"]
[dependencies]
crossbeam = "0.8.2"
log = "0.4.19"
[dependencies.crossbeam-channel]
version = "0.5"
optional = true
[target.'cfg(windows)'.dependencies]
windows = {version = "0.48.0", features = ["Win32_UI_Accessibility", "Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_Graphics_Gdi", "Win32_System_Com", "Win32_System_Ole"]}

@ -1,8 +1,12 @@
use std::sync::mpsc::Receiver;
#[cfg(feature = "crossbeam")]
use crossbeam_channel::{unbounded, Receiver};
#[cfg_attr(unix, path = "linux/mod.rs")]
#[cfg_attr(windows, path = "windows/mod.rs")]
#[cfg_attr(mac, path = "windows/mod.rs")]
#[cfg(not(feature = "crossbeam"))]
use std::sync::mpsc::{channel as unbounded, Receiver};
#[cfg_attr(target_os = "linux", path = "linux/mod.rs")]
#[cfg_attr(target_os = "windows", path = "windows/mod.rs")]
#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
pub mod platform_impl;
#[derive(Debug, Clone, Copy, Default)]
@ -34,7 +38,7 @@ pub fn focus_target() {
}
pub fn register<T: Into<String>>(window_title: T) -> Receiver<UnderlayEvent> {
let (tx, rx) = std::sync::mpsc::channel();
let (tx, rx) = unbounded();
platform_impl::init(window_title.into(), tx).expect("Catastrophe");

@ -1,7 +1,10 @@
use std::{
cell::OnceCell,
sync::{atomic::AtomicPtr, Arc, Mutex, OnceLock},
};
use std::sync::{Arc, Mutex, OnceLock};
#[cfg(feature = "crossbeam")]
use crossbeam_channel::Sender;
#[cfg(not(feature = "crossbeam"))]
use std::sync::mpsc::Sender;
use x11rb::{
connect,
@ -65,7 +68,6 @@ fn get_atom<T: Into<String>>(conn: &RustConnection, name: T) -> Option<Atom> {
//Not very pretty and a bit wasteful making a new connection and getting the atom every time..
pub fn focus_target() {
unsafe {
if let Some(target) = TARGET.get() {
if let Ok(target) = target.lock() {
if *target != x11rb::NONE {
@ -97,7 +99,6 @@ pub fn focus_target() {
}
}
}
}
}
struct Runtime {
@ -105,7 +106,7 @@ struct Runtime {
root: Window,
target: Target,
atoms: AtomCollection,
underlay_tx: std::sync::mpsc::Sender<UnderlayEvent>,
underlay_tx: Sender<UnderlayEvent>,
active: Window,
}
@ -133,14 +134,12 @@ impl Runtime {
///Using this instead to allow setting the globally accessible target too for focus_target.
fn set_target(&mut self, wid: Window) {
self.target.wid = wid;
unsafe {
if let Some(target) = TARGET.get() {
if let Ok(mut target) = target.lock() {
*target = wid;
}
}
}
}
fn get_title(&self, wid: Window) -> Option<String> {
if wid == x11rb::NONE {
@ -360,10 +359,7 @@ impl Runtime {
}
}
pub fn init(
window_title: String,
tx: std::sync::mpsc::Sender<crate::UnderlayEvent>,
) -> Result<(), String> {
pub fn init(window_title: String, tx: Sender<crate::UnderlayEvent>) -> Result<(), String> {
TARGET
.set(Arc::new(Mutex::new(Window::default())))
.map_err(|e| log::error!("Could not init global TARGET storage {e:?}"))

@ -22,6 +22,13 @@ use windows::Win32::{
UI::Accessibility::{SetWinEventHook, UnhookWinEvent, HWINEVENTHOOK},
};
#[cfg(feature = "crossbeam")]
use crossbeam_channel::{Sender};
#[cfg(not(feature = "crossbeam"))]
use std::sync::mpsc::{Sender};
use crate::{Bounds, UnderlayEvent};
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> = AtomicPtr::new(std::ptr::null_mut());
@ -213,7 +220,7 @@ struct Runtime {
target: TargetWindow,
underlay_tx: std::sync::mpsc::Sender<UnderlayEvent>,
underlay_tx: Sender<UnderlayEvent>,
uipi_msg_id: u32,
}
@ -474,7 +481,7 @@ const OW_FOREGROUND_TIMER_MS: u32 = 83;
pub fn init(
window_title: String,
tx: std::sync::mpsc::Sender<crate::UnderlayEvent>,
tx: Sender<crate::UnderlayEvent>,
) -> Result<(), String> {
std::thread::spawn(move || {
let uipi_msg_id = register_message("UNDERLAY_UIPI_TEST");

Loading…
Cancel
Save