Win32: Add GLFW_WIN32_SHOWDEFAULT

Fixes #2359
This commit is contained in:
Camilla Löwy 2024-02-01 02:10:34 +01:00
parent 2afd57bf9b
commit 8946f5314d
8 changed files with 45 additions and 1 deletions

View File

@ -155,6 +155,8 @@ information on what to include when reporting a bug.
- Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan - Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan
surface extension (#1793) surface extension (#1793)
- Added `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu - Added `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu
- Added `GLFW_WIN32_SHOWDEFAULT` window hint for applying the parent process
show command (#2359)
- Added `GLFW_NATIVE_INCLUDE_NONE` for disabling inclusion of native headers (#1348) - Added `GLFW_NATIVE_INCLUDE_NONE` for disabling inclusion of native headers (#1348)
- Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958) - Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
- Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958) - Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)

View File

@ -103,6 +103,13 @@ Alt-and-then-Space shortcuts. This may be useful for more GUI-oriented
applications. applications.
@subsubsection features_34_win32_showdefault Support for applying STARTUPINFO show command
GLFW now provides the [GLFW_WIN32_SHOWDEFAULT](@ref GLFW_WIN32_SHOWDEFAULT_hint) window
hint for applying the show command in the program's `STARTUPINFO` when showing the window
for the first time. This may be useful for the main window of a windowed-mode tool.
@subsection caveats Caveats for version 3.4 @subsection caveats Caveats for version 3.4
@subsubsection native_34 Multiple sets of native access functions @subsubsection native_34 Multiple sets of native access functions
@ -261,6 +268,7 @@ then GLFW will fail to initialize.
- @ref GLFW_NOT_ALLOWED_CURSOR - @ref GLFW_NOT_ALLOWED_CURSOR
- @ref GLFW_CURSOR_UNAVAILABLE - @ref GLFW_CURSOR_UNAVAILABLE
- @ref GLFW_WIN32_KEYBOARD_MENU - @ref GLFW_WIN32_KEYBOARD_MENU
- @ref GLFW_WIN32_SHOWDEFAULT
- @ref GLFW_CONTEXT_DEBUG - @ref GLFW_CONTEXT_DEBUG
- @ref GLFW_FEATURE_UNAVAILABLE - @ref GLFW_FEATURE_UNAVAILABLE
- @ref GLFW_FEATURE_UNIMPLEMENTED - @ref GLFW_FEATURE_UNIMPLEMENTED

View File

@ -462,6 +462,14 @@ __GLFW_WIN32_KEYBOARD_MENU__ specifies whether to allow access to the window
menu via the Alt+Space and Alt-and-then-Space keyboard shortcuts. This is menu via the Alt+Space and Alt-and-then-Space keyboard shortcuts. This is
ignored on other platforms. ignored on other platforms.
@anchor GLFW_WIN32_SHOWDEFAULT_hint
__GLFW_WIN32_SHOWDEFAULT__ specifies whether to show the window the way
specified in the program's `STARTUPINFO` when it is shown for the first time.
This is the same information as the `Run` option in the shortcut properties
window. If this information was not specified when the program was started,
GLFW behaves as if this hint was set to `GLFW_FALSE`. Possible values are
`GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms.
@subsubsection window_hints_osx macOS specific hints @subsubsection window_hints_osx macOS specific hints
@ -553,6 +561,7 @@ GLFW_OPENGL_FORWARD_COMPAT | `GLFW_FALSE` | `GLFW_TRUE` or `GL
GLFW_CONTEXT_DEBUG | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_CONTEXT_DEBUG | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_OPENGL_PROFILE | `GLFW_OPENGL_ANY_PROFILE` | `GLFW_OPENGL_ANY_PROFILE`, `GLFW_OPENGL_COMPAT_PROFILE` or `GLFW_OPENGL_CORE_PROFILE` GLFW_OPENGL_PROFILE | `GLFW_OPENGL_ANY_PROFILE` | `GLFW_OPENGL_ANY_PROFILE`, `GLFW_OPENGL_COMPAT_PROFILE` or `GLFW_OPENGL_CORE_PROFILE`
GLFW_WIN32_KEYBOARD_MENU | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_WIN32_KEYBOARD_MENU | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_WIN32_SHOWDEFAULT | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_COCOA_RETINA_FRAMEBUFFER | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_COCOA_RETINA_FRAMEBUFFER | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded frame autosave name GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded frame autosave name
GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`

View File

@ -1119,6 +1119,9 @@ extern "C" {
*/ */
#define GLFW_X11_INSTANCE_NAME 0x00024002 #define GLFW_X11_INSTANCE_NAME 0x00024002
#define GLFW_WIN32_KEYBOARD_MENU 0x00025001 #define GLFW_WIN32_KEYBOARD_MENU 0x00025001
/*! @brief Win32 specific [window hint](@ref GLFW_WIN32_SHOWDEFAULT_hint).
*/
#define GLFW_WIN32_SHOWDEFAULT 0x00025002
/*! @brief Wayland specific /*! @brief Wayland specific
* [window hint](@ref GLFW_WAYLAND_APP_ID_hint). * [window hint](@ref GLFW_WAYLAND_APP_ID_hint).
* *

View File

@ -412,6 +412,7 @@ struct _GLFWwndconfig
} x11; } x11;
struct { struct {
GLFWbool keymenu; GLFWbool keymenu;
GLFWbool showDefault;
} win32; } win32;
struct { struct {
char appId[256]; char appId[256];

View File

@ -424,6 +424,7 @@ typedef struct _GLFWwindowWin32
GLFWbool transparent; GLFWbool transparent;
GLFWbool scaleToMonitor; GLFWbool scaleToMonitor;
GLFWbool keymenu; GLFWbool keymenu;
GLFWbool showDefault;
// Cached size used to filter out duplicate events // Cached size used to filter out duplicate events
int width, height; int width, height;

View File

@ -1390,6 +1390,7 @@ static int createNativeWindow(_GLFWwindow* window,
window->win32.scaleToMonitor = wndconfig->scaleToMonitor; window->win32.scaleToMonitor = wndconfig->scaleToMonitor;
window->win32.keymenu = wndconfig->win32.keymenu; window->win32.keymenu = wndconfig->win32.keymenu;
window->win32.showDefault = wndconfig->win32.showDefault;
if (!window->monitor) if (!window->monitor)
{ {
@ -1772,7 +1773,23 @@ void _glfwMaximizeWindowWin32(_GLFWwindow* window)
void _glfwShowWindowWin32(_GLFWwindow* window) void _glfwShowWindowWin32(_GLFWwindow* window)
{ {
ShowWindow(window->win32.handle, SW_SHOWNA); int showCommand = SW_SHOWNA;
if (window->win32.showDefault)
{
// NOTE: GLFW windows currently do not seem to match the Windows 10 definition of
// a main window, so even SW_SHOWDEFAULT does nothing
// This definition is undocumented and can change (source: Raymond Chen)
// HACK: Apply the STARTUPINFO show command manually if available
STARTUPINFOW si = { sizeof(si) };
GetStartupInfoW(&si);
if (si.dwFlags & STARTF_USESHOWWINDOW)
showCommand = si.wShowWindow;
window->win32.showDefault = GLFW_FALSE;
}
ShowWindow(window->win32.handle, showCommand);
} }
void _glfwHideWindowWin32(_GLFWwindow* window) void _glfwHideWindowWin32(_GLFWwindow* window)

View File

@ -380,6 +380,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_WIN32_KEYBOARD_MENU: case GLFW_WIN32_KEYBOARD_MENU:
_glfw.hints.window.win32.keymenu = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.window.win32.keymenu = value ? GLFW_TRUE : GLFW_FALSE;
return; return;
case GLFW_WIN32_SHOWDEFAULT:
_glfw.hints.window.win32.showDefault = value ? GLFW_TRUE : GLFW_FALSE;
return;
case GLFW_COCOA_GRAPHICS_SWITCHING: case GLFW_COCOA_GRAPHICS_SWITCHING:
_glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE;
return; return;