Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
inputtools.cpp File Reference

The input tools' shared parts, the mouse tools, and installInputTools(). More...

#include "inputtools_p.h"
#include <sonde/guiintegration.h>
#include <sonde/guitools.h>
#include <sonde/objecttree.h>
#include <sonde/schema.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QElapsedTimer>
#include <QtCore/QPointer>
#include <QtCore/QTimer>
#include <QtGui/QGuiApplication>
#include <QtGui/QStyleHints>
#include <QtGui/QWheelEvent>
#include <QtGui/QWindow>
#include <array>
#include <climits>
#include <cmath>

Classes

struct  Sonde::anonymous_namespace{inputtools.cpp}::PointerState
 Pointer state shared by all input tools: the buttons currently held and a synthetic, monotonic event clock (like QTest's lastMouseTimestamp). More...
struct  Sonde::anonymous_namespace{inputtools.cpp}::Target
 A resolved pointer target. More...
struct  Sonde::anonymous_namespace{inputtools.cpp}::TargetKeys
 Keys naming a target in a tool's arguments: {object, x, y} or {toObject, toX, toY}. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

void qt_handleMouseEvent (QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods, int timestamp)
 QtGui entry point used by QtTest: delivers a mouse event synchronously through QGuiApplication.
void qt_handleKeyEvent (QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text, bool autorep, ushort count)
 QtGui entry point used by QtTest: delivers a key event synchronously through QGuiApplication (shortcuts included).
PointerState & Sonde::anonymous_namespace{inputtools.cpp}::pointer ()
 The process-wide pointer state.
int Sonde::anonymous_namespace{inputtools.cpp}::nextTimestamp (int delta=10)
 Advances the synthetic clock by at least delta ms and returns it as an event timestamp.
QJsonObject Sonde::anonymous_namespace{inputtools.cpp}::settleProperty ()
 Schema of the settleMs argument.
QJsonObject Sonde::anonymous_namespace{inputtools.cpp}::modifiersProperty ()
 Schema of the modifiers argument.
QJsonObject Sonde::anonymous_namespace{inputtools.cpp}::pointerSchema (const QJsonObject &extra)
 The argument schema of a pointer tool: window, object, x, y, modifiers, settleMs, plus extra.
Qt::KeyboardModifiers Sonde::anonymous_namespace{inputtools.cpp}::parseModifiers (const QJsonValue &v)
 Parses a modifiers array ("shift", "ctrl"/"control", "alt", "meta").
std::optional< Qt::MouseButton > Sonde::anonymous_namespace{inputtools.cpp}::parseButton (const QJsonValue &v)
 Parses a button name (default "left"); std::nullopt if unknown.
QWindow * Sonde::anonymous_namespace{inputtools.cpp}::objectWindow (const QString &spec, QRectF *rect, Target *target, QString *error)
 Resolves the object named by spec to its window and on-screen rectangle.
bool Sonde::anonymous_namespace{inputtools.cpp}::checkTarget (const Target &t, QString *error)
 Checks that t is a visible window and a point inside it.
std::optional< Target > Sonde::anonymous_namespace{inputtools.cpp}::resolveTarget (const QJsonObject &args, QString *error, const TargetKeys &keys={ })
 Resolves {window, object, x, y} (or the keys in keys) to a window and a point inside it.
QString Sonde::anonymous_namespace{inputtools.cpp}::missedTargetNote (const DeliveryRecorder &recorder, const Target &target)
 A note when the tool aimed at an object that the press never reached.
void Sonde::anonymous_namespace{inputtools.cpp}::mouse (QWindow *w, QEvent::Type type, const QPointF &pos, Qt::MouseButton button, Qt::KeyboardModifiers mods, int delta=10)
 Delivers one mouse event and tracks the pressed buttons.
QString Sonde::anonymous_namespace{inputtools.cpp}::hitDescription (QWindow *w, const QPointF &pos)
 Describes the object at pos (or the window).
QString Sonde::anonymous_namespace{inputtools.cpp}::pointText (const Target &t)
 "(x, y) in <window>".
QObjectList Sonde::anonymous_namespace{inputtools.cpp}::movingViews ()
 The views still scrolling on their own, in every visible window.
QString Sonde::anonymous_namespace{inputtools.cpp}::describeViews (const QObjectList &views)
 "a, b and 2 more" for the first views of views.
void Sonde::anonymous_namespace{inputtools.cpp}::finishWhenStill (const ToolCall &call, const std::function< QString()> &summary, const QElapsedTimer &waited, int maxWaitMs)
 Finishes call once no view is scrolling, or maxWaitMs after waited started.
QString Sonde::anonymous_namespace{inputtools.cpp}::movingViewNote (const Target &t)
 A note if the press at t lands on a view that is still scrolling, which takes the press to stop itself; empty otherwise.
void Sonde::anonymous_namespace{inputtools.cpp}::mouseClick (const ToolCall &call)
 The input_click tool.
void Sonde::anonymous_namespace{inputtools.cpp}::mouseMove (const ToolCall &call)
 The input_move tool.
bool Sonde::anonymous_namespace{inputtools.cpp}::resolveDrag (const QJsonObject &args, Target *from, Target *to, QString *error)
 Resolves both ends of a drag; the end is looked up in the start's window.
void Sonde::anonymous_namespace{inputtools.cpp}::mouseDrag (const ToolCall &call)
 The input_drag tool.
std::optional< int > Sonde::anonymous_namespace{inputtools.cpp}::wheelAngle (const QJsonObject &args, const QString &key, QString *error)
 Reads a wheel delta argument (in notches) as an angle delta.
void Sonde::anonymous_namespace{inputtools.cpp}::mouseScroll (const ToolCall &call)
 The input_scroll tool.
void Sonde::anonymous_namespace{inputtools.cpp}::installMouseTools (Server &server)
 Registers the four mouse tools.
void Sonde::installInputTools (Server &server)
 Registers input_click, input_move, input_drag, input_scroll, input_keys and input_text.

Variables

constexpr int Sonde::anonymous_namespace{inputtools.cpp}::kDefaultSettleMs = 100
 Default time the application gets to react before a tool replies.
constexpr int Sonde::anonymous_namespace{inputtools.cpp}::kMaxScrollWaitMs = 3000
 Longest a tool waits, after settleMs, for scrolling views to stop.
constexpr int Sonde::anonymous_namespace{inputtools.cpp}::kScrollPollMs = 16
 How often a tool checks whether views are still scrolling.
constexpr double Sonde::anonymous_namespace{inputtools.cpp}::kMaxScrollNotches = 1000
 Largest wheel movement input_scroll accepts, in notches per axis.
constexpr int Sonde::anonymous_namespace{inputtools.cpp}::kAnglePerNotch = 120
 Angle delta of one wheel notch (1/8 degree units, as Qt reports it).

Detailed Description

The input tools' shared parts, the mouse tools, and installInputTools().

The keyboard tools are in keyboardtools.cpp.