Skip to content

Commit

Permalink
fix(tray): prevent widget buttons from piling up (#788)
Browse files Browse the repository at this point in the history
each call to set_menu_widget registered a new event handler,
resulting in multiple popups to be created. each popup tried
to issue a grab with the same serial.
prevent this by disconnecting any previously registered handler.
  • Loading branch information
cmeissl authored Nov 19, 2024
1 parent 944006f commit ce48fc9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/modules/tray/interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glib::Propagation;
use glib::{Propagation, SignalHandlerId};
use gtk::gdk::Gravity;
use gtk::prelude::*;
use gtk::{EventBox, Image, Label, MenuItem};
Expand All @@ -7,6 +7,7 @@ use system_tray::item::{IconPixmap, StatusNotifierItem, Tooltip};
/// Main tray icon to show on the bar
pub(crate) struct TrayMenu {
pub event_box: EventBox,
button_handler: Option<SignalHandlerId>,
widget: MenuItem,
image_widget: Option<Image>,
label_widget: Option<Label>,
Expand All @@ -29,6 +30,7 @@ impl TrayMenu {

let mut slf = Self {
event_box,
button_handler: None,
widget,
image_widget: None,
label_widget: None,
Expand Down Expand Up @@ -113,10 +115,14 @@ impl TrayMenu {
}

pub fn set_menu_widget(&mut self, menu: system_tray::gtk_menu::Menu) {
self.event_box
let button_handler = self
.event_box
.connect_button_press_event(move |event_box, _event| {
menu.popup_at_widget(event_box, Gravity::North, Gravity::South, None);
Propagation::Proceed
});
if let Some(handler) = self.button_handler.replace(button_handler) {
self.event_box.disconnect(handler);
}
}
}

0 comments on commit ce48fc9

Please sign in to comment.