Skip to content

Commit

Permalink
lock usage of rdev's grab behind new grab feature
Browse files Browse the repository at this point in the history
  • Loading branch information
justDeeevin committed Aug 24, 2024
1 parent ef7083c commit d1b5dda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ display-info = "0.5.1"
geo = "0.28.0"
zip = "2.2.0"

[features]
grab = ["rdev/unstable_grab"]

[target.'cfg(windows)'.dependencies]
mslnk = "0.1.8"

Expand Down
14 changes: 13 additions & 1 deletion src/logic/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use iced::{
futures::{channel::mpsc, StreamExt},
subscription, Subscription,
};
use rdev::{grab, listen};
#[cfg(feature = "grab")]
use rdev::grab;
use rdev::listen;

enum State {
Starting,
Expand All @@ -27,6 +29,7 @@ pub fn bind() -> Subscription<Event> {
State::Starting => {
let (tx, rx) = mpsc::unbounded();
std::thread::spawn(move || {
#[cfg(feature = "grab")]
if cfg!(target_os = "linux")
&& std::env::var("XDG_SESSION_TYPE").unwrap() == "wayland"
{
Expand All @@ -50,6 +53,15 @@ pub fn bind() -> Subscription<Event> {
})
.unwrap();
}
#[cfg(not(feature = "grab"))]
listen(move |event| {
if let Err(e) = tx.unbounded_send(event.clone()) {
if !e.is_disconnected() {
panic!("{}", e);
}
}
})
.unwrap();
});
(Event::Ready, State::Ready(rx))
}
Expand Down

0 comments on commit d1b5dda

Please sign in to comment.