diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 84 | ||||
-rw-r--r-- | src/beamergui.pro | 25 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/timeoutdialog.cpp | 3 | ||||
-rw-r--r-- | src/timeoutdialog.h | 1 | ||||
-rw-r--r-- | src/widget.cpp | 35 | ||||
-rw-r--r-- | src/widget.ui | 2 | ||||
-rw-r--r-- | src/x.cpp | 2 | ||||
-rw-r--r-- | src/x.h | 6 |
10 files changed, 118 insertions, 45 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3bae8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/build/ +/CMakeLists.txt.user + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c8ca1ac --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +# cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug .. + +# project name +project(beamergui) + +set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra -pedantic -Werror -Wno-multichar") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wno-multichar") + +set(CMAKE_CXX_STANDARD 11) +# Some cmake versions can't understand the CMAKE_CXX_STANDARD option above? +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +file(GLOB_RECURSE BEAMERGUI_SOURCES src/*.cpp) +file(GLOB_RECURSE BEAMERGUI_UIS src/*.ui) +file(GLOB_RECURSE BEAMERGUI_RESOURCES src/*.qrc) +file(GLOB_RECURSE BEAMERGUI_TSS src/i18n/*.ts) + +option(UPDATE_TRANSLATIONS "Update .ts files (WARNING: make clean will delete the .ts files!)" OFF) +if(BEAMERGUI_TSS) + if (UPDATE_TRANSLATIONS) + set (FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${BEAMERGUI_SOURCES} ${BEAMERGUI_UIS}) + QT5_CREATE_TRANSLATION(BEAMERGUI_QMS ${FILES_TO_TRANSLATE} ${BEAMERGUI_TSS} OPTIONS -noobsolete) + message(STATUS ".tr files have been updated") + else (UPDATE_TRANSLATIONS) + QT5_ADD_TRANSLATION(BEAMERGUI_QMS ${BEAMERGUI_TSS}) + endif (UPDATE_TRANSLATIONS) + + # write a resource file for qm files + set(resource_file_content "<RCC>\n <qresource prefix=\"/\">\n") + foreach(file ${BEAMERGUI_QMS}) + get_filename_component(filename ${file} NAME) + set(resource_file_content "${resource_file_content} <file>${filename}</file>\n") + endforeach(file) + set(resource_file_content "${resource_file_content} </qresource>\n</RCC>\n") + file(WRITE "${CMAKE_BINARY_DIR}/translation.qrc" "${resource_file_content}") + set(BEAMERGUI_RESOURCES ${BEAMERGUI_RESOURCES} "${CMAKE_BINARY_DIR}/translation.qrc") + + #add_custom_target(translations_target DEPENDS ${BEAMERGUI_QMS}) +endif(BEAMERGUI_TSS) + +#include_directories( +# ${CMAKE_CURRENT_SOURCE_DIR}/src +# ${CMAKE_CURRENT_BINARY_DIR} +#) + +# +# Qt5 +# +FIND_PACKAGE(Qt5 COMPONENTS Widgets REQUIRED) +FIND_PACKAGE(X11 REQUIRED) + +if(NOT X11_Xrandr_FOUND) + MESSAGE( FATAL_ERROR "Cannot find xrandr libs" ) +endif() + + +QT5_WRAP_UI(BEAMERGUI_UI_HEADERS ${BEAMERGUI_UIS}) + +QT5_ADD_RESOURCES(BEAMERGUI_RC_SOURCES ${BEAMERGUI_RESOURCES}) + +# +# build beamergui +# +add_executable(beamergui + ${BEAMERGUI_SOURCES} + ${BEAMERGUI_UI_HEADERS} +# ${BEAMERGUI_RC_SOURCES} + ${BEAMERGUI_QMS} +) + +target_link_libraries(beamergui + Qt5::Widgets + ${X11_LIBRARIES} + ${X11_Xrandr_LIB} +) + +install(TARGETS beamergui RUNTIME DESTINATION bin) + diff --git a/src/beamergui.pro b/src/beamergui.pro deleted file mode 100644 index 1b9ee2a..0000000 --- a/src/beamergui.pro +++ /dev/null @@ -1,25 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2013-10-14T14:24:40 -# -#------------------------------------------------- - - -QT += core gui # qt4 -QT += widgets # qt5 - -TARGET = beamergui -TEMPLATE = app - -SOURCES += main.cpp\ - widget.cpp \ - timeoutdialog.cpp - -HEADERS += widget.h \ - timeoutdialog.h - -FORMS += widget.ui - -LIBS += -lXrandr -lX11 - -RESOURCES += diff --git a/src/main.cpp b/src/main.cpp index 8f90cd7..7ae6558 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ // Copyright 2013, University of Freiburg, // Author: Manuel Schneider <ms1144> -#include <QtWidgets/QApplication> // for Qt4 +#include <QtWidgets/QApplication> // for Qt5 #include "widget.h" int main(int argc, char *argv[]) diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp index 719fddd..418d791 100644 --- a/src/timeoutdialog.cpp +++ b/src/timeoutdialog.cpp @@ -13,11 +13,10 @@ TimeOutDialog::TimeOutDialog(int time, QWidget *parent) // QProgressDialog takes ownership of QProgressBar QProgressBar *qbar = new QProgressBar(this); - qbar->setFormat("%v seconds"); + qbar->setFormat(trUtf8("%v seconds")); qbar->setMaximum(_time); qbar->setMinimum(0); qbar->setValue(_time); - qbar->setLayoutDirection(Qt::RightToLeft); setBar(qbar); _timer.start(1000); } diff --git a/src/timeoutdialog.h b/src/timeoutdialog.h index 4961e6f..eb0f969 100644 --- a/src/timeoutdialog.h +++ b/src/timeoutdialog.h @@ -13,6 +13,7 @@ class TimeOutDialog : public QProgressDialog public: TimeOutDialog(int time, QWidget *parent = 0); + bool isActive() const { return _timer.isActive(); } private: int _time; diff --git a/src/widget.cpp b/src/widget.cpp index b3a559f..887249f 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -244,6 +244,7 @@ Widget::Widget(QWidget *parent) : void Widget::bringToTopTimer() { + if (_ui->comboBox->isVisible()) return; raise(); } @@ -346,8 +347,9 @@ void Widget::handleButton(){ // First disconnect all crts to avoid conflicts for(CrtcMap::iterator it = _crtcMap.begin(); it != _crtcMap.end(); ++it) { - XRRSetCrtcConfig(_display, _screenResources, it.key(), CurrentTime, + Status st = XRRSetCrtcConfig(_display, _screenResources, it.key(), CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0); + qDebug() << "Disconnecting" << it.key() << ":" << st; } // Set screensize @@ -357,27 +359,28 @@ void Widget::handleButton(){ 25.4 * monitorMode->height / 96); // standard dpi that X uses // Apply the modes - XRRSetCrtcConfig(_display, - _screenResources, + Status stMon = XRRSetCrtcConfig(_display, + _screenResources, _outputMap[_monitor]->crtc, CurrentTime, 0, 0, monitorMode->id, RR_Rotate_0, &_monitor, 1); - XRRSetCrtcConfig(_display, + Status stBem = XRRSetCrtcConfig(_display, _screenResources, _outputMap[_beamer]->crtc, CurrentTime, 0, 0, beamerMode->id, RR_Rotate_0, - &_beamer, 1); + &_beamer, 1); // Sync... whatever... XSync (_display, False); + qDebug() << "Monitor set:" << stMon << ", beamer set: " << stBem; // Center widget on screenbottom this->move( monitorMode->width/2 - this->width()/2, - monitorMode->height - this->height()); + monitorMode->height - this->height() ); // Set the mouse pointer in the middle of the screen QCursor::setPos(monitorMode->width/2, monitorMode->height/2); @@ -385,16 +388,22 @@ void Widget::handleButton(){ /*************************** ASK for confirmtion ****************************/ // 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(monitorMode->width/2 - this->width()/2, + TimeOutDialog keepDialog(15, this); + keepDialog.setWindowModality(Qt::ApplicationModal); + keepDialog.setWindowTitle(" "); + keepDialog.setLabelText(trUtf8("Do you want to keep this resolution?")); + keepDialog.setCancelButtonText(trUtf8("Keep")); + keepDialog.move(monitorMode->width/2 - this->width()/2, monitorMode->height/2 - this->height()); - keepDialog->exec(); + keepDialog.show(); + + while (keepDialog.isActive()) { + QCoreApplication::processEvents(); + } // If the dialog was not canceled revert the resolution - if ( ! keepDialog->wasCanceled()) { + if ( !keepDialog.wasCanceled()) { + qDebug() << "User did not cancel timeout, reverting!"; /**************************** Apply the backup ****************************/ diff --git a/src/widget.ui b/src/widget.ui index 3755397..6086eae 100644 --- a/src/widget.ui +++ b/src/widget.ui @@ -25,7 +25,7 @@ <item> <widget class="QPushButton" name="pushButton"> <property name="text"> - <string>Anwenden</string> + <string>Apply</string> </property> </widget> </item> @@ -192,7 +192,7 @@ namespace X ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// - Crtc::Crtc(XID id = None, Screen * parent = NULL) + Crtc::Crtc(XID id, Screen * parent) : XElement(id), _parent(parent) { // Get the information from XRROutputInfo @@ -87,8 +87,9 @@ namespace X /////////////////////////////////////////////////////////////////////////// - struct XElement + class XElement { + public: XElement(XID = 0); XID _id; bool _validity; @@ -100,8 +101,9 @@ namespace X /////////////////////////////////////////////////////////////////////////// - struct Mode : public XElement + class Mode : public XElement { + public: Mode(XRRModeInfo* = NULL); // Xlib internal stuff |