kdeui: new KKeyboardLayout class

KKeyboardLayout along with Solid::Input are to be used not only in a
reimplementation of the keyboard plasma applet but also potentially
for a software input panel (QEvent::RequestSoftwareInputPanel and
QEvent::CloseSoftwareInputPanel handler)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-09-04 15:39:22 +03:00
parent aeba52714a
commit ce1dcbb552
7 changed files with 1521 additions and 1 deletions

View file

@ -158,6 +158,7 @@ install(
KJobTrackerInterface
KJobUiDelegate
KKeySequenceWidget
KKeyboardLayout
KLed
KLineEdit
KLinkItemSelectionModel

1
includes/KKeyboardLayout Normal file
View file

@ -0,0 +1 @@
#include "../kkeyboardlayout.h"

View file

@ -197,6 +197,7 @@ set(kdeui_LIB_SRCS
util/kpixmapsequencewidget.cpp
util/kimageio.cpp
util/kkeyserver_x11.cpp
util/kkeyboardlayout.cpp
widgets/kactionselector.cpp
widgets/kdialogbuttonbox.cpp
widgets/kbuttongroup.cpp
@ -272,6 +273,11 @@ if (X11_Xkb_FOUND AND X11_Xkbfile_FOUND)
${X11_Xkb_INCLUDE_PATH}
${X11_Xlib_INCLUDE_PATH}
)
set(KDEUI_EXTRA_LIBS
${KDEUI_EXTRA_LIBS}
${X11_LIBRARIES}
${X11_Xkbfile_LIB}
)
endif()
qt4_add_dbus_interfaces(kdeui_LIB_SRCS jobs/org.kde.JobViewServer.xml )
@ -482,6 +488,7 @@ install(
util/kcursor.h
util/kguiitem.h
util/kkeyserver.h
util/kkeyboardlayout.h
util/kselectionowner.h
util/knumvalidator.h
util/kpassivepopup.h

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,79 @@
/* This file is part of the KDE libraries
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KKEYBOARDLAYOUT_H
#define KKEYBOARDLAYOUT_H
#include <kdeui_export.h>
#include <QObject>
#include <QList>
#include <qwindowdefs.h>
class KKeyboardLayoutPrivate;
struct KKeyboardType
{
QByteArray rule;
QByteArray model;
QByteArray layout;
QByteArray variant;
QByteArray option;
bool operator==(const KKeyboardType &other) const;
};
/*!
Class to query and change the keyboard layout.
@since 4.24
@warning the API is subject to change
*/
class KDEUI_EXPORT KKeyboardLayout : public QObject
{
Q_OBJECT
public:
KKeyboardLayout(QObject *parent = nullptr);
~KKeyboardLayout();
QList<KKeyboardType> layouts() const;
bool setLayouts(const QList<KKeyboardType> &layouts);
static KKeyboardType defaultLayout();
static QList<QByteArray> modelNames();
static QList<QByteArray> layoutNames();
static QList<QByteArray> variantNames(const QByteArray &layout);
static QList<QByteArray> optionNames();
static QString modelDescription(const QByteArray &model);
static QString layoutDescription(const QByteArray &layout);
static QString variantDescription(const QByteArray &layout, const QByteArray &variant);
static QString optionDescription(const QByteArray &option);
Q_SIGNALS:
void layoutChanged();
private:
friend KKeyboardLayoutPrivate;
Q_DISABLE_COPY(KKeyboardLayout);
KKeyboardLayoutPrivate * const d;
Q_PRIVATE_SLOT(d, void _k_checkLayouts())
};
#endif // KKEYBOARDLAYOUT_H

93
kdeui/util/scoop-rules.py Executable file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env python
import os, sys, glob
def cstringify(s):
r = s.replace('"', '\\"')
r = r.replace('\\', '\\\\')
return r
if len(sys.argv) < 2:
print('usage: scoop-rules <model|layout|variant|option>')
exit(1)
printmodel = False
printlayout = False
printvariant = False
printoption = False
if sys.argv[1] == 'model':
printmodel = True
elif sys.argv[1] == 'layout':
printlayout = True
elif sys.argv[1] == 'variant':
printvariant = True
elif sys.argv[1] == 'option':
printoption = True
else:
print('usage: scoop-rules <model|layout|variant|option>')
exit(1)
lstfiles = glob.glob('/usr/share/X11/xkb/rules/*.lst')
if len(lstfiles) < 1:
print('Could not find lst files')
exit(2)
for lstfile in lstfiles:
with open(lstfile, 'r') as lsthandle:
printline = False
for lstline in lsthandle.readlines():
if printmodel:
strippedline = lstline.strip()
if strippedline.startswith('! model'):
printline = True
continue
elif len(strippedline) == 0:
printline = False
if not printline:
continue
splitline = strippedline.split(' ')
splitpart0 = splitline[0].strip()
splitpart1 = ' '.join(splitline[1:]).strip()
print(' { "%s", I18N_NOOP("%s") },' % (splitpart0, cstringify(splitpart1)))
elif printlayout:
strippedline = lstline.strip()
if strippedline.startswith('! layout'):
printline = True
continue
elif len(strippedline) == 0:
printline = False
if not printline:
continue
splitline = strippedline.split(' ')
splitpart0 = splitline[0].strip()
splitpart1 = ' '.join(splitline[1:]).strip()
print(' { "%s", I18N_NOOP("%s") },' % (splitpart0, cstringify(splitpart1)))
elif printvariant:
strippedline = lstline.strip()
if strippedline.startswith('! variant'):
printline = True
continue
elif len(strippedline) == 0:
printline = False
if not printline:
continue
splitline = strippedline.split(' ')
splitpart0 = splitline[0].strip()
splitpart1 = ' '.join(splitline[1:]).strip()
splitlayout = splitpart1.split(':')[0].strip()
splitdescription = ' '.join(splitpart1.split(':')[1:]).strip()
print(' { "%s", "%s", I18N_NOOP("%s") },' % (splitlayout, cstringify(splitpart0), cstringify(splitdescription)))
elif printoption:
strippedline = lstline.strip()
if strippedline.startswith('! option'):
printline = True
continue
elif len(strippedline) == 0:
printline = False
if not printline:
continue
splitline = strippedline.split(' ')
splitpart0 = splitline[0].strip()
splitpart1 = ' '.join(splitline[1:]).strip()
print(' { "%s", I18N_NOOP("%s") },' % (splitpart0, cstringify(splitpart1)))

View file

@ -1,5 +1,5 @@
/*
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
Copyright 2023 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public