@ -20,8 +20,8 @@ enum CommandLineParseResult
CommandLineHelpRequested
} ;
struct ColorOption {
ColorOption ( ) :
struct ColorPreset Option {
ColorPreset Option ( ) :
region ( REGION_LEFT )
, color ( COLOR_RED )
, intensity ( INTENSITY_HIGH )
@ -32,18 +32,32 @@ struct ColorOption {
Intensity intensity ;
} ;
struct ColorOption {
ColorOption ( ) :
region ( TOUCHPAD )
, rgb { 0 , 0 , 0 }
{ }
Region region ;
char rgb [ 3 ] ;
} ;
struct KeyboardOptions {
KeyboardOptions ( ) :
modeOption ( MODE_NORMAL )
, colorOptions ( )
, modeSet ( false )
, colorSet ( false )
, presetSet ( false )
{ }
Mode modeOption ;
QList < ColorPresetOption * > presetOptions ;
QList < ColorOption * > colorOptions ;
bool modeSet ;
bool colorSet ;
bool presetSet ;
void setMode ( QString mode ) {
if ( mode = = " normal " ) { modeOption = MODE_NORMAL ; }
@ -55,7 +69,7 @@ struct KeyboardOptions {
modeSet = true ;
}
void setColor ( QString colorString ) {
void setColorPreset ( QString colorString ) {
QStringList fields = colorString . split ( ' , ' ) ;
if ( fields . count ( ) ! = 3 ) {
@ -68,27 +82,67 @@ struct KeyboardOptions {
QString color = fields . at ( 1 ) ;
QString intensity = fields . at ( 2 ) ;
ColorPresetOption * presetOption = new ColorPresetOption ;
if ( region = = " left " ) presetOption - > region = REGION_LEFT ;
else if ( region = = " middle " ) presetOption - > region = REGION_MIDDLE ;
else if ( region = = " right " ) presetOption - > region = REGION_RIGHT ;
else {
std : : cerr < < " invalid region selection " < < std : : endl ;
qApp - > quit ( ) ;
return ;
}
if ( color = = " off " ) presetOption - > color = COLOR_OFF ;
if ( color = = " red " ) presetOption - > color = COLOR_RED ;
if ( color = = " orange " ) presetOption - > color = COLOR_ORANGE ;
if ( color = = " yellow " ) presetOption - > color = COLOR_YELLOW ;
if ( color = = " green " ) presetOption - > color = COLOR_GREEN ;
if ( color = = " sky " ) presetOption - > color = COLOR_SKY ;
if ( color = = " blue " ) presetOption - > color = COLOR_BLUE ;
if ( color = = " purple " ) presetOption - > color = COLOR_PURPLE ;
if ( color = = " white " ) presetOption - > color = COLOR_WHITE ;
if ( intensity = = " high " ) presetOption - > intensity = INTENSITY_HIGH ;
if ( intensity = = " medium " ) presetOption - > intensity = INTENSITY_MEDIUM ;
if ( intensity = = " low " ) presetOption - > intensity = INTENSITY_LOW ;
if ( intensity = = " light " ) presetOption - > intensity = INTENSITY_LIGHT ;
presetSet = true ;
presetOptions . append ( presetOption ) ;
}
void setColor ( QString colorString ) {
QStringList fields = colorString . split ( ' , ' ) ;
if ( fields . count ( ) ! = 4 ) {
std : : cerr < < " invalid color selection " < < std : : endl ;
qApp - > quit ( ) ;
return ;
}
QString region = fields . at ( 0 ) ;
ColorOption * colorOption = new ColorOption ;
if ( region = = " left " ) colorOption - > region = REGION_LEFT ;
if ( region = = " middle " ) colorOption - > region = REGION_MIDDLE ;
if ( region = = " right " ) colorOption - > region = REGION_RIGHT ;
if ( color = = " off " ) colorOption - > color = COLOR_OFF ;
if ( color = = " red " ) colorOption - > color = COLOR_RED ;
if ( color = = " orange " ) colorOption - > color = COLOR_ORANGE ;
if ( color = = " yellow " ) colorOption - > color = COLOR_YELLOW ;
if ( color = = " green " ) colorOption - > color = COLOR_GREEN ;
if ( color = = " sky " ) colorOption - > color = COLOR_SKY ;
if ( color = = " blue " ) colorOption - > color = COLOR_BLUE ;
if ( color = = " purple " ) colorOption - > color = COLOR_PURPLE ;
if ( color = = " white " ) colorOption - > color = COLOR_WHITE ;
if ( intensity = = " high " ) colorOption - > intensity = INTENSITY_HIGH ;
if ( intensity = = " medium " ) colorOption - > intensity = INTENSITY_MEDIUM ;
if ( intensity = = " low " ) colorOption - > intensity = INTENSITY_LOW ;
if ( intensity = = " light " ) colorOption - > intensity = INTENSITY_LIGHT ;
if ( region = = " logo " ) colorOption - > region = LOGO ;
if ( region = = " front-left " ) colorOption - > region = FRL_LEFT ;
if ( region = = " front-right " ) colorOption - > region = FRL_RIGHT ;
if ( region = = " touchpad " ) colorOption - > region = TOUCHPAD ;
bool ok = false ;
for ( uint k = 0 ; k < 3 ; k + + ) {
colorOption - > rgb [ k ] = fields . at ( k + 1 ) . toInt ( & ok ) ;
if ( ! ok ) {
std : : cerr < < " invalid color selection " < < std : : endl ;
qApp - > quit ( ) ;
return ;
}
}
colorSet = true ;
colorOptions . append ( colorOption ) ;
@ -100,10 +154,12 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, KeyboardOpti
QCommandLineOption versionOption = parser . addVersionOption ( ) ;
QCommandLineOption mode ( QStringList ( ) < < " m " < < " mode " , " set color <mode>: normal, gaming, breathe, demo, wave " , " mode " ) ;
QCommandLineOption color ( QStringList ( ) < < " c " < < " color " , " set a <color> using the format: region,color,intensity " , " color " ) ;
QCommandLineOption color ( QStringList ( ) < < " c " < < " color " , " set a <color> using the format: region,red,green,blue with rgb values between 0 and 255 " , " color " ) ;
QCommandLineOption colorPreset ( QStringList ( ) < < " p " < < " preset " , " set a color <preset> using the format: region,color,intensity (only valid for left/middle/right regions) " , " preset " ) ;
parser . addOption ( mode ) ;
parser . addOption ( color ) ;
parser . addOption ( colorPreset ) ;
if ( ! parser . parse ( QCoreApplication : : arguments ( ) ) ) {
* errorMessage = parser . errorText ( ) ;
@ -120,6 +176,12 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, KeyboardOpti
keyboardOptions - > setMode ( parser . value ( mode ) ) ;
}
if ( parser . isSet ( colorPreset ) ) {
foreach ( const QString & presetValue , parser . values ( colorPreset ) ) {
keyboardOptions - > setColorPreset ( presetValue ) ;
}
}
if ( parser . isSet ( color ) ) {
foreach ( const QString & colorValue , parser . values ( color ) ) {
keyboardOptions - > setColor ( colorValue ) ;
@ -132,7 +194,7 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, KeyboardOpti
int main ( int argc , char * argv [ ] ) {
QCoreApplication app ( argc , argv ) ;
app . setApplicationName ( " msi-keyboard " ) ;
app . setApplicationVersion ( " 1.0 " ) ;
app . setApplicationVersion ( " 1.1 " ) ;
QCommandLineParser parser ;
parser . setApplicationDescription ( " Keyboard color changer for MSI steelseries keyboards " ) ;
@ -156,7 +218,7 @@ int main(int argc, char *argv[]) {
{
std : : cout < < qPrintable ( parser . helpText ( ) ) < < std : : endl ;
QStringList regions = QStringList ( ) < < " left " < < " middle " < < " right " ;
QStringList regions = QStringList ( ) < < " left " < < " middle " < < " right " < < " logo " < < " front-left " < < " front-right " < < " touchpad " ;
QStringList colors = QStringList ( ) < < " off " < < " red " < < " orange " < < " yellow " < < " green " < < " sky " < < " blue " < < " purple " < < " white " ;
QStringList intensities = QStringList ( ) < < " high " < < " medium " < < " low " < < " light " ;
@ -164,18 +226,18 @@ int main(int argc, char *argv[]) {
% 1
Available c olors :
Available color presets ( on ly f or left / middle / right regions ) :
% 2
Available intensities :
Available preset intensities ( only for left / middle / right regions ) :
% 3
Example :
% 4
) " ).arg(regions.join(' \n ')).arg(colors.join(' \n ')).arg(intensities.join(' \n ')).arg(QString(argv[0]) + " - m normal - c left , red , high - c middle , purple , high - c right , sky , high " );
) " ).arg(regions.join(' \n ')).arg(colors.join(' \n ')).arg(intensities.join(' \n ')).arg(QString(argv[0]) + " - m normal - p left , red , high - p middle , purple , high - p right , sky , high - c touchpad , 255 , 0 , 0 " );
std : : cout < < qPrintable ( colorHelp ) < < std : : endl ;
@ -183,17 +245,25 @@ Example:
}
}
if ( ! keyboardOptions . modeSet | | ! keyboardOptions . colorSet ) {
std : : cerr < < " Please set a mode as well as at least one color region to change. " < < std : : endl ;
if ( ! keyboardOptions . modeSet & & ! keyboardOptions . colorSet & & ! keyboardOptions . preset Set ) {
std : : cerr < < " Please set a mode or at least one color region to change. " < < std : : endl ;
return 1 ;
} else {
Keyboard k ;
if ( keyboardOptions . presetSet ) {
for ( int i = 0 ; i < keyboardOptions . presetOptions . count ( ) ; + + i ) {
ColorPresetOption * presetOption = keyboardOptions . presetOptions . at ( i ) ;
k . setColorPreset ( presetOption - > region , presetOption - > color , presetOption - > intensity ) ;
}
}
if ( keyboardOptions . colorSet ) {
for ( int i = 0 ; i < keyboardOptions . colorOptions . count ( ) ; + + i ) {
ColorOption * colorOption = keyboardOptions . colorOptions . at ( i ) ;
k . setColor ( colorOption - > region , colorOption - > color , colorOption - > intensity ) ;
k . setColor ( colorOption - > region , colorOption - > rgb ) ;
}
}