File indexing completed on 2024-05-05 17:41:53

0001 /*
0002     SPDX-FileCopyrightText: 2000 Matthias Hölzer-Klüpfel <hoelzer@kde.org>
0003     SPDX-FileCopyrightText: 2014 Frederik Gladhorn <gladhorn@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include "kcmaccessibilitybell.h"
0011 #include "kcmaccessibilitykeyboard.h"
0012 #include "kcmaccessibilitykeyboardfilters.h"
0013 #include "kcmaccessibilitymouse.h"
0014 #include "kcmaccessibilityscreenreader.h"
0015 
0016 #include <QAbstractNativeEventFilter>
0017 #include <QColor>
0018 #include <QLabel>
0019 #include <QPaintEvent>
0020 #include <QWidget>
0021 
0022 #include <phonon/MediaObject>
0023 
0024 #include <X11/Xlib.h>
0025 #define explicit int_explicit // avoid compiler name clash in XKBlib.h
0026 #include <X11/XKBlib.h>
0027 #include <xcb/xkb.h>
0028 #undef explicit
0029 #include <fixx11h.h>
0030 
0031 class KComboBox;
0032 
0033 class KAccessApp : public QObject, public QAbstractNativeEventFilter
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit KAccessApp();
0038     void newInstance();
0039     void setXkbOpcode(int opcode);
0040 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0041     bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
0042 #else
0043     bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
0044 #endif
0045 
0046     bool isFailed() const
0047     {
0048         return m_error;
0049     }
0050 
0051 protected:
0052     void readSettings();
0053 
0054     void xkbStateNotify();
0055     void xkbBellNotify(xcb_xkb_bell_notify_event_t *event);
0056     void xkbControlsNotify(xcb_xkb_controls_notify_event_t *event);
0057 
0058 private Q_SLOTS:
0059 
0060     void activeWindowChanged(WId wid);
0061     void notifyChanges();
0062     void applyChanges();
0063     void yesClicked();
0064     void noClicked();
0065     void dialogClosed();
0066     void toggleScreenReader();
0067 
0068 private:
0069     void createDialogContents();
0070     void initMasks();
0071     void setScreenReaderEnabled(bool enabled);
0072 
0073     BellSettings m_bellSettings;
0074     KeyboardSettings m_keyboardSettings;
0075     KeyboardFiltersSettings m_keyboardFiltersSettings;
0076     MouseSettings m_mouseSettings;
0077     ScreenReaderSettings m_screenReaderSettings;
0078 
0079     int xkb_opcode;
0080     unsigned int features;
0081     unsigned int requestedFeatures;
0082 
0083     QWidget *overlay;
0084 
0085     Phonon::MediaObject *_player;
0086     QString _currentPlayerSource;
0087 
0088     WId _activeWindow;
0089 
0090     QDialog *dialog;
0091     QLabel *featuresLabel;
0092     KComboBox *showModeCombobox;
0093 
0094     int keys[8];
0095     int state;
0096 
0097     QAction *toggleScreenReaderAction;
0098     bool m_error;
0099 };
0100 
0101 class VisualBell : public QWidget
0102 {
0103     Q_OBJECT
0104 
0105 public:
0106     VisualBell(int pause)
0107         : QWidget((QWidget *)nullptr, Qt::X11BypassWindowManagerHint)
0108         , _pause(pause)
0109     {
0110     }
0111 
0112 protected:
0113     void paintEvent(QPaintEvent *) override;
0114 
0115 private:
0116     int _pause;
0117 };