Changed state attribs to direct access.

Changed the window states (focused, iconified and visible) to query the
system directly.

THIS IS A BREAKING CHANGE, although a fairly obscure one.  It affects
applications that both care about telling actual key events from
synthetic ones, and are implemented in a non-self-synchronizing way, and
that poll the GLFW_FOCUSED window attribute instead of using the window
focus callback.

If you maintain one of these, please feel free to drop me an email and
I'll help any way I can to transition your application to 3.1.

Fixes #189.
Fixes #204.
This commit is contained in:
Camilla Berglund
2014-12-26 12:25:48 +01:00
parent f9c1f85f02
commit 641761ddb0
8 changed files with 159 additions and 139 deletions
+48 -29
View File
@@ -57,6 +57,28 @@ typedef struct
#define MWM_HINTS_DECORATIONS (1L << 1)
// Returns whether the window is iconified
//
static int getWindowState(_GLFWwindow* window)
{
int result = WithdrawnState;
struct {
CARD32 state;
Window icon;
} *state = NULL;
if (_glfwGetWindowProperty(window->x11.handle,
_glfw.x11.WM_STATE,
_glfw.x11.WM_STATE,
(unsigned char**) &state) >= 2)
{
result = state->state;
}
XFree(state);
return result;
}
// Returns whether the event is a selection event
//
static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointer)
@@ -1229,18 +1251,6 @@ static void processEvent(XEvent *event)
break;
}
case MapNotify:
{
_glfwInputWindowVisibility(window, GL_TRUE);
break;
}
case UnmapNotify:
{
_glfwInputWindowVisibility(window, GL_FALSE);
break;
}
case FocusIn:
{
if (event->xfocus.mode == NotifyNormal)
@@ -1278,23 +1288,11 @@ static void processEvent(XEvent *event)
if (event->xproperty.atom == _glfw.x11.WM_STATE &&
event->xproperty.state == PropertyNewValue)
{
struct {
CARD32 state;
Window icon;
} *state = NULL;
if (_glfwGetWindowProperty(window->x11.handle,
_glfw.x11.WM_STATE,
_glfw.x11.WM_STATE,
(unsigned char**) &state) >= 2)
{
if (state->state == IconicState)
_glfwInputWindowIconify(window, GL_TRUE);
else if (state->state == NormalState)
_glfwInputWindowIconify(window, GL_FALSE);
}
XFree(state);
const int state = getWindowState(window);
if (state == IconicState)
_glfwInputWindowIconify(window, GL_TRUE);
else if (state == NormalState)
_glfwInputWindowIconify(window, GL_FALSE);
}
break;
@@ -1671,6 +1669,27 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
Window focused;
int state;
XGetInputFocus(_glfw.x11.display, &focused, &state);
return window->x11.handle == focused;
}
int _glfwPlatformWindowIconified(_GLFWwindow* window)
{
return getWindowState(window) == IconicState;
}
int _glfwPlatformWindowVisible(_GLFWwindow* window)
{
XWindowAttributes wa;
XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &wa);
return wa.map_state == IsViewable;
}
void _glfwPlatformPollEvents(void)
{
int count = XPending(_glfw.x11.display);