aboutsummaryrefslogtreecommitdiff
path: root/src/Timer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Timer.cc')
-rw-r--r--src/Timer.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/Timer.cc b/src/Timer.cc
new file mode 100644
index 0000000..f35f274
--- /dev/null
+++ b/src/Timer.cc
@@ -0,0 +1,82 @@
1// Timer.cc for Blackbox - An X11 Window Manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// stupid macros needed to access some functions in version 2 of the GNU C
23// library
24#ifndef _GNU_SOURCE
25# define _GNU_SOURCE
26#endif // _GNU_SOURCE
27
28#ifdef HAVE_CONFIG_H
29# include "../config.h"
30#endif // HAVE_CONFIG_H
31
32#include "BaseDisplay.hh"
33#include "Timer.hh"
34
35
36BTimer::BTimer(BaseDisplay *d, TimeoutHandler *h) {
37 display = d;
38 handler = h;
39
40 once = timing = False;
41}
42
43
44BTimer::~BTimer(void) {
45 if (timing) stop();
46}
47
48
49void BTimer::setTimeout(long t) {
50 _timeout.tv_sec = t / 1000;
51 _timeout.tv_usec = t;
52 _timeout.tv_usec -= (_timeout.tv_sec * 1000);
53 _timeout.tv_usec *= 1000;
54}
55
56
57void BTimer::setTimeout(timeval t) {
58 _timeout.tv_sec = t.tv_sec;
59 _timeout.tv_usec = t.tv_usec;
60}
61
62
63void BTimer::start(void) {
64 gettimeofday(&_start, 0);
65
66 if (! timing) {
67 timing = True;
68 display->addTimer(this);
69 }
70}
71
72
73void BTimer::stop(void) {
74 timing = False;
75
76 display->removeTimer(this);
77}
78
79
80void BTimer::fireTimeout(void) {
81 if (handler) handler->timeout();
82}