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]
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

@ -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'...
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(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<bool>,
is_fullscreen: Option<bool>,
},
@ -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<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");
return rx;
rx
}

@ -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();
}

@ -24,14 +24,11 @@ use windows::Win32::{
use crate::{Bounds, UnderlayEvent};
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> =
AtomicPtr::new(std::ptr::null_mut());
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> = 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) {

Loading…
Cancel
Save