2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-01-14 17:06:41 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
|
2017-01-14 17:06:41 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-01-14 17:06:41 +00:00
|
|
|
#ifndef KWIN_KEYBOARD_LAYOUT_H
|
|
|
|
#define KWIN_KEYBOARD_LAYOUT_H
|
|
|
|
|
|
|
|
#include "input_event_spy.h"
|
|
|
|
#include <QObject>
|
2017-01-23 19:06:53 +00:00
|
|
|
#include <QVector>
|
2017-01-20 06:15:27 +00:00
|
|
|
|
2021-01-06 16:25:03 +00:00
|
|
|
#include <KConfigGroup>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KSharedConfig>
|
2017-01-14 17:06:41 +00:00
|
|
|
typedef uint32_t xkb_layout_index_t;
|
|
|
|
|
2017-01-23 19:06:53 +00:00
|
|
|
class QAction;
|
2021-01-06 16:25:03 +00:00
|
|
|
class QDBusArgument;
|
2017-01-20 06:15:27 +00:00
|
|
|
|
2017-01-14 17:06:41 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
class Xkb;
|
2017-02-11 10:34:49 +00:00
|
|
|
class KeyboardLayoutDBusInterface;
|
2017-01-14 17:06:41 +00:00
|
|
|
|
2017-04-04 16:56:10 +00:00
|
|
|
namespace KeyboardLayoutSwitching
|
|
|
|
{
|
|
|
|
class Policy;
|
|
|
|
}
|
|
|
|
|
2017-01-14 17:06:41 +00:00
|
|
|
class KeyboardLayout : public QObject, public InputEventSpy
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-01-06 16:25:03 +00:00
|
|
|
explicit KeyboardLayout(Xkb *xkb, const KSharedConfigPtr &config);
|
2017-01-14 17:06:41 +00:00
|
|
|
|
2021-01-06 16:25:03 +00:00
|
|
|
~KeyboardLayout() override;
|
2017-01-20 06:15:27 +00:00
|
|
|
|
2017-01-14 17:06:41 +00:00
|
|
|
void init();
|
|
|
|
|
2021-01-09 13:22:29 +00:00
|
|
|
void checkLayoutChange(uint previousLayout);
|
2020-11-23 13:56:18 +00:00
|
|
|
void switchToNextLayout();
|
|
|
|
void switchToPreviousLayout();
|
2017-01-14 17:06:41 +00:00
|
|
|
void resetLayout();
|
|
|
|
|
2017-01-28 14:25:40 +00:00
|
|
|
Q_SIGNALS:
|
2021-01-09 13:22:29 +00:00
|
|
|
void layoutChanged(uint index);
|
2017-01-28 14:25:40 +00:00
|
|
|
void layoutsReconfigured();
|
|
|
|
|
2017-01-14 17:06:41 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void reconfigure();
|
|
|
|
|
|
|
|
private:
|
2017-01-28 14:25:40 +00:00
|
|
|
void initDBusInterface();
|
2017-01-14 17:06:41 +00:00
|
|
|
void notifyLayoutChange();
|
2017-01-23 19:06:53 +00:00
|
|
|
void switchToLayout(xkb_layout_index_t index);
|
|
|
|
void loadShortcuts();
|
2017-01-14 17:06:41 +00:00
|
|
|
Xkb *m_xkb;
|
|
|
|
xkb_layout_index_t m_layout = 0;
|
2021-01-06 16:25:03 +00:00
|
|
|
KConfigGroup m_configGroup;
|
2022-03-23 10:13:38 +00:00
|
|
|
QVector<QAction *> m_layoutShortcuts;
|
2017-02-11 10:34:49 +00:00
|
|
|
KeyboardLayoutDBusInterface *m_dbusInterface = nullptr;
|
2017-04-04 16:56:10 +00:00
|
|
|
KeyboardLayoutSwitching::Policy *m_policy = nullptr;
|
2017-01-14 17:06:41 +00:00
|
|
|
};
|
|
|
|
|
2017-01-28 14:25:40 +00:00
|
|
|
class KeyboardLayoutDBusInterface : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.KeyboardLayouts")
|
|
|
|
|
|
|
|
public:
|
2021-01-06 16:25:03 +00:00
|
|
|
explicit KeyboardLayoutDBusInterface(Xkb *xkb, const KConfigGroup &configGroup, KeyboardLayout *parent);
|
2017-01-28 14:25:40 +00:00
|
|
|
~KeyboardLayoutDBusInterface() override;
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
struct LayoutNames
|
|
|
|
{
|
|
|
|
QString shortName;
|
|
|
|
QString displayName;
|
|
|
|
QString longName;
|
|
|
|
};
|
2021-01-06 16:25:03 +00:00
|
|
|
|
2017-01-28 14:25:40 +00:00
|
|
|
public Q_SLOTS:
|
2020-11-23 13:56:18 +00:00
|
|
|
void switchToNextLayout();
|
|
|
|
void switchToPreviousLayout();
|
2021-01-08 20:06:59 +00:00
|
|
|
bool setLayout(uint index);
|
|
|
|
uint getLayout() const;
|
2021-01-06 16:25:03 +00:00
|
|
|
QVector<LayoutNames> getLayoutsList() const;
|
2017-01-28 14:25:40 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2021-01-08 20:06:59 +00:00
|
|
|
void layoutChanged(uint index);
|
2017-01-28 14:25:40 +00:00
|
|
|
void layoutListChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Xkb *m_xkb;
|
2021-01-06 16:25:03 +00:00
|
|
|
const KConfigGroup &m_configGroup;
|
2017-02-01 05:49:32 +00:00
|
|
|
KeyboardLayout *m_keyboardLayout;
|
2017-01-28 14:25:40 +00:00
|
|
|
};
|
|
|
|
|
2021-01-06 16:25:03 +00:00
|
|
|
QDBusArgument &operator<<(QDBusArgument &argument, const KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
|
|
|
|
const QDBusArgument &operator>>(const QDBusArgument &argument, KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
|
|
|
|
|
2017-01-14 17:06:41 +00:00
|
|
|
}
|
2021-01-06 16:25:03 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::KeyboardLayoutDBusInterface::LayoutNames)
|
2017-01-14 17:06:41 +00:00
|
|
|
|
|
|
|
#endif
|