diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-03-06 14:25:48 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-03-06 14:25:48 +0100 |
commit | f8617f2043ea4ec536c4622df63a77b25268aeb0 (patch) | |
tree | 0db0d16a3bbc68c0564f7c7f9166f1cf71f1838b /src/QuickMedia.cpp | |
parent | d3091854805fc625e2f6109f6f4af579420cd2a5 (diff) |
Youtube: fix channel next page, add proper channel search (non filter search)
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 6b480d2..03fe6b2 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -72,62 +72,53 @@ static const XRRModeInfo* get_mode_info(const XRRScreenResources *sr, RRMode id) return nullptr; } -static int get_monitor_max_hz(Display *display) { +static void for_each_active_monitor_output(Display *display, std::function<void(const XRRModeInfo*)> callback_func) { XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display)); - if(screen_res) { - unsigned long max_hz = 0; - for(int i = 0; i < screen_res->noutput; ++i) { - XRROutputInfo *out_info = XRRGetOutputInfo(display, screen_res, screen_res->outputs[i]); - if(out_info && out_info->connection == RR_Connected) { - XRRCrtcInfo *crt_info = XRRGetCrtcInfo(display, screen_res, out_info->crtc); - if(crt_info) { - const XRRModeInfo *mode_info = get_mode_info(screen_res, crt_info->mode); - if(mode_info) { - unsigned long total = mode_info->hTotal * mode_info->vTotal; - if(total > 0) - max_hz = std::max(max_hz, mode_info->dotClock / total); - } - XRRFreeCrtcInfo(crt_info); - } + if(!screen_res) + return; + + for(int i = 0; i < screen_res->noutput; ++i) { + XRROutputInfo *out_info = XRRGetOutputInfo(display, screen_res, screen_res->outputs[i]); + if(out_info && out_info->connection == RR_Connected) { + XRRCrtcInfo *crt_info = XRRGetCrtcInfo(display, screen_res, out_info->crtc); + if(crt_info) { + const XRRModeInfo *mode_info = get_mode_info(screen_res, crt_info->mode); + if(mode_info) + callback_func(mode_info); + XRRFreeCrtcInfo(crt_info); } - if(out_info) - XRRFreeOutputInfo(out_info); } - XRRFreeScreenResources(screen_res); - if(max_hz == 0) - max_hz = 60; - return std::min(max_hz, 144UL); + if(out_info) + XRRFreeOutputInfo(out_info); } - return 60; + + XRRFreeScreenResources(screen_res); +} + +static int get_monitor_max_hz(Display *display) { + unsigned long max_hz = 0; + for_each_active_monitor_output(display, [&max_hz](const XRRModeInfo *mode_info) { + unsigned long total = mode_info->hTotal * mode_info->vTotal; + if(total > 0) + max_hz = std::max(max_hz, (unsigned long)std::round((double)mode_info->dotClock / (double)total)); + }); + + if(max_hz == 0) + return 60; + return std::min(max_hz, 144UL); } static int get_largest_monitor_height(Display *display) { - XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display)); - if(screen_res) { - int max_height = 0; - for(int i = 0; i < screen_res->noutput; ++i) { - XRROutputInfo *out_info = XRRGetOutputInfo(display, screen_res, screen_res->outputs[i]); - if(out_info && out_info->connection == RR_Connected) { - XRRCrtcInfo* crt_info = XRRGetCrtcInfo(display, screen_res, out_info->crtc); - if(crt_info) { - const XRRModeInfo *mode_info = get_mode_info(screen_res, crt_info->mode); - if(mode_info) { - // Need to get the min of width or height because we want to get the smallest size for monitors in portrait mode, for mobile devices such as pinephone - int width_or_height = std::min((int)mode_info->width, (int)mode_info->height); - max_height = std::max(max_height, width_or_height); - } - XRRFreeCrtcInfo(crt_info); - } - } - if(out_info) - XRRFreeOutputInfo(out_info); - } - XRRFreeScreenResources(screen_res); - if(max_height == 0) - max_height = 720; - return std::max(max_height, 480); - } - return 720; + int max_height = 0; + for_each_active_monitor_output(display, [&max_height](const XRRModeInfo *mode_info) { + // Need to get the min of width or height because we want to get the smallest size for monitors in portrait mode, for mobile devices such as pinephone + int width_or_height = std::min((int)mode_info->width, (int)mode_info->height); + max_height = std::max(max_height, width_or_height); + }); + + if(max_height == 0) + return 720; + return std::max(max_height, 480); } static void get_screen_resolution(Display *display, int *width, int *height) { @@ -1903,7 +1894,7 @@ namespace QuickMedia { tabs.push_back(Tab{std::move(related_videos_body), std::move(related_videos_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } if(channels_page) { - tabs.push_back(Tab{create_body(), std::move(channels_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + tabs.push_back(Tab{create_body(), std::move(channels_page), create_search_bar("Search...", is_youtube ? 350 : SEARCH_DELAY_FILTER)}); } bool page_changed = false; @@ -2518,6 +2509,9 @@ namespace QuickMedia { images_to_upscale_queue.clear(); image_upscale_status.clear(); } + + window_size.x = window.getSize().x; + window_size.y = window.getSize().y; } static bool is_url_video(const std::string &url) { |