-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/sdl3' into sdl3
# Conflicts: # src/tauon/__main__.py
- Loading branch information
Showing
1 changed file
with
44 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,16 +89,9 @@ def emit(self, record: dict): | |
], | ||
) | ||
# INFO+ to std_err | ||
logging.getLogger().handlers[0].setLevel(logging.DEBUG if os.path.isfile(install_directory / "debug") else logging.INFO) | ||
logging.getLogger().handlers[0].setLevel(logging.DEBUG) | ||
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter()) | ||
|
||
# https://docs.python.org/3/library/warnings.html | ||
logging.captureWarnings(capture=True) | ||
if not sys.warnoptions: | ||
import warnings | ||
warnings.simplefilter("default") | ||
os.environ["PYTHONWARNINGS"] = "default" # Also affect subprocesses | ||
|
||
if sys.platform != "win32": | ||
import fcntl | ||
|
||
|
@@ -108,8 +101,9 @@ def emit(self, record: dict): | |
t_id = "tauonmb" | ||
t_agent = "TauonMusicBox/" + n_version | ||
|
||
logging.info(f"{t_title} {t_version}") | ||
logging.info("Copyright 2015-2024 Taiko2k [email protected]\n") | ||
# Leave these outside of logging for prettiness | ||
print(f"{t_title} {t_version}") | ||
print("Copyright 2015-2024 Taiko2k [email protected]\n") | ||
|
||
# Early arg processing | ||
def transfer_args_and_exit() -> None: | ||
|
@@ -240,10 +234,11 @@ def transfer_args_and_exit() -> None: | |
if sys.platform == "win32" and sys.getwindowsversion().major < 10 or Path(user_directory / "nohidpi").is_file(): | ||
allow_hidpi = False | ||
|
||
sdl3.SDL_SetHint(sdl3.SDL_HINT_VIDEO_ALLOW_SCREENSAVER.encode(), b"1") | ||
sdl3.SDL_SetHint(sdl3.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH.encode(), b"1") | ||
sdl3.SDL_SetHint(sdl3.SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR.encode(), b"0") | ||
# sdl3.SDL_SetHint(b"SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR", b"0") | ||
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()) | ||
# SDL_SetHint(b"SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR", b"0") | ||
|
||
draw_border = True | ||
w = 1120 | ||
|
@@ -310,43 +305,45 @@ def transfer_args_and_exit() -> None: | |
if Path(user_directory / "x11").exists(): | ||
os.environ["SDL_VIDEODRIVER"] = "x11" | ||
|
||
|
||
sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO) | ||
err = sdl3.SDL_GetError() | ||
SDL_Init(SDL_INIT_VIDEO) | ||
err = SDL_GetError() | ||
if err and "GLX" in err.decode(): | ||
logging.error(f"SDL init error: {err.decode()}") | ||
sdl3.SDL_ShowSimpleMessageBox( | ||
sdl3.SDL_MESSAGEBOX_ERROR, b"Tauon Music Box failed to start :(", | ||
SDL_ShowSimpleMessageBox( | ||
SDL_MESSAGEBOX_ERROR, b"Tauon Music Box failed to start :(", | ||
b"Error: " + err + b".\n If you're using Flatpak, try run `$ flatpak update`", None) | ||
sys.exit(1) | ||
|
||
window_title = t_title | ||
window_title = window_title.encode("utf-8") | ||
|
||
flags = sdl3.SDL_WINDOW_RESIZABLE | sdl3.SDL_WINDOW_TRANSPARENT | ||
flags = SDL_WINDOW_RESIZABLE | ||
|
||
if allow_hidpi: | ||
flags |= SDL_WINDOW_ALLOW_HIGHDPI | ||
|
||
if draw_border and not fs_mode: | ||
flags |= sdl3.SDL_WINDOW_BORDERLESS | ||
flags |= SDL_WINDOW_BORDERLESS | ||
|
||
if fs_mode: | ||
flags |= sdl3.SDL_WINDOW_FULLSCREEN_DESKTOP | ||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP | ||
|
||
if old_window_position is None: | ||
o_x = sdl3.SDL_WINDOWPOS_UNDEFINED | ||
o_y = sdl3.SDL_WINDOWPOS_UNDEFINED | ||
o_x = SDL_WINDOWPOS_UNDEFINED | ||
o_y = SDL_WINDOWPOS_UNDEFINED | ||
else: | ||
o_x = old_window_position[0] | ||
o_y = old_window_position[1] | ||
|
||
if "--tray" in sys.argv: | ||
flags |= sdl3.SDL_WINDOW_HIDDEN | ||
flags |= SDL_WINDOW_HIDDEN | ||
|
||
|
||
t_window = sdl3.SDL_CreateWindow( # todo use SDL_CreateWindowAndRenderer() | ||
t_window = SDL_CreateWindow( | ||
window_title, | ||
# o_x, o_y, | ||
o_x, o_y, | ||
logical_size[0], logical_size[1], | ||
flags) | ||
flags) # | SDL_WINDOW_FULLSCREEN) | ||
|
||
if not t_window: | ||
logging.error("ERROR CREATING WINDOW!") | ||
|
@@ -356,44 +353,32 @@ def transfer_args_and_exit() -> None: | |
logging.error(f"Size 0: {logical_size[0]}") | ||
logging.error(f"Size 1: {logical_size[1]}") | ||
logging.error(f"Flags: {flags}") | ||
logging.error(f"SDL Error: {sdl3.SDL_GetError()}") | ||
logging.error(f"SDL Error: {SDL_GetError()}") | ||
sys.exit(1) | ||
|
||
if maximized: | ||
sdl3.SDL_MaximizeWindow(t_window) | ||
|
||
drivers = [] | ||
i = 0 | ||
while True: | ||
x = sdl3.SDL_GetRenderDriver(i) | ||
i += 1 | ||
if x is None: | ||
break | ||
drivers.append(x) | ||
SDL_MaximizeWindow(t_window) | ||
|
||
logging.debug(f"SDL availiable drivers: {drivers}") | ||
|
||
renderer = sdl3.SDL_CreateRenderer(t_window, b"opengl") # sdl3.SDL_RENDERER_PRESENTVSYNC | ||
renderer = SDL_CreateRenderer(t_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC) | ||
|
||
if not renderer: | ||
logging.error("ERROR CREATING RENDERER!") | ||
sys.exit(1) | ||
|
||
sdl3.SDL_SetRenderDrawBlendMode(renderer, sdl3.SDL_BLENDMODE_BLEND) | ||
sdl3.SDL_SetWindowOpacity(t_window, window_opacity) | ||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) | ||
SDL_SetWindowOpacity(t_window, window_opacity) | ||
|
||
sdl3.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0) | ||
sdl3.SDL_RenderClear(renderer) | ||
SDL_SetRenderDrawColor(renderer, 7, 7, 7, 255) | ||
SDL_RenderClear(renderer) | ||
|
||
logging.info(f"SDL window system: {sdl3.SDL_GetCurrentVideoDriver().decode()}") | ||
|
||
i_x = pointer(c_int(0)) | ||
i_y = pointer(c_int(0)) | ||
sdl3.SDL_GetWindowSizeInPixels(t_window, i_x, i_y) | ||
SDL_GL_GetDrawableSize(t_window, i_x, i_y) | ||
window_size[0] = i_x.contents.value | ||
window_size[1] = i_y.contents.value | ||
|
||
sdl3.SDL_GetWindowSize(t_window, i_x, i_y) | ||
SDL_GetWindowSize(t_window, i_x, i_y) | ||
logical_size[0] = i_x.contents.value | ||
logical_size[1] = i_y.contents.value | ||
|
||
|
@@ -407,26 +392,18 @@ def transfer_args_and_exit() -> None: | |
img_path = img_path2 | ||
del img_path2 | ||
|
||
sdl3.SDL_SetRenderDrawColor(renderer, 7, 7, 7, 255) | ||
sdl3.SDL_RenderFillRect(renderer, None) | ||
|
||
raw_image = sdl3.IMG_Load(str(img_path).encode()) | ||
texture = sdl3.SDL_CreateTextureFromSurface(renderer, raw_image) | ||
i_x = c_float(0.0) | ||
i_y = c_float(0.0) | ||
sdl3.SDL_GetTextureSize(texture, byref(i_x), byref(i_y)) | ||
w = i_x.value | ||
h = i_y.value | ||
rect = sdl3.SDL_FRect(window_size[0] // 2 - w // 2, window_size[1] // 2 - h // 2, w, h) | ||
sdl3.SDL_RenderTexture(renderer, texture, None, rect) | ||
|
||
|
||
raw_image = IMG_Load(str(img_path).encode()) | ||
sdl_texture = SDL_CreateTextureFromSurface(renderer, raw_image) | ||
w = raw_image.contents.w | ||
h = raw_image.contents.h | ||
rect = SDL_Rect(window_size[0] // 2 - w // 2, window_size[1] // 2 - h // 2, w, h) | ||
|
||
SDL_RenderCopy(renderer, sdl_texture, None, rect) | ||
|
||
sdl3.SDL_RenderPresent(renderer) | ||
SDL_RenderPresent(renderer) | ||
|
||
sdl3.SDL_DestroySurface(raw_image) | ||
sdl3.SDL_DestroyTexture(texture) | ||
SDL_FreeSurface(raw_image) | ||
SDL_DestroyTexture(sdl_texture) | ||
|
||
holder = t_bootstrap.holder | ||
holder.t_window = t_window | ||
|
@@ -455,7 +432,7 @@ def transfer_args_and_exit() -> None: | |
holder.log = log | ||
|
||
del raw_image | ||
del texture | ||
del sdl_texture | ||
del w | ||
del h | ||
del rect | ||
|