From 11f5eb5a7910a41b151f3a535f64b1629b0b305d Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Mon, 6 Jan 2025 21:00:36 -0500 Subject: [PATCH] added screen resolution detection --- steam_saver/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/steam_saver/main.py b/steam_saver/main.py index 75e94d8..f5c885d 100644 --- a/steam_saver/main.py +++ b/steam_saver/main.py @@ -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()