Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tray: prevent widget buttons from piling up #788

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading