114 explicit ScriptedAlgorithm(
const QString& filePath, std::shared_ptr<ScriptedAlgorithmWatchdog> watchdog =
nullptr,
115 QObject* parent =
nullptr);
164 bool supportsMemory() const noexcept override;
165 QString zoneNumberDisplay() const noexcept override;
166 bool centerLayout() const override;
167 bool isScripted() const noexcept override;
168 bool isUserScript() const noexcept override;
172 bool supportsLifecycleHooks() const noexcept override;
174 void onWindowRemoved(
TilingState* state,
int windowIndex) override;
177 bool supportsCustomParams() const noexcept override;
178 QVariantList customParamDefList() const override;
179 bool hasCustomParam(const QString& name) const override;
183 const QVector<ScriptedHelpers::CustomParamDef>& customParamDefs() const;
191 bool loadScript(const QString& filePath);
199 QJSValue splitNodeToJSValue(const
SplitNode* node,
int depth = 0) const;
202 QJSValue splitNodeToJSValueImpl(const
SplitNode* node, const QJSValue& freezeFn,
int depth,
int& nodeCount) const;
212 T resolveJsOverride(const QJSValue& jsFn, T cachedValue, T metadataFallback)
const
214 if (m_cachedValuesLoaded && jsFn.isCallable()) {
219 return metadataFallback;
226 T resolveJsOverrideClamped(
const QJSValue& jsFn, T cachedValue, T metadataFallback, T minVal, T maxVal)
const
228 return std::clamp(resolveJsOverride<T>(jsFn, cachedValue, metadataFallback), minVal, maxVal);
232 QJSValue buildJsState(
const TilingState* state)
const;
235 QJSValue buildJsWindowArray(
const QVector<WindowInfo>& infos,
int cap)
const;
238 QJSValue guardedCall(
const std::function<QJSValue()>& fn)
const;
258 void interruptEngine();
261 static constexpr int MaxTreeConversionDepth = AutotileDefaults::MaxRuntimeTreeDepth;
264 mutable QJSEngine* m_engine =
nullptr;
271 std::shared_ptr<ScriptedAlgorithmWatchdog> m_watchdog;
272 mutable QJSValue m_calculateZonesFn;
275 bool m_valid =
false;
276 bool m_isUserScript =
false;
277 mutable std::atomic<bool> m_evaluating{
false};
278 mutable bool m_lastCallTimedOut =
false;
279 mutable uint32_t m_gcCounter = 0;
280 static constexpr uint32_t GcInterval = 8;
283 ScriptedHelpers::ScriptMetadata m_metadata;
286 mutable QJSValue m_jsMasterZoneIndex;
287 mutable QJSValue m_jsSupportsMasterCount;
288 mutable QJSValue m_jsSupportsSplitRatio;
289 mutable QJSValue m_jsDefaultSplitRatio;
290 mutable QJSValue m_jsMinimumWindows;
291 mutable QJSValue m_jsDefaultMaxWindows;
292 mutable QJSValue m_jsProducesOverlappingZones;
293 mutable QJSValue m_jsCenterLayout;
296 mutable QJSValue m_jsOnWindowAdded;
297 mutable QJSValue m_jsOnWindowRemoved;
298 bool m_hasLifecycleHooks =
false;
301 int m_cachedMinimumWindows = 1;
302 int m_cachedDefaultMaxWindows = 6;
303 int m_cachedMasterZoneIndex = -1;
304 qreal m_cachedDefaultSplitRatio = AutotileDefaults::DefaultSplitRatio;
305 bool m_cachedProducesOverlappingZones =
false;
306 bool m_cachedSupportsMasterCount =
false;
307 bool m_cachedSupportsSplitRatio =
false;
308 bool m_cachedCenterLayout =
false;
309 bool m_cachedValuesLoaded =
false;
T jsValueTo(const QJSValue &v)
Type-converter for QJSValue results — selects toBool() for bool, toInt() for int, toNumber() for qrea...
Definition ScriptedAlgorithm.h:44