diff options
Diffstat (limited to 'src-qt5/core-utils')
-rw-r--r-- | src-qt5/core-utils/lumina-config/LPlugins.cpp | 9 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-config/mainUI.cpp | 10 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.cpp | 18 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.h | 12 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/MainUI.ui | 13 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp | 191 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/ScreenSettings.h | 49 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/lumina-xconfig.pro | 6 | ||||
-rw-r--r-- | src-qt5/core-utils/lumina-xconfig/main.cpp | 16 |
9 files changed, 288 insertions, 36 deletions
diff --git a/src-qt5/core-utils/lumina-config/LPlugins.cpp b/src-qt5/core-utils/lumina-config/LPlugins.cpp index 629171e1..03490216 100644 --- a/src-qt5/core-utils/lumina-config/LPlugins.cpp +++ b/src-qt5/core-utils/lumina-config/LPlugins.cpp @@ -211,6 +211,13 @@ void LPlugins::LoadDesktopPlugins(){ info.ID = "systemmonitor"; info.icon = "cpu"; DESKTOP.insert(info.ID, info); + //RSS Reader Plugin + info = LPI(); //clear it + info.name = QObject::tr("RSS Reader"); + info.description = QObject::tr("Monitor RSS Feeds (Requires internet connection)"); + info.ID = "rssreader"; + info.icon = "application-rss+xml"; + DESKTOP.insert(info.ID, info); //Available QtQuick scripts /*QStringList quickID = LUtils::listQuickPlugins(); for(int i=0; i<quickID.length(); i++){ @@ -358,4 +365,4 @@ void LPlugins::LoadColorItems(){ info.description = QObject::tr("Color used for highlighting an item (more subdued)."); info.ID = "HIGHLIGHTDISABLECOLOR"; COLORS.insert(info.ID, info); -}
\ No newline at end of file +} diff --git a/src-qt5/core-utils/lumina-config/mainUI.cpp b/src-qt5/core-utils/lumina-config/mainUI.cpp index 5062a5ef..bd2bf695 100644 --- a/src-qt5/core-utils/lumina-config/mainUI.cpp +++ b/src-qt5/core-utils/lumina-config/mainUI.cpp @@ -1136,7 +1136,8 @@ void MainUI::changeDefaultEmail(){ desk.filePath=""; } //save the new app setting and adjust the button appearance - appsettings->setValue("default/email", desk.filePath); + LXDG::setDefaultAppForMime("application/email",desk.filePath); + // appsettings->setValue("default/email", desk.filePath); QString tmp = desk.filePath; if(tmp.endsWith(".desktop")){ bool ok = false; @@ -1200,7 +1201,8 @@ void MainUI::changeDefaultTerminal(){ desk.filePath="xterm"; } //save the new app setting and adjust the button appearance - sessionsettings->setValue("default-terminal", desk.filePath); + LXDG::setDefaultAppForMime("application/terminal",desk.filePath); + //sessionsettings->setValue("default-terminal", desk.filePath); QString tmp = desk.filePath; if(tmp.endsWith(".desktop")){ bool ok = false; @@ -1249,7 +1251,7 @@ void MainUI::loadDefaultSettings(){ ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") ); } // - Default Terminal - tmp = sessionsettings->value("default-terminal", "xterm").toString(); + tmp =LXDG::findDefaultAppForMime("application/terminal"); //sessionsettings->value("default-terminal", "xterm").toString(); if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings if(tmp.endsWith(".desktop")){ bool ok = false; @@ -1293,7 +1295,7 @@ void MainUI::loadDefaultSettings(){ ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") ); } // - Default Email Client - tmp = appsettings->value("default/email", "").toString(); + tmp = LXDG::findDefaultAppForMime("application/email"); //appsettings->value("default/email", "").toString(); if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings if(tmp.endsWith(".desktop")){ bool ok = false; diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp index f4aa1c49..2aed4d30 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.cpp +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.cpp @@ -54,6 +54,7 @@ QStringList MainUI::currentOpts(){ for(int i=0; i<SCREENS.length(); i++){ if(SCREENS[i].order <0){ continue; } //skip this screen - non-active opts << "--output" << SCREENS[i].ID << "--mode" << QString::number(SCREENS[i].geom.width())+"x"+QString::number(SCREENS[i].geom.height()); + if(SCREENS[i].isprimary){ opts << "--primary"; } if(SCREENS[i].order > 0){ //Get the ID of the previous screen QString id; @@ -79,8 +80,8 @@ ScreenInfo MainUI::currentScreenInfo(){ void MainUI::UpdateScreens(){ //First probe the server for current screens - SCREENS.clear(); - QStringList info = LUtils::getCmdOutput("xrandr -q"); + SCREENS = RRSettings::CurrentScreens(); + /*QStringList info = LUtils::getCmdOutput("xrandr -q"); ScreenInfo cscreen; for(int i=0; i<info.length(); i++){ if(info[i].contains("connected") ){ @@ -105,6 +106,7 @@ void MainUI::UpdateScreens(){ 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; @@ -121,9 +123,9 @@ void MainUI::UpdateScreens(){ //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 @@ -138,7 +140,7 @@ void MainUI::UpdateScreens(){ else if(SCREENS[i].geom.x()==xoffset){ 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 currrent order to it + SCREENS[i].order = cnum; //assign the current order to it cnum++; //get ready for the next one QListWidgetItem *it = new QListWidgetItem(); it->setTextAlignment(Qt::AlignCenter); @@ -170,6 +172,7 @@ void MainUI::UpdateScreens(){ } if(ui->list_screens->currentItem()==0){ ui->list_screens->setCurrentRow(0); } ScreenSelected(); //update buttons + RRSettings::SaveScreens(SCREENS); } void MainUI::ScreenSelected(){ @@ -196,6 +199,7 @@ void MainUI::ScreenSelected(){ else{ui->combo_resolution->addItem(res, res); } if(cur.resList[i].contains(cres)){ ui->combo_resolution->setCurrentIndex(i); } } + ui->check_primary->setChecked( cur.isprimary ); } } @@ -282,14 +286,16 @@ void MainUI::ApplyChanges(){ 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(); for(int i=0; i<SCREENS.length(); i++){ if(SCREENS[i].ID == it->whatsThis()){ 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(); } } //Now run the command QStringList opts = currentOpts(); LUtils::runCmd("xrandr", opts); QTimer::singleShot(500, this, SLOT(UpdateScreens()) ); -}
\ No newline at end of file +} diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.h b/src-qt5/core-utils/lumina-xconfig/MainUI.h index 0563c4ca..b8be8701 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.h +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.h @@ -12,17 +12,7 @@ #include <QString> #include <QList> -class ScreenInfo{ - public: - QString ID; - QRect geom; //screen geometry - int order; //left to right - QStringList resList; - ScreenInfo(){ - order = -1; //initial value is invalid - } - ~ScreenInfo(){} -}; +#include "ScreenSettings.h" namespace Ui{ class MainUI; diff --git a/src-qt5/core-utils/lumina-xconfig/MainUI.ui b/src-qt5/core-utils/lumina-xconfig/MainUI.ui index c1c4b614..de1cc18d 100644 --- a/src-qt5/core-utils/lumina-xconfig/MainUI.ui +++ b/src-qt5/core-utils/lumina-xconfig/MainUI.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>408</width> - <height>316</height> + <height>321</height> </rect> </property> <property name="windowTitle"> @@ -142,7 +142,7 @@ </item> </layout> </item> - <item row="1" column="1"> + <item row="2" column="1"> <spacer name="verticalSpacer_3"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -155,7 +155,7 @@ </property> </spacer> </item> - <item row="2" column="1"> + <item row="3" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <spacer name="horizontalSpacer_2"> @@ -182,6 +182,13 @@ </item> </layout> </item> + <item row="1" column="1"> + <widget class="QCheckBox" name="check_primary"> + <property name="text"> + <string>Primary Screen</string> + </property> + </widget> + </item> </layout> </widget> <widget class="QWidget" name="tab_new"> diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp new file mode 100644 index 00000000..c9a833c3 --- /dev/null +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp @@ -0,0 +1,191 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "ScreenSettings.h" +#include <LuminaUtils.h> +#include <QDebug> +#include <QSettings> + +//Reset current screen config to match previously-saved settings +void RRSettings::ApplyPrevious(){ + 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(screens[i].order>=0){screens[i].order = -1; } //reset all screen orders (need to re-check all) + 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].isactive = lastactive.contains(screens[i].ID); + screens[i].order = (screens[i].isactive ? -1 : -3); //check/ignore + set.endGroup(); + }else if(screens[i].isavailable){ + screens[i].order = -2; //needs activation/placement + }else{ + screens[i].order = -3; //ignored + } + //Now clean up the list as needed + if(screens[i].order < -2){ screens.removeAt(i); i--; } //just remove it (less to loop through later) + 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; } + + //Typical ID's: LVDS-[], DVI-I-[], DP-[], HDMI-[], VGA-[] + //"LVDS" is the built-in laptop display normally + if(primary.isEmpty()){ + QStringList priority; priority << "LVDS" << "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; } + screens[i].isactive = true; //we want all these monitors to be active eventually + } + // Handle all the available monitors + int handled = 0; + int cx = 0; //current x point + while(handled<screens.length()){ + //Go through horizontally and place monitors (TO-DO: Vertical placement not handled yet) + int next = -1; + int diff = -1; + for(int i=0; i<screens.length(); i++){ + if(screens[i].order==-1){ + if(diff<0 || ((screens[i].geom.x()-cx) < diff)){ + diff = screens[i].geom.x()-cx; + next = i; + } + } + }//end loop over screens + if(next<0){ + //Go through and start adding the non-assigned screens to the end + for(int i=0; i<screens.length(); i++){ + if(screens[i].order==-2){ + if(diff<0 || ((screens[i].geom.x()-cx) < diff)){ + diff = screens[i].geom.x()-cx; + next = i; + } + } + } //end loop over screens + } + if(next>=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); +} + +//Read the current screen config from xrandr +QList<ScreenInfo> RRSettings::CurrentScreens(){ + QList<ScreenInfo> SCREENS; + 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() ){ + //Device disconnected, but still active on X + cscreen.isavailable = false; + cscreen.isactive = true; + }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() ); + cscreen.isavailable = true; + cscreen.isactive = true; + }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 + cscreen.isavailable = true; + cscreen.isactive = false; + } + }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 primary info lines + if(!cscreen.ID.isEmpty()){ SCREENS << cscreen; } //make sure to add the last screen to the array + return SCREENS; +} + +//Save the screen config for later +bool RRSettings::SaveScreens(QList<ScreenInfo> screens){ + QSettings set("lumina-desktop","lumina-xconfig"); + set.beginGroup("MonitorSettings"); + //Setup a couple lists + QStringList olddevs = set.childGroups(); + QStringList active; + //Now go through all the current screens and save that info + for(int i=0; i<screens.length(); i++){ + olddevs.removeAll(screens[i].ID); //this is still a valid device + if(screens[i].isactive){ active << screens[i].ID; } + set.beginGroup(screens[i].ID); + set.setValue("geometry", screens[i].geom); + set.setValue("isprimary", screens[i].isprimary); + set.endGroup(); + } + set.setValue("lastActive",active); + //Clean up any old device settings (no longer available for this hardware) + for(int i=0; i<olddevs.length(); i++){ + set.remove(olddevs[i]); + } + return true; +} + +//Apply screen configuration +void RRSettings::Apply(QList<ScreenInfo> screens){ + //Read all the settings and create the xrandr options to maintain these settings + QStringList opts; + qDebug() << "Apply:" << screens.length(); + for(int i=0; i<screens.length(); i++){ + qDebug() << " -- Screen:" << i << screens[i].ID << screens[i].isactive << screens[i].order; + if(screens[i].order <0 || !screens[i].isactive){ continue; } //skip this screen - non-active + opts << "--output" << screens[i].ID << "--mode" << QString::number(screens[i].geom.width())+"x"+QString::number(screens[i].geom.height()); + //opts << "--pos" << QString::number(screens[i].geom.x())+"x"+QString::number(screens[i].geom.y()); + if(screens[i].isprimary){ opts << "--primary"; } + } + 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 new file mode 100644 index 00000000..770c4f95 --- /dev/null +++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.h @@ -0,0 +1,49 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_SCREEN_SETTINGS_BACKEND_H +#define _LUMINA_SCREEN_SETTINGS_BACKEND_H + +#include <QString> +#include <QList> +#include <QRect> + +class ScreenInfo{ + public: + QString ID; + QRect geom; //screen geometry + bool isprimary; + bool isactive; + bool isavailable; + int order; //left to right + QStringList resList; + + //Initial Defaults + ScreenInfo(){ + order = -1; //initial value is invalid + isprimary = false; + isactive = false; + isavailable = false; + } + ~ScreenInfo(){} +}; + +class RRSettings{ +public: + //Reset current screen config to match previously-saved settings + static void ApplyPrevious(); //generally performed on startup of the desktop + + //Read the current screen config from xrandr + static QList<ScreenInfo> CurrentScreens(); //reads xrandr information + + //Save the screen config for later + static bool SaveScreens(QList<ScreenInfo> screens); + + //Apply screen configuration + static void Apply(QList<ScreenInfo> screens); +}; + +#endif diff --git a/src-qt5/core-utils/lumina-xconfig/lumina-xconfig.pro b/src-qt5/core-utils/lumina-xconfig/lumina-xconfig.pro index 676f237c..2661c19b 100644 --- a/src-qt5/core-utils/lumina-xconfig/lumina-xconfig.pro +++ b/src-qt5/core-utils/lumina-xconfig/lumina-xconfig.pro @@ -9,9 +9,11 @@ target.path = $${L_BINDIR} TEMPLATE = app SOURCES += main.cpp \ - mainUI.cpp + mainUI.cpp \ + ScreenSettings.cpp -HEADERS += mainUI.h +HEADERS += mainUI.h \ + ScreenSettings.h FORMS += mainUI.ui diff --git a/src-qt5/core-utils/lumina-xconfig/main.cpp b/src-qt5/core-utils/lumina-xconfig/main.cpp index 699665fb..f30486f4 100644 --- a/src-qt5/core-utils/lumina-xconfig/main.cpp +++ b/src-qt5/core-utils/lumina-xconfig/main.cpp @@ -9,20 +9,18 @@ #include <LuminaUtils.h> #include <LuminaSingleApplication.h> +#include "ScreenSettings.h" int main(int argc, char ** argv) { - /*QStringList in; + bool CLIdone = false; for(int i=1; i<argc; i++){ //skip the first arg (app binary) - QString path = argv[i]; - if(path=="."){ - //Insert the current working directory - in << QDir::currentPath(); - }else{ - if(!path.startsWith("/")){ path.prepend(QDir::currentPath()+"/"); } - in << path; + if(QString(argv[i]) == "--reset-monitors"){ + RRSettings::ApplyPrevious(); + CLIdone = true; + break; } } - if(in.isEmpty()){ in << QDir::homePath(); }*/ + if(CLIdone){ return 0; } LTHEME::LoadCustomEnvSettings(); LSingleApplication a(argc, argv, "lumina-xconfig"); //loads translations inside constructor if( !a.isPrimaryProcess()){ return 0; } |