File indexing completed on 2024-02-25 17:23:42

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "input_event_spy.h"
0012 #include <QObject>
0013 #include <QVector>
0014 #include <memory>
0015 
0016 #include <KConfigGroup>
0017 #include <KSharedConfig>
0018 typedef uint32_t xkb_layout_index_t;
0019 
0020 class QAction;
0021 class QDBusArgument;
0022 
0023 namespace KWin
0024 {
0025 class Xkb;
0026 class KeyboardLayoutDBusInterface;
0027 
0028 namespace KeyboardLayoutSwitching
0029 {
0030 class Policy;
0031 }
0032 
0033 class KeyboardLayout : public QObject, public InputEventSpy
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit KeyboardLayout(Xkb *xkb, const KSharedConfigPtr &config);
0038 
0039     ~KeyboardLayout() override;
0040 
0041     void init();
0042 
0043     void checkLayoutChange(uint previousLayout);
0044     void switchToNextLayout();
0045     void switchToPreviousLayout();
0046     void resetLayout();
0047 
0048 Q_SIGNALS:
0049     void layoutChanged(uint index);
0050     void layoutsReconfigured();
0051 
0052 private Q_SLOTS:
0053     void reconfigure();
0054 
0055 private:
0056     void initDBusInterface();
0057     void notifyLayoutChange();
0058     void switchToLayout(xkb_layout_index_t index);
0059     void loadShortcuts();
0060     Xkb *m_xkb;
0061     xkb_layout_index_t m_layout = 0;
0062     KConfigGroup m_configGroup;
0063     QVector<QAction *> m_layoutShortcuts;
0064     KeyboardLayoutDBusInterface *m_dbusInterface = nullptr;
0065     std::unique_ptr<KeyboardLayoutSwitching::Policy> m_policy;
0066 };
0067 
0068 class KeyboardLayoutDBusInterface : public QObject
0069 {
0070     Q_OBJECT
0071     Q_CLASSINFO("D-Bus Interface", "org.kde.KeyboardLayouts")
0072 
0073 public:
0074     explicit KeyboardLayoutDBusInterface(Xkb *xkb, const KConfigGroup &configGroup, KeyboardLayout *parent);
0075     ~KeyboardLayoutDBusInterface() override;
0076 
0077     struct LayoutNames
0078     {
0079         QString shortName;
0080         QString displayName;
0081         QString longName;
0082     };
0083 
0084 public Q_SLOTS:
0085     void switchToNextLayout();
0086     void switchToPreviousLayout();
0087     bool setLayout(uint index);
0088     uint getLayout() const;
0089     QVector<LayoutNames> getLayoutsList() const;
0090 
0091 Q_SIGNALS:
0092     void layoutChanged(uint index);
0093     void layoutListChanged();
0094 
0095 private:
0096     Xkb *m_xkb;
0097     const KConfigGroup &m_configGroup;
0098     KeyboardLayout *m_keyboardLayout;
0099 };
0100 
0101 QDBusArgument &operator<<(QDBusArgument &argument, const KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
0102 const QDBusArgument &operator>>(const QDBusArgument &argument, KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
0103 
0104 }
0105 Q_DECLARE_METATYPE(KWin::KeyboardLayoutDBusInterface::LayoutNames)