1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-27 20:59:01 +00:00

Add lua_shutdown_hook.

This commit is contained in:
Brenden Matthews 2009-08-01 14:30:14 -06:00
parent bb89efee5b
commit 41aed41e35
6 changed files with 57 additions and 16 deletions

View File

@ -370,6 +370,24 @@
<listitem>Loads the Lua scripts separated by spaces.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
<option>lua_shutdown_hook</option>
</command>
<option>function_name [function arguments]</option>
</term>
<listitem>
<para>This function, if defined, will be called by
Conky at shutdown or when the configuration is
reloaded. Use this hook to clean up after yourself,
such as freeing memory which has been allocated by
external libraries via Lua. Conky puts 'conky_' in
front of function_name to prevent accidental calls to
the wrong function unless you put you place 'conky_' in
front of it yourself.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>

View File

@ -5,7 +5,7 @@
syntax "conky" "(\.*conkyrc.*$|conky.conf)"
## Configuration items
color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>"
color green "\<(alignment|append_file|background|border_inner_margin|border_outer_margin|border_width|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|colorN|cpu_avg_samples|default_bar_size|default_color|default_gauge_size|default_graph_size|default_outline_color|default_shade_color|diskio_avg_samples|display|double_buffer|draw_borders|draw_graph_borders|draw_outline|draw_shades|extra_newline|font|format_human_readable|gap_x|gap_y|if_up_strictness|imap|imlib_cache_flush_interval|imlib_cache_size|lua_draw_hook_post|lua_draw_hook_pre|lua_load|lua_shutdown_hook|mail_spool|max_port_monitor_connections|max_specials|max_user_text|maximum_width|minimum_size|mpd_host|mpd_password|mpd_port|music_player_interval|net_avg_samples|no_buffers|out_to_console|out_to_ncurses|out_to_stderr|out_to_x|override_utf8_locale|overwrite_file|own_window|own_window_class|own_window_colour|own_window_hints|own_window_title|own_window_transparent|own_window_type|pad_percents|pop3|sensor_device|short_units|show_graph_range|show_graph_scale|stippled_borders|temperature_unit|template|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|text|text_buffer_size|top_cpu_separate|top_name_width|total_run_times|update_interval|update_interval_on_battery|uppercase|use_spacer|use_xft|xftalpha|xftfont)\>"
## Configuration item constants
color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>"

View File

@ -12,7 +12,7 @@ endif
syn region ConkyrcComment start=/^\s*#/ end=/$/
syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont
syn keyword ConkyrcSetting alignment append_file background border_inner_margin border_outer_margin border_width color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 colorN cpu_avg_samples default_bar_size default_color default_gauge_size default_graph_size default_outline_color default_shade_color diskio_avg_samples display double_buffer draw_borders draw_graph_borders draw_outline draw_shades extra_newline font format_human_readable gap_x gap_y if_up_strictness imap imlib_cache_flush_interval imlib_cache_size lua_draw_hook_post lua_draw_hook_pre lua_load lua_shutdown_hook mail_spool max_port_monitor_connections max_specials max_user_text maximum_width minimum_size mpd_host mpd_password mpd_port music_player_interval net_avg_samples no_buffers out_to_console out_to_ncurses out_to_stderr out_to_x override_utf8_locale overwrite_file own_window own_window_class own_window_colour own_window_hints own_window_title own_window_transparent own_window_type pad_percents pop3 sensor_device short_units show_graph_range show_graph_scale stippled_borders temperature_unit template template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 text text_buffer_size top_cpu_separate top_name_width total_run_times update_interval update_interval_on_battery uppercase use_spacer use_xft xftalpha xftfont
syn keyword ConkyrcConstant
\ above

View File

@ -7780,6 +7780,7 @@ void clean_up(void *memtofree1, void* memtofree2)
weather_free_info();
#endif
#ifdef HAVE_LUA
llua_shutdown_hook();
llua_close();
#endif /* HAVE_LUA */
@ -8931,6 +8932,13 @@ char load_config_file(const char *f)
CONF_ERR;
}
}
CONF("lua_shutdown_hook") {
if (value) {
llua_set_shutdown_hook(value);
} else {
CONF_ERR;
}
}
#endif /* X11 */
#endif /* HAVE_LUA */

View File

@ -39,8 +39,9 @@ void llua_rm_notifies(void);
static int llua_block_notify = 0;
#endif /* HAVE_SYS_INOTIFY_H */
static char *draw_pre = 0;
static char *draw_post = 0;
static char *draw_pre_hook = 0;
static char *draw_post_hook = 0;
static char *shutdown_hook = 0;
lua_State *lua_L = NULL;
@ -287,13 +288,13 @@ void llua_close(void)
#ifdef HAVE_SYS_INOTIFY_H
llua_rm_notifies();
#endif /* HAVE_SYS_INOTIFY_H */
if (draw_pre) {
free(draw_pre);
draw_pre = 0;
if (draw_pre_hook) {
free(draw_pre_hook);
draw_pre_hook = 0;
}
if (draw_post) {
free(draw_post);
draw_post = 0;
if (draw_post_hook) {
free(draw_post_hook);
draw_post_hook = 0;
}
if(!lua_L) return;
lua_close(lua_L);
@ -391,24 +392,35 @@ void llua_set_number(const char *key, double value)
#ifdef X11
void llua_draw_pre_hook(void)
{
if (!lua_L || !draw_pre) return;
llua_do_call(draw_pre, 0);
if (!lua_L || !draw_pre_hook) return;
llua_do_call(draw_pre_hook, 0);
}
void llua_draw_post_hook(void)
{
if (!lua_L || !draw_post) return;
llua_do_call(draw_post, 0);
if (!lua_L || !draw_post_hook) return;
llua_do_call(draw_post_hook, 0);
}
void llua_shutdown_hook(void)
{
if (!lua_L || !shutdown_hook) return;
llua_do_call(shutdown_hook, 0);
}
void llua_set_draw_pre_hook(const char *args)
{
draw_pre = strdup(args);
draw_pre_hook = strdup(args);
}
void llua_set_draw_post_hook(const char *args)
{
draw_post = strdup(args);
draw_post_hook = strdup(args);
}
void llua_set_shutdown_hook(const char *args)
{
shutdown_hook = strdup(args);
}
#ifdef LUA_EXTRAS

View File

@ -54,8 +54,11 @@ void llua_inotify_query(int wd, int mask);
#ifdef X11
void llua_draw_pre_hook(void);
void llua_draw_post_hook(void);
void llua_shutdown_hook(void);
void llua_set_draw_pre_hook(const char *args);
void llua_set_draw_post_hook(const char *args);
void llua_set_shutdown_hook(const char *args);
void llua_setup_window_table(int text_start_x, int text_start_y, int text_width, int text_height);
void llua_update_window_table(int text_start_x, int text_start_y, int text_width, int text_height);