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

The app_info, window_list, window_resize, screenshot, object_at and layout_explain tools, and installStandardTools(). More...

#include "instance_p.h"
#include "overflowtools_p.h"
#include <sonde/guiintegration.h>
#include <sonde/guitools.h>
#include <sonde/instance.h>
#include <sonde/introspectiontools.h>
#include <sonde/logeventsource.h>
#include <sonde/objecttree.h>
#include <sonde/schema.h>
#include <sonde/stalleventsource.h>
#include <QtCore/QBuffer>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QMetaEnum>
#include <QtCore/QPointer>
#include <QtCore/QTimer>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <QtGui/QWindow>
#include <utility>

Classes

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

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

QJsonObject Sonde::anonymous_namespace{windowtools.cpp}::rectJson (const QRectF &r)
 A rectangle as {x, y, width, height}.
auto Sonde::anonymous_namespace{windowtools.cpp}::metaEnumValue (int value)
 value as QMetaEnum takes it: quint64 since Qt 6.9, int before.
template<typename E>
QString Sonde::anonymous_namespace{windowtools.cpp}::enumKey (E value)
 The key name of a Q_ENUM value (or its number).
QJsonObject Sonde::anonymous_namespace{windowtools.cpp}::windowJson (QWindow *w)
 A window_list entry.
QJsonObject Sonde::anonymous_namespace{windowtools.cpp}::endpointsJson (const Server &server)
 The endpoints server listens on, so a client can tell which copy it reached.
ToolResult Sonde::anonymous_namespace{windowtools.cpp}::appInfo (const Server &server)
 The app_info tool.
void Sonde::anonymous_namespace{windowtools.cpp}::installAppInfo (Server &server)
 Registers app_info.
ToolResult Sonde::anonymous_namespace{windowtools.cpp}::listWindows (const QJsonObject &args)
 The window_list tool.
void Sonde::anonymous_namespace{windowtools.cpp}::installListWindows (Server &server)
 Registers window_list.
std::optional< Capture > Sonde::anonymous_namespace{windowtools.cpp}::captureFor (const QJsonObject &args, QString *error)
 Resolves the "object" or "window" argument of screenshot.
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.
QByteArray Sonde::anonymous_namespace{windowtools.cpp}::encodeImage (QImage image, bool jpeg, int quality)
 Encodes image as PNG, or as JPEG with quality if jpeg. Empty on failure.
QString Sonde::anonymous_namespace{windowtools.cpp}::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 Sonde::anonymous_namespace{windowtools.cpp}::screenshot (const QJsonObject &args)
 The window_screenshot tool.
void Sonde::anonymous_namespace{windowtools.cpp}::installScreenshot (Server &server)
 Registers screenshot.
QString Sonde::anonymous_namespace{windowtools.cpp}::sizeText (const QSize &s)
 "WxH".
QStringList Sonde::anonymous_namespace{windowtools.cpp}::resizeNotes (const QWindow *window, const QObject *object, const QSize &asked)
 Why window may not have the size asked, as notes.
QString Sonde::anonymous_namespace{windowtools.cpp}::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 Sonde::anonymous_namespace{windowtools.cpp}::windowResize (const ToolCall &call)
 The window_resize tool: resize, wait for the size to arrive, then let layouts settle.
void Sonde::anonymous_namespace{windowtools.cpp}::installWindowResize (Server &server)
 Registers window_resize.
ToolResult Sonde::anonymous_namespace{windowtools.cpp}::objectAt (const QJsonObject &args)
 The object_at tool.
void Sonde::anonymous_namespace{windowtools.cpp}::installObjectAt (Server &server)
 Registers object_at.
ToolResult Sonde::anonymous_namespace{windowtools.cpp}::objectLayout (const QJsonObject &args)
 The layout_explain tool: the integration's layout facts, notes first.
void Sonde::anonymous_namespace{windowtools.cpp}::installObjectLayout (Server &server)
 Registers layout_explain.
bool Sonde::anonymous_namespace{windowtools.cpp}::hasLogSource (const Server &server)
 Whether server already has a LogEventSource.
void Sonde::installWindowTools (Server &server)
 Registers app_info, window_list, window_resize, screenshot, object_at, layout_explain and layout_overflow.
void Sonde::installStandardTools (Server &server)
 Registers everything above, the QObject introspection tools, a LogEventSource that feeds Qt log output to the events tools, and a StallEventSource that reports when the main thread was blocked.

Variables

constexpr int Sonde::anonymous_namespace{windowtools.cpp}::kDefaultMaxScreenshotSize = 1568
 Default longest edge of a screenshot, in pixels.
constexpr int Sonde::anonymous_namespace{windowtools.cpp}::kResizePollMs = 20
 How often window_resize checks whether the new size has arrived, in milliseconds.
constexpr int Sonde::anonymous_namespace{windowtools.cpp}::kResizeWaitMs = 2000
 How long window_resize waits for the new size, in milliseconds.
constexpr int Sonde::anonymous_namespace{windowtools.cpp}::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 Sonde::anonymous_namespace{windowtools.cpp}::kDefaultResizeSettleMs = 100
 Default time to let layouts settle after a resize, in milliseconds.

Detailed Description

The app_info, window_list, window_resize, screenshot, object_at and layout_explain tools, and installStandardTools().