1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00

feat(launcher): add option to minimize window if focused

This commit is contained in:
pachliopta 2024-11-10 16:20:28 +11:00 committed by Jake Stanger
parent 9c13e534b7
commit 64b953ce5e
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
6 changed files with 58 additions and 7 deletions

View file

@ -76,6 +76,8 @@ pub enum Request {
ToplevelInfoAll,
#[cfg(feature = "launcher")]
ToplevelFocus(usize),
#[cfg(feature = "launcher")]
ToplevelMinimize(usize),
#[cfg(feature = "clipboard")]
CopyToClipboard(ClipboardItem),
@ -350,6 +352,19 @@ impl Environment {
send!(env.response_tx, Response::Ok);
}
#[cfg(feature = "launcher")]
Msg(Request::ToplevelMinimize(id)) => {
let handle = env
.handles
.iter()
.find(|handle| handle.info().map_or(false, |info| info.id == id));
if let Some(handle) = handle {
handle.minimize();
}
send!(env.response_tx, Response::Ok);
}
#[cfg(feature = "clipboard")]
Msg(Request::CopyToClipboard(item)) => {
env.copy_to_clipboard(item);

View file

@ -33,6 +33,11 @@ impl ToplevelHandle {
trace!("Activating handle");
self.handle.activate(seat);
}
pub fn minimize(&self) {
trace!("Minimizing handle");
self.handle.set_minimized();
}
}
#[derive(Debug, Default)]

View file

@ -36,6 +36,15 @@ impl Client {
}
}
/// Minimizes the toplevel with the provided ID.
#[cfg(feature = "launcher")]
pub fn toplevel_minimize(&self, handle_id: usize) {
match self.send_request(Request::ToplevelMinimize(handle_id)) {
Response::Ok => (),
_ => unreachable!(),
}
}
/// Subscribes to events from toplevels.
pub fn subscribe_toplevels(&self) -> broadcast::Receiver<ToplevelEvent> {
self.toplevel_channel.0.subscribe()