Add glfwFocusWindow

This removes the (undocumented) behavior where glfwShowWindow would
bring the window to front and set input focus.  That function now
does what it says.
This commit is contained in:
Camilla Berglund
2016-02-21 15:42:49 +01:00
parent de3e413aab
commit baf574494d
11 changed files with 103 additions and 51 deletions
+11 -10
View File
@@ -84,6 +84,7 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window)
bounds.size.height);
[window->ns.object setFrame:frame display:YES];
_glfwPlatformFocusWindow(window);
return status;
}
@@ -1039,6 +1040,16 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
[window->ns.object orderFront:nil];
}
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
[window->ns.object orderOut:nil];
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
// Make us the active application
// HACK: This has been moved here from initializeAppKit to prevent
@@ -1049,16 +1060,6 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
[window->ns.object makeKeyAndOrderFront:nil];
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
[window->ns.object orderFront:nil];
}
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
[window->ns.object orderOut:nil];
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
return [window->ns.object isKeyWindow];
+5 -4
View File
@@ -684,15 +684,16 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
*/
void _glfwPlatformShowWindow(_GLFWwindow* window);
/*! @ingroup platform
*/
void _glfwPlatformUnhideWindow(_GLFWwindow* window);
/*! @copydoc glfwHideWindow
* @ingroup platform
*/
void _glfwPlatformHideWindow(_GLFWwindow* window);
/*! @copydoc glfwFocusWindow
* @ingroup platform
*/
void _glfwPlatformFocusWindow(_GLFWwindow* window);
/*! @brief Returns whether the window is focused.
* @ingroup platform
*/
+1 -1
View File
@@ -495,7 +495,7 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
mir_surface_spec_release(spec);
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
+7 -8
View File
@@ -1034,14 +1034,6 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
ShowWindow(window->win32.handle, SW_SHOW);
BringWindowToTop(window->win32.handle);
SetForegroundWindow(window->win32.handle);
SetFocus(window->win32.handle);
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
ShowWindow(window->win32.handle, SW_SHOW);
}
@@ -1051,6 +1043,13 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
ShowWindow(window->win32.handle, SW_HIDE);
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
BringWindowToTop(window->win32.handle);
SetForegroundWindow(window->win32.handle);
SetFocus(window->win32.handle);
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
return window->win32.handle == GetActiveWindow();
+12 -3
View File
@@ -231,10 +231,9 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
{
if (wndconfig.visible)
{
_glfwPlatformShowWindow(window);
if (wndconfig.focused)
_glfwPlatformShowWindow(window);
else
_glfwPlatformUnhideWindow(window);
_glfwPlatformFocusWindow(window);
}
}
@@ -629,6 +628,16 @@ GLFWAPI void glfwHideWindow(GLFWwindow* handle)
_glfwPlatformHideWindow(window);
}
GLFWAPI void glfwFocusWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window);
_GLFW_REQUIRE_INIT();
_glfwPlatformFocusWindow(window);
}
GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
+6 -6
View File
@@ -470,18 +470,18 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
wl_shell_surface_set_toplevel(window->wl.shell_surface);
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
// TODO
fprintf(stderr, "_glfwPlatformUnhideWindow not implemented yet\n");
}
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
wl_surface_attach(window->wl.surface, NULL, 0, 0);
wl_surface_commit(window->wl.surface);
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
// TODO
fprintf(stderr, "_glfwPlatformFocusWindow not implemented yet\n");
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
// TODO
+20 -19
View File
@@ -763,19 +763,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
0);
}
if (_glfw.x11.NET_ACTIVE_WINDOW)
{
// Ask the window manager to raise and focus the GLFW window
// Only focused windows with the _NET_WM_STATE_FULLSCREEN state end up
// on top of all other windows ("Stacking order" in EWMH spec)
sendEventToWM(window, _glfw.x11.NET_ACTIVE_WINDOW, 1, 0, 0, 0, 0);
}
else
{
XRaiseWindow(_glfw.x11.display, window->x11.handle);
XSetInputFocus(_glfw.x11.display, window->x11.handle,
RevertToParent, CurrentTime);
}
_glfwPlatformFocusWindow(window);
if (_glfw.x11.NET_WM_STATE && _glfw.x11.NET_WM_STATE_FULLSCREEN)
{
@@ -1810,12 +1798,6 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
XMapRaised(_glfw.x11.display, window->x11.handle);
XFlush(_glfw.x11.display);
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
XMapWindow(_glfw.x11.display, window->x11.handle);
XFlush(_glfw.x11.display);
@@ -1827,6 +1809,25 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
if (_glfw.x11.NET_ACTIVE_WINDOW)
{
// Ask the window manager to raise and focus the GLFW window
// Only focused windows with the _NET_WM_STATE_FULLSCREEN state end up
// on top of all other windows ("Stacking order" in EWMH spec)
sendEventToWM(window, _glfw.x11.NET_ACTIVE_WINDOW, 1, 0, 0, 0, 0);
}
else
{
XRaiseWindow(_glfw.x11.display, window->x11.handle);
XSetInputFocus(_glfw.x11.display, window->x11.handle,
RevertToParent, CurrentTime);
}
XFlush(_glfw.x11.display);
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
Window focused;