I am creating an event with g_timeout_add
or g_timeout_add_seconds
which returns an event id; I can cancel the event by calling g_source_remove
.
However, at some point what I would like to do is see how much time is remaining until the event is fired. Is there a simple way to do this with the glib api, or do I need to manually store and compare timestamps with g_source_get_current_time
?
There is no reasonable way to do this in GLib.
The unreasonable way would be to get the GSource (g_main_context_find_source_by_id) and then invoke the source->source_funcs->prepare() operation on the GSource, which would return the time until the source should be dispatched. This is kind of sketchy: source_funcs is private, and prepare() isn't really intended to be used except internally by the main loop.
Best I can tell it would work though. I haven't tried it.
save the start time + timeout interval, subract from current time when you want to know the time left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With