Repository: kivy/kivy

Issue:
SDL2 - add new config options to the graphics section: maximized, minimized, hidden
There is no easy way to maximize a window from kivy.
It could be:

<pre><code>
# maximize: (0, 1)
# Default is 0.

from kivy.config import Config
Config.set('graphics', 'maximize', 1)
</pre></code>

UPDATE:
These options were already added as methods for the sdl2 window provider.
Pygame mostly lacks these flags, i think it should be best if we'd add this when sdl2 will be the default on desktop.



Discussion:
Here is a workaround on Windows:

```
from kivy.utils import platform

if platform == 'win':
    import ctypes
    import pygame

    ShowWindow = ctypes.windll.user32.ShowWindow
    SystemParametersInfo = ctypes.windll.user32.SystemParametersInfoA

    SW_MAXIMIZE = 3
    SPI_GETWORKAREA = 48

    class WorkArea(ctypes.Structure):
        _fields_ = [('left', ctypes.c_int), ('top', ctypes.c_int),
            ('right', ctypes.c_int), ('bottom', ctypes.c_int)]

    def maximize_window():
        hn_window = pygame.display.get_wm_info()['window']
        ShowWindow(hn_window, SW_MAXIMIZE)

    r = WorkArea()
    SystemParametersInfo(SPI_GETWORKAREA, 0, ctypes.byref(r), 0)

    app_pos_size = [r.left + 10, r.top + 32, r.right - r.left - 20,
        r.bottom - r.top - 42]
    app_pos_type = 'custom'
else:
    app_pos_size = [0, 0, 800, 600]
    app_pos_type = 'auto'

from kivy.config import Config
Config.set('graphics', 'position', app_pos_type)
Config.set('graphics', 'left', app_pos_size[0])
Config.set('graphics', 'top', app_pos_size[1])
Config.set('graphics', 'width', app_pos_size[2])
Config.set('graphics', 'height', app_pos_size[3])

from kivy.app import App
from kivy.uix.button import Button


class TestApp(App):

    def on_start(self):
        if platform == 'win':
            maximize_window()

    def build(self):
        return Button()

if __name__ == '__main__':
    TestApp().run()
```


Resolving patch:
diff --git a/kivy/config.py b/kivy/config.py
--- a/kivy/config.py
+++ b/kivy/config.py
@@ -114,6 +114,11 @@
 :graphics:
     `borderless`: int , one of 0 or 1
         If set to `1`, removes the window border/decoration.
+    `window_state`: string , one of `visible`, `hidden`, `maximized`
+        or `minimized`
+        Sets the window state, defaults to `visible`. This option is available
+        only for the SDL2 window provider and it should be used on desktop
+        OSes.
     `fbo`: string, one of 'hardware', 'software' or 'force-hardware'
         Selects the FBO backend to use.
     `fullscreen`: int or string, one of 0, 1, 'fake' or 'auto'
@@ -230,9 +235,9 @@
     is required for value changes to take effect.
 
 .. versionchanged:: 1.9.0
-    `borderless` has been added to the graphics section.
-    The `fake` option of `fullscreen` in the graphics section has been
-    deprecated, use the `borderless` option instead.
+    `borderless` and `window_state` have been added to the graphics section.
+    The `fake` setting of the `fullscreen` option has been deprecated,
+    use the `borderless` option instead.
     `pause_on_minimize` has been added to the kivy section.
 
 .. versionchanged:: 1.8.0
@@ -274,7 +279,7 @@
 _is_rpi = exists('/opt/vc/include/bcm_host.h')
 
 # Version number of current configuration format
-KIVY_CONFIG_VERSION = 12
+KIVY_CONFIG_VERSION = 13
 
 Config = None
 '''Kivy configuration object. Its :attr:`~kivy.config.ConfigParser.name` is
@@ -744,6 +749,9 @@ def name(self, value):
         elif version == 11:
             Config.setdefault('kivy', 'pause_on_minimize', '0')
 
+        elif version == 12:
+            Config.set('graphics', 'window_state', 'visible')
+
         #elif version == 1:
         #   # add here the command for upgrading from configuration 0 to 1
         #
diff --git a/kivy/core/window/window_sdl2.py b/kivy/core/window/window_sdl2.py
--- a/kivy/core/window/window_sdl2.py
+++ b/kivy/core/window/window_sdl2.py
@@ -164,9 +164,11 @@ def create_window(self, *largs):
             # setup !
             w, h = self.system_size
             resizable = Config.getboolean('graphics', 'resizable')
+            state = (Config.get('graphics', 'window_state')
+                     if self._is_desktop else None)
             self.system_size = _size = self._win.setup_window(
                 pos[0], pos[1], w, h, self.borderless,
-                self.fullscreen, resizable)
+                self.fullscreen, resizable, state)
             sz = self.size[0]
             self._density = density = sz / _size[0]
             if self._is_desktop and self.size[0] != _size[0]:


Test patch: