Repository: psychopy/psychopy

Issue:
visual.Window.resetViewport() error
When I run

```
from psychopy import visual  
win = visual.Window()  
win.resetViewport()  
```
with psychopy 2022.1.4 and python 3.8.13 on a Win10 laptop with integrated graphics, I get an error
```
File:  "psychopy\visual\window.py", line 1710, in resetViewport
    self.scissor = self.viewport = self.frameBufferSize
TypeError: this function takes 4 arguments (2 given)
```

It seems that the line should be `self.scissor = self.viewport = [0,0] + self.frameBufferSize` to correctly reset the viewport.

Edit: I didn't see the frameBufferSize is a numpy array, so the fix should be `self.scissor = self.viewport = [0,0] + self.frameBufferSize.tolist()`


Discussion:

Resolving patch:
diff --git a/psychopy/visual/window.py b/psychopy/visual/window.py
--- a/psychopy/visual/window.py
+++ b/psychopy/visual/window.py
@@ -525,6 +525,9 @@ def __init__(self,
         self.cullFaceMode = 'back'
         self.draw3d = False
 
+        # gl viewport and scissor
+        self._viewport = self._scissor = None  # set later
+
         # scene light sources
         self._lights = []
         self._useLights = False
@@ -1707,7 +1710,9 @@ def resetViewport(self):
         match the dimensions of the viewport.
 
         """
-        self.scissor = self.viewport = self.frameBufferSize
+        # use the framebuffer size here, not the window size (hi-dpi compat)
+        bufferWidth, bufferHeight = self.frameBufferSize
+        self.scissor = self.viewport = [0, 0, bufferWidth, bufferHeight]
 
     @property
     def viewport(self):


Test patch:
diff --git a/psychopy/tests/test_visual/test_all_stimuli.py b/psychopy/tests/test_visual/test_all_stimuli.py
--- a/psychopy/tests/test_visual/test_all_stimuli.py
+++ b/psychopy/tests/test_visual/test_all_stimuli.py
@@ -55,6 +55,32 @@ def assertThisIs2(val):
         self.win.callOnFlip(assertThisIs2, 2)
         self.win.flip()
 
+    def test_resetViewport(self):
+        # Check if the `Window.resetViewport()` method works correctly. Not
+        # checking if the OpenGL state is correct here, just if the property
+        # setter `Window.viewport` updates accordingly.
+        #
+        # bugfix: https://github.com/psychopy/psychopy/issues/5135
+        #
+        viewportOld = self.win.viewport.copy()  # store old viewport value
+
+        # Create a new viewport, ensure that the test value never equals the
+        # windows size.
+        viewportNew = [0, 0] + [max(int(v / 2.0), 1) for v in viewportOld[2:]]
+        self.win.viewport = viewportNew
+
+        # assert that the change has been made correctly after setting
+        assert numpy.allclose(self.win.viewport, viewportNew), \
+            "Failed to change viewport, expected `{}` got `{}`.".format(
+                viewportNew, list(self.win.viewport))  # show as list
+
+        # reset the viewport and check if the value is reset to original
+        self.win.resetViewport()
+
+        assert numpy.allclose(self.win.viewport, viewportOld), \
+            "Failed to reset viewport, expected `{}` got `{}`.".format(
+                viewportOld, list(self.win.viewport))
+
 
 class _baseVisualTest():
     #this class allows others to be created that inherit all the tests for