1 // ActivityMonitor.hh --- ActivityMonitor functionality
2 //
3 // Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2010, 2013 Rob Caelers <robc@krandor.nl>
4 // All rights reserved.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef ACTIVITYMONITOR_HH
21 #define ACTIVITYMONITOR_HH
22 
23 #include "IActivityMonitor.hh"
24 #include "IInputMonitorListener.hh"
25 #include "Mutex.hh"
26 
27 #if TIME_WITH_SYS_TIME
28 # include <sys/time.h>
29 # include <time.h>
30 #else
31 # if HAVE_SYS_TIME_H
32 #  include <sys/time.h>
33 # else
34 #  include <time.h>
35 # endif
36 #endif
37 
38 class ActivityListener;
39 class IInputMonitor;
40 
41 class ActivityMonitor :
42   public IInputMonitorListener,
43   public IActivityMonitor
44 {
45 public:
46   ActivityMonitor();
47   virtual ~ActivityMonitor();
48 
49   void terminate();
50   void suspend();
51   void resume();
52   void force_idle();
53   void shift_time(int delta);
54 
55   ActivityState get_current_state();
56 
57   void set_parameters(int noise, int activity, int idle, int sensitivity);
58   void get_parameters(int &noise, int &activity, int &idle, int &sensitivity);
59 
60   void set_listener(ActivityMonitorListener *l);
61 
62   void action_notify();
63   void mouse_notify(int x, int y, int wheel = 0);
64   void button_notify(bool is_press);
65   void keyboard_notify(bool repeat);
66 
67 private:
68   void call_listener();
69 
70 private:
71   //! The actual monitoring driver.
72   IInputMonitor *input_monitor;
73 
74   //! the current state.
75   ActivityState activity_state;
76 
77   //! Internal locking
78   Mutex lock;
79 
80   //! Previous X coordinate
81   int prev_x;
82 
83   //! Previous Y coordinate
84   int prev_y;
85 
86   //! Is the button currently pressed?
87   bool button_is_pressed;
88 
89   //! Last time activity was detected
90   gint64 last_action_time;
91 
92   //! First time the \c ACTIVITY_IDLE state was left.
93   gint64 first_action_time;
94 
95   //! The noise threshold
96   gint64 noise_threshold;
97 
98   //! The activity threshold.
99   gint64 activity_threshold;
100 
101   //! The idle threshold.
102   gint64 idle_threshold;
103 
104   //! Mouse sensitivity
105   int sensitivity;
106 
107   //! Activity listener.
108   ActivityMonitorListener *listener;
109 };
110 
111 #endif // ACTIVITYMONITOR_HH
112