0.1.3, bit of cleanup, extra readme comment, Default derived for Bounds

main
isark 2 years ago
parent eef7577b69
commit 9bde4bfdae

@ -1,6 +1,6 @@
[package] [package]
name = "Underlayer" name = "Underlayer"
version = "0.1.2" version = "0.1.3"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -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. 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'... 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.

@ -1,12 +1,11 @@
use std::{sync::mpsc::Receiver}; use std::sync::mpsc::Receiver;
#[cfg_attr(unix, path = "linux/mod.rs")] #[cfg_attr(unix, path = "linux/mod.rs")]
#[cfg_attr(windows, path = "windows/mod.rs")] #[cfg_attr(windows, path = "windows/mod.rs")]
#[cfg_attr(mac, path = "windows/mod.rs")] #[cfg_attr(mac, path = "windows/mod.rs")]
pub mod platform_impl; pub mod platform_impl;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, Default)]
pub struct Bounds { pub struct Bounds {
pub x: i32, pub x: i32,
pub y: i32, pub y: i32,
@ -16,8 +15,8 @@ pub struct Bounds {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum UnderlayEvent { pub enum UnderlayEvent {
Attach { Attach {
bounds: Bounds, bounds: Bounds,
has_access: Option<bool>, has_access: Option<bool>,
is_fullscreen: Option<bool>, is_fullscreen: Option<bool>,
}, },
@ -25,7 +24,9 @@ pub enum UnderlayEvent {
MoveResize(Bounds), MoveResize(Bounds),
Focus, Focus,
Blur, Blur,
X11FullscreenEvent{ is_fullscreen: bool } X11FullscreenEvent {
is_fullscreen: bool,
},
} }
pub fn focus_target() { pub fn focus_target() {
@ -33,12 +34,9 @@ pub fn focus_target() {
} }
pub fn register<T: Into<String>>(window_title: T) -> Receiver<UnderlayEvent> { pub fn register<T: Into<String>>(window_title: T) -> Receiver<UnderlayEvent> {
let (tx,rx) = std::sync::mpsc::channel(); let (tx, rx) = std::sync::mpsc::channel();
platform_impl::init(window_title.into(), tx).expect("Catastrophe"); platform_impl::init(window_title.into(), tx).expect("Catastrophe");
return rx; rx
} }

@ -5,8 +5,8 @@ use x11rb::{
connection::Connection, connection::Connection,
protocol::{ protocol::{
xproto::{ xproto::{
Atom, AtomEnum, ChangeWindowAttributesAux, ClientMessageData, ClientMessageEvent, Atom, AtomEnum, ChangeWindowAttributesAux,
ConnectionExt, EventMask, Window, CLIENT_MESSAGE_EVENT, InputFocus, ConnectionExt, EventMask, Window, InputFocus,
}, },
Event, Event,
}, },
@ -64,7 +64,7 @@ pub fn focus_target() {
unsafe { unsafe {
if let Ok(target) = (*TARGET.load(std::sync::atomic::Ordering::Relaxed)).lock() { if let Ok(target) = (*TARGET.load(std::sync::atomic::Ordering::Relaxed)).lock() {
if *target != x11rb::NONE { 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.set_input_focus(InputFocus::PARENT, *target, x11rb::CURRENT_TIME).ok();
conn.flush().ok(); conn.flush().ok();
} }

@ -24,14 +24,11 @@ use windows::Win32::{
use crate::{Bounds, UnderlayEvent}; use crate::{Bounds, UnderlayEvent};
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> = static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> = AtomicPtr::new(std::ptr::null_mut());
AtomicPtr::new(std::ptr::null_mut());
pub fn focus_target() { pub fn focus_target() {
unsafe { unsafe {
if let Ok(runtime) = if let Ok(runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
{
if runtime.target.hwnd.is_valid() { if runtime.target.hwnd.is_valid() {
SetForegroundWindow(runtime.target.hwnd); SetForegroundWindow(runtime.target.hwnd);
} }
@ -181,9 +178,7 @@ unsafe extern "system" fn global_hook(
_ideventthread: u32, _ideventthread: u32,
_dwmseventtime: u32, _dwmseventtime: u32,
) { ) {
if let Ok(mut runtime) = if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
{
runtime.on_event(Event::from_data( runtime.on_event(Event::from_data(
event, event,
hwnd, hwnd,
@ -199,9 +194,7 @@ unsafe extern "system" fn global_timer_hook(
_timer_id: usize, _timer_id: usize,
_dwms_event_time: u32, _dwms_event_time: u32,
) { ) {
if let Ok(mut runtime) = if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
{
let system_foreground_window = GetForegroundWindow(); let system_foreground_window = GetForegroundWindow();
if runtime.foreground_window != system_foreground_window if runtime.foreground_window != system_foreground_window
&& runtime.msaa_check_window_focused_state(system_foreground_window) && runtime.msaa_check_window_focused_state(system_foreground_window)
@ -251,10 +244,10 @@ impl Runtime {
log::trace!("ForegroundChange: {hwnd:?}"); log::trace!("ForegroundChange: {hwnd:?}");
//Sometimes focus changes doesn't keep up, check manually. //Sometimes focus changes doesn't keep up, check manually.
if unsafe { GetForegroundWindow() } != hwnd { if unsafe { GetForegroundWindow() } != hwnd
if !self.msaa_check_window_focused_state(hwnd) { && !self.msaa_check_window_focused_state(hwnd)
return; {
} return;
} }
self.on_new_foreground(hwnd) self.on_new_foreground(hwnd)
@ -430,7 +423,7 @@ impl Runtime {
}; };
} }
return is_focused; is_focused
} }
fn handle_movesize(&self) { fn handle_movesize(&self) {

Loading…
Cancel
Save