summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Schneider2014-04-09 19:44:28 +0200
committerManuel Schneider2014-04-09 19:44:28 +0200
commit141451ea9f34d71d4255f323492cb463d96dd865 (patch)
treef3da5656e3dd393431fbcf9d78dcc810261bc36b
parent[beamergui] Removed the need of a configfile in beamergui, because it is hand... (diff)
downloadbeamergui-141451ea9f34d71d4255f323492cb463d96dd865.tar.gz
beamergui-141451ea9f34d71d4255f323492cb463d96dd865.tar.xz
beamergui-141451ea9f34d71d4255f323492cb463d96dd865.zip
[beamergui] Several changes
+ mouse position will be centered after changing the resolution. + fixed the bug with the positioning of the gui + fixed curious X async bug + deleted a lot of crap and old debug statements + current resolution will be highlighted
-rw-r--r--src/beamergui.pro6
-rw-r--r--src/main.cpp319
-rw-r--r--src/timeoutdialog.cpp4
-rw-r--r--src/timeoutdialog.h1
-rw-r--r--src/widget.cpp449
-rw-r--r--src/widget.h13
6 files changed, 102 insertions, 690 deletions
diff --git a/src/beamergui.pro b/src/beamergui.pro
index e8b5ab5..3ff480a 100644
--- a/src/beamergui.pro
+++ b/src/beamergui.pro
@@ -4,12 +4,13 @@
#
#-------------------------------------------------
-QT += core gui
+
+QT += core gui # qt4
+#QT += widgets # qt5
TARGET = beamergui
TEMPLATE = app
-
SOURCES += main.cpp\
widget.cpp \
timeoutdialog.cpp
@@ -19,7 +20,6 @@ HEADERS += widget.h \
FORMS += widget.ui
-
LIBS += -lXrandr -lX11
RESOURCES +=
diff --git a/src/main.cpp b/src/main.cpp
index 6a5fa7c..7c2daab 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,330 +1,15 @@
// Copyright 2013, University of Freiburg,
// Author: Manuel Schneider <ms1144>
-#include <QtGui/QApplication>
-#include <fstream>
-#include <iostream>
+#include <QtGui/QApplication> // for Qt4
#include "widget.h"
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();
- //}
-
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
-
-
-
-////////////////////////////////////////// CODE MÜLLEIMER
-
-
- // eine datei
-
-
-//Widget::Widget(QWidget *parent) :
-// QWidget(parent),
-// ui(new Ui::Widget)
-//{
-// ui->setupUi(this);
-
-// for (std::vector<Output>::iterator i = DisplayManager::Inst()->getConnectedOutputs().begin();
-// i != DisplayManager::Inst()->getConnectedOutputs().end();
-// ++i)
-// {
-// qDebug() << "EDID?" << ( (*i).hasEDID() ? "true" : "false");
-// qDebug() << "Proj?" << ( (*i).isProjector() ? "true" : "false");
-// qDebug() << "Current?"
-// << DisplayManager::Inst()->getResolution((*i).getCurrentMode()).width
-// << DisplayManager::Inst()->getResolution((*i).getCurrentMode()).height;
-// Resolution res;
-// if ((*i).getPreferredMode())
-// qDebug() << "Preferred?"
-// << DisplayManager::Inst()->getResolution((*i).getPreferredMode()).width
-// << DisplayManager::Inst()->getResolution((*i).getPreferredMode()).height;
-
-// QSet<RRMode> modes = (*i).getSupportedModes();
-
-// for ( QSet<RRMode>::iterator i = modes.begin(); i != modes.end(); ++i )
-// {
-// qDebug() << "---- "
-// << DisplayManager::Inst()->getResolution(*i).width
-// << DisplayManager::Inst()->getResolution(*i).height;
-// }
-// }
-
-
-// switch ( DisplayManager::Inst()->getConnectedOutputs().size() ){
-// /*************************************************************************/
-// case 1:// In case of one connected output - xrandr --auto
-// qDebug() << "Normal output";
-// exit(0);
-// break;
-// /*************************************************************************/
-// case 2: // In case of two connected outputs
-
-// /*********************************************************************/
-// // If one of the two connected outputs is a beamer
-
-// if ( true)//DisplayManager::Inst()->isProjectorConnected() )
-// {
-// /*
-// Here the usecases have to be listed theoretically there are two
-// in this case. 2 Projectors, 1 projectors and on monitor. Only the
-// latter is asumed here.
-// */
-
-// // Remember which one is the projector
-// int ProjectorIndex;
-// DisplayManager::Inst()->getConnectedOutputs().at(0).isProjector()
-// ? ProjectorIndex = 0 : ProjectorIndex = 0;
-
-// /*****************************************************************/
-// // If the beamer transmits reliable EDID data.
-// if( DisplayManager::Inst()->getConnectedOutputs().at(ProjectorIndex).hasEDID() )
-// {
-// // Now we can assume that the preferred mode of the projector to be correnct
-// // to be correct.
-
-// // Get the AR of the beamer
-// Resolution res;
-// if ( DisplayManager::Inst()->getConnectedOutputs().at(ProjectorIndex).getPreferredMode() )
-// fprintf(stderr, "Beamer has EDID but no preferred mode.");
-
-// float AR = res.width/res.height;
-
-// QSet<RRMode> BeamerModes =
-// DisplayManager::Inst()->getConnectedOutputs().at(ProjectorIndex).getSupportedModes();
-
-// QSet<RRMode> MonitorModes =
-// DisplayManager::Inst()->getConnectedOutputs().at(1-ProjectorIndex).getSupportedModes();
-
-// QSet<RRMode> CommonModes = BeamerModes.unite(MonitorModes);
-
-// CommonModes.intersect(BeamerModes);
-// CommonModes.intersect(MonitorModes);
-
-// // Fill treewidget with data from cups dests;
-// for ( QSet<RRMode>::iterator i = CommonModes.begin(); i != CommonModes.end(); ++i )
-// {
-// char * ModeString;
-// sprintf(ModeString, "%dx%d",
-// DisplayManager::Inst()->getResolution(*i).width,
-// DisplayManager::Inst()->getResolution(*i).height
-// );
-
-// qDebug() << ModeString;
-// ui->comboBox->addItem(ModeString, QVariant((unsigned long long int)*i));
-// }
-// }
-// /*****************************************************************/
-// // If the beamer DOES NOT transmits reliable EDID data.
-// else
-// {
-// qDebug() << "beamer output no reliable EDID ";
-// configureWidgetForBeamerWithEDID();
-// }
-// /*****************************************************************/
-
-// }
-// /*********************************************************************/
-// // If NEITHER of the outputs is a beamer (likely dualscreen setup)
-// else
-// {
-// // Just apply preferred settings
-
-// qDebug() << "dualscreen output";
-
-// }
-// break;
-// /*************************************************************************/
-// default:
-// // If there are more than 3 outputs
-// // its up to the user. Quit.
-// exit(0);
-// break;
-// }
-// /*************************************************************************/
-
-
-
-
-
-
-// //Remove borders and stuff
-// setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
-
-
-
-
-// // QSet<RRMode> outputs0, outputs1;
-// // for (int i = 0; i < XManager::Inst()->getOutputInfos()[0]->nmode; ++i)
-// // outputs0.insert(XManager::Inst()->getOutputInfos()[0]->modes[i]);
-// // for (int i = 0; i < XManager::Inst()->getOutputInfos()[1]->nmode; ++i)
-// // outputs1.insert(XManager::Inst()->getOutputInfos()[1]->modes[i]);
-// // outputs0.intersect(outputs1);
-
-// // // Fill treewidget with data from cups dests;
-// // for ( QSet<RRMode>::iterator it = outputs0.begin(); it != outputs0.end(); ++it )
-// // {
-// // qDebug() << *it;
-// // qDebug() << XManager::Inst()->getModeMap()[*it];
-// // ui->comboBox->addItem(XManager::Inst()->getModeMap().at(*it), (unsigned long long int)*it);
-// // }
-
-// // // Fill treewidget with data from cups dests;
-// // for ( map<XID, char *>::iterator it = XManager::Inst()->getModeMap().begin(); it != XManager::Inst()->getModeMap().end(); ++it )
-// // {
-// // qDebug() << it->first ;
-// //// qDebug() << XManager::getInstance()->getModeMap()[*it];
-// //// ui->comboBox->addItem(XManager::getInstance()->getModeMap().at(*it), (unsigned long long int)*it);
-// // }
-
-// // Resize widget to its content
-// resize(sizeHint());
-
-// // Center dialog on screenbottom
-// const QRect desktopRect = QApplication::desktop()->screenGeometry();
-// this->move( desktopRect.width()/2-this->width()/2,
-// desktopRect.height()-this->height());
-// }
-
-// Widget::~Widget()
-// {
-// delete ui;
-// }
-
-// void Widget::configureWidgetForBeamerWithEDID()
-// {
-// }
-
-// void Widget::configureWidgetForBeamerWithOUTEDID()
-// {
-// }
-
-
-
-
-
- // eine andre datei
-
-
-
-
-
-
-//Widget::Widget(QWidget *parent) :
-// QWidget(parent),
-// ui(new Ui::Widget)
-//{
-// ui->setupUi(this);
-
-
-// X11::XManager * XM = X11::XManager::getInstance();
-
-
-// switch ( XM->getOutputInfos().size() ){
-// /*************************************************************************/
-// case 1:// In case of one connected output - xrandr --auto
-// qDebug() << "Normal output";
-// exit(0);
-// break;
-// /*************************************************************************/
-// case 2: // In case of two connected outputs
-
-// /*********************************************************************/
-// // If one of the two connected outputs is a beamer
-// if ( true ) //( XM->getOutputInfos()[0]->mm_width == 0 && XM->getOutputInfos()[0]->mm_height == 0 )
-// // || ( XM->getOutputInfos()[1]->mm_width == 0 && XM->getOutputInfos()[1]->mm_height == 0 ) )
-// {
-// /*****************************************************************/
-// // If the beamer transmits reliable EDID data.
-// if( isReliableEDIDpresent() )
-// {
-// qDebug() << "beamer output reliable EDID ";
-// configureWidgetForBeamerWithEDID();
-// }
-// /*****************************************************************/
-// // If the beamer DOES NOT transmits reliable EDID data.
-// else
-// {
-// qDebug() << "beamer output no reliable EDID ";
-// configureWidgetForBeamerWithEDID();
-// }
-// /*****************************************************************/
-
-// }
-// /*********************************************************************/
-// // If NEITHER of the outputs is a beamer (likely dualscreen setup)
-// else
-// {
-// // Just apply preferred settings
-// qDebug() << "dualscreen output";
-
-// }
-// break;
-// /*************************************************************************/
-// default:
-// // If there are more than 3 outputs
-// // its up to the user. Quit.
-// exit(0);
-// break;
-// }
-// /*************************************************************************/
-
-
-
-
-// Remove borders and stuff
-// setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
-
-
-
-
-// QSet<RRMode> outputs0, outputs1;
-// for (int i = 0; i < XManager::Inst()->getOutputInfos()[0]->nmode; ++i)
-// outputs0.insert(XManager::Inst()->getOutputInfos()[0]->modes[i]);
-// for (int i = 0; i < XManager::Inst()->getOutputInfos()[1]->nmode; ++i)
-// outputs1.insert(XManager::Inst()->getOutputInfos()[1]->modes[i]);
-// outputs0.intersect(outputs1);
-
-// // Fill treewidget with data from cups dests;
-// for ( QSet<RRMode>::iterator it = outputs0.begin(); it != outputs0.end(); ++it )
-// {
-// qDebug() << *it;
-// qDebug() << XManager::Inst()->getModeMap()[*it];
-// ui->comboBox->addItem(XManager::Inst()->getModeMap().at(*it), (unsigned long long int)*it);
-// }
-
-// // Fill treewidget with data from cups dests;
-// for ( map<XID, char *>::iterator it = XManager::Inst()->getModeMap().begin(); it != XManager::Inst()->getModeMap().end(); ++it )
-// {
-// qDebug() << it->first ;
-//// qDebug() << XManager::getInstance()->getModeMap()[*it];
-//// ui->comboBox->addItem(XManager::getInstance()->getModeMap().at(*it), (unsigned long long int)*it);
-// }
-
-// // Resize widget to its content
-// resize(sizeHint());
-
-// // Center dialog on screenbottom
-// const QRect desktopRect = QApplication::desktop()->screenGeometry();
-// this->move( desktopRect.width()/2-this->width()/2,
-// desktopRect.height()-this->height());
-//}
-
-
+////////////////////////////////////////////////////////////////////////////////
diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp
index 8eb9aab..719fddd 100644
--- a/src/timeoutdialog.cpp
+++ b/src/timeoutdialog.cpp
@@ -2,10 +2,8 @@
// Author: Manuel Schneider <ms1144>
#include "timeoutdialog.h"
-#include <iostream>
#include <QProgressBar>
-
TimeOutDialog::TimeOutDialog(int time, QWidget *parent)
: QProgressDialog(parent), _time(time)
{
@@ -24,6 +22,7 @@ TimeOutDialog::TimeOutDialog(int time, QWidget *parent)
_timer.start(1000);
}
+
//___________________________________________________________________________
void TimeOutDialog::update()
{
@@ -36,6 +35,7 @@ void TimeOutDialog::update()
--_time;
}
+
//___________________________________________________________________________
void TimeOutDialog::cancel()
{
diff --git a/src/timeoutdialog.h b/src/timeoutdialog.h
index a5278cb..4961e6f 100644
--- a/src/timeoutdialog.h
+++ b/src/timeoutdialog.h
@@ -4,7 +4,6 @@
#ifndef TIMEOUTDIALOG_H
#define TIMEOUTDIALOG_H
-#include <QtGui/QApplication>
#include <QProgressDialog>
#include <QTimer>
diff --git a/src/widget.cpp b/src/widget.cpp
index d7a2ff5..71280c7 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -1,34 +1,17 @@
// Copyright 2013, University of Freiburg,
// Author: Manuel Schneider <ms1144>
-#include <stdio.h>
-#include <sys/types.h>
-#include <ifaddrs.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include <math.h>
-
#include <iostream>
#include <algorithm>
-#include <QString>
#include <QDebug>
-#include <QSet>
+#include <QtGui/QAction>
#include "widget.h"
#include "ui_widget.h"
#include "timeoutdialog.h"
-#define INTERFACE "eth0"
-#define GROUP_SPECIFIC "SpecificSettings"
-#define OPENSLXCONFIG "/opt/openslx/config"
-#define OPENSLXCONFIG_IPKEY "SLX_PXE_CLIENT_IP"
-
-//#define DEBUG
-
-
-//_____________________________________________________________________________
+//______________________________________________________________________________
Widget::Widget(QWidget *parent) :
QWidget(parent),
_ui(new Ui::Widget)
@@ -56,8 +39,7 @@ Widget::Widget(QWidget *parent) :
// Check if one of the connected outputs is a beamer. This program only
// adresses cases in which eiter of the outouts is a beamer. Meaning
// either output one has dimension zero or output tow has no dimension.
- // The case of two beamers is not covered.
-#ifdef DEBUG
+#ifdef QT_DEBUG
if ( true ) {
#else
if ( ((_outputMap[_connectedOutputList[0]]->mm_width == 0
@@ -82,25 +64,6 @@ Widget::Widget(QWidget *parent) :
_monitor = _connectedOutputList[0];
}
- // Deprecated, will be deleted after confirmation from above
- //setResFromConfig();
-
-
- // Check if the beamer transmitted reliable data.
- bool gotEDID = false;
- int nprop;
- Atom *props = XRRListOutputProperties(_display, _beamer, &nprop);
- for (int i = 0; i < nprop; ++i) {
- char *atom_name = XGetAtomName (_display, props[i]);
- if ( strcmp (atom_name, "EDID") == 0) {
- gotEDID = true;
- XFree (atom_name);
- break;
- }
- XFree (atom_name);
- }
- free(props);
-
// Intersect them by the resolution sorted, dont care about O(n³)
QList<QPair<XRRModeInfo*, XRRModeInfo*> > commonModes;
@@ -126,12 +89,9 @@ Widget::Widget(QWidget *parent) :
if ( monitorMode->height == beamerMode->height
&& monitorMode->width == beamerMode->width ) {
-// qDebug() << "Potential common mode"
-// << monitorMode->width
-// << monitorMode->height ;
-
// Build a sorted list of common modes in descending order
- QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator k = commonModes.begin();
+ QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator k
+ = commonModes.begin();
for (;;++k) {
// If at the end, the mode to insert is the smallest, insert.
@@ -139,18 +99,12 @@ Widget::Widget(QWidget *parent) :
if (k == commonModes.end()) {
commonModes.insert(k, qMakePair (monitorMode, beamerMode));
-// qDebug() << "Smallest"
-// << monitorMode->width
-// << monitorMode->height ;
break;
}
// If the mode to insert is larger than k, insert.
if ( monitorMode->width > k->first->width) {
commonModes.insert(k, qMakePair (monitorMode, beamerMode));
-// qDebug() << "Insert"
-// << monitorMode->width
-// << monitorMode->height ;
break;
}
@@ -159,18 +113,12 @@ Widget::Widget(QWidget *parent) :
// ... and the height is the same, the mode already exists
if ( monitorMode->height == k->first->height ) {
-// qDebug() << "Already exists"
-// << monitorMode->width
-// << monitorMode->height ;
break;
}
// ... and the height is larger, insert.
if ( monitorMode->height > k->first->height ) {
commonModes.insert(k, qMakePair (monitorMode, beamerMode));
-// qDebug() << "Insert"
-// << monitorMode->width
-// << monitorMode->height ;
break;
}
}
@@ -179,8 +127,24 @@ Widget::Widget(QWidget *parent) :
}
}
+
+ // Check if the beamer transmitted reliable data.
+ bool gotEDID = false;
+ int nprop;
+ Atom *props = XRRListOutputProperties(_display, _beamer, &nprop);
+ for (int i = 0; i < nprop; ++i) {
+ char *atom_name = XGetAtomName (_display, props[i]);
+ if ( strcmp (atom_name, "EDID") == 0) {
+ gotEDID = true;
+ XFree (atom_name);
+ break;
+ }
+ XFree (atom_name);
+ }
+ free(props);
+
// If the beamer transmits no reliable EDID data add modes
-#ifdef DEBUG
+#ifdef QT_DEBUG
gotEDID = false;
#endif
if (gotEDID) {
@@ -188,7 +152,7 @@ Widget::Widget(QWidget *parent) :
qDebug() << "GOT EDID!";
// Extract the preferred mode of the beamer
- RRMode preferredBeamerModeId;
+ RRMode preferredBeamerModeId = 0;
for (int i = 0; i < _outputMap[_beamer]->nmode; ++i) {
if (i < _outputMap[_beamer]->npreferred) {
preferredBeamerModeId = _outputMap[_beamer]->modes[i];
@@ -201,8 +165,8 @@ Widget::Widget(QWidget *parent) :
/ _modeMap[preferredBeamerModeId]->height;
// Fill widget with data
- for ( QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator i = commonModes.begin();
- i != commonModes.end(); ++i ) {
+ for (QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator i
+ = commonModes.begin(); i != commonModes.end(); ++i ) {
float modeAspectRatio = ((float)i->first->width / i->first->height);
if ( abs(modeAspectRatio - aspectRatio) < 0.05 ) // APPROX
_ui->comboBox->addItem(i->first->name,
@@ -216,12 +180,11 @@ Widget::Widget(QWidget *parent) :
// Fill widget with data without AR match
// Fill widget with data
- for ( QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator i = commonModes.begin();
- i != commonModes.end(); ++i ) {
+ for ( QList<QPair<XRRModeInfo*, XRRModeInfo*> >::iterator i
+ = commonModes.begin(); i != commonModes.end(); ++i ) {
qDebug() << "Insert into QComboBox"
<< i->first->width << "x" << i->first->height
- << "\t\tBEAMER:" << QVariant((qulonglong)i->first->id).toULongLong()
- << " \tMONITOR:" << QVariant((qulonglong)i->second->id).toULongLong();
+ << "(" << i->first->id << ")";
_ui->comboBox->addItem(i->first->name,
QList<QVariant>()
<< QVariant((qulonglong)i->first->id)
@@ -229,9 +192,14 @@ Widget::Widget(QWidget *parent) :
}
}
+ // Set the current resolution highlighted
+ QString n = _modeMap[_crtcMap[_outputMap[_monitor]->crtc]->mode]->name;
+ int index = _ui->comboBox->findText(n);
+ _ui->comboBox->setCurrentIndex(index);
+
// Remove borders and stuff
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
- // setStyleSheet("background:transparent;");
+ setStyleSheet("background:transparent;");
// setAttribute(Qt::WA_TranslucentBackground);
// Resize widget to its content
@@ -244,9 +212,7 @@ Widget::Widget(QWidget *parent) :
// Connect button signal to appropriate slot
connect(_ui->pushButton, SIGNAL(clicked()), this, SLOT(handleButton()));
-
-
- } // End of the beamer section
+ }
/*********************************************************************/
// If NEITHER of the outputs is a beamer (likely dualscreen setup)
else {
@@ -266,7 +232,7 @@ Widget::Widget(QWidget *parent) :
/*************************************************************************/
}
-//___________________________________________________________________________
+//______________________________________________________________________________
void Widget::updateScreenResources()
{
// Clear the modemap (nothing to be freed, stored in screenResources)
@@ -279,7 +245,8 @@ void Widget::updateScreenResources()
_screenResources->modes[i].id,
&_screenResources->modes[i]);
qDebug() << _screenResources->modes[i].id << "\t"
- << _screenResources->modes[i].width << "x" << _screenResources->modes[i].height;
+ << _screenResources->modes[i].width << "x"
+ << _screenResources->modes[i].height;
}
// Clear the crtmap
@@ -323,126 +290,29 @@ void Widget::updateScreenResources()
}
}
-//___________________________________________________________________________
+
+//______________________________________________________________________________
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()
-{
- // Backup the crtcinfos
+
+//______________________________________________________________________________
+void Widget::handleButton(){
+
+ /*************************** Backup the crtcinfos ***************************/
+
qDebug() << "Backup the crtc infos";
+
CrtcMap backup;
for ( CrtcMap::iterator it = _crtcMap.begin();
it != _crtcMap.end(); ++it ) {
-
- qDebug() << " Key is " << it.key();
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;
- 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];
@@ -451,24 +321,27 @@ void Widget::handleButton()
}
}
- // Get the modes from QComboBox
- QList<QVariant> modes = _ui->comboBox->itemData( _ui->comboBox->currentIndex()).toList();
+ /**************************** Apply the resolution **************************/
+
+ // Get the modes which has to be applied from QComboBox
+ QList<QVariant> modes =
+ _ui->comboBox->itemData( _ui->comboBox->currentIndex()).toList();
XRRModeInfo* monitorMode = _modeMap[modes[0].toULongLong()];
- XRRModeInfo* beamerMode = _modeMap[modes[1].toULongLong()];
+ XRRModeInfo* beamerMode = _modeMap[modes[1].toULongLong()];
- // Set screensize
- uint width = monitorMode->width;
- uint height = monitorMode->height;
+ // 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);
+ }
- qDebug() << " Set screensize to" << width << height;
+ // 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
+ monitorMode->width, monitorMode->height,
+ 25.4 * monitorMode->width / 96, // standard dpi that X uses
+ 25.4 * monitorMode->height / 96); // standard dpi that X uses
// Apply the modes
- qDebug() << "Apply the modes" << monitorMode->id << beamerMode->id;
XRRSetCrtcConfig(_display,
_screenResources,
_outputMap[_monitor]->crtc,
@@ -484,39 +357,38 @@ void Widget::handleButton()
RR_Rotate_0,
&_beamer, 1);
+ // Sync... whatever...
+ XSync (_display, False);
+
// Center widget on screenbottom
- qDebug() << "Center widget on screenbottom";
- this->move( width/2 - this->width()/2, height - this->height());
+ this->move( monitorMode->width/2 - this->width()/2,
+ monitorMode->height - this->height());
+
+ QCursor::setPos(monitorMode->width/2, monitorMode->height/2);
+
+ /*************************** ASK for confirmtion ****************************/
// Show a dialog asking if the res should be kept
- qDebug() << "Show a dialog asking if the res should be kept";
TimeOutDialog *keepDialog = new TimeOutDialog(15, this);
keepDialog->setWindowTitle(" ");
keepDialog->setLabelText("Do you want to keep this resolution?");
keepDialog->setCancelButtonText("Keep");
- keepDialog->move( width/2 - this->width()/2, height/2 - this->height());
+ keepDialog->move(monitorMode->width/2 - this->width()/2,
+ monitorMode->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 ( ! keepDialog->wasCanceled()) {
+ /**************************** Apply the backup ****************************/
+
// First disconnect all crts to avoid conflicts
- qDebug() << "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);
+ 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
- qDebug() << "Then calc backed up screensize...";
QSize ScreenSize(0,0);
for ( CrtcMap::iterator it = backup.begin();
it != backup.end(); ++it ) {
@@ -528,24 +400,18 @@ void Widget::handleButton()
ScreenSize.setHeight(
std::max((uint)ScreenSize.height(),
it.value()->y+_modeMap[it.value()->mode]->height));
- }
+ }
}
- qDebug() << "screensize is" << ScreenSize;
// Set screensize
- qDebug() << "Apply 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
+ ScreenSize.width(), ScreenSize.height(),
+ 25.4 * ScreenSize.width() / 96, // dpi used by X
+ 25.4 * ScreenSize.height() / 96); // dpi used by X
- // Then apply the backup
- qDebug() << "Then apply the backup";
+ // Apply the backup
for ( CrtcMap::iterator it = backup.begin();
it != backup.end(); ++it ) {
-
- qDebug() << "CRTC" << it.key() << "MODE" << it.value()->mode;
XRRSetCrtcConfig(_display,
_screenResources,
it.key(),
@@ -558,15 +424,16 @@ void Widget::handleButton()
it.value()->noutput);
}
- // Again center dialog on screenbottom
+ // Sync... whatever...
+ XSync (_display, False);
+
+ // center dialog on screenbottom
qDebug() << "Again center dialog on screenbottom";
this->move( ScreenSize.width()/2 - this->width()/2,
ScreenSize.height() - this->height());
-
- } // End of Revert section
+ }
// Delete the backup
- qDebug() << "Delete the backup";
for ( CrtcMap::iterator it = backup.begin();
it != backup.end(); ++it ) {
delete[] it.value()->outputs;
@@ -577,142 +444,4 @@ void Widget::handleButton()
updateScreenResources();
}
-
-
-/////////////////////////// CODE PAPIERKORB /////////////////////////////////
-
-
-// // Apply the mode via xrandr
-// 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();
-
-// // TO BE DONE VIA BASH
-// // Iterate over the modes in the config file
-// for (QList<QString>::const_iterator it =
-// Config::inst()->getModeLines().begin();
-// it != Config::inst()->getModeLines().end(); ++it) {
-// // Add mode to xrandr
-// QProcess p;
-// QStringList arguments;
-// arguments << "--current" << "--newmode"
-// << it->split(" ", QString::SkipEmptyParts);
-// p.start("xrandr", arguments);
-// p.waitForFinished();
-// }
-
-// // TO BE DONE VIA BASH
-// // Iterate over all modes and add them to the outputs,
-// // if the AR matches.
-// for(ModeMap::iterator it = _modeMap.begin();
-// it != _modeMap.end(); ++it) {
-// float MODEAR = ((float)(*it)->width / (*it)->height);
-// if ( MODEAR == AR ) {
-// XRRAddOutputMode(_display, _beamer, (*it)->id);
-// XRRAddOutputMode(_display, _monitor, (*it)->id);
-// }
-// }
-
-// TO BE DONE VIA BASH
-// // Iterate over all modes and add them to the outputs
-// for(ModeMap::iterator it = _modeMap.begin();
-// it != _modeMap.end(); ++it) {
-// XRRAddOutputMode(_display, _beamer, (*it)->id);
-// XRRAddOutputMode(_display, _monitor, (*it)->id);
-
-// // 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[_monitor]->nmode; ++i)
-// monitorModes.insert(_modeMap[_outputMap[_monitor]->modes[i]]);
-
-// // Intersect them by the resolution sorted
-// // dont care about O(n³)
-// 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()){
-// commonModes.insert(k, *i);
-// break;
-// }
-// if ( (*i)->width == (*k)->width ) {
-// if ( (*i)->height == (*k)->height )
-// break;
-// if ( (*i)->height > (*k)->height ) {
-// commonModes.insert(k, *i);
-// break;
-// }
-// }
-// if ( (*i)->width > (*k)->width ) {
-// commonModes.insert(k, *i);
-// break;
-// }
-// ++k;
-// }
-// }
-// }// }
-
-// // First get a useful representation
-// qDebug() << "// 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();
-// // 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
-// && !(_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
-// && !(_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);
+////////////////////////////////////////////////////////////////////////////////
diff --git a/src/widget.h b/src/widget.h
index 83404ac..a737412 100644
--- a/src/widget.h
+++ b/src/widget.h
@@ -4,12 +4,13 @@
#ifndef WIDGET_H
#define WIDGET_H
-#include <QWidget>
-#include <QtGui>
+#include <QtGui> // for Qt4
+#include <QWidget> // for Qt4
+//#include <QtWidgets> // for Qt5
#include <QDebug>
-#include <QProgressDialog>
-#include <x.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/Xrandr.h>
namespace Ui {
class Widget;
@@ -40,10 +41,8 @@ public:
void handleButton();
private:
- void updateScreenResources();
- // Deprecated, will be deleted after confirmation from above
- //void setResFromConfig();
void timeout();
+ void updateScreenResources();
Ui::Widget * _ui;
Display* _display;