1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-20 03:44:23 +02:00

fix(launcher): popup not closing when hover leaves widget

Fixes #224
This commit is contained in:
Jake Stanger 2023-08-13 14:23:05 +01:00
parent 5255ddffbb
commit 54f0f232f2
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
2 changed files with 33 additions and 5 deletions

View file

@ -1,5 +1,6 @@
use super::open_state::OpenState; use super::open_state::OpenState;
use crate::clients::wayland::ToplevelHandle; use crate::clients::wayland::ToplevelHandle;
use crate::config::BarPosition;
use crate::gtk_helpers::IronbarGtkExt; use crate::gtk_helpers::IronbarGtkExt;
use crate::image::ImageProvider; use crate::image::ImageProvider;
use crate::modules::launcher::{ItemEvent, LauncherUpdate}; use crate::modules::launcher::{ItemEvent, LauncherUpdate};
@ -7,7 +8,7 @@ use crate::modules::ModuleUpdateEvent;
use crate::{read_lock, try_send}; use crate::{read_lock, try_send};
use color_eyre::{Report, Result}; use color_eyre::{Report, Result};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Button, IconTheme, Orientation}; use gtk::{Button, IconTheme};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::rc::Rc; use std::rc::Rc;
use std::sync::RwLock; use std::sync::RwLock;
@ -176,7 +177,7 @@ impl ItemButton {
item: &Item, item: &Item,
appearance: AppearanceOptions, appearance: AppearanceOptions,
icon_theme: &IconTheme, icon_theme: &IconTheme,
orientation: Orientation, bar_position: BarPosition,
tx: &Sender<ModuleUpdateEvent<LauncherUpdate>>, tx: &Sender<ModuleUpdateEvent<LauncherUpdate>>,
controller_tx: &Sender<ItemEvent>, controller_tx: &Sender<ItemEvent>,
) -> Self { ) -> Self {
@ -249,7 +250,9 @@ impl ItemButton {
try_send!( try_send!(
tx, tx,
ModuleUpdateEvent::OpenPopupAt(button.geometry(orientation)) ModuleUpdateEvent::OpenPopupAt(
button.geometry(bar_position.get_orientation())
)
); );
} else { } else {
try_send!(tx, ModuleUpdateEvent::ClosePopup); try_send!(tx, ModuleUpdateEvent::ClosePopup);
@ -259,6 +262,31 @@ impl ItemButton {
}); });
} }
{
let tx = tx.clone();
button.connect_leave_notify_event(move |button, ev| {
const THRESHOLD: f64 = 5.0;
let alloc = button.allocation();
let (x, y) = ev.position();
let close = match bar_position {
BarPosition::Top => y + THRESHOLD < alloc.height() as f64,
BarPosition::Bottom => y > 0.0,
BarPosition::Left => x + THRESHOLD < alloc.width() as f64,
BarPosition::Right => x > THRESHOLD,
};
if close {
try_send!(tx, ModuleUpdateEvent::ClosePopup);
}
Inhibit(false)
});
}
button.show_all(); button.show_all();
Self { Self {

View file

@ -334,7 +334,7 @@ impl Module<gtk::Box> for LauncherModule {
}; };
let show_names = self.show_names; let show_names = self.show_names;
let orientation = info.bar_position.get_orientation(); let bar_position = info.bar_position;
let mut buttons = IndexMap::<String, ItemButton>::new(); let mut buttons = IndexMap::<String, ItemButton>::new();
@ -350,7 +350,7 @@ impl Module<gtk::Box> for LauncherModule {
&item, &item,
appearance_options, appearance_options,
&icon_theme, &icon_theme,
orientation, bar_position,
&context.tx, &context.tx,
&controller_tx, &controller_tx,
); );