Screenlocker is a cross platform command line tool that locks your desktop session until a password is entered. It is also a reusable library for developers who want to perform this action programmatically.
Use Rust's cargo tool to install screenlocker.
$ cargo install screenlocker
$ screenlocker # if $PATH contains `~/.cargo/bin`
Please contact me or create a new issue if you would like to have downloadable installers for your platform rather than use cargo.
The latest API documentation is available from a link on screenlockers's crates.io page. All you need is the lock_screen
function, as seen here in this example:
use screenlocker::lock_screen;
fn main() {
lock_screen().unwrap_or_else(|err| {
eprintln!("{}", err);
});
}
Make sure you install Rust on your computer before building.
$ git clone https://github.com/smacdo/screenlocker.git
$ cd screenlocker
$ cargo test
$ cargo run
On Mac and Windows this crate uses the platform's native SDK to implement screen locking. Linux does not have any such functionality, and instead relies on any number of programs to lock the screen. This crate hard codes the most common programs (xdg-screensaver
, gnome-screensaver-command
, etc) but it is possible that less mainstream window managers don't work. Please open an issue to flag this problem - or better - a pull request adding the missing program.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.