window capture works

This commit is contained in:
Michael Zhang 2018-09-11 13:25:06 -05:00
parent 24d019fdcb
commit 9b7121c8bd
No known key found for this signature in database
GPG key ID: A1B65B603268116B
2 changed files with 17 additions and 16 deletions

View file

@ -25,4 +25,3 @@ pub fn context_set_display(display: *mut x11::xlib::Display) {
pub fn context_set_visual(visual: Visual) {
unsafe { imlib2_sys::imlib_context_set_visual(visual.inner) };
}

View file

@ -3,8 +3,6 @@ use errors::ScreenshotError;
use gui::GUI;
use options::{Options, Region};
use Rectangle;
pub fn capture(opt: &Options) -> Result<(), ScreenshotError> {
let gui = GUI::new()?;
@ -12,21 +10,25 @@ pub fn capture(opt: &Options) -> Result<(), ScreenshotError> {
// Region::Fullscreen | Region::Selection => gui.display.get_default_root_window()?,
// Region::ActiveWindow => gui.get_active_window()?,
// };
let window_to_capture = gui.display.get_default_root_window()?;
let window_to_capture = match opt.region {
Region::ActiveWindow => gui.get_active_window()?,
_ => gui.display.get_default_root_window()?,
};
// let _clip = match opt.region {
// Region::ActiveWindow => {
// let win = gui.get_active_window()?;
// let attr = win.get_attributes()?;
// let width = attr.get_width();
// let height = attr.get_height();
// let root = gui.display.get_default_root_window()?;
// let (x, y, _) = gui.display.translate_coordinates(win, 0, 0, root)?;
// Some(Rectangle::new(x as u32, y as u32, width, height))
// }
// _ => None,
// };
let capture = gui.capture_window(window_to_capture)?;
let _clip = match opt.region {
Region::ActiveWindow => {
let win = gui.get_active_window()?;
let attr = win.get_attributes()?;
let width = attr.get_width();
let height = attr.get_height();
let root = gui.display.get_default_root_window()?;
let (x, y, _) = gui.display.translate_coordinates(win, 0, 0, root)?;
Some(Rectangle::new(x as u32, y as u32, width, height))
}
_ => None,
};
// capture.write_png(&opt.outfile, clip)?;
capture.save_image(&opt.outfile)?;