|
|
|
@ -6,7 +6,7 @@ use x11rb::{
|
|
|
|
|
protocol::{
|
|
|
|
|
xproto::{
|
|
|
|
|
Atom, AtomEnum, ChangeWindowAttributesAux,
|
|
|
|
|
ConnectionExt, EventMask, Window, InputFocus,
|
|
|
|
|
ConnectionExt, EventMask, Window, InputFocus, ClientMessageData, ClientMessageEvent, self,
|
|
|
|
|
},
|
|
|
|
|
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() {
|
|
|
|
|
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 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|