From c7e156165d1cf8ba470c022df661d77715ccb9fc Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 16 Aug 2022 17:31:41 +0200 Subject: [PATCH] inputmethod_v1_interface: Use RamFile for passing keymap to clients This uses a sealed anonymous file (memfd) instead of a `QTemporaryFile`, which is more efficient. Ideally, this file was also reused if the keymap didn't change. Signed-off-by: Victoria Fischer --- src/wayland/inputmethod_v1_interface.cpp | 25 +++--------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/wayland/inputmethod_v1_interface.cpp b/src/wayland/inputmethod_v1_interface.cpp index 3c28dcb439..2877cc3416 100644 --- a/src/wayland/inputmethod_v1_interface.cpp +++ b/src/wayland/inputmethod_v1_interface.cpp @@ -13,9 +13,9 @@ #include "surface_interface.h" #include "surfacerole_p.h" #include "utils/common.h" +#include "utils/ramfile.h" #include -#include #include @@ -47,30 +47,11 @@ InputMethodGrabV1::~InputMethodGrabV1() void InputMethodGrabV1::sendKeymap(const QByteArray &keymap) { - std::unique_ptr tmp(new QTemporaryFile()); - if (!tmp->open()) { - qCWarning(KWIN_CORE) << "Failed to create keymap file:" << tmp->errorString(); - return; - } - - unlink(tmp->fileName().toUtf8().constData()); - if (!tmp->resize(keymap.size())) { - qCWarning(KWIN_CORE) << "Failed to resize keymap file:" << tmp->errorString(); - return; - } - - uchar *address = tmp->map(0, keymap.size()); - if (!address) { - qCWarning(KWIN_CORE) << "Failed to map keymap file:" << tmp->errorString(); - return; - } - - qstrncpy(reinterpret_cast(address), keymap.constData(), keymap.size() + 1); - tmp->unmap(address); + KWin::RamFile keymapFile("kwin-xkb-input-method-grab-keymap", keymap.constData(), keymap.size() + 1); // include QByteArray null terminator const auto resources = d->resourceMap(); for (auto r : resources) { - d->send_keymap(r->handle, QtWaylandServer::wl_keyboard::keymap_format::keymap_format_xkb_v1, tmp->handle(), tmp->size()); + d->send_keymap(r->handle, QtWaylandServer::wl_keyboard::keymap_format::keymap_format_xkb_v1, keymapFile.fd(), keymapFile.size()); } }