Changed focus target to sending a message event instead, seemingly more reliable...

main
isark 2 years ago
parent 397c538020
commit 828f4b0355

@ -1,6 +1,6 @@
[package] [package]
name = "Underlayer" name = "Underlayer"
version = "0.2.0" version = "0.2.1"
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

@ -6,7 +6,7 @@ use x11rb::{
protocol::{ protocol::{
xproto::{ xproto::{
Atom, AtomEnum, ChangeWindowAttributesAux, Atom, AtomEnum, ChangeWindowAttributesAux,
ConnectionExt, EventMask, Window, InputFocus, ConnectionExt, EventMask, Window, InputFocus, ClientMessageData, ClientMessageEvent, self,
}, },
Event, Event,
}, },
@ -60,12 +60,31 @@ 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() { 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::SeqCst)).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();
let net_active_window = get_atom(&conn, "_NET_ACTIVE_WINDOW").unwrap();
let event = ClientMessageEvent {
response_type: xproto::CLIENT_MESSAGE_EVENT,
format: 32,
sequence: 0,
window: *target,
type_: net_active_window,
data: ClientMessageData::from([
1,
0,
0,
0,
0,
]),
};
conn.send_event(false, conn.setup().roots[_screen_num].root, EventMask::SUBSTRUCTURE_NOTIFY | EventMask::SUBSTRUCTURE_REDIRECT, event).ok();
conn.flush().ok(); conn.flush().ok();
} }
} }

Loading…
Cancel
Save