Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Asura committed Nov 4, 2022
1 parent 66f6d68 commit 6ad74d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ fn main() {
enable_grab();
thread::sleep(delay);

println!("[*] ungrab keys(5s), try to press Ctrl+C");
disable_grab();
println!("[*] grab keys(5s), try to press Ctrl+C");
thread::sleep(delay);

enable_grab();
println!("[*] grab keys(5s), try to press Ctrl+C, won't work on other applications");
enable_grab();
thread::sleep(delay);

exit_grab_listen();
Expand Down
5 changes: 3 additions & 2 deletions src/linux/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
sync::{mpsc::Sender, Arc, Mutex},
time::SystemTime,
};
use x11::xlib::{self, Display, GrabModeAsync, KeyPressMask};
use x11::xlib::{self, Display, GrabModeAsync, KeyPressMask, KeyReleaseMask};

#[derive(Debug)]
pub struct MyDisplay(*mut xlib::Display);
Expand Down Expand Up @@ -92,6 +92,7 @@ pub fn enable_grab() -> Result<(), GrabError> {
pub fn disable_grab() -> Result<(), GrabError> {
if let Some(tx) = &*SENDER.lock().unwrap() {
tx.send(GrabEvent::UnGrab).ok();
thread::sleep(Duration::from_millis(50));
} else {
return Err(GrabError::ListenError);
};
Expand Down Expand Up @@ -184,7 +185,7 @@ fn start_grab_thread() {
let grab_window = unsafe { xlib::XRootWindowOfScreen(screen) };

unsafe {
xlib::XSelectInput(display, grab_window, KeyPressMask);
xlib::XSelectInput(display, grab_window, KeyPressMask | KeyReleaseMask);
}

let grab_fd = unsafe { xlib::XConnectionNumber(display) };
Expand Down

0 comments on commit 6ad74d3

Please sign in to comment.