From 9b7121c8bd489ca4a1c1ac7ed45a0d63c9767d62 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 11 Sep 2018 13:25:06 -0500 Subject: [PATCH] window capture works --- imlib2/lib.rs | 1 - src/capture.rs | 32 +++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/imlib2/lib.rs b/imlib2/lib.rs index 3d23c22..6c8da1a 100644 --- a/imlib2/lib.rs +++ b/imlib2/lib.rs @@ -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) }; } - diff --git a/src/capture.rs b/src/capture.rs index c42b4d4..ec7fb43 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -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)?;