On X11 and Wayland, add is_maximized support

Fixes #1845.

Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
garasubo 2021-06-10 16:43:27 +09:00 committed by GitHub
parent 67cca71524
commit c916eb6137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View file

@ -779,6 +779,30 @@ impl UnownedWindow {
.expect("Failed to change window minimization");
}
#[inline]
pub fn is_maximized(&self) -> bool {
let state_atom = unsafe { self.xconn.get_atom_unchecked(b"_NET_WM_STATE\0") };
let state = self
.xconn
.get_property(self.xwindow, state_atom, ffi::XA_ATOM);
let horz_atom = unsafe {
self.xconn
.get_atom_unchecked(b"_NET_WM_STATE_MAXIMIZED_HORZ\0")
};
let vert_atom = unsafe {
self.xconn
.get_atom_unchecked(b"_NET_WM_STATE_MAXIMIZED_VERT\0")
};
match state {
Ok(atoms) => {
let horz_maximized = atoms.iter().any(|atom: &ffi::Atom| *atom == horz_atom);
let vert_maximized = atoms.iter().any(|atom: &ffi::Atom| *atom == vert_atom);
horz_maximized && vert_maximized
}
_ => false,
}
}
fn set_maximized_inner(&self, maximized: bool) -> util::Flusher<'_> {
let horz_atom = unsafe {
self.xconn