From 4473c070989a9e3835ad032e03e952cf2cb6b0fa Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 16 Aug 2017 15:23:22 -0400 Subject: Fix up a bit more of the new lumina-xconfig. --- src-qt5/core-utils/lumina-xconfig/MainUI.cpp | 156 +++++++-------------- src-qt5/core-utils/lumina-xconfig/MainUI.h | 7 +- src-qt5/core-utils/lumina-xconfig/MainUI.ui | 73 +++------- .../core-utils/lumina-xconfig/ScreenSettings.cpp | 50 ++----- src-qt5/core-utils/lumina-xconfig/ScreenSettings.h | 2 +- 5 files changed, 83 insertions(+), 205 deletions(-) (limited to 'src-qt5/core-utils') diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp index 9c110126..246fba62 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp @@ -16,10 +16,6 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); loadIcons(); scaleFactor = 1/15.0; //simple default value - //Fill the location list with the valid entries - ui->combo_location->clear(); - ui->combo_location->addItem(tr("Right Of"), "--right-of"); - ui->combo_location->addItem(tr("Left Of"), "--left-of"); ui->combo_rotation->clear(); ui->combo_rotation->addItem(tr("None"), 0); ui->combo_rotation->addItem(tr("Left"), -90); @@ -35,7 +31,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->tool_save, SIGNAL(clicked()), this, SLOT(SaveSettings()) ); connect(ui->tool_applyconfig, SIGNAL(clicked()), this, SLOT(ApplyChanges()) ); connect(ui->mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(ScreenSelected()) ); - connect(ui->tool_tile, SIGNAL(clicked()), ui->mdiArea, SLOT(tileSubWindows()) ); + connect(ui->tool_tile, SIGNAL(clicked()), this, SLOT(tileScreens()) ); + connect(ui->combo_availscreens, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewScreenResolutions()) ); QTimer::singleShot(0, this, SLOT(UpdateScreens()) ); } @@ -56,25 +53,6 @@ void MainUI::loadIcons(){ ui->tool_applyconfig->setIcon( LXDG::findIcon("dialog-ok-apply","") ); } -/*QStringList MainUI::currentOpts(){ - //Read all the settings and create the xrandr options to maintain these settings - QStringList opts; - for(int i=0; i 0){ - //Get the ID of the previous screen - QString id; - for(int j=0; jmdiArea->activeSubWindow(); if(tmp!=0){ return tmp->whatsThis(); } @@ -93,22 +71,17 @@ ScreenInfo MainUI::currentScreenInfo(){ } void MainUI::AddScreenToWidget(ScreenInfo screen){ - //qDebug() << "Add Screen To Widget:" << screen.ID << screen.geom; + 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->setWhatsThis(screen.ID); - //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()); @@ -117,9 +90,9 @@ void MainUI::AddScreenToWidget(ScreenInfo screen){ void MainUI::SyncBackend(){ QString item = currentSelection(); if(item.isEmpty()){ return; } //nothing to do - QString newres = ui->combo_resolution->currentData().toString(); + QString newres = ui->combo_resolution->currentData().toString().section("(",0,0).simplified(); if(newres.isEmpty()){ return; } //nothing to do - //qDebug() << "Apply Screen Changes" << it->whatsThis() << "->" << newres; + //qDebug() << "Apply Screen Changes" << item << "->" << newres; //Adjust the order of the two screens bool setprimary = ui->check_primary->isChecked(); QList windows = ui->mdiArea->subWindowList(); @@ -127,14 +100,15 @@ void MainUI::SyncBackend(){ 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()); + //qDebug() << " - New Geom:" << SCREENS[i].geom; SCREENS[i].rotation = ui->combo_rotation->currentData().toInt(); } - if(setprimary){ SCREENS[i].isprimary = SCREENS[i].ID==item; } + if(setprimary){ SCREENS[i].isprimary = (SCREENS[i].ID==item); } //Find the window associated with this screen for(int s=0; swhatsThis()==SCREENS[i].ID){ - SCREENS[i].geom.setTopLeft( windows[s]->geometry().topLeft()/scaleFactor ); - SCREENS[i].applyChange = (windows[s]->isEnabled() ? 0 : 1); //disabled window is one that will be removed + SCREENS[i].geom.moveTopLeft( windows[s]->geometry().topLeft()/scaleFactor ); + if(SCREENS[i].applyChange<1){ SCREENS[i].applyChange = (windows[s]->widget()->isEnabled() ? 0 : 1); } //disabled window is one that will be removed } } } @@ -159,36 +133,12 @@ void MainUI::UpdateScreens(){ for(int i=0; i xoffset){ - //Screen not aligned with previous screen edge - qDebug() << "Found mis-aligned screen:" << i << SCREENS[i].ID; - found = true; //make sure to look for the next one - xoffset = xoffset+SCREENS[i].geom.width(); //next number to look for - SCREENS[i].order = cnum; //assign the current order to it - cnum++; //get ready for the next one - AddScreenToWidget(SCREENS[i]); - } - } - }*/ //Now update the available/current screens in the UI ui->combo_availscreens->clear(); - ui->combo_cscreens->clear(); for(int i=0; icombo_availscreens->addItem(SCREENS[i].ID); - }else if(SCREENS[i].isactive){ - ui->combo_cscreens->addItem(SCREENS[i].ID); } } if(ui->combo_availscreens->count()<1){ @@ -201,7 +151,7 @@ void MainUI::UpdateScreens(){ } //if(ui->list_screens->currentItem()==0){ ui->list_screens->setCurrentRow(0); } ScreenSelected(); //update buttons - RRSettings::SaveScreens(SCREENS); + updateNewScreenResolutions(); } void MainUI::ScreenSelected(){ @@ -232,75 +182,65 @@ void MainUI::ScreenSelected(){ } } -/*void MainUI::MoveScreenLeft(){ - QListWidgetItem *item = ui->list_screens->currentItem(); - if(item==0){ return; } //no selection - //Get the current ID - QString CID = item->whatsThis(); - //Now get the ID of the one on the left - item = ui->list_screens->item( ui->list_screens->row(item)-1 ); - if(item == 0){ return; } //no item on the left (can't go left) - QString LID = item->whatsThis(); //left ID - //Adjust the order of the two screens +void MainUI::updateNewScreenResolutions(){ + QString id = ui->combo_availscreens->currentText(); for(int i=0; icombo_resolutions->clear(); + for(int r=0; rcombo_resolutions->addItem(SCREENS[i].resList[r].section(" ",0,0, QString::SectionSkipEmpty)); + if(SCREENS[i].resList[r].contains("+")){ ui->combo_resolutions->setCurrentIndex(r); } //preferred resolution + } + break; + } } - //Now run the command - QStringList opts = currentOpts(); - LUtils::runCmd("xrandr", opts); - //Now run the command - //LUtils::runCmd("xrandr", QStringList() << "--output" << CID << "--left-of" << LID); - QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); -}*/ +} -/*void MainUI::MoveScreenRight(){ - QListWidgetItem *item = ui->list_screens->currentItem(); - if(item==0){ return; } //no selection - //Get the current ID - QString CID = item->whatsThis(); - //Now get the ID of the one on the left - item = ui->list_screens->item( ui->list_screens->row(item)+1 ); - if(item == 0){ return; } //no item on the right (can't go right) - QString RID = item->whatsThis(); //right ID - //Adjust the order of the two screens - for(int i=0; i wins = ui->mdiArea->subWindowList(); + QRegion total; + int xpos, ypos; + xpos = ypos = 0; + QMdiSubWindow *cur = 0; + float diff; + while(!wins.isEmpty()){ + cur=0; + diff = -1; + //Scan for the window closest to the current X value + for(x=0; xgeometry().y()geometry().y() && wins[y]->geometry().y()>ypos){ cur = wins[y]; } + } + } + if(cur!=0){ + + } } - //Now run the command - QStringList opts = currentOpts(); - LUtils::runCmd("xrandr", opts); - QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); -}*/ +} -void MainUI::DeactivateScreen(QString device){ +void MainUI::DeactivateScreen(){ QMdiSubWindow *cur = ui->mdiArea->currentSubWindow(); if(cur==0){ return; } - cur->setEnabled( !cur->isEnabled() ); //toggle it between enabled/disabled + cur->widget()->setEnabled( !cur->widget()->isEnabled() ); //toggle it between enabled/disabled } void MainUI::ActivateScreen(){ //Assemble the command; QString ID = ui->combo_availscreens->currentText(); + QStringList res = ui->combo_resolutions->currentText().split("x"); //Find the screen infor associated with this ID for(int i=0; icombo_cscreens->currentText(); - QString loc = ui->combo_location->currentData().toString(); - if(ID.isEmpty() || DID.isEmpty() || loc.isEmpty()){ return; } //invalid inputs - QStringList opts = currentOpts(); - opts << "--output" << ID << loc << DID <<"--auto"; - //qDebug() << "Activate Options:" << opts; - LUtils::runCmd("xrandr", opts ); - QTimer::singleShot(500, this, SLOT(UpdateScreens()) );*/ } void MainUI::ApplyChanges(){ diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.h b/src-qt5/core-utils/lumina-xconfig/MainUI.h index 3a6c9f3f..9a54304a 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.h +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.h @@ -48,9 +48,10 @@ private: private slots: void UpdateScreens(); void ScreenSelected(); - //void MoveScreenLeft(); - //void MoveScreenRight(); - void DeactivateScreen(QString device = ""); + void updateNewScreenResolutions(); + void tileScreens(); + + void DeactivateScreen(); void ActivateScreen(); void ApplyChanges(); //config changes void SaveSettings(); diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.ui b/src-qt5/core-utils/lumina-xconfig/MainUI.ui index 7febb0fd..8a655589 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.ui +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.ui @@ -18,7 +18,14 @@ - + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAsNeeded + + @@ -79,7 +86,7 @@ - 0 + 1 @@ -124,36 +131,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -167,6 +144,9 @@ + + + @@ -174,9 +154,6 @@ - - - @@ -196,6 +173,13 @@ Available Screens + + + + Enable Screen + + + @@ -204,26 +188,12 @@ - + Location to insert the screen - - - - Current screens - - - - - - - Enable Screen - - - @@ -285,7 +255,8 @@ Save - + + .. Qt::ToolButtonTextBesideIcon diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp index 9bad91db..99cfc918 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp @@ -50,43 +50,7 @@ void RRSettings::ApplyPrevious(){ //Ensure only one monitor is primary, and reset a few flags for(int i=0; i=0){ - cx+=screens[next].geom.width(); - screens[next].order = handled; handled++; - }else{ - //Still missing monitors (vertical alignment?) - qDebug() << "Unhandled Monitors:" << screens.length()-handled; - break; - } - }*/ //Now reset the display with xrandr RRSettings::Apply(screens); } @@ -111,7 +75,7 @@ QList RRSettings::CurrentScreens(){ if(!devres.contains("x")){ devres.clear(); } //Pull the monitor rotation mode out as well (last word before the parenthesis) QString devrotate = info[i].section("(",0,0).split(" ",QString::SkipEmptyParts).last(); - qDebug() << " - ID:" < RRSettings::CurrentScreens(){ }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 << devrotate << info[i].section("(",0,0); + //qDebug() << "Create new Screen entry:" << dev << devres << devrotate << info[i].section("(",0,0); cscreen.ID = dev; //Note: devres format: "x++" 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() ); @@ -134,7 +98,7 @@ QList RRSettings::CurrentScreens(){ else{ cscreen.rotation = 0; } }else if(info[i].contains(" connected")){ //Device that is connected, but not attached - qDebug() << "Create new Screen entry:" << dev << "none"; + //qDebug() << "Create new Screen entry:" << dev << "none"; cscreen.ID = dev; //cscreen.order = -2; //flag this right now as a non-active screen cscreen.isavailable = true; @@ -181,9 +145,11 @@ void RRSettings::Apply(QList screens){ //qDebug() << "Apply:" << screens.length(); for(int i=0; i screens){ else{ opts << "--rotate" << "normal"; } if(screens[i].isprimary){ opts << "--primary"; } } - //qDebug() << "Run command: xrandr" << opts; + qDebug() << "Run command: xrandr" << opts; LUtils::runCmd("xrandr", opts); } diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h index 9371e361..b1b9cad9 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h @@ -19,7 +19,7 @@ class ScreenInfo{ bool isprimary; bool isactive; bool isavailable; - int applyChange; //[<=0: do nothing, 1: deactivate] + int applyChange; //[<=0: do nothing, 1: deactivate, 2: activate] QStringList resList; int rotation; //possible values: [-90, 0, 90, 180] -- cgit