Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::anonymous_namespace{inputtools.cpp} Namespace Reference

Classes

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

Functions

PointerState & pointer ()
 The process-wide pointer state.
int nextTimestamp (int delta=10)
 Advances the synthetic clock by at least delta ms and returns it as an event timestamp.
QJsonObject settleProperty ()
 Schema of the settleMs argument.
QJsonObject modifiersProperty ()
 Schema of the modifiers argument.
QJsonObject pointerSchema (const QJsonObject &extra)
 The argument schema of a pointer tool: window, object, x, y, modifiers, settleMs, plus extra.
Qt::KeyboardModifiers parseModifiers (const QJsonValue &v)
 Parses a modifiers array ("shift", "ctrl"/"control", "alt", "meta").
std::optional< Qt::MouseButton > parseButton (const QJsonValue &v)
 Parses a button name (default "left"); std::nullopt if unknown.
QWindow * objectWindow (const QString &spec, QRectF *rect, Target *target, QString *error)
 Resolves the object named by spec to its window and on-screen rectangle.
bool checkTarget (const Target &t, QString *error)
 Checks that t is a visible window and a point inside it.
std::optional< Target > 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 missedTargetNote (const DeliveryRecorder &recorder, const Target &target)
 A note when the tool aimed at an object that the press never reached.
void 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 hitDescription (QWindow *w, const QPointF &pos)
 Describes the object at pos (or the window).
QString pointText (const Target &t)
 "(x, y) in <window>".
QObjectList movingViews ()
 The views still scrolling on their own, in every visible window.
QString describeViews (const QObjectList &views)
 "a, b and 2 more" for the first views of views.
void 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 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 mouseClick (const ToolCall &call)
 The input_click tool.
void mouseMove (const ToolCall &call)
 The input_move tool.
bool 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 mouseDrag (const ToolCall &call)
 The input_drag tool.
std::optional< int > wheelAngle (const QJsonObject &args, const QString &key, QString *error)
 Reads a wheel delta argument (in notches) as an angle delta.
void mouseScroll (const ToolCall &call)
 The input_scroll tool.
void installMouseTools (Server &server)
 Registers the four mouse tools.

Variables

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

Function Documentation

◆ movingViewNote()

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.

Call before pressing.

◆ nextTimestamp()

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.

The clock is kept in 64 bits; event timestamps are int, so the value wraps to 0 after about 24.8 days. Qt compares timestamps as unsigned differences, so the wrap at worst prevents one double click.

◆ objectWindow()

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.

Returns
The window, or nullptr with error set.

◆ resolveDrag()

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.

Returns
Whether both ends are valid and in the same window (error set otherwise).

◆ resolveTarget()

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.

With an object, x/y are relative to its top-left corner, and its center is used without them. Without an object, x/y are window coordinates in the "window" argument's window.

◆ wheelAngle()

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.

Returns
The angle, or std::nullopt if it exceeds kMaxScrollNotches (error set).