Skip to content

Commit

Permalink
Merge pull request kivy#4921 from inclement/sdl2_screensaver
Browse files Browse the repository at this point in the history
Added an allow_screensaver property for Window
  • Loading branch information
dessant authored Feb 2, 2017
2 parents 309ac12 + 49ccdba commit c3dcb13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
15 changes: 11 additions & 4 deletions kivy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
'data/fonts/Roboto-Bold.ttf', 'data/fonts/Roboto-BoldItalic.ttf']
Default font used for widgets displaying any text.
`allow_screensaver`: int, one of 0 or 1, defaults to 1
Allow the device to show a screen saver, or to go to sleep
on mobile devices. Only works for the sdl2 window provider.
:input:
Expand Down Expand Up @@ -269,9 +272,10 @@
arguments.
.. versionchanged:: 1.9.2
`min_state_time` has been added to the `graphics` section.
`kivy_clock` has been added to the kivy section
`default_font` has beed added to the kivy section
`min_state_time` and `allow_screensaver` have been added
to the `graphics` section.
`kivy_clock` has been added to the kivy section.
`default_font` has beed added to the kivy section.
.. versionchanged:: 1.9.0
`borderless` and `window_state` have been added to the graphics section.
Expand Down Expand Up @@ -318,7 +322,7 @@
_is_rpi = exists('/opt/vc/include/bcm_host.h')

# Version number of current configuration format
KIVY_CONFIG_VERSION = 17
KIVY_CONFIG_VERSION = 18

Config = None
'''The default Kivy configuration object. This is a :class:`ConfigParser`
Expand Down Expand Up @@ -819,6 +823,9 @@ def name(self, value):
'data/fonts/Roboto-Bold.ttf',
'data/fonts/Roboto-BoldItalic.ttf'])

elif version == 17:
Config.setdefault('graphics', 'allow_screensaver', '1')

# elif version == 1:
# # add here the command for upgrading from configuration 0 to 1

Expand Down
17 changes: 17 additions & 0 deletions kivy/core/window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class WindowBase(EventDispatcher):
Minimum width of the window (only works for sdl2 window provider).
`minimum_height`: int
Minimum height of the window (only works for sdl2 window provider).
`allow_screensaver`: bool
Allow the device to show a screen saver, or to go to sleep
on mobile devices. Defaults to True. Only works for sdl2 window
provider.
:Events:
`on_motion`: etype, motionevent
Expand Down Expand Up @@ -392,6 +396,16 @@ def _set_size(self, size):
defaults to 0.
'''

allow_screensaver = BooleanProperty(True)
'''Whether the screen saver is enabled, or on mobile devices whether the
device is allowed to go to sleep while the app is open.
.. versionadded:: 1.10.0
:attr:`allow_screensaver` is a :class:`~kivy.properties.BooleanProperty`
and defaults to True.
'''

size = AliasProperty(_get_size, _set_size, bind=('_size', ))
'''Get the rotated size of the window. If :attr:`rotation` is set, then the
size will change to reflect the rotation.
Expand Down Expand Up @@ -798,6 +812,9 @@ def __init__(self, **kwargs):
if 'minimum_height' not in kwargs:
kwargs['minimum_height'] = Config.getint('graphics',
'minimum_height')
if 'allow_screensaver' not in kwargs:
kwargs['allow_screensaver'] = Config.getboolean(
'graphics', 'allow_screensaver')
if 'rotation' not in kwargs:
kwargs['rotation'] = Config.getint('graphics', 'rotation')
if 'position' not in kwargs:
Expand Down
6 changes: 6 additions & 0 deletions kivy/core/window/_window_sdl2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ cdef class _WindowSDL2Storage:
def set_minimum_size(self, w, h):
SDL_SetWindowMinimumSize(self.win, w, h)

def set_allow_screensaver(self, allow_screensaver):
if allow_screensaver:
SDL_EnableScreenSaver()
else:
SDL_DisableScreenSaver()

def maximize_window(self):
SDL_MaximizeWindow(self.win)

Expand Down
6 changes: 6 additions & 0 deletions kivy/core/window/window_sdl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def __init__(self, **kwargs):
self.bind(minimum_width=self._set_minimum_size,
minimum_height=self._set_minimum_size)

self.bind(allow_screensaver=self._set_allow_screensaver)

def _set_minimum_size(self, *args):
minimum_width = self.minimum_width
minimum_height = self.minimum_height
Expand All @@ -195,6 +197,9 @@ def _set_minimum_size(self, *args):
'Both Window.minimum_width and Window.minimum_height must be '
'bigger than 0 for the size restriction to take effect.')

def _set_allow_screensaver(self, *args):
self._win.set_allow_screensaver(self.allow_screensaver)

def _event_filter(self, action):
from kivy.app import App
if action == 'app_terminating':
Expand Down Expand Up @@ -272,6 +277,7 @@ def create_window(self, *largs):
# will be fired.
self._pos = (0, 0)
self._set_minimum_size()
self._set_allow_screensaver()

if state == 'hidden':
self._focus = False
Expand Down

0 comments on commit c3dcb13

Please sign in to comment.