File indexing completed on 2024-11-10 04:57:13
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "accessibilityintegration.h" 0011 0012 using namespace QAccessibleClient; // Whatever, sue me... 0013 0014 namespace KWin 0015 { 0016 0017 ZoomAccessibilityIntegration::ZoomAccessibilityIntegration(QObject *parent) 0018 : QObject(parent) 0019 { 0020 } 0021 0022 void ZoomAccessibilityIntegration::setFocusTrackingEnabled(bool enabled) 0023 { 0024 if (m_isFocusTrackingEnabled == enabled) { 0025 return; 0026 } 0027 m_isFocusTrackingEnabled = enabled; 0028 updateAccessibilityRegistry(); 0029 } 0030 0031 bool ZoomAccessibilityIntegration::isFocusTrackingEnabled() const 0032 { 0033 return m_isFocusTrackingEnabled; 0034 } 0035 0036 void ZoomAccessibilityIntegration::setTextCaretTrackingEnabled(bool enabled) 0037 { 0038 if (m_isTextCaretTrackingEnabled == enabled) { 0039 return; 0040 } 0041 m_isTextCaretTrackingEnabled = enabled; 0042 updateAccessibilityRegistry(); 0043 } 0044 0045 bool ZoomAccessibilityIntegration::isTextCaretTrackingEnabled() const 0046 { 0047 return m_isTextCaretTrackingEnabled; 0048 } 0049 0050 void ZoomAccessibilityIntegration::updateAccessibilityRegistry() 0051 { 0052 Registry::EventListeners eventListeners = Registry::NoEventListeners; 0053 0054 if (isTextCaretTrackingEnabled()) { 0055 eventListeners |= Registry::TextCaretMoved; 0056 } 0057 if (isFocusTrackingEnabled()) { 0058 eventListeners |= Registry::Focus; 0059 } 0060 0061 if (eventListeners == Registry::NoEventListeners) { 0062 destroyAccessibilityRegistry(); 0063 return; 0064 } 0065 if (!m_accessibilityRegistry) { 0066 createAccessibilityRegistry(); 0067 } 0068 0069 m_accessibilityRegistry->subscribeEventListeners(eventListeners); 0070 } 0071 0072 void ZoomAccessibilityIntegration::createAccessibilityRegistry() 0073 { 0074 m_accessibilityRegistry = new Registry(this); 0075 0076 connect(m_accessibilityRegistry, &Registry::textCaretMoved, 0077 this, &ZoomAccessibilityIntegration::slotFocusChanged); 0078 connect(m_accessibilityRegistry, &Registry::focusChanged, 0079 this, &ZoomAccessibilityIntegration::slotFocusChanged); 0080 } 0081 0082 void ZoomAccessibilityIntegration::destroyAccessibilityRegistry() 0083 { 0084 if (!m_accessibilityRegistry) { 0085 return; 0086 } 0087 0088 disconnect(m_accessibilityRegistry, nullptr, this, nullptr); 0089 0090 m_accessibilityRegistry->deleteLater(); 0091 m_accessibilityRegistry = nullptr; 0092 } 0093 0094 void ZoomAccessibilityIntegration::slotFocusChanged(const AccessibleObject &object) 0095 { 0096 Q_EMIT focusPointChanged(object.focusPoint()); 0097 } 0098 0099 } // namespace KWin 0100 0101 #include "moc_accessibilityintegration.cpp"