Skip to content

Commit ca391df

Browse files
authored
Merge pull request #1309 from JakeStanger/fix/launcher-popup
fix(launcher): popup flicker when `popup_autohide` enabled
2 parents 7a8a26b + 8ac2b8a commit ca391df

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/modules/launcher/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ mod pagination;
55
use self::item::{AppearanceOptions, Item, ItemButton, Window};
66
use self::open_state::OpenState;
77
use super::{
8-
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
8+
Module, ModuleInfo, ModuleParts, ModulePopup, ModulePopupParts, ModuleUpdateEvent, PopupButton,
9+
WidgetContext,
910
};
1011
use crate::channels::{AsyncSenderExt, BroadcastReceiverExt};
1112
use crate::clients::wayland::{self, ToplevelEvent};
@@ -595,7 +596,8 @@ impl Module<gtk::Box> for LauncherModule {
595596
.values()
596597
.find(|b| b.button.button.popup_id() == id)
597598
.map(|b| b.button.button.clone())
598-
}));
599+
}))
600+
.map(ModulePopupParts::disable_autohide);
599601

600602
Ok(ModuleParts {
601603
widget: container,

src/modules/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,20 @@ pub struct ModulePopupParts {
198198
/// An array of buttons which can be used for opening the popup.
199199
/// For most modules, this will only be a single button.
200200
pub buttons: Vec<Button>,
201+
/// Whether this module disallows the popover widget from using autohide.
202+
/// Where popups are controlled via hover, autohide can cause issues.
203+
pub disable_autohide: bool,
201204

202205
pub button_finder: Option<Rc<ButtonFinder>>,
203206
}
204207

208+
impl ModulePopupParts {
209+
fn disable_autohide(mut self) -> Self {
210+
self.disable_autohide = true;
211+
self
212+
}
213+
}
214+
205215
impl Debug for ModulePopupParts {
206216
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
207217
f.debug_struct("ModulePopupParts")
@@ -229,6 +239,7 @@ impl ModulePopup for Option<gtk::Box> {
229239
container,
230240
buttons,
231241
button_finder: None,
242+
disable_autohide: false,
232243
})
233244
}
234245

@@ -237,6 +248,7 @@ impl ModulePopup for Option<gtk::Box> {
237248
container,
238249
buttons: vec![],
239250
button_finder: Some(finder),
251+
disable_autohide: false,
240252
})
241253
}
242254
}

src/popup.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use tracing::{debug, error};
1111

1212
#[derive(Debug)]
1313
pub struct PopupCacheValue {
14-
// pub name: String,
1514
pub content: gtk::Box,
15+
/// Whether this module disallows the popover widget from using autohide.
16+
/// Where popups are controlled via hover, autohide can cause issues.
17+
pub disable_autohide: bool,
1618
}
1719

1820
#[derive(Debug, Clone, Copy)]
@@ -30,6 +32,7 @@ pub struct Popup {
3032
pub button_cache: Rc<RefCell<Vec<Button>>>,
3133
pos: BarPosition,
3234
current_widget: Rc<RefCell<Option<CurrentWidgetInfo>>>,
35+
autohide: bool,
3336
}
3437

3538
impl Debug for Popup {
@@ -84,6 +87,7 @@ impl Popup {
8487
button_finder_cache: rc_mut!(HashMap::new()),
8588
pos,
8689
current_widget: rc_mut!(None),
90+
autohide,
8791
}
8892
}
8993

@@ -102,6 +106,7 @@ impl Popup {
102106
key,
103107
PopupCacheValue {
104108
content: content.container.clone(),
109+
disable_autohide: content.disable_autohide,
105110
},
106111
);
107112

@@ -128,7 +133,11 @@ impl Popup {
128133
pub fn show(&self, widget_id: usize, button_id: usize) {
129134
self.clear_window();
130135

131-
if let Some(PopupCacheValue { content, .. }) = self.container_cache.borrow().get(&widget_id)
136+
if let Some(PopupCacheValue {
137+
content,
138+
disable_autohide,
139+
..
140+
}) = self.container_cache.borrow().get(&widget_id)
132141
{
133142
*self.current_widget.borrow_mut() = Some(CurrentWidgetInfo { widget_id });
134143

@@ -151,6 +160,11 @@ impl Popup {
151160
self.popover.set_child(Some(content));
152161
self.popover.unparent();
153162
self.popover.set_parent(&button);
163+
164+
if *disable_autohide {
165+
self.popover.set_autohide(false);
166+
}
167+
154168
self.popover.popup();
155169
}
156170
}
@@ -163,14 +177,23 @@ impl Popup {
163177
pub fn show_for(&self, widget_id: usize, button: &Button) -> bool {
164178
self.clear_window();
165179

166-
if let Some(PopupCacheValue { content, .. }) = self.container_cache.borrow().get(&widget_id)
180+
if let Some(PopupCacheValue {
181+
content,
182+
disable_autohide,
183+
..
184+
}) = self.container_cache.borrow().get(&widget_id)
167185
{
168186
*self.current_widget.borrow_mut() = Some(CurrentWidgetInfo { widget_id });
169187

170188
content.add_css_class("popup");
171189
self.popover.set_child(Some(content));
172190
self.popover.unparent();
173191
self.popover.set_parent(button);
192+
193+
if *disable_autohide {
194+
self.popover.set_autohide(false);
195+
}
196+
174197
self.popover.popup();
175198

176199
true
@@ -181,6 +204,7 @@ impl Popup {
181204

182205
fn clear_window(&self) {
183206
self.popover.set_child(None::<&gtk::Box>);
207+
self.popover.set_autohide(self.autohide);
184208
}
185209

186210
/// Hides the popup

0 commit comments

Comments
 (0)