diff options
Diffstat (limited to 'src-qt5/core-utils/lumina-xconfig')
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.cpp | 160 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.h | 9 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.ui | 84 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp | 21 |
4 files changed, 105 insertions, 169 deletions
diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp index 6553bb37..90f09104 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp @@ -15,6 +15,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); loadIcons(); + scaleFactor = 1/20.0; //Fill the location list with the valid entries ui->combo_location->clear(); ui->combo_location->addItem(tr("Right Of"), "--right-of"); @@ -24,10 +25,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->push_rescan, SIGNAL(clicked()), this, SLOT(UpdateScreens()) ); connect(ui->push_activate, SIGNAL(clicked()), this, SLOT(ActivateScreen()) ); connect(ui->tool_deactivate, SIGNAL(clicked()), this, SLOT(DeactivateScreen()) ); - connect(ui->tool_moveleft, SIGNAL(clicked()), this, SLOT(MoveScreenLeft()) ); - connect(ui->tool_moveright, SIGNAL(clicked()), this, SLOT(MoveScreenRight()) ); + //connect(ui->tool_moveleft, SIGNAL(clicked()), this, SLOT(MoveScreenLeft()) ); + //connect(ui->tool_moveright, SIGNAL(clicked()), this, SLOT(MoveScreenRight()) ); connect(ui->tool_applyconfig, SIGNAL(clicked()), this, SLOT(ApplyChanges()) ); - connect(ui->list_screens, SIGNAL(itemSelectionChanged()),this, SLOT(ScreenSelected()) ); + connect(ui->mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(ScreenSelected()) ); + connect(ui->tool_tile, SIGNAL(clicked()), ui->mdiArea, SLOT(tileSubWindows()) ); QTimer::singleShot(0, this, SLOT(UpdateScreens()) ); } @@ -38,8 +40,8 @@ MainUI::~MainUI(){ void MainUI::loadIcons(){ this->setWindowIcon( LXDG::findIcon("preferences-system-windows-actions","") ); ui->tool_deactivate->setIcon( LXDG::findIcon("list-remove","") ); - ui->tool_moveleft->setIcon( LXDG::findIcon("arrow-left","") ); - ui->tool_moveright->setIcon( LXDG::findIcon("arrow-right","") ); + //ui->tool_moveleft->setIcon( LXDG::findIcon("arrow-left","") ); + //ui->tool_moveright->setIcon( LXDG::findIcon("arrow-right","") ); ui->push_activate->setIcon( LXDG::findIcon("list-add","") ); ui->push_rescan->setIcon( LXDG::findIcon("view-refresh","") ); ui->push_close->setIcon( LXDG::findIcon("window-close","") ); @@ -67,11 +69,17 @@ QStringList MainUI::currentOpts(){ return opts; } +QString MainUI::currentSelection(){ + QMdiSubWindow *tmp = ui->mdiArea->activeSubWindow(); + if(tmp!=0){ return tmp->whatsThis(); } + else{ return ""; } +} + ScreenInfo MainUI::currentScreenInfo(){ - QListWidgetItem *item = ui->list_screens->currentItem(); + QString item = currentSelection(); if(item!=0){ for(int i=0; i<SCREENS.length(); i++){ - if(SCREENS[i].ID==item->whatsThis()){ return SCREENS[i]; } + if(SCREENS[i].ID==item){ return SCREENS[i]; } } } //Fallback when nothing found/selected @@ -79,68 +87,43 @@ ScreenInfo MainUI::currentScreenInfo(){ } void MainUI::AddScreenToWidget(ScreenInfo screen){ - QListWidgetItem *it = new QListWidgetItem(); + //qDebug() << "Add Screen To Widget:" << screen.ID << screen.geom; + QLabel *lab = new QLabel(this); + lab->setAlignment(Qt::AlignCenter); + QMdiSubWindow *it = ui->mdiArea->addSubWindow(lab, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowTitleHint); + it->setWindowTitle(screen.ID); + lab->setText(QString::number(screen.geom.width())+"x"+QString::number(screen.geom.height())); + + /*QListWidgetItem *it = new QListWidgetItem(); it->setTextAlignment(Qt::AlignCenter); - it->setText( screen.ID+"\n\n ("+QString::number(screen.geom.x())+", "+QString::number(screen.geom.y())+")\n ("+QString::number(screen.geom.width())+"x"+QString::number(screen.geom.height())+") " ); + it->setText( screen.ID+"\n\n ("+QString::number(screen.geom.x())+", "+QString::number(screen.geom.y())+")\n ("+QString::number(screen.geom.width())+"x"+QString::number(screen.geom.height())+") " );*/ it->setWhatsThis(screen.ID); - ui->list_screens->addItem(it); + //ui->list_screens->addItem(it); + QRect scaled( screen.geom.topLeft()*scaleFactor, screen.geom.size()*scaleFactor); + qDebug() << " - Scaled:" << scaled; + it->show(); + //QApplication::processEvents(); + it->setGeometry(scaled); //scale it down for the display + it->setFixedSize(scaled.size()); + } void MainUI::UpdateScreens(){ //First probe the server for current screens SCREENS = RRSettings::CurrentScreens(); - /*QStringList info = LUtils::getCmdOutput("xrandr -q"); - ScreenInfo cscreen; - for(int i=0; i<info.length(); i++){ - if(info[i].contains("connected") ){ - //qDebug() << "xrandr info:" << info[i]; - if(!cscreen.ID.isEmpty()){ - SCREENS << cscreen; //current screen finished - save it into the array - cscreen = ScreenInfo(); //Now create a new structure - } - //qDebug() << "Line:" << info[i]; - QString dev = info[i].section(" ",0,0); //device ID - //The device resolution can be either the 3rd or 4th output - check both - QString devres = info[i].section(" ",2,2, QString::SectionSkipEmpty); - if(!devres.contains("x")){ devres = info[i].section(" ",3,3,QString::SectionSkipEmpty); } - if(!devres.contains("x")){ devres.clear(); } - qDebug() << " - ID:" <<dev << "Current Geometry:" << devres; - //qDebug() << " - Res:" << devres; - if( !devres.contains("x") || !devres.contains("+") ){ devres.clear(); } - //qDebug() << " - Res (modified):" << devres; - if(info[i].contains(" disconnected ") && !devres.isEmpty() ){ - //Disable this device and restart (disconnected, but still attached to the X server) - DeactivateScreen(dev); - UpdateScreens(); - return; - }else if( !devres.isEmpty() ){ - cscreen.isprimary = info[i].contains(" primary "); - //Device that is connected and attached (has a resolution) - qDebug() << "Create new Screen entry:" << dev << devres; - cscreen.ID = dev; - //Note: devres format: "<width>x<height>+<xoffset>+<yoffset>" - cscreen.geom.setRect( devres.section("+",-2,-2).toInt(), devres.section("+",-1,-1).toInt(), devres.section("x",0,0).toInt(), devres.section("+",0,0).section("x",1,1).toInt() ); - - }else if(info[i].contains(" connected")){ - //Device that is connected, but not attached - qDebug() << "Create new Screen entry:" << dev << "none"; - cscreen.ID = dev; - cscreen.order = -2; //flag this right now as a non-active screen - } - }else if( !cscreen.ID.isEmpty() && info[i].section("\t",0,0,QString::SectionSkipEmpty).contains("x")){ - //available resolution for a device - cscreen.resList << info[i].section("\t",0,0,QString::SectionSkipEmpty); - } - } //end loop over info lines - if(!cscreen.ID.isEmpty()){ SCREENS << cscreen; } //make sure to add the last screen to the array - */ //Now go through the screens and arrange them in order from left->right in the UI bool found = true; int xoffset = 0; //start at 0 int cnum = 0; - QString csel = ""; - if(ui->list_screens->currentItem()!=0){ csel = ui->list_screens->currentItem()->whatsThis(); } - ui->list_screens->clear(); + QString csel = currentSelection(); + //Clear all the current widgets + while(ui->mdiArea->currentSubWindow()!=0 ){ + QMdiSubWindow *tmp = ui->mdiArea->currentSubWindow(); + tmp->widget()->deleteLater(); + ui->mdiArea->removeSubWindow(tmp); + tmp->deleteLater(); + } + while(found){ found = false; //make sure to break out if a screen is not found for(int i=0; i<SCREENS.length(); i++){ @@ -151,12 +134,6 @@ void MainUI::UpdateScreens(){ SCREENS[i].order = cnum; //assign the current order to it cnum++; //get ready for the next one AddScreenToWidget(SCREENS[i]); - /*QListWidgetItem *it = new QListWidgetItem(); - it->setTextAlignment(Qt::AlignCenter); - it->setText( SCREENS[i].ID+"\n ("+QString::number(SCREENS[i].geom.x())+", "+QString::number(SCREENS[i].geom.y())+")\n("+QString::number(SCREENS[i].geom.width())+"x"+QString::number(SCREENS[i].geom.height())+") " ); - it->setWhatsThis(SCREENS[i].ID); - ui->list_screens->addItem(it);*/ - //if(SCREENS[i].ID==csel){ ui->list_screens->setCurrentItem(it); } }else if(SCREENS[i].geom.x() < xoffset || SCREENS[i].geom.x() > xoffset){ //Screen not aligned with previous screen edge qDebug() << "Found mis-aligned screen:" << i << SCREENS[i].ID; @@ -187,24 +164,25 @@ void MainUI::UpdateScreens(){ ui->group_avail->setVisible(true); ui->tabWidget->setTabEnabled(1,true); } - if(ui->list_screens->currentItem()==0){ ui->list_screens->setCurrentRow(0); } + //if(ui->list_screens->currentItem()==0){ ui->list_screens->setCurrentRow(0); } ScreenSelected(); //update buttons RRSettings::SaveScreens(SCREENS); } void MainUI::ScreenSelected(){ - QListWidgetItem *item = ui->list_screens->currentItem(); - if(item==0){ + QString item = currentSelection(); + //QListWidgetItem *item = ui->list_screens->currentItem(); + if(item.isEmpty()){ //nothing selected - ui->tool_deactivate->setEnabled(false); - ui->tool_moveleft->setEnabled(false); - ui->tool_moveright->setEnabled(false); + //ui->tool_deactivate->setEnabled(false); + //ui->tool_moveleft->setEnabled(false); + //ui->tool_moveright->setEnabled(false); ui->tab_config->setEnabled(false); }else{ //Item selected - ui->tool_deactivate->setEnabled(ui->list_screens->count()>1); - ui->tool_moveleft->setEnabled(ui->list_screens->row(item) > 0); - ui->tool_moveright->setEnabled(ui->list_screens->row(item) < (ui->list_screens->count()-1)); + //ui->tool_deactivate->setEnabled(ui->list_screens->count()>1); + //ui->tool_moveleft->setEnabled(ui->list_screens->row(item) > 0); + //ui->tool_moveright->setEnabled(ui->list_screens->row(item) < (ui->list_screens->count()-1)); ui->tab_config->setEnabled(true); //Update the info available on the config tab ScreenInfo cur = currentScreenInfo(); @@ -220,7 +198,7 @@ void MainUI::ScreenSelected(){ } } -void MainUI::MoveScreenLeft(){ +/*void MainUI::MoveScreenLeft(){ QListWidgetItem *item = ui->list_screens->currentItem(); if(item==0){ return; } //no selection //Get the current ID @@ -240,9 +218,9 @@ void MainUI::MoveScreenLeft(){ //Now run the command //LUtils::runCmd("xrandr", QStringList() << "--output" << CID << "--left-of" << LID); QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); -} +}*/ -void MainUI::MoveScreenRight(){ +/*void MainUI::MoveScreenRight(){ QListWidgetItem *item = ui->list_screens->currentItem(); if(item==0){ return; } //no selection //Get the current ID @@ -260,16 +238,10 @@ void MainUI::MoveScreenRight(){ QStringList opts = currentOpts(); LUtils::runCmd("xrandr", opts); QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); -} +}*/ void MainUI::DeactivateScreen(QString device){ - if(device.isEmpty()){ - //Get the currently selected device - QListWidgetItem *item = ui->list_screens->currentItem(); - if(item==0){ return; } //no selection - //Get the current ID - device = item->whatsThis(); - } + if(device.isEmpty()){ device = currentSelection(); } if(device.isEmpty()){ return; } //nothing found //Remove the screen from the settings for(int i=0; i<SCREENS.length(); i++){ @@ -297,22 +269,34 @@ void MainUI::ActivateScreen(){ void MainUI::ApplyChanges(){ //NOTE: need to re-specifiy the - QListWidgetItem *it = ui->list_screens->currentItem(); - if(it==0){ return; } //nothing to do + QString item = currentSelection(); + if(item.isEmpty()){ return; } //nothing to do QString newres = ui->combo_resolution->currentData().toString(); if(newres.isEmpty()){ return; } //nothing to do //qDebug() << "Apply Screen Changes" << it->whatsThis() << "->" << newres; //Adjust the order of the two screens bool setprimary = ui->check_primary->isChecked(); + QList<QMdiSubWindow*> windows = ui->mdiArea->subWindowList(); for(int i=0; i<SCREENS.length(); i++){ - if(SCREENS[i].ID == it->whatsThis()){ + if(SCREENS[i].ID == item){ SCREENS[i].geom.setWidth(newres.section("x",0,0).toInt()); SCREENS[i].geom.setHeight(newres.section("x",1,1).toInt()); } - if(setprimary){ SCREENS[i].isprimary = SCREENS[i].ID==it->whatsThis(); } + if(setprimary){ SCREENS[i].isprimary = SCREENS[i].ID==item; } + //Find the window associated with this screen + for(int s=0; s<windows.length(); s++){ + if(windows[s]->whatsThis()==SCREENS[i].ID){ + SCREENS[i].geom.setTopLeft( windows[s]->geometry().topLeft()/scaleFactor ); + } + } } //Now run the command QStringList opts = currentOpts(); LUtils::runCmd("xrandr", opts); QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); + QTimer::singleShot(1000, this, SLOT(RestartFluxbox()) ); +} + +void MainUI::RestartFluxbox(){ + QProcess::startDetached("killall fluxbox"); } diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.h b/src-qt5/core-utils/lumina-xconfig/MainUI.h index 5a1a62cc..69a2841a 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.h +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.h @@ -11,6 +11,8 @@ #include <QRect> #include <QString> #include <QList> +#include <QMdiArea> +#include <QMdiSubWindow> #include "ScreenSettings.h" @@ -34,20 +36,23 @@ public slots: private: Ui::MainUI *ui; QList<ScreenInfo> SCREENS; + double scaleFactor; ScreenInfo currentScreenInfo(); QStringList currentOpts(); + QString currentSelection(); void AddScreenToWidget(ScreenInfo); private slots: void UpdateScreens(); void ScreenSelected(); - void MoveScreenLeft(); - void MoveScreenRight(); + //void MoveScreenLeft(); + //void MoveScreenRight(); void DeactivateScreen(QString device = ""); void ActivateScreen(); void ApplyChanges(); //config changes + void RestartFluxbox(); }; #endif diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.ui b/src-qt5/core-utils/lumina-xconfig/MainUI.ui index de1cc18d..01bb032d 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.ui +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>408</width> - <height>321</height> + <width>560</width> + <height>548</height> </rect> </property> <property name="windowTitle"> @@ -18,44 +18,10 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QListWidget" name="list_screens"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>100</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>100</height> - </size> - </property> - <property name="flow"> - <enum>QListView::LeftToRight</enum> - </property> - <property name="viewMode"> - <enum>QListView::ListMode</enum> - </property> - <property name="uniformItemSizes"> - <bool>true</bool> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - <property name="selectionRectVisible"> - <bool>true</bool> - </property> - </widget> + <widget class="QMdiArea" name="mdiArea"/> </item> <item> - <layout class="QVBoxLayout" name="verticalLayout_3"> + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QToolButton" name="tool_deactivate"> <property name="text"> @@ -64,27 +30,7 @@ </widget> </item> <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QToolButton" name="tool_moveleft"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="tool_moveright"> + <widget class="QToolButton" name="tool_tile"> <property name="text"> <string>...</string> </property> @@ -170,16 +116,6 @@ </property> </spacer> </item> - <item> - <widget class="QToolButton" name="tool_applyconfig"> - <property name="text"> - <string>Apply Settings</string> - </property> - <property name="toolButtonStyle"> - <enum>Qt::ToolButtonTextBesideIcon</enum> - </property> - </widget> - </item> </layout> </item> <item row="1" column="1"> @@ -279,6 +215,16 @@ </spacer> </item> <item> + <widget class="QToolButton" name="tool_applyconfig"> + <property name="text"> + <string>Apply Settings</string> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="push_close"> <property name="text"> <string>Close</string> diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp index 91e1f498..6122c1a9 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp @@ -40,9 +40,9 @@ void RRSettings::ApplyPrevious(){ else{ avail << screens[i].ID; } //needed for some checks later - make it simple } //NOTE ABOUT orders: -1: check geom, -2: auto-add to end, -3: ignored - + //Quick checks for simple systems - just use current X config as-is - if(devs.isEmpty() && (avail.filter("LVDS").isEmpty() || screens.length()==1) ){ return; } + if(devs.isEmpty() && (avail.filter("LVDS").isEmpty() || screens.length()==1) ){ return; } //Typical ID's: LVDS-[], DVI-I-[], DP-[], HDMI-[], VGA-[] //"LVDS" is the built-in laptop display normally @@ -55,8 +55,8 @@ void RRSettings::ApplyPrevious(){ if(primary.isEmpty()){ primary = avail.first(); } } //Ensure only one monitor is primary, and reset a few flags - for(int i=0; i<screens.length(); i++){ - if(screens[i].ID!=primary){ screens[i].isprimary = false; } + for(int i=0; i<screens.length(); i++){ + if(screens[i].ID!=primary){ screens[i].isprimary = false; } screens[i].isactive = true; //we want all these monitors to be active eventually } // Handle all the available monitors @@ -85,9 +85,9 @@ void RRSettings::ApplyPrevious(){ } } //end loop over screens } - if(next>=0){ + if(next>=0){ cx+=screens[next].geom.width(); - screens[next].order = handled; handled++; + screens[next].order = handled; handled++; }else{ //Still missing monitors (vertical alignment?) qDebug() << "Unhandled Monitors:" << screens.length()-handled; @@ -106,10 +106,10 @@ QList<ScreenInfo> RRSettings::CurrentScreens(){ for(int i=0; i<info.length(); i++){ if(info[i].contains("connected") ){ //qDebug() << "xrandr info:" << info[i]; - if(!cscreen.ID.isEmpty()){ + if(!cscreen.ID.isEmpty()){ SCREENS << cscreen; //current screen finished - save it into the array - cscreen = ScreenInfo(); //Now create a new structure - } + cscreen = ScreenInfo(); //Now create a new structure + } //qDebug() << "Line:" << info[i]; QString dev = info[i].section(" ",0,0); //device ID //The device resolution can be either the 3rd or 4th output - check both @@ -173,7 +173,7 @@ bool RRSettings::SaveScreens(QList<ScreenInfo> screens){ } return true; } - + //Apply screen configuration void RRSettings::Apply(QList<ScreenInfo> screens){ //Read all the settings and create the xrandr options to maintain these settings @@ -188,4 +188,5 @@ void RRSettings::Apply(QList<ScreenInfo> screens){ } qDebug() << "Run command: xrandr" << opts; LUtils::runCmd("xrandr", opts); + //LUtils::runCmd("sleep 2; killall fluxbox"); //restart fluxbox as needed - it can't handle xrandr changes to the current session } |