Skip to content

Commit

Permalink
Pass image through stdin, add Cargo.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthewizard committed May 24, 2019
1 parent 46e0524 commit 4c070ab
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Complete rewrite with fewer dependencies
- Pass image to `i3lock` via `/dev/stdin` instead of temporay file
- Pass raw bytes to `i3lock` rather than encoding PNG

## [0.1.2]
## [0.1.2] - 2019-05-24
### Changed
- Don't `clone()` `args`, flag a `bool` instead
- Pass image to `i3lock` via `/dev/stdin` instead of temporay file

### Fixed
- Hacky `thread::sleep` solution no longer necessary
Expand Down
213 changes: 213 additions & 0 deletions Cargo.lock

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

33 changes: 10 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::cmp::min;
use std::process::Command;
use std::thread::sleep;
use std::time::{Duration, Instant};
use std::io::Write;
use std::process::{Command, Stdio};
use std::time::Instant;

use clap::{crate_authors, crate_description, crate_name, crate_version, load_yaml, value_t, App};

use image::DynamicImage::ImageRgba8;
use image::{imageops, DynamicImage, FilterType, GenericImageView, Pixel, Rgba, RgbaImage};

use mktemp::TempFile;

use xcb::{randr, Connection};

use xcb_util::image as xcb_img;
Expand Down Expand Up @@ -85,20 +83,6 @@ fn main() {
let mut shot = shot.to_rgba();
draw_stuff(&mut shot, &lock, args.occurrences_of("invert") > 0);

let outfile = match TempFile::new("i3lockr-", ".png") {
Ok(tf) => tf,
Err(e) => panic!("Failed to create temporary file: {}", e),
};
time_it!(
"Exporting image",
match shot.save(&outfile.path()) {
Ok(()) => (),
Err(e) => {
panic!("Failed to export image: {}", e);
}
}
);

let mut nofork = false;
let mut i3lock_args = match args.values_of("i3lock") {
Some(args) => {
Expand All @@ -110,15 +94,18 @@ fn main() {
}
None => Vec::with_capacity(2),
};
let arg = format!("--raw={}x{}:rgbx", shot.width(), shot.height());
i3lock_args.extend_from_slice(&["-i", "/dev/stdin", &arg]);
/*
i3lock_args.push("-i");
i3lock_args.push(&outfile.path());
i3lock_args.push("/dev/stdin");
*/
debug!("Calling i3lock with arguments: {:?}", i3lock_args);
let mut out = Command::new("i3lock").args(i3lock_args).spawn().unwrap(); // clone args to use later, could also flag a bool or something
let mut out = Command::new("i3lock").args(i3lock_args).stdin(Stdio::piped()).spawn().unwrap();
out.stdin.as_mut().unwrap().write_all(&shot.into_vec()).unwrap();

if nofork {
let _ = out.wait();
} else {
sleep(Duration::from_millis(10)); // dumb solution, without this the temp file is dropped before i3lock starts
}
}

Expand Down

0 comments on commit 4c070ab

Please sign in to comment.