20 #include "tdeeventdevice.h" 23 #include <linux/input.h> 25 #include <tqsocketnotifier.h> 30 #include "tdehardwaredevices.h" 34 #define BITS_PER_LONG (sizeof(long) * 8) 35 #define NUM_BITS(x) ((((x) - 1) / BITS_PER_LONG) + 1) 36 #define OFF(x) ((x) % BITS_PER_LONG) 37 #define BIT(x) (1UL << OFF(x)) 38 #define LONG(x) ((x) / BITS_PER_LONG) 39 #define BIT_IS_SET(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1) 41 #if defined(WITH_TDEHWLIB_DAEMONS) 42 #include <tqdbusconnection.h> 43 #include <tqdbusproxy.h> 44 #include <tqdbusmessage.h> 45 #include <tqdbusvariant.h> 46 #include <tqdbusdata.h> 47 #include <tqdbusdatalist.h> 50 TDEEventDevice::TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
53 m_monitorActive =
false;
56 TDEEventDevice::~TDEEventDevice() {
66 TDEEventDeviceType::TDEEventDeviceType TDEEventDevice::eventType() {
70 void TDEEventDevice::internalSetEventType(TDEEventDeviceType::TDEEventDeviceType et) {
74 TDESwitchType::TDESwitchType TDEEventDevice::providedSwitches() {
75 if (!m_monitorActive) {
76 internalReadProvidedSwitches();
78 return m_providedSwitches;
81 void TDEEventDevice::internalReadProvidedSwitches() {
82 unsigned long switches[NUM_BITS(EV_CNT)];
86 TDESwitchType::TDESwitchType supportedSwitches = TDESwitchType::Null;
88 r = ioctl(m_fd, EVIOCGBIT(EV_SW, EV_CNT), switches);
90 #ifdef WITH_TDEHWLIB_DAEMONS 92 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
93 if (dbusConn.isConnected()) {
94 TQT_DBusProxy switchesProxy(
"org.trinitydesktop.hardwarecontrol",
95 "/org/trinitydesktop/hardwarecontrol",
96 "org.trinitydesktop.hardwarecontrol.InputEvents",
98 if (switchesProxy.canSend()) {
99 TQValueList<TQT_DBusData> params;
100 params << TQT_DBusData::fromString(deviceNode().ascii());
101 TQT_DBusMessage reply = switchesProxy.sendWithReply(
"GetProvidedSwitches", params);
102 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
103 TQValueList<TQ_UINT32> list = reply[0].toList().toUInt32List();
104 TQValueList<TQ_UINT32>::const_iterator it = list.begin();
105 for (r = 0; it != list.end(); ++it, r++) {
114 if (BIT_IS_SET(switches, SW_LID)) {
115 supportedSwitches = supportedSwitches | TDESwitchType::Lid;
117 if (BIT_IS_SET(switches, SW_TABLET_MODE)) {
118 supportedSwitches = supportedSwitches | TDESwitchType::TabletMode;
120 if (BIT_IS_SET(switches, SW_RFKILL_ALL)) {
121 supportedSwitches = supportedSwitches | TDESwitchType::RFKill;
123 if (BIT_IS_SET(switches, SW_RADIO)) {
124 supportedSwitches = supportedSwitches | TDESwitchType::Radio;
126 if (BIT_IS_SET(switches, SW_MICROPHONE_INSERT)) {
127 supportedSwitches = supportedSwitches | TDESwitchType::MicrophoneInsert;
129 if (BIT_IS_SET(switches, SW_DOCK)) {
130 supportedSwitches = supportedSwitches | TDESwitchType::Dock;
132 if (BIT_IS_SET(switches, SW_LINEOUT_INSERT)) {
133 supportedSwitches = supportedSwitches | TDESwitchType::LineOutInsert;
135 if (BIT_IS_SET(switches, SW_JACK_PHYSICAL_INSERT)) {
136 supportedSwitches = supportedSwitches | TDESwitchType::JackPhysicalInsert;
138 if (BIT_IS_SET(switches, SW_VIDEOOUT_INSERT)) {
139 supportedSwitches = supportedSwitches | TDESwitchType::VideoOutInsert;
141 # ifdef SW_CAMERA_LENS_COVER 142 if (BIT_IS_SET(switches, SW_CAMERA_LENS_COVER)) {
143 supportedSwitches = supportedSwitches | TDESwitchType::CameraLensCover;
146 # ifdef SW_KEYPAD_SLIDE 147 if (BIT_IS_SET(switches, SW_KEYPAD_SLIDE)) {
148 supportedSwitches = supportedSwitches | TDESwitchType::KeypadSlide;
151 # ifdef SW_FRONT_PROXIMITY 152 if (BIT_IS_SET(switches, SW_FRONT_PROXIMITY)) {
153 supportedSwitches = supportedSwitches | TDESwitchType::FrontProximity;
156 # ifdef SW_ROTATE_LOCK 157 if (BIT_IS_SET(switches, SW_ROTATE_LOCK)) {
158 supportedSwitches = supportedSwitches | TDESwitchType::RotateLock;
161 # ifdef SW_LINEIN_INSERT 162 if (BIT_IS_SET(switches, SW_LINEIN_INSERT)) {
163 supportedSwitches = supportedSwitches | TDESwitchType::LineInInsert;
167 if (systemPath().contains(
"PNP0C0D")) {
168 supportedSwitches = supportedSwitches | TDESwitchType::Lid;
170 if (systemPath().contains(
"PNP0C0E") || systemPath().contains(
"/LNXSLPBN")) {
171 supportedSwitches = supportedSwitches | TDESwitchType::SleepButton;
173 if (systemPath().contains(
"PNP0C0C") || systemPath().contains(
"/LNXPWRBN")) {
174 supportedSwitches = supportedSwitches | TDESwitchType::PowerButton;
177 m_providedSwitches = supportedSwitches;
180 void TDEEventDevice::internalSetProvidedSwitches(TDESwitchType::TDESwitchType sl) {
181 m_providedSwitches = sl;
184 TDESwitchType::TDESwitchType TDEEventDevice::activeSwitches() {
185 if (!m_monitorActive) {
186 internalReadActiveSwitches();
188 return m_switchActive;
191 void TDEEventDevice::internalReadActiveSwitches() {
192 unsigned long switches[NUM_BITS(EV_CNT)];
195 TDESwitchType::TDESwitchType activeSwitches = TDESwitchType::Null;
197 r = ioctl(m_fd, EVIOCGSW(
sizeof(switches)), switches);
199 #ifdef WITH_TDEHWLIB_DAEMONS 201 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
202 if (dbusConn.isConnected()) {
203 TQT_DBusProxy switchesProxy(
"org.trinitydesktop.hardwarecontrol",
204 "/org/trinitydesktop/hardwarecontrol",
205 "org.trinitydesktop.hardwarecontrol.InputEvents",
207 if (switchesProxy.canSend()) {
208 TQValueList<TQT_DBusData> params;
209 params << TQT_DBusData::fromString(deviceNode().ascii());
210 TQT_DBusMessage reply = switchesProxy.sendWithReply(
"GetActiveSwitches", params);
211 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
212 TQValueList<TQ_UINT32> list = reply[0].toList().toUInt32List();
213 TQValueList<TQ_UINT32>::const_iterator it = list.begin();
214 for (r = 0; it != list.end(); ++it, r++) {
223 if (BIT_IS_SET(switches, SW_LID)) {
224 activeSwitches = activeSwitches | TDESwitchType::Lid;
226 if (BIT_IS_SET(switches, SW_TABLET_MODE)) {
227 activeSwitches = activeSwitches | TDESwitchType::TabletMode;
229 if (BIT_IS_SET(switches, SW_RFKILL_ALL)) {
230 activeSwitches = activeSwitches | TDESwitchType::RFKill;
232 if (BIT_IS_SET(switches, SW_RADIO)) {
233 activeSwitches = activeSwitches | TDESwitchType::Radio;
235 if (BIT_IS_SET(switches, SW_MICROPHONE_INSERT)) {
236 activeSwitches = activeSwitches | TDESwitchType::MicrophoneInsert;
238 if (BIT_IS_SET(switches, SW_DOCK)) {
239 activeSwitches = activeSwitches | TDESwitchType::Dock;
241 if (BIT_IS_SET(switches, SW_LINEOUT_INSERT)) {
242 activeSwitches = activeSwitches | TDESwitchType::LineOutInsert;
244 if (BIT_IS_SET(switches, SW_JACK_PHYSICAL_INSERT)) {
245 activeSwitches = activeSwitches | TDESwitchType::JackPhysicalInsert;
247 if (BIT_IS_SET(switches, SW_VIDEOOUT_INSERT)) {
248 activeSwitches = activeSwitches | TDESwitchType::VideoOutInsert;
250 # ifdef SW_CAMERA_LENS_COVER 251 if (BIT_IS_SET(switches, SW_CAMERA_LENS_COVER)) {
252 activeSwitches = activeSwitches | TDESwitchType::CameraLensCover;
255 # ifdef SW_KEYPAD_SLIDE 256 if (BIT_IS_SET(switches, SW_KEYPAD_SLIDE)) {
257 activeSwitches = activeSwitches | TDESwitchType::KeypadSlide;
260 # ifdef SW_FRONT_PROXIMITY 261 if (BIT_IS_SET(switches, SW_FRONT_PROXIMITY)) {
262 activeSwitches = activeSwitches | TDESwitchType::FrontProximity;
265 # ifdef SW_ROTATE_LOCK 266 if (BIT_IS_SET(switches, SW_ROTATE_LOCK)) {
267 activeSwitches = activeSwitches | TDESwitchType::RotateLock;
270 # ifdef SW_LINEIN_INSERT 271 if (BIT_IS_SET(switches, SW_LINEIN_INSERT)) {
272 activeSwitches = activeSwitches | TDESwitchType::LineInInsert;
276 m_switchActive = activeSwitches;
279 void TDEEventDevice::internalSetActiveSwitches(TDESwitchType::TDESwitchType sl) {
284 TQStringList TDEEventDevice::friendlySwitchList(TDESwitchType::TDESwitchType switches) {
287 if (switches & TDESwitchType::Lid) {
288 ret.append(i18n(
"Lid Switch"));
290 if (switches & TDESwitchType::TabletMode) {
291 ret.append(i18n(
"Tablet Mode"));
293 if (switches & TDESwitchType::HeadphoneInsert) {
294 ret.append(i18n(
"Headphone Inserted"));
296 if (switches & TDESwitchType::RFKill) {
297 ret.append(i18n(
"Radio Frequency Device Kill Switch"));
299 if (switches & TDESwitchType::Radio) {
300 ret.append(i18n(
"Enable Radio"));
302 if (switches & TDESwitchType::MicrophoneInsert) {
303 ret.append(i18n(
"Microphone Inserted"));
305 if (switches & TDESwitchType::Dock) {
306 ret.append(i18n(
"Docked"));
308 if (switches & TDESwitchType::LineOutInsert) {
309 ret.append(i18n(
"Line Out Inserted"));
311 if (switches & TDESwitchType::JackPhysicalInsert) {
312 ret.append(i18n(
"Physical Jack Inserted"));
314 if (switches & TDESwitchType::VideoOutInsert) {
315 ret.append(i18n(
"Video Out Inserted"));
317 if (switches & TDESwitchType::CameraLensCover) {
318 ret.append(i18n(
"Camera Lens Cover"));
320 if (switches & TDESwitchType::KeypadSlide) {
321 ret.append(i18n(
"Keypad Slide"));
323 if (switches & TDESwitchType::FrontProximity) {
324 ret.append(i18n(
"Front Proximity"));
326 if (switches & TDESwitchType::RotateLock) {
327 ret.append(i18n(
"Rotate Lock"));
329 if (switches & TDESwitchType::LineInInsert) {
330 ret.append(i18n(
"Line In Inserted"));
332 if (switches & TDESwitchType::PowerButton) {
333 ret.append(i18n(
"Power Button"));
335 if (switches & TDESwitchType::SleepButton) {
336 ret.append(i18n(
"Sleep Button"));
342 void TDEEventDevice::internalStartMonitoring(TDEHardwareDevices* hwmanager) {
343 if (!m_monitorActive) {
345 if (eventType() != TDEEventDeviceType::Unknown) {
347 m_eventNotifier =
new TQSocketNotifier(m_fd, TQSocketNotifier::Read,
this);
348 connect( m_eventNotifier, TQT_SIGNAL(activated(
int)),
this, TQT_SLOT(eventReceived()) );
349 m_monitorActive =
true;
352 if (m_monitorActive ==
true) {
354 internalReadProvidedSwitches();
355 internalReadActiveSwitches();
356 connect(
this, TQT_SIGNAL(keyPressed(
unsigned int, TDEEventDevice*)), hwmanager, TQT_SLOT(processEventDeviceKeyPressed(
unsigned int, TDEEventDevice*)) );
361 void TDEEventDevice::eventReceived() {
362 struct input_event ev;
364 r = read(m_fd, &ev,
sizeof(
struct input_event));
366 if ((ev.type == EV_KEY) && (ev.value == 1)) {
367 emit keyPressed(ev.code,
this);
369 if (ev.type == EV_SW) {
370 emit switchChanged();
375 void TDEEventDevice::processActiveSwitches() {
376 TDESwitchType::TDESwitchType previousSwitches = m_switchActive;
377 internalReadActiveSwitches();
379 if (previousSwitches != m_switchActive) {
380 emit switchChanged();
384 void TDEEventDevice::connectNotify(
const char* signal ) {
385 if( !m_monitorActive && qstrcmp( signal, TQT_SIGNAL(switchChanged())) == 0 ) {
386 m_watchTimer =
new TQTimer(
this);
387 connect( m_watchTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(processActiveSwitches()) );
388 m_watchTimer->start( 2500, FALSE );
389 m_monitorActive =
true;
392 internalReadProvidedSwitches();
393 internalReadActiveSwitches();
395 TQObject::connectNotify( signal );
398 #include "tdeeventdevice.moc"
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)