From 6622c2a0b74dfe23d8be8d0203de20a48e24ae3f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 9 Jul 2023 19:23:01 +0200 Subject: Set fps limit (even when vsync is enabled) for retards who disable vsync system-wide --- depends/mglpp | 2 +- include/QuickMedia.hpp | 3 +++ src/QuickMedia.cpp | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/depends/mglpp b/depends/mglpp index e85ce72..f91ac8b 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit e85ce72f213f182508510a291cd82289dd639b5e +Subproject commit f91ac8b0fcc801bc6b2d04ebaeffe1feee4437f2 diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 0f8837d..ea814e4 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -242,5 +242,8 @@ namespace QuickMedia { int video_max_height = 0; std::mutex login_inputs_mutex; const char *yt_dl_name = nullptr; + + mgl::Clock update_monitor_max_fps_timer; + int monitor_max_fps = 0; }; } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 25f17d0..051b08d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -72,7 +72,23 @@ extern "C" { static int FPS_IDLE; static const double IDLE_TIMEOUT_SEC = 2.0; static const mgl::vec2i AVATAR_THUMBNAIL_SIZE(std::floor(32), std::floor(32)); -static const int FPS_SYNC_TO_VSYNC = 0; + +static int monitor_info_get_fps(const XRRModeInfo *mode_info) { + double v_total = mode_info->vTotal; + if(mode_info->modeFlags & RR_DoubleScan) { + v_total *= 2; + } + + if(mode_info->modeFlags & RR_Interlace) { + v_total /= 2; + } + + if(mode_info->hTotal > 0 && v_total > 0.0001) { + return std::round((double)mode_info->dotClock / ((double)mode_info->hTotal * v_total)); + } else { + return 0; + } +} struct Logo { const char *dark_theme_path; @@ -787,7 +803,12 @@ namespace QuickMedia { XSetErrorHandler(x_error_handler); XSetIOErrorHandler(x_io_error_handler); - window.set_framerate_limit(FPS_SYNC_TO_VSYNC); + monitor_max_fps = 0; + for_each_active_monitor_output(disp, [&](const XRRCrtcInfo*, const XRRModeInfo *mode_info) { + monitor_max_fps = std::max(monitor_max_fps, monitor_info_get_fps(mode_info)); + }); + + window.set_framerate_limit(monitor_max_fps); idle = false; if(create_directory_recursive(get_cache_dir().join("media")) != 0) { @@ -1444,8 +1465,16 @@ namespace QuickMedia { } void Program::idle_active_handler() { - if(idle) - window.set_framerate_limit(FPS_SYNC_TO_VSYNC); + if(idle) { + if(update_monitor_max_fps_timer.get_elapsed_time_seconds() >= 3.0) { + update_monitor_max_fps_timer.restart(); + monitor_max_fps = 0; + for_each_active_monitor_output(disp, [&](const XRRCrtcInfo*, const XRRModeInfo *mode_info) { + monitor_max_fps = std::max(monitor_max_fps, monitor_info_get_fps(mode_info)); + }); + } + window.set_framerate_limit(monitor_max_fps); + } idle = false; idle_timer.restart(); } @@ -3576,6 +3605,8 @@ namespace QuickMedia { } }; + idle_active_handler(); + while (current_page == PageType::VIDEO_CONTENT && window.is_open() && !go_to_previous_page) { while (window.poll_event(event)) { common_event_handler(event); -- cgit v1.2.3