Created
February 4, 2018 20:07
-
-
Save mtao/f9b733103e229b7711196977d406c1d6 to your computer and use it in GitHub Desktop.
glfw patch for libigl on xmonad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/x11_platform.h b/src/x11_platform.h | |
| index 7b46025..b48968f 100644 | |
| --- a/src/x11_platform.h | |
| +++ b/src/x11_platform.h | |
| @@ -112,6 +112,7 @@ typedef struct _GLFWwindowX11 | |
| XIC ic; | |
| GLFWbool overrideRedirect; | |
| + GLFWbool visuallyMapped; | |
| // Cached position and size used to filter out duplicate events | |
| int width, height; | |
| diff --git a/src/x11_window.c b/src/x11_window.c | |
| index 1bcab26..36d915f 100644 | |
| --- a/src/x11_window.c | |
| +++ b/src/x11_window.c | |
| @@ -604,6 +604,7 @@ static GLFWbool createWindow(_GLFWwindow* window, | |
| _glfwPlatformGetWindowPos(window, &window->x11.xpos, &window->x11.ypos); | |
| _glfwPlatformGetWindowSize(window, &window->x11.width, &window->x11.height); | |
| + window->x11.visuallyMapped = GLFW_FALSE; // Assume window isn't mapped yet. | |
| return GLFW_TRUE; | |
| } | |
| @@ -1365,6 +1366,29 @@ static void processEvent(XEvent *event) | |
| return; | |
| } | |
| + case VisibilityNotify: | |
| + { | |
| + int visibilityState = event->xvisibility.state; | |
| + // Some window managers (mostly non-reparenting | |
| + // like dwm, xmonad, ratpoision, openbox, cwm), | |
| + // don't set the visibility flag after mapping, | |
| + // a pre-condition for e.g. XSetInputFocus()... | |
| + // leads to BadMatch error as described in X11. | |
| + // Most of these will however notify with event | |
| + // VisibilityFullyObscured on visibility unset. | |
| + if (visibilityState != VisibilityFullyObscured) | |
| + window->x11.visuallyMapped = GLFW_TRUE; | |
| + return; | |
| + } | |
| + | |
| + case UnmapNotify: | |
| + { | |
| + // Should be the only case when a window | |
| + // becomes completely visually unmapped. | |
| + window->x11.visuallyMapped = GLFW_FALSE; | |
| + return; | |
| + } | |
| + | |
| case FocusIn: | |
| { | |
| if (window->cursorMode == GLFW_CURSOR_DISABLED) | |
| @@ -1925,6 +1949,11 @@ void _glfwPlatformFocusWindow(_GLFWwindow* window) | |
| else | |
| { | |
| XRaiseWindow(_glfw.x11.display, window->x11.handle); | |
| + // Requested window might not have been completely initialized | |
| + // by the window manager at this point, need to wait until the | |
| + // window has both been mapped and also set a visibility flag. | |
| + // Wait for VisibilityNotify X11 event before setting a focus. | |
| + while (!window->x11.visuallyMapped) _glfwPlatformWaitEvents(); | |
| XSetInputFocus(_glfw.x11.display, window->x11.handle, | |
| RevertToParent, CurrentTime); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment