We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5314

Summary: UnmapNotify does not mean that window has been iconified
Product: SDL Reporter: Alberts Muktupāvels <alberts.muktupavels>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: alberts.muktupavels, sezeroz
Version: 2.0.12   
Hardware: x86_64   
OS: Linux   
Attachments: x11events: ignore UnmapNotify events from XReparentWindow

Description Alberts Muktupāvels 2020-10-10 14:32:46 UTC
https://github.com/SDL-mirror/SDL/blob/master/src/video/x11/SDL_x11events.c#L949-L956

SDL receiving UnmapNotify event assumes that window has been iconified. This assumption seems wrong... For example UnmapNotify event is also sent when window is reparented, see https://tronche.com/gui/x/xlib/window-and-session-manager/XReparentWindow.html.

This causes problems when using SDL applications with Metacity 3.36+. Metacity now removes decorations when windows are fullscreen.

Perhaps SDL could check if next event is ReparentNotify and not dispatch UnmapNotify in that case? Something like this:

XEvent ev;
if (X11_XCheckIfEvent(display, &ev, &isReparentNotify, (XPointer)&xevent.xunmap))
  X11_XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&xevent.xunmap);
else
  X11_DispatchUnmapNotify(data);


static Bool isMapNotify(Display *dpy, XEvent *ev, XPointer unmap)
{
    XUnmapEvent *event;

    event = (XUnmapEvent*) unmap;

    return ev->type == MapNotify &&
        ev->xmap.window == event->window &&
        ev->xmap.serial == event->serial;
}

static Bool isReparentNotify(Display *dpy, XEvent *ev, XPointer unmap)
{
    XUnmapEvent *event;

    event = (XUnmapEvent*) unmap;

    return ev->type == ReparentNotify &&
        ev->xreparent.window == event->window &&
        ev->xreparent.serial == event->serial;
}
Comment 1 Sam Lantinga 2020-10-12 16:27:58 UTC
That seems reasonable, can you provide a tested and working patch? Can you also make sure that iconification is still detected correctly?
Comment 2 Alberts Muktupāvels 2020-10-17 20:11:44 UTC
Created attachment 4480 [details]
x11events: ignore UnmapNotify events from XReparentWindow
Comment 3 Alberts Muktupāvels 2020-10-17 20:16:32 UTC
(In reply to Sam Lantinga from comment #1)
> That seems reasonable, can you provide a tested and working patch? Can you
> also make sure that iconification is still detected correctly?

Patch attached. Iconification seems to work as expected.
Comment 4 Sam Lantinga 2020-10-20 00:27:20 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/204628027601