Pārlūkot izejas kodu

Win32: Add GLFW_WIN32_SHOWDEFAULT

Fixes #2359
Camilla Löwy 1 gadu atpakaļ
vecāks
revīzija
8946f5314d
8 mainītis faili ar 45 papildinājumiem un 1 dzēšanām
  1. 2 0
      README.md
  2. 8 0
      docs/news.dox
  3. 9 0
      docs/window.dox
  4. 3 0
      include/GLFW/glfw3.h
  5. 1 0
      src/internal.h
  6. 1 0
      src/win32_platform.h
  7. 18 1
      src/win32_window.c
  8. 3 0
      src/window.c

+ 2 - 0
README.md

@@ -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
    surface extension (#1793)
  - 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_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
  - Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)

+ 8 - 0
docs/news.dox

@@ -103,6 +103,13 @@ Alt-and-then-Space shortcuts.  This may be useful for more GUI-oriented
 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
 
 @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_CURSOR_UNAVAILABLE
  - @ref GLFW_WIN32_KEYBOARD_MENU
+ - @ref GLFW_WIN32_SHOWDEFAULT
  - @ref GLFW_CONTEXT_DEBUG
  - @ref GLFW_FEATURE_UNAVAILABLE
  - @ref GLFW_FEATURE_UNIMPLEMENTED

+ 9 - 0
docs/window.dox

@@ -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
 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
 
@@ -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_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_SHOWDEFAULT        | `GLFW_FALSE`                | `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_GRAPHICS_SWITCHING | `GLFW_FALSE`                | `GLFW_TRUE` or `GLFW_FALSE`

+ 3 - 0
include/GLFW/glfw3.h

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

+ 1 - 0
src/internal.h

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

+ 1 - 0
src/win32_platform.h

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

+ 18 - 1
src/win32_window.c

@@ -1390,6 +1390,7 @@ static int createNativeWindow(_GLFWwindow* window,
 
     window->win32.scaleToMonitor = wndconfig->scaleToMonitor;
     window->win32.keymenu = wndconfig->win32.keymenu;
+    window->win32.showDefault = wndconfig->win32.showDefault;
 
     if (!window->monitor)
     {
@@ -1772,7 +1773,23 @@ void _glfwMaximizeWindowWin32(_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)

+ 3 - 0
src/window.c

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