Add removing window decorations to FAQ.
[fvwm.git] / libs / timeout.c
blob9ee78585bd7eb4dc463696908a50b04741471406
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* ---------------------------- included header files ---------------------- */
19 #include "config.h"
20 #include <stdio.h>
22 #include "safemalloc.h"
23 #include "timeout.h"
25 /* ---------------------------- local definitions -------------------------- */
27 /* ---------------------------- local macros ------------------------------- */
29 /* ---------------------------- imports ------------------------------------ */
31 /* ---------------------------- included code files ------------------------ */
33 /* ---------------------------- local types -------------------------------- */
35 /* ---------------------------- forward declarations ----------------------- */
37 /* ---------------------------- local variables ---------------------------- */
39 /* ---------------------------- exported variables (globals) --------------- */
41 /* ---------------------------- local functions ---------------------------- */
43 /* ---------------------------- interface functions ------------------------ */
45 timeout_t *timeout_create(
46 int n_timeouts)
48 timeout_t *to;
50 if (n_timeouts < 0 || n_timeouts > TIMEOUT_MAX_TIMEOUTS)
52 return NULL;
54 to = (timeout_t *)safecalloc(1, sizeof(timeout_t));
55 to->n_timeouts = n_timeouts;
56 to->timeouts = (timeout_time_t *)safecalloc(
57 1, n_timeouts * sizeof(timeout_time_t));
59 return to;
62 void timeout_destroy(
63 timeout_t *to)
65 if (to == NULL)
67 return;
69 if (to->timeouts != NULL)
71 free(to->timeouts);
73 free(to);
75 return;
78 timeout_mask_t timeout_tick(
79 timeout_t *to, timeout_time_t n_ticks)
81 timeout_mask_t mask;
82 int i;
84 if (n_ticks <= 0)
86 return 0;
88 for (i = 0, mask = 0; i < to->n_timeouts; i++)
90 if (to->timeouts[i] > n_ticks)
92 to->timeouts[i] -= n_ticks;
94 else if (to->timeouts[i] > 0)
96 to->timeouts[i] = 0;
97 mask |= 1 << i;
101 return mask;
104 void timeout_rewind(
105 timeout_t *to, timeout_mask_t mask, timeout_time_t ticks_before_alarm)
107 int i;
109 if (ticks_before_alarm < 0)
111 return;
113 for (i = 0; i < to->n_timeouts; i++)
115 if (mask & (1 << i))
117 to->timeouts[i] = ticks_before_alarm;
121 return;