-
Notifications
You must be signed in to change notification settings - Fork 0
/
focus.cpp
101 lines (80 loc) · 2.57 KB
/
focus.cpp
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
#include<QtDBus/QDBusConnection>
#include<QtDBus/QDBusMessage>
#include<QtDBus/QDBusVariant>
#include<QtDBus/QDBusMetaType>
#include "focus.h"
QDBusArgument& operator<< (QDBusArgument& argument, const SpiReference& address)
{
argument.beginStructure();
argument << address.service;
argument << address.path;
argument.endStructure();
return argument;
}
const QDBusArgument& operator>> (const QDBusArgument& argument, SpiReference& address)
{
argument.beginStructure();
argument >> address.service;
argument >> address.path;
argument.endStructure();
return argument;
}
Focus::Focus()
{
qDBusRegisterMetaType<SpiReference>();
if(!dbc.connection().registerService("org.aman.focustracker"))
qWarning() << "Could not register service";
QVariantList subscriptions;
subscriptions << QString("object:state-changed") << QString("focus:");
QDBusMessage m = QDBusMessage::createMethodCall("org.a11y.atspi.Registry", //service
"/org/a11y/atspi/registry", //path
"org.a11y.atspi.Registry", //interface
"RegisterEvent"); //Method
m.setArguments(subscriptions);
QDBusMessage reply = dbc.connection().call(m);
if(reply.type() == QDBusMessage::ErrorMessage)
qWarning() << "focus :: Could not register subscriptions\n";
if(!dbc.connection().connect(QString(), //service
"", //path
"org.a11y.atspi.Event.Object", //interface
"StateChanged",
this, //reciever
SLOT(stateChanged(QString,int,int,QDBusVariant,SpiReference)))){
qWarning() << "Could not connect the signal\n";
}
}
void Focus::stateChanged(const QString& state,
int detail1,
int detail2,
const QDBusVariant& arg,
const SpiReference& ref) const
{
if(state=="focused" && detail1==1){
qDebug() << "Focus signal detected\n";
//qDebug() << "State: "<<state << detail1 << detail2 << arg.variant() << ref.service <<ref.path.path() << "\n";
QDBusMessage m = QDBusMessage::createMethodCall(
ref.service,
ref.path.path(),
"org.a11y.atspi.Accessible",
"GetState");
QDBusMessage reply = dbc.connection().call(m);
if(reply.arguments().isEmpty()){
qDebug() << "Empty reply : State not obtained\n";
return;
}
QList<uint> objectState;
const QDBusArgument returnValue = reply.arguments().at(0).value<QDBusArgument>();
returnValue.beginArray();
while(returnValue.atEnd()){
int arg;
returnValue >> arg;
objectState << arg;
}
returnValue.endArray();
Q_ASSERT(state.count()==2); //Make sure that there are only
}
}
const DBusConnection& Focus::connection() const
{
return dbc;
}