File indexing completed on 2024-04-28 05:33:06

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 <X11/Xlib.h>
0023 #define explicit int_explicit // avoid compiler name clash in XKBlib.h
0024 #include <X11/XKBlib.h>
0025 #include <xcb/xkb.h>
0026 #undef explicit
0027 #include <fixx11h.h>
0028 
0029 class KComboBox;
0030 struct ca_context;
0031 struct ca_proplist;
0032 
0033 class KAccessApp : public QObject, public QAbstractNativeEventFilter
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit KAccessApp();
0038     ~KAccessApp();
0039 
0040     void newInstance();
0041     void setXkbOpcode(int opcode);
0042     bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
0043 
0044     bool isFailed() const
0045     {
0046         return m_error;
0047     }
0048 
0049 protected:
0050     void readSettings();
0051 
0052     void xkbStateNotify();
0053     void xkbBellNotify(xcb_xkb_bell_notify_event_t *event);
0054     void xkbControlsNotify(xcb_xkb_controls_notify_event_t *event);
0055 
0056 private Q_SLOTS:
0057 
0058     void activeWindowChanged(WId wid);
0059     void notifyChanges();
0060     void applyChanges();
0061     void yesClicked();
0062     void noClicked();
0063     void dialogClosed();
0064     void toggleScreenReader();
0065 
0066 private:
0067     void createDialogContents();
0068     void initMasks();
0069     void setScreenReaderEnabled(bool enabled);
0070 
0071     BellSettings m_bellSettings;
0072     KeyboardSettings m_keyboardSettings;
0073     KeyboardFiltersSettings m_keyboardFiltersSettings;
0074     MouseSettings m_mouseSettings;
0075     ScreenReaderSettings m_screenReaderSettings;
0076 
0077     int xkb_opcode;
0078     unsigned int features;
0079     unsigned int requestedFeatures;
0080 
0081     QWidget *overlay;
0082 
0083     ca_context *m_caContext = nullptr;
0084     QUrl m_currentPlayerSource;
0085 
0086     WId _activeWindow;
0087 
0088     QDialog *dialog;
0089     QLabel *featuresLabel;
0090     KComboBox *showModeCombobox;
0091 
0092     int keys[8];
0093     int state;
0094 
0095     QAction *toggleScreenReaderAction;
0096     bool m_error;
0097 };
0098 
0099 class VisualBell : public QWidget
0100 {
0101     Q_OBJECT
0102 
0103 public:
0104     VisualBell(int pause)
0105         : QWidget((QWidget *)nullptr, Qt::X11BypassWindowManagerHint)
0106         , _pause(pause)
0107     {
0108     }
0109 
0110 protected:
0111     void paintEvent(QPaintEvent *) override;
0112 
0113 private:
0114     int _pause;
0115 };