From 5de0c9816f9bd93f13592c6c16e27396a5bcb8ea Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 20 Jun 2017 14:02:57 -0400 Subject: Commit a bit more work on the LuminaRandR class - still not ready yet. --- src-qt5/core/libLumina/LuminaRandR-X11.cpp | 40 ++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src-qt5/core/libLumina/LuminaRandR-X11.cpp') diff --git a/src-qt5/core/libLumina/LuminaRandR-X11.cpp b/src-qt5/core/libLumina/LuminaRandR-X11.cpp index f8907741..d22955fd 100644 --- a/src-qt5/core/libLumina/LuminaRandR-X11.cpp +++ b/src-qt5/core/libLumina/LuminaRandR-X11.cpp @@ -27,7 +27,7 @@ inline QStringList atomsToNames(xcb_atom_t *atoms, unsigned int num){ for(unsigned int i=0; i OutputDevice::availableMonitors(){ //Get the list of monitors xcb_randr_get_monitors_cookie_t cookie = xcb_randr_get_monitors_unchecked(QX11Info::connection(), QX11Info::appRootWindow(), 1); xcb_randr_get_monitors_reply_t *reply = xcb_randr_get_monitors_reply(QX11Info::connection(), cookie, NULL); - if(reply==0){ + if(reply==0){ qDebug() << "Could not get monitor list"; return list; } @@ -113,6 +113,7 @@ bool OutputDevice::isAutomatic(){ return p_obj.automatic; } QList OutputDevice::availableResolutions(){ return p_obj.resolutions; } QSize OutputDevice::currentResolution(){ return p_obj.geometry.size(); } //no concept of panning/scaling yet QRect OutputDevice::currentGeometry(){ return p_obj.geometry; } +QSize OutputDevice::physicalSizeMM(){ return p_obj.physicalSizeMM; } //Modification bool OutputDevice::setAsPrimary(bool set){ @@ -131,7 +132,7 @@ bool OutputDevice::disable(){ if(p_obj.monitor_atom!=0){ xcb_randr_delete_monitor(QX11Info::connection(), QX11Info::appRootWindow(), p_obj.monitor_atom); p_obj.monitor_atom = 0; - return true; + return true; } return false; } @@ -152,7 +153,7 @@ void OutputDevice::updateInfoCache(){ if(p_obj.monitor_atom !=0 || !p_obj.name.isEmpty() ){ xcb_randr_get_monitors_cookie_t cookie = xcb_randr_get_monitors_unchecked(QX11Info::connection(), QX11Info::appRootWindow(), 1); xcb_randr_get_monitors_reply_t *reply = xcb_randr_get_monitors_reply(QX11Info::connection(), cookie, NULL); - if(reply!=0){ + if(reply!=0){ xcb_randr_monitor_info_iterator_t iter = xcb_randr_get_monitors_monitors_iterator(reply); //qDebug() << "Number of Monitors:" << xcb_randr_get_monitors_monitors_length(reply); while(iter.rem>0){ @@ -165,7 +166,7 @@ void OutputDevice::updateInfoCache(){ p_obj.automatic = (iter.data->automatic == 1); p_obj.geometry = QRect(iter.data->x, iter.data->y, iter.data->width, iter.data->height); p_obj.physicalSizeMM = QSize(iter.data->width_in_millimeters, iter.data->height_in_millimeters); - //Load the "outputs" + //Load the "outputs" p_obj.outputs.clear(); int out_len = xcb_randr_monitor_info_outputs_length(iter.data); for(int i=0; i0){ @@ -225,9 +230,18 @@ OutputDeviceList::OutputDeviceList(){ free(replyA); } //end loading of active/enabled monitors -/* + //Now get the information about any **UNUSED** monitors/outputs - xcb_randr_get_screen_resources_reply_t *reply = xcb_randr_get_screen_resources_reply(QX11Info::connection(), + xcb_randr_get_providers_reply_t *pinfo = xcb_randr_get_providers_reply( QX11Info::connection(), + xcb_randr_get_providers(QX11Info::connection(), QX11Info::appRootWindow()), NULL); + if(pinfo != 0){ + xcb_randr_provider_t *prov = xcb_randr_get_providers_providers(pinfo); + int plen = xcb_randr_get_providers_providers_length(pinfo); + qDebug() << "Number of Providers:" << plen; + free(pinfo); + } + + /*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 outputnum = xcb_randr_get_screen_resources_outputs_length(reply); @@ -255,7 +269,7 @@ OutputDeviceList::OutputDeviceList(){ if(mode_len<=0){ continue; } //skip this output - not a physical screen which can be used - //Clones + //Clones qDebug() << "Number of Clones:" << xcb_randr_get_output_info_clones_length(info); //Names @@ -289,7 +303,7 @@ OutputDeviceList::OutputDeviceList(){ free(info); } - + free(reply);*/ } -- cgit From 060ae4166fd5b071e4ff787fbba0fd76f867a4f4 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 21 Jun 2017 15:13:22 -0400 Subject: Oops - forgot to add the changes to the LuminaRandR files. --- src-qt5/core/libLumina/LuminaRandR-X11.cpp | 207 +++++++++++++++++------------ 1 file changed, 120 insertions(+), 87 deletions(-) (limited to 'src-qt5/core/libLumina/LuminaRandR-X11.cpp') diff --git a/src-qt5/core/libLumina/LuminaRandR-X11.cpp b/src-qt5/core/libLumina/LuminaRandR-X11.cpp index d22955fd..52eda71a 100644 --- a/src-qt5/core/libLumina/LuminaRandR-X11.cpp +++ b/src-qt5/core/libLumina/LuminaRandR-X11.cpp @@ -6,11 +6,7 @@ //=========================================== #include "LuminaRandR.h" -//#include "xcb/randr.h" -//#include "xcb/xcb_atom.h" - -#include -#include +//#include "X11/extensions/Xrandr.h" inline QString atomToName(xcb_atom_t atom){ xcb_get_atom_name_reply_t *nreply = xcb_get_atom_name_reply(QX11Info::connection(), xcb_get_atom_name_unchecked(QX11Info::connection(), atom), NULL); @@ -36,6 +32,61 @@ inline QStringList atomsToNames(xcb_atom_t *atoms, unsigned int num){ return names; }; +inline bool loadScreenInfo(p_objects *p_obj, xcb_randr_monitor_info_t *info){ + if(p_obj->monitor_atom == 0){ p_obj->monitor_atom = info->name; } + if(p_obj->name.isEmpty()){ p_obj->name = atomToName(info->name); } + //Now update all the info in the cache + p_obj->primary = (info->primary == 1); + p_obj->automatic = (info->automatic == 1); + p_obj->geometry = QRect(info->x, info->y, info->width, info->height); + p_obj->physicalSizeMM = QSize(info->width_in_millimeters, info->height_in_millimeters); + //Load the "outputs" + p_obj->outputs.clear(); + int out_len = xcb_randr_monitor_info_outputs_length(info); + for(int i=0; ioutputs << xcb_randr_monitor_info_outputs(info)[i]; } + qDebug() << "Info Loaded:" << p_obj->name; + //qDebug() << "Output Number:" << screennum; + /*xcb_screen_t *scrn = xcb_aux_get_screen(QX11Info::connection(), screennum); + if(scrn==0){ return; } + xcb_randr_get_screen_info_reply_t *sinfo = xcb_randr_get_screen_info_reply(QX11Info::connection(), xcb_randr_get_screen_info_unchecked( QX11Info::connection(), scrn->root), NULL); + if(sinfo!=0){ + qDebug() << "Got valid screen info"; + qDebug() << " - Number of Screen Resolutions:" << xcb_randr_get_screen_info_sizes_length(sinfo); + free(sinfo); + }*/ + for(int i=0; ioutputs.length(); i++){ + xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(QX11Info::connection(), + xcb_randr_get_output_info_unchecked(QX11Info::connection(), p_obj->outputs[i], QX11Info::appTime()), + NULL); + if(info==0){ continue; } //bad output + //Modes + int mode_len = xcb_randr_get_output_info_modes_length(info); + qDebug() << "Number of Modes:" << mode_len; + if(mode_len<=0){ continue; } //skip this output - not a physical screen which can be used + p_obj->modes.clear(); + for(int j=0; jmodes.append( xcb_randr_get_output_info_modes(info)[j] ); + } + } + //qDebug() << "INFO:" << p_obj->name; + //qDebug() << "Found Outputs:" << p_obj->outputs; + //qDebug() << "Found Modes:" << p_obj->modes; + p_obj->resolutions.clear(); + xcb_randr_get_screen_resources_reply_t *srreply = xcb_randr_get_screen_resources_reply(QX11Info::connection(), + xcb_randr_get_screen_resources_unchecked(QX11Info::connection(), QX11Info::appRootWindow()), NULL); + if(srreply!=0){ + for(int i=0; imodes.contains(minfo.id)){ + QSize sz(minfo.width, minfo.height); + if(!p_obj->resolutions.contains(sz)){ p_obj->resolutions.append( sz); } + } + } + free(srreply); + } + return true; +} + /*class OutputDevice::p_objects{ public: xcb_atom_t monitor_atom; //This is the index used to identify particular monitors (unique ID) @@ -106,8 +157,8 @@ OutputDevice::~OutputDevice(){ } // INFORMATION FUNCTIONS (simply read from cache) -QString OutputDevice::ID(){ qDebug() << "Find ID"; return p_obj.name; } -bool OutputDevice::isEnabled(){ return p_obj.monitor_atom !=0; } +QString OutputDevice::ID(){ return p_obj.name; } +bool OutputDevice::isEnabled(){ return !p_obj.geometry.isNull(); } bool OutputDevice::isPrimary(){ return p_obj.primary; } bool OutputDevice::isAutomatic(){ return p_obj.automatic; } QList OutputDevice::availableResolutions(){ return p_obj.resolutions; } @@ -129,9 +180,21 @@ bool OutputDevice::setAsPrimary(bool set){ } bool OutputDevice::disable(){ + //qDebug() << "Disable Monitor:" << p_obj.monitor_atom; if(p_obj.monitor_atom!=0){ - xcb_randr_delete_monitor(QX11Info::connection(), QX11Info::appRootWindow(), p_obj.monitor_atom); - p_obj.monitor_atom = 0; + //qDebug() << " - Go ahead"; + for(int o=0; o0){ - //qDebug() << " Index:" << iter.index << "Rem:" << iter.rem; - if( p_obj.monitor_atom == iter.data->name || p_obj.name == atomToName(iter.data->name) ){ - if(p_obj.monitor_atom == 0){ p_obj.monitor_atom = iter.data->name; } - if(p_obj.name.isEmpty()){ p_obj.name = atomToName(iter.data->name); } - //Now update all the info in the cache - p_obj.primary = (iter.data->primary == 1); - p_obj.automatic = (iter.data->automatic == 1); - p_obj.geometry = QRect(iter.data->x, iter.data->y, iter.data->width, iter.data->height); - p_obj.physicalSizeMM = QSize(iter.data->width_in_millimeters, iter.data->height_in_millimeters); - //Load the "outputs" - p_obj.outputs.clear(); - int out_len = xcb_randr_monitor_info_outputs_length(iter.data); - for(int i=0; i0){ + if( p_obj.monitor_atom == iter.data->name || p_obj.name == atomToName(iter.data->name) ){ + loadScreenInfo(&p_obj, iter.data); + found = true; + break; //Finished with the information for this particular monitor + } + xcb_randr_monitor_info_next(&iter); } - xcb_randr_monitor_info_next(&iter); - } - free(reply); - } //end check for reply structure + free(reply); + } //end check for reply structure + } //end loop over active/inactive monitor state } //end loading of active/enabled monitor information - //Now load any information from the outputs - for(int i=0; i usedOutputs; + QList usedOutputs; //Get the information about all the "enabled" monitors - xcb_randr_get_monitors_cookie_t cookieA = xcb_randr_get_monitors_unchecked(QX11Info::connection(), QX11Info::appRootWindow(), 1); - xcb_randr_get_monitors_reply_t *replyA = xcb_randr_get_monitors_reply(QX11Info::connection(), cookieA, NULL); - if(replyA!=0){ - xcb_randr_monitor_info_iterator_t iter = xcb_randr_get_monitors_monitors_iterator(replyA); - //qDebug() << "Number of Monitors:" << xcb_randr_get_monitors_monitors_length(reply); - while(iter.rem>0){ - //qDebug() << "Found Monitor:"; - //qDebug() << " Index:" << iter.index << "Rem:" << iter.rem; - QString name = atomToName(iter.data->name); - OutputDevice dev(name); - usedOutputs << dev.p_obj.outputs; - - this->append(dev); //add to the internal list - xcb_randr_monitor_info_next(&iter); - } - //Free up any objects we are done with - free(replyA); - } //end loading of active/enabled monitors + for(int i=0; i<2; i++){ //loop over active/inactive monitors + qDebug() << "Scanning For Monitors:" << (i==0 ? "active" : "inactive"); + xcb_randr_get_monitors_cookie_t cookieA = xcb_randr_get_monitors_unchecked(QX11Info::connection(), QX11Info::appRootWindow(), (i==0 ? 1 : 10)); //toggle active/inactive monitors + xcb_randr_get_monitors_reply_t *replyA = xcb_randr_get_monitors_reply(QX11Info::connection(), cookieA, NULL); + if(replyA!=0){ + xcb_randr_monitor_info_iterator_t iter = xcb_randr_get_monitors_monitors_iterator(replyA); + //qDebug() << "Number of Monitors:" << xcb_randr_get_monitors_monitors_length(reply); + while(iter.rem>0){ + //qDebug() << "Found Monitor:"; + //qDebug() << " Index:" << iter.index << "Rem:" << iter.rem; + if(!usedOutputs.contains(iter.data->name)){ + QString name = atomToName(iter.data->name); + OutputDevice dev(name); + usedOutputs << iter.data->name; + out_devs.append(dev); //add to the internal list + } + xcb_randr_monitor_info_next(&iter); + } + //Free up any objects we are done with + free(replyA); + } //end loading of active/enabled monitors + } //end loop over active/inactive monitors //Now get the information about any **UNUSED** monitors/outputs - xcb_randr_get_providers_reply_t *pinfo = xcb_randr_get_providers_reply( QX11Info::connection(), - xcb_randr_get_providers(QX11Info::connection(), QX11Info::appRootWindow()), NULL); - if(pinfo != 0){ - xcb_randr_provider_t *prov = xcb_randr_get_providers_providers(pinfo); - int plen = xcb_randr_get_providers_providers_length(pinfo); - qDebug() << "Number of Providers:" << plen; - free(pinfo); - } - /*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); @@ -281,7 +308,7 @@ OutputDeviceList::OutputDeviceList(){ } //Properties - xcb_randr_list_output_properties_reply_t *pinfo = xcb_randr_list_output_properties_reply(QX11Info::connection(), + xcb_randr_list_output_properties_reply_t *pinfo = xcb_randr_list_output_properties_reply(QX11Info::connection(), xcb_randr_list_output_properties_unchecked(QX11Info::connection(), output), NULL); int pinfo_len = xcb_randr_list_output_properties_atoms_length(pinfo); @@ -317,5 +344,11 @@ void OutputDeviceList::setPrimaryMonitor(QString id){ } void OutputDeviceList::disableMonitor(QString id){ - + for(int i=0; i Date: Wed, 21 Jun 2017 16:01:50 -0400 Subject: Start a large update to LuminaRandR info retrieval routine. **DOES NOT COMPILE** Nothing should be using this class yet, so there should be no pkg fallout from it. --- src-qt5/core/libLumina/LuminaRandR-X11.cpp | 100 ++++++++++++++++++----------- 1 file changed, 63 insertions(+), 37 deletions(-) (limited to 'src-qt5/core/libLumina/LuminaRandR-X11.cpp') diff --git a/src-qt5/core/libLumina/LuminaRandR-X11.cpp b/src-qt5/core/libLumina/LuminaRandR-X11.cpp index 52eda71a..0e68cfd2 100644 --- a/src-qt5/core/libLumina/LuminaRandR-X11.cpp +++ b/src-qt5/core/libLumina/LuminaRandR-X11.cpp @@ -41,33 +41,24 @@ inline bool loadScreenInfo(p_objects *p_obj, xcb_randr_monitor_info_t *info){ p_obj->geometry = QRect(info->x, info->y, info->width, info->height); p_obj->physicalSizeMM = QSize(info->width_in_millimeters, info->height_in_millimeters); //Load the "outputs" - p_obj->outputs.clear(); + /*p_obj->outputs.clear(); int out_len = xcb_randr_monitor_info_outputs_length(info); for(int i=0; ioutputs << xcb_randr_monitor_info_outputs(info)[i]; } qDebug() << "Info Loaded:" << p_obj->name; - //qDebug() << "Output Number:" << screennum; - /*xcb_screen_t *scrn = xcb_aux_get_screen(QX11Info::connection(), screennum); - if(scrn==0){ return; } - xcb_randr_get_screen_info_reply_t *sinfo = xcb_randr_get_screen_info_reply(QX11Info::connection(), xcb_randr_get_screen_info_unchecked( QX11Info::connection(), scrn->root), NULL); - if(sinfo!=0){ - qDebug() << "Got valid screen info"; - qDebug() << " - Number of Screen Resolutions:" << xcb_randr_get_screen_info_sizes_length(sinfo); - free(sinfo); - }*/ - for(int i=0; ioutputs.length(); i++){ + for(int i=0; ioutputs.length(); i++){*/ xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(QX11Info::connection(), - xcb_randr_get_output_info_unchecked(QX11Info::connection(), p_obj->outputs[i], QX11Info::appTime()), + xcb_randr_get_output_info_unchecked(QX11Info::connection(), p_obj->output, QX11Info::appTime()), NULL); if(info==0){ continue; } //bad output //Modes int mode_len = xcb_randr_get_output_info_modes_length(info); - qDebug() << "Number of Modes:" << mode_len; + //qDebug() << "Number of Modes:" << mode_len; if(mode_len<=0){ continue; } //skip this output - not a physical screen which can be used p_obj->modes.clear(); for(int j=0; jmodes.append( xcb_randr_get_output_info_modes(info)[j] ); } - } + //} //qDebug() << "INFO:" << p_obj->name; //qDebug() << "Found Outputs:" << p_obj->outputs; //qDebug() << "Found Modes:" << p_obj->modes; @@ -149,6 +140,13 @@ OutputDevice::OutputDevice(QString id){ p_obj.name = id; p_obj.primary = p_obj.automatic = false; p_obj.monitor_atom = 0; + p_obj.output = 0; + bool ok = false; + p_obj.output = id.toInt(&ok); + if(ok){ + //output ID number instead + p_obj.name.clear(); + } updateInfoCache(); } @@ -161,6 +159,8 @@ QString OutputDevice::ID(){ return p_obj.name; } bool OutputDevice::isEnabled(){ return !p_obj.geometry.isNull(); } bool OutputDevice::isPrimary(){ return p_obj.primary; } bool OutputDevice::isAutomatic(){ return p_obj.automatic; } +bool OutputDevice::isConnected(){ return !p_obj.modes.isEmpty(); } + QList OutputDevice::availableResolutions(){ return p_obj.resolutions; } QSize OutputDevice::currentResolution(){ return p_obj.geometry.size(); } //no concept of panning/scaling yet QRect OutputDevice::currentGeometry(){ return p_obj.geometry; } @@ -212,6 +212,22 @@ void OutputDevice::changeResolution(QSize){ } void OutputDevice::updateInfoCache(){ + 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 outputnum = xcb_randr_get_screen_resources_outputs_length(reply); + for(int i=0; ioutput==0){ + //Need to detect the name for this output (inefficient - better to pass in the output number directly) + xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(QX11Info::connection(), + xcb_randr_get_output_info_unchecked(QX11Info::connection(), output, QX11Info::appTime()), + NULL); + //Name + QString name = QString::fromLocal8Bit( (char*) xcb_randr_get_output_info_name(info), xcb_randr_get_output_info_name_length(info)); + if( + } + //Find the **active** monitor with the given id/name if(p_obj.monitor_atom !=0 || !p_obj.name.isEmpty() ){ bool found = false; @@ -241,15 +257,30 @@ void OutputDevice::updateInfoCache(){ // ============================ OutputDeviceList::OutputDeviceList(){ - QList usedOutputs; + 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 outputnum = xcb_randr_get_screen_resources_outputs_length(reply); + for(int i=0; i usedOutputs; //Get the information about all the "enabled" monitors - for(int i=0; i<2; i++){ //loop over active/inactive monitors + /*for(int i=0; i<2; i++){ //loop over active/inactive monitors qDebug() << "Scanning For Monitors:" << (i==0 ? "active" : "inactive"); xcb_randr_get_monitors_cookie_t cookieA = xcb_randr_get_monitors_unchecked(QX11Info::connection(), QX11Info::appRootWindow(), (i==0 ? 1 : 10)); //toggle active/inactive monitors xcb_randr_get_monitors_reply_t *replyA = xcb_randr_get_monitors_reply(QX11Info::connection(), cookieA, NULL); if(replyA!=0){ xcb_randr_monitor_info_iterator_t iter = xcb_randr_get_monitors_monitors_iterator(replyA); - //qDebug() << "Number of Monitors:" << xcb_randr_get_monitors_monitors_length(reply); + qDebug() << "Number of Monitors:" << xcb_randr_get_monitors_monitors_length(replyA); while(iter.rem>0){ //qDebug() << "Found Monitor:"; //qDebug() << " Index:" << iter.index << "Rem:" << iter.rem; @@ -265,30 +296,33 @@ OutputDeviceList::OutputDeviceList(){ free(replyA); } //end loading of active/enabled monitors } //end loop over active/inactive monitors - - + */ + qDebug() << "========================="; //Now get the information about any **UNUSED** monitors/outputs - /*xcb_randr_get_screen_resources_reply_t *reply = xcb_randr_get_screen_resources_reply(QX11Info::connection(), + 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 outputnum = xcb_randr_get_screen_resources_outputs_length(reply); qDebug() << "Probing Screen Resources:"; qDebug() << " - Number of Outputs:" << outputnum; - qDebug() << " - Number of CRTC's:" << xcb_randr_get_screen_resources_crtcs_length(reply); - int mode_len =xcb_randr_get_screen_resources_modes_length(reply); - qDebug() << " - Modes:" << mode_len; - for(int m=0; m