all repos — tint2 @ c298a39d00db8856133cee0da18b1db55ee5ac67

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

moved initial values in function default_xxx

git-svn-id: http://tint2.googlecode.com/svn/trunk@423 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
thilor77 thilor77@121b4492-b84c-0410-8b4c-0d4edfb3f3cc
commit

c298a39d00db8856133cee0da18b1db55ee5ac67

parent

a94d75d39333680b2da39fc21fa5daa7315410d5

M src/battery/battery.csrc/battery/battery.c

@@ -33,23 +33,23 @@ #include "battery.h"

#include "clock.h" #include "timer.h" -PangoFontDescription *bat1_font_desc=0; -PangoFontDescription *bat2_font_desc=0; +PangoFontDescription *bat1_font_desc; +PangoFontDescription *bat2_font_desc; struct batstate battery_state; int battery_enabled; int percentage_hide; -static timeout* battery_timeout=0; +static timeout* battery_timeout; static char buf_bat_percentage[10]; static char buf_bat_time[20]; int8_t battery_low_status; unsigned char battery_low_cmd_send; -char *battery_low_cmd=0; -char *path_energy_now=0; -char *path_energy_full=0; -char *path_current_now=0; -char *path_status=0; +char *battery_low_cmd; +char *path_energy_now; +char *path_energy_full; +char *path_current_now; +char *path_status; void update_batterys(void* arg) {

@@ -77,6 +77,32 @@ panel1[i].battery.area.resize = 1;

} } +void default_battery() +{ + battery_enabled = 0; + percentage_hide = 101; + battery_low_cmd_send = 0; + battery_timeout = 0; + bat1_font_desc = 0; + bat2_font_desc = 0; + battery_low_cmd = 0; + path_energy_now = 0; + path_energy_full = 0; + path_current_now = 0; + path_status = 0; +} + +void cleanup_battery() +{ + if (bat1_font_desc) pango_font_description_free(bat1_font_desc); + if (bat2_font_desc) pango_font_description_free(bat2_font_desc); + if (path_energy_now) g_free(path_energy_now); + if (path_energy_full) g_free(path_energy_full); + if (path_current_now) g_free(path_current_now); + if (path_status) g_free(path_status); + if (battery_low_cmd) g_free(battery_low_cmd); +} + void init_battery() {

@@ -153,43 +179,6 @@ g_free(battery_dir);

if (battery_enabled && battery_timeout==0) battery_timeout = add_timeout(10, 10000, update_batterys, 0); -} - - -void cleanup_battery() -{ - battery_enabled = 0; - percentage_hide = 101; - battery_low_cmd_send = 0; - - if (bat1_font_desc) { - pango_font_description_free(bat1_font_desc); - bat1_font_desc = 0; - } - if (bat2_font_desc) { - pango_font_description_free(bat2_font_desc); - bat2_font_desc = 0; - } - if (path_energy_now) { - g_free(path_energy_now); - path_energy_now = 0; - } - if (path_energy_full) { - g_free(path_energy_full); - path_energy_full = 0; - } - if (path_current_now) { - g_free(path_current_now); - path_current_now = 0; - } - if (path_status) { - g_free(path_status); - path_status = 0; - } - if (battery_low_cmd) { - g_free(battery_low_cmd); - battery_low_cmd = 0; - } }
M src/battery/battery.hsrc/battery/battery.h

@@ -57,15 +57,16 @@ extern int8_t battery_low_status;

extern char *battery_low_cmd; extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status; +// default values +void default_battery(); +// freed memory +void cleanup_battery(); // initialize clock : y position, ... void update_battery(); void init_battery(); void init_battery_panel(void *panel); - -// freed memory and set default values -void cleanup_battery(); void draw_battery(void *obj, cairo_t *c);
M src/clock/clock.csrc/clock/clock.c

@@ -35,22 +35,53 @@ #include "clock.h"

#include "timer.h" -char *time1_format=0; -char *time1_timezone=0; -char *time2_format=0; -char *time2_timezone=0; -char *time_tooltip_format=0; -char *time_tooltip_timezone=0; -char *clock_lclick_command=0; -char *clock_rclick_command=0; +char *time1_format; +char *time1_timezone; +char *time2_format; +char *time2_timezone; +char *time_tooltip_format; +char *time_tooltip_timezone; +char *clock_lclick_command; +char *clock_rclick_command; struct timeval time_clock; -PangoFontDescription *time1_font_desc=0; -PangoFontDescription *time2_font_desc=0; +PangoFontDescription *time1_font_desc; +PangoFontDescription *time2_font_desc; static char buf_time[40]; static char buf_date[40]; static char buf_tooltip[40]; int clock_enabled; -static timeout* clock_timeout=0; +static timeout* clock_timeout; + + +void default_clock() +{ + clock_enabled = 0; + clock_timeout = 0; + time1_format = 0; + time1_timezone = 0; + time2_format = 0; + time2_timezone = 0; + time_tooltip_format = 0; + time_tooltip_timezone = 0; + clock_lclick_command = 0; + clock_rclick_command = 0; + time1_font_desc = 0; + time2_font_desc = 0; +} + +void cleanup_clock() +{ + if (time1_font_desc) pango_font_description_free(time1_font_desc); + if (time2_font_desc) pango_font_description_free(time2_font_desc); + if (time1_format) g_free(time1_format); + if (time2_format) g_free(time2_format); + if (time_tooltip_format) g_free(time_tooltip_format); + if (time1_timezone) g_free(time1_timezone); + if (time2_timezone) g_free(time2_timezone); + if (time_tooltip_timezone) g_free(time_tooltip_timezone); + if (clock_lclick_command) g_free(clock_lclick_command); + if (clock_rclick_command) g_free(clock_rclick_command); +} void update_clocks_sec(void* arg)

@@ -156,52 +187,6 @@

if (time_tooltip_format) { clock->area._get_tooltip_text = clock_get_tooltip; strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone)); - } -} - - -void cleanup_clock() -{ - clock_enabled = 0; - if (time1_font_desc) { - pango_font_description_free(time1_font_desc); - time1_font_desc = 0; - } - if (time2_font_desc) { - pango_font_description_free(time2_font_desc); - time2_font_desc = 0; - } - if (time1_format) { - g_free(time1_format); - time1_format = 0; - } - if (time2_format) { - g_free(time2_format); - time2_format = 0; - } - if (time_tooltip_format) { - g_free(time_tooltip_format); - time_tooltip_format = 0; - } - if (time1_timezone) { - g_free(time1_timezone); - time1_timezone = 0; - } - if (time2_timezone) { - g_free(time2_timezone); - time2_timezone = 0; - } - if (time_tooltip_timezone) { - g_free(time_tooltip_timezone); - time_tooltip_timezone = 0; - } - if (clock_lclick_command) { - g_free(clock_lclick_command); - clock_lclick_command = 0; - } - if (clock_rclick_command) { - g_free(clock_rclick_command); - clock_rclick_command = 0; } }
M src/clock/clock.hsrc/clock/clock.h

@@ -37,12 +37,14 @@ extern char *clock_rclick_command;

extern int clock_enabled; +// default values +void default_clock(); +// freed memory +void cleanup_clock(); + // initialize clock : y position, precision, ... void init_clock(); void init_clock_panel(void *panel); - -// freed memory and set default values -void cleanup_clock(); void draw_clock (void *obj, cairo_t *c);
M src/config.csrc/config.c

@@ -52,8 +52,8 @@ #include "battery.h"

#endif // global path -char *config_path = 0; -char *snapshot_path = 0; +char *config_path; +char *snapshot_path; // -------------------------------------------------- // backward compatibility

@@ -63,6 +63,20 @@ // ==1

static int old_config_file; +void default_config() +{ + config_path = 0; + snapshot_path = 0; + old_config_file = 1; +} + +void cleanup_config() +{ + if (config_path) g_free(config_path); + if (snapshot_path) g_free(snapshot_path); +} + + void init_config() { if (backgrounds)

@@ -88,9 +102,6 @@ if (panel_config.g_task.font_desc) {

pango_font_description_free(panel_config.g_task.font_desc); } memset(&panel_config, 0, sizeof(Panel)); - systray.alpha = 100; - systray.sort = 3; - old_config_file = 1; // window manager's menu default value == false wm_menu = 0;

@@ -100,11 +111,6 @@ // flush pango cache if possible

//pango_xft_shutdown_display(server.dsp, server.screen); //PangoFontMap *font_map = pango_xft_get_font_map(server.dsp, server.screen); //pango_fc_font_map_shutdown(font_map); -} - - -void cleanup_config() -{ }
M src/config.hsrc/config.h

@@ -12,8 +12,12 @@

extern char *config_path; extern char *snapshot_path; -void init_config(); +// default values +void default_config(); +// freed memory void cleanup_config(); + +void init_config(); int config_read_file (const char *path); int config_read ();
M src/panel.csrc/panel.c

@@ -288,6 +288,7 @@ void cleanup_panel()

{ if (!panel1) return; +printf("*** cleanup_panel()\n"); task_active = 0; task_drag = 0;

@@ -568,7 +569,7 @@ yoff = p->area.height-p->hidden_height;

else if (!panel_horizontal && panel_position & RIGHT) xoff = p->area.width-p->hidden_width; - if (real_transparency) { + if (server.real_transparency) { clear_pixmap(p->area.pix, 0, 0, p->area.width, p->area.height); } else {
M src/server.csrc/server.c

@@ -33,8 +33,6 @@ #include "window.h"

void server_catch_error (Display *d, XErrorEvent *ev){} -int real_transparency = 0; - void server_init_atoms () { server.atom._XROOTPMAP_ID = XInternAtom (server.dsp, "_XROOTPMAP_ID", False);

@@ -96,10 +94,6 @@ // drag 'n' drop

server.atom.XdndAware = XInternAtom(server.dsp, "XdndAware", False); server.atom.XdndPosition = XInternAtom(server.dsp, "XdndPosition", False); server.atom.XdndStatus = XInternAtom(server.dsp, "XdndStatus", False); - - server.colormap = 0; - server.monitor = 0; - server.gc = 0; }

@@ -391,7 +385,7 @@ XSetWindowAttributes attrs;

attrs.event_mask = StructureNotifyMask; XChangeWindowAttributes (server.dsp, server.composite_manager, CWEventMask, &attrs); - real_transparency = 1; + server.real_transparency = 1; server.depth = 32; printf("real transparency on... depth: %d\n", server.depth); server.colormap = XCreateColormap(server.dsp, server.root_win, visual, AllocNone);

@@ -399,7 +393,7 @@ server.visual = visual;

} else { // no composite manager or snapshot mode => fake transparency - real_transparency = 0; + server.real_transparency = 0; server.depth = DefaultDepth(server.dsp, server.screen); printf("real transparency off.... depth: %d\n", server.depth); server.colormap = DefaultColormap(server.dsp, server.screen);
M src/server.hsrc/server.h

@@ -13,7 +13,7 @@ #include <X11/Xlib.h>

#include <X11/Xatom.h> #include <X11/extensions/Xinerama.h> -extern int real_transparency; + typedef struct Global_atom { Atom _XROOTPMAP_ID;

@@ -87,6 +87,7 @@ {

Display *dsp; Window root_win; Window composite_manager; + int real_transparency; // current desktop int desktop; int screen;

@@ -110,6 +111,9 @@

Server_global server; +// freed memory +void cleanup_server(); + void send_event32 (Window win, Atom at, long data1, long data2, long data3); int get_property32 (Window win, Atom at, Atom type); void *server_get_property (Window win, Atom at, Atom type, int *num_results);

@@ -117,7 +121,6 @@ Atom server_get_atom (char *atom_name);

void server_catch_error (Display *d, XErrorEvent *ev); void server_init_atoms (); void server_init_visual(); -void cleanup_server(); // detect root background void get_root_pixmap();
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -51,9 +51,32 @@ int systray_enabled;

int systray_max_icon_size; // background pixmap if we render ourselves the icons -static Pixmap render_background = 0; +static Pixmap render_background; +void default_systray() +{ +printf("*** default_systray()\n"); + memset(&systray, 0, sizeof(Systraybar)); + render_background = 0; + systray.alpha = 100; + systray.sort = 3; + systray.area._draw_foreground = draw_systray; + systray.area._resize = resize_systray; +} + +void cleanup_systray() +{ + systray_enabled = 0; + systray_max_icon_size = 0; + systray.area.on_screen = 0; + free_area(&systray.area); + if (render_background) { + XFreePixmap(server.dsp, render_background); + render_background = 0; + } +} + void init_systray() { start_net();

@@ -66,8 +89,6 @@ printf("No 32 bit visual for your X implementation. 'systray_asb = 100 0 0' will be forced\n");

systray.alpha = 100; systray.brightness = systray.saturation = 0; } - systray.area._draw_foreground = draw_systray; - systray.area._resize = resize_systray; systray.area.resize = 1; systray.area.redraw = 1; systray.area.on_screen = 1;

@@ -92,22 +113,9 @@ systray.area.panel = p;

} -void cleanup_systray() -{ - systray_enabled = 0; - systray_max_icon_size = 0; - systray.area.on_screen = 0; - free_area(&systray.area); - if (render_background) { - XFreePixmap(server.dsp, render_background); - render_background = 0; - } -} - - void draw_systray(void *obj, cairo_t *c) { - if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { + if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { if (render_background) XFreePixmap(server.dsp, render_background); render_background = XCreatePixmap(server.dsp, server.root_win, systray.area.width, systray.area.height, server.depth); XCopyArea(server.dsp, systray.area.pix, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0);

@@ -446,7 +454,7 @@ //printf("add_icon id %lx, %d\n", id, g_slist_length(systray.list_icons));

// watch for the icon trying to resize itself! XSelectInput(server.dsp, traywin->tray_id, StructureNotifyMask); - if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { + if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { traywin->damage = XDamageCreate(server.dsp, traywin->id, XDamageReportRawRectangles); XCompositeRedirectWindow(server.dsp, traywin->id, CompositeRedirectManual); }

@@ -550,7 +558,7 @@ printf("Strange tray icon found with depth: %d\n", traywin->depth);

return; } Picture pict_image; - if (real_transparency) + if (server.real_transparency) pict_image = XRenderCreatePicture(server.dsp, traywin->id, f, 0, 0); else pict_image = XRenderCreatePicture(server.dsp, traywin->tray_id, f, 0, 0);

@@ -592,7 +600,7 @@

void systray_render_icon(TrayWindow* traywin) { - if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { + if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { // wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms if (traywin->render_timeout == 0) traywin->render_timeout = add_timeout(50, 0, systray_render_icon_now, traywin);
M src/systray/systraybar.hsrc/systray/systraybar.h

@@ -52,12 +52,14 @@ extern int refresh_systray;

extern int systray_enabled; extern int systray_max_icon_size; -void init_systray(); +// default values +void default_systray(); +// freed memory +void cleanup_systray(); +// initialize protocol and panel position +void init_systray(); void init_systray_panel(void *p); - -// freed memory and set default values -void cleanup_systray(); void draw_systray(void *obj, cairo_t *c); void resize_systray(void *obj);
M src/taskbar/task.csrc/taskbar/task.c

@@ -35,8 +35,8 @@ #include "panel.h"

#include "tooltip.h" #include "timer.h" -static timeout* urgent_timeout = 0; -static GSList* urgent_list = 0; +timeout* urgent_timeout; +GSList* urgent_list; const char* task_get_tooltip(void* obj) {

@@ -325,7 +325,7 @@ else pos_x = panel->g_task.area.paddingxlr + tsk->area.bg->border.width;

// Render imlib_context_set_image (tsk->icon[tsk->current_state]); - if (real_transparency) { + if (server.real_transparency) { render_image(tsk->area.pix, pos_x, panel->g_task.icon_posy, imlib_image_get_width(), imlib_image_get_height() ); } else {
M src/taskbar/task.hsrc/taskbar/task.h

@@ -11,9 +11,12 @@ #include <X11/Xlib.h>

#include <pango/pangocairo.h> #include <Imlib2.h> #include "common.h" +#include "timer.h" enum { TASK_NORMAL, TASK_ACTIVE, TASK_ICONIFIED, TASK_URGENT, TASK_STATE_COUNT }; +extern timeout* urgent_timeout; +extern GSList* urgent_list; // -------------------------------------------------- // global task parameter
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -37,7 +37,7 @@ /* win_to_task_table holds for every Window an array of tasks. Usually the array contains only one

element. However for omnipresent windows (windows which are visible in every taskbar) the array contains to every Task* on each panel a pointer (i.e. GPtrArray.len == server.nb_desktop) */ -GHashTable* win_to_task_table = 0; +GHashTable* win_to_task_table; guint win_hash(gconstpointer key) { return (guint)*((Window*)key); } gboolean win_compare(gconstpointer a, gconstpointer b) { return (*((Window*)a) == *((Window*)b)); }

@@ -169,6 +169,13 @@

void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data) { remove_task(task_get_task(*(Window*)key)); +} + +void default_taskbar() +{ + win_to_task_table = 0; + urgent_timeout = 0; + urgent_list = 0; } void cleanup_taskbar()
M src/taskbar/taskbar.hsrc/taskbar/taskbar.h

@@ -33,10 +33,13 @@ Background* bg_active;

int use_active; } Global_taskbar; -void init_taskbar(); -// freed memory and set default values +// default values +void default_taskbar(); +// freed memory void cleanup_taskbar(); + +void init_taskbar(); Task *task_get_task (Window win); GPtrArray* task_get_tasks(Window win);
M src/tint.csrc/tint.c

@@ -42,6 +42,7 @@ #include "panel.h"

#include "tooltip.h" #include "timer.h" + void signal_handler(int sig) { // signal handler is light as it should be

@@ -52,6 +53,16 @@

void init (int argc, char *argv[]) { int i; + + // set global data + default_timeout(); + default_systray(); + memset(&server, 0, sizeof(Server_global)); + default_battery(); + default_clock(); + default_taskbar(); + default_tooltip(); + default_config(); // read options for (i = 1; i < argc; ++i) {

@@ -91,10 +102,6 @@ // sigaddset(&block_mask, SIGTERM);

// sigaddset(&block_mask, SIGHUP); // sigaddset(&block_mask, SIGUSR1); // sigprocmask(SIG_BLOCK, &block_mask, 0); - - // set global data - memset(&server, 0, sizeof(Server_global)); - memset(&systray, 0, sizeof(Systraybar)); } void init_X11()

@@ -140,7 +147,8 @@

void cleanup() { - stop_all_timeouts(); +printf("*** cleanup()\n"); + cleanup_timeout(); cleanup_systray(); stop_net(); cleanup_panel();

@@ -149,13 +157,12 @@ cleanup_clock();

#ifdef ENABLE_BATTERY cleanup_battery(); #endif + cleanup_config(); if (default_icon) { imlib_context_set_image(default_icon); imlib_free_image(); } - if (config_path) g_free(config_path); - if (snapshot_path) g_free(snapshot_path); cleanup_server(); if (server.dsp) XCloseDisplay(server.dsp);
M src/tooltip/tooltip.csrc/tooltip/tooltip.c

@@ -34,23 +34,29 @@ void start_show_timeout();

void start_hide_timeout(); void stop_tooltip_timeout(); -// give the tooltip some reasonable default values -Tooltip g_tooltip = { - .tooltip_text = 0, - .area = 0, - .panel = 0, - .window = 0, - .show_timeout_msec = 0, - .hide_timeout_msec = 0, - .enabled = False, - .mapped = False, - .paddingx = 0, - .paddingy = 0, - .font_color = { .color={1, 1, 1}, .alpha=1 }, - .bg = 0, - .font_desc = 0, - .timeout = 0 -}; +Tooltip g_tooltip; + + +void default_tooltip() +{ + // give the tooltip some reasonable default values + memset(&g_tooltip, 0, sizeof(Tooltip)); + + g_tooltip.font_color.color[0] = 1; + g_tooltip.font_color.color[1] = 1; + g_tooltip.font_color.color[2] = 1; + g_tooltip.font_color.alpha = 1; +} + +void cleanup_tooltip() +{ + stop_tooltip_timeout(); + tooltip_hide(0); + tooltip_copy_text(0); + if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window); + if (g_tooltip.font_desc) pango_font_description_free(g_tooltip.font_desc); +} + void init_tooltip() {

@@ -66,23 +72,6 @@ attr.border_pixel = 0;

unsigned long mask = CWEventMask|CWColormap|CWBorderPixel|CWBackPixel|CWOverrideRedirect; if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window); g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, server.visual, mask, &attr); -} - - -void cleanup_tooltip() -{ - stop_tooltip_timeout(); - tooltip_hide(0); - g_tooltip.enabled = False; - tooltip_copy_text(0); - if (g_tooltip.window) { - XDestroyWindow(server.dsp, g_tooltip.window); - g_tooltip.window = 0; - } - if (g_tooltip.font_desc) { - pango_font_description_free(g_tooltip.font_desc); - g_tooltip.font_desc = 0; - } }

@@ -215,7 +204,7 @@ cs = cairo_xlib_surface_create(server.dsp, g_tooltip.window, server.visual, width, height);

c = cairo_create(cs); Color bc = g_tooltip.bg->back; Border b = g_tooltip.bg->border; - if (real_transparency) { + if (server.real_transparency) { clear_pixmap(g_tooltip.window, 0, 0, width, height); draw_rect(c, b.width, b.width, width-2*b.width, height-2*b.width, b.rounded-b.width/1.571); cairo_set_source_rgba(c, bc.color[0], bc.color[1], bc.color[2], bc.alpha);

@@ -226,8 +215,10 @@ cairo_set_source_rgb(c, bc.color[0], bc.color[1], bc.color[2]);

} cairo_fill(c); cairo_set_line_width(c, b.width); - if (real_transparency) draw_rect(c, b.width/2.0, b.width/2.0, width - b.width, height - b.width, b.rounded); - else cairo_rectangle(c, b.width/2.0, b.width/2.0, width-b.width, height-b.width); + if (server.real_transparency) + draw_rect(c, b.width/2.0, b.width/2.0, width - b.width, height - b.width, b.rounded); + else + cairo_rectangle(c, b.width/2.0, b.width/2.0, width-b.width, height-b.width); cairo_set_source_rgba(c, b.color[0], b.color[1], b.color[2], b.alpha); cairo_stroke(c);
M src/tooltip/tooltip.hsrc/tooltip/tooltip.h

@@ -42,8 +42,13 @@ } Tooltip;

extern Tooltip g_tooltip; + +// default values +void default_tooltip(); +// freed memory +void cleanup_tooltip(); + void init_tooltip(); -void cleanup_tooltip(); void tooltip_trigger_show(Area* area, Panel* p, int x, int y); void tooltip_show(void* /*arg*/); void tooltip_update();
M src/util/area.csrc/util/area.c

@@ -101,7 +101,7 @@ if (a->pix) XFreePixmap (server.dsp, a->pix);

a->pix = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth); // add layer of root pixmap (or clear pixmap if real_transparency==true) - if (real_transparency) + if (server.real_transparency) clear_pixmap(a->pix, 0 ,0, a->width, a->height); XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, a->pix, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
M src/util/timer.csrc/util/timer.c

@@ -22,8 +22,9 @@ #include <stdio.h>

#include "timer.h" -GSList* timeout_list = 0; +GSList* timeout_list; struct timeval next_timeout; +GHashTable* multi_timeouts; // functions and structs for multi timeouts

@@ -45,6 +46,24 @@ void* arg;

multi_timeout* multi_timeout; }; + +void default_timeout() +{ + timeout_list = 0; + multi_timeouts = 0; +} + +void cleanup_timeout() +{ + while (timeout_list) { + timeout* t = timeout_list->data; + if (t->multi_timeout) + stop_multi_timeout(t); + free(t); + timeout_list = g_slist_remove(timeout_list, t); + } +} + void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(void*), void* arg, timeout* t); gint compare_timeouts(gconstpointer t1, gconstpointer t2); gint compare_timespecs(const struct timespec* t1, const struct timespec* t2);

@@ -60,8 +79,6 @@ void update_multi_timeout_values(multi_timeout_handler* mth);

void callback_multi_timeout(void* mth); void remove_from_multi_timeout(timeout* t); void stop_multi_timeout(timeout* t); - -GHashTable* multi_timeouts = 0; /** Implementation notes for timeouts: The timeouts are kept in a GSList sorted by their * expiration time.

@@ -152,18 +169,6 @@ if (t->multi_timeout)

remove_from_multi_timeout((timeout*)t); timeout_list = g_slist_remove(timeout_list, t); free((void*)t); - } -} - - -void stop_all_timeouts() -{ - while (timeout_list) { - timeout* t = timeout_list->data; - if (t->multi_timeout) - stop_multi_timeout(t); - free(t); - timeout_list = g_slist_remove(timeout_list, t); } }
M src/util/timer.hsrc/util/timer.h

@@ -36,6 +36,11 @@ * Periodic timeouts are aligned to each other whenever possible, i.e. one interval_msec is an

* integral multiple of the other. **/ +/** default values **/ +void default_timeout(); +/** freed memory : stops all timeouts **/ +void cleanup_timeout(); + /** installs a timeout with the first timeout of 'value_msec' and then a periodic timeout with * 'interval_msec'. '_callback' is the callback function when the timer reaches the timeout. * returns a pointer to the timeout, which is needed for stopping it again

@@ -47,9 +52,6 @@ void change_timeout(timeout* t, int value_msec, int interval_msec, void (*_callback)(void*), void* arg);

/** stops the timeout 't' **/ void stop_timeout(timeout* t); - -/** stops all timeouts **/ -void stop_all_timeouts(); /** update_next_timeout updates next_timeout to the value, when the next installed timeout will expire **/ void update_next_timeout();