diff options
-rw-r--r-- | src/widget.cpp | 192 |
1 files changed, 116 insertions, 76 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index cc7fd97..bd9ab49 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -21,6 +21,8 @@ #define INTERFACE "eth0" #define GROUP_SPECIFIC "SpecificSettings" +#define OPENSLXCONFIG "/opt/openslx/config" +#define OPENSLXCONFIG_IPKEY "SLX_PXE_CLIENT_IP" //#define DEBUG @@ -80,89 +82,99 @@ Widget::Widget(QWidget *parent) : } -// /opt/openslx/config + // Try to get the ip of the machine + QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat); + QString IP; + if ( SLXsettings.contains(OPENSLXCONFIG_IPKEY) ) { + IP = SLXsettings.value(OPENSLXCONFIG_IPKEY).toString(); + qDebug() << "IP is" << IP; + } else + qDebug() << "No IP found!"; + + // remove the ' around the ip + IP.remove('\''); + + // Try to get beamer config related to the ip of the machine + 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(IP) ) { + // First get a useful representation + unsigned int width, height; + QStringList modeAsStrings = + settings.value(IP) + .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; + } -// // 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); + qDebug() << "Found modes are" << m1 << m2; + qDebug() << "Witdth" << width ; + qDebug() << "Height" << height ; -// // 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 mode via xrandr + QProcess p; + QStringList arguments; + arguments << "--output" << _outputMap[_monitor]->name + << "--mode" << settings.value(IP).toString() + << "--output" << _outputMap[_beamer]->name + << "--mode" << settings.value(IP).toString() + << "--same-as" <<_outputMap[_monitor]->name; + qDebug() << arguments ; + + p.start("xrandr", arguments); + p.waitForFinished(); + qDebug() << p.readAllStandardOutput(); + qDebug() << p.readAllStandardError(); + + +// // // Set screensize // XRRSetScreenSize(_display, DefaultRootWindow(_display), // width, // height, -// 25.4 * width / 96, // standard dpi that X uses +// 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(); +// qDebug() << "Apply mode m1 " << m1; +// qDebug() << XRRSetCrtcConfig(_display, +// _screenResources, +// _outputMap[_monitor]->crtc, +// CurrentTime, +// 0, 0, +// m1, +// RR_Rotate_0, +// &_monitor, 1); +// +// qDebug() << "Apply mode m2 " << m2; +// qDebug() << XRRSetCrtcConfig(_display, +// _screenResources, +// _outputMap[_beamer]->crtc, +// CurrentTime, +// 0, 0, +// m2, +// RR_Rotate_0, +// &_beamer, 1); + } + settings.endGroup(); // Check if the beamer transmitted reliable data. bool gotEDID = false; @@ -505,10 +517,10 @@ void Widget::handleButton() if ( it.value()->mode != None ) { ScreenSize.setWidth( std::max((uint)ScreenSize.width(), - it.value()->x+_modeMap.at(it.value()->mode)->width)); + it.value()->x+_modeMap[it.value()->mode]->width)); ScreenSize.setHeight( std::max((uint)ScreenSize.height(), - it.value()->y+_modeMap.at(it.value()->mode)->height)); + it.value()->y+_modeMap[it.value()->mode]->height)); } } qDebug() << "screensize is" << ScreenSize; @@ -669,3 +681,31 @@ void Widget::handleButton() // && !(_modeMap[_outputMap[_beamer]->modes[i]]->modeFlags & RR_Interlace) ) // skip interlaced modes // m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id; // } + + + + + + +// 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); |