diff options
author | Ken Moore <ken@pcbsd.org> | 2015-04-22 11:04:53 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-04-22 11:04:53 -0400 |
commit | a02f2f5025d089401025c092963eef823cfe3726 (patch) | |
tree | 1351530776f8877d68f19e7fbc6d8829529d5bf9 /libLumina/LuminaOS-FreeBSD.cpp | |
parent | Clean up the new lumina-fileinfo utility. (diff) | |
download | lumina-a02f2f5025d089401025c092963eef823cfe3726.tar.gz lumina-a02f2f5025d089401025c092963eef823cfe3726.tar.bz2 lumina-a02f2f5025d089401025c092963eef823cfe3726.zip |
Move the initial screen brightness and volume setting routines into the session initialization (out of the system dashboard plugin).
Diffstat (limited to 'libLumina/LuminaOS-FreeBSD.cpp')
-rw-r--r-- | libLumina/LuminaOS-FreeBSD.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp index c9874605..39eae307 100644 --- a/libLumina/LuminaOS-FreeBSD.cpp +++ b/libLumina/LuminaOS-FreeBSD.cpp @@ -11,6 +11,7 @@ #include <QDebug> //can't read xbrightness settings - assume invalid until set static int screenbrightness = -1; +static int audiovolume = -1; QString LOS::OSName(){ return "FreeBSD"; } @@ -95,14 +96,31 @@ void LOS::setScreenBrightness(int percent){ //Read the current volume int LOS::audioVolume(){ //Returns: audio volume as a percentage (0-100, with -1 for errors) - QString info = LUtils::getCmdOutput("mixer -S vol").join(":").simplified(); //ignores any other lines - int out = -1; - if(!info.isEmpty()){ - int L = info.section(":",1,1).toInt(); - int R = info.section(":",2,2).toInt(); - if(L>R){ out = L; } - else{ out = R; } + int out = audiovolume; + if(out < 0){ + //First time session check: Load the last setting for this user + QString info = LUtils::readFile(QDir::homePath()+"/.lumina/.currentvolume").join(""); + if(!info.isEmpty()){ + out = info.simplified().toInt(); + audiovolume = out; //unset this internal flag + return out; + } } + + //probe the system for the current volume (other utils could be changing it) + QString info = LUtils::getCmdOutput("mixer -S vol").join(":").simplified(); //ignores any other lines + if(!info.isEmpty()){ + int L = info.section(":",1,1).toInt(); + int R = info.section(":",2,2).toInt(); + if(L>R){ out = L; } + else{ out = R; } + if(out != audiovolume){ + //Volume changed by other utility: adjust the saved value as well + LUtils::writeFile(QDir::homePath()+"/.lumina/.currentvolume", QStringList() << QString::number(out), true); + } + audiovolume = out; + } + return out; } @@ -115,13 +133,16 @@ void LOS::setAudioVolume(int percent){ int L = info.section(":",1,1).toInt(); int R = info.section(":",2,2).toInt(); int diff = L-R; + if((percent == L) && (L==R)){ return; } //already set to that volume if(diff<0){ R=percent; L=percent+diff; } //R Greater else{ L=percent; R=percent-diff; } //L Greater or equal //Check bounds if(L<0){L=0;}else if(L>100){L=100;} if(R<0){R=0;}else if(R>100){R=100;} //Run Command + audiovolume = percent; //save for checking later LUtils::runCmd("mixer vol "+QString::number(L)+":"+QString::number(R)); + LUtils::writeFile(QDir::homePath()+"/.lumina/.currentvolume", QStringList() << QString::number(percent), true); } } |