diff --git a/Cargo.toml b/Cargo.toml index a374ab6..2220b21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Underlayer" -version = "0.1.2" +version = "0.1.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index be68104..9f389be 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ Essentially a Rust re-implementation of https://github.com/SnosMe/electron-overlay-window with some additions or tweaks for my needs. -More documentation, information and licensing coming 'soon'... \ No newline at end of file +More documentation, information and licensing coming 'soon'... + +Features I want to implement sometime in the future: +* Allow multiple runtimes that can be unbound and do not depend on global state. \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 258cc71..9a6e54d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,11 @@ -use std::{sync::mpsc::Receiver}; - +use std::sync::mpsc::Receiver; #[cfg_attr(unix, path = "linux/mod.rs")] #[cfg_attr(windows, path = "windows/mod.rs")] #[cfg_attr(mac, path = "windows/mod.rs")] pub mod platform_impl; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub struct Bounds { pub x: i32, pub y: i32, @@ -16,8 +15,8 @@ pub struct Bounds { #[derive(Debug, Clone, Copy)] pub enum UnderlayEvent { - Attach { - bounds: Bounds, + Attach { + bounds: Bounds, has_access: Option, is_fullscreen: Option, }, @@ -25,7 +24,9 @@ pub enum UnderlayEvent { MoveResize(Bounds), Focus, Blur, - X11FullscreenEvent{ is_fullscreen: bool } + X11FullscreenEvent { + is_fullscreen: bool, + }, } pub fn focus_target() { @@ -33,12 +34,9 @@ pub fn focus_target() { } pub fn register>(window_title: T) -> Receiver { - let (tx,rx) = std::sync::mpsc::channel(); + let (tx, rx) = std::sync::mpsc::channel(); platform_impl::init(window_title.into(), tx).expect("Catastrophe"); - return rx; + rx } - - - diff --git a/src/linux/mod.rs b/src/linux/mod.rs index a31a315..b6686a7 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -5,8 +5,8 @@ use x11rb::{ connection::Connection, protocol::{ xproto::{ - Atom, AtomEnum, ChangeWindowAttributesAux, ClientMessageData, ClientMessageEvent, - ConnectionExt, EventMask, Window, CLIENT_MESSAGE_EVENT, InputFocus, + Atom, AtomEnum, ChangeWindowAttributesAux, + ConnectionExt, EventMask, Window, InputFocus, }, Event, }, @@ -64,7 +64,7 @@ pub fn focus_target() { unsafe { if let Ok(target) = (*TARGET.load(std::sync::atomic::Ordering::Relaxed)).lock() { if *target != x11rb::NONE { - if let Ok((conn, screen_num)) = connect(None) { + if let Ok((conn, _screen_num)) = connect(None) { conn.set_input_focus(InputFocus::PARENT, *target, x11rb::CURRENT_TIME).ok(); conn.flush().ok(); } diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 6dadac2..1c0f824 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -24,14 +24,11 @@ use windows::Win32::{ use crate::{Bounds, UnderlayEvent}; -static GLOBAL_RUNTIME: AtomicPtr>> = - AtomicPtr::new(std::ptr::null_mut()); +static GLOBAL_RUNTIME: AtomicPtr>> = AtomicPtr::new(std::ptr::null_mut()); pub fn focus_target() { unsafe { - if let Ok(runtime) = - (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() - { + if let Ok(runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() { if runtime.target.hwnd.is_valid() { SetForegroundWindow(runtime.target.hwnd); } @@ -181,9 +178,7 @@ unsafe extern "system" fn global_hook( _ideventthread: u32, _dwmseventtime: u32, ) { - if let Ok(mut runtime) = - (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() - { + if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() { runtime.on_event(Event::from_data( event, hwnd, @@ -199,9 +194,7 @@ unsafe extern "system" fn global_timer_hook( _timer_id: usize, _dwms_event_time: u32, ) { - if let Ok(mut runtime) = - (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() - { + if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() { let system_foreground_window = GetForegroundWindow(); if runtime.foreground_window != system_foreground_window && runtime.msaa_check_window_focused_state(system_foreground_window) @@ -251,10 +244,10 @@ impl Runtime { log::trace!("ForegroundChange: {hwnd:?}"); //Sometimes focus changes doesn't keep up, check manually. - if unsafe { GetForegroundWindow() } != hwnd { - if !self.msaa_check_window_focused_state(hwnd) { - return; - } + if unsafe { GetForegroundWindow() } != hwnd + && !self.msaa_check_window_focused_state(hwnd) + { + return; } self.on_new_foreground(hwnd) @@ -430,7 +423,7 @@ impl Runtime { }; } - return is_focused; + is_focused } fn handle_movesize(&self) {