BurntSushi / xgb

The X Go Binding is a low-level API to communicate with the X server. It is modeled on XCB and supports many X extensions.
Other
489 stars 75 forks source link

Not reciving DestroyNotifyEvents despite using EventMaskSubstructureNotify #51

Closed manfromth3m0oN closed 4 years ago

manfromth3m0oN commented 4 years ago

In a similar fashion to #47 I am trying to receive DestroyNotifyEvents. I have registered the root window with EventMaskSubstructureNotify yet don't receive any. My code to get the root window looks like this

func takeOwnership() error {
    return xproto.ChangeWindowAttributesChecked(
        xc,
        xroot.Root,
        xproto.CwEventMask,
        []uint32{
            xproto.EventMaskButtonPress |
                xproto.EventMaskButtonRelease |
                xproto.EventMaskKeyPress |
                xproto.EventMaskKeyRelease |
                xproto.EventMaskStructureNotify |
                xproto.EventMaskSubstructureRedirect,
        }).Check()
}

And my event loop case concerning DestroyNotifyEvents looks like this:

case xproto.DestroyNotifyEvent:
                log.Println("destroy event registered")
                for _, w := range workspaces {
                    go func(w *workspace) {
                        if err := w.removeWindow(e.Window); err == nil {
                            if err := w.TileWindows(); err != nil {
                                log.Fatal(err)
                            }
                        }
                    }(w)
                }

I am unsure of what I'm doing wrong or if this is an error with with package (which I do doubt) The whole source can be viewed here Many thanks in advance

jezek commented 4 years ago

Pardon my intrusion.

I don't know, why your example doesn't work. I should work in theory.

What I understand is, you try to catch a close event on your created window. If yes, I've been in your position some years ago. After some struggles I've solved the window close notify problems by setting the WM_PROTOCOLS property using xproto.ChangePropertyChecked function and then listening to xproto.ClientMessageEvent with WM_DELETE_WINDOW protocol message. Here is the package which implements this approach, may it help you.

manfromth3m0oN commented 4 years ago

Thanks for your reply @jezek, Either I don't wholly understand your response or you are slightly misconstrued. The code here is intended to serve as a window manager so I don't end up creating any windows. I've taken a look at implementing what you recommend but to no avail. Just to make it doubly clear, I should be setting WM_PROTOCOLS on every window?

jezek commented 4 years ago

Oh, a window manager. Sorry, my fault, didn't even bother to click on your link. My apologies.

So you are trying to catch the destruction of any window. That wasn't my previous attempt. My attempt was to create window and then be able to listen to the destruction of the window initiated by code, user, etc. I don't really remember clearly, but I think, I made some research back then and that was the only reliable solution back then. I failed to figure out why other solutions didn't work, or I missed something. It feel to me like a hacky workaround back then and it feels the same today.

Just to make it doubly clear, I should be setting WM_PROTOCOLS on every window?

I really don't know right now. When I think, the WM in WM_PROTOCOLS stands for window manager. So I've been listening to window manager messages. But you are trying to do the window manager...

I'm sorry I was no real help.

manfromth3m0oN commented 4 years ago

Thanks for the help either way @jezek, I've managed to fix the problem by registering for xproto.EventMaskStructureNotify | xproto.EventMaskEnterWindow whenever encountering a new window. The problem is fixed so I'm going to close the issue