Sfoglia il codice sorgente

windisplay: allow changing undecorated/fixed_size after window open

Fixes #405
rdb 7 anni fa
parent
commit
7bd8cbdeb6

+ 31 - 7
panda/src/windisplay/winGraphicsWindow.cxx

@@ -283,6 +283,25 @@ set_properties_now(WindowProperties &properties) {
     return;
     return;
   }
   }
 
 
+  if (properties.has_undecorated() ||
+      properties.has_fixed_size()) {
+    if (properties.has_undecorated()) {
+      _properties.set_undecorated(properties.get_undecorated());
+      properties.clear_undecorated();
+    }
+    if (properties.has_fixed_size()) {
+      _properties.set_fixed_size(properties.get_fixed_size());
+      properties.clear_fixed_size();
+    }
+    DWORD window_style = make_style(_properties);
+    SetWindowLong(_hWnd, GWL_STYLE, window_style);
+
+    // We need to call this to ensure that the style change takes effect.
+    SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
+      SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE |
+      SWP_FRAMECHANGED | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
+  }
+
   if (properties.has_title()) {
   if (properties.has_title()) {
     std::string title = properties.get_title();
     std::string title = properties.get_title();
     _properties.set_title(title);
     _properties.set_title(title);
@@ -487,7 +506,7 @@ open_window() {
   // CreateWindow() and know which window it is sending events to even before
   // CreateWindow() and know which window it is sending events to even before
   // it gives us a handle.  Warning: this is not thread safe!
   // it gives us a handle.  Warning: this is not thread safe!
   _creating_window = this;
   _creating_window = this;
-  bool opened = open_graphic_window(is_fullscreen());
+  bool opened = open_graphic_window();
   _creating_window = nullptr;
   _creating_window = nullptr;
 
 
   if (!opened) {
   if (!opened) {
@@ -865,7 +884,9 @@ do_fullscreen_switch() {
     return false;
     return false;
   }
   }
 
 
-  DWORD window_style = make_style(true);
+  WindowProperties props(_properties);
+  props.set_fullscreen(true);
+  DWORD window_style = make_style(props);
   SetWindowLong(_hWnd, GWL_STYLE, window_style);
   SetWindowLong(_hWnd, GWL_STYLE, window_style);
 
 
   WINDOW_METRICS metrics;
   WINDOW_METRICS metrics;
@@ -885,7 +906,10 @@ do_fullscreen_switch() {
 bool WinGraphicsWindow::
 bool WinGraphicsWindow::
 do_windowed_switch() {
 do_windowed_switch() {
   do_fullscreen_disable();
   do_fullscreen_disable();
-  DWORD window_style = make_style(false);
+
+  WindowProperties props(_properties);
+  props.set_fullscreen(false);
+  DWORD window_style = make_style(props);
   SetWindowLong(_hWnd, GWL_STYLE, window_style);
   SetWindowLong(_hWnd, GWL_STYLE, window_style);
 
 
   WINDOW_METRICS metrics;
   WINDOW_METRICS metrics;
@@ -928,7 +952,7 @@ support_overlay_window(bool) {
  * Constructs a dwStyle for the specified mode, be it windowed or fullscreen.
  * Constructs a dwStyle for the specified mode, be it windowed or fullscreen.
  */
  */
 DWORD WinGraphicsWindow::
 DWORD WinGraphicsWindow::
-make_style(bool fullscreen) {
+make_style(const WindowProperties &properties) {
   // from MSDN: An OpenGL window has its own pixel format.  Because of this,
   // from MSDN: An OpenGL window has its own pixel format.  Because of this,
   // only device contexts retrieved for the client area of an OpenGL window
   // only device contexts retrieved for the client area of an OpenGL window
   // are allowed to draw into the window.  As a result, an OpenGL window
   // are allowed to draw into the window.  As a result, an OpenGL window
@@ -938,7 +962,7 @@ make_style(bool fullscreen) {
 
 
   DWORD window_style = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
   DWORD window_style = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
 
 
-  if (fullscreen){
+  if (_properties.get_fullscreen()) {
     window_style |= WS_SYSMENU;
     window_style |= WS_SYSMENU;
   } else if (!_properties.get_undecorated()) {
   } else if (!_properties.get_undecorated()) {
     window_style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
     window_style |= (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
@@ -1015,8 +1039,8 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
  * Creates a regular or fullscreen window.
  * Creates a regular or fullscreen window.
  */
  */
 bool WinGraphicsWindow::
 bool WinGraphicsWindow::
-open_graphic_window(bool fullscreen) {
-  DWORD window_style = make_style(fullscreen);
+open_graphic_window() {
+  DWORD window_style = make_style(_properties);
 
 
   wstring title;
   wstring title;
   if (_properties.has_title()) {
   if (_properties.has_title()) {

+ 2 - 2
panda/src/windisplay/winGraphicsWindow.h

@@ -119,7 +119,7 @@ protected:
   virtual bool calculate_metrics(bool fullscreen, DWORD style,
   virtual bool calculate_metrics(bool fullscreen, DWORD style,
                                  WINDOW_METRICS &metrics, bool &has_origin);
                                  WINDOW_METRICS &metrics, bool &has_origin);
 
 
-  virtual DWORD make_style(bool fullscreen);
+  DWORD make_style(const WindowProperties &properties);
 
 
   virtual void reconsider_fullscreen_size(DWORD &x_size, DWORD &y_size,
   virtual void reconsider_fullscreen_size(DWORD &x_size, DWORD &y_size,
                                           DWORD &bitdepth);
                                           DWORD &bitdepth);
@@ -127,7 +127,7 @@ protected:
   virtual void support_overlay_window(bool flag);
   virtual void support_overlay_window(bool flag);
 
 
 private:
 private:
-  bool open_graphic_window(bool fullscreen);
+  bool open_graphic_window();
   void adjust_z_order();
   void adjust_z_order();
   void adjust_z_order(WindowProperties::ZOrder last_z_order,
   void adjust_z_order(WindowProperties::ZOrder last_z_order,
                       WindowProperties::ZOrder this_z_order);
                       WindowProperties::ZOrder this_z_order);