summaryrefslogtreecommitdiffstats
path: root/src/widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget.cpp')
-rw-r--r--src/widget.cpp152
1 files changed, 114 insertions, 38 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 4254530..dda729a 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -6,6 +6,8 @@
#include <QSet>
#include <algorithm>
#include <iostream>
+#include "timeoutdialog.h"
+
//void setRefreshSpeed::on_okButton_clicked()
//{
@@ -212,12 +214,6 @@ Widget::Widget(QWidget *parent) :
break;
}
/*************************************************************************/
-
-
-
-
-
-
}
//___________________________________________________________________________
@@ -284,19 +280,21 @@ Widget::~Widget()
void Widget::handleButton()
{
-
-// QProcess p;
-// QStringList arguments;
-// arguments << "--output" << _outputMap[_monitor]->name
-// << "--mode" << _ui->comboBox->currentText()
-// << "--output" << _outputMap[_beamer]->name
-// << "--mode" << _ui->comboBox->currentText()
-// << "--same-as" <<_outputMap[_monitor]->name;
-
-// p.start("xrandr", arguments);
-// p.waitForFinished();
-
- XGrabServer(_display);
+ // Backup the crtcinfos
+ CrtcMap backup;
+ for ( CrtcMap::iterator it = _crtcMap.begin();
+ it != _crtcMap.end(); ++it ) {
+ backup[it.key()] = new XRRCrtcInfo;
+ backup[it.key()]->x = it.value()->x;
+ backup[it.key()]->y = it.value()->y;
+ backup[it.key()]->mode = it.value()->mode;
+ backup[it.key()]->rotation = it.value()->rotation;
+ backup[it.key()]->noutput = it.value()->noutput;
+ backup[it.key()]->outputs = new RROutput[it.value()->noutput];
+ for (int i = 0; i < it.value()->noutput; ++i) {
+ backup[it.key()]->outputs[i] = it.value()->outputs[i];
+ }
+ }
// First get a useful representation
unsigned int width, height;
@@ -317,20 +315,12 @@ void Widget::handleButton()
m2 = _modeMap[_outputMap[_beamer]->modes[i]]->id;
}
- qDebug() << _modeMap[m1]->width << _modeMap[m1]->height;
- qDebug() << _modeMap[m2]->width << _modeMap[m2]->height;
-
-
-
- /* values from xrandr */
- float dpi = (25.4 * DisplayHeight(_display, 0)) / DisplayHeightMM(_display, 0);
- int widthMM = (int) ((25.4 * width) / dpi);
- int heightMM = (int) ((25.4 * height) / dpi);
-
// Set screensize
XRRSetScreenSize(_display, DefaultRootWindow(_display),
- width, height,
- widthMM, heightMM);
+ 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,
@@ -340,8 +330,7 @@ void Widget::handleButton()
0, 0,
m1,
RR_Rotate_0,
- &_monitor,
- 1);
+ &_monitor, 1);
XRRSetCrtcConfig(_display,
_screenResources,
@@ -350,13 +339,100 @@ void Widget::handleButton()
0, 0,
m2,
RR_Rotate_0,
- &_beamer,
- 1);
+ &_beamer, 1);
+
+// // Apply the change
+// QProcess p;
+// QStringList arguments;
+// arguments << "--output" << _outputMap[_monitor]->name
+// << "--mode" << _ui->comboBox->currentText()
+// << "--output" << _outputMap[_beamer]->name
+// << "--mode" << _ui->comboBox->currentText()
+// << "--same-as" <<_outputMap[_monitor]->name;
+// p.start("xrandr", arguments);
+// p.waitForFinished();
- XUngrabServer(_display);
+// // First get a useful representation
+// unsigned int width, height;
+// QStringList modeAsStrings = _ui->comboBox->currentText().split("x", QString::SkipEmptyParts);
+// width = modeAsStrings.at(0).toInt();
+// height = modeAsStrings.at(1).toInt();
// Center dialog on screenbottom
- this->move( width/2 - this->width()/2,
- height - this->height());
+
+ // Center dialog on screenbottom
+ const QRect desktopRect = QApplication::desktop()->screenGeometry();
+ this->move( desktopRect.width()/2-this->width()/2,
+ desktopRect.height()-this->height());
+
+ // Show a dialog asking if the res should be kept
+ TimeOutDialog *t = new TimeOutDialog(5, this);
+ t->setWindowModality(Qt::WindowModal);
+ t->setLabelText("Keep resolution?");
+ t->setCancelButtonText("Keep");
+ t->exec();
+
+ // If the dialog was not canceled revert the resolution
+ if ( ! t->wasCanceled()) {
+
+ // First disconnect all crts to avoid conflicts
+ for ( CrtcMap::iterator it = _crtcMap.begin();
+ it != _crtcMap.end(); ++it ) {
+ XRRSetCrtcConfig(_display,
+ _screenResources,
+ it.key(),
+ CurrentTime,
+ 0, 0,
+ None,
+ RR_Rotate_0,
+ NULL, 0);
+ }
+
+ // Then calc backed up screensize
+ QSize ScreenSize(0,0);
+ for ( CrtcMap::iterator it = backup.begin();
+ it != backup.end(); ++it ) {
+ ScreenSize.setWidth(
+ std::max((uint)ScreenSize.width(),
+ it.value()->x+_modeMap[it.value()->mode]->width));
+ ScreenSize.setHeight(
+ std::max((uint)ScreenSize.height(),
+ it.value()->y+_modeMap[it.value()->mode]->height));
+ }
+
+ // Set screensize
+ XRRSetScreenSize(_display, DefaultRootWindow(_display),
+ ScreenSize.width(),
+ ScreenSize.height(),
+ 25.4 * ScreenSize.width() / 96, // standard dpi that X uses
+ 25.4 * ScreenSize.height() / 96); // standard dpi that X uses
+
+ // Then apply the backup
+ for ( CrtcMap::iterator it = backup.begin();
+ it != backup.end(); ++it ) {
+ XRRSetCrtcConfig(_display,
+ _screenResources,
+ it.key(),
+ CurrentTime,
+ it.value()->x,
+ it.value()->y,
+ it.value()->mode,
+ it.value()->rotation,
+ it.value()->outputs,
+ it.value()->noutput);
+ }
+
+ const QRect desktopRect = QApplication::desktop()->screenGeometry();
+ this->move( desktopRect.width()/2-this->width()/2,
+ desktopRect.height()-this->height());
+
+ } // End of Revert section
+
+ // Delete the backup
+ for ( CrtcMap::iterator it = backup.begin();
+ it != backup.end(); ++it ) {
+ delete[] it.value()->outputs;
+ delete it.value();
+ }
}