From ea2d41ad1b171f5fbaf4929c3c7cfa5ab10342a8 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 10 Sep 2018 01:52:54 -0500 Subject: [PATCH] 0.3.0 wip --- .gdb_history | 3 + .gitmodules | 3 - Cargo.lock | 342 ++++++++---------------------------- Cargo.toml | 20 +-- peda-session-screenshot.txt | 2 + slop-sys/Cargo.lock | 4 - slop-sys/Cargo.toml | 13 -- slop-sys/build.rs | 12 -- slop-sys/lib.rs | 264 ---------------------------- slop-sys/slop | 1 - src/capture.rs | 157 +++++++++-------- src/errors.rs | 16 +- src/gui.rs | 71 ++++++++ src/image.rs | 15 ++ src/lib.rs | 30 ++++ src/main.rs | 68 +------ src/options.rs | 29 ++- src/selection.rs | 43 ----- 18 files changed, 303 insertions(+), 790 deletions(-) create mode 100644 .gdb_history delete mode 100644 .gitmodules create mode 100644 peda-session-screenshot.txt delete mode 100644 slop-sys/Cargo.lock delete mode 100644 slop-sys/Cargo.toml delete mode 100644 slop-sys/build.rs delete mode 100644 slop-sys/lib.rs delete mode 160000 slop-sys/slop create mode 100644 src/gui.rs create mode 100644 src/image.rs create mode 100644 src/lib.rs delete mode 100644 src/selection.rs diff --git a/.gdb_history b/.gdb_history new file mode 100644 index 0000000..8785128 --- /dev/null +++ b/.gdb_history @@ -0,0 +1,3 @@ +run +run -o shiet.png fullscreen +bt diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ae6ebfb..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "slop-sys/slop"] - path = slop-sys/slop - url = https://github.com/naelstrof/slop.git diff --git a/Cargo.lock b/Cargo.lock index 3a7b3dc..8880252 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,18 +6,6 @@ dependencies = [ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "atk-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "atty" version = "0.2.10" @@ -54,33 +42,6 @@ name = "bitflags" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "c_vec" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cairo-rs" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "c_vec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cairo-sys-rs" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cc" version = "1.0.15" @@ -105,14 +66,6 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cmake" -version = "0.1.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "failure" version = "0.1.1" @@ -132,213 +85,37 @@ dependencies = [ "synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "gdk" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pango 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gdk-pixbuf" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gdk-pixbuf-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gdk-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gio" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gio-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "glib" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "glib-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gobject-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gtk" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gtk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pango 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gtk-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "pango" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pango-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "pkg-config" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro2" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "quote" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.37" @@ -359,24 +136,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "screenshot" -version = "0.2.3" +version = "0.3.0" dependencies = [ - "cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slop-sys 0.1.0", + "structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "slop-sys" -version = "0.1.0" -dependencies = [ - "cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -384,6 +149,25 @@ name = "strsim" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "structopt" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "structopt-derive" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.11.11" @@ -394,6 +178,16 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synom" version = "0.11.3" @@ -449,6 +243,11 @@ name = "unicode-xid" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "vec_map" version = "0.8.1" @@ -473,44 +272,39 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "x11" +version = "2.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8dc233521f7bffd3042c31082ea71bd08820abf44bac938fb36591e20f76f39" "checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1" "checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639" "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" -"checksum c_vec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11f56b93adbca81a4ed1bb654070013b496a9b0b259a296281f4be24af84debd" -"checksum cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a110f269c2fd382df5fe8bd46dfa5f1b83608aa717fecb6e7a28c08c202f0e13" -"checksum cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0395175ecba60accac076a02c31d143b9dcd9d5eb5316d7163a3273803b765c7" "checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba" "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536" -"checksum cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "704fbf3bb5149daab0afb255dbea24a1f08d2f4099cedb9baab6d470d4c5eefb" "checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82" "checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b" -"checksum gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd30051ff3d908ff2fc7e5776ffe1c699821e043809f294c3a61004f11d6c3a9" -"checksum gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2d2199eba47ebcb9977ce28179649bdd59305ef465c4e6f9b65aaa41c24e6b5" -"checksum gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df6a3b73e04fafc07f5ebc083f1096a773412e627828e1103a55e921f81187d8" -"checksum gdk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3162ff940526ddff71bf1f630facee6b5e05d282d125ba0c4c803842819b80c3" -"checksum gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "071fd4e5592b39fdc31318e32d2497842501f539bcedb60c75cd365946642adc" -"checksum gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a57872499171d279f8577ce83837da4cae62b08dd32892236ed67ab7ea61030" -"checksum glib 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e0be1b1432e227bcd1a9b28db9dc1474a7e7fd4227e08e16f35304f32d09b61" -"checksum glib-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615bef979b5838526aee99241afc80cfb2e34a8735d4bcb8ec6072598c18a408" -"checksum gobject-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70409d6405db8b1591602fcd0cbe8af52cd9976dd39194442b4c149ba343f86d" -"checksum gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d695d6be4110618a97c19cd068e8a00e53e33b87e3c65cdc5397667498b1bc24" -"checksum gtk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d9554cf5b3a85a13fb39258c65b04b262989c1d7a758f8f555b77a478621a91" -"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" -"checksum pango 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45374801e224373c3c0393cd48073c81093494c8735721e81d1dbaa4096b2767" -"checksum pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94039b3921a4af4058a3e4335e5d15099101f298a92f5afc40bab3a3027594a1" "checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f" +"checksum proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ffe022fb8c8bd254524b0b3305906c1921fa37a84a644e29079a9e62200c3901" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" +"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e9ad6a11096cbecdcca0cc6aa403fdfdbaeda2fb3323a39c98e6a166a1e45a" +"checksum structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4cbce8ccdc62166bd594c14396a3242bf94c337a51dbfa9be1076dd74b3db2af" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" +"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" @@ -518,7 +312,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39697e3123f715483d311b5826e254b6f3cfebdd83cf7ef3358f579c3d68e235" diff --git a/Cargo.toml b/Cargo.toml index 972ac9f..18d05b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,14 @@ [package] name = "screenshot" -version = "0.2.4" +description = "Screenshot capture utility." +version = "0.3.0" authors = ["Michael Zhang "] -[workspace] -members = [".", "slop-sys"] +[lib] +crate-type = ["dylib", "rlib"] [dependencies] -clap = "2.31.2" -cairo-rs = { version = "0.4.1", features = ["png"] } -failure = "0.1.1" -gdk = "0.8.0" -gdk-pixbuf = "0.4.0" -gio = "0.4.0" -gtk = { version = "0.4.1", features = ["v3_16"] } -time = "0.1.40" -slop-sys = { path = "slop-sys" } +failure = "0.1" +structopt = "0.2" +time = "0.1" +x11 = { version = "2.18", features = ["xlib"] } diff --git a/peda-session-screenshot.txt b/peda-session-screenshot.txt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/peda-session-screenshot.txt @@ -0,0 +1,2 @@ + + diff --git a/slop-sys/Cargo.lock b/slop-sys/Cargo.lock deleted file mode 100644 index bd4ff7e..0000000 --- a/slop-sys/Cargo.lock +++ /dev/null @@ -1,4 +0,0 @@ -[[package]] -name = "slop-sys" -version = "0.1.0" - diff --git a/slop-sys/Cargo.toml b/slop-sys/Cargo.toml deleted file mode 100644 index ef0768a..0000000 --- a/slop-sys/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "slop-sys" -version = "0.1.0" -authors = ["Michael Zhang "] -build = "build.rs" - -[lib] -path = "lib.rs" - -[build-dependencies] -cmake = "0.1" - -[dependencies] diff --git a/slop-sys/build.rs b/slop-sys/build.rs deleted file mode 100644 index 6189406..0000000 --- a/slop-sys/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern crate cmake; - -use cmake::Config; - -fn main() { - let dst = Config::new("slop").define("CMAKE_SKIP_RPATH", "ON").build(); - println!("cargo:rustc-link-search=native={}", dst.display()); - println!("cargo:rustc-link-lib=slopy"); - - // println!("cargo:rustc-link-lib=slopy"); - // println!("cargo:rustc-link-search=native=/usr/lib/usr/lib/x86_64-linux-gnu"); -} diff --git a/slop-sys/lib.rs b/slop-sys/lib.rs deleted file mode 100644 index ca17483..0000000 --- a/slop-sys/lib.rs +++ /dev/null @@ -1,264 +0,0 @@ -/* automatically generated by rust-bindgen */ - -#![allow(dead_code)] - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct slop_options { - pub quiet: ::std::os::raw::c_int, - pub border: f32, - pub padding: f32, - pub tolerance: f32, - pub highlight: ::std::os::raw::c_int, - pub noopengl: ::std::os::raw::c_int, - pub nokeyboard: ::std::os::raw::c_int, - pub nodecorations: ::std::os::raw::c_int, - pub shaders: *mut ::std::os::raw::c_char, - pub r: f32, - pub g: f32, - pub b: f32, - pub a: f32, - pub xdisplay: *const ::std::os::raw::c_char, -} -#[test] -fn bindgen_test_layout_slop_options() { - assert_eq!( - ::std::mem::size_of::(), - 64usize, - concat!("Size of: ", stringify!(slop_options)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(slop_options)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).quiet as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(quiet) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).border as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(border) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).padding as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(padding) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).tolerance as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(tolerance) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).highlight as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(highlight) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).noopengl as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(noopengl) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).nokeyboard as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(nokeyboard) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).nodecorations as *const _ as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(nodecorations) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).shaders as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(shaders) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).r as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).g as *const _ as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 52usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).xdisplay as *const _ as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(slop_options), - "::", - stringify!(xdisplay) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct slop_selection { - pub cancelled: ::std::os::raw::c_int, - pub x: f32, - pub y: f32, - pub w: f32, - pub h: f32, - pub id: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_slop_selection() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(slop_selection)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(slop_selection)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).cancelled as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(cancelled) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(y) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(w) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).h as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(h) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).id as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(slop_selection), - "::", - stringify!(id) - ) - ); -} -extern "C" { - pub fn slop_options_default() -> slop_options; -} -extern "C" { - pub fn slop_select(options: *mut slop_options) -> slop_selection; -} diff --git a/slop-sys/slop b/slop-sys/slop deleted file mode 160000 index 2196617..0000000 --- a/slop-sys/slop +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2196617d8e10bb4a4a1e4a1520af4cab890f1e00 diff --git a/src/capture.rs b/src/capture.rs index 11ba399..1ed8c6b 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -1,84 +1,99 @@ -use std::fs::File; - -use cairo::{Context, Format, ImageSurface}; -use failure::Error; -use gdk::prelude::*; -use gdk::{ContextExt, Display, DisplayExt, Screen, ScreenExt, Window as GdkWindow, WindowExt}; -use gdk_pixbuf::{Pixbuf, PixbufExt}; -use gtk::{Clipboard, ClipboardExt}; -use time; - use errors::ScreenshotError; + +use gui::GUI; +use image::Image; use options::{Options, Region}; -use selection::select_area; -pub fn capture(options: Options) -> Result<(), Error> { - let display; - let screen; - match (Display::get_default(), Screen::get_default()) { - (Some(d), Some(s)) => { - display = d; - screen = s; - } - _ => { - bail!("Failed to open screen and display."); - } - } +pub fn capture(opt: &Options) -> Result { + let gui = GUI::new(); - display.sync(); - - // first, choose the window - let window_opt = match options.region { - Region::Fullscreen | Region::Selection => screen.get_root_window(), - Region::ActiveWindow => screen.get_active_window(), + let window_to_capture = match opt.region { + Region::Fullscreen | Region::Selection => gui.get_root_window(), + Region::ActiveWindow => gui.get_active_window(), }; - let window: GdkWindow; - match window_opt { - Some(window_) => window = window_, - None => bail!("Failed to locate root window."), - } - window.process_updates(true); + println!("Got window_to_capture: {:?}", window_to_capture); - // take a screenshot of it - let width: i32 = window.get_width(); - let height: i32 = window.get_height(); - let pixbuf: Pixbuf = match window.get_pixbuf(0, 0, width, height) { - Some(pixbuf) => Ok(pixbuf), - None => Err(ScreenshotError), - }?; + let mut capture = gui.window_capture(window_to_capture)?; + println!("Captured the window."); - // launch selection - let pixbuf = match options.region { - Region::Selection => select_area(pixbuf)?, - _ => pixbuf, + // let final_capture = match opt.region { + // Region::Fullscreen | Region::ActiveWindow => window_capture, + // Region::Selection => gui.interactive_select(&window_capture), + // }; + + if let Region::Selection = opt.region { + let region = gui.interactive_select(&capture)?; + capture.apply_region(®ion); + println!("Subimaged."); }; - let width = pixbuf.get_width(); - let height = pixbuf.get_height(); - // create and draw to the surface - let surface = match ImageSurface::create(Format::Rgb24, width, height) { - Ok(surface) => Ok(surface), - Err(_status) => Err(ScreenshotError), - }?; - let ctx = Context::new(&surface); - ctx.set_source_pixbuf(&pixbuf, 0.0, 0.0); - ctx.paint(); + Ok(capture) - // write surface to file + // let display; + // let screen; + // match (Display::get_default(), Screen::get_default()) { + // (Some(d), Some(s)) => { + // display = d; + // screen = s; + // } + // _ => { + // bail!("Failed to open screen and display."); + // } + // } - let now = time::now(); - let path = time::strftime(&options.outfile.as_os_str().to_str().unwrap(), &now)?; - let mut file = File::create(path)?; - surface.write_to_png(&mut file)?; + // display.sync(); - if options.clip { - match Clipboard::get_default(&display) { - Some(clipboard) => { - clipboard.set_image(&pixbuf); - clipboard.store(); - } - None => eprintln!("Failed to copy to the clipboard."), - } - } - Ok(()) + // // first, choose the window + // let window_opt = match options.region { + // Region::Fullscreen | Region::Selection => screen.get_root_window(), + // Region::ActiveWindow => screen.get_active_window(), + // }; + // let window: GdkWindow; + // match window_opt { + // Some(window_) => window = window_, + // None => bail!("Failed to locate root window."), + // } + // window.process_updates(true); + + // // take a screenshot of it + // let width: i32 = window.get_width(); + // let height: i32 = window.get_height(); + // let pixbuf: Pixbuf = match window.get_pixbuf(0, 0, width, height) { + // Some(pixbuf) => Ok(pixbuf), + // None => Err(ScreenshotError::InvalidPixbuf), + // }?; + + // // launch selection + // let pixbuf = match options.region { + // Region::Selection => select_area(pixbuf)?, + // _ => pixbuf, + // }; + // let width = pixbuf.get_width(); + // let height = pixbuf.get_height(); + + // // create and draw to the surface + // let surface = match ImageSurface::create(Format::Rgb24, width, height) { + // Ok(surface) => Ok(surface), + // Err(_status) => Err(ScreenshotError::SurfaceCreateFail), + // }?; + // let ctx = Context::new(&surface); + // ctx.set_source_pixbuf(&pixbuf, 0.0, 0.0); + // ctx.paint(); + + // // write surface to file + + // let now = time::now(); + // let path = time::strftime(&options.outfile.as_os_str().to_str().unwrap(), &now)?; + // let mut file = File::create(path)?; + // surface.write_to_png(&mut file)?; + + // if options.clipboard { + // match Clipboard::get_default(&display) { + // Some(clipboard) => { + // clipboard.set_image(&pixbuf); + // clipboard.store(); + // } + // None => eprintln!("Failed to copy to the clipboard."), + // } + // } } diff --git a/src/errors.rs b/src/errors.rs index df24809..9dc70d2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,13 +1,5 @@ -use std::error::Error; -use std::fmt; - -#[derive(Debug)] -pub struct ScreenshotError; - -impl fmt::Display for ScreenshotError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "error") - } +#[derive(Debug, Fail)] +pub enum ScreenshotError { + #[fail(display = "error")] + Error, } - -impl Error for ScreenshotError {} diff --git a/src/gui.rs b/src/gui.rs new file mode 100644 index 0000000..9242db1 --- /dev/null +++ b/src/gui.rs @@ -0,0 +1,71 @@ +use std::ffi::CString; + +use x11::xlib::{self, *}; + +use errors::ScreenshotError; +use image::Image; +use Rectangle; + +pub struct GUI { + display: *mut Display, +} + +impl GUI { + pub fn new() -> Self { + let display_str = CString::new(":0").unwrap(); + let display = unsafe { xlib::XOpenDisplay(display_str.as_ptr()) }; + unsafe { XGrabServer(display) }; + GUI { display } + } + + fn get_window_attributes(&self, window: *mut Window) -> *mut XWindowAttributes { + let attr: *mut XWindowAttributes = unsafe { ::std::mem::uninitialized() }; + unsafe { XGetWindowAttributes(self.display, *window, attr) }; + attr + } + + /// Captures the window and produces a DynamicImage. + pub fn window_capture(&self, window: *mut Window) -> Result { + println!("Getting window attributes."); + let attr = unsafe { *self.get_window_attributes(window) }; + println!("Got window attributes."); + let image = unsafe { + xlib::XGetImage( + self.display, + *window, + attr.x, + attr.y, + attr.width as u32, + attr.height as u32, + 0xffffffff, + ZPixmap, + ) + }; + Ok(Image::from(image)) + } + + /// Get the full screen. + pub fn get_root_window(&self) -> *mut Window { + println!("Getting root window..."); + unsafe { xlib::XRootWindow(self.display, 0) as *mut Window } + } + + /// Get the active window. + pub fn get_active_window(&self) -> *mut Window { + let window: *mut Window = unsafe { ::std::mem::uninitialized() }; + let mut revert_to_return: i32 = unsafe { ::std::mem::uninitialized() }; + unsafe { xlib::XGetInputFocus(self.display, window, &mut revert_to_return) }; + window + } + + /// Brings up an interactive selection GUI. + pub fn interactive_select(&self, _capture: &Image) -> Result { + Err(ScreenshotError::Error) + } +} + +impl Drop for GUI { + fn drop(&mut self) { + unsafe { XUngrabServer(self.display) }; + } +} diff --git a/src/image.rs b/src/image.rs new file mode 100644 index 0000000..11c3fa7 --- /dev/null +++ b/src/image.rs @@ -0,0 +1,15 @@ +use x11::xlib::XImage; + +use Rectangle; + +pub struct Image { + _inner: *mut XImage, +} + +impl Image { + pub fn from(inner: *mut XImage) -> Self { + Image { _inner: inner } + } + + pub fn apply_region(&mut self, _region: &Rectangle) {} +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..34cb934 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate failure; +#[macro_use] +extern crate structopt; +extern crate time; +extern crate x11; + +mod capture; +mod errors; +mod gui; +mod image; +mod options; + +use failure::Error; +use structopt::StructOpt; + +use options::Options; + +pub struct Rectangle { + pub x: u32, + pub y: u32, + pub width: u32, + pub height: u32, +} + +pub fn run() -> Result<(), Error> { + let opt = Options::from_args(); + capture::capture(&opt)?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 9d54eb3..6f02a3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,31 +1,9 @@ -#![crate_name = "screenshot"] -#![crate_type = "bin"] - -extern crate cairo; -extern crate clap; -#[macro_use] -extern crate failure; -extern crate gdk; -extern crate gdk_pixbuf; -extern crate gio; -extern crate gtk; -extern crate slop_sys; -extern crate time; - -mod capture; -mod errors; -mod options; -mod selection; +extern crate screenshot; use std::process::exit; -use clap::{App, Arg}; -use failure::Error; - -use options::{Options, Region}; - fn main() { - match run() { + match screenshot::run() { Ok(()) => (), Err(error) => { eprintln!("Error: {}", error); @@ -33,45 +11,3 @@ fn main() { } } } - -fn run() -> Result<(), Error> { - let app = App::new("screenshot") - .version("0.1") - .arg( - Arg::with_name("region") - .help("The region to be captured.") - .takes_value(false) - .required(true), - ).arg( - Arg::with_name("output") - .alias("o") - .long("output") - .help("Specify the output file.") - .takes_value(true) - .required(true), - ).arg( - Arg::with_name("clip") - .alias("c") - .long("clip") - .help("Copies the image to the clipboard if set."), - ).get_matches(); - let region = match app.value_of("region").unwrap() { - "fullscreen" => Region::Fullscreen, - "active" | "window" => Region::ActiveWindow, - "select" | "selection" => Region::Selection, - _ => bail!("Please choose a valid region [fullscreen|active|select]"), - }; - let path = String::from(app.value_of("output").unwrap()); - let clip = app.is_present("clip"); - let options = Options::new(region, path, clip)?; - - gdk::init(); - gtk::init()?; - capture::capture(options)?; - // unsafe { - // libscreenshot_main(region, outfile_c.as_ptr()); - // } - // let image = capture(options)?.convert()?; - // image.save("target/shiet.png")?; - Ok(()) -} diff --git a/src/options.rs b/src/options.rs index 0774a2e..35ff500 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,28 +1,25 @@ -use std::fs::{canonicalize, OpenOptions}; use std::path::PathBuf; -use failure::Error; - +#[derive(StructOpt)] pub enum Region { + #[structopt(name = "fullscreen")] Fullscreen, + + #[structopt(name = "window")] ActiveWindow, + + #[structopt(name = "select")] Selection, } +#[derive(StructOpt)] pub struct Options { + #[structopt(subcommand)] pub region: Region, - pub outfile: PathBuf, - pub clip: bool, -} -impl Options { - pub fn new(region: Region, outfile: String, clip: bool) -> Result { - OpenOptions::new().create(true).write(true).open(&outfile)?; - let outfile = canonicalize(&outfile)?; - Ok(Options { - region, - outfile, - clip, - }) - } + #[structopt(short = "o", long = "out", parse(from_os_str))] + pub outfile: PathBuf, + + #[structopt(short = "c")] + pub clipboard: bool, } diff --git a/src/selection.rs b/src/selection.rs deleted file mode 100644 index b7ffeca..0000000 --- a/src/selection.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::ffi::CString; - -use failure::Error; -use gdk_pixbuf::{Pixbuf, PixbufExt}; - -use errors::ScreenshotError; -use slop_sys::{slop_options, slop_select}; - -pub fn select_area(pixbuf: Pixbuf) -> Result { - let xdisplay = CString::new(":0")?.as_ptr(); - - let mut options = slop_options { - quiet: 0, - border: 1.0, - padding: 1.0, - tolerance: 1.0, - highlight: 0, - nokeyboard: 0, - noopengl: 1, - nodecorations: 1, - shaders: &mut 0, - r: 0.7, - g: 0.7, - b: 0.7, - a: 1.0, - xdisplay, - }; - let selection = unsafe { slop_select(&mut options) }; - println!("{:?}", selection); - - if selection.cancelled == 1 { - bail!(ScreenshotError); - } - match pixbuf.new_subpixbuf( - selection.x.round() as i32, - selection.y.round() as i32, - selection.w.round() as i32, - selection.h.round() as i32, - ) { - Some(pixbuf) => Ok(pixbuf), - None => bail!(ScreenshotError), - } -}