Commit 1c9e21b2 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Fix management of keymap files

This is a regression that was introduced with the port to the new
approach.

(cherry picked from commit db2a8acd)
parent 5ba30dca
Pipeline #55557 passed with stage
in 7 minutes and 17 seconds
......@@ -30,7 +30,7 @@ void KeyboardInterfacePrivate::keyboard_bind_resource(Resource *resource)
send_repeat_info(resource->handle, keyRepeat.charactersPerSecond, keyRepeat.delay);
}
if (!keymap.isNull()) {
send_keymap(resource->handle, keymap_format::keymap_format_xkb_v1, keymap->handle(), keymap->size());
sendKeymap(resource);
}
}
......@@ -79,37 +79,45 @@ void KeyboardInterfacePrivate::sendEnter(SurfaceInterface *surface, quint32 seri
sendModifiers();
}
void KeyboardInterface::setKeymap(const QByteArray &content)
void KeyboardInterfacePrivate::sendKeymap(Resource *resource)
{
if (content.isNull()) {
return;
}
QScopedPointer<QTemporaryFile> tmp{new QTemporaryFile(this)};
QScopedPointer<QTemporaryFile> tmp(new QTemporaryFile());
if (!tmp->open()) {
qCWarning(KWAYLAND_SERVER) << "Failed to create keymap file:" << tmp->errorString();
return;
}
unlink(tmp->fileName().toUtf8().constData());
if (!tmp->resize(content.size())) {
if (!tmp->resize(keymap.size())) {
qCWarning(KWAYLAND_SERVER) << "Failed to resize keymap file:" << tmp->errorString();
return;
}
uchar *address = tmp->map(0, content.size());
uchar *address = tmp->map(0, keymap.size());
if (!address) {
qCWarning(KWAYLAND_SERVER) << "Failed to map keymap file:" << tmp->errorString();
return;
}
if (qstrncpy(reinterpret_cast<char*>(address), content.constData(), content.size() + 1) == nullptr) {
if (qstrncpy(reinterpret_cast<char *>(address), keymap.constData(), keymap.size() + 1) == nullptr) {
return;
}
tmp->unmap(address);
d->sendKeymap(tmp->handle(), content.size());
d->keymap.swap(tmp);
send_keymap(resource->handle, keymap_format::keymap_format_xkb_v1, tmp->handle(), tmp->size());
}
void KeyboardInterfacePrivate::sendKeymap(int fd, quint32 size)
void KeyboardInterface::setKeymap(const QByteArray &content)
{
const QList<Resource *> keyboards = resourceMap().values();
for (Resource *keyboardResource : keyboards) {
send_keymap(keyboardResource->handle, keymap_format::keymap_format_xkb_v1, fd, size);
if (content.isNull()) {
return;
}
d->keymap = content;
const auto keyboardResources = d->resourceMap();
for (KeyboardInterfacePrivate::Resource *resource : keyboardResources) {
d->sendKeymap(resource);
}
}
......
......@@ -12,8 +12,6 @@
#include <QPointer>
#include <QHash>
class QTemporaryFile;
namespace KWaylandServer
{
......@@ -25,7 +23,7 @@ public:
KeyboardInterfacePrivate(SeatInterface *s);
void sendKeymap(int fd, quint32 size);
void sendKeymap(Resource *resource);
void sendModifiers();
void sendModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group, quint32 serial);
......@@ -40,7 +38,7 @@ public:
SurfaceInterface *focusedSurface = nullptr;
QPointer<SurfaceInterface> focusedChildSurface;
QMetaObject::Connection destroyConnection;
QScopedPointer<QTemporaryFile> keymap;
QByteArray keymap;
struct {
qint32 charactersPerSecond = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment