From 1ea2ff8cf7f9a012fafc4b910e940aa5627ccaa6 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 22 Jun 2017 13:50:48 -0400 Subject: Get the LuminaRandR framework able to enable/resize/move a monitor as requested. NOTE: The automatic resolution routine picks the larges one available for the monitor, but some monitors lie and don't actually support all the listed resolutions (probably because I am using an HDMI->VGA converter on my Laptop output right now). --- src-qt5/core/libLumina/LuminaRandR-X11.cpp | 67 +++++++++++++++++++++++++++--- src-qt5/core/libLumina/LuminaRandR.h | 4 +- src-qt5/core/libLumina/test/main.cpp | 19 +++++++-- 3 files changed, 79 insertions(+), 11 deletions(-) (limited to 'src-qt5/core/libLumina') diff --git a/src-qt5/core/libLumina/LuminaRandR-X11.cpp b/src-qt5/core/libLumina/LuminaRandR-X11.cpp index a78821db..8fcdbad0 100644 --- a/src-qt5/core/libLumina/LuminaRandR-X11.cpp +++ b/src-qt5/core/libLumina/LuminaRandR-X11.cpp @@ -40,6 +40,7 @@ inline bool loadScreenInfo(p_objects *p_obj){ p_obj->primary = false; p_obj->modes.clear(); p_obj->resolutions.clear(); + p_obj->crtc = 0; //Get the information associated with the output and save it in the p_objects cache xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(QX11Info::connection(), @@ -55,6 +56,11 @@ inline bool loadScreenInfo(p_objects *p_obj){ for(int j=0; jmodes.append( xcb_randr_get_output_info_modes(info)[j] ); } + //int pref_len = info->num_preferred; + //qDebug() << "Modes:" << p_obj->modes << "Num Preferred:" << pref_len; + /*for(int j=0; jpreferred.append( xcb_randr_get_output_info_preferred(info)[j] ); + }*/ p_obj->crtc = info->crtc; free(info); //done with output_info @@ -102,11 +108,19 @@ inline xcb_randr_mode_t modeForResolution(QSize res, QList mod xcb_randr_get_screen_resources_unchecked(QX11Info::connection(), QX11Info::appRootWindow()), NULL); if(srreply!=0){ unsigned int refreshrate = 0; + QSize sz; for(int i=0; i refreshrate){ det_mode = minfo.id; refreshrate = minfo.dot_clock; } + if(res.isNull() && (minfo.width > sz.width() || minfo.height > sz.height()) ){ + //No resolution requested - pick the largest one + qDebug() << "Found Bigger Mode:" << sz << QSize(minfo.width, minfo.height); + sz = QSize(minfo.width, minfo.height); + det_mode = minfo.id; + }else if(!res.isNull()){ + sz = QSize(minfo.width, minfo.height); + if(sz == res && minfo.dot_clock > refreshrate){ det_mode = minfo.id; refreshrate = minfo.dot_clock; } + } } } free(srreply); @@ -197,12 +211,38 @@ bool OutputDevice::disable(){ bool OutputDevice::enable(QRect geom){ //if no geom provided, will add as the right-most screen at optimal resolution - if(this->isEnabled()){ return true; } //already enabled + //if(this->isEnabled()){ return true; } //already enabled qDebug() << "Enable Monitor:" << geom; xcb_randr_mode_t mode = modeForResolution(geom.size(), p_obj.modes); if(mode==XCB_NONE){ return false; } //invalid resolution for this monitor + //qDebug() << " - Found Mode:" << mode; + if(p_obj.crtc == 0){ + //Need to scan for an available crtc to use (turning on a monitor for the first time) + xcb_randr_get_screen_resources_reply_t *reply = xcb_randr_get_screen_resources_reply(QX11Info::connection(), + xcb_randr_get_screen_resources_unchecked(QX11Info::connection(), QX11Info::appRootWindow()), + NULL); + int num = xcb_randr_get_screen_resources_crtcs_length(reply); + for(int i=0; i possible; + if(xcb_randr_get_crtc_info_outputs_length(info) < 1){ //make sure it is not already associated with an output + int pnum = xcb_randr_get_crtc_info_possible_length(info); + for(int p=0; pID()+"]"; @@ -19,11 +24,19 @@ int main(int argc, char** argv){ qDebug() << " - Physical Size (mm):" << devList.at(i)->physicalSizeMM(); qDebug() << " - Current DPI:" << devList.at(i)->physicalDPI(); qDebug() << " - Available Resolutions:" << devList.at(i)->availableResolutions(); + if(devList.at(i)->ID() == toggle && toggleOK<0){ toggleOK = (devList.at(i)->isEnabled() ? 1 : 0); } } } - /*QString disable = "HDMI-2"; - qDebug() << "Try Disabling Monitor:" << disable; - devList.disableMonitor(disable);*/ + qDebug() << "\n================\n"; + if(toggleOK == 0){ + qDebug() << "Try Enabling Monitor:" << toggle << toggleGeom; + bool ok = devList.enableMonitor(toggle, toggleGeom); + qDebug() << " -- Success:" << ok; + }else if(toggleOK == 1){ + qDebug() << "Try Disabling Monitor:" << toggle; + bool ok = devList.disableMonitor(toggle); + qDebug() << " -- Success:" << ok; + } /*QString setprimary = "eDP-1"; if(devList.primaryMonitor() != setprimary){ -- cgit