diff --git a/src/battery/battery.c b/src/battery/battery.c index e43ee00..0d19443 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -41,7 +41,7 @@ struct BatteryState battery_state; gboolean battery_enabled; gboolean battery_tooltip_enabled; int percentage_hide; -static timeout *battery_timeout; +static Timer battery_timeout; #define BATTERY_BUF_SIZE 256 static char buf_bat_line1[BATTERY_BUF_SIZE]; @@ -76,7 +76,7 @@ void default_battery() percentage_hide = 101; battery_low_cmd_sent = FALSE; battery_full_cmd_sent = FALSE; - battery_timeout = NULL; + INIT_TIMER(battery_timeout); bat1_has_font = FALSE; bat1_font_desc = NULL; bat1_format = NULL; @@ -127,8 +127,7 @@ void cleanup_battery() ac_connected_cmd = NULL; free(ac_disconnected_cmd); ac_disconnected_cmd = NULL; - stop_timeout(battery_timeout); - battery_timeout = NULL; + stop_timer(&battery_timeout); battery_found = FALSE; battery_os_free(); @@ -226,7 +225,7 @@ void init_battery() battery_found = battery_os_init(); - battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); + change_timer(&battery_timeout, true, 10, 30000, update_battery_tick, 0); update_battery(); } diff --git a/src/clock/clock.c b/src/clock/clock.c index 2b10484..fca4c30 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -51,7 +51,7 @@ static char buf_time[256]; static char buf_date[256]; static char buf_tooltip[512]; int clock_enabled; -static timeout *clock_timeout; +static Timer clock_timeout; void clock_init_fonts(); char *clock_get_tooltip(void *obj); @@ -61,7 +61,6 @@ void clock_dump_geometry(void *obj, int indent); void default_clock() { clock_enabled = 0; - clock_timeout = NULL; time1_format = NULL; time1_timezone = NULL; time2_format = NULL; @@ -110,8 +109,7 @@ void cleanup_clock() clock_uwheel_command = NULL; free(clock_dwheel_command); clock_dwheel_command = NULL; - stop_timeout(clock_timeout); - clock_timeout = NULL; + stop_timer(&clock_timeout); } struct tm *clock_gettime_for_tz(const char *timezone) @@ -155,7 +153,7 @@ void update_clocks_sec(void *arg) { gettimeofday(&time_clock, 0); update_clocks(); - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, &clock_timeout); + change_timer(&clock_timeout, true, ms_until_second_change(&time_clock), 0, update_clocks_sec, 0); } void update_clocks_min(void *arg) @@ -167,7 +165,7 @@ void update_clocks_min(void *arg) if (time_clock.tv_sec % 60 == 0 || time_clock.tv_sec - old_sec > 60 || (time1_format && !buf_time[0]) || (time2_format && !buf_date[0])) update_clocks(); old_sec = time_clock.tv_sec; - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_min, 0, &clock_timeout); + change_timer(&clock_timeout, true, ms_until_second_change(&time_clock), 0, update_clocks_min, 0); } gboolean time_format_needs_sec_ticks(char *time_format) @@ -216,7 +214,7 @@ void init_clock_panel(void *p) strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone)); } - if (!clock_timeout) { + if (!clock_timeout.enabled_) { if (time_format_needs_sec_ticks(time1_format) || time_format_needs_sec_ticks(time2_format)) { update_clocks_sec(NULL); } else { diff --git a/src/execplugin/execplugin.c b/src/execplugin/execplugin.c index 849203e..4df235f 100644 --- a/src/execplugin/execplugin.c +++ b/src/execplugin/execplugin.c @@ -67,8 +67,7 @@ void destroy_execp(void *obj) free_and_null(execp); } else { // This is a backend element - stop_timeout(execp->backend->timer); - execp->backend->timer = NULL; + stop_timer(&execp->backend->timer); free_icon(execp->backend->icon); free_and_null(execp->backend->buf_stdout); @@ -192,7 +191,7 @@ void init_execp_panel(void *p) execp->area.on_screen = TRUE; instantiate_area_gradients(&execp->area); - execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); + change_timer(&execp->backend->timer, true, 10, 0, execp_timer_callback, execp); execp_update_post_read(execp); } @@ -540,10 +539,8 @@ void execp_force_update(Execp *execp) if (execp->backend->child_pipe_stdout > 0) { // Command currently running, nothing to do } else { - if (execp->backend->timer) - stop_timeout(execp->backend->timer); // Run command right away - execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); + change_timer(&execp->backend->timer, true, 10, 0, execp_timer_callback, execp); } } @@ -757,8 +754,7 @@ gboolean read_execp(void *obj) close(execp->backend->child_pipe_stderr); execp->backend->child_pipe_stderr = -1; if (execp->backend->interval) - execp->backend->timer = - add_timeout(execp->backend->interval * 1000, 0, execp_timer_callback, execp, &execp->backend->timer); + change_timer(&execp->backend->timer, true, execp->backend->interval * 1000, 0, execp_timer_callback, execp); } char *ansi_clear_screen = (char*)"\x1b[2J"; diff --git a/src/execplugin/execplugin.h b/src/execplugin/execplugin.h index 8bf3d50..d410935 100644 --- a/src/execplugin/execplugin.h +++ b/src/execplugin/execplugin.h @@ -46,7 +46,7 @@ typedef struct ExecpBackend { Background *bg; // Backend state: - timeout *timer; + Timer timer; int child_pipe_stdout; int child_pipe_stderr; pid_t child; diff --git a/src/init.c b/src/init.c index 86e02c6..363e04c 100644 --- a/src/init.c +++ b/src/init.c @@ -110,25 +110,25 @@ void handle_env_vars() } } -static timeout *detect_compositor_timer = NULL; +static Timer detect_compositor_timer = DEFAULT_TIMER; static int detect_compositor_timer_counter = 0; void detect_compositor(void *arg) { if (server.composite_manager) { - stop_timeout(detect_compositor_timer); + stop_timer(&detect_compositor_timer); return; } detect_compositor_timer_counter--; if (detect_compositor_timer_counter < 0) { - stop_timeout(detect_compositor_timer); + stop_timer(&detect_compositor_timer); return; } // No compositor, check for one if (XGetSelectionOwner(server.display, server.atom._NET_WM_CM_S0) != None) { - stop_timeout(detect_compositor_timer); + stop_timer(&detect_compositor_timer); // Restart tint2 fprintf(stderr, "tint2: Detected compositor, restarting tint2...\n"); kill(getpid(), SIGUSR1); @@ -141,15 +141,15 @@ void start_detect_compositor() if (server.composite_manager) return; - stop_timeout(detect_compositor_timer); // Check every 0.5 seconds for up to 30 seconds detect_compositor_timer_counter = 60; - detect_compositor_timer = add_timeout(500, 500, detect_compositor, 0, &detect_compositor_timer); + init_timer(&detect_compositor_timer, "detect_compositor_timer"); + change_timer(&detect_compositor_timer, true, 500, 500, detect_compositor, 0); } void create_default_elements() { - default_timeout(); + default_timers(); default_systray(); memset(&server, 0, sizeof(server)); #ifdef ENABLE_BATTERY @@ -280,7 +280,7 @@ void cleanup() xsettings_client = NULL; cleanup_server(); - cleanup_timeout(); + cleanup_timers(); if (server.display) XCloseDisplay(server.display); diff --git a/src/main.c b/src/main.c index 0641266..cc34847 100644 --- a/src/main.c +++ b/src/main.c @@ -748,7 +748,7 @@ void run_tint2_event_loop() // Wait for an event and handle it ts_event_read = 0; - if (XPending(server.display) > 0 || select(max_fd + 1, &fds, 0, 0, get_next_timeout()) >= 0) { + if (XPending(server.display) > 0 || select(max_fd + 1, &fds, 0, 0, get_duration_to_next_timer_expiration()) >= 0) { #ifdef HAVE_TRACING start_tracing((void*)run_tint2_event_loop); #endif diff --git a/src/panel.c b/src/panel.c index 89478ff..4deafb4 100644 --- a/src/panel.c +++ b/src/panel.c @@ -145,7 +145,7 @@ void cleanup_panel() if (p->main_win) XDestroyWindow(server.display, p->main_win); p->main_win = 0; - stop_timeout(p->autohide_timeout); + stop_timer(&p->autohide_timeout); cleanup_freespace(p); } @@ -1062,7 +1062,7 @@ Button *click_button(Panel *panel, int x, int y) void stop_autohide_timeout(Panel *p) { - stop_timeout(p->autohide_timeout); + stop_timer(&p->autohide_timeout); } void autohide_show(void *p) @@ -1092,7 +1092,7 @@ void autohide_trigger_show(Panel *p) { if (!p) return; - change_timeout(&p->autohide_timeout, panel_autohide_show_timeout, 0, autohide_show, p); + change_timer(&p->autohide_timeout, true, panel_autohide_show_timeout, 0, autohide_show, p); } void autohide_trigger_hide(Panel *p) @@ -1107,7 +1107,7 @@ void autohide_trigger_hide(Panel *p) if (child) return; // mouse over one of the system tray icons - change_timeout(&p->autohide_timeout, panel_autohide_hide_timeout, 0, autohide_hide, p); + change_timer(&p->autohide_timeout, true, panel_autohide_hide_timeout, 0, autohide_hide, p); } void shrink_panel(Panel *panel) diff --git a/src/panel.h b/src/panel.h index 8601602..46ac686 100644 --- a/src/panel.h +++ b/src/panel.h @@ -144,7 +144,7 @@ typedef struct Panel { gboolean is_hidden; int hidden_width, hidden_height; Pixmap hidden_pixmap; - timeout *autohide_timeout; + Timer autohide_timeout; } Panel; extern Panel panel_config; diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index ba4730c..2f0b4e0 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -543,11 +543,11 @@ static gint compare_traywindows(gconstpointer a, gconstpointer b) const TrayWindow *traywin_b = (const TrayWindow *)b; #if 0 - // This breaks pygtk2 StatusIcon with blinking activated - if (traywin_a->empty && !traywin_b->empty) - return 1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1); - if (!traywin_a->empty && traywin_b->empty) - return -1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1); + // This breaks pygtk2 StatusIcon with blinking activated + if (traywin_a->empty && !traywin_b->empty) + return 1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1); + if (!traywin_a->empty && traywin_b->empty) + return -1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1); #endif if (systray.sort == SYSTRAY_SORT_ASCENDING || systray.sort == SYSTRAY_SORT_DESCENDING) { @@ -940,8 +940,8 @@ void remove_icon(TrayWindow *traywin) XDestroyWindow(server.display, traywin->parent); XSync(server.display, False); XSetErrorHandler(old); - stop_timeout(traywin->render_timeout); - stop_timeout(traywin->resize_timeout); + stop_timer(&traywin->render_timeout); + stop_timer(&traywin->resize_timeout); free(traywin->name); if (traywin->image) { imlib_context_set_image(traywin->image); @@ -1055,9 +1055,8 @@ void systray_reconfigure_event(TrayWindow *traywin, XEvent *e) if (traywin->bad_size_counter < min_bad_resize_events) { systray_resize_icon(traywin); } else { - if (!traywin->resize_timeout) - traywin->resize_timeout = - add_timeout(fast_resize_period, 0, systray_resize_icon, traywin, &traywin->resize_timeout); + if (!traywin->resize_timeout.enabled_) + change_timer(&traywin->resize_timeout, true, fast_resize_period, 0, systray_resize_icon, traywin); } } else { if (traywin->bad_size_counter == max_bad_resize_events) { @@ -1071,14 +1070,13 @@ void systray_reconfigure_event(TrayWindow *traywin, XEvent *e) // FIXME Normally we should force the icon to resize fill_color to the size we resized it to when we // embedded it. // However this triggers a resize loop in new versions of GTK, which we must avoid. - if (!traywin->resize_timeout) - traywin->resize_timeout = - add_timeout(slow_resize_period, 0, systray_resize_icon, traywin, &traywin->resize_timeout); + if (!traywin->resize_timeout.enabled_) + change_timer(&traywin->resize_timeout, true, slow_resize_period, 0, systray_resize_icon, traywin); return; } } else { // Correct size - stop_timeout(traywin->resize_timeout); + stop_timer(&traywin->resize_timeout); } // Resize and redraw the systray @@ -1135,9 +1133,8 @@ void systray_resize_request_event(TrayWindow *traywin, XEvent *e) if (traywin->bad_size_counter < min_bad_resize_events) { systray_resize_icon(traywin); } else { - if (!traywin->resize_timeout) - traywin->resize_timeout = - add_timeout(fast_resize_period, 0, systray_resize_icon, traywin, &traywin->resize_timeout); + if (!traywin->resize_timeout.enabled_) + change_timer(&traywin->resize_timeout, true, fast_resize_period, 0, systray_resize_icon, traywin); } } else { if (traywin->bad_size_counter == max_bad_resize_events) { @@ -1150,14 +1147,13 @@ void systray_resize_request_event(TrayWindow *traywin, XEvent *e) // Delayed resize // FIXME Normally we should force the icon to resize to the size we resized it to when we embedded it. // However this triggers a resize loop in some versions of GTK, which we must avoid. - if (!traywin->resize_timeout) - traywin->resize_timeout = - add_timeout(slow_resize_period, 0, systray_resize_icon, traywin, &traywin->resize_timeout); + if (!traywin->resize_timeout.enabled_) + change_timer(&traywin->resize_timeout, true, slow_resize_period, 0, systray_resize_icon, traywin); return; } } else { // Correct size - stop_timeout(traywin->resize_timeout); + stop_timer(&traywin->resize_timeout); } // Resize and redraw the systray @@ -1224,8 +1220,7 @@ void systray_render_icon_composited(void *t) if (compare_timespecs(&earliest_render, &now) > 0) { traywin->num_fast_renders++; if (traywin->num_fast_renders > max_fast_refreshes) { - traywin->render_timeout = - add_timeout(min_refresh_period, 0, systray_render_icon_composited, traywin, &traywin->render_timeout); + change_timer(&traywin->render_timeout, true, min_refresh_period, 0, systray_render_icon_composited, traywin); if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", @@ -1244,8 +1239,7 @@ void systray_render_icon_composited(void *t) if (traywin->width == 0 || traywin->height == 0) { // reschedule rendering since the geometry information has not yet been processed (can happen on slow cpu) - traywin->render_timeout = - add_timeout(min_refresh_period, 0, systray_render_icon_composited, traywin, &traywin->render_timeout); + change_timer(&traywin->render_timeout, true, min_refresh_period, 0, systray_render_icon_composited, traywin); if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", @@ -1257,9 +1251,8 @@ void systray_render_icon_composited(void *t) return; } - if (traywin->render_timeout) { - stop_timeout(traywin->render_timeout); - traywin->render_timeout = NULL; + if (traywin->render_timeout.enabled_) { + stop_timer(&traywin->render_timeout); } // good systray icons support 32 bit depth, but some icons are still 24 bit. @@ -1423,9 +1416,8 @@ void systray_render_icon(void *t) // __LINE__, // traywin->win, // traywin->name); - stop_timeout(traywin->render_timeout); - traywin->render_timeout = - add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); + stop_timer(&traywin->render_timeout); + change_timer(&traywin->render_timeout, true, min_refresh_period, 0, systray_render_icon, traywin); return; } @@ -1448,19 +1440,17 @@ void systray_render_icon(void *t) unsigned int width, height, depth; Window root; if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { - stop_timeout(traywin->render_timeout); - if (!traywin->render_timeout) - traywin->render_timeout = - add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); + stop_timer(&traywin->render_timeout); + if (!traywin->render_timeout.enabled_) + change_timer(&traywin->render_timeout, true, min_refresh_period, 0, systray_render_icon, traywin); systray_render_icon_from_image(traywin); XSetErrorHandler(old); return; } else { if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) { - stop_timeout(traywin->render_timeout); - if (!traywin->render_timeout) - traywin->render_timeout = - add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); + stop_timer(&traywin->render_timeout); + if (!traywin->render_timeout.enabled_) + change_timer(&traywin->render_timeout, true, min_refresh_period, 0, systray_render_icon, traywin); systray_render_icon_from_image(traywin); if (systray_profile) fprintf(stderr, diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index c1f86e0..66211f2 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -56,11 +56,11 @@ typedef struct { // Members used for rendering struct timespec time_last_render; int num_fast_renders; - timeout *render_timeout; + Timer render_timeout; // Members used for resizing int bad_size_counter; struct timespec time_last_resize; - timeout *resize_timeout; + Timer resize_timeout; // Icon contents if we are compositing the icon, otherwise null Imlib_Image image; // XDamage diff --git a/src/taskbar/task.c b/src/taskbar/task.c index c5798f0..76edf49 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -35,7 +35,7 @@ #include "tooltip.h" #include "window.h" -timeout *urgent_timeout; +Timer urgent_timer; GSList *urgent_list; void task_dump_geometry(void *obj, int indent); @@ -782,8 +782,8 @@ void add_urgent(Task *task) // not yet in the list, so we have to add it urgent_list = g_slist_prepend(urgent_list, task); - if (!urgent_timeout) - urgent_timeout = add_timeout(10, 1000, blink_urgent, 0, &urgent_timeout); + if (!urgent_timer.enabled_) + change_timer(&urgent_timer, true, 10, 1000, blink_urgent, 0); Panel *panel = task->area.panel; if (panel->is_hidden) @@ -793,10 +793,8 @@ void add_urgent(Task *task) void del_urgent(Task *task) { urgent_list = g_slist_remove(urgent_list, task); - if (!urgent_list) { - stop_timeout(urgent_timeout); - urgent_timeout = NULL; - } + if (!urgent_list) + stop_timer(&urgent_timer); } void task_handle_mouse_event(Task *task, MouseAction action) diff --git a/src/taskbar/task.h b/src/taskbar/task.h index 9d84b18..7e44074 100644 --- a/src/taskbar/task.h +++ b/src/taskbar/task.h @@ -84,7 +84,7 @@ typedef struct Task { double thumbnail_last_update; } Task; -extern timeout *urgent_timeout; +extern Timer urgent_timer; extern GSList *urgent_list; Task *add_task(Window win); diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 70fd77d..6234883 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -47,9 +47,9 @@ gboolean hide_taskbar_if_empty; gboolean always_show_all_desktop_tasks; TaskbarSortMethod taskbar_sort_method; Alignment taskbar_alignment; -static timeout *thumbnail_update_timer_all; -static timeout *thumbnail_update_timer_active; -static timeout *thumbnail_update_timer_tooltip; +static Timer thumbnail_update_timer_all; +static Timer thumbnail_update_timer_active; +static Timer thumbnail_update_timer_tooltip; static GList *taskbar_task_orderings = NULL; static GList *taskbar_thumbnail_jobs_done = NULL; @@ -80,7 +80,7 @@ void free_ptr_array(gpointer data) void default_taskbar() { win_to_task = NULL; - urgent_timeout = NULL; + INIT_TIMER(urgent_timer); urgent_list = NULL; taskbar_enabled = FALSE; taskbar_distribute_size = FALSE; @@ -89,9 +89,9 @@ void default_taskbar() hide_task_diff_monitor = FALSE; hide_taskbar_if_empty = FALSE; always_show_all_desktop_tasks = FALSE; - thumbnail_update_timer_all = NULL; - thumbnail_update_timer_active = NULL; - thumbnail_update_timer_tooltip = NULL; + INIT_TIMER(thumbnail_update_timer_all); + INIT_TIMER(thumbnail_update_timer_active); + INIT_TIMER(thumbnail_update_timer_tooltip); taskbar_thumbnail_jobs_done = NULL; taskbar_sort_method = TASKBAR_NOSORT; taskbar_alignment = ALIGN_LEFT; @@ -134,9 +134,9 @@ void taskbar_save_orderings() void cleanup_taskbar() { - stop_timeout(thumbnail_update_timer_all); - stop_timeout(thumbnail_update_timer_active); - stop_timeout(thumbnail_update_timer_tooltip); + destroy_timer(&thumbnail_update_timer_all); + destroy_timer(&thumbnail_update_timer_active); + destroy_timer(&thumbnail_update_timer_tooltip); g_list_free(taskbar_thumbnail_jobs_done); taskbar_save_orderings(); if (win_to_task) { @@ -170,7 +170,7 @@ void cleanup_taskbar() g_slist_free(urgent_list); urgent_list = NULL; - stop_timeout(urgent_timeout); + destroy_timer(&urgent_timer); for (int state = 0; state < TASK_STATE_COUNT; state++) { g_list_free(panel_config.g_task.gradient[state]); @@ -384,12 +384,13 @@ void taskbar_start_thumbnail_timer(ThumbnailUpdateMode mode) return; if (debug_thumbnails) fprintf(stderr, BLUE "tint2: taskbar_start_thumbnail_timer %s" RESET "\n", mode == THUMB_MODE_ACTIVE_WINDOW ? "active" : mode == THUMB_MODE_TOOLTIP_WINDOW ? "tooltip" : "all"); - change_timeout(mode == THUMB_MODE_ALL ? &thumbnail_update_timer_all : + change_timer(mode == THUMB_MODE_ALL ? &thumbnail_update_timer_all : mode == THUMB_MODE_ACTIVE_WINDOW ? &thumbnail_update_timer_active : &thumbnail_update_timer_tooltip, - mode == THUMB_MODE_TOOLTIP_WINDOW ? 1000 : 500, - mode == THUMB_MODE_ALL ? 10 * 1000 : 0, - taskbar_update_thumbnails, - (void *)(long)mode); + true, + mode == THUMB_MODE_TOOLTIP_WINDOW ? 1000 : 500, + mode == THUMB_MODE_ALL ? 10 * 1000 : 0, + taskbar_update_thumbnails, + (void *)(long)mode); } void taskbar_init_fonts() @@ -844,7 +845,7 @@ void taskbar_update_thumbnails(void *arg) if (mode == THUMB_MODE_ALL) { double now = get_time(); if (now - start_time > 0.030) { - change_timeout(&thumbnail_update_timer_all, 50, 10 * 1000, taskbar_update_thumbnails, arg); + change_timer(&thumbnail_update_timer_all, true, 50, 10 * 1000, taskbar_update_thumbnails, arg); return; } } @@ -855,7 +856,7 @@ void taskbar_update_thumbnails(void *arg) if (taskbar_thumbnail_jobs_done) { g_list_free(taskbar_thumbnail_jobs_done); taskbar_thumbnail_jobs_done = NULL; - change_timeout(&thumbnail_update_timer_all, 10 * 1000, 10 * 1000, taskbar_update_thumbnails, arg); + change_timer(&thumbnail_update_timer_all, true, 10 * 1000, 10 * 1000, taskbar_update_thumbnails, arg); } } } diff --git a/src/tooltip/tooltip.c b/src/tooltip/tooltip.c index d81ecff..1b60010 100644 --- a/src/tooltip/tooltip.c +++ b/src/tooltip/tooltip.c @@ -54,7 +54,7 @@ void default_tooltip() void cleanup_tooltip() { stop_tooltip_timeout(); - stop_timeout(g_tooltip.update_timeout); + stop_timer(&g_tooltip.update_timeout); tooltip_hide(NULL); tooltip_update_contents_for(NULL); if (g_tooltip.window) @@ -325,17 +325,17 @@ void tooltip_hide(void *arg) void start_show_timeout() { - change_timeout(&g_tooltip.timeout, g_tooltip.show_timeout_msec, 0, tooltip_show, 0); + change_timer(&g_tooltip.timeout, true, g_tooltip.show_timeout_msec, 0, tooltip_show, 0); } void start_hide_timeout() { - change_timeout(&g_tooltip.timeout, g_tooltip.hide_timeout_msec, 0, tooltip_hide, 0); + change_timer(&g_tooltip.timeout, true, g_tooltip.hide_timeout_msec, 0, tooltip_hide, 0); } void stop_tooltip_timeout() { - stop_timeout(g_tooltip.timeout); + stop_timer(&g_tooltip.timeout); } void tooltip_update_contents_timeout(void *arg) @@ -356,7 +356,7 @@ void tooltip_update_contents_for(Area *area) if (g_tooltip.image) cairo_surface_reference(g_tooltip.image); else - change_timeout(&g_tooltip.update_timeout, 300, 0, tooltip_update_contents_timeout, NULL); + change_timer(&g_tooltip.update_timeout, true, 300, 0, tooltip_update_contents_timeout, NULL); } g_tooltip.area = area; } diff --git a/src/tooltip/tooltip.h b/src/tooltip/tooltip.h index f6ccf22..7694cb4 100644 --- a/src/tooltip/tooltip.h +++ b/src/tooltip/tooltip.h @@ -36,8 +36,8 @@ typedef struct { PangoFontDescription *font_desc; Color font_color; Background *bg; - timeout *timeout; - timeout *update_timeout; + Timer timeout; + Timer update_timeout; cairo_surface_t *image; } Tooltip; diff --git a/src/util/test.c b/src/util/test.c index 33f810b..2c640f1 100644 --- a/src/util/test.c +++ b/src/util/test.c @@ -58,10 +58,17 @@ err: free(output_name); } +static void crash(int sig) +{ + kill(getpid(), SIGSEGV); +} + __attribute__((noreturn)) static void run_test_child(TestListItem *item) { reset_signals(); + struct sigaction sa = {.sa_handler = crash}; + sigaction(SIGINT, &sa, 0); redirect_test_output(item->name); bool result = true; item->test(&result); @@ -120,6 +127,8 @@ static Status run_test(TestListItem *item) pid_t pid = fork(); if (pid == 0) run_test_child(item); + struct sigaction sa = {.sa_handler = SIG_IGN}; + sigaction(SIGINT, &sa, 0); return run_test_parent(item, pid); } diff --git a/src/util/timer.c b/src/util/timer.c index 363f53f..30fd7db 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -41,19 +41,17 @@ void cleanup_timers() void init_timer(Timer *timer, const char *name) { - if (g_list_find(timers, timer)) { - fprintf(stderr, RED "tint2: Attempt to init the same timer twice: %s" RESET "\n", timer->name_); - return; - } bzero(timer, sizeof(*timer)); strncpy(timer->name_, name, sizeof(timer->name_)); - timers = g_list_append(timers, timer); + if (!g_list_find(timers, timer)) { + timers = g_list_append(timers, timer); + } } void destroy_timer(Timer *timer) { if (!g_list_find(timers, timer)) { - fprintf(stderr, RED "tint2: Attempt to destroy unexisting timer: %s" RESET "\n", timer->name_); + fprintf(stderr, RED "tint2: Attempt to destroy nonexisting timer: %s" RESET "\n", timer->name_); return; } timers = g_list_remove(timers, timer); @@ -62,8 +60,8 @@ void destroy_timer(Timer *timer) void change_timer(Timer *timer, bool enabled, int delay_ms, int period_ms, TimerCallback *callback, void *arg) { if (!g_list_find(timers, timer)) { - fprintf(stderr, RED "tint2: Attempt to change unexisting timer: %s" RESET "\n", timer->name_); - return; + fprintf(stderr, RED "tint2: Attempt to change unknown timer" RESET "\n"); + init_timer(timer, "unknown"); } timer->enabled_ = enabled; timer->expiration_time_ = get_time() + delay_ms / 1000.; @@ -121,8 +119,9 @@ void handle_expired_timers() timer->handled_ = false; } - bool triggered = false; + bool triggered; do { + triggered = false; for (GList *it = current_timers; it; it = it->next) { Timer *timer = (Timer *)it->data; // Check that it is still registered. diff --git a/src/util/timer.h b/src/util/timer.h index 522844d..bd0024d 100644 --- a/src/util/timer.h +++ b/src/util/timer.h @@ -35,6 +35,10 @@ typedef struct { bool handled_; } Timer; +#define DEFAULT_TIMER {"", 0, 0, 0, 0, 0, 0} + +#define INIT_TIMER(t) init_timer(&t, #t) + // Initialize the timer module. void default_timers();