aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-07-09 19:23:01 +0200
committerdec05eba <dec05eba@protonmail.com>2023-07-09 19:23:01 +0200
commit6622c2a0b74dfe23d8be8d0203de20a48e24ae3f (patch)
treeb14f8f70d2326c528bf0c71592c0c301ec94396c /src
parentf0693a48f176c01dd7b22ca4aa2aca0299146b30 (diff)
Set fps limit (even when vsync is enabled) for retards who disable vsync system-wide
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp39
1 files changed, 35 insertions, 4 deletions
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);