diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs index a7e2bd3f..1ef69ec1 100644 --- a/fractal-gtk/src/widgets/message.rs +++ b/fractal-gtk/src/widgets/message.rs @@ -53,10 +53,8 @@ impl<'a> MessageBox<'a> { let ui = op.ui.clone(); row_eb.connect_button_press_event(clone!(msg => move |eb, btn| { if btn.get_button() == 3 { - let position = btn.get_position(); - *message_menu.write().unwrap() = Some(MessageMenu::new_message_menu(ui.clone(), msg.clone())); - message_menu.read().unwrap().clone().unwrap().show_menu_popover(eb.clone().upcast::(), position); + message_menu.read().unwrap().clone().unwrap().show_menu_popover(eb.clone().upcast::()); } Inhibit(false) @@ -565,10 +563,8 @@ impl<'a> MessageBox<'a> { w.connect_button_press_event(move |_, btn| { if btn.get_button() == 3 { - let position = btn.get_position(); - *message_menu.write().unwrap() = Some(MessageMenu::new_message_menu(ui.clone(), msg.clone())); - message_menu.read().unwrap().clone().unwrap().show_menu_popover(eb.clone().upcast::(), position); + message_menu.read().unwrap().clone().unwrap().show_menu_popover(eb.clone().upcast::()); Inhibit(true) } else { diff --git a/fractal-gtk/src/widgets/message_menu.rs b/fractal-gtk/src/widgets/message_menu.rs index d949b9d4..db6864b7 100644 --- a/fractal-gtk/src/widgets/message_menu.rs +++ b/fractal-gtk/src/widgets/message_menu.rs @@ -2,6 +2,7 @@ extern crate gdk; extern crate gtk; extern crate sourceview; +use self::gdk::prelude::*; use self::gtk::prelude::*; use self::sourceview::prelude::*; @@ -23,22 +24,32 @@ impl MessageMenu { } } - pub fn show_menu_popover(&self, w: gtk::Widget, (x, y): (f64, f64)) { - let menu_popover: gtk::Popover = self.ui.builder - .get_object("message_menu_popover") - .expect("Can't find message_menu_popover in ui file."); - let rect = gtk::Rectangle { - x: x as i32, - y: y as i32, - width: 0, - height: 0, - }; + pub fn show_menu_popover(&self, w: gtk::Widget) { + gdk::Display::get_default() + .and_then(|disp| disp.get_default_seat()) + .and_then(|seat| seat.get_pointer()) + .map(|ptr| { + let win = w.get_window()?; + let (_, x, y, _) = win.get_device_position(&ptr); - menu_popover.set_relative_to(&w); - menu_popover.set_pointing_to(&rect); - menu_popover.set_position(gtk::PositionType::Bottom); + let menu_popover: gtk::Popover = self.ui.builder + .get_object("message_menu_popover") + .expect("Can't find message_menu_popover in ui file."); + let rect = gtk::Rectangle { + x, + y, + width: 0, + height: 0, + }; - menu_popover.popup(); + menu_popover.set_relative_to(&w); + menu_popover.set_pointing_to(&rect); + menu_popover.set_position(gtk::PositionType::Bottom); + + menu_popover.popup(); + + Some(true) + }); } pub fn insert_quote(&self) {