hydraveil-gui/gui/v2/presenters/data/resolution_data.py

69 lines
2.6 KiB
Python

from gui.v2.infrastructure.screen_size import get_max_screensize
from gui.v2.actions.config import get_registrations
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, full_btn_path: str) -> 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)
# print(f"dynamic_resolutions are {dynamic_resolutions}")
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)
# print(f"final premade_resolutions {premade_resolutions}")
return premade_resolutions
def get_resolution_data(btn_path: str) -> list:
max_screen_size = get_max_screensize()
# print(f"max_screen_size is {max_screen_size}")
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)