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 committed Feb 20, 2015
1 parent 028e050 commit ca4fe53
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 684 deletions.
5 changes: 5 additions & 0 deletions lxqt-config-monitor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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(KF5Screen REQUIRED)

set(H_FILES
main.h
monitorsettingsdialog.h
Expand Down Expand Up @@ -64,6 +68,7 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::X11Extras
KF5::Screen
${LXQT_LIBRARIES}
)

Expand Down
3 changes: 2 additions & 1 deletion lxqt-config-monitor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#include "main.h"
#include <LXQt/SingleApplication>
#include "monitorsettingsdialog.h"
#include "xrandr.h"


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

XRandRBackend *xrandr = new XRandRBackend();

This comment has been minimized.

Copy link
@palinek

palinek Feb 26, 2015

Contributor

XRandR still here.. however the parameter is unused in MonitorSettingsDialog c-tor

This comment has been minimized.

Copy link
@jleclanche

jleclanche Feb 26, 2015

Author Member

I ran into trouble dropping it, compilation errors. I'd love your help with it.

This comment has been minimized.

Copy link
@palinek

palinek Feb 27, 2015

Contributor

Actually this was quite easy (after finding the right debian package libkf5screen-dev ...had to dig in ubuntu's launchpad :-) ) ... see https://github.com/palinek/lxqt-config/tree/switch-to-kscreen
Didn't test it quite much... just compiled, run and made some cliks.


MonitorSettingsDialog dlg(xrandr);
app.setActivationWindow(&dlg);
dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display"));
Expand Down
230 changes: 47 additions & 183 deletions lxqt-config-monitor/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,155 +20,67 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="quickOptionsTab">
<attribute name="title">
<string>Quick Options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="useBoth">
<property name="text">
<string>Show the same screen on both laptop LCD and external monitor</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="extended">
<property name="text">
<string>Extended view</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="externalOnly">
<property name="text">
<string>Turn off laptop LCD and use external monitor only</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="laptopOnly">
<property name="text">
<string>Turn off external monitor and use laptop LCD only</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="settingsTab">
<attribute name="title">
<string>Settings</string>
</attribute>
<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>
</widget>
</widget>
<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|QDialogButtonBox::Save</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>monitorList</sender>
<signal>currentRowChanged(int)</signal>
<receiver>stackedWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>126</x>
<y>181</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
Expand All @@ -185,53 +97,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>unify</sender>
<signal>toggled(bool)</signal>
<receiver>primaryLabel</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>115</x>
<y>386</y>
</hint>
<hint type="destinationlabel">
<x>413</x>
<y>388</y>
</hint>
</hints>
</connection>
<connection>
<sender>unify</sender>
<signal>toggled(bool)</signal>
<receiver>primaryCombo</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>60</x>
<y>386</y>
</hint>
<hint type="destinationlabel">
<x>491</x>
<y>388</y>
</hint>
</hints>
</connection>
<connection>
<sender>monitorList</sender>
<signal>currentRowChanged(int)</signal>
<receiver>stackedWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>126</x>
<y>181</y>
</hint>
<hint type="destinationlabel">
<x>392</x>
<y>186</y>
</hint>
</hints>
</connection>
</connections>
</ui>
6 changes: 5 additions & 1 deletion 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 All @@ -48,8 +50,10 @@ class MonitorSettings: 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, QStringList> modeLines; // Rates suported by each mode
Expand Down
14 changes: 7 additions & 7 deletions lxqt-config-monitor/monitorpicture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 @@ -63,17 +63,17 @@ MonitorPicture::MonitorPicture(QGraphicsItem * parent, MonitorWidget *monitorWid
originX = x;
originY = y;
setPen(QPen(Qt::black, 20));
textItem = new QGraphicsTextItem(monitorWidget->monitorInfo->name, this);
textItem = new QGraphicsTextItem(monitorWidget->output->name(), this);
textItem->setX(x);
textItem->setY(y);
textItem->setParentItem(this);

adjustNameSize();
}


void MonitorPicture::adjustNameSize() {
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);
}

Expand Down Expand Up @@ -105,7 +105,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 @@ -198,14 +198,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 ca4fe53

Please sign in to comment.