From 272fbd06edb80e321b7c172d207714ce6f2050a6 Mon Sep 17 00:00:00 2001 From: ksamak Date: Fri, 17 Jun 2016 18:34:34 +0200 Subject: [PATCH] working focuspoll, need lock with mousepoll not to freeze --- plugins/ezoom/src/ezoom.cpp | 6 +- plugins/focuspoll/CMakeLists.txt | 6 - plugins/focuspoll/src/private.h | 1 + .../mousepoll/src/accessibilitywatcher.cpp | 659 ------------------ plugins/mousepoll/src/mousepoll.cpp | 7 +- plugins/mousepoll/src/private.h | 5 - 6 files changed, 3 insertions(+), 681 deletions(-) delete mode 100644 plugins/mousepoll/src/accessibilitywatcher.cpp diff --git a/plugins/ezoom/src/ezoom.cpp b/plugins/ezoom/src/ezoom.cpp index bc904901d..eabbb2440 100644 --- a/plugins/ezoom/src/ezoom.cpp +++ b/plugins/ezoom/src/ezoom.cpp @@ -695,7 +695,7 @@ EZoomScreen::enableMousePolling() /* Enables polling of focus position */ void EZoomScreen::enableFocusPolling() { if (!optionGetFollowFocus()) { return; } - pollFocusHandle.start (); + //pollFocusHandle.start (); lastFocusChange = time(NULL); } @@ -1220,10 +1220,6 @@ EZoomScreen::updateMouseInterval (const CompPoint &p) { void EZoomScreen::updateFocusInterval() { updateFocusPosition(); - if (!grabbed) { - cursorMoved (); - } - if (pollFocusHandle.active ()) { pollFocusHandle.stop (); } diff --git a/plugins/focuspoll/CMakeLists.txt b/plugins/focuspoll/CMakeLists.txt index 5d078cb9d..9b641b62d 100644 --- a/plugins/focuspoll/CMakeLists.txt +++ b/plugins/focuspoll/CMakeLists.txt @@ -1,16 +1,10 @@ find_package (Compiz REQUIRED) include (CompizPlugin) - include_directories (include/accessibilitywatcher) -#link_directories (${CMAKE_CURRENT_BINARY_DIR}/src/pixmapbinding) -#include( FindPkgConfig ) pkg_search_module( ATSPI REQUIRED atspi-2 ) -message(STATUS "at-spi include : " ${ATSPI_LIBRARIES}) -message(STATUS "at-spi include : " ${ATSPI_LIB}) - compiz_plugin (focuspoll LIBRARIES ${ATSPI_LIBRARIES} INCDIRS ${ATSPI_INCLUDE_DIRS} ) # PKGDEPS pangocairo cairo cairo-xlib-xrender diff --git a/plugins/focuspoll/src/private.h b/plugins/focuspoll/src/private.h index 438774a19..b9a10e283 100644 --- a/plugins/focuspoll/src/private.h +++ b/plugins/focuspoll/src/private.h @@ -53,6 +53,7 @@ class FocuspollScreen : bool addTimer (FocusPoller *poller); void removeTimer (FocusPoller *poller); void updateTimer (); + private: AccessibilityWatcher* a11ywatcher; }; diff --git a/plugins/mousepoll/src/accessibilitywatcher.cpp b/plugins/mousepoll/src/accessibilitywatcher.cpp deleted file mode 100644 index 8c11f668b..000000000 --- a/plugins/mousepoll/src/accessibilitywatcher.cpp +++ /dev/null @@ -1,659 +0,0 @@ -/* - * Coyright (C) 2016 Auboyneau Vincent - * - * mate-accessibility is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * mate-accessibility 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along - * with mate-accessibility. If not, see . - */ - - -#include - -#include -#include -#include - -#include "accessibilitywatcher.h" - -AccessibilityWatcher* AccessibilityWatcher::_instance = NULL; - -AccessibilityWatcher::AccessibilityWatcher() : - _initialized(false), - _curSender(), - _curPath(), - _curRole(""), - _activeSender(), - _activePath(), - _activeRole(), - _componentX(), - _componentY(), - _componentWidth(), - _componentHeight(), - _caretX(), - _caretY(), - _caretWidth(), - _caretHeight() -{ -} - -AccessibilityWatcher* AccessibilityWatcher::get_instance() { - if(_instance == NULL) { - _instance = new AccessibilityWatcher(); - } - return _instance; -} - -DBusMessage* AccessibilityWatcher::new_method_call(std::string sender, std::string path, std::string interface, std::string method) { - DBusError error; - DBusMessage *msg; - - dbus_error_init(&error); - msg = dbus_message_new_method_call(sender.c_str(), path.c_str(), interface.c_str(), method.c_str()); - if (dbus_error_is_set(&error)) { - std::string errmsg = "error while making message: " + method + " " + error.name + " " + error.message; - dbus_error_free(&error); - throw DbusException(errmsg); - } - if (!msg) { throw DbusException("no memory while making message: " + method); } - return msg; -} - -/* Creates a method call message */ -DBusMessage* AccessibilityWatcher::new_method_call(std::string interface, std::string method) { - return new_method_call(_curSender, _curPath, interface, method); -} - -/* Sends a method call message, and returns the reply, if any. This unrefs the message. */ -DBusMessage* AccessibilityWatcher::send_with_reply_and_block(DBusMessage *msg, std::string doing) { - return send_with_reply_and_block(msg, doing, _timeout_ms); -} - -DBusMessage* AccessibilityWatcher::send_with_reply_and_block(DBusMessage *msg, std::string doing, int timeout) { - DBusError error; - DBusMessage *reply; - - dbus_error_init(&error); - reply = dbus_connection_send_with_reply_and_block(_bus, msg, timeout, &error); - dbus_message_unref(msg); - if (dbus_error_is_set(&error)) { - std::string errmsg = "error while " + doing + " name:" + error.name + " : " + error.message; - dbus_error_free(&error); - throw DbusException(errmsg); - } - if (!reply) { - std::string errmsg = "timeout while " + doing; - throw DbusException(errmsg); - } - if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { - std::string errmsg = "Dbus error reply received while " + doing; - dbus_message_unref(reply); - throw DbusException(errmsg); - } - return reply; -} - -void AccessibilityWatcher::finiTerm() { - _activeSender = ""; - _activePath = ""; -} - -/* Get the role of an AT-SPI2 object */ -std::string AccessibilityWatcher::getRole() { - const char *text; - DBusMessage *msg, *reply; - DBusMessageIter iter; - - msg = new_method_call(SPI2_DBUS_INTERFACE_ACCESSIBLE, "GetRoleName"); - if (!msg) { throw DbusException("failed to get message in getRoleName"); } - reply = send_with_reply_and_block(msg, "getting role"); - - dbus_message_iter_init(reply, &iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { - std::string errmsg = "GetRoleName didn't return a string but " + dbus_message_iter_get_arg_type(&iter); - dbus_message_unref(reply); - throw DbusException(errmsg); - } - dbus_message_iter_get_basic(&iter, &text); - dbus_message_unref(reply); - return std::string(strdup(text)); -} - -/* Get the absolute position of an AT-SPI2 object */ -void AccessibilityWatcher::getPosition(unsigned* x, unsigned* y) { - dbus_uint32_t dbus_x, dbus_y; - DBusMessage *msg, *reply; - dbus_uint32_t coord_type = ATSPI_COORD_TYPE_SCREEN; - DBusMessageIter iter; - - msg = new_method_call(SPI2_DBUS_INTERFACE_COMPONENT, "GetPosition"); - dbus_message_append_args(msg, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID); - reply = send_with_reply_and_block(msg, "getting component position"); - - dbus_message_iter_init(reply, &iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { - dbus_message_unref(reply); - throw DbusException("getPosition didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter)); - } - dbus_message_iter_get_basic(&iter, &dbus_x); - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { - dbus_message_unref(reply); - throw DbusException("getPosition didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter)); - } - dbus_message_iter_get_basic(&iter, &dbus_y); - *x = dbus_x; - *y = dbus_y; // TODO lose the unsigned* c-style -} - -/* Get the size of an AT-SPI2 object */ -void AccessibilityWatcher::getSize(unsigned* width, unsigned* height) { - dbus_uint32_t dbus_width, dbus_height; - DBusMessage *msg, *reply; - DBusMessageIter iter; - - msg = new_method_call(SPI2_DBUS_INTERFACE_COMPONENT, "GetSize"); - reply = send_with_reply_and_block(msg, "getting size"); - - dbus_message_iter_init(reply, &iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { - dbus_message_unref(reply); - throw DbusException("getSize didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter)); - } - dbus_message_iter_get_basic(&iter, &dbus_width); - dbus_message_iter_next (&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { - dbus_message_unref(reply); - throw DbusException("getSize didn't return an int32 but " + dbus_message_iter_get_arg_type(&iter)); - } - dbus_message_iter_get_basic(&iter, &dbus_height); - *width = dbus_width; - *height = dbus_height; // TODO lose the c-style signature -} - -std::tuple AccessibilityWatcher::getTextExtents(dbus_int32_t offset) { - dbus_uint32_t dbus_x, dbus_y, dbus_width, dbus_height; - DBusMessage *msg, *reply; - DBusMessageIter iter; - dbus_uint32_t coordType = ATSPI_COORD_TYPE_SCREEN; - - msg = new_method_call(SPI2_DBUS_INTERFACE_TEXT, "GetCharacterExtents"); - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &offset, DBUS_TYPE_UINT32, &coordType, DBUS_TYPE_INVALID); - reply = send_with_reply_and_block(msg, "getting character extents"); - - if (strcmp (dbus_message_get_signature (reply), "iiii") != 0) { - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting caret position"; - dbus_message_unref(reply); - throw DbusException(err_msg); - } - - // let's get the values out of the message - dbus_message_iter_init (reply, &iter); - - dbus_message_iter_get_basic(&iter, &dbus_x); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic(&iter, &dbus_y); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic(&iter, &dbus_width); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic(&iter, &dbus_height); - dbus_message_iter_next (&iter); - - dbus_message_unref(reply); - return std::make_tuple(unsigned(dbus_x), unsigned(dbus_y), unsigned(dbus_width), unsigned(dbus_height)); -} - - -/* Switched to a new terminal, restart from scratch */ -void AccessibilityWatcher::restartTerm() { - unsigned x = 0, y = 0, width = 0, height = 0; - std::string role; - if (_activePath != "") { - finiTerm(); - } - try { - role = getRole(); - } catch (DbusException e) { - std::cerr << "caught exception: " << e.what() << std::endl << " component => " << _curSender << ":" << _curPath << std::endl; - } - - try { - getPosition(&x, &y); - getSize(&width, &height); - } catch (DbusException e) { - std::cerr << "caught exception: " << e.what() << std::endl << "Not switching active component to " << _curSender << ":" << _curPath << std::endl; - return; - } - - _activeSender = _curSender; - _activePath = _curPath; - _activeRole = role; - _componentX = x; - _componentY = y; - _componentWidth = width; - _componentHeight = height; - - _focus_list.push_front(FocusInfo("component", _curSender, role, int16_t(x), int16_t(y), int16_t(width), int16_t(height))); -} - -/* Get the state of an object */ -dbus_uint32_t AccessibilityWatcher::getState() { - DBusMessage *msg, *reply; - DBusMessageIter iter, iter_array; - dbus_uint32_t *states = NULL; - int count; - - msg = new_method_call(SPI2_DBUS_INTERFACE_ACCESSIBLE, "GetState"); - reply = send_with_reply_and_block(msg, "getting state"); - if (strcmp (dbus_message_get_signature (reply), "au") != 0) { - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting active state"; - dbus_message_unref(reply); - throw DbusException(err_msg); - } - dbus_message_iter_init (reply, &iter); - dbus_message_iter_recurse (&iter, &iter_array); - dbus_message_iter_get_fixed_array (&iter_array, &states, &count); - if (count != 2) { - auto err_msg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while getting active state"; - dbus_message_unref(reply); - throw DbusException(err_msg); - } - return states[0]; // TODO there are two uint32 returned, we only use one, but make this func return both eventually. -} - -/* Check whether an ancestor of this object is active */ -bool AccessibilityWatcher::checkActiveParent(const char* sender, const char* path) { - DBusMessage *msg, *reply; - DBusMessageIter iter, iter_variant, iter_struct; - const char *interface = SPI2_DBUS_INTERFACE_ACCESSIBLE; - const char *property = "Parent"; - dbus_uint32_t states; - - msg = new_method_call(sender, path, FREEDESKTOP_DBUS_INTERFACE_PROP, "Get"); - dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); - reply = send_with_reply_and_block(msg, "checking active object"); - if (strcmp (dbus_message_get_signature (reply), "v") != 0) { - auto errmsg = "unexpected signature " + std::string(dbus_message_get_signature(reply)) + " while checking active object"; - dbus_message_unref(reply); - throw DbusException(errmsg); - } - - dbus_message_iter_init (reply, &iter); - dbus_message_iter_recurse (&iter, &iter_variant); - dbus_message_iter_recurse (&iter_variant, &iter_struct); - dbus_message_iter_get_basic (&iter_struct, &sender); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &path); - - states = getState(); - return (states & (1<AtSpi2HandleEvent(interface + strlen(SPI2_DBUS_INTERFACE_EVENT"."), message); - } else { - std::cout << "unknown signal: Intf:" << interface <<" Msg:" << member << std::endl; - } - } else { - std::cout << "unknown message: Type:" << type << " Intf:" << interface << " Msg:" << member << std::endl; - } - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* Driver construction / destruction */ -void AccessibilityWatcher::addWatch(const char* message, const char* event) { - DBusError error; - DBusMessage *msg, *reply; - - dbus_error_init(&error); - dbus_bus_add_match(_bus, message, &error); - if (dbus_error_is_set(&error)) { - std::string errmsg = "error while adding watch " + std::string(message) + ":" + std::string(error.name) + " " + std::string(error.message); - dbus_error_free(&error); - throw DbusException(errmsg); - } - if (!event) { - dbus_error_free(&error); - throw DbusException("no event given in dbus addWatch"); - } - - /* Register as event listener. */ - msg = new_method_call(SPI2_DBUS_INTERFACE_REG, SPI2_DBUS_PATH_REG, SPI2_DBUS_INTERFACE_REG, "RegisterEvent"); - dbus_message_append_args(msg, DBUS_TYPE_STRING, &event, DBUS_TYPE_INVALID); - reply = send_with_reply_and_block(msg, "registering listener", 1000); - - dbus_error_free(&error); - //dbus_message_unref(msg); - dbus_message_unref(reply); -} - -/* Register to events */ -void AccessibilityWatcher::addWatches() { - typedef struct { - const char *message; - const char *event; - } WatchEntry; - - static const WatchEntry watchTable[] = { -// { .message = "type='method_call',interface='" SPI2_DBUS_INTERFACE_TREE "'", -// .event = NULL -// }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Focus'", - .event = "focus" - }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object'", - .event = "object" - }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='ChildrenChanged'", - .event = "object:childrenchanged" - }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='StateChanged'", - .event = "object:statechanged" - }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_EVENT ".Object',member='StateChanged'", - .event = "object:statechanged:focused" - }, - { .message = "type='signal',interface='" SPI2_DBUS_INTERFACE_TEXT ".Object',member='text'", - .event = "object:text-caret-moved" - }, - { .message = NULL } - }; - - for (const WatchEntry *watch=watchTable; watch->message; watch+=1) { - addWatch(watch->message, watch->event); - } -} - -void AccessibilityWatcher::init() { - if (_initialized) { return; } - DBusError error; - - dbus_error_init(&error); - _bus = atspi_get_a11y_bus(); - if (!_bus) - { - _bus = dbus_bus_get(DBUS_BUS_SESSION, &error); - if (dbus_error_is_set(&error)) { - auto exc = DbusException("can't get dbus session bus: " + std::string(error.name) + " " + std::string(error.message)); - dbus_error_free(&error); - throw exc; - } - } - - if (!_bus) { - throw DbusException("can't get dbus session bus"); - return; - } - - if (!dbus_connection_add_filter(_bus, AtSpi2Filter, NULL, NULL)) { - dbus_connection_unref(_bus); - return; - } - - try { - addWatches(); - } catch (DbusException e) { - std::cerr << "caught an exception in " << __func__ << ": " << e.what() << std::endl; - dbus_connection_remove_filter(_bus, AtSpi2Filter, NULL); - dbus_connection_unref(_bus); - return; - }; - - if (_activePath.empty()) { - initTerm(); - } else if (!reinitTerm()) { - std::cerr << "Dbus caching failed, trying a restart" << std::endl; - initTerm(); - } - - _initialized = true; -} - -void AccessibilityWatcher::quit() { - dbus_connection_remove_filter(_bus, AtSpi2Filter, NULL); - dbus_connection_close(_bus); - dbus_connection_unref(_bus); - _initialized = false; -} - -void AccessibilityWatcher::check_and_process_queue() { - try { - dbus_connection_read_write(_bus, _timeout_ms); - while (dbus_connection_get_dispatch_status(_bus) == DBUS_DISPATCH_DATA_REMAINS) { - dbus_connection_dispatch(_bus); - } - } catch (DbusException e) { - std::cerr << "Dbus failed => " << e.what() << std::endl; - } -} - -std::deque AccessibilityWatcher::get_focus_queue() { - return _focus_list; -} - -void AccessibilityWatcher::reset_focus_queue() { - _focus_list.clear(); -} - -std::tuple AccessibilityWatcher::get_current_caret_bbox() { - return std::tie(_caretX, _caretY, _caretWidth, _caretHeight); -} - -std::tuple AccessibilityWatcher::get_current_active_widget_bbox() { - return std::tie(_componentX, _componentY, _componentWidth, _componentHeight); -} - - -//int main() { -// auto watcher = AccessibilityWatcher::get_instance(); -// watcher->init(); -// while (true) { -// watcher->check_and_process_queue(); -// } -// watcher->quit(); -//} diff --git a/plugins/mousepoll/src/mousepoll.cpp b/plugins/mousepoll/src/mousepoll.cpp index 28b94ed05..425935bb3 100644 --- a/plugins/mousepoll/src/mousepoll.cpp +++ b/plugins/mousepoll/src/mousepoll.cpp @@ -52,11 +52,9 @@ MousepollScreen::getMousePosition () bool MousepollScreen::updatePosition () { - a11ywatcher->check_and_process_queue(); - _has_mouse_moved = getMousePosition(); - if (_has_mouse_moved || !a11ywatcher->get_focus_queue().empty()) { + if (_has_mouse_moved) { for (std::list::iterator it = pollers.begin (); it != pollers.end ();) { MousePoller *poller = *it; @@ -230,8 +228,6 @@ template class PluginClassHandler (screen) { - a11ywatcher = AccessibilityWatcher::get_instance(); - a11ywatcher->init(); updateTimer (); timer.setCallback (boost::bind (&MousepollScreen::updatePosition, this)); @@ -239,7 +235,6 @@ MousepollScreen::MousepollScreen (CompScreen *screen) : } MousepollScreen::~MousepollScreen() { - a11ywatcher->quit(); } bool diff --git a/plugins/mousepoll/src/private.h b/plugins/mousepoll/src/private.h index 46617a92d..29302a12f 100644 --- a/plugins/mousepoll/src/private.h +++ b/plugins/mousepoll/src/private.h @@ -25,8 +25,6 @@ #include #include -#include - #include "mousepoll_options.h" typedef enum _MousepollOptions @@ -68,9 +66,6 @@ class MousepollScreen : removeTimer (MousePoller *poller); void updateTimer (); - - private: - AccessibilityWatcher* a11ywatcher; }; #define MOUSEPOLL_SCREEN(s) \ -- GitLab