Added checks to mouse pointer

This commit is contained in:
Jack Yu 2023-05-22 13:35:59 -07:00
parent a9af013f56
commit 427f1c6c96
1 changed files with 21 additions and 3 deletions

View File

@ -8,6 +8,7 @@ use std::thread;
use std::time; use std::time;
const KEYID_LSUPER: u32 = 130; const KEYID_LSUPER: u32 = 130;
const MOUSE_MASK_LSUPER: u32 = 64;
fn usage(prog: &String) -> () { fn usage(prog: &String) -> () {
println!("usage: {prog} [cmd...]"); println!("usage: {prog} [cmd...]");
@ -35,8 +36,24 @@ fn x11_check_lsuper() -> Option<bool> {
match x11_open_display() { match x11_open_display() {
Some(display) => { Some(display) => {
loop { loop {
let mut root_return: u64 = 0;
let mut child_return: u64 = 0;
let mut win_x: i32 = 0;
let mut win_y: i32 = 0;
let mut root_x: i32 = 0;
let mut root_y: i32 = 0;
let mut mask_return: u32 = 0;
let mut keymap: [i8; 32] = [0; 32]; let mut keymap: [i8; 32] = [0; 32];
unsafe { unsafe {
let win: u64 = x11::xlib::XDefaultRootWindow(display);
x11::xlib::XQueryPointer(display, win,
&mut root_return,
&mut child_return,
&mut root_x,
&mut root_y,
&mut win_x,
&mut win_y,
&mut mask_return);
x11::xlib::XQueryKeymap(display, keymap.as_mut_ptr()); x11::xlib::XQueryKeymap(display, keymap.as_mut_ptr());
} }
let (count, keyid, _) : (u32, u32, bool) = keymap.iter().fold( let (count, keyid, _) : (u32, u32, bool) = keymap.iter().fold(
@ -49,7 +66,8 @@ fn x11_check_lsuper() -> Option<bool> {
x11_close_display(display); x11_close_display(display);
return Some(true); return Some(true);
} }
if count > 1 || keyid != KEYID_LSUPER { if count > 1 || keyid != KEYID_LSUPER
|| mask_return != MOUSE_MASK_LSUPER {
x11_close_display(display); x11_close_display(display);
return Some(false); return Some(false);
} }