mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Add GLFW_FOCUS_ON_SHOW window hint and attribute for issue #1189
This commit is contained in:
parent
7ef34eb06d
commit
9d1224a932
@ -819,6 +819,12 @@ extern "C" {
|
|||||||
* Mouse cursor hover [window attribute](@ref GLFW_HOVERED_attrib).
|
* Mouse cursor hover [window attribute](@ref GLFW_HOVERED_attrib).
|
||||||
*/
|
*/
|
||||||
#define GLFW_HOVERED 0x0002000B
|
#define GLFW_HOVERED 0x0002000B
|
||||||
|
/*! @brief Input focus on calling show window hint and attribute
|
||||||
|
*
|
||||||
|
* Input focus [window hint](@ref GLFW_FOCUS_ON_SHOW_hint) or
|
||||||
|
* [window attribute](@ref GLFW_FOCUS_ON_SHOW_attrib).
|
||||||
|
*/
|
||||||
|
#define GLFW_FOCUS_ON_SHOW 0x0002000C
|
||||||
|
|
||||||
/*! @brief Framebuffer bit depth hint.
|
/*! @brief Framebuffer bit depth hint.
|
||||||
*
|
*
|
||||||
@ -3085,6 +3091,10 @@ GLFWAPI void glfwMaximizeWindow(GLFWwindow* window);
|
|||||||
* hidden. If the window is already visible or is in full screen mode, this
|
* hidden. If the window is already visible or is in full screen mode, this
|
||||||
* function does nothing.
|
* function does nothing.
|
||||||
*
|
*
|
||||||
|
* By default, windowed mode windows are focused when shown
|
||||||
|
* Set the [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) to
|
||||||
|
* disable this behavior.
|
||||||
|
*
|
||||||
* @param[in] window The window to make visible.
|
* @param[in] window The window to make visible.
|
||||||
*
|
*
|
||||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
|
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
|
||||||
@ -3132,6 +3142,10 @@ GLFWAPI void glfwHideWindow(GLFWwindow* window);
|
|||||||
* initially created. Set the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) to
|
* initially created. Set the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) to
|
||||||
* disable this behavior.
|
* disable this behavior.
|
||||||
*
|
*
|
||||||
|
* Also by default, windowed mode windows are focused when shown
|
||||||
|
* with @ref glfwShowWindow. Set the
|
||||||
|
* [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) to disable this behavior.
|
||||||
|
*
|
||||||
* __Do not use this function__ to steal focus from other applications unless
|
* __Do not use this function__ to steal focus from other applications unless
|
||||||
* you are certain that is what the user wants. Focus stealing can be
|
* you are certain that is what the user wants. Focus stealing can be
|
||||||
* extremely disruptive.
|
* extremely disruptive.
|
||||||
|
@ -267,6 +267,7 @@ struct _GLFWwndconfig
|
|||||||
GLFWbool floating;
|
GLFWbool floating;
|
||||||
GLFWbool maximized;
|
GLFWbool maximized;
|
||||||
GLFWbool centerCursor;
|
GLFWbool centerCursor;
|
||||||
|
GLFWbool focusOnShow;
|
||||||
struct {
|
struct {
|
||||||
GLFWbool retina;
|
GLFWbool retina;
|
||||||
char frameName[256];
|
char frameName[256];
|
||||||
@ -372,6 +373,7 @@ struct _GLFWwindow
|
|||||||
GLFWbool decorated;
|
GLFWbool decorated;
|
||||||
GLFWbool autoIconify;
|
GLFWbool autoIconify;
|
||||||
GLFWbool floating;
|
GLFWbool floating;
|
||||||
|
GLFWbool focusOnShow;
|
||||||
GLFWbool shouldClose;
|
GLFWbool shouldClose;
|
||||||
void* userPointer;
|
void* userPointer;
|
||||||
GLFWvidmode videoMode;
|
GLFWvidmode videoMode;
|
||||||
|
11
src/window.c
11
src/window.c
@ -201,6 +201,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||||||
window->decorated = wndconfig.decorated;
|
window->decorated = wndconfig.decorated;
|
||||||
window->autoIconify = wndconfig.autoIconify;
|
window->autoIconify = wndconfig.autoIconify;
|
||||||
window->floating = wndconfig.floating;
|
window->floating = wndconfig.floating;
|
||||||
|
window->focusOnShow = wndconfig.focusOnShow;
|
||||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||||
|
|
||||||
window->minwidth = GLFW_DONT_CARE;
|
window->minwidth = GLFW_DONT_CARE;
|
||||||
@ -267,6 +268,7 @@ void glfwDefaultWindowHints(void)
|
|||||||
_glfw.hints.window.focused = GLFW_TRUE;
|
_glfw.hints.window.focused = GLFW_TRUE;
|
||||||
_glfw.hints.window.autoIconify = GLFW_TRUE;
|
_glfw.hints.window.autoIconify = GLFW_TRUE;
|
||||||
_glfw.hints.window.centerCursor = GLFW_TRUE;
|
_glfw.hints.window.centerCursor = GLFW_TRUE;
|
||||||
|
_glfw.hints.window.focusOnShow = GLFW_TRUE;
|
||||||
|
|
||||||
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
|
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
|
||||||
// double buffered
|
// double buffered
|
||||||
@ -370,6 +372,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
|
|||||||
case GLFW_CENTER_CURSOR:
|
case GLFW_CENTER_CURSOR:
|
||||||
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
|
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
|
||||||
return;
|
return;
|
||||||
|
case GLFW_FOCUS_ON_SHOW:
|
||||||
|
_glfw.hints.window.focusOnShow = value ? GLFW_TRUE : GLFW_FALSE;
|
||||||
|
return;
|
||||||
case GLFW_CLIENT_API:
|
case GLFW_CLIENT_API:
|
||||||
_glfw.hints.context.client = value;
|
_glfw.hints.context.client = value;
|
||||||
return;
|
return;
|
||||||
@ -755,7 +760,9 @@ GLFWAPI void glfwShowWindow(GLFWwindow* handle)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_glfwPlatformShowWindow(window);
|
_glfwPlatformShowWindow(window);
|
||||||
_glfwPlatformFocusWindow(window);
|
|
||||||
|
if(window->focusOnShow)
|
||||||
|
_glfwPlatformFocusWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
|
GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
|
||||||
@ -810,6 +817,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
|
|||||||
return _glfwPlatformWindowMaximized(window);
|
return _glfwPlatformWindowMaximized(window);
|
||||||
case GLFW_HOVERED:
|
case GLFW_HOVERED:
|
||||||
return _glfwPlatformWindowHovered(window);
|
return _glfwPlatformWindowHovered(window);
|
||||||
|
case GLFW_FOCUS_ON_SHOW:
|
||||||
|
return window->focusOnShow;
|
||||||
case GLFW_TRANSPARENT_FRAMEBUFFER:
|
case GLFW_TRANSPARENT_FRAMEBUFFER:
|
||||||
return _glfwPlatformFramebufferTransparent(window);
|
return _glfwPlatformFramebufferTransparent(window);
|
||||||
case GLFW_RESIZABLE:
|
case GLFW_RESIZABLE:
|
||||||
|
@ -56,9 +56,10 @@ static const struct
|
|||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("Usage: windows [-h] [-b]\n");
|
printf("Usage: windows [-h] [-b] [-f] \n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -b create decorated windows\n");
|
printf(" -b create decorated windows\n");
|
||||||
|
printf(" -f set focus on show off for all but first window\n");
|
||||||
printf(" -h show this help\n");
|
printf(" -h show this help\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,16 +93,20 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
int i, ch;
|
int i, ch;
|
||||||
int decorated = GLFW_FALSE;
|
int decorated = GLFW_FALSE;
|
||||||
|
int focusOnShow = GLFW_TRUE;
|
||||||
int running = GLFW_TRUE;
|
int running = GLFW_TRUE;
|
||||||
GLFWwindow* windows[4];
|
GLFWwindow* windows[4];
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "bh")) != -1)
|
while ((ch = getopt(argc, argv, "bfh")) != -1)
|
||||||
{
|
{
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'b':
|
||||||
decorated = GLFW_TRUE;
|
decorated = GLFW_TRUE;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
focusOnShow = GLFW_FALSE;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -122,6 +127,8 @@ int main(int argc, char** argv)
|
|||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
int left, top, right, bottom;
|
int left, top, right, bottom;
|
||||||
|
if(i)
|
||||||
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, focusOnShow);
|
||||||
|
|
||||||
windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL);
|
windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL);
|
||||||
if (!windows[i])
|
if (!windows[i])
|
||||||
|
Loading…
Reference in New Issue
Block a user