Skip to content

Commit

Permalink
Replace xrandr backend by KScreen
Browse files Browse the repository at this point in the history
References lxqt/lxqt#502
  • Loading branch information
jleclanche authored and paulolieuthier committed May 21, 2015
1 parent ca940d0 commit 82f3915
Show file tree
Hide file tree
Showing 12 changed files with 426 additions and 684 deletions.
10 changes: 5 additions & 5 deletions lxqt-config-monitor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
project(lxqt-config-monitor)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories (
"${CMAKE_CURRENT_BINARY_DIR}"
${LXQT_INCLUDE_DIRS}
)

find_package(Qt5Svg REQUIRED)
find_package(KF5Screen REQUIRED)

set(H_FILES
main.h
monitorsettingsdialog.h
monitor.h
monitorwidget.h
xrandr.h
monitorpicture.h
quickoptions.h
applydialog.h
Expand All @@ -21,7 +22,6 @@ set(H_FILES
set(CPP_FILES
main.cpp
monitorsettingsdialog.cpp
xrandr.cpp
monitor.cpp
monitorwidget.cpp
timeoutdialog.cpp
Expand Down Expand Up @@ -83,10 +83,10 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::X11Extras
Qt5::Svg
KF5::Screen
${LXQT_LIBRARIES}
)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES ${DESKTOP_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications")
install(FILES ${ICON_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/lxqt/icons/")
install(FILES ${ICON_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/lxqt/icons/")
27 changes: 12 additions & 15 deletions lxqt-config-monitor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#include "main.h"
#include <LXQt/SingleApplication>
#include <LXQt/ConfigDialog>
#include <LXQt/Settings>
#include <QDebug>
#include "monitorsettingsdialog.h"
#include "quickoptions.h"
#include "xrandr.h"
#include "applydialog.h"

int main(int argc, char** argv) {
LxQt::SingleApplication app(argc, argv);

QByteArray configName = qgetenv("LXQT_SESSION_CONFIG");
if(configName.isEmpty())
configName = "MonitorSettings";
Expand All @@ -38,7 +34,7 @@ int main(int argc, char** argv) {
dlg.setButtons(QDialogButtonBox::QDialogButtonBox::Apply|QDialogButtonBox::Close);
app.setActivationWindow(&dlg);
dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display"));

XRandRBackend *xrandr = new XRandRBackend();
MonitorSettingsDialog *monitorSettingsDialog = new MonitorSettingsDialog(xrandr, &settings);
monitorSettingsDialog->connect(&dlg, SIGNAL(clicked(QDialogButtonBox::StandardButton)), SLOT(processClickedFromDialog(QDialogButtonBox::StandardButton)));
Expand All @@ -54,22 +50,23 @@ int main(int argc, char** argv) {
dlg.addPage(quickOptions, QObject::tr("Quick Options"), "format-justify-left");
}
}

dlg.addPage(monitorSettingsDialog, QObject::tr("Settings"), "preferences-desktop-display");

ApplyDialog *apply = new ApplyDialog(&settings);
apply->setHardwareIdentifier(monitorSettingsDialog->getHardwareIdentifier());
// monitorSettingsDialog->connect(apply->ui.apply, SIGNAL(clicked(bool)), SLOT(applySettings()));
monitorSettingsDialog->connect(apply->ui.save, SIGNAL(clicked(bool)), SLOT(saveSettings()));
apply->connect(monitorSettingsDialog, SIGNAL(settingsSaved()), SLOT(loadSettings()));

dlg.addPage(apply, QObject::tr("Save settings"), "system-run");

QObject::connect(&dlg, SIGNAL(reset()), &dlg, SLOT(accept()));

if(QDialog::Accepted == dlg.exec() ) {
main(argc, argv);
}

return 0;
MonitorSettingsDialog dlg;
app.setActivationWindow(&dlg);
dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display"));
dlg.show();

return app.exec();
}
140 changes: 59 additions & 81 deletions lxqt-config-monitor/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,83 +20,49 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<item>
<widget class="QListWidget" name="monitorList">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="unify">
<property name="text">
<string>Unify all monitors</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="positionPushButton">
<property name="text">
<string>Monitor Position</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="primaryLabel">
<property name="text">
<string>Primary monitor:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="primaryCombo">
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<item>
<widget class="QListWidget" name="monitorList">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
Expand All @@ -110,12 +76,24 @@
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>146</x>
<y>146</y>
<x>126</x>
<y>181</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MonitorSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>338</x>
<y>439</y>
</hint>
<hint type="destinationlabel">
<x>394</x>
<y>146</y>
<x>286</x>
<y>257</y>
</hint>
</hints>
</connection>
Expand Down
13 changes: 8 additions & 5 deletions lxqt-config-monitor/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

bool MonitorInfo::LVDS_Ok = false;

bool MonitorSettingsBackend::isUnified(const QList< MonitorInfo* > monitors) {
Q_FOREACH(MonitorInfo * monitor, monitors) {
if(monitor->position != MonitorSettings::None)
return false;
QSize sizeFromString(QString str) {
int width = 0;
int height = 0;
int x = str.indexOf('x');
if(x > 0) {
width = str.left(x).toInt();
height = str.mid(x + 1).toInt();
}
return true;
return QSize(width, height);
}

MonitorSettings::MonitorSettings(QObject* parent): QObject(parent) {
Expand Down
18 changes: 5 additions & 13 deletions lxqt-config-monitor/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <QHash>
#include <QList>
#include <QRect>
#include <KScreen/Config>


//Settings to pass to backend
class MonitorSettings: public QObject {
Expand Down Expand Up @@ -55,8 +57,10 @@ class MonitorMode: public QObject {

// Monitor information from backend
class MonitorInfo: public MonitorSettings {
Q_OBJECT
Q_OBJECT
public:
KScreen::ConfigPtr mConfig;

MonitorInfo(QObject* parent = 0);
QStringList modes; // Modes of this monitor in order
QHash <QString, MonitorMode*> monitorModes; // Rates suported by each mode
Expand All @@ -69,18 +73,6 @@ class MonitorInfo: public MonitorSettings {
QString humanReadableName();
};


class MonitorSettingsBackend: public QObject {
Q_OBJECT
public:
virtual QList<MonitorInfo*> getMonitorsInfo() = 0;
virtual bool setMonitorsSettings(const QList<MonitorSettings*> monitors) = 0;
virtual QString getCommand(const QList<MonitorSettings*> monitors) = 0;
virtual bool isUnified(const QList<MonitorInfo*> monitors);
};



/**Gets size from string rate. String rate format is "widthxheight". Example: 800x600*/
QSize sizeFromString(QString str);

Expand Down
29 changes: 8 additions & 21 deletions lxqt-config-monitor/monitorpicture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void MonitorPictureDialog::updateMonitorWidgets(QString primaryMonitor) {
int x0, y0;
x0 = y0 =0;
Q_FOREACH(MonitorPicture * picture, pictures) {
if( picture->monitorWidget->monitorInfo->name == primaryMonitor || primaryMonitor=="") {
if( picture->monitorWidget->output->name() == primaryMonitor || primaryMonitor=="") {
x0 = picture->monitorWidget->ui.xPosSpinBox->value() + picture->pos().x();
y0 = picture->monitorWidget->ui.yPosSpinBox->value() + picture->pos().y();
break;
Expand Down Expand Up @@ -69,31 +69,18 @@ MonitorPicture::MonitorPicture(QGraphicsItem * parent, MonitorWidget *monitorWid
setRect(x, y, currentSizeWidth, currentSizeHeight);
originX = x;
originY = y;


QSvgRenderer *renderer = new QSvgRenderer(QLatin1String(ICON_PATH "monitor.svg"));
svgItem = new QGraphicsSvgItem();
svgItem->setSharedRenderer(renderer);
svgItem->setX(x);
svgItem->setY(y);
svgItem->setOpacity(0.7);
svgItem->setParentItem(this);


textItem = new QGraphicsTextItem(monitorWidget->monitorInfo->name, this);
textItem->setDefaultTextColor(Qt::white);
setPen(QPen(Qt::black, 20));
textItem = new QGraphicsTextItem(monitorWidget->output->name(), this);
textItem->setX(x);
textItem->setY(y);
textItem->setParentItem(this);
setPen(QPen(Qt::black, 20));


adjustNameSize();
}


void MonitorPicture::adjustNameSize() {
prepareGeometryChange();
qreal fontWidth = QFontMetrics(textItem->font()).width(monitorWidget->monitorInfo->name+" ");
qreal fontWidth = QFontMetrics(textItem->font()).width(monitorWidget->output->name() + " ");
textItem->setScale((qreal)this->rect().width()/fontWidth);
QTransform transform;
qreal width = qAbs(this->rect().width()/svgItem->boundingRect().width());
Expand Down Expand Up @@ -130,7 +117,7 @@ void MonitorPicture::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)

//////////////////////////////////////////////////////////////////////////////////
// Move picture to nearest picture procedure.
// Read magnetic_attraction.html for more info about the algorithm used.
// Read magnetic_attraction.html for more info about the algorithm used.
//////////////////////////////////////////////////////////////////////////////////

struct Parameters {
Expand Down Expand Up @@ -223,14 +210,14 @@ static Result_moveMonitorPictureToNearest compareTwoMonitors(MonitorPicture* mon
if(params.t1>=0.0 && params.t1<=1.0 && params.t2>=0.0 && params.t2<=1.0) {
if(t2<0) {t2 = params.t1; P2 = params.cutPoint;}
}

if(t1>t2) { //Monitor outside
result.vector = P1-P2;
result.ok = false;
} else {
result.ok = true;
}

return result;
}

Expand Down
Loading

0 comments on commit 82f3915

Please sign in to comment.