mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 13:22:23 +08:00
Added support for setting values to properties from command-line to modify how backgrounds look
Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
cf37fe388c
commit
9cddb56f60
45
main.cpp
45
main.cpp
@ -50,13 +50,14 @@ void print_help (const char* route)
|
|||||||
<< "\ta full path to the background's folder" << std::endl
|
<< "\ta full path to the background's folder" << std::endl
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< "options:" << std::endl
|
<< "options:" << std::endl
|
||||||
<< " --silent\t\tMutes all the sound the wallpaper might produce" << std::endl
|
<< "\t--silent\t\t\t\t\tMutes all the sound the wallpaper might produce" << std::endl
|
||||||
<< " --volume <amount>\tSets the volume for all the sounds in the background" << std::endl
|
<< "\t--volume <amount>\t\t\tSets the volume for all the sounds in the background" << std::endl
|
||||||
<< " --screen-root <screen name>\tDisplay as screen's background" << std::endl
|
<< "\t--screen-root <screen name>\tDisplay as screen's background" << std::endl
|
||||||
<< " --fps <maximum-fps>\tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl
|
<< "\t--fps <maximum-fps>\t\t\tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl
|
||||||
<< " --assets-dir <path>\tFolder where the assets are stored" << std::endl
|
<< "\t--assets-dir <path>\t\t\tFolder where the assets are stored" << std::endl
|
||||||
<< " --screenshot\t\tTakes a screenshot of the background" << std::endl
|
<< "\t--screenshot\t\t\t\tTakes a screenshot of the background" << std::endl
|
||||||
<< " --list-properties\tList all the available properties and their possible values" << std::endl;
|
<< "\t--list-properties\t\t\tList all the available properties and their possible values" << std::endl
|
||||||
|
<< "\t--set-property <name=value>\tOverrides the default value of the given property" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stringPathFixes(const std::string& s)
|
std::string stringPathFixes(const std::string& s)
|
||||||
@ -315,6 +316,7 @@ void takeScreenshot (WallpaperEngine::Render::CWallpaper* wp, const std::string&
|
|||||||
int main (int argc, char* argv[])
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
std::vector <std::string> screens;
|
std::vector <std::string> screens;
|
||||||
|
std::map <std::string, std::string> propertyOverrides;
|
||||||
|
|
||||||
int maximumFPS = 30;
|
int maximumFPS = 30;
|
||||||
bool shouldEnableAudio = true;
|
bool shouldEnableAudio = true;
|
||||||
@ -336,6 +338,7 @@ int main (int argc, char* argv[])
|
|||||||
{"assets-dir", required_argument, 0, 'a'},
|
{"assets-dir", required_argument, 0, 'a'},
|
||||||
{"screenshot", required_argument, 0, 'c'},
|
{"screenshot", required_argument, 0, 'c'},
|
||||||
{"list-properties", no_argument, 0, 'l'},
|
{"list-properties", no_argument, 0, 'l'},
|
||||||
|
{"set-property", required_argument, 0, 'o'},
|
||||||
{nullptr, 0, 0, 0}
|
{nullptr, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -348,6 +351,22 @@ int main (int argc, char* argv[])
|
|||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
case 'o':
|
||||||
|
{
|
||||||
|
std::string value = optarg;
|
||||||
|
std::string::size_type equals = value.find ('=');
|
||||||
|
|
||||||
|
// properties without value are treated as booleans for now
|
||||||
|
if (equals == std::string::npos)
|
||||||
|
propertyOverrides.insert_or_assign (value, "1");
|
||||||
|
else
|
||||||
|
propertyOverrides.insert_or_assign (
|
||||||
|
value.substr (0, equals),
|
||||||
|
value.substr (equals + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
shouldListPropertiesAndStop = true;
|
shouldListPropertiesAndStop = true;
|
||||||
break;
|
break;
|
||||||
@ -522,15 +541,21 @@ int main (int argc, char* argv[])
|
|||||||
chdir (path.c_str ());
|
chdir (path.c_str ());
|
||||||
|
|
||||||
// show properties if required
|
// show properties if required
|
||||||
if (shouldListPropertiesAndStop)
|
|
||||||
{
|
|
||||||
for (auto cur : project->getProperties ())
|
for (auto cur : project->getProperties ())
|
||||||
{
|
{
|
||||||
|
// update the value of the property
|
||||||
|
auto override = propertyOverrides.find (cur->getName ());
|
||||||
|
|
||||||
|
if (override != propertyOverrides.end ())
|
||||||
|
cur->update (override->second);
|
||||||
|
|
||||||
|
if (shouldListPropertiesAndStop)
|
||||||
std::cout << cur->dump () << std::endl;
|
std::cout << cur->dump () << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// halt if the list-properties option was specified
|
||||||
|
if (shouldListPropertiesAndStop)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
|
// attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
|
||||||
std::signal(SIGINT, signalhandler);
|
std::signal(SIGINT, signalhandler);
|
||||||
|
@ -19,6 +19,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
template<class T> bool is () { return this->m_type == T::Type; }
|
template<class T> bool is () { return this->m_type == T::Type; }
|
||||||
|
|
||||||
virtual std::string dump () const = 0;
|
virtual std::string dump () const = 0;
|
||||||
|
virtual void update (const std::string& value) = 0;
|
||||||
|
|
||||||
const std::string& getName () const;
|
const std::string& getName () const;
|
||||||
const std::string& getType () const;
|
const std::string& getType () const;
|
||||||
|
@ -22,6 +22,11 @@ bool CPropertyBoolean::getValue ()
|
|||||||
return this->m_value;
|
return this->m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPropertyBoolean::update (const std::string& value)
|
||||||
|
{
|
||||||
|
this->m_value = value == "1" || value == "true";
|
||||||
|
}
|
||||||
|
|
||||||
std::string CPropertyBoolean::dump () const
|
std::string CPropertyBoolean::dump () const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -13,6 +13,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
|
|
||||||
bool getValue ();
|
bool getValue ();
|
||||||
std::string dump () const override;
|
std::string dump () const override;
|
||||||
|
void update (const std::string& value) override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
|
@ -4,28 +4,30 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::Core::Projects;
|
using namespace WallpaperEngine::Core::Projects;
|
||||||
|
|
||||||
CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name)
|
FloatColor ParseColor (const std::string& value)
|
||||||
{
|
{
|
||||||
std::string value = *jsonFindRequired (data, "value", "Color property must have a value");
|
|
||||||
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
|
||||||
FloatColor color (0, 0, 0, 0);
|
|
||||||
|
|
||||||
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1")
|
if (value.find ('.') == std::string::npos && value != "0 0 0" && value != "1 1 1")
|
||||||
{
|
{
|
||||||
IntegerColor intcolor = WallpaperEngine::Core::aToColori (value);
|
IntegerColor intcolor = WallpaperEngine::Core::aToColori (value);
|
||||||
|
|
||||||
color.r = intcolor.r / 255.0;
|
return {
|
||||||
color.g = intcolor.g / 255.0;
|
intcolor.r / 255.0,
|
||||||
color.b = intcolor.b / 255.0;
|
intcolor.g / 255.0,
|
||||||
color.a = intcolor.a / 255.0;
|
intcolor.b / 255.0,
|
||||||
}
|
intcolor.a / 255.0
|
||||||
else
|
};
|
||||||
{
|
|
||||||
color = WallpaperEngine::Core::aToColorf (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return WallpaperEngine::Core::aToColorf (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
CPropertyColor* CPropertyColor::fromJSON (json data, const std::string& name)
|
||||||
|
{
|
||||||
|
std::string value = *jsonFindRequired (data, "value", "Color property must have a value");
|
||||||
|
std::string text = jsonFindDefault <std::string> (data, "text", "");
|
||||||
|
|
||||||
return new CPropertyColor (
|
return new CPropertyColor (
|
||||||
color,
|
ParseColor (value),
|
||||||
name,
|
name,
|
||||||
text
|
text
|
||||||
);
|
);
|
||||||
@ -36,6 +38,12 @@ const FloatColor& CPropertyColor::getValue () const
|
|||||||
return this->m_color;
|
return this->m_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPropertyColor::update (const std::string& value)
|
||||||
|
{
|
||||||
|
this->m_color = ParseColor (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string CPropertyColor::dump () const
|
std::string CPropertyColor::dump () const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -16,6 +16,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
|
|
||||||
const FloatColor& getValue () const;
|
const FloatColor& getValue () const;
|
||||||
std::string dump () const override;
|
std::string dump () const override;
|
||||||
|
void update (const std::string& value) override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
|
@ -72,6 +72,26 @@ std::string CPropertyCombo::dump () const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPropertyCombo::update (const std::string& value)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
// ensure the value is present somewhere in the value list
|
||||||
|
for (auto cur : this->m_values)
|
||||||
|
{
|
||||||
|
if (cur->value != value)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == false)
|
||||||
|
throw std::runtime_error ("Assigning invalid value to property");
|
||||||
|
|
||||||
|
this->m_defaultValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CPropertyCombo::addValue (std::string label, std::string value)
|
void CPropertyCombo::addValue (std::string label, std::string value)
|
||||||
{
|
{
|
||||||
CPropertyComboValue* prop = new CPropertyComboValue;
|
CPropertyComboValue* prop = new CPropertyComboValue;
|
||||||
|
@ -20,6 +20,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
|
|
||||||
const std::string& getValue () const;
|
const std::string& getValue () const;
|
||||||
std::string dump () const override;
|
std::string dump () const override;
|
||||||
|
void update (const std::string& value) override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
|
@ -56,6 +56,16 @@ std::string CPropertySlider::dump () const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPropertySlider::update (const std::string& value)
|
||||||
|
{
|
||||||
|
double newValue = atof (value.c_str ());
|
||||||
|
|
||||||
|
if (newValue < this->m_min || newValue > this->m_max)
|
||||||
|
throw std::runtime_error ("Slider value is out of range");
|
||||||
|
|
||||||
|
this->m_value = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
CPropertySlider::CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step) :
|
CPropertySlider::CPropertySlider (double value, const std::string& name, const std::string& text, double min, double max, double step) :
|
||||||
CProperty (name, Type, text),
|
CProperty (name, Type, text),
|
||||||
m_value (value), m_min (min), m_max (max), m_step (step)
|
m_value (value), m_min (min), m_max (max), m_step (step)
|
||||||
|
@ -19,6 +19,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
const double& getMaxValue () const;
|
const double& getMaxValue () const;
|
||||||
const double& getStep () const;
|
const double& getStep () const;
|
||||||
std::string dump () const override;
|
std::string dump () const override;
|
||||||
|
void update (const std::string& value) override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ std::string CPropertyText::dump () const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPropertyText::update (const std::string& value)
|
||||||
|
{
|
||||||
|
this->m_text = value;
|
||||||
|
}
|
||||||
|
|
||||||
CPropertyText::CPropertyText (const std::string& name, const std::string& text) :
|
CPropertyText::CPropertyText (const std::string& name, const std::string& text) :
|
||||||
CProperty (name, Type, text)
|
CProperty (name, Type, text)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ namespace WallpaperEngine::Core::Projects
|
|||||||
public:
|
public:
|
||||||
static CPropertyText* fromJSON (json data, const std::string& name);
|
static CPropertyText* fromJSON (json data, const std::string& name);
|
||||||
std::string dump () const override;
|
std::string dump () const override;
|
||||||
|
void update (const std::string& value) override;
|
||||||
|
|
||||||
static const std::string Type;
|
static const std::string Type;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user