diff options
author | Michael Neumann <mneumann@ntecs.de> | 2015-08-16 16:13:14 +0200 |
---|---|---|
committer | Michael Neumann <mneumann@ntecs.de> | 2015-08-16 16:13:14 +0200 |
commit | 3756041e8abafad21f0bff253aa2bce0fca3feba (patch) | |
tree | 8f303077fe92a526de55b9f4df4aaa11c5e02ff0 /libLumina/LuminaOS-DragonFly.cpp | |
parent | DragonFly: Sync get/set ScreenBrightness a bit with FreeBSD (diff) | |
download | lumina-3756041e8abafad21f0bff253aa2bce0fca3feba.tar.gz lumina-3756041e8abafad21f0bff253aa2bce0fca3feba.tar.bz2 lumina-3756041e8abafad21f0bff253aa2bce0fca3feba.zip |
DragonFly: Sync get/set audio volume with FreeBSD
Diffstat (limited to 'libLumina/LuminaOS-DragonFly.cpp')
-rw-r--r-- | libLumina/LuminaOS-DragonFly.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/libLumina/LuminaOS-DragonFly.cpp b/libLumina/LuminaOS-DragonFly.cpp index 2f9beb4b..f0e54ff7 100644 --- a/libLumina/LuminaOS-DragonFly.cpp +++ b/libLumina/LuminaOS-DragonFly.cpp @@ -10,6 +10,7 @@ //can't read xbrightness settings - assume invalid until set static int screenbrightness = -1; +static int audiovolume = -1; QString LOS::OSName(){ return "DragonFly BSD"; } @@ -85,14 +86,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) + 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 - 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; } + 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; } @@ -105,14 +123,17 @@ 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); + } } //Change the current volume a set amount (+ or -) |