X11 Client Events

Started by
2 comments, last by andrew111 8 years, 6 months ago

Hi,

my next milestone is to port the Window class (or better the Window_Impl class) to X11 but

I am uncertain how to catch and process events like "WM_CLOSE" known from WinAPI.

Are there even events like this in Linux/X11?

Sincerely Julien

P.S.: My team has a reason NOT to use GLFW etc. even if it's just personal preference.

It's not a shame to make mistakes. As a programmer I am doing mistakes on a daily basis. - JonathanKlein

Advertisement

Yes there are equivalent messages in X11. Take a look at the XNextEvent function. This function will be run in a loop like the WndProc function. It accepts an XEvent structure in which you can query the type field to determine which event (Expose (a.k.a Paint), Click, ect.) occurred.

Sorry, my question was too unprecise.

I couldn't find any ID for a equivalent of WM_CLOSE/WM_QUIT/WM_DESTROY for "XEvent.type".

It's not a shame to make mistakes. As a programmer I am doing mistakes on a daily basis. - JonathanKlein

Try this:

Display *display;
Window win;
Atom wmDelete;

void onInit() {
    wmDelete=XInternAtom(display, "WM_DELETE_WINDOW", True);
    XSetWMProtocols(display, win, &wmDelete, 1);
}

void onUpdate() {
    XEvent ev;

    while(XPending(display)) {
        XNextEvent(display,&ev);

        if(ev.type==DestroyNotify) {
            //on exit
        }

        if(ev.type==ClientMessage && (Atom)ev.xclient.data.l[0] == wmDelete) {
            //on close window
        }

        XFreeEventData(display, &ev.xcookie);
    }
}

This topic is closed to new replies.

Advertisement