fixed i think

This commit is contained in:
Michael Zhang 2018-09-30 07:25:18 -05:00
parent 01a294c8c5
commit f717a69fd8
No known key found for this signature in database
GPG key ID: A1B65B603268116B
9 changed files with 45 additions and 34 deletions

View file

@ -1,15 +1,12 @@
[package]
name = "screenshot"
description = "Screenshot capture utility."
name = "leanshot"
description = "Screenshot capture for Linux."
version = "0.3.0"
authors = ["Michael Zhang <failed.down@gmail.com>"]
[workspace]
members = [".", "imlib2", "imlib2/imlib2-sys", "xlib"]
[lib]
crate-type = ["dylib", "rlib"]
[dependencies]
failure = "0.1"
gl = "0.10"

View file

@ -4,5 +4,3 @@ RUN sudo apt-get update -y && sudo apt-get install -y mesa-common-dev libx11-dev
COPY . ./
RUN sudo chown -R rust:rust .
CMD cargo build --release

View file

@ -1,8 +0,0 @@
FROM ekidd/rust-musl-builder
RUN sudo apt-get update -y && sudo apt-get install -y libx11-dev libimlib2-dev
COPY . ./
RUN sudo chown -R rust:rust .
CMD cargo build

View file

@ -20,7 +20,7 @@ case `uname -s` in
Linux)
echo "Building static binaries using ekidd/rust-musl-builder"
docker build -t build-"$1"-image .
docker run -it --name build-"$1" build-"$1"-image
docker run -it --name build-"$1" build-"$1"-image bash -c 'cargo build --release'
docker cp build-"$1":/home/rust/src/target/x86_64-unknown-linux-musl/release/"$1" "$1"
docker rm build-"$1"
docker rmi build-"$1"-image

View file

@ -19,8 +19,8 @@ set -euo pipefail
case `uname -s` in
Linux)
echo "Building static binaries using ekidd/rust-musl-builder"
docker build -f Dockerfile.check -t build-"$1"-image .
docker run -it --name build-"$1" build-"$1"-image
docker build -f Dockerfile -t build-"$1"-image .
docker run -it --name build-"$1" build-"$1"-image bash -c 'cargo check'
docker rm build-"$1"
docker rmi build-"$1"-image
;;

View file

@ -16,5 +16,5 @@ fn main() {
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("bindings.rs"))
.expect("Unable to write bindings");
.expect("Unable to write bindings");
}

View file

@ -3,8 +3,8 @@ use std::path::Path;
use imlib2_sys as im;
use Error;
use xlib::Drawable;
use Error;
/// A simple wrapper around Imlib_Image
pub struct Image {
@ -37,6 +37,22 @@ impl Image {
Ok(Image { inner: image })
}
/// Get width
pub fn get_width(&self) -> i32 {
unsafe {
im::imlib_context_set_image(self.inner);
im::imlib_image_get_width()
}
}
/// Get height
pub fn get_height(&self) -> i32 {
unsafe {
im::imlib_context_set_image(self.inner);
im::imlib_image_get_height()
}
}
/// Save this image
pub fn save_image(&self, file: impl AsRef<Path>) -> Result<(), Error> {
let mut error = 0;

View file

@ -23,6 +23,7 @@ impl GUI {
let mut height = attr.get_height();
let root = attr.get_root();
let (mut x, mut y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
println!("{} {}", window.as_raw(), root.as_raw());
imlib2::context_set_display(&self.display);
let visual = Visual::default(&self.display, 0);
@ -30,7 +31,16 @@ impl GUI {
match opt.region {
Region::Selection => {
let region = self.interactive_select(window)?;
let capture = Image2::create_from_drawable(
window,
0,
x,
y,
width as i32,
height as i32,
true,
)?;
let region = self.interactive_select(capture)?;
x = region.x;
y = region.y;
width = region.width;
@ -52,7 +62,7 @@ impl GUI {
}
/// Brings up an interactive selection GUI.
pub fn interactive_select(&self, window: Window) -> Result<Rectangle, ScreenshotError> {
pub fn interactive_select(&self, capture: Image2) -> Result<Rectangle, ScreenshotError> {
// let window = SelectWindow::new(&self.display);
// let root = self.display.get_default_root_window()?;
@ -84,12 +94,13 @@ impl GUI {
use nanovg::{Color, Image, ImagePattern, PathOptions, StrokeOptions};
use std::{f32::consts, slice};
let attr = window.get_attributes()?;
let width = attr.get_width();
let height = attr.get_height();
let root = attr.get_root();
println!("{} {}", width, height);
let (x, y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
// let attr = window.get_attributes()?;
// let width = attr.get_width();
// let height = attr.get_height();
// let root = attr.get_root();
// let (x, y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
let width = capture.get_width();
let height = capture.get_height();
let mut evl = EventsLoop::new();
let mon = evl.get_primary_monitor();
@ -114,13 +125,10 @@ impl GUI {
// println!("size={:?} pos={:?} outer={:?}", win.get_inner_size(), win.get_inner_position(), win.get_outer_size());
// println!("{:?}", win.get_hidpi_factor());
imlib2::context_set_display(&self.display);
let visual = Visual::default(&self.display, 0);
imlib2::context_set_visual(&visual);
let img = Image2::create_from_drawable(window, 0, x, y, width as i32, height as i32, true)?;
imlib2::context_set_image(&img);
// let img = Image2::create_from_drawable(window, 0, 0, 0, width as i32, height as i32, true)?;
imlib2::context_set_image(&capture);
let len = (width * height) as usize;
// println!("{}", window.as_raw());
let raw_data = unsafe { slice::from_raw_parts(imlib2::image_get_data(), len) };
// convert ARGB to RGBA