Spike: KWin input-method backend with floating layer-shell window
Registers as KWin's virtual keyboard (input-method-unstable-v1), shows a non-focusable layer-shell overlay, and commits Unicode text. Verified in a nested headless KWin with the textprobe tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#include "KWinInputMethod.h"
|
||||
#include "KWinInputContext.h"
|
||||
|
||||
KWinInputMethodGlobal::KWinInputMethodGlobal()
|
||||
: QWaylandClientExtensionTemplate(1)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
void KWinInputMethodGlobal::zwp_input_method_v1_activate(::zwp_input_method_context_v1 *context)
|
||||
{
|
||||
Q_EMIT activated(context);
|
||||
}
|
||||
|
||||
void KWinInputMethodGlobal::zwp_input_method_v1_deactivate(::zwp_input_method_context_v1 *)
|
||||
{
|
||||
Q_EMIT deactivated();
|
||||
}
|
||||
|
||||
KWinInputMethod::KWinInputMethod(QObject *parent)
|
||||
: TextBackend(parent)
|
||||
{
|
||||
connect(&m_global, &KWinInputMethodGlobal::activated, this, &KWinInputMethod::activate);
|
||||
connect(&m_global, &KWinInputMethodGlobal::deactivated, this, &KWinInputMethod::deactivate);
|
||||
connect(&m_global, &QWaylandClientExtension::activeChanged, this, &KWinInputMethod::availableChanged);
|
||||
}
|
||||
|
||||
KWinInputMethod::~KWinInputMethod() = default;
|
||||
|
||||
bool KWinInputMethod::isAvailable() const
|
||||
{
|
||||
return m_global.isActive();
|
||||
}
|
||||
|
||||
bool KWinInputMethod::isActive() const
|
||||
{
|
||||
return m_context != nullptr;
|
||||
}
|
||||
|
||||
QString KWinInputMethod::surroundingText() const
|
||||
{
|
||||
return m_context ? m_context->surroundingText() : QString();
|
||||
}
|
||||
|
||||
int KWinInputMethod::cursorPosition() const
|
||||
{
|
||||
return m_context ? m_context->cursorPosition() : -1;
|
||||
}
|
||||
|
||||
void KWinInputMethod::commitText(const QString &text)
|
||||
{
|
||||
if (m_context)
|
||||
m_context->commit(text);
|
||||
}
|
||||
|
||||
void KWinInputMethod::setPreedit(const QString &text)
|
||||
{
|
||||
if (m_context)
|
||||
m_context->preedit(text);
|
||||
}
|
||||
|
||||
void KWinInputMethod::sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
if (m_context)
|
||||
m_context->sendKeysym(keysym, modifiers);
|
||||
}
|
||||
|
||||
void KWinInputMethod::activate(::zwp_input_method_context_v1 *context)
|
||||
{
|
||||
m_context = std::make_unique<KWinInputContext>(context);
|
||||
connect(m_context.get(), &KWinInputContext::surroundingChanged, this, &TextBackend::surroundingChanged);
|
||||
Q_EMIT activeChanged();
|
||||
}
|
||||
|
||||
void KWinInputMethod::deactivate()
|
||||
{
|
||||
m_context.reset();
|
||||
Q_EMIT activeChanged();
|
||||
Q_EMIT surroundingChanged();
|
||||
}
|
||||
Reference in New Issue
Block a user