6#include <QTextCharFormat>
7#include <QGuiApplication>
12#include <QStandardPaths>
13#include <QDBusVariant>
14#include <QDBusPendingReply>
16#include <QDBusServiceWatcher>
23#include <qpa/qplatformcursor.h>
24#include <qpa/qplatformscreen.h>
25#include <qpa/qwindowsysteminterface_p.h>
27#include <private/qguiapplication_p.h>
28#include <private/qxkbcommon_p.h>
36#ifndef IBUS_RELEASE_MASK
37#define IBUS_RELEASE_MASK (1 << 30)
38#define IBUS_SHIFT_MASK (1 << 0)
39#define IBUS_CONTROL_MASK (1 << 2)
40#define IBUS_MOD1_MASK (1 << 3)
41#define IBUS_META_MASK (1 << 28)
78 std::unique_ptr<QIBusProxy>
bus;
80 std::unique_ptr<QIBusInputContextProxy>
context;
101#if QT_CONFIG(filesystemwatcher)
102 qCDebug(qtQpaInputMethods) <<
"socketWatcher.addPath" << socketPath;
106 m_socketWatcher.addPath(socketPath);
117 connectToContextSignals();
121 m_eventFilterUseSynchronousMode =
false;
125 if (
ok && enableSync == 1)
126 m_eventFilterUseSynchronousMode =
true;
142 switch (capability) {
185 event.setCommitString(d->
predit);
220 text.text = surroundingText;
226 d->
context->SetSurroundingText(dbusText, cursorPosition, anchorPosition);
235 QRect r =
qApp->inputMethod()->cursorRectangle().toRect();
242 if (!inputWindow->screen())
246 auto margins = inputWindow->frameMargins();
247 r.translate(margins.left(), margins.top());
248 qreal scale = inputWindow->devicePixelRatio();
251 qDebug() <<
"microFocus" << newRect;
252 d->
context->SetCursorLocationRelative(newRect.x(), newRect.y(),
253 newRect.width(), newRect.height());
258 auto screenGeometry = inputWindow->screen()->geometry();
259 auto point = inputWindow->mapToGlobal(
r.topLeft());
260 qreal scale = inputWindow->devicePixelRatio();
261 auto native = (point - screenGeometry.topLeft()) *
scale + screenGeometry.topLeft();
264 qDebug() <<
"microFocus" << newRect;
265 d->
context->SetCursorLocation(newRect.x(), newRect.y(),
266 newRect.width(), newRect.height());
301 qDebug() <<
"commit text:" <<
t.text;
304 event.setCommitString(
t.text);
325 qDebug() <<
"preedit text:" <<
t.text;
328 if (!
t.text.isEmpty())
359 state &= ~IBUS_RELEASE_MASK;
385 qDebug(
"surroundingTextRequired");
397 qDebug() <<
"deleteSurroundingText" <<
offset << n_chars;
400 event.setCommitString(
"",
offset, n_chars);
410 QList<QInputMethodEvent::Attribute> attributes;
442 QDBusPendingReply<bool>
reply = d->
context->ProcessKeyEvent(sym, code - 8, ibusState);
445 bool filtered =
reply.value();
446 qCDebug(qtQpaInputMethods) <<
"filterEvent return" << code << sym <<
state << filtered;
451 const int qtcode = keyEvent->
key();
474 args << QVariant::fromValue(static_cast<uint>(keyEvent->
type()));
489 QDBusPendingReply<bool>
reply = *call;
491 if (
reply.isError()) {
509 const int qtcode =
args.
at(2).toInt();
514 const bool isAutoRepeat =
args.
at(7).toBool();
517 bool filtered =
reply.value();
518 qCDebug(qtQpaInputMethods) <<
"filterEventFinished return" << code << sym <<
state << filtered;
520#ifndef QT_NO_CONTEXTMENU
523 const QPoint globalPos =
window->screen()->handle()->cursor()->pos();
531 code, sym,
state,
string, isAutoRepeat);
547 qCDebug(qtQpaInputMethods) <<
"socketChanged";
564 qCDebug(qtQpaInputMethods) <<
"busRegistered";
573 qCDebug(qtQpaInputMethods) <<
"busUnregistered";
582 qCDebug(qtQpaInputMethods) <<
"QIBusPlatformInputContext::connectToBus";
584 connectToContextSignals();
586#if QT_CONFIG(filesystemwatcher)
587 if (!d->
usePortal && m_socketWatcher.files().size() == 0)
594 if (!d->
bus || !d->
bus->isValid())
598 Q_ASSERT(engine_name == desc.engine_name);
606void QIBusPlatformInputContext::connectToContextSignals()
608 if (d->
bus && d->
bus->isValid()) {
639 needsSurroundingText(
false)
644 qDebug() <<
"use IBus portal";
652 if (
bus &&
bus->isValid()) {
671 const char* ibusService =
usePortal ?
"org.freedesktop.portal.IBus" :
"org.freedesktop.IBus";
672 QDBusReply<QDBusObjectPath> ic;
675 "/org/freedesktop/IBus"_L1,
678 qWarning(
"QIBusPlatformInputContext: invalid portal bus.");
682 ic =
portalBus->CreateInputContext(
"QIBusInputContext"_L1);
685 "/org/freedesktop/IBus"_L1,
687 if (!
bus->isValid()) {
688 qWarning(
"QIBusPlatformInputContext: invalid bus.");
692 ic =
bus->CreateInputContext(
"QIBusInputContext"_L1);
700 qWarning(
"QIBusPlatformInputContext: CreateInputContext failed.");
707 qWarning(
"QIBusPlatformInputContext: invalid input context.");
712 IBUS_CAP_PREEDIT_TEXT = 1 << 0,
713 IBUS_CAP_AUXILIARY_TEXT = 1 << 1,
714 IBUS_CAP_LOOKUP_TABLE = 1 << 2,
715 IBUS_CAP_FOCUS = 1 << 3,
716 IBUS_CAP_PROPERTY = 1 << 4,
717 IBUS_CAP_SURROUNDING_TEXT = 1 << 5
719 context->SetCapabilities(IBUS_CAP_PREEDIT_TEXT|IBUS_CAP_FOCUS|IBUS_CAP_SURROUNDING_TEXT);
724 qDebug(
">>>> bus connected!");
732 bool isWayland =
false;
760 qDebug() <<
"host=" << host <<
"displayNumber" << displayNumber;
795 if (
address.isEmpty() || pid < 0 || kill(pid, 0) != 0)
803#include "moc_qibusplatforminputcontext.cpp"
QByteArray left(qsizetype n) const &
qsizetype indexOf(char c, qsizetype from=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QByteArray localMachineId()
static QDBusConnection connectToBus(BusType type, const QString &name)
Opens a connection of type type to one of the known buses and associate with it the connection name n...
static void disconnectFromBus(const QString &name)
Closes the bus connection of name name.
void finished(QDBusPendingCallWatcher *self=nullptr)
This signal is emitted when the pending call has finished and its reply is available.
The QDBusServiceWatcher class allows the user to watch for a bus service change.
bool removeWatchedService(const QString &service)
Removes the service from the list of services being watched by this object.
void setConnection(const QDBusConnection &connection)
Sets the D-Bus connection that this object is attached to be connection.
void addWatchedService(const QString &newService)
Adds newService to the list of services to be watched by this object.
Type
This enum type defines the valid event types in Qt.
Type type() const
Returns the event type.
bool atEnd() const override
Returns true if the end of the file has been reached; otherwise returns false.
bool exists() const
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
QString platformName
The name of the underlying platform plugin.
bool needsSurroundingText
std::unique_ptr< QIBusProxy > bus
QIBusPlatformInputContextPrivate()
~QIBusPlatformInputContextPrivate()
QList< QInputMethodEvent::Attribute > attributes
PreeditFocusMode preeditFocusMode
std::unique_ptr< QIBusInputContextProxy > context
static QString getSocketPath()
QDBusServiceWatcher serviceWatcher
std::unique_ptr< QIBusProxyPortal > portalBus
QIBusPlatformInputContext()
void invokeAction(QInputMethod::Action a, int x) override
Called when the word currently being composed in the input item is tapped by the user.
void commitText(const QDBusVariant &text)
void busUnregistered(const QString &str)
bool filterEvent(const QEvent *event) override
This function can be reimplemented to filter input events.
void globalEngineChanged(const QString &engine_name)
void filterEventFinished(QDBusPendingCallWatcher *call)
void update(Qt::InputMethodQueries) override
Notification on editor updates.
bool hasCapability(Capability capability) const override
Returns whether the implementation supports capability.
void socketChanged(const QString &str)
QLocale locale() const override
bool isValid() const override
Returns input context validity.
void forwardKeyEvent(uint keyval, uint keycode, uint state)
void setFocusObject(QObject *object) override
This virtual method gets called to notify updated focus to object.
void updatePreeditText(const QDBusVariant &text, uint cursor_pos, bool visible)
~QIBusPlatformInputContext()
void surroundingTextRequired()
void updatePreeditTextWithMode(const QDBusVariant &text, uint cursor_pos, bool visible, uint mode)
void reset() override
Method to be called when input method needs to be reset.
void busRegistered(const QString &str)
void deleteSurroundingText(int offset, uint n_chars)
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes,...
The QKeyEvent class describes a key event.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
quint32 nativeScanCode() const
QString text() const
Returns the Unicode text that this key generated.
quint32 nativeVirtualKey() const
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
quint32 nativeModifiers() const
int key() const
Returns the code of the key that was pressed or released.
const_reference at(qsizetype i) const noexcept
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void deleteLater()
\threadsafe
bool inputMethodAccepted() const
Returns true if current focus object supports input method events.
virtual QLocale locale() const
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
static QString writableLocation(StandardLocation type)
static QString findExecutable(const QString &executableName, const QStringList &paths=QStringList())
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const &
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an {unsigned int} using base base, which is 10 by default and must be...
void setSingleShot(bool singleShot)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void stop()
Stops the timer.
void setValue(T &&avalue)
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
static QString lookupStringNoKeysymTransformations(xkb_keysym_t keysym)
static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers)
EGLImageKHR int int EGLuint64KHR * modifiers
struct wl_display * display
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
DBusConnection * connection
static bool shouldConnectIbusPortal()
static bool checkNeedPortalSupport()
#define IBUS_CONTROL_MASK
#define IBUS_RELEASE_MASK
#define qCDebug(category,...)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLbitfield GLuint64 timeout
[4]
GLenum GLuint GLintptr offset
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
GLenum GLenum GLenum GLenum GLenum scale
GLenum GLenum GLenum input
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QFutureWatcher< int > watcher