Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

Easy way to access variant parameter in action handler #39

@nilathedragon

Description

@nilathedragon

Currently there seems to be no way to easily access the parameter given to an action. I was able to figure out I can unsafe-cast the pointer to a variant, but ideally the callback function would type the parameter with a *glib.Variant instead.

Current Solution

action := gio.NewSimpleAction("win.some-action", glib.NewVariantType("x"))
action.ConnectActivate(g.Ptr(func(action gio.SimpleAction, parameter uintptr) {
	variant := (*glib.Variant)(unsafe.Pointer(parameter))
	id := variant.GetInt64()
	fmt.Println(id)
}))
w.AddAction(action)

Ideal Solution

action := gio.NewSimpleAction("win.some-action", glib.NewVariantType("x"))
action.ConnectActivate(g.Ptr(func(action gio.SimpleAction, parameter *glib.Variant) {
	id := parameter.GetInt64()
	fmt.Println(id)
}))
w.AddAction(action)

(g.Ptr is a helper I made, it just makes a pointer to whatever is passed in)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions