1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-14 18:06:32 +00:00

Make music_player_interval a lua setting

This commit is contained in:
Pavel Labath 2010-09-11 14:45:19 +02:00
parent 47d9a63dff
commit a111356ea4
5 changed files with 35 additions and 17 deletions

View File

@ -90,7 +90,7 @@ int create_audacious_thread(void)
if (!info.audacious.p_timed_thread) {
info.audacious.p_timed_thread =
timed_thread::create(std::bind(audacious_thread_func, std::placeholders::_1),
std::chrono::microseconds(long(info.music_player_interval * 1000000)));
std::chrono::microseconds(long(music_player_interval.get(*state) * 1000000)));
}
if (!info.audacious.p_timed_thread) {

View File

@ -186,6 +186,23 @@ static bool on_battery = false;
double active_update_interval()
{ return (on_battery?update_interval_on_battery:update_interval).get(*state); }
void music_player_interval_setting::lua_setter(lua::state &l, bool init)
{
lua::stack_sentry s(l, -2);
if(l.isnil(-2)) {
l.checkstack(1);
l.pushnumber(update_interval.get(l));
l.replace(-3);
}
Base::lua_setter(l, init);
++s;
}
music_player_interval_setting music_player_interval;
void *global_cpu = NULL;
static conky::range_config_setting<unsigned int> max_text_width("max_text_width", 0,
std::numeric_limits<unsigned int>::max(), 0, true);
@ -2616,7 +2633,6 @@ static void set_default_configurations(void)
out_to_stdout.lua_set(*state);
#endif
info.music_player_interval = 1.0;
info.users.number = 1;
}
@ -2753,13 +2769,6 @@ char load_config_file(const char *f)
// start the whole if-then-else-if cascade
if (false) {}
CONF("music_player_interval") {
if (value) {
info.music_player_interval = strtod(value, 0);
} else {
CONF_ERR;
}
}
CONF("text") {
free_and_zero(global_text);
@ -2808,10 +2817,6 @@ char load_config_file(const char *f)
fclose(fp);
if (info.music_player_interval == 0) {
// default to update_interval
info.music_player_interval = active_update_interval();
}
if (!global_text) { // didn't supply any text
CRIT_ERR(NULL, NULL, "missing text block in configuration; exiting");
}
@ -3250,7 +3255,7 @@ int main(int argc, char **argv)
"conky.config = { alignment='top_left', asdf=47, [42]=47, out_to_x=true,\n"
" own_window_hints='above, skip_taskbar',\n"
" background_colour='pink', own_window=true, double_buffer=true,\n"
" pop3='asdf wet xcbv'};\n"
" update_interval=5, update_interval_on_battery=10};\n"
);
l.call(0, 0);
conky::set_config_settings(l);
@ -3269,6 +3274,7 @@ int main(int argc, char **argv)
"print('config.mpd_host = ', conky.config.mpd_host);\n"
"print('config.mpd_password = ', conky.config.mpd_password);\n"
"print('config.mpd_port = ', conky.config.mpd_port);\n"
"print('config.music_player_interval = ', conky.config.music_player_interval);\n"
);
l.call(0, 0);

View File

@ -233,7 +233,6 @@ struct information {
#endif /* BUILD_IOSTATS */
struct process *first_process;
unsigned long looped;
double music_player_interval;
#ifdef BUILD_X11
struct x11_info x11;
@ -242,6 +241,19 @@ struct information {
short kflags; /* kernel settings, see enum KFLAG */
};
class music_player_interval_setting: public conky::simple_config_setting<double> {
typedef conky::simple_config_setting<double> Base;
protected:
virtual void lua_setter(lua::state &l, bool init);
public:
music_player_interval_setting()
: Base("music_player_interval", 0, true)
{}
};
extern music_player_interval_setting music_player_interval;
extern conky::range_config_setting<int> cpu_avg_samples;
extern conky::range_config_setting<int> net_avg_samples;
extern conky::range_config_setting<int> diskio_avg_samples;

View File

@ -141,7 +141,7 @@ static int run_moc_thread(std::chrono::microseconds interval)
int update_moc(void)
{
run_moc_thread(std::chrono::microseconds(long(info.music_player_interval * 100000)));
run_moc_thread(std::chrono::microseconds(long(music_player_interval.get(*state) * 1000000)));
return 0;
}

View File

@ -179,7 +179,7 @@ int update_mpd(void)
return 0;
thread = timed_thread::create(std::bind(update_mpd_thread, std::placeholders::_1),
std::chrono::microseconds(long(info.music_player_interval * 1000000)) );
std::chrono::microseconds(long(music_player_interval.get(*state) * 1000000)) );
if (!thread) {
NORM_ERR("Failed to create MPD timed thread");
return 0;