get active window

This commit is contained in:
Michael Zhang 2018-09-10 20:44:07 -05:00
parent a9511b94de
commit f9126c4f83
No known key found for this signature in database
GPG key ID: A1B65B603268116B
2 changed files with 16 additions and 6 deletions

View file

@ -20,12 +20,10 @@ impl GUI {
/// Get the active window. /// Get the active window.
pub fn get_active_window(&self) -> Result<Window, ScreenshotError> { pub fn get_active_window(&self) -> Result<Window, ScreenshotError> {
Ok(self.display.get_default_root_window()?) self.display
// let mut window: Window = self.display.get_default_root_window(); .get_input_focus()
// let mut revert_to_return: i32 = RevertToParent; .map(|(window, _)| window)
// unsafe { XGetInputFocus(self.display, &mut window, &mut revert_to_return) }; .map_err(|err| err.into())
// unsafe { XMapRaised(self.display, window) };
// window
} }
/// Brings up an interactive selection GUI. /// Brings up an interactive selection GUI.

View file

@ -38,6 +38,18 @@ impl Display {
}; };
Ok(window) Ok(window)
} }
/// eturns the focus window and the current focus state.
pub fn get_input_focus(&self) -> Result<(Window, i32), X11Error> {
let mut focus_return: x::Window = 0;
let mut revert_to_return = 0;
unsafe { x::XGetInputFocus(self.inner, &mut focus_return, &mut revert_to_return) };
let window = Window {
display: self.inner,
inner: focus_return,
};
return Ok((window, revert_to_return));
}
} }
impl Drop for Display { impl Drop for Display {