Skip to content

Commit

Permalink
fix: set time for GTK context menu (#190)
Browse files Browse the repository at this point in the history
* setting the time field of the context menu event

fixes tauri-apps/tauri#9658

* change file

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
  • Loading branch information
rtbo and amrbashir authored May 7, 2024
1 parent 67c9d6c commit 1dc9d3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/gtk-context-menu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"muda": patch
---

On Linux, fix context menu closing immediately when right click is released.
14 changes: 13 additions & 1 deletion src/platform_impl/gtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use crate::{
IsMenuItem, MenuEvent, MenuId, MenuItemKind, MenuItemType,
};
use accelerator::{from_gtk_mnemonic, parse_accelerator, to_gtk_mnemonic};
use gtk::{gdk, prelude::*, AboutDialog, Container, Orientation};
use glib::translate::ToGlibPtr;
use gtk::{gdk, glib, prelude::*, AboutDialog, Container, Orientation};
use std::{
cell::RefCell,
collections::{hash_map::Entry, HashMap},
Expand Down Expand Up @@ -1388,6 +1389,17 @@ fn show_context_menu(
.and_then(|d| d.pointer())
.as_ref(),
);

// Set the time of the event otherwise GTK will close the menu
// when right click is released
let event_ffi: *mut gdk::ffi::GdkEvent = event.to_glib_none().0;
if !event_ffi.is_null() {
let time = glib::monotonic_time() / 1000;
unsafe {
(*event_ffi).button.time = time as _;
}
}

gtk_menu.popup_at_rect(
&window,
&gdk::Rectangle::new(pos.0, pos.1, 0, 0),
Expand Down

0 comments on commit 1dc9d3f

Please sign in to comment.