From ee43155a4bedc6f9e2eafd2e2af00b85e92ad2be Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 28 Nov 2025 00:55:48 +0100 Subject: Add method to list running timeouts (#1306). \see Fl::timeout_list(); --- FL/Fl.H | 3 +++ src/Fl.cxx | 8 ++++++++ src/Fl_Timeout.cxx | 11 +++++++++++ src/Fl_Timeout.h | 1 + 4 files changed, 23 insertions(+) diff --git a/FL/Fl.H b/FL/Fl.H index 358dde432..fbaad5df1 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -50,6 +50,7 @@ #endif #include // FIXME: Fl::is_scheme(): strcmp needs string.h +#include class Fl_Widget; class Fl_Window; @@ -242,6 +243,8 @@ FL_EXPORT extern void repeat_timeout(double t, Fl_Timeout_Handler cb, void *data FL_EXPORT extern int has_timeout(Fl_Timeout_Handler cb, void *data = 0); FL_EXPORT extern void remove_timeout(Fl_Timeout_Handler cb, void *data = 0); FL_EXPORT extern int remove_next_timeout(Fl_Timeout_Handler cb, void *data = 0, void **data_return = 0); +typedef struct { double t; Fl_Timeout_Handler cb; void *data; } TimeoutData; +FL_EXPORT extern std::vector timeout_list(); FL_EXPORT extern void add_check(Fl_Timeout_Handler, void* = 0); FL_EXPORT extern int has_check(Fl_Timeout_Handler, void* = 0); diff --git a/src/Fl.cxx b/src/Fl.cxx index 22ad0353a..c470f95e3 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -448,6 +448,14 @@ int Fl::remove_next_timeout(Fl_Timeout_Handler cb, void *data, void **data_retur return Fl_Timeout::remove_next_timeout(cb, data, data_return); } +/** + Return a list of all currently running timeouts. + \return a vector with all relevant timeout data +*/ +std::vector Fl::timeout_list() { + return Fl_Timeout::timeout_list(); +} + //////////////////////////////////////////////////////////////// // Checks are just stored in a list. They are called in the reverse diff --git a/src/Fl_Timeout.cxx b/src/Fl_Timeout.cxx index 9aa89b839..4ba8a0f63 100644 --- a/src/Fl_Timeout.cxx +++ b/src/Fl_Timeout.cxx @@ -344,6 +344,17 @@ int Fl_Timeout::remove_next_timeout(Fl_Timeout_Handler cb, void *data, void **da return ret; } +std::vector Fl_Timeout::timeout_list() { + std::vector v; + const Fl_Timeout *t = first_timeout; + while (t) { + v.push_back( { t->time, t->callback, t->data } ); + t = t->next; + } + return v; +} + + /** Remove the timeout from the active timer queue and push it onto the stack of currently running callbacks. diff --git a/src/Fl_Timeout.h b/src/Fl_Timeout.h index 9d9cc2337..279935a71 100644 --- a/src/Fl_Timeout.h +++ b/src/Fl_Timeout.h @@ -109,6 +109,7 @@ public: static void repeat_timeout(double time, Fl_Timeout_Handler cb, void *data); static void remove_timeout(Fl_Timeout_Handler cb, void *data); static int remove_next_timeout(Fl_Timeout_Handler cb, void *data = NULL, void **data_return = NULL); + static std::vector timeout_list(); // Elapse timeouts, i.e. calculate new delay time of all timers. // This does not call the timer callbacks. -- cgit v1.2.3