mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-18 07:11:04 +02:00
feat(launcher): add option to minimize window if focused
This commit is contained in:
parent
9c13e534b7
commit
64b953ce5e
6 changed files with 58 additions and 7 deletions
|
@ -193,24 +193,31 @@ impl ItemButton {
|
|||
button.add_class("focused");
|
||||
}
|
||||
|
||||
let menu_state = Rc::new(RwLock::new(MenuState {
|
||||
num_windows: item.windows.len(),
|
||||
}));
|
||||
|
||||
{
|
||||
let app_id = item.app_id.clone();
|
||||
let tx = controller_tx.clone();
|
||||
let menu_state = menu_state.clone();
|
||||
button.connect_clicked(move |button| {
|
||||
// lazy check :| TODO: Improve this
|
||||
let style_context = button.style_context();
|
||||
if style_context.has_class("open") {
|
||||
try_send!(tx, ItemEvent::FocusItem(app_id.clone()));
|
||||
let menu_state = read_lock!(menu_state);
|
||||
|
||||
if style_context.has_class("focused") && menu_state.num_windows == 1 {
|
||||
try_send!(tx, ItemEvent::MinimizeItem(app_id.clone()));
|
||||
} else {
|
||||
try_send!(tx, ItemEvent::FocusItem(app_id.clone()));
|
||||
}
|
||||
} else {
|
||||
try_send!(tx, ItemEvent::OpenItem(app_id.clone()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let menu_state = Rc::new(RwLock::new(MenuState {
|
||||
num_windows: item.windows.len(),
|
||||
}));
|
||||
|
||||
{
|
||||
let app_id = item.app_id.clone();
|
||||
let tx = tx.clone();
|
||||
|
|
|
@ -56,6 +56,12 @@ pub struct LauncherModule {
|
|||
#[serde(default = "crate::config::default_false")]
|
||||
reversed: bool,
|
||||
|
||||
/// Whether to minimize a window if it is focused when clicked.
|
||||
///
|
||||
/// **Default**: `true`
|
||||
#[serde(default = "crate::config::default_true")]
|
||||
minimize_focused: bool,
|
||||
|
||||
// -- common --
|
||||
/// Truncate application names on the bar if they get too long.
|
||||
/// See [truncate options](module-level-options#truncate-mode).
|
||||
|
@ -111,6 +117,7 @@ pub enum ItemEvent {
|
|||
FocusItem(String),
|
||||
FocusWindow(usize),
|
||||
OpenItem(String),
|
||||
MinimizeItem(String),
|
||||
}
|
||||
|
||||
enum ItemOrWindow {
|
||||
|
@ -290,6 +297,7 @@ impl Module<gtk::Box> for LauncherModule {
|
|||
});
|
||||
|
||||
// listen to ui events
|
||||
let minimize_focused = self.minimize_focused;
|
||||
let wl = context.client::<wayland::Client>();
|
||||
spawn(async move {
|
||||
while let Some(event) = rx.recv().await {
|
||||
|
@ -318,8 +326,10 @@ impl Module<gtk::Box> for LauncherModule {
|
|||
} else {
|
||||
send_async!(tx, ModuleUpdateEvent::ClosePopup);
|
||||
|
||||
let minimize_window = matches!(event, ItemEvent::MinimizeItem(_));
|
||||
|
||||
let id = match event {
|
||||
ItemEvent::FocusItem(app_id) => {
|
||||
ItemEvent::FocusItem(app_id) | ItemEvent::MinimizeItem(app_id) => {
|
||||
lock!(items).get(&app_id).and_then(|item| {
|
||||
item.windows
|
||||
.iter()
|
||||
|
@ -338,7 +348,11 @@ impl Module<gtk::Box> for LauncherModule {
|
|||
.find_map(|(_, item)| item.windows.get(&id))
|
||||
{
|
||||
debug!("Focusing window {id}: {}", window.name);
|
||||
wl.toplevel_focus(window.id);
|
||||
if minimize_window && minimize_focused {
|
||||
wl.toplevel_minimize(window.id);
|
||||
} else {
|
||||
wl.toplevel_focus(window.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue