from gui.v2.infrastructure.screen_size import get_max_screensize from gui.v2.actions.config import get_registrations from core.errors.logger import logger PRE_MADE_RESOLUTIONS = [ '800x600', '1024x760', '1152x1080', '1200x1000', '1280x1024', '1300x900', '1920x1080', '2560x1440', '2560x1600', '1920x1440', '1792x1344', '2048x1152' ] def are_dynamic_larger_profiles_enabled(): registration_settings = get_registrations() return registration_settings.get("dynamic_larger_profiles", False) def _get_dynamic_resolution_list(host_width: int, host_height: int) -> list: """Get a list of resolutions slightly smaller than the host, counting down by incriments of 50, after adjusting for heights too long""" adjusted_host_height = round(host_height * 0.8) dynamic_resolutions = [] for i in range(5): new_height = host_width - (50 * (i + 1)) new_width = adjusted_host_height - (50 * (i + 1)) resolution_as_string = f"{str(new_height)}x{str(new_width)}" dynamic_resolutions.append(resolution_as_string) return dynamic_resolutions def _get_filtered_premade_list(host_width: int, host_height: int) -> list: """Get a list of resolutions that fit with a small buffer""" premade_resolutions = [] adjusted_host_height = host_height - 50 adjusted_host_width = host_width - 50 for each_pre_made in PRE_MADE_RESOLUTIONS: premade_width, premade_height = each_pre_made.split("x") if int(premade_width) > adjusted_host_width: # print(f"skipping {each_pre_made} due to width. the premade width is {premade_width} which is larger than the host of {adjusted_host_width}") continue if int(premade_height) > adjusted_host_height: # print(f"skipping {each_pre_made} due to height. the premade height is {premade_height} which is larger than the host of {adjusted_host_height}") continue premade_resolutions.append(each_pre_made) return premade_resolutions def get_resolution_data(btn_path: str) -> list: max_screen_size = get_max_screensize() host_w, host_h = max_screen_size.split("x") host_width = int(host_w) host_height = int(host_h) dynamic_enabled = are_dynamic_larger_profiles_enabled() if dynamic_enabled: return _get_dynamic_resolution_list(host_width=host_width, host_height=host_height) return _get_filtered_premade_list(host_width=host_width, host_height=host_height) def get_host_resolution_limits(): """Returns the (width, height) maximums allowed (including buffer).""" max_screen_size = get_max_screensize() w, h = map(int, max_screen_size.split("x")) return w - 50, h - 50 def process_custom_resolution(res_string: str): """ Validates and clamps a resolution string to host limits. Returns: (final_res_string, was_adjusted, is_valid) """ if not res_string or "x" not in res_string: return None, False, False try: w, h = map(int, res_string.split("x")) except ValueError: return None, False, False limit_w, limit_h = get_host_resolution_limits() was_adjusted = False if w > limit_w: w = limit_w was_adjusted = True if h > limit_h: h = limit_h was_adjusted = True return f"{w}x{h}", was_adjusted, True def validate_selected_resolution(resolution_choice: str) -> bool: """Given a user picked resolution, is it valid? (called by GUI's state)""" _, _, is_valid = process_custom_resolution(resolution_choice) return is_valid