diff options
author | Manuel Schneider | 2014-04-08 12:17:53 +0200 |
---|---|---|
committer | Manuel Schneider | 2014-04-08 12:17:53 +0200 |
commit | 56f8876e57f5d3c3dd0a384850bb77bcff116e0a (patch) | |
tree | d4da3dda4b1451a91eb206919f7422299b755661 | |
parent | moved conf to slx configs (diff) | |
download | beamergui-56f8876e57f5d3c3dd0a384850bb77bcff116e0a.tar.gz beamergui-56f8876e57f5d3c3dd0a384850bb77bcff116e0a.tar.xz beamergui-56f8876e57f5d3c3dd0a384850bb77bcff116e0a.zip |
[beamergui] Removed the need of a configfile in beamergui, because it is handled in Xsetup stage now.
-rw-r--r-- | src/main.cpp | 24 | ||||
-rw-r--r-- | src/widget.cpp | 209 | ||||
-rw-r--r-- | src/widget.h | 2 |
3 files changed, 122 insertions, 113 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0a54d52..6a5fa7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,18 +8,18 @@ int main(int argc, char *argv[]) { - if (argc != 2) { - std::cout << "Usage: " << argv[0] << " <config file>" << std::endl; - } else { - // Check if file exists - std::ifstream f(argv[1]); - if (!f) { - std::cerr << "The config file does not exist." << std::endl; - exit(1); - } - else - f.close(); - } + //if (argc != 2) { + // std::cout << "Usage: " << argv[0] << " <config file>" << std::endl; + //} else { + // // Check if file exists + // std::ifstream f(argv[1]); + // if (!f) { + // std::cerr << "The config file does not exist." << std::endl; + // exit(1); + // } + // else + // f.close(); + //} QApplication a(argc, argv); Widget w; diff --git a/src/widget.cpp b/src/widget.cpp index bd9ab49..d7a2ff5 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -7,6 +7,7 @@ #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> +#include <math.h> #include <iostream> #include <algorithm> @@ -34,11 +35,11 @@ Widget::Widget(QWidget *parent) : { _ui->setupUi(this); - // Get initial data (to be freed) _display = XOpenDisplay(NULL); - _screenResources = XRRGetScreenResourcesCurrent(_display, - DefaultRootWindow(_display)); + _screenResources = XRRGetScreenResourcesCurrent( + _display, + DefaultRootWindow(_display)); // Get the information about the X elements updateScreenResources(); @@ -79,102 +80,11 @@ Widget::Widget(QWidget *parent) : } else { _beamer = _connectedOutputList[1]; _monitor = _connectedOutputList[0]; - } - // 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; - } - - qDebug() << "Found modes are" << m1 << m2; - qDebug() << "Witdth" << width ; - qDebug() << "Height" << height ; - - // 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(); + // Deprecated, will be deleted after confirmation from above + //setResFromConfig(); - 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 * height / 96); // standard dpi that X uses -// -// // Apply the modes -// 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; @@ -294,7 +204,7 @@ Widget::Widget(QWidget *parent) : for ( QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator i = commonModes.begin(); i != commonModes.end(); ++i ) { float modeAspectRatio = ((float)i->first->width / i->first->height); - if ( modeAspectRatio == aspectRatio ) // TODO APPROX + if ( abs(modeAspectRatio - aspectRatio) < 0.05 ) // APPROX _ui->comboBox->addItem(i->first->name, QList<QVariant>() << QVariant((qulonglong)i->first->id) @@ -340,7 +250,7 @@ Widget::Widget(QWidget *parent) : /*********************************************************************/ // If NEITHER of the outputs is a beamer (likely dualscreen setup) else { - // TODO(manuel): Furture feature. Setup dualscreen + // TODO(manuel): Future feature. Setup dualscreen qDebug() << "Dual output"; exit(0); } @@ -414,13 +324,110 @@ void Widget::updateScreenResources() } //___________________________________________________________________________ -Widget::~Widget() -{ +Widget::~Widget() { delete _ui; XCloseDisplay(_display); XRRFreeScreenResources(_screenResources); } +//// Deprecated, will be deleted after confirmation from above +////___________________________________________________________________________ +//void Widget::setResFromConfig() { +// // 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; +// } +// +// qDebug() << "Found modes are" << m1 << m2; +// qDebug() << "Witdth" << width ; +// qDebug() << "Height" << height ; +// +// // 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 * height / 96); // standard dpi that X uses +//// +//// // Apply the modes +//// 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(); +//} + //___________________________________________________________________________ void Widget::handleButton() { @@ -435,7 +442,7 @@ void Widget::handleButton() backup[it.key()]->x = it.value()->x; backup[it.key()]->y = it.value()->y; backup[it.key()]->mode = it.value()->mode; - qDebug() << " Moed is " << backup[it.key()]->mode; + qDebug() << " Mode is " << backup[it.key()]->mode; backup[it.key()]->rotation = it.value()->rotation; backup[it.key()]->noutput = it.value()->noutput; backup[it.key()]->outputs = new RROutput[it.value()->noutput]; diff --git a/src/widget.h b/src/widget.h index b80f714..83404ac 100644 --- a/src/widget.h +++ b/src/widget.h @@ -41,6 +41,8 @@ public: private: void updateScreenResources(); + // Deprecated, will be deleted after confirmation from above + //void setResFromConfig(); void timeout(); Ui::Widget * _ui; |