Skip to content

Commit

Permalink
Add UI scale fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiko2k committed Dec 11, 2022
1 parent 42f2f59 commit 1f219b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog----------------------------
v7.4.6

- Added theme entries for menu and corner buttons
- Added UI scale safety auto fallback
- Fixed crash when auto-theme enabled
- Fixed un-maximize button in fullscreen

Expand Down
22 changes: 15 additions & 7 deletions t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ def whicher(target):
icon = IMG_Load(os.path.join(asset_directory, "tau-mac.png").encode())

SDL_SetWindowIcon(t_window, icon)
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best".encode())

if not phone:
if window_size[0] != logical_size[0]:
Expand Down Expand Up @@ -4137,16 +4136,18 @@ def load_prefs():
SDL_GetWindowWMInfo(t_window, sss)

def auto_scale():
old = prefs.x_scale

old = prefs.scale_want

if prefs.x_scale:
if sss.subsystem in (SDL_SYSWM_WAYLAND, SDL_SYSWM_COCOA, SDL_SYSWM_UNKNOWN):
prefs.scale_want = window_size[0] / logical_size[0]
if old != prefs.x_scale:
if old != prefs.scale_want:
print("Applying scale based on buffer size")
elif sss.subsystem == SDL_SYSWM_X11:
if xdpi > 40:
prefs.scale_want = xdpi / 96
if old != prefs.x_scale:
if old != prefs.scale_want:
print("Applying scale based on xft setting")

prefs.scale_want = round(round(prefs.scale_want / 0.05) * 0.05, 2)
Expand All @@ -4160,11 +4161,16 @@ def auto_scale():
if prefs.scale_want == 2.05:
prefs.scale_want = 2.0

if old != prefs.x_scale:
if old != prefs.scale_want:
print(f"Using UI scale: {prefs.scale_want}")

if prefs.scale_want < 0.5:
prefs.scale_want = 1.0
if prefs.scale_want < 0.5:
prefs.scale_want = 1.0

if window_size[0] < (560 * prefs.scale_want) * 0.9 or window_size[1] < (330 * prefs.scale_want) * 0.9:
print("Window overscale!")
show_message("Detected unsuitable UI scaling.", "Scaling setting reset to 1x")
prefs.scale_want = 1.0

auto_scale()

Expand Down Expand Up @@ -40898,6 +40904,8 @@ def bk_playtime_transfer(self, fr, fr_s, fr_scr, so, to_s, to_scr):


def reload_scale():
auto_scale()

scale = prefs.scale_want

gui.scale = scale
Expand Down
2 changes: 2 additions & 0 deletions tauon.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def transfer_args_and_exit():
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, b'1')
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, b"1")
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, b"0")
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best".encode())

draw_border = True
w = 1120
Expand Down Expand Up @@ -249,6 +250,7 @@ def transfer_args_and_exit():
if maximized:
SDL_MaximizeWindow(t_window)


renderer = SDL_CreateRenderer(t_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND)
SDL_SetWindowOpacity(t_window, window_opacity)
Expand Down

0 comments on commit 1f219b4

Please sign in to comment.