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

Classes

struct  Capture
 What a screenshot shows: a window, and the part of it to keep. More...
class  ResizeWait
 One window_resize call waiting for its window to take the new size. More...

Functions

QJsonObject rectJson (const QRectF &r)
 A rectangle as {x, y, width, height}.
auto metaEnumValue (int value)
 value as QMetaEnum takes it: quint64 since Qt 6.9, int before.
template<typename E>
QString enumKey (E value)
 The key name of a Q_ENUM value (or its number).
QJsonObject windowJson (QWindow *w)
 A window_list entry.
QJsonObject endpointsJson (const Server &server)
 The endpoints server listens on, so a client can tell which copy it reached.
ToolResult appInfo (const Server &server)
 The app_info tool.
void installAppInfo (Server &server)
 Registers app_info.
ToolResult listWindows (const QJsonObject &args)
 The window_list tool.
void installListWindows (Server &server)
 Registers window_list.
std::optional< Capture > captureFor (const QJsonObject &args, QString *error)
 Resolves the "object" or "window" argument of screenshot.
QImage grabScaled (const Capture &c, int maxSize, double *scale, QString *error)
 Grabs c and scales it to logical size, or smaller to fit maxSize.
QByteArray encodeImage (QImage image, bool jpeg, int quality)
 Encodes image as PNG, or as JPEG with quality if jpeg. Empty on failure.
QString popupWindowsNote (QWindow *window)
 A line per open popup of window that has its own window, so a screenshot of window doesn't show it (a combo box's list, a menu).
ToolResult screenshot (const QJsonObject &args)
 The window_screenshot tool.
void installScreenshot (Server &server)
 Registers screenshot.
QString sizeText (const QSize &s)
 "WxH".
QStringList resizeNotes (const QWindow *window, const QObject *object, const QSize &asked)
 Why window may not have the size asked, as notes.
QString resizeReply (QWindow *window, const QObject *object, const QSize &before, const QSize &asked)
 The reply to window_resize: the size before and after, and why it differs from asked.
void windowResize (const ToolCall &call)
 The window_resize tool: resize, wait for the size to arrive, then let layouts settle.
void installWindowResize (Server &server)
 Registers window_resize.
ToolResult objectAt (const QJsonObject &args)
 The object_at tool.
void installObjectAt (Server &server)
 Registers object_at.
ToolResult objectLayout (const QJsonObject &args)
 The layout_explain tool: the integration's layout facts, notes first.
void installObjectLayout (Server &server)
 Registers layout_explain.
bool hasLogSource (const Server &server)
 Whether server already has a LogEventSource.

Variables

constexpr int kDefaultMaxScreenshotSize = 1568
 Default longest edge of a screenshot, in pixels.
constexpr int kResizePollMs = 20
 How often window_resize checks whether the new size has arrived, in milliseconds.
constexpr int kResizeWaitMs = 2000
 How long window_resize waits for the new size, in milliseconds.
constexpr int kResizeStableMs = 100
 A size that hasn't changed for this long is final, even if it isn't the one asked for (a minimum size, say), in milliseconds.
constexpr int kDefaultResizeSettleMs = 100
 Default time to let layouts settle after a resize, in milliseconds.

Function Documentation

◆ captureFor()

std::optional< Capture > Sonde::anonymous_namespace{windowtools.cpp}::captureFor ( const QJsonObject & args,
QString * error )

Resolves the "object" or "window" argument of screenshot.

Returns
The capture, or std::nullopt with error set.

◆ grabScaled()

QImage Sonde::anonymous_namespace{windowtools.cpp}::grabScaled ( const Capture & c,
int maxSize,
double * scale,
QString * error )

Grabs c and scales it to logical size, or smaller to fit maxSize.

Parameters
cWhat to capture.
maxSizeLongest edge of the result.
scaleReceives image pixels per logical pixel.
errorReceives why it failed.
Returns
The image, or a null image.

◆ metaEnumValue()

auto Sonde::anonymous_namespace{windowtools.cpp}::metaEnumValue ( int value)

value as QMetaEnum takes it: quint64 since Qt 6.9, int before.

Converting a negative value to quint64 sign-extends it, which Qt 6.9 expects.