std::unique_ptr<Atspi::WatchHandler> watchHandle;
ecore::Timer rebuildContextTimer;
std::shared_ptr<AtspiAccessible> rootObject, keyboardRootObject;
+ unsigned int contextRebuildId = 0;
std::unique_ptr<AtspiEventListener, utils::GObjectUnref> eventListener;
rebuildContextTimer.reset();
}
- void rebuildContextFromZero(bool force)
+ void rebuildContextFromZero(unsigned int rebuildId, bool force)
{
auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
if (!atspi) {
struct Contextes {
NavigationImpl *self;
Optional<NavigationRows> real, keyboard;
+ unsigned int rebuildId;
~Contextes()
{
ASSERT(real || keyboard);
if (!real)
real = std::move(keyboard);
- self->buildNavigationElementsTreeAndEmitContextChanged(std::move(*real), std::move(keyboard));
+ self->buildNavigationElementsTreeAndEmitContextChanged(rebuildId, std::move(*real), std::move(keyboard));
}
};
auto contextes = std::make_shared<Contextes>();
+ contextes->rebuildId = rebuildId;
contextes->self = this;
buildNavigationRows(root, application, [ = ](Optional<NavigationRows> rows) {
contextes->real = std::move(rows);
auto nav = std::dynamic_pointer_cast<NavigationImpl>(Singleton<UniversalSwitch>::instance().getNavigationInterface());
if (nav) {
DEBUG("restarting context navigation, as selected window was lost");
- nav->initializeRebuildingContext(force, 0.2f);
+ nav->initializeRebuildingContext(force);
} else {
DEBUG("no navigation");
}
out << "* " << pos.toString() << " " << Atspi::getUniqueId(obj) << " app " << (int)getApplicationCategory() << "\n";
}
};
- void buildNavigationElementsTree(NavigationRows realContext, Optional<NavigationRows> keyboardContext)
+ void buildNavigationElementsTree(unsigned int rebuildId, NavigationRows realContext, Optional<NavigationRows> keyboardContext)
{
+ if (contextRebuildId != rebuildId) return;
using ParentType = const std::shared_ptr<NavigationElement> &;
std::function<std::shared_ptr<NavigationElement>(ParentType parent, size_t indexInParent, NavigationRows &ctx)> buildRows;
std::function<std::shared_ptr<NavigationElement>(ParentType parent, size_t indexInParent, NavigationRows &ctx, size_t)> buildSingleRow;
}
}
- void buildNavigationElementsTreeAndEmitContextChanged(NavigationRows realContext, Optional<NavigationRows> keyboardContext)
+ void buildNavigationElementsTreeAndEmitContextChanged(unsigned int rebuildId, NavigationRows realContext, Optional<NavigationRows> keyboardContext)
{
- buildNavigationElementsTree(realContext, keyboardContext);
+ if (rebuildId != contextRebuildId) return;
+ buildNavigationElementsTree(rebuildId, realContext, keyboardContext);
auto root = realContext.getRootVisibleObject();
auto pos = (*realContext.getRowSize(0)).getCenterPoint();
void initializeRebuildingContext(bool force, float delay = 0.2f)
{
DEBUG("requesting context rebuild");
+ auto id = ++contextRebuildId;
rebuildContextTimer.reset(delay,
[ = ]() {
auto nav = std::dynamic_pointer_cast<NavigationImpl>(Singleton<UniversalSwitch>::instance().getNavigationInterface());
if (nav) {
- nav->rebuildContextFromZero(force);
+ nav->rebuildContextFromZero(id, force);
}
return ecore::TimerRepetitionPolicy::cancel;
});