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)
71 std::unique_ptr<QIBusProxy>
bus;
73 std::unique_ptr<QIBusInputContextProxy>
context;
93#if QT_CONFIG(filesystemwatcher)
94 qCDebug(qtQpaInputMethods) <<
"socketWatcher.addPath" << socketPath;
98 m_socketWatcher.addPath(socketPath);
109 connectToContextSignals();
113 m_eventFilterUseSynchronousMode =
false;
117 if (
ok && enableSync == 1)
118 m_eventFilterUseSynchronousMode =
true;
134 switch (capability) {
176 event.setCommitString(d->
predit);
204 text.text = surroundingText;
210 d->
context->SetSurroundingText(dbusText, cursorPosition, anchorPosition);
219 QRect r =
qApp->inputMethod()->cursorRectangle().toRect();
226 if (!inputWindow->screen())
230 auto margins = inputWindow->frameMargins();
231 r.translate(margins.left(), margins.top());
232 qreal scale = inputWindow->devicePixelRatio();
235 qDebug() <<
"microFocus" << newRect;
236 d->
context->SetCursorLocationRelative(newRect.
x(), newRect.
y(),
242 auto screenGeometry = inputWindow->screen()->
geometry();
243 auto point = inputWindow->mapToGlobal(
r.topLeft());
244 qreal scale = inputWindow->devicePixelRatio();
245 auto native = (point - screenGeometry.topLeft()) *
scale + screenGeometry.topLeft();
248 qDebug() <<
"microFocus" << newRect;
249 d->
context->SetCursorLocation(newRect.
x(), newRect.
y(),
285 qDebug() <<
"commit text:" <<
t.text;
288 event.setCommitString(
t.text);
309 qDebug() <<
"preedit text:" <<
t.text;
312 if (!
t.text.isEmpty())
334 state &= ~IBUS_RELEASE_MASK;
360 qDebug(
"surroundingTextRequired");
372 qDebug() <<
"deleteSurroundingText" <<
offset << n_chars;
375 event.setCommitString(
"",
offset, n_chars);
420 bool filtered =
reply.value();
421 qCDebug(qtQpaInputMethods) <<
"filterEvent return" << code << sym <<
state << filtered;
426 const int qtcode = keyEvent->
key();
449 args << QVariant::fromValue(static_cast<uint>(keyEvent->
type()));
466 if (
reply.isError()) {
484 const int qtcode =
args.
at(2).toInt();
489 const bool isAutoRepeat =
args.
at(7).toBool();
492 bool filtered =
reply.value();
493 qCDebug(qtQpaInputMethods) <<
"filterEventFinished return" << code << sym <<
state << filtered;
495#ifndef QT_NO_CONTEXTMENU
498 const QPoint globalPos =
window->screen()->handle()->cursor()->pos();
506 code, sym,
state,
string, isAutoRepeat);
522 qCDebug(qtQpaInputMethods) <<
"socketChanged";
539 qCDebug(qtQpaInputMethods) <<
"busRegistered";
548 qCDebug(qtQpaInputMethods) <<
"busUnregistered";
557 qCDebug(qtQpaInputMethods) <<
"QIBusPlatformInputContext::connectToBus";
559 connectToContextSignals();
561#if QT_CONFIG(filesystemwatcher)
562 if (!d->
usePortal && m_socketWatcher.files().size() == 0)
569 if (!d->
bus || !d->
bus->isValid())
581void QIBusPlatformInputContext::connectToContextSignals()
583 if (d->
bus && d->
bus->isValid()) {
613 needsSurroundingText(
false)
618 qDebug() <<
"use IBus portal";
626 if (
bus &&
bus->isValid()) {
645 const char* ibusService =
usePortal ?
"org.freedesktop.portal.IBus" :
"org.freedesktop.IBus";
649 "/org/freedesktop/IBus"_L1,
652 qWarning(
"QIBusPlatformInputContext: invalid portal bus.");
656 ic =
portalBus->CreateInputContext(
"QIBusInputContext"_L1);
659 "/org/freedesktop/IBus"_L1,
661 if (!
bus->isValid()) {
662 qWarning(
"QIBusPlatformInputContext: invalid bus.");
666 ic =
bus->CreateInputContext(
"QIBusInputContext"_L1);
674 qWarning(
"QIBusPlatformInputContext: CreateInputContext failed.");
681 qWarning(
"QIBusPlatformInputContext: invalid input context.");
686 IBUS_CAP_PREEDIT_TEXT = 1 << 0,
687 IBUS_CAP_AUXILIARY_TEXT = 1 << 1,
688 IBUS_CAP_LOOKUP_TABLE = 1 << 2,
689 IBUS_CAP_FOCUS = 1 << 3,
690 IBUS_CAP_PROPERTY = 1 << 4,
691 IBUS_CAP_SURROUNDING_TEXT = 1 << 5
693 context->SetCapabilities(IBUS_CAP_PREEDIT_TEXT|IBUS_CAP_FOCUS|IBUS_CAP_SURROUNDING_TEXT);
696 qDebug(
">>>> bus connected!");
704 bool isWayland =
false;
732 qDebug() <<
"host=" << host <<
"displayNumber" << displayNumber;
767 if (
address.isEmpty() || pid < 0 || kill(pid, 0) != 0)
775#include "moc_qibusplatforminputcontext.cpp"
QByteArray left(qsizetype len) const
Returns a byte array that contains the first len bytes of this byte array.
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
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.
Type value() const
Returns the remote function's calls return value.
bool isValid() const
Returns true if no error occurred; otherwise, returns false.
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 exists; otherwise returns false.
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
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 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
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
QRect geometry
the screen's geometry in pixels
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...
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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...
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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.
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 >
void setValue(T &&avalue)
Stores a copy of value.
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.
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