1
0
forked from ndyer/pygame-dvd

added screen resolution detection

This commit is contained in:
Nicholas Dyer 2025-01-06 21:00:36 -05:00
parent 399092238e
commit 11f5eb5a79
Signed by: ndyer
GPG Key ID: B4FEDEE7298D2503

View File

@ -1,13 +1,18 @@
import pygame
import subprocess
import steam_saver.surfaces as surfaces
# Global variables
SCREEN_SIZE = (1920, 1080)
FPS = 60
VALID_SURFACES = [
'steam_screen'
]
def get_screen_resolution():
command_output = subprocess.check_output(['xrandr']).decode('utf-8')
for line in command_output.split('\n'):
if '*' in line:
return tuple(map(int, line.split()[0].split('x')))
def main(windowed_mode=False):
"""
@ -16,13 +21,16 @@ def main(windowed_mode=False):
"""
pygame.init()
clock = pygame.time.Clock()
screen_size = get_screen_resolution()
if windowed_mode:
window = pygame.display.set_mode(SCREEN_SIZE)
window = pygame.display.set_mode(screen_size)
else:
window = pygame.display.set_mode(SCREEN_SIZE, pygame.FULLSCREEN)
window = pygame.display.set_mode(screen_size, pygame.FULLSCREEN)
# Starts the program with the surface 'steam_screen' as the default
surface = getattr(globals()['surfaces'], 'steam_screen').Surface(SCREEN_SIZE)
surface = getattr(globals()['surfaces'], 'steam_screen').Surface(screen_size)
running = True
while running:
clock.tick(FPS)
@ -37,7 +45,7 @@ def main(windowed_mode=False):
next_surface = surface.next_surface
if next_surface not in VALID_SURFACES:
raise Exception('Given surface is not a valid surface!')
surface = getattr(globals()['surfaces'], next_surface).Surface(SCREEN_SIZE)
surface = getattr(globals()['surfaces'], next_surface).Surface(screen_size)
pygame.display.flip()
pygame.quit()