| Summary: | Window steals focus when switching to a different desktop | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Katie Stafford <katie> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | ASSIGNED --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | blacktav, katie |
| Version: | 2.0.1 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: | Quick patch | ||
|
Description
Katie Stafford
2014-02-21 07:16:35 UTC
I've never seen this behavior or heard of it before. Can you track down the sequence of X11 events and calls that are causing this? Thanks! Created attachment 1575 [details]
Quick patch
I've traced the problem to SDL_x11events.c:768, in the handling for PropertyNotify:
if (xevent.xproperty.atom == data->videodata->_NET_WM_STATE) {
/* Get the new state from the window manager.
Compositing window managers can alter visibility of windows
without ever mapping / unmapping them, so we handle that here,
because they use the NETWM protocol to notify us of changes.
*/
Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window);
if ((flags^data->window->flags) & SDL_WINDOW_HIDDEN) {
if (flags & SDL_WINDOW_HIDDEN) {
X11_DispatchUnmapNotify(data);
} else {
X11_DispatchMapNotify(data);
}
}
}
The problem is that XFCE only sets _NET_WM_STATE_HIDDEN on windows that are minimized, not on windows that are not visible due to being on another desktop.
The comment above indicates that this code works around other window managers not sending unmap events, so it shouldn't be run if an unmap event has been received, i.e. SDL_WINDOW_HIDDEN should be the logical OR of <unmapped> or <_NET_WM_STATE_HIDDEN>.
I have attached a quick-and-dirty patch which fixes the problem for me, but I haven't tested with any other window managers.
There is another related issue that happens now that I have applied the patch: SDL_OnWindowRestored calls SDL_RaiseWindow, so any time the window is unhidden, it steals focus. If I have an SDL application in the background, and I switch to another desktop, then switch back, the SDL application will now be in the foreground. Is there a reason SDL_RaiseWindow needs to be called from SDL_OnWindowRestored? It seems that the intention was that OnWindowRestored means that the window was minimized, and the user has just switched to it, in which case it should already be in the foreground and focused. Forgot to mark as responded Should this issue be closed now? I seem to be experiencing similar behaviour with SDL 2.0.3 |