Skip to content

Commit

Permalink
Changelog 0.1.7:
Browse files Browse the repository at this point in the history
* minor refactoring
* fix typos
* added `-D` for specifing the device dev path and `-K`, `-M` to set the device type, this was requested by @lnee94
  • Loading branch information
konkitoman committed Mar 9, 2024
1 parent 5fbd618 commit 063ae7c
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target_ra
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "theclicker"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
license = "MIT"
authors = ["konkitoman"]
Expand Down
16 changes: 14 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,28 @@ pub struct Args {
#[arg(long, default_value_t = false)]
pub debug: bool,

/// Grabs the input device and emulates any unused action from it
/// I will not: grab the input device and emulates any unused action from it
#[arg(long, default_value_t = false)]
pub no_grab: bool,

/// This will let the keyboard to be grabed!
/// This will let the keyboard to be grabbed!
#[arg(long, default_value_t = false)]
pub grab_kbd: bool,

/// Automatically uses the specified device by name
/// (first looks for exact match, then takes the first device that contains the string)
#[arg(short = 'd', long)]
pub use_device: Option<String>,

/// This will try to open the specified dev path, you need to specify what type of device is!
#[arg(short = 'D')]
pub use_dev_path: Option<String>,

/// Set the device type as Keyboard
#[arg(short = 'K', default_value_t = false)]
pub is_keyboard: bool,

/// Set the device type as Mouse
#[arg(short = 'M', default_value_t = false)]
pub is_mouse: bool,
}
2 changes: 1 addition & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl Device {
.create(true)
.open("/tmp/TheClicker")
.unwrap();
let mut args = crate::args::Args::parse();
let mut args = crate::Args::parse();
args.use_device = Some(device.name.clone());
args.clear_cache = false;

Expand Down
44 changes: 37 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
pub mod args;
mod args;
mod device;

pub use args::Args;

use std::{
io::{stdout, IsTerminal},
path::PathBuf,
str::FromStr,
sync::{mpsc, Arc},
thread,
time::Duration,
};

use crate::device::Device;
pub use device::{Device, DeviceType};
use input_linux::{sys::input_event, Key, KeyState};

#[derive(Default)]
Expand All @@ -32,6 +35,8 @@ pub struct StateArgs {
pub grab: bool,
pub grab_kbd: bool,
pub use_device: Option<String>,
pub use_dev_path: Option<String>,
pub device_type: Option<DeviceType>,
}

pub struct State {
Expand Down Expand Up @@ -62,18 +67,43 @@ impl State {
grab,
use_device,
grab_kbd,
use_dev_path,
device_type,
}: StateArgs,
) -> Self {
let input;

if let Some(device_name) = use_device {
if let Some(device) = Device::find_device(&device_name) {
input = device;
} else {
'try_set_input: {
if let Some(dev_path) = use_dev_path {
let Ok(path) = PathBuf::from_str(&dev_path) else {
eprintln!("Cannot make {dev_path} to path, invalid path");
std::process::exit(3);
};

let Some(device_type) = device_type else {
eprintln!("You didn't specified the device type!");
std::process::exit(5);
};

if let Ok(device) = Device::dev_open(path, device_type) {
input = device;
break 'try_set_input;
}

eprintln!("Cannot open device: {dev_path}");
std::process::exit(2);
}

if let Some(device_name) = use_device {
if let Some(device) = Device::find_device(&device_name) {
input = device;
break 'try_set_input;
}

eprintln!("Cannot find device: {device_name}");
std::process::exit(1);
}
} else {

input = Device::select_device();
}

Expand Down
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
pub mod args;
pub mod device;

use std::{
fs::{self, File},
io::Read,
};

use clap::Parser;
use theclicker::State;

use crate::args::Args;
use theclicker::{Args, DeviceType, State};

fn main() {
let Args {
Expand All @@ -24,6 +19,9 @@ fn main() {
mut no_grab,
mut use_device,
mut grab_kbd,
mut use_dev_path,
mut is_keyboard,
mut is_mouse,
} = Args::parse();

if clear_cache {
Expand All @@ -48,6 +46,9 @@ fn main() {
no_grab,
grab_kbd,
use_device,
use_dev_path,
is_keyboard,
is_mouse,
} = ron::from_str::<Args>(&string).unwrap();
}

Expand All @@ -65,6 +66,16 @@ fn main() {
grab,
use_device,
grab_kbd,
use_dev_path,
device_type: match (is_mouse, is_keyboard) {
(true, false) => Some(DeviceType::Mouse),
(false, true) => Some(DeviceType::Keyboard),
(false, false) => None,
_ => {
eprintln!("You cannot set both -K and -M");
std::process::exit(4)
}
},
});

println!();
Expand Down

0 comments on commit 063ae7c

Please sign in to comment.