Commit 272fbd06edb80e321b7c172d207714ce6f2050a6

Authored by ksamak
1 parent 07a89e5b
Exists in focuspoll

working focuspoll, need lock with mousepoll not to freeze

plugins/ezoom/src/ezoom.cpp
... ... @@ -695,7 +695,7 @@ EZoomScreen::enableMousePolling()
695 695 /* Enables polling of focus position */
696 696 void EZoomScreen::enableFocusPolling() {
697 697 if (!optionGetFollowFocus()) { return; }
698   - pollFocusHandle.start ();
  698 + //pollFocusHandle.start ();
699 699 lastFocusChange = time(NULL);
700 700 }
701 701  
... ... @@ -1220,10 +1220,6 @@ EZoomScreen::updateMouseInterval (const CompPoint &p) {
1220 1220 void EZoomScreen::updateFocusInterval() {
1221 1221 updateFocusPosition();
1222 1222  
1223   - if (!grabbed) {
1224   - cursorMoved ();
1225   - }
1226   -
1227 1223 if (pollFocusHandle.active ()) {
1228 1224 pollFocusHandle.stop ();
1229 1225 }
... ...
plugins/focuspoll/CMakeLists.txt
1 1 find_package (Compiz REQUIRED)
2 2  
3 3 include (CompizPlugin)
4   -
5 4 include_directories (include/accessibilitywatcher)
6   -#link_directories (${CMAKE_CURRENT_BINARY_DIR}/src/pixmapbinding)
7 5  
8   -#include( FindPkgConfig )
9 6 pkg_search_module( ATSPI REQUIRED atspi-2 )
10 7  
11   -message(STATUS "at-spi include : " ${ATSPI_LIBRARIES})
12   -message(STATUS "at-spi include : " ${ATSPI_LIB})
13   -
14 8 compiz_plugin (focuspoll LIBRARIES ${ATSPI_LIBRARIES} INCDIRS ${ATSPI_INCLUDE_DIRS} )
15 9  
16 10 # PKGDEPS pangocairo cairo cairo-xlib-xrender
... ...
plugins/focuspoll/src/private.h
... ... @@ -53,6 +53,7 @@ class FocuspollScreen :
53 53 bool addTimer (FocusPoller *poller);
54 54 void removeTimer (FocusPoller *poller);
55 55 void updateTimer ();
  56 +
56 57 private:
57 58 AccessibilityWatcher* a11ywatcher;
58 59 };
... ...
plugins/mousepoll/src/accessibilitywatcher.cpp
... ... @@ -1,659 +0,0 @@
1   -/*
2   - * Coyright (C) 2016 Auboyneau Vincent <ksamak@riseup.net>
3   - *
4   - * mate-accessibility is free software: you can redistribute it and/or modify
5   - * it under the terms of the GNU General Public License as published by the Free
6   - * Software Foundation, either version 3 of the License, or (at your option) any
7   - * later version.
8   - *
9   - * mate-accessibility is distributed in the hope that it will be useful, but
10   - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12   - * details.
13   - *
14   - * You should have received a copy of the GNU General Public License along
15   - * with mate-accessibility. If not, see <http://www.gnu.org/licenses/>.
16   - */
17   -
18   -
19   -#include <iostream>
20   -
21   -#include <string.h>
22   -#include <stdlib.h>
23   -#include <unistd.h>
24   -
25   -#include "accessibilitywatcher.h"
26   -
27   -AccessibilityWatcher* AccessibilityWatcher::_instance = NULL;
28   -
29   -AccessibilityWatcher::AccessibilityWatcher() :
30   - _initialized(false),
31   - _curSender(),
32   - _curPath(),
33   - _curRole(""),
34   - _activeSender(),
35   - _activePath(),
36   - _activeRole(),
37   - _componentX(),
38   - _componentY(),
39   - _componentWidth(),
40   - _componentHeight(),
41   - _caretX(),
42   - _caretY(),
43   - _caretWidth(),
44   - _caretHeight()
45   -{
46   -}
47   -
48   -AccessibilityWatcher* AccessibilityWatcher::get_instance() {
49   - if(_instance == NULL) {
50   - _instance = new AccessibilityWatcher();
51   - }
52   - return _instance;
53   -}
54   -
55   -DBusMessage* AccessibilityWatcher::new_method_call(std::string sender, std::string path, std::string interface, std::string method) {
56   - DBusError error;
57   - DBusMessage *msg;
58   -
59   - dbus_error_init(&error);
60   - msg = dbus_message_new_method_call(sender.c_str(), path.c_str(), interface.c_str(), method.c_str());
61   - if (dbus_error_is_set(&error)) {
62   - std::string errmsg = "error while making message: " + method + " " + error.name + " " + error.message;
63   - dbus_error_free(&error);
64   - throw DbusException(errmsg);
65   - }
66   - if (!msg) { throw DbusException("no memory while making message: " + method); }
67   - return msg;
68   -}
69   -
70   -/* Creates a method call message */
71   -DBusMessage* AccessibilityWatcher::new_method_call(std::string interface, std::string method) {
72   - return new_method_call(_curSender, _curPath, interface, method);
73   -}
74   -
75   -/* Sends a method call message, and returns the reply, if any. This unrefs the message. */
76   -DBusMessage* AccessibilityWatcher::send_with_reply_and_block(DBusMessage *msg, std::string doing) {
77   - return send_with_reply_and_block(msg, doing, _timeout_ms);
78   -}
79   -
80   -DBusMessage* AccessibilityWatcher::send_with_reply_and_block(DBusMessage *msg, std::string doing, int timeout) {
81   - DBusError error;
82   - DBusMessage *reply;
83   -
84   - dbus_error_init(&error);
85   - reply = dbus_connection_send_with_reply_and_block(_bus, msg, timeout, &error);
86   - dbus_message_unref(msg);
87   - if (dbus_error_is_set(&error)) {
88   - std::string errmsg = "error while " + doing + " name:" + error.name + " : " + error.message;
89   - dbus_error_free(&error);
90   - throw DbusException(errmsg);
91   - }
92   - if (!reply) {
93   - std::string errmsg = "timeout while " + doing;
94   - throw DbusException(errmsg);
95   - }
96   - if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
97   - std::string errmsg = "Dbus error reply received while " + doing;
98   - dbus_message_unref(reply);
99   - throw DbusException(errmsg);
100   - }
101   - return reply;
102   -}
103   -
104   -void AccessibilityWatcher::finiTerm() {
105   - _activeSender = "";
106   - _activePath = "";
107   -}
108   -
109   -/* Get the role of an AT-SPI2 object */
110   -std::string AccessibilityWatcher::getRole() {
111   - const char *text;
112   - DBusMessage *msg, *reply;
113   - DBusMessageIter iter;
114   -
115   - msg = new_method_call(SPI2_DBUS_INTERFACE_ACCESSIBLE, "GetRoleName");
116   - if (!msg) { throw DbusException("failed to get message in getRoleName"); }
117   - reply = send_with_reply_and_block(msg, "getting role");
118   -
119   - dbus_message_iter_init(reply, &iter);
120   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
121   - std::string errmsg = "GetRoleName didn't return a string but " + dbus_message_iter_get_arg_type(&iter);
122   - dbus_message_unref(reply);
123   - throw DbusException(errmsg);
124   - }
125   - dbus_message_iter_get_basic(&iter, &text);
126   - dbus_message_unref(reply);
127   - return std::string(strdup(text));
128   -}
129   -
130   -/* Get the absolute position of an AT-SPI2 object */
131   -void AccessibilityWatcher::getPosition(unsigned* x, unsigned* y) {
132   - dbus_uint32_t dbus_x, dbus_y;
133   - DBusMessage *msg, *reply;
134   - dbus_uint32_t coord_type = ATSPI_COORD_TYPE_SCREEN;
135   - DBusMessageIter iter;
136   -
137   - msg = new_method_call(SPI2_DBUS_INTERFACE_COMPONENT, "GetPosition");
138   - dbus_message_append_args(msg, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID);
139   - reply = send_with_reply_and_block(msg, "getting component position");
140   -
141   - dbus_message_iter_init(reply, &iter);
142   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
143   - dbus_message_unref(reply);
144   - throw DbusException("getPosition didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter));
145   - }
146   - dbus_message_iter_get_basic(&iter, &dbus_x);
147   - dbus_message_iter_next (&iter);
148   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
149   - dbus_message_unref(reply);
150   - throw DbusException("getPosition didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter));
151   - }
152   - dbus_message_iter_get_basic(&iter, &dbus_y);
153   - *x = dbus_x;
154   - *y = dbus_y; // TODO lose the unsigned* c-style
155   -}
156   -
157   -/* Get the size of an AT-SPI2 object */
158   -void AccessibilityWatcher::getSize(unsigned* width, unsigned* height) {
159   - dbus_uint32_t dbus_width, dbus_height;
160   - DBusMessage *msg, *reply;
161   - DBusMessageIter iter;
162   -
163   - msg = new_method_call(SPI2_DBUS_INTERFACE_COMPONENT, "GetSize");
164   - reply = send_with_reply_and_block(msg, "getting size");
165   -
166   - dbus_message_iter_init(reply, &iter);
167   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
168   - dbus_message_unref(reply);
169   - throw DbusException("getSize didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter));
170   - }
171   - dbus_message_iter_get_basic(&iter, &dbus_width);
172   - dbus_message_iter_next (&iter);
173   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
174   - dbus_message_unref(reply);
175   - throw DbusException("getSize didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter));
176   - }
177   - dbus_message_iter_get_basic(&iter, &dbus_height);
178   - *width = dbus_width;
179   - *height = dbus_height; // TODO lose the c-style signature
180   -}
181   -
182   -std::tuple<unsigned, unsigned, unsigned, unsigned> AccessibilityWatcher::getTextExtents(dbus_int32_t offset) {
183   - dbus_uint32_t dbus_x, dbus_y, dbus_width, dbus_height;
184   - DBusMessage *msg, *reply;
185   - DBusMessageIter iter;
186   - dbus_uint32_t coordType = ATSPI_COORD_TYPE_SCREEN;
187   -
188   - msg = new_method_call(SPI2_DBUS_INTERFACE_TEXT, "GetCharacterExtents");
189   -
190   - dbus_message_append_args(msg, DBUS_TYPE_INT32, &offset, DBUS_TYPE_UINT32, &coordType, DBUS_TYPE_INVALID);
191   - reply = send_with_reply_and_block(msg, "getting character extents");
192   -
193   - if (strcmp (dbus_message_get_signature (reply), "iiii") != 0) {
194   - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting caret position";
195   - dbus_message_unref(reply);
196   - throw DbusException(err_msg);
197   - }
198   -
199   - // let's get the values out of the message
200   - dbus_message_iter_init (reply, &iter);
201   -
202   - dbus_message_iter_get_basic(&iter, &dbus_x);
203   - dbus_message_iter_next (&iter);
204   - dbus_message_iter_get_basic(&iter, &dbus_y);
205   - dbus_message_iter_next (&iter);
206   - dbus_message_iter_get_basic(&iter, &dbus_width);
207   - dbus_message_iter_next (&iter);
208   - dbus_message_iter_get_basic(&iter, &dbus_height);
209   - dbus_message_iter_next (&iter);
210   -
211   - dbus_message_unref(reply);
212   - return std::make_tuple(unsigned(dbus_x), unsigned(dbus_y), unsigned(dbus_width), unsigned(dbus_height));
213   -}
214   -
215   -
216   -/* Switched to a new terminal, restart from scratch */
217   -void AccessibilityWatcher::restartTerm() {
218   - unsigned x = 0, y = 0, width = 0, height = 0;
219   - std::string role;
220   - if (_activePath != "") {
221   - finiTerm();
222   - }
223   - try {
224   - role = getRole();
225   - } catch (DbusException e) {
226   - std::cerr << "caught exception: " << e.what() << std::endl << " component => " << _curSender << ":" << _curPath << std::endl;
227   - }
228   -
229   - try {
230   - getPosition(&x, &y);
231   - getSize(&width, &height);
232   - } catch (DbusException e) {
233   - std::cerr << "caught exception: " << e.what() << std::endl << "Not switching active component to " << _curSender << ":" << _curPath << std::endl;
234   - return;
235   - }
236   -
237   - _activeSender = _curSender;
238   - _activePath = _curPath;
239   - _activeRole = role;
240   - _componentX = x;
241   - _componentY = y;
242   - _componentWidth = width;
243   - _componentHeight = height;
244   -
245   - _focus_list.push_front(FocusInfo("component", _curSender, role, int16_t(x), int16_t(y), int16_t(width), int16_t(height)));
246   -}
247   -
248   -/* Get the state of an object */
249   -dbus_uint32_t AccessibilityWatcher::getState() {
250   - DBusMessage *msg, *reply;
251   - DBusMessageIter iter, iter_array;
252   - dbus_uint32_t *states = NULL;
253   - int count;
254   -
255   - msg = new_method_call(SPI2_DBUS_INTERFACE_ACCESSIBLE, "GetState");
256   - reply = send_with_reply_and_block(msg, "getting state");
257   - if (strcmp (dbus_message_get_signature (reply), "au") != 0) {
258   - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting active state";
259   - dbus_message_unref(reply);
260   - throw DbusException(err_msg);
261   - }
262   - dbus_message_iter_init (reply, &iter);
263   - dbus_message_iter_recurse (&iter, &iter_array);
264   - dbus_message_iter_get_fixed_array (&iter_array, &states, &count);
265   - if (count != 2) {
266   - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting active state";
267   - dbus_message_unref(reply);
268   - throw DbusException(err_msg);
269   - }
270   - return states[0]; // TODO there are two uint32 returned, we only use one, but make this func return both eventually.
271   -}
272   -
273   -/* Check whether an ancestor of this object is active */
274   -bool AccessibilityWatcher::checkActiveParent(const char* sender, const char* path) {
275   - DBusMessage *msg, *reply;
276   - DBusMessageIter iter, iter_variant, iter_struct;
277   - const char *interface = SPI2_DBUS_INTERFACE_ACCESSIBLE;
278   - const char *property = "Parent";
279   - dbus_uint32_t states;
280   -
281   - msg = new_method_call(sender, path, FREEDESKTOP_DBUS_INTERFACE_PROP, "Get");
282   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
283   - reply = send_with_reply_and_block(msg, "checking active object");
284   - if (strcmp (dbus_message_get_signature (reply), "v") != 0) {
285   - auto errmsg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while checking active object";
286   - dbus_message_unref(reply);
287   - throw DbusException(errmsg);
288   - }
289   -
290   - dbus_message_iter_init (reply, &iter);
291   - dbus_message_iter_recurse (&iter, &iter_variant);
292   - dbus_message_iter_recurse (&iter_variant, &iter_struct);
293   - dbus_message_iter_get_basic (&iter_struct, &sender);
294   - dbus_message_iter_next (&iter_struct);
295   - dbus_message_iter_get_basic (&iter_struct, &path);
296   -
297   - states = getState();
298   - return (states & (1<<ATSPI_STATE_ACTIVE)) != 0 || checkActiveParent(sender, path);
299   -}
300   -
301   -/* Check whether this object is the focused object (which is way faster than
302   - * browsing all objects of the desktop) */
303   -bool AccessibilityWatcher::reinitTerm() {
304   - dbus_uint32_t states = 0;
305   - try {
306   - states = getState();
307   - } catch (DbusException e) {
308   - std::cerr << "caught exception in " << __func__ << ": " << e.what() << std::endl;
309   - }
310   - int active = 0;
311   -
312   - if (!states) {
313   - return false;
314   - }
315   -
316   - /* Whether this widget is active */
317   - active = (states & (1<<ATSPI_STATE_ACTIVE)) != 0;
318   -
319   - if (states & (1<<ATSPI_STATE_FOCUSED)) {
320   - /* This widget is focused */
321   - if (active) {
322   - /* And it is active, we are done. */
323   - restartTerm();
324   - return true;
325   - } else {
326   - /* Check that a parent is active. */
327   - const char *sender = _curSender.c_str();
328   - const char *path = _curPath.c_str();
329   - bool res = checkActiveParent(sender, path);
330   - _curSender = std::string(sender);
331   - _curPath = std::string(path);
332   - return res;
333   - }
334   - }
335   - return false;
336   -}
337   -
338   -/* Try to find an active object among children of the given object */
339   -bool AccessibilityWatcher::recurseFindTerm(const char *sender, const char *path, int active, int depth) {
340   - DBusMessage *msg, *reply;
341   - DBusMessageIter iter, iter_array, iter_struct;
342   -
343   - msg = new_method_call(sender, path, SPI2_DBUS_INTERFACE_ACCESSIBLE, "GetChildren");
344   - reply = send_with_reply_and_block(msg, "getting active object");
345   -
346   - if (strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
347   - {
348   - auto errmsg = "unexpected signature" + std::string(dbus_message_get_signature(reply)) + " while getting active object";
349   - dbus_message_unref(reply);
350   - throw DbusException(errmsg);
351   - }
352   - dbus_message_iter_init(reply, &iter);
353   - dbus_message_iter_recurse (&iter, &iter_array);
354   - while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
355   - {
356   - char *sender, *path;
357   - dbus_message_iter_recurse (&iter_array, &iter_struct);
358   - dbus_message_iter_get_basic (&iter_struct, &sender);
359   - dbus_message_iter_next (&iter_struct);
360   - dbus_message_iter_get_basic (&iter_struct, &path);
361   - _curSender = std::string(sender);
362   - _curPath = std::string(path);
363   - try {
364   - if (findTerm(sender, path, active, depth)) {
365   - dbus_message_unref(reply);
366   - return true;
367   - }
368   - } catch (DbusException e) {
369   - std::cerr << "caught exception in " << __func__ << ": " << e.what() << std::endl;
370   - }
371   - dbus_message_iter_next (&iter_array);
372   - }
373   -
374   - dbus_message_unref(reply);
375   - return false;
376   -}
377   -
378   -/* Test whether this object is active, and if not recurse in its children */
379   -bool AccessibilityWatcher::findTerm(const char *sender, const char *path, int active, int depth) {
380   - dbus_uint32_t states = getState();
381   - if (states & (1<<ATSPI_STATE_ACTIVE))
382   - /* This application is active */
383   - active = 1;
384   -
385   - if (states & (1<<ATSPI_STATE_FOCUSED) && active)
386   - {
387   - /* And this widget is focused */
388   - restartTerm();
389   - return true;
390   - }
391   - return recurseFindTerm(sender, path, active, depth+1);
392   -}
393   -
394   -/* Find out currently focused terminal, starting from registry */
395   -void AccessibilityWatcher::initTerm(void) {
396   - const char* sender;
397   - if (_curSender.empty()) {
398   - sender = SPI2_DBUS_INTERFACE_REG;
399   - } else {
400   - sender = _curSender.c_str();
401   - }
402   - const char* path;
403   - if (_curPath.empty()) {
404   - path = SPI2_DBUS_PATH_ROOT;
405   - } else {
406   - path = _curPath.c_str();
407   - }
408   - recurseFindTerm(sender, path, 0, 0);
409   - _curSender = std::string(sender);
410   - _curPath = std::string(path);
411   -}
412   -
413   -/* Handle incoming events */
414   -void AccessibilityWatcher::AtSpi2HandleEvent(const char* interface, DBusMessage* message) {
415   - DBusMessageIter iter, iter_variant;
416   - const char *detail;
417   - dbus_int32_t detail1, detail2;
418   - const char *member = dbus_message_get_member(message);
419   - _curSender = dbus_message_get_sender(message);
420   - _curPath = dbus_message_get_path(message);
421   -
422   - dbus_message_iter_init(message, &iter);
423   -
424   - if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRUCT) {
425   - /* skip struct */
426   - dbus_message_iter_next(&iter);
427   - }
428   -
429   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
430   - std::cerr << "message detail not a string but " << dbus_message_iter_get_arg_type(&iter) << std::endl;
431   - return;
432   - }
433   - dbus_message_iter_get_basic(&iter, &detail);
434   -
435   - dbus_message_iter_next(&iter);
436   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
437   - std::cerr << "message detail1 not an int32 but " << dbus_message_iter_get_arg_type(&iter) << std::endl;
438   - return;
439   - }
440   - dbus_message_iter_get_basic(&iter, &detail1);
441   -
442   - dbus_message_iter_next(&iter);
443   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) {
444   - std::cerr << "message detail2 not an int32 but " << dbus_message_iter_get_arg_type(&iter) << std::endl;
445   - return;
446   - }
447   - dbus_message_iter_get_basic(&iter, &detail2);
448   -
449   - dbus_message_iter_next(&iter);
450   - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
451   - std::cerr << "message detail2 not a variant but " << dbus_message_iter_get_arg_type(&iter) << std::endl;
452   - return;
453   - }
454   - dbus_message_iter_recurse(&iter, &iter_variant);
455   -
456   - bool StateChanged_focused =
457   - !strcmp(interface, "Object")
458   - && !strcmp(member, "StateChanged")
459   - && !strcmp(detail, "focused");
460   - bool textCaretMoved =
461   - !strcmp(interface, "Object")
462   - && !strcmp(member, "TextCaretMoved");
463   -
464   - if (StateChanged_focused && !detail1) { // object has lost focus
465   - if (_activeSender != "" && _curSender == _activeSender && _curPath == _activePath)
466   - AccessibilityWatcher::finiTerm();
467   - } else if (!strcmp(interface,"Focus") || (StateChanged_focused && detail1)) { // object has lost focus
468   - AccessibilityWatcher::restartTerm();
469   - } else if (textCaretMoved && _curSender == _activeSender && _curPath == _activePath){ // caret has moved. test also prevents taking events in background
470   - unsigned x = 0, y = 0, w = 0, h = 0;
471   - try {
472   - std::tie(x, y, w, h) = getTextExtents(detail1);
473   - } catch (DbusException e) {
474   - std::cerr << "caught exception in " << __func__ << ": " << e.what() << std::endl;
475   - }
476   - if (x == 0 && y == 0) {
477   - return;
478   - }
479   - if (_caretX != x || _caretY != y || _caretWidth != w || _caretHeight != h) { // prevents auto generate, on own output scroll
480   - _caretX = x;
481   - _caretY = y;
482   - _caretWidth = w;
483   - _caretHeight = h;
484   - _focus_list.push_front(FocusInfo("caret", _curSender, _activeRole, int16_t(x), int16_t(y), int16_t(w), int16_t(h)));
485   - //std::cout << _activeRole << " moved to " << _componentX << "," << _componentY << " (" << _componentWidth << "x" << _componentHeight << ") caret:" << _caretX << "," << _caretY << " (" << _caretWidth << "x" << _caretHeight << ")" << std::endl;
486   - }
487   - }
488   -}
489   -
490   -/* Called on messages */
491   -DBusHandlerResult AccessibilityWatcher::AtSpi2Filter(DBusConnection* connection, DBusMessage* message, void* user_data) {
492   - int type = dbus_message_get_type(message);
493   - const char *interface = dbus_message_get_interface(message);
494   - const char *member = dbus_message_get_member(message);
495   -
496   - if (type == DBUS_MESSAGE_TYPE_SIGNAL) {
497   - if (!strncmp(interface, SPI2_DBUS_INTERFACE_EVENT".", strlen(SPI2_DBUS_INTERFACE_EVENT"."))) {
498   - AccessibilityWatcher::get_instance()->AtSpi2HandleEvent(interface + strlen(SPI2_DBUS_INTERFACE_EVENT"."), message);
499   - } else {
500   - std::cout << "unknown signal: Intf:" << interface <<" Msg:" << member << std::endl;
501   - }
502   - } else {
503   - std::cout << "unknown message: Type:" << type << " Intf:" << interface << " Msg:" << member << std::endl;
504   - }
505   - return DBUS_HANDLER_RESULT_HANDLED;
506   -}
507   -
508   -/* Driver construction / destruction */
509   -void AccessibilityWatcher::addWatch(const char* message, const char* event) {
510   - DBusError error;
511   - DBusMessage *msg, *reply;
512   -
513   - dbus_error_init(&error);
514   - dbus_bus_add_match(_bus, message, &error);
515   - if (dbus_error_is_set(&error)) {
516   - std::string errmsg = "error while adding watch " + std::string(message) + ":" + std::string(error.name) + " " + std::string(error.message);
517   - dbus_error_free(&error);
518   - throw DbusException(errmsg);
519   - }
520   - if (!event) {
521   - dbus_error_free(&error);
522   - throw DbusException("no event given in dbus addWatch");
523   - }
524   -
525   - /* Register as event listener. */
526   - msg = new_method_call(SPI2_DBUS_INTERFACE_REG, SPI2_DBUS_PATH_REG, SPI2_DBUS_INTERFACE_REG, "RegisterEvent");
527   - dbus_message_append_args(msg, DBUS_TYPE_STRING, &event, DBUS_TYPE_INVALID);
528   - reply = send_with_reply_and_block(msg, "registering listener", 1000);
529   -
530   - dbus_error_free(&error);
531   - //dbus_message_unref(msg);
532   - dbus_message_unref(reply);
533   -}
534   -
535   -/* Register to events */
536   -void AccessibilityWatcher::addWatches() {
537   - typedef struct {
538   - const char *message;
539   - const char *event;
540   - } WatchEntry;
541   -
542   - static const WatchEntry watchTable[] = {
543   -// { .message = "type='method_call',interface='" SPI2_DBUS_INTERFACE_TREE "'",
544   -// .event = NULL
545   -// },
546   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Focus'",
547   - .event = "focus"
548   - },
549   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object'",
550   - .event = "object"
551   - },
552   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='ChildrenChanged'",
553   - .event = "object:childrenchanged"
554   - },
555   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='StateChanged'",
556   - .event = "object:statechanged"
557   - },
558   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='StateChanged'",
559   - .event = "object:statechanged:focused"
560   - },
561   - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_TEXT ".Object',member='text'",
562   - .event = "object:text-caret-moved"
563   - },
564   - { .message = NULL }
565   - };
566   -
567   - for (const WatchEntry *watch=watchTable; watch->message; watch+=1) {
568   - addWatch(watch->message, watch->event);
569   - }
570   -}
571   -
572   -void AccessibilityWatcher::init() {
573   - if (_initialized) { return; }
574   - DBusError error;
575   -
576   - dbus_error_init(&error);
577   - _bus = atspi_get_a11y_bus();
578   - if (!_bus)
579   - {
580   - _bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
581   - if (dbus_error_is_set(&error)) {
582   - auto exc = DbusException("can't get dbus session bus: " + std::string(error.name) + " " + std::string(error.message));
583   - dbus_error_free(&error);
584   - throw exc;
585   - }
586   - }
587   -
588   - if (!_bus) {
589   - throw DbusException("can't get dbus session bus");
590   - return;
591   - }
592   -
593   - if (!dbus_connection_add_filter(_bus, AtSpi2Filter, NULL, NULL)) {
594   - dbus_connection_unref(_bus);
595   - return;
596   - }
597   -
598   - try {
599   - addWatches();
600   - } catch (DbusException e) {
601   - std::cerr << "caught an exception in " << __func__ << ": " << e.what() << std::endl;
602   - dbus_connection_remove_filter(_bus, AtSpi2Filter, NULL);
603   - dbus_connection_unref(_bus);
604   - return;
605   - };
606   -
607   - if (_activePath.empty()) {
608   - initTerm();
609   - } else if (!reinitTerm()) {
610   - std::cerr << "Dbus caching failed, trying a restart" << std::endl;
611   - initTerm();
612   - }
613   -
614   - _initialized = true;
615   -}
616   -
617   -void AccessibilityWatcher::quit() {
618   - dbus_connection_remove_filter(_bus, AtSpi2Filter, NULL);
619   - dbus_connection_close(_bus);
620   - dbus_connection_unref(_bus);
621   - _initialized = false;
622   -}
623   -
624   -void AccessibilityWatcher::check_and_process_queue() {
625   - try {
626   - dbus_connection_read_write(_bus, _timeout_ms);
627   - while (dbus_connection_get_dispatch_status(_bus) == DBUS_DISPATCH_DATA_REMAINS) {
628   - dbus_connection_dispatch(_bus);
629   - }
630   - } catch (DbusException e) {
631   - std::cerr << "Dbus failed => " << e.what() << std::endl;
632   - }
633   -}
634   -
635   -std::deque<FocusInfo> AccessibilityWatcher::get_focus_queue() {
636   - return _focus_list;
637   -}
638   -
639   -void AccessibilityWatcher::reset_focus_queue() {
640   - _focus_list.clear();
641   -}
642   -
643   -std::tuple<unsigned, unsigned, unsigned, unsigned> AccessibilityWatcher::get_current_caret_bbox() {
644   - return std::tie(_caretX, _caretY, _caretWidth, _caretHeight);
645   -}
646   -
647   -std::tuple<unsigned, unsigned, unsigned, unsigned> AccessibilityWatcher::get_current_active_widget_bbox() {
648   - return std::tie(_componentX, _componentY, _componentWidth, _componentHeight);
649   -}
650   -
651   -
652   -//int main() {
653   -// auto watcher = AccessibilityWatcher::get_instance();
654   -// watcher->init();
655   -// while (true) {
656   -// watcher->check_and_process_queue();
657   -// }
658   -// watcher->quit();
659   -//}
plugins/mousepoll/src/mousepoll.cpp
... ... @@ -52,11 +52,9 @@ MousepollScreen::getMousePosition ()
52 52 bool
53 53 MousepollScreen::updatePosition ()
54 54 {
55   - a11ywatcher->check_and_process_queue();
56   -
57 55 _has_mouse_moved = getMousePosition();
58 56  
59   - if (_has_mouse_moved || !a11ywatcher->get_focus_queue().empty()) {
  57 + if (_has_mouse_moved) {
60 58 for (std::list<MousePoller *>::iterator it = pollers.begin (); it != pollers.end ();) {
61 59 MousePoller *poller = *it;
62 60  
... ... @@ -230,8 +228,6 @@ template class PluginClassHandler &lt;MousepollScreen, CompScreen, COMPIZ_MOUSEPOLL
230 228 MousepollScreen::MousepollScreen (CompScreen *screen) :
231 229 PluginClassHandler <MousepollScreen, CompScreen, COMPIZ_MOUSEPOLL_ABI> (screen)
232 230 {
233   - a11ywatcher = AccessibilityWatcher::get_instance();
234   - a11ywatcher->init();
235 231 updateTimer ();
236 232 timer.setCallback (boost::bind (&MousepollScreen::updatePosition, this));
237 233  
... ... @@ -239,7 +235,6 @@ MousepollScreen::MousepollScreen (CompScreen *screen) :
239 235 }
240 236  
241 237 MousepollScreen::~MousepollScreen() {
242   - a11ywatcher->quit();
243 238 }
244 239  
245 240 bool
... ...
plugins/mousepoll/src/private.h
... ... @@ -25,8 +25,6 @@
25 25 #include <core/timer.h>
26 26  
27 27 #include <mousepoll/mousepoll.h>
28   -#include <accessibilitywatcher/accessibilitywatcher.h>
29   -
30 28 #include "mousepoll_options.h"
31 29  
32 30 typedef enum _MousepollOptions
... ... @@ -68,9 +66,6 @@ class MousepollScreen :
68 66 removeTimer (MousePoller *poller);
69 67  
70 68 void updateTimer ();
71   -
72   - private:
73   - AccessibilityWatcher* a11ywatcher;
74 69 };
75 70  
76 71 #define MOUSEPOLL_SCREEN(s) \
... ...