summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/tdeeventdevice.h
blob: a1f1af6a68d6a4b37c26f3819da2e8f270b63956 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* This file is part of the TDE libraries
   Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
             (C) 2013 Golubev Alexander <fatzer2@gmail.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef _TDEEVENTDEVICE_H
#define _TDEEVENTDEVICE_H

#include "tdegenericdevice.h"

class TDEHardwareDevices;

namespace TDEEventDeviceType {
enum TDEEventDeviceType {
	Unknown,
	ACPILidSwitch,
	ACPISleepButton,
	ACPISuspendButton,
	ACPIPowerButton,
	ACPIOtherInput,
	Other = 0x80000000
};
};

// Keep friendlySwitchList() in tdehardwaredevices.cpp in sync with this enum
namespace TDESwitchType {
enum TDESwitchType {
	Null			= 0x00000000,
	Lid			= 0x00000001,
	TabletMode		= 0x00000002,
	HeadphoneInsert		= 0x00000004,
	RFKill			= 0x00000008,
	Radio			= 0x00000010,
	MicrophoneInsert	= 0x00000020,
	Dock			= 0x00000040,
	LineOutInsert		= 0x00000080,
	JackPhysicalInsert	= 0x00000100,
	VideoOutInsert		= 0x00000200,
	CameraLensCover		= 0x00000400,
	KeypadSlide		= 0x00000800,
	FrontProximity		= 0x00001000,
	RotateLock		= 0x00002000,
	LineInInsert		= 0x00004000,
	PowerButton		= 0x00008000,
	SleepButton		= 0x00010000
};

inline TDESwitchType operator|(TDESwitchType a, TDESwitchType b)
{
	return static_cast<TDESwitchType>(static_cast<int>(a) | static_cast<int>(b));
}

inline TDESwitchType operator&(TDESwitchType a, TDESwitchType b)
{
	return static_cast<TDESwitchType>(static_cast<int>(a) & static_cast<int>(b));
}

inline TDESwitchType operator~(TDESwitchType a)
{
	return static_cast<TDESwitchType>(~static_cast<int>(a));
}
};

class TQSocketNotifier;

class TDECORE_EXPORT TDEEventDevice : public TDEGenericDevice
{
	TQ_OBJECT

	public:
		/**
		*  Constructor.
		*  @param Device type
		*/
		TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null);
		
		/**
		* Destructor.
		*/
		~TDEEventDevice();

		/**
		* @return a TDEEventDeviceType::TDEEventDeviceType with the event device type, if known
		*/
		TDEEventDeviceType::TDEEventDeviceType eventType();

		/**
		* @return a TDESwitchType::TDESwitchType with all switches provided by this device
		*/
		TDESwitchType::TDESwitchType providedSwitches();

		/**
		* @return a TDESwitchType::TDESwitchType with all active switches provided by this device
		*/
		TDESwitchType::TDESwitchType activeSwitches();

		/**
		* @param switches a TDESwitchType::TDESwitchType with any switch flags set
		* @return a TQStringList with friendly names for all set switch flags
		*/
		static TQStringList friendlySwitchList(TDESwitchType::TDESwitchType switches);

	protected:
		/**
		* @param et a TDEEventDeviceType::TDEEventDeviceType with the event device type, if known
		* @internal
		*/
		void internalSetEventType(TDEEventDeviceType::TDEEventDeviceType et);

		/**
		* @internal
		*/
		void internalReadProvidedSwitches();

		/**
		* @param sl a TDESwitchType::TDESwitchType with all switches provided by this device
		* @internal
		*/
		void internalSetProvidedSwitches(TDESwitchType::TDESwitchType sl);

		/**
		* @internal
		*/
		void internalReadActiveSwitches();

		/**
		* @param sl a TDESwitchType::TDESwitchType with all active switches provided by this device
		* @internal
		*/
		void internalSetActiveSwitches(TDESwitchType::TDESwitchType sl);

		/**
		* @param hwmanager the master hardware manager
		* @internal
		*/
		void internalStartMonitoring(TDEHardwareDevices* hwmanager);

	protected slots:
		void eventReceived();
		void processActiveSwitches();
		virtual void connectNotify( const char* signal );

	signals:
		/**
		* @param keycode the code of the key that was pressed/released
		* See include/linux/input.h for a complete list of keycodes
		* @param device a TDEEventDevice* with the device that received the event
		*/
		void keyPressed(unsigned int keycode, TDEEventDevice* device);

		void switchChanged();

	private:
		TDEEventDeviceType::TDEEventDeviceType m_eventType;
		TDESwitchType::TDESwitchType m_providedSwitches;
		TDESwitchType::TDESwitchType m_switchActive;

		int m_fd;
		bool m_monitorActive;
		TQTimer* m_watchTimer;
		TQSocketNotifier* m_eventNotifier;

	friend class TDEHardwareDevices;
};

#endif // _TDEEVENTDEVICE_H