Skip to content

Instantly share code, notes, and snippets.

@Bakterija
Created June 21, 2017 18:34
Show Gist options
  • Save Bakterija/651d8f023a899e1583bc756e7d24595a to your computer and use it in GitHub Desktop.
Save Bakterija/651d8f023a899e1583bc756e7d24595a to your computer and use it in GitHub Desktop.
class FullscreenToggleApp(App):
fullscreen = BooleanProperty(False)
maximized = BooleanProperty(False)
last_size = ListProperty([0, 0])
last_pos = ListProperty([0, 0])
_window_update_lock = False
def build(self):
self.root_widget = RootWidget(self)
if platform in ('linux', 'win'):
Clock.schedule_interval(self._update_window_pos, 0.2)
self.root_widget.bind(size=self._update_window_size)
return self.root_widget
def _update_window_size(self, _, value):
if not self._window_update_lock:
self.last_size = value
def _update_window_pos(self, *args):
if not self._window_update_lock:
self.last_pos = [Window.left, Window.top]
def set_window_pos(self, x, y):
Window.left = x
Window.top = y
Window.show()
Window.restore()
def set_window_size(self, size):
Window.size = size
Window.hide()
def toggle_fullscreen(self, *args):
if self.fullscreen:
Window.fullscreen = False
self.fullscreen = False
new_pos = (self.last_pos)
new_size = (self.last_size)
Clock.schedule_once(
lambda dt: self.set_window_pos(*new_pos), 0.2)
Clock.schedule_once(
lambda dt: self.set_window_size(new_size), 0)
self._window_update_lock = False
else:
self._window_update_lock = True
Window.maximize()
Clock.schedule_once(
lambda dt: setattr(Window, 'fullscreen', True), 0.2)
self.fullscreen = True
lock_keyboard_input_somehow_temporarily()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment