all repos — openbox @ d6652d0a90bd6c93084b0b9e6cf36123e0ec15d1

openbox fork - make it a bit more like ryudo

openbox/timer.h (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef __timer_h
#define __timer_h

#include <glib.h>

/*! Data type of Timer callback */
typedef void (*TimeoutHandler)(void *data);

typedef struct Timer {
    /*! Microseconds between timer firings */
    long delay;
    /*! Callback for timer expiry */
    TimeoutHandler action;
    /*! Data sent to callback */
    void *data;
    /*! We overload the delete operator to just set this to true */
    gboolean del_me;
    /*! The time the last fire should've been at */
    GTimeVal last;
    /*! When this timer will next trigger */
    GTimeVal timeout;
} Timer;

/*! Initializes the timer subsection */
void timer_startup();
/*! Destroys the timer subsection */
void timer_shutdown();

/* Creates a new timer with a given delay */
Timer *timer_start(long delay, TimeoutHandler cb, void *data);
/* Stops and frees a timer */
void timer_stop(Timer *self);

/*! Dispatch all pending timers. Sets wait to the amount of time to wait for
  the next timer, or NULL if there are no timers to wait for */
void timer_dispatch(GTimeVal **wait);

#endif