diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index c966b8c..7eb36ca 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -64,14 +64,32 @@ static int x_io_error_handler(Display*) { return 0; } +static const XRRModeInfo* get_mode_info(const XRRScreenResources *sr, RRMode id) { + for(int i = 0; i < sr->nmode; ++i) { + if(sr->modes[i].id == id) + return &sr->modes[i]; + } + return nullptr; +} + static int get_monitor_max_hz(Display *display) { XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display)); if(screen_res) { unsigned long max_hz = 0; - for(int i = 0; i < screen_res->nmode; ++i) { - unsigned long total = screen_res->modes[i].hTotal*screen_res->modes[i].vTotal; - if(total > 0) - max_hz = std::max(max_hz, screen_res->modes[i].dotClock/total); + 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); + 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(out_info) + XRRFreeOutputInfo(out_info); } XRRFreeScreenResources(screen_res); if(max_hz == 0) @@ -85,15 +103,27 @@ 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->nmode; ++i) { - max_height = std::max(max_height, (int)screen_res->modes[i].height); + 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); + 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 = 1080; + max_height = 720; return std::max(max_height, 480); } - return 1080; + return 720; } static void get_screen_resolution(Display *display, int *width, int *height) { |