Skip to content

How to correctly handle widget destoryment #318

Answered by Aylur
A7R7 asked this question in Q&A
Discussion options

You must be logged in to vote

you can either keep a reference to the menu and reuse it, or destroy it explicitly after it closes

// keep a reference
function EventBox() {
    const menu = Widget.Menu()

    return Widget.EventBox({
        on_secondary_click: (_, event) => {
            menu.popup_at_pointer(event)
        },
    })
}

// destroy explicitly
on_secondary_click: (_, event) => {
    return Widget.Menu()
        .on("notify::visible", (self) => {
            if (!self.visible)
                self.destroy()
        })
        .popup_at_pointer(event)
},

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@A7R7
Comment options

@Aylur
Comment options

Answer selected by A7R7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants