-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdish-atk-backend.c
More file actions
151 lines (122 loc) · 3.75 KB
/
dish-atk-backend.c
File metadata and controls
151 lines (122 loc) · 3.75 KB
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
/*
* Dump the accessibility hierarchy tree for a given application.
* It shows the (name, role) for each object
* TODO: show stateset too.
*
* To get the name it tries get_name and the labelled_by relationship.
*
*/
#include <atspi/atspi.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
static gchar*
get_label(AtspiAccessible *accessible)
{
GArray *relations;
AtspiRelation *relation;
gint i;
gchar *result = "";
relations = atspi_accessible_get_relation_set (accessible, NULL);
if (relations == NULL) {
return "";
}
for (i = 0; i < relations->len; i++) {
relation = g_array_index (relations, AtspiRelation*, i);
if (atspi_relation_get_relation_type (relation) == ATSPI_RELATION_LABELLED_BY) {
result = atspi_accessible_get_name (atspi_relation_get_target (relation, 0), NULL);
}
}
if (relations != NULL)
g_array_free (relations, TRUE);
return result;
}
static void output_atkocr_line(int x, int w, int y, int h, const char* text)
{
if(!*text || x < 0 || y < 0)
return;
typedef struct Duplicate_Suppression
{
int x, w, y, h;
char text[16];
} Duplicate_Suppression;
static Duplicate_Suppression* duplicate_list;
static unsigned duplicate_list_size;
Duplicate_Suppression current = {x, w, y, h};
strncpy(current.text,text,15);
for(unsigned i=0; i<duplicate_list_size; i++)
if(!memcmp(duplicate_list + i, ¤t, sizeof(Duplicate_Suppression)))
return;
duplicate_list_size++;
duplicate_list = realloc(duplicate_list, sizeof(Duplicate_Suppression) * duplicate_list_size);
memcpy(duplicate_list + duplicate_list_size - 1, ¤t, sizeof(Duplicate_Suppression));
printf("atkocr INFO: [[[%d, %d], [%d, %d], [%d, %d], [%d, %d]], (\"", x, y, x+w, y, x+w, y+h, x, y+h);
while(*text)
{
if(*text=='"')
putchar('\\');
putchar(*text);
text++;
}
puts("\", 1)]");
}
static gchar*
print_info (AtspiAccessible *accessible)
{
gchar *name = "";
gchar *role_name = "";
gchar* text = "";
AtspiPoint* position = NULL;
AtspiPoint* size = NULL;
if (accessible != NULL) {
name = atspi_accessible_get_name (accessible, NULL);
if ((name == NULL) || (g_strcmp0 (name, "") == 0))
name = get_label (accessible);
role_name = atspi_accessible_get_role_name (accessible, NULL);
AtspiText* text_subobject = atspi_accessible_get_text(accessible);
if(text_subobject)
text = atspi_text_get_text(text_subobject,0,100,NULL);
AtspiComponent* component_subobject = atspi_accessible_get_component(accessible);
if(component_subobject)
{
position = atspi_component_get_position(component_subobject,ATSPI_COORD_TYPE_SCREEN,NULL);
size = atspi_component_get_size(component_subobject,NULL);
}
}
if(position && size)
{
output_atkocr_line(position->x, size->x, position->y, size->y, name);
output_atkocr_line(position->x, size->x, position->y, size->y, role_name);
output_atkocr_line(position->x, size->x, position->y, size->y, text);
}
return NULL;
}
static void
dump_node_content (AtspiAccessible *node)
{
AtspiAccessible *inner_node = NULL;
gint c;
gchar *string = NULL;
print_info(node);
for (c = 0; c < atspi_accessible_get_child_count (node, NULL); c++) {
inner_node = atspi_accessible_get_child_at_index (node, c, NULL);
dump_node_content (inner_node);
g_object_unref (inner_node);
}
g_free (string);
}
int main()
{
gint i;
AtspiAccessible *desktop = NULL;
AtspiAccessible *app = NULL;
atspi_init ();
desktop = atspi_get_desktop (0);
for (i = 0; i < atspi_accessible_get_child_count (desktop, NULL); i++) {
app = atspi_accessible_get_child_at_index (desktop, i, NULL);
dump_node_content (app);
g_object_unref (app);
}
return 1;
}