diff options
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.cpp | 62 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.h | 9 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.ui | 125 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp | 108 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/ScreenSettings.h | 5 |
5 files changed, 240 insertions, 69 deletions
diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp index 1a3662fe..aecc5122 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp @@ -11,6 +11,8 @@ #include <LUtils.h> #include <QTimer> +#include <QInputDialog> +#include <QLineEdit> MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); @@ -28,6 +30,10 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ singleTileMenu->addAction(tr("Align Horizontal then Vertical"))->setWhatsThis("XY"); singleTileMenu->addAction(tr("Align Vertical then Horizontal"))->setWhatsThis("YX"); ui->mdiArea->setContextMenuPolicy(Qt::CustomContextMenu); + + profilesMenu = new QMenu(this); + ui->tool_save->setMenu(profilesMenu); + connect(ui->mdiArea, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu()) ); connect(singleTileMenu, SIGNAL(triggered(QAction*)), this, SLOT(tileSingleScreen(QAction*)) ); @@ -43,6 +49,12 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->tool_tileY, SIGNAL(clicked()), this, SLOT(tileScreensY()) ); connect(ui->tool_tile, SIGNAL(clicked()), this, SLOT(tileScreens()) ); connect(ui->combo_availscreens, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewScreenResolutions()) ); + + connect(ui->tool_profile_load, SIGNAL(clicked()), this, SLOT(loadProfile()) ); + connect(ui->tool_profile_remove, SIGNAL(clicked()), this, SLOT(removeProfile()) ); + connect(profilesMenu, SIGNAL(triggered(QAction*)), this, SLOT(saveAsProfile(QAction*)) ); + + updateProfiles(); QTimer::singleShot(0, this, SLOT(UpdateScreens()) ); } @@ -126,9 +138,11 @@ void MainUI::SyncBackend(){ } } -void MainUI::UpdateScreens(){ +void MainUI::UpdateScreens(QString profile){ //First probe the server for current screens - SCREENS = RRSettings::CurrentScreens(); + if(profile.isEmpty()){ SCREENS = RRSettings::CurrentScreens(); } + else{ SCREENS = RRSettings::PreviousSettings(profile); } + //Determine the scale factor for putting these into the UI QRegion tot; for(int i=0; i<SCREENS.length(); i++){ @@ -397,3 +411,47 @@ void MainUI::SaveSettings(){ void MainUI::RestartFluxbox(){ QProcess::startDetached("killall fluxbox"); } + +void MainUI::removeProfile(){ + QString cur = ui->combo_profiles->currentText(); + RRSettings::removeProfile(cur); + updateProfiles(); +} + +void MainUI::updateProfiles(){ + QStringList profiles = RRSettings::savedProfiles(); + ui->combo_profiles->clear(); + profiles.sort(); + ui->combo_profiles->addItems(profiles); + //Update the profiles menu as needed + profilesMenu->clear(); + for(int i=0; i<profiles.length(); i++){ + profilesMenu->addAction(profiles[i])->setWhatsThis(profiles[i]); + } + if(!profiles.isEmpty()){ profilesMenu->addSeparator(); } + profilesMenu->addAction(tr("New Profile") ); + + //Now update the tab as needed + ui->tabWidget->setTabEnabled(2,!profiles.isEmpty()); + if(ui->tabWidget->currentIndex()==2){ ui->tabWidget->setCurrentIndex(0); } +} + +void MainUI::loadProfile(){ + QString cur = ui->combo_profiles->currentText(); + UpdateScreens(cur); +} + +void MainUI::saveAsProfile(QAction *act){ + QString profile = act->whatsThis(); + if(profile.isEmpty()){ + //Need to prompt for a profile name + QStringList known = RRSettings::savedProfiles(); + while(known.contains(profile) || profile.isEmpty()){ + bool ok = false; + profile = QInputDialog::getText(this, tr("Create Screen Profile"), profile.isEmpty() ? tr("Profile Name") : tr("Profile exists - different name:"), QLineEdit::Normal, profile, &ok); + if(!ok || profile.isEmpty()){ return; } //cancelled + } + } + RRSettings::SaveScreens(SCREENS, profile); + updateProfiles(); +} diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.h b/src-qt5/core-utils/lumina-xconfig/MainUI.h index d1abc153..53bf06db 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.h +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.h @@ -39,7 +39,7 @@ private: Ui::MainUI *ui; QList<ScreenInfo> SCREENS; double scaleFactor; - QMenu *singleTileMenu; + QMenu *singleTileMenu, *profilesMenu; ScreenInfo currentScreenInfo(); @@ -50,7 +50,7 @@ private: void SyncBackend(); //sync backend structures to current settings private slots: - void UpdateScreens(); + void UpdateScreens(QString profile = ""); void ScreenSelected(); void updateNewScreenResolutions(); void tileScreensY(bool activeonly = false); @@ -64,6 +64,11 @@ private slots: void ApplyChanges(); //config changes void SaveSettings(); void RestartFluxbox(); + + void removeProfile(); + void updateProfiles(); + void loadProfile(); + void saveAsProfile(QAction *); }; #endif diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.ui b/src-qt5/core-utils/lumina-xconfig/MainUI.ui index 872df95b..b6ef4383 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.ui +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.ui @@ -30,6 +30,19 @@ <item> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> + <widget class="QToolButton" name="push_rescan"> + <property name="toolTip"> + <string>Refresh Screens</string> + </property> + <property name="text"> + <string>Refresh Screens</string> + </property> + <property name="icon"> + <iconset theme="view-refresh"/> + </property> + </widget> + </item> + <item> <widget class="QToolButton" name="tool_deactivate"> <property name="toolTip"> <string>Disable Current Screen</string> @@ -37,6 +50,9 @@ <property name="text"> <string notr="true">...</string> </property> + <property name="icon"> + <iconset theme="list-remove"/> + </property> </widget> </item> <item> @@ -71,7 +87,8 @@ <string notr="true">...</string> </property> <property name="icon"> - <iconset theme="format-view-column"/> + <iconset theme="format-view-column"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -81,7 +98,8 @@ <string notr="true">...</string> </property> <property name="icon"> - <iconset theme="format-view-agenda"/> + <iconset theme="format-view-agenda"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -106,7 +124,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>1</number> + <number>2</number> </property> <widget class="QWidget" name="tab_config"> <attribute name="title"> @@ -219,6 +237,53 @@ </item> </layout> </widget> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Profiles</string> + </attribute> + <layout class="QFormLayout" name="formLayout_2"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Profiles</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="combo_profiles"/> + </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QToolButton" name="tool_profile_load"> + <property name="text"> + <string>Preview</string> + </property> + <property name="icon"> + <iconset theme="view-restore"/> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_profile_remove"> + <property name="text"> + <string>Delete</string> + </property> + <property name="icon"> + <iconset theme="view-close"/> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> </widget> </item> <item> @@ -237,27 +302,13 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QPushButton" name="push_rescan"> - <property name="text"> - <string>Refresh Screens</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="QToolButton" name="tool_applyconfig"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Apply</string> </property> @@ -268,6 +319,12 @@ </item> <item> <widget class="QToolButton" name="tool_save"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="toolTip"> <string>Save current settings as user defaults</string> </property> @@ -278,13 +335,35 @@ <iconset theme="document-save"> <normaloff>.</normaloff>.</iconset> </property> + <property name="popupMode"> + <enum>QToolButton::MenuButtonPopup</enum> + </property> <property name="toolButtonStyle"> <enum>Qt::ToolButtonTextBesideIcon</enum> </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="QPushButton" name="push_close"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> <string>Close</string> </property> diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp index 99cfc918..f962f7d7 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp @@ -11,46 +11,11 @@ //Reset current screen config to match previously-saved settings void RRSettings::ApplyPrevious(){ + QList<ScreenInfo> screens; QSettings set("lumina-desktop","lumina-xconfig"); - set.beginGroup("MonitorSettings"); - //Setup a couple lists - QStringList devs = set.childGroups(); //known/saved devices - QList<ScreenInfo> screens = RRSettings::CurrentScreens(); - QStringList lastactive = set.value("lastActive",QStringList()).toStringList(); - //Now go through all the saved settings and put that info into the array - QString primary; - QStringList avail; - for(int i=0; i<screens.length(); i++){ - if(devs.contains(screens[i].ID) && screens[i].isavailable){ //only load settings for monitors which are currently attached - set.beginGroup(screens[i].ID); - screens[i].geom = set.value("geometry", QRect()).toRect(); - screens[i].isprimary = set.value("isprimary", false).toBool(); - if(screens[i].isprimary){ primary = screens[i].ID; } - screens[i].applyChange = (screens[i].isactive && !lastactive.contains(screens[i].ID) ? 1 : 0); //disable/ignore - screens[i].rotation = set.value("rotation",0).toInt(); - set.endGroup(); - }else if(screens[i].isactive){ - screens[i].applyChange = 1; //disable monitor - not enabled in the default settings - } - } - - //Quick checks for simple systems - just use current X config as-is - if(devs.isEmpty() && (avail.filter("LVDS").isEmpty() || screens.length()==1) ){ return; } - - //Typical ID's: LVDS-[], DVI-I-[], DP-[], HDMI-[], VGA-[] - //"LVDS" or "eDP" is the built-in laptop display normally - if(primary.isEmpty()){ - QStringList priority; priority << "LVDS" << "eDP" << "DP" << "HDMI" << "DVI" << "VGA"; - for(int i=0; i<priority.length() && primary.isEmpty(); i++){ - QStringList filter = avail.filter(priority[i]); - if(!filter.isEmpty()){ filter.sort(); primary = filter.first(); } - } - 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; } - } + QString profile = set.value("default_profile","").toString(); + if(profile.isEmpty() || !savedProfiles().contains(profile) ){ screens = PreviousSettings(); } + else{ screens = PreviousSettings(profile); } //Now reset the display with xrandr RRSettings::Apply(screens); } @@ -113,10 +78,71 @@ QList<ScreenInfo> RRSettings::CurrentScreens(){ return SCREENS; } +QList<ScreenInfo> RRSettings::PreviousSettings(QString profile){ + QSettings set("lumina-desktop","lumina-xconfig"); + if(profile.isEmpty()){ set.beginGroup("MonitorSettings"); } + else{ set.beginGroup("MonitorProfiles/"+profile); } + //Setup a couple lists + QStringList devs = set.childGroups(); //known/saved devices + QList<ScreenInfo> screens = RRSettings::CurrentScreens(); + QStringList lastactive = set.value("lastActive",QStringList()).toStringList(); + //Now go through all the saved settings and put that info into the array + QString primary; + QStringList avail; + for(int i=0; i<screens.length(); i++){ + if(devs.contains(screens[i].ID) && screens[i].isavailable){ //only load settings for monitors which are currently attached + set.beginGroup(screens[i].ID); + screens[i].geom = set.value("geometry", QRect()).toRect(); + screens[i].isprimary = set.value("isprimary", false).toBool(); + if(screens[i].isprimary){ primary = screens[i].ID; } + screens[i].applyChange = (screens[i].isactive && !lastactive.contains(screens[i].ID) ? 1 : 0); //disable/ignore + screens[i].rotation = set.value("rotation",0).toInt(); + set.endGroup(); + }else if(screens[i].isactive){ + screens[i].applyChange = 1; //disable monitor - not enabled in the default settings + } + } + + //Quick checks for simple systems - just use current X config as-is + if(devs.isEmpty() && (avail.filter("LVDS").isEmpty() || screens.length()==1) ){ return screens; } + + //Typical ID's: LVDS-[], DVI-I-[], DP-[], HDMI-[], VGA-[] + //"LVDS" or "eDP" is the built-in laptop display normally + if(primary.isEmpty()){ + QStringList priority; priority << "LVDS" << "eDP" << "DP" << "HDMI" << "DVI" << "VGA"; + for(int i=0; i<priority.length() && primary.isEmpty(); i++){ + QStringList filter = avail.filter(priority[i]); + if(!filter.isEmpty()){ filter.sort(); primary = filter.first(); } + } + 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; } + } + return screens; +} + +QStringList RRSettings::savedProfiles(){ + QSettings set("lumina-desktop","lumina-xconfig"); + set.beginGroup("MonitorProfiles"); + return set.childGroups(); +} + +void RRSettings::removeProfile(QString profile){ + QSettings set("lumina-desktop","lumina-xconfig"); + set.beginGroup("MonitorProfiles"); + QStringList known = set.childGroups(); + if(known.contains(profile) && !profile.isEmpty()){ + set.remove(profile); + } +} + //Save the screen config for later -bool RRSettings::SaveScreens(QList<ScreenInfo> screens){ +bool RRSettings::SaveScreens(QList<ScreenInfo> screens, QString profile){ QSettings set("lumina-desktop","lumina-xconfig"); - set.beginGroup("MonitorSettings"); + if(profile.isEmpty()){ set.beginGroup("MonitorSettings"); } + else{ set.beginGroup("MonitorProfiles/"+profile); } //Setup a couple lists QStringList olddevs = set.childGroups(); QStringList active; diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h index b1b9cad9..ab480a97 100644 --- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h @@ -42,9 +42,12 @@ public: //Read the current screen config from xrandr static QList<ScreenInfo> CurrentScreens(); //reads xrandr information + static QList<ScreenInfo> PreviousSettings(QString profile=""); + static QStringList savedProfiles(); + static void removeProfile(QString profile); //Save the screen config for later - static bool SaveScreens(QList<ScreenInfo> screens); + static bool SaveScreens(QList<ScreenInfo> screens, QString profile = ""); //Apply screen configuration static void Apply(QList<ScreenInfo> screens); |