summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xXModeSetter.sh42
-rw-r--r--src/beamergui.pro7
-rw-r--r--src/timeoutdialog.cpp40
-rw-r--r--src/timeoutdialog.h26
-rw-r--r--src/widget.cpp152
-rw-r--r--src/widget.h4
6 files changed, 229 insertions, 42 deletions
diff --git a/XModeSetter.sh b/XModeSetter.sh
new file mode 100755
index 0000000..ae81b28
--- /dev/null
+++ b/XModeSetter.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# List all modes
+declare -a MODES
+#16:10
+MODES=("${MODES[@]}" "1280x800 83.50 1280 1352 1480 1680 800 803 809 831 -hsync +vsync")
+MODES=("${MODES[@]}" "1440x1050 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync")
+MODES=("${MODES[@]}" "1680x1200 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync")
+MODES=("${MODES[@]}" "1920x1200 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync")
+MODES=("${MODES[@]}" "2560x1600 348.50 2560 2760 3032 3504 1600 1603 1609 1658 -hsync +vsync")
+#16:9
+MODES=("${MODES[@]}" "1280x720 74.50 1280 1344 1472 1664 720 723 728 748 -hsync +vsync")
+MODES=("${MODES[@]}" "1368x768 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync")
+MODES=("${MODES[@]}" "1600x900 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync")
+MODES=("${MODES[@]}" "1920x1080 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync")
+MODES=("${MODES[@]}" "2560x1440 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync")
+#4:3
+MODES=("${MODES[@]}" "800x600 38.25 800 832 912 1024 600 603 607 624 -hsync +vsync")
+MODES=("${MODES[@]}" "1024x768 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync")
+MODES=("${MODES[@]}" "1152x864 81.75 1152 1216 1336 1520 864 867 871 897 -hsync +vsync")
+MODES=("${MODES[@]}" "1280x960 101.25 1280 1360 1488 1696 960 963 967 996 -hsync +vsync")
+MODES=("${MODES[@]}" "1400x1050 121.75 1400 1488 1632 1864 1050 1053 1057 1089 -hsync +vsync")
+
+# Create all modes
+for i in "${MODES[@]}"; do
+ #echo -e "\e[32mxrandr --current --newmode $i\e[0m"
+ xrandr --current --newmode $i > /dev/null 2>&1
+done
+
+# Get the connected outputs
+declare -a OUTPUTNAMES
+while read line; do
+ OUTPUTNAMES+=("$(echo "$line" | grep -o "^\S*" )")
+done < <( xrandr | grep -i " connected" )
+
+# Add the modes to all outputs
+for i in "${OUTPUTNAMES[@]}"; do
+ for j in "${MODES[@]}"; do
+ #echo -e "\e[32mxrandr --current --addmode $i $(echo $j| awk '{print $1;}')\e[0m"
+ xrandr --current --addmode $i $(echo $j| awk '{print $1;}')
+ done
+done
diff --git a/src/beamergui.pro b/src/beamergui.pro
index 6c1fbdc..6d72436 100644
--- a/src/beamergui.pro
+++ b/src/beamergui.pro
@@ -13,14 +13,15 @@ TEMPLATE = app
SOURCES += main.cpp\
widget.cpp \
config.cpp \
- x.cpp
+ timeoutdialog.cpp
HEADERS += widget.h \
- displaymanager.h \
config.h \
- x.h
+ timeoutdialog.h
FORMS += widget.ui
LIBS += -lXrandr -lX11
+
+RESOURCES +=
diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp
new file mode 100644
index 0000000..5a76504
--- /dev/null
+++ b/src/timeoutdialog.cpp
@@ -0,0 +1,40 @@
+#include "timeoutdialog.h"
+#include <iostream>
+#include <QProgressBar>
+
+
+TimeOutDialog::TimeOutDialog(int time, QWidget *parent)
+ : QProgressDialog(parent), _time(time)
+{
+ QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
+ QObject::connect(this, SIGNAL(canceled()), this, SLOT(cancel()));
+
+
+ // QProgressDialog takes ownership of QProgressBar
+ QProgressBar *qbar = new QProgressBar(this);
+ qbar->setFormat("%v seconds");
+ qbar->setMaximum(_time);
+ qbar->setMinimum(0);
+ qbar->setValue(_time);
+ qbar->setLayoutDirection(Qt::RightToLeft);
+ setBar(qbar);
+ _timer.start(1000);
+}
+
+//___________________________________________________________________________
+void TimeOutDialog::update()
+{
+ if (_time == 0) {
+ _timer.stop();
+ accept();
+ }
+ else
+ setValue(_time);
+ --_time;
+}
+
+//___________________________________________________________________________
+void TimeOutDialog::cancel()
+{
+ _timer.stop();
+}
diff --git a/src/timeoutdialog.h b/src/timeoutdialog.h
new file mode 100644
index 0000000..643b593
--- /dev/null
+++ b/src/timeoutdialog.h
@@ -0,0 +1,26 @@
+#ifndef TIMEOUTDIALOG_H
+#define TIMEOUTDIALOG_H
+
+#include <QtGui/QApplication>
+#include <QProgressDialog>
+#include <QTimer>
+
+class TimeOutDialog : public QProgressDialog
+{
+ Q_OBJECT
+
+ public:
+ TimeOutDialog(int time, QWidget *parent = 0);
+
+ private:
+ int _time;
+ QTimer _timer;
+
+ public slots:
+ void cancel();
+
+ private slots:
+ void update();
+};
+
+#endif // TIMEOUTDIALOG_H
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();
+ }
}
diff --git a/src/widget.h b/src/widget.h
index 5df8ab5..ad3077a 100644
--- a/src/widget.h
+++ b/src/widget.h
@@ -4,8 +4,10 @@
#include <QWidget>
#include <QtGui>
#include <QDebug>
+#include <QProgressDialog>
#include <x.h>
+
namespace Ui {
class Widget;
}
@@ -36,6 +38,7 @@ public:
private:
void updateScreenResources();
+ void timeout();
Ui::Widget * _ui;
Display* _display;
@@ -45,7 +48,6 @@ private:
OutputMap _outputMap;
OutputList _connectedOutputList;
RROutput _beamer, _monitor;
-
};
#endif // WIDGET_H