mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-25 09:59:21 +01:00
Simplify window methods
This commit is contained in:
parent
17975cbbda
commit
f54f73b105
1 changed files with 28 additions and 80 deletions
|
@ -8,12 +8,12 @@ pub struct Window;
|
|||
impl Window {
|
||||
pub fn get_by_class<'a>(&self, class: &'a str) -> impl Iterator<Item = WindowHandle> + 'a {
|
||||
self.get_all()
|
||||
.filter(|win| win.class().as_deref() == Some(class))
|
||||
.filter(|win| win.properties().class.as_deref() == Some(class))
|
||||
}
|
||||
|
||||
pub fn get_focused(&self) -> Option<WindowHandle> {
|
||||
self.get_all()
|
||||
.find(|win| win.focused().is_some_and(|focused| focused))
|
||||
.find(|win| win.properties().focused.is_some_and(|focused| focused))
|
||||
}
|
||||
|
||||
pub fn get_all(&self) -> impl Iterator<Item = WindowHandle> {
|
||||
|
@ -27,6 +27,17 @@ impl Window {
|
|||
|
||||
pub struct WindowHandle(WindowId);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WindowProperties {
|
||||
pub size: Option<(i32, i32)>,
|
||||
pub loc: Option<(i32, i32)>,
|
||||
pub class: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub focused: Option<bool>,
|
||||
pub floating: Option<bool>,
|
||||
pub fullscreen_or_maximized: Option<FullscreenOrMaximized>,
|
||||
}
|
||||
|
||||
impl WindowHandle {
|
||||
pub fn toggle_floating(&self) {
|
||||
send_msg(Msg::ToggleFloating { window_id: self.0 }).unwrap();
|
||||
|
@ -53,91 +64,28 @@ impl WindowHandle {
|
|||
send_msg(Msg::CloseWindow { window_id: self.0 }).unwrap();
|
||||
}
|
||||
|
||||
pub fn size(&self) -> Option<(i32, i32)> {
|
||||
let RequestResponse::WindowProps { size, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
size
|
||||
}
|
||||
|
||||
pub fn loc(&self) -> Option<(i32, i32)> {
|
||||
let RequestResponse::WindowProps { loc, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
loc
|
||||
}
|
||||
|
||||
pub fn class(&self) -> Option<String> {
|
||||
let RequestResponse::WindowProps { class, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
class
|
||||
}
|
||||
|
||||
pub fn title(&self) -> Option<String> {
|
||||
let RequestResponse::WindowProps { title, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
title
|
||||
}
|
||||
|
||||
pub fn floating(&self) -> Option<bool> {
|
||||
let RequestResponse::WindowProps { floating, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
floating
|
||||
}
|
||||
|
||||
pub fn maximized(&self) -> Option<bool> {
|
||||
pub fn properties(&self) -> WindowProperties {
|
||||
let RequestResponse::WindowProps {
|
||||
size,
|
||||
loc,
|
||||
class,
|
||||
title,
|
||||
focused,
|
||||
floating,
|
||||
fullscreen_or_maximized,
|
||||
..
|
||||
} = request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
fullscreen_or_maximized.map(|fullscreen_or_maximized| {
|
||||
matches!(fullscreen_or_maximized, FullscreenOrMaximized::Maximized)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn fullscreen(&self) -> Option<bool> {
|
||||
let RequestResponse::WindowProps {
|
||||
WindowProperties {
|
||||
size,
|
||||
loc,
|
||||
class,
|
||||
title,
|
||||
focused,
|
||||
floating,
|
||||
fullscreen_or_maximized,
|
||||
..
|
||||
} = request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
fullscreen_or_maximized.map(|fullscreen_or_maximized| {
|
||||
matches!(fullscreen_or_maximized, FullscreenOrMaximized::Fullscreen)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn focused(&self) -> Option<bool> {
|
||||
let RequestResponse::WindowProps { focused, .. } =
|
||||
request(Request::GetWindowProps { window_id: self.0 })
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
focused
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue