all repos — tint2 @ 405c2c9286a719481de59bda030dd1ee99a5f994

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

src/util/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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*************************************************************************
*
* Copyright (C) 2009 Andreas.Fink (Andreas.Fink85@gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**************************************************************************/

#ifndef TIMER_H
#define TIMER_H

#include <glib.h>
#include <time.h>
#include <sys/time.h>
#include "bool.h"

extern bool debug_timers;

typedef void TimerCallback(void *arg);

typedef struct {
    char name_[64];
    bool enabled_;
    long long expiration_time_ms_;
    int period_ms_;
    TimerCallback *callback_;
    void *arg_;
    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();

// Destroy the timer module.
void cleanup_timers();

// Initialize a timer. Caller keeps ownership.
void init_timer(Timer *timer, const char *name);

// Destroy a timer. Does not free() the pointer.
void destroy_timer(Timer *timer);

// Modify a timer.
void change_timer(Timer *timer, bool enabled, int delay_ms, int period_ms, TimerCallback *callback, void *arg);

void stop_timer(Timer *timer);

// Get the time duration to the next expiration time, or NULL if there is no active timer.
// Do not free the pointer; it is harmless to change its contents.
struct timeval *get_duration_to_next_timer_expiration();

// Trigger all expired timers, and reschedule them if they are periodic timers
void handle_expired_timers();

// Time helper functions.

// Returns -1 if t1 < t2, 0 if t1 == t2, 1 if t1 > t2
gint compare_timespecs(const struct timespec *t1, const struct timespec *t2);

struct timespec add_msec_to_timespec(struct timespec ts, int msec);

// Returns the time difference in seconds between the current time and the last time this function was called.
// At the first call returns zero.
double profiling_get_time();

// Get current time in seconds, from an unspecified origin.
double get_time();

#endif // TIMER_H