diff options
author | Jesse Smith <jessefrgsmith@yahoo.ca> | 2014-09-06 17:28:06 -0300 |
---|---|---|
committer | Jesse Smith <jessefrgsmith@yahoo.ca> | 2014-09-06 17:28:06 -0300 |
commit | 31a2df51b78736da677fc61f9a09a93579cbdb7a (patch) | |
tree | 616df2cc9c7b53033c89cb48822251bcb029b21f | |
parent | Added volume control and initial screen brightness control code to Linux. Upd... (diff) | |
download | lumina-31a2df51b78736da677fc61f9a09a93579cbdb7a.tar.gz lumina-31a2df51b78736da677fc61f9a09a93579cbdb7a.tar.bz2 lumina-31a2df51b78736da677fc61f9a09a93579cbdb7a.zip |
Added audio volume control to Linux. Added initial code for changing screen brightness on Linux and updated dependnecy list. Added template file for future operating system support.
-rw-r--r-- | DEPENDENCIES | 3 | ||||
-rw-r--r-- | libLumina/LuminaOS-Linux.cpp | 62 | ||||
-rw-r--r-- | libLumina/libLumina.pro | 1 |
3 files changed, 60 insertions, 6 deletions
diff --git a/DEPENDENCIES b/DEPENDENCIES index 540831ee..0b3c7cf2 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -24,6 +24,9 @@ numlockx (x11/numlockx) libqt4-svg libxcomposite-dev + Optional Debian/Ubuntu/Mint packages + xbacklight (required for changing screen brightness) + === BUILD & RUN === Qt 4.8+ (modules: core, gui, network, linguist, svg) also includes: (qt4-qmake, qt4-uic, qt4-moc, qt4-rcc) diff --git a/libLumina/LuminaOS-Linux.cpp b/libLumina/LuminaOS-Linux.cpp index 9d891461..ce5b8240 100644 --- a/libLumina/LuminaOS-Linux.cpp +++ b/libLumina/LuminaOS-Linux.cpp @@ -5,10 +5,14 @@ // See the LICENSE file for full details //=========================================== #ifdef __linux__ +#include <QDebug> #include "LuminaOS.h" #include <unistd.h> #include <stdio.h> // Needed for BUFSIZ +//can't read xbrightness settings - assume invalid until set +static int screenbrightness = -1; + // ==== ExternalDevicePaths() ==== QStringList LOS::ExternalDevicePaths(){ //Returns: QStringList[<type>::::<filesystem>::::<path>] @@ -20,28 +24,74 @@ QStringList LOS::ExternalDevicePaths(){ //Read screen brightness information int LOS::ScreenBrightness(){ - //Returns: Screen Brightness as a percentage (0-100, with -1 for errors) - return -1; //not implemented yet for Linux + //Returns: Screen Brightness as a percentage (0-100, with -1 for errors) + if(screenbrightness==-1){ + if(QFile::exists("/tmp/.lumina-currentxbrightness")){ + int val = LUtils::readFile("/tmp/.lumina-currentxbrightness").join("").simplified().toInt(); + screenbrightness = val; + } + } + return screenbrightness; + } //Set screen brightness void LOS::setScreenBrightness(int percent){ - //not implemented yet for Linux + //ensure bounds + if(percent<0){percent=0;} + else if(percent>100){ percent=100; } + // float pf = percent/100.0; //convert to a decimel + //Run the command + QString cmd = "xbacklight -set %1"; + // cmd = cmd.arg( QString::number( int(65535*pf) ) ); + cmd = cmd.arg( QString::number( percent ) ); + int ret = LUtils::runCmd(cmd); + //Save the result for later + if(ret!=0){ screenbrightness = -1; } + else{ screenbrightness = percent; } + LUtils::writeFile("/tmp/.lumina-currentxbrightness", QStringList() << QString::number(screenbrightness), true); + } //Read the current volume int LOS::audioVolume(){ //Returns: audio volume as a percentage (0-100, with -1 for errors) - return -1; //Not implemented yet for Linux +QString info = LUtils::getCmdOutput("amixer get Master").join("").simplified();; + int out = -1; + int start_position, end_position; + QString current_volume; + if(!info.isEmpty()){ + start_position = info.indexOf("["); + end_position = info.indexOf("%"); + current_volume = info.mid(start_position + 1, (end_position - start_position) - 1); + out = current_volume.toInt(); + } + return out; + + } //Set the current volume void LOS::setAudioVolume(int percent){ - //not implemented yet for Linux + if(percent<0){percent=0;} + else if(percent>100){percent=100;} + QString info = "amixer -c 0 sset Master,0 " + QString::number(percent) + "%"; + if(!info.isEmpty()){ + //Run Command + LUtils::runCmd(info); + } + } //Change the current volume a set amount (+ or -) void LOS::changeAudioVolume(int percentdiff){ - //not implemented yet for Linux + int old_volume = audioVolume(); + int new_volume = old_volume + percentdiff; + if (new_volume < 0) + new_volume = 0; + if (new_volume > 100) + new_volume = 100; + qDebug() << "Setting new volume to: " << new_volume; + setAudioVolume(new_volume); } //Check if a graphical audio mixer is installed diff --git a/libLumina/libLumina.pro b/libLumina/libLumina.pro index fcf84980..9de16637 100644 --- a/libLumina/libLumina.pro +++ b/libLumina/libLumina.pro @@ -20,6 +20,7 @@ SOURCES += LuminaXDG.cpp \ LuminaX11.cpp \ LuminaOS-FreeBSD.cpp \ LuminaOS-Linux.cpp +# new OS support can be added here INCLUDEPATH += /usr/local/include |