diff options
author | Manuel Schneider | 2013-12-02 21:23:39 +0100 |
---|---|---|
committer | Manuel Schneider | 2013-12-02 21:23:39 +0100 |
commit | dc34d29ba4fe28739c14bbff29c5fbcc6a7d4bc3 (patch) | |
tree | b0612294d61f77f9a91cfbb28e9f19889efb975e /src | |
parent | Debug stuff (diff) | |
download | beamergui-dc34d29ba4fe28739c14bbff29c5fbcc6a7d4bc3.tar.gz beamergui-dc34d29ba4fe28739c14bbff29c5fbcc6a7d4bc3.tar.xz beamergui-dc34d29ba4fe28739c14bbff29c5fbcc6a7d4bc3.zip |
Segfault fixed. Exclude interlaced modes
Diffstat (limited to 'src')
-rw-r--r-- | src/widget.cpp | 193 |
1 files changed, 102 insertions, 91 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index 3e31dbb..4875dfd 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -71,89 +71,90 @@ Widget::Widget(QWidget *parent) : } - // Get the ip adress of the interface - struct ifaddrs * ifAddrStruct=NULL; - struct ifaddrs * ifa=NULL; - void * tmpAddrPtr=NULL; - QString ipV4; - qDebug() << "Ip is" << ipV4; - getifaddrs(&ifAddrStruct); - // Iterate through the adresses. - for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { - // If the address is IP V4 and the interface is _if - if (ifa ->ifa_addr->sa_family==AF_INET - && ( strcmp(ifa->ifa_name, INTERFACE) == 0) ) { - // Get the IP - tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; - // convert to readable form - char addressBuffer[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); - ipV4 = addressBuffer; - } - } - // clean up - if (ifAddrStruct!=NULL) - freeifaddrs(ifAddrStruct); - - // Open Qsettings file - QSettings settings(QCoreApplication::arguments()[1], QSettings::NativeFormat); - - // Find any information saved about this ip. This config is assumed - // to be tested on this system and will be applied immediately. - settings.beginGroup(GROUP_SPECIFIC); - if ( settings.contains(ipV4) ) { - // First get a useful representation - unsigned int width, height; - QStringList modeAsStrings = - settings.value(ipV4) - .toString().split("x", QString::SkipEmptyParts); - qDebug() << "Found Ip setting" << modeAsStrings; - width = modeAsStrings.at(0).toInt(); - height = modeAsStrings.at(1).toInt(); - - // Find a mode that matches the string - // No sanity check here as the modes have to exist and be tested - RRMode m1,m2; - for (int i = 0; i < _outputMap[_monitor]->nmode; ++i){ - if ( width == _modeMap[_outputMap[_monitor]->modes[i]]->width - && height == _modeMap[_outputMap[_monitor]->modes[i]]->height ) - m1 = _modeMap[_outputMap[_monitor]->modes[i]]->id; - } - for (int i = 0; i < _outputMap[_beamer]->nmode; ++i){ - if ( width == _modeMap[_outputMap[_beamer]->modes[i]]->width - && height == _modeMap[_outputMap[_beamer]->modes[i]]->height ) - m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id; - } - - // Set screensize - XRRSetScreenSize(_display, DefaultRootWindow(_display), - width, - height, - 25.4 * width / 96, // standard dpi that X uses - 25.4 * height / 96); // standard dpi that X uses +// /opt/openslx/config +// // Get the ip adress of the interface +// struct ifaddrs * ifAddrStruct=NULL; +// struct ifaddrs * ifa=NULL; +// void * tmpAddrPtr=NULL; +// QString ipV4; +// qDebug() << "Ip is" << ipV4; +// getifaddrs(&ifAddrStruct); +// // Iterate through the adresses. +// for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { +// // If the address is IP V4 and the interface is _if +// if (ifa ->ifa_addr->sa_family==AF_INET +// && ( strcmp(ifa->ifa_name, INTERFACE) == 0) ) { +// // Get the IP +// tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; +// // convert to readable form +// char addressBuffer[INET_ADDRSTRLEN]; +// inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); +// ipV4 = addressBuffer; +// } +// } +// // clean up +// if (ifAddrStruct!=NULL) +// freeifaddrs(ifAddrStruct); + +// // Open Qsettings file +// QSettings settings(QCoreApplication::arguments()[1], QSettings::NativeFormat); + +// // Find any information saved about this ip. This config is assumed +// // to be tested on this system and will be applied immediately. +// settings.beginGroup(GROUP_SPECIFIC); +// if ( settings.contains(ipV4) ) { +// // First get a useful representation +// unsigned int width, height; +// QStringList modeAsStrings = +// settings.value(ipV4) +// .toString().split("x", QString::SkipEmptyParts); +// qDebug() << "Found Ip setting" << modeAsStrings; +// width = modeAsStrings.at(0).toInt(); +// height = modeAsStrings.at(1).toInt(); + +// // Find a mode that matches the string +// // No sanity check here as the modes have to exist and be tested +// RRMode m1,m2; +// for (int i = 0; i < _outputMap[_monitor]->nmode; ++i){ +// if ( width == _modeMap[_outputMap[_monitor]->modes[i]]->width +// && height == _modeMap[_outputMap[_monitor]->modes[i]]->height ) +// m1 = _modeMap[_outputMap[_monitor]->modes[i]]->id; +// } +// for (int i = 0; i < _outputMap[_beamer]->nmode; ++i){ +// if ( width == _modeMap[_outputMap[_beamer]->modes[i]]->width +// && height == _modeMap[_outputMap[_beamer]->modes[i]]->height ) +// m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id; +// } - // Apply the modes - XRRSetCrtcConfig(_display, - _screenResources, - _outputMap[_monitor]->crtc, - CurrentTime, - 0, 0, - m1, - RR_Rotate_0, - &_monitor, 1); - - XRRSetCrtcConfig(_display, - _screenResources, - _outputMap[_beamer]->crtc, - CurrentTime, - 0, 0, - m2, - RR_Rotate_0, - &_beamer, 1); +// // Set screensize +// XRRSetScreenSize(_display, DefaultRootWindow(_display), +// width, +// height, +// 25.4 * width / 96, // standard dpi that X uses +// 25.4 * height / 96); // standard dpi that X uses + +// // Apply the modes +// XRRSetCrtcConfig(_display, +// _screenResources, +// _outputMap[_monitor]->crtc, +// CurrentTime, +// 0, 0, +// m1, +// RR_Rotate_0, +// &_monitor, 1); + +// XRRSetCrtcConfig(_display, +// _screenResources, +// _outputMap[_beamer]->crtc, +// CurrentTime, +// 0, 0, +// m2, +// RR_Rotate_0, +// &_beamer, 1); - } - settings.endGroup(); +// } +// settings.endGroup(); // Check if the beamer transmitted reliable data. bool gotEDID = false; @@ -163,8 +164,10 @@ Widget::Widget(QWidget *parent) : char *atom_name = XGetAtomName (_display, props[i]); if ( strcmp (atom_name, "EDID") == 0) { gotEDID = true; + XFree (atom_name); break; } + XFree (atom_name); } free(props); @@ -182,11 +185,12 @@ Widget::Widget(QWidget *parent) : // p.waitForFinished(); // } + // Get the names of the modes and intersect QSet<XRRModeInfo*> beamerModes, monitorModes; for (int i = 0; i < _outputMap[_beamer]->nmode; ++i) beamerModes.insert(_modeMap[_outputMap[_beamer]->modes[i]]); - for (int i = 0; i < _outputMap[_beamer]->nmode; ++i) + for (int i = 0; i < _outputMap[_monitor]->nmode; ++i) monitorModes.insert(_modeMap[_outputMap[_monitor]->modes[i]]); // Intersect them by the resolution sorted @@ -194,8 +198,10 @@ Widget::Widget(QWidget *parent) : QList<XRRModeInfo*> commonModes; for (QSet<XRRModeInfo*>::iterator i = beamerModes.begin(); i != beamerModes.end(); ++i) { + if ((*i)->modeFlags & RR_Interlace) continue; for (QSet<XRRModeInfo*>::iterator j = monitorModes.begin(); j != monitorModes.end(); ++j) { + if ((*j)->modeFlags & RR_Interlace) continue; QList<XRRModeInfo*>::iterator k = commonModes.begin(); for (;;) { if (k == commonModes.end()){ @@ -370,6 +376,7 @@ Widget::~Widget() XRRFreeScreenResources(_screenResources); } +//___________________________________________________________________________ void Widget::handleButton() { // Backup the crtcinfos @@ -397,16 +404,19 @@ void Widget::handleButton() height = modeAsStrings.at(1).toInt(); // Find a mode that matches the string - qDebug() << "// Find a mode that matches the string"; RRMode m1,m2; + qDebug() << "// Find a mode that matches the string"; for (int i = 0; i < _outputMap[_monitor]->nmode; ++i){ if ( width == _modeMap[_outputMap[_monitor]->modes[i]]->width - && height == _modeMap[_outputMap[_monitor]->modes[i]]->height ) + && height == _modeMap[_outputMap[_monitor]->modes[i]]->height + && !(_modeMap[_outputMap[_monitor]->modes[i]]->modeFlags & RR_Interlace) ) // skip interlaced modes m1 = _modeMap[_outputMap[_monitor]->modes[i]]->id; } + qDebug() << "// Find a mode that matches the string"; for (int i = 0; i < _outputMap[_beamer]->nmode; ++i){ if ( width == _modeMap[_outputMap[_beamer]->modes[i]]->width - && height == _modeMap[_outputMap[_beamer]->modes[i]]->height ) + && height == _modeMap[_outputMap[_beamer]->modes[i]]->height + && !(_modeMap[_outputMap[_beamer]->modes[i]]->modeFlags & RR_Interlace) ) // skip interlaced modes m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id; } @@ -441,19 +451,20 @@ void Widget::handleButton() // Show a dialog asking if the res should be kept qDebug() << "// Show a dialog asking if the res should be kept"; - TimeOutDialog *t = new TimeOutDialog(15, this); - t->setWindowTitle(" "); - t->setLabelText("Do you want to keep this resolution?"); - t->setCancelButtonText("Keep"); - t->exec(); + TimeOutDialog *keepDialog = new TimeOutDialog(15, this); + keepDialog->setWindowTitle(" "); + keepDialog->setLabelText("Do you want to keep this resolution?"); + keepDialog->setCancelButtonText("Keep"); // Center the dialog qDebug() << "// Center the dialog"; - t->move( width/2 - this->width()/2, height/2 - this->height()); + keepDialog->move( width/2 - this->width()/2, height/2 - this->height()); + + keepDialog->exec(); // If the dialog was not canceled revert the resolution qDebug() << "// If the dialog was not canceled revert the resolution"; - if ( ! t->wasCanceled()) { + if ( ! keepDialog->wasCanceled()) { // First disconnect all crts to avoid conflicts qDebug() << "// First disconnect all crts to avoid conflicts"; |