forked from michael/leanshot
get active window
This commit is contained in:
parent
a9511b94de
commit
f9126c4f83
2 changed files with 16 additions and 6 deletions
10
src/gui.rs
10
src/gui.rs
|
@ -20,12 +20,10 @@ impl GUI {
|
|||
|
||||
/// Get the active window.
|
||||
pub fn get_active_window(&self) -> Result<Window, ScreenshotError> {
|
||||
Ok(self.display.get_default_root_window()?)
|
||||
// let mut window: Window = self.display.get_default_root_window();
|
||||
// let mut revert_to_return: i32 = RevertToParent;
|
||||
// unsafe { XGetInputFocus(self.display, &mut window, &mut revert_to_return) };
|
||||
// unsafe { XMapRaised(self.display, window) };
|
||||
// window
|
||||
self.display
|
||||
.get_input_focus()
|
||||
.map(|(window, _)| window)
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
/// Brings up an interactive selection GUI.
|
||||
|
|
|
@ -38,6 +38,18 @@ impl Display {
|
|||
};
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue