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

[linux] fix closing of custom context menu #3329 #3330

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Correctly compute `startURL` across multiple `GetStartURL` invocations when `FRONTEND_DEVSERVER_URL` is present. [#3299](https://github.com/wailsapp/wails/pull/3299)
- Fix the JS type of the `Screen` struct to match its Go counterpart by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295)
- Fix the `WML.Reload` method to ensure proper cleanup of registered event listeners by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295)
- Fix custom context menu closing immediately on linux by [@abichinger](https://github.com/abichinger) in [#3330](https://github.com/wailsapp/wails/pull/3330)
- Fix the output path and extension of model files produced by the binding generator by [@fbbdev](https://github.com/fbbdev) in [#3334](https://github.com/wailsapp/wails/pull/3334)
- Fix the import paths of model files in JS code produced by the binding generator by [@fbbdev](https://github.com/fbbdev) in [#3334](https://github.com/wailsapp/wails/pull/3334)

Expand Down
33 changes: 33 additions & 0 deletions v3/pkg/application/linux_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern gboolean handleFocusEvent(GtkWidget*, GdkEvent*, uintptr_t);
extern void handleLoadChanged(WebKitWebView*, WebKitLoadEvent, uintptr_t);
void handleClick(void*);
extern gboolean onButtonEvent(GtkWidget *widget, GdkEventButton *event, uintptr_t user_data);
extern gboolean onMenuButtonEvent(GtkWidget *widget, GdkEventButton *event, uintptr_t user_data);
extern void onDragNDrop(
void *target,
GdkDragContext* context,
Expand Down Expand Up @@ -361,6 +362,13 @@ func appDestroy(application pointer) {
C.g_application_quit((*C.GApplication)(application))
}

func (w *linuxWebviewWindow) contextMenuSignals(menu pointer) {
c := NewCalloc()
defer c.Free()
winID := unsafe.Pointer(uintptr(C.uint(w.parent.ID())))
C.signal_connect(unsafe.Pointer(menu), c.String("button-release-event"), C.onMenuButtonEvent, winID)
}

func (w *linuxWebviewWindow) contextMenuShow(menu pointer, data *ContextMenuData) {
geometry := C.GdkRectangle{
x: C.int(data.X),
Expand All @@ -376,6 +384,7 @@ func (w *linuxWebviewWindow) contextMenuShow(menu pointer, data *ContextMenuData
C.GDK_GRAVITY_NORTH_WEST,
(*C.GdkEvent)(&event),
)
w.ctxMenuOpened = true
}

func (a *linuxApp) getCurrentWindowID() uint {
Expand Down Expand Up @@ -1329,6 +1338,30 @@ func onButtonEvent(_ *C.GtkWidget, event *C.GdkEventButton, data C.uintptr_t) C.
return C.gboolean(0)
}

//export onMenuButtonEvent
func onMenuButtonEvent(_ *C.GtkWidget, event *C.GdkEventButton, data C.uintptr_t) C.gboolean {
// Constants (defined here to be easier to use with purego)
GdkButtonRelease := C.GDK_BUTTON_RELEASE // 7

windowId := uint(C.uint(data))
window := globalApplication.getWindowForID(windowId)
if window == nil {
return C.gboolean(0)
}
lw, ok := (window.(*WebviewWindow).impl).(*linuxWebviewWindow)
if !ok {
return C.gboolean(0)
}

// prevent custom context menu from closing immediately
if event.button == 3 && int(event._type) == GdkButtonRelease && lw.ctxMenuOpened {
lw.ctxMenuOpened = false
return C.gboolean(1)
}

return C.gboolean(0)
}

//export onDragNDrop
func onDragNDrop(target unsafe.Pointer, context *C.GdkDragContext, x C.gint, y C.gint, seldata unsafe.Pointer, info C.guint, time C.guint, data unsafe.Pointer) {
var length C.gint
Expand Down
32 changes: 18 additions & 14 deletions v3/pkg/application/webview_window_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ type dragInfo struct {
}

type linuxWebviewWindow struct {
id uint
application pointer
window pointer
webview pointer
parent *WebviewWindow
menubar pointer
vbox pointer
menu *Menu
accels pointer
lastWidth int
lastHeight int
drag dragInfo
lastX, lastY int
gtkmenu pointer
id uint
application pointer
window pointer
webview pointer
parent *WebviewWindow
menubar pointer
vbox pointer
menu *Menu
accels pointer
lastWidth int
lastHeight int
drag dragInfo
lastX, lastY int
gtkmenu pointer
ctxMenuOpened bool
}

var (
Expand Down Expand Up @@ -61,6 +62,9 @@ func (w *linuxWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData)
}
if menu.impl == nil {
ctxMenu.update()

native := ctxMenu.menu.impl.(*linuxMenu).native
w.contextMenuSignals(native)
}

native := ctxMenu.menu.impl.(*linuxMenu).native
Expand Down
Loading