aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp')
-rw-r--r--src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp101
1 files changed, 36 insertions, 65 deletions
diff --git a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp
index 91e1f498..99cfc918 100644
--- a/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp
+++ b/src-qt5/core-utils/lumina-xconfig/ScreenSettings.cpp
@@ -21,33 +21,26 @@ void RRSettings::ApplyPrevious(){
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
+ 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].isavailable){
- screens[i].order = -2; //needs activation/placement
- }else{
- screens[i].order = -3; //ignored
+ }else if(screens[i].isactive){
+ screens[i].applyChange = 1; //disable monitor - not enabled in the default settings
}
- //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; }
+ 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
+ //"LVDS" or "eDP" is the built-in laptop display normally
if(primary.isEmpty()){
- QStringList priority; priority << "LVDS" << "DP" << "HDMI" << "DVI" << "VGA";
+ 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(); }
@@ -55,44 +48,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; }
- 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;
- }
+ for(int i=0; i<screens.length(); i++){
+ if(screens[i].ID!=primary){ screens[i].isprimary = false; }
}
//Now reset the display with xrandr
RRSettings::Apply(screens);
@@ -106,17 +63,19 @@ 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
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;
+ //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:" <<dev << "Current Geometry:" << devres;
//qDebug() << " - Res:" << devres;
if( !devres.contains("x") || !devres.contains("+") ){ devres.clear(); }
//qDebug() << " - Res (modified):" << devres;
@@ -127,17 +86,21 @@ QList<ScreenInfo> 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;
+ //qDebug() << "Create new Screen entry:" << dev << devres << devrotate << info[i].section("(",0,0);
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;
+ if(devrotate=="left"){ cscreen.rotation = -90; }
+ else if(devrotate=="right"){ cscreen.rotation = 90; }
+ else if(devrotate=="inverted"){ cscreen.rotation = 180; }
+ 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.order = -2; //flag this right now as a non-active screen
cscreen.isavailable = true;
cscreen.isactive = false;
}
@@ -164,6 +127,7 @@ bool RRSettings::SaveScreens(QList<ScreenInfo> screens){
set.beginGroup(screens[i].ID);
set.setValue("geometry", screens[i].geom);
set.setValue("isprimary", screens[i].isprimary);
+ set.setValue("rotation", screens[i].rotation);
set.endGroup();
}
set.setValue("lastActive",active);
@@ -173,17 +137,24 @@ 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
QStringList opts;
- qDebug() << "Apply:" << screens.length();
+ //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());
+ qDebug() << " -- Screen:" << i << screens[i].ID << screens[i].isactive;
+ if( !screens[i].isactive){ continue; } //skip this screen - non-active
+ else if(screens[i].applyChange==1){ opts << "--output" << screens[i].ID << "--off"; continue; } //deactivate a screen
+ opts << "--output" << screens[i].ID;
+ if(screens[i].applyChange==2){ opts << "--auto"; }
+ else{ opts << "--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].rotation==-90){ opts << "--rotate" << "left"; }
+ else if(screens[i].rotation==90){ opts << "--rotate" << "right"; }
+ else if(screens[i].rotation==180){ opts << "--rotate" << "inverted"; }
+ else{ opts << "--rotate" << "normal"; }
if(screens[i].isprimary){ opts << "--primary"; }
}
qDebug() << "Run command: xrandr" << opts;
bgstack15