From f91d0397a00b0ca383d6f519494f66dfe9d2ed98 Mon Sep 17 00:00:00 2001 From: Niko Savola Date: Mon, 27 Apr 2026 14:02:48 +0300 Subject: [PATCH] Add `[[nodiscard]]` annotations to API methods --- src/Compositor.hpp | 160 +++++++++++++++---------------- src/config/lua/ConfigManager.hpp | 32 +++---- src/managers/input/Touch.cpp | 2 +- src/plugins/PluginAPI.hpp | 34 +++---- src/plugins/PluginSystem.hpp | 20 ++-- 5 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 7fbc7d525..e383dd307 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -92,88 +92,88 @@ class CCompositor { // - PHLMONITOR getMonitorFromID(const MONITORID&); - PHLMONITOR getMonitorFromName(const std::string&); - PHLMONITOR getMonitorFromDesc(const std::string&); - PHLMONITOR getMonitorFromCursor(); - PHLMONITOR getMonitorFromVector(const Vector2D&); - void removeWindowFromVectorSafe(PHLWINDOW); - bool monitorExists(PHLMONITOR); - PHLWINDOW vectorToWindowUnified(const Vector2D&, uint16_t properties, PHLWINDOW pIgnoreWindow = nullptr); - SP vectorToLayerSurface(const Vector2D&, std::vector*, Vector2D*, PHLLS*, bool aboveLockscreen = false); - SP vectorToLayerPopupSurface(const Vector2D&, PHLMONITOR monitor, Vector2D*, PHLLS*); - SP vectorWindowToSurface(const Vector2D&, PHLWINDOW, Vector2D& sl); - Vector2D vectorToSurfaceLocal(const Vector2D&, PHLWINDOW, SP); - PHLMONITOR getMonitorFromOutput(SP); - PHLMONITOR getRealMonitorFromOutput(SP); - PHLWINDOW getWindowFromSurface(SP); - PHLWINDOW getWindowFromHandle(uint32_t); - PHLWORKSPACE getWorkspaceByID(const WORKSPACEID&); - PHLWORKSPACE getWorkspaceByName(const std::string&); - PHLWORKSPACE getWorkspaceByString(const std::string&); - PHLWINDOW getUrgentWindow(); - bool isWindowActive(PHLWINDOW); - void changeWindowZOrder(PHLWINDOW, bool); - void cleanupFadingOut(const MONITORID& monid); - PHLWINDOW getWindowInDirection(PHLWINDOW, Math::eDirection); - PHLWINDOW getWindowInDirection(const CBox& box, PHLWORKSPACE pWorkspace, Math::eDirection dir, PHLWINDOW ignoreWindow = nullptr, bool useVectorAngles = false); - PHLWINDOW getWindowCycle(PHLWINDOW cur, bool focusableOnly = false, std::optional floating = std::nullopt, bool visible = false, bool prev = false, - bool allowFullscreenBlocked = false); - PHLWINDOW getWindowCycleHist(PHLWINDOWREF cur, bool focusableOnly = false, std::optional floating = std::nullopt, bool visible = false, bool next = false, - bool allowFullscreenBlocked = false); - WORKSPACEID getNextAvailableNamedWorkspace(); - bool isPointOnAnyMonitor(const Vector2D&); - bool isPointOnReservedArea(const Vector2D& point, const PHLMONITOR monitor = nullptr); - std::optional calculateX11WorkArea(); - PHLMONITOR getMonitorInDirection(Math::eDirection); - PHLMONITOR getMonitorInDirection(PHLMONITOR, Math::eDirection); - void updateAllWindowsAnimatedDecorationValues(); - MONITORID getNextAvailableMonitorID(std::string const& name); - void moveWorkspaceToMonitor(PHLWORKSPACE, PHLMONITOR, bool noWarpCursor = false); - void swapActiveWorkspaces(PHLMONITOR, PHLMONITOR); - PHLMONITOR getMonitorFromString(const std::string&); - bool workspaceIDOutOfBounds(const WORKSPACEID&); - void setWindowFullscreenInternal(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); - void setWindowFullscreenClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); - void setWindowFullscreenState(const PHLWINDOW PWINDOW, const Desktop::View::SFullscreenState state); - void changeWindowFullscreenModeClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE, const bool ON); - PHLWINDOW getX11Parent(PHLWINDOW); - void scheduleFrameForMonitor(PHLMONITOR, Aquamarine::IOutput::scheduleFrameReason reason = Aquamarine::IOutput::AQ_SCHEDULE_CLIENT_UNKNOWN); - void addToFadingOutSafe(PHLLS); - void removeFromFadingOutSafe(PHLLS); - void addToFadingOutSafe(PHLWINDOW); - PHLWINDOW getWindowByRegex(const std::string&); - void warpCursorTo(const Vector2D&, bool force = false); - PHLLS getLayerSurfaceFromSurface(SP); - Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); - [[nodiscard]] PHLWORKSPACE createNewWorkspace(const WORKSPACEID&, const MONITORID&, const std::string& name = "", - bool isEmpty = true); // will be deleted next frame if left empty and unfocused! - bool isWorkspaceSpecial(const WORKSPACEID&); - WORKSPACEID getNewSpecialID(); - void performUserChecks(); - void moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWorkspace); - PHLWINDOW getForceFocus(); - void scheduleMonitorStateRecheck(); - void arrangeMonitors(); - void checkMonitorOverlaps(); - void enterUnsafeState(); - void leaveUnsafeState(); - void setPreferredScaleForSurface(SP pSurface, double scale); - void setPreferredTransformForSurface(SP pSurface, wl_output_transform transform); - void updateSuspendedStates(); - void onNewMonitor(SP output); - void ensurePersistentWorkspacesPresent(const std::vector& rules, PHLWORKSPACE pWorkspace = nullptr); - void ensurePersistentWorkspacesPresent(PHLWORKSPACE pWorkspace = nullptr); - void ensureWorkspacesOnAssignedMonitors(); - std::optional getVTNr(); - bool isVRRActiveOnAnyMonitor() const; + [[nodiscard]] PHLMONITOR getMonitorFromID(const MONITORID&); + [[nodiscard]] PHLMONITOR getMonitorFromName(const std::string&); + [[nodiscard]] PHLMONITOR getMonitorFromDesc(const std::string&); + [[nodiscard]] PHLMONITOR getMonitorFromCursor(); + [[nodiscard]] PHLMONITOR getMonitorFromVector(const Vector2D&); + void removeWindowFromVectorSafe(PHLWINDOW); + [[nodiscard]] bool monitorExists(PHLMONITOR); + [[nodiscard]] PHLWINDOW vectorToWindowUnified(const Vector2D&, uint16_t properties, PHLWINDOW pIgnoreWindow = nullptr); + [[nodiscard]] SP vectorToLayerSurface(const Vector2D&, std::vector*, Vector2D*, PHLLS*, bool aboveLockscreen = false); + [[nodiscard]] SP vectorToLayerPopupSurface(const Vector2D&, PHLMONITOR monitor, Vector2D*, PHLLS*); + [[nodiscard]] SP vectorWindowToSurface(const Vector2D&, PHLWINDOW, Vector2D& sl); + [[nodiscard]] Vector2D vectorToSurfaceLocal(const Vector2D&, PHLWINDOW, SP); + [[nodiscard]] PHLMONITOR getMonitorFromOutput(SP); + [[nodiscard]] PHLMONITOR getRealMonitorFromOutput(SP); + [[nodiscard]] PHLWINDOW getWindowFromSurface(SP); + [[nodiscard]] PHLWINDOW getWindowFromHandle(uint32_t); + [[nodiscard]] PHLWORKSPACE getWorkspaceByID(const WORKSPACEID&); + [[nodiscard]] PHLWORKSPACE getWorkspaceByName(const std::string&); + [[nodiscard]] PHLWORKSPACE getWorkspaceByString(const std::string&); + [[nodiscard]] PHLWINDOW getUrgentWindow(); + [[nodiscard]] bool isWindowActive(PHLWINDOW); + void changeWindowZOrder(PHLWINDOW, bool); + void cleanupFadingOut(const MONITORID& monid); + [[nodiscard]] PHLWINDOW getWindowInDirection(PHLWINDOW, Math::eDirection); + [[nodiscard]] PHLWINDOW getWindowInDirection(const CBox& box, PHLWORKSPACE pWorkspace, Math::eDirection dir, PHLWINDOW ignoreWindow = nullptr, bool useVectorAngles = false); + [[nodiscard]] PHLWINDOW getWindowCycle(PHLWINDOW cur, bool focusableOnly = false, std::optional floating = std::nullopt, bool visible = false, bool prev = false, + bool allowFullscreenBlocked = false); + [[nodiscard]] PHLWINDOW getWindowCycleHist(PHLWINDOWREF cur, bool focusableOnly = false, std::optional floating = std::nullopt, bool visible = false, bool next = false, + bool allowFullscreenBlocked = false); + [[nodiscard]] WORKSPACEID getNextAvailableNamedWorkspace(); + [[nodiscard]] bool isPointOnAnyMonitor(const Vector2D&); + [[nodiscard]] bool isPointOnReservedArea(const Vector2D& point, const PHLMONITOR monitor = nullptr); + [[nodiscard]] std::optional calculateX11WorkArea(); + [[nodiscard]] PHLMONITOR getMonitorInDirection(Math::eDirection); + [[nodiscard]] PHLMONITOR getMonitorInDirection(PHLMONITOR, Math::eDirection); + void updateAllWindowsAnimatedDecorationValues(); + [[nodiscard]] MONITORID getNextAvailableMonitorID(std::string const& name); + void moveWorkspaceToMonitor(PHLWORKSPACE, PHLMONITOR, bool noWarpCursor = false); + void swapActiveWorkspaces(PHLMONITOR, PHLMONITOR); + [[nodiscard]] PHLMONITOR getMonitorFromString(const std::string&); + [[nodiscard]] bool workspaceIDOutOfBounds(const WORKSPACEID&); + void setWindowFullscreenInternal(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); + void setWindowFullscreenClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE); + void setWindowFullscreenState(const PHLWINDOW PWINDOW, const Desktop::View::SFullscreenState state); + void changeWindowFullscreenModeClient(const PHLWINDOW PWINDOW, const eFullscreenMode MODE, const bool ON); + [[nodiscard]] PHLWINDOW getX11Parent(PHLWINDOW); + void scheduleFrameForMonitor(PHLMONITOR, Aquamarine::IOutput::scheduleFrameReason reason = Aquamarine::IOutput::AQ_SCHEDULE_CLIENT_UNKNOWN); + void addToFadingOutSafe(PHLLS); + void removeFromFadingOutSafe(PHLLS); + void addToFadingOutSafe(PHLWINDOW); + [[nodiscard]] PHLWINDOW getWindowByRegex(const std::string&); + void warpCursorTo(const Vector2D&, bool force = false); + [[nodiscard]] PHLLS getLayerSurfaceFromSurface(SP); + [[nodiscard]] Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); + [[nodiscard]] PHLWORKSPACE createNewWorkspace(const WORKSPACEID&, const MONITORID&, const std::string& name = "", + bool isEmpty = true); // will be deleted next frame if left empty and unfocused! + [[nodiscard]] bool isWorkspaceSpecial(const WORKSPACEID&); + [[nodiscard]] WORKSPACEID getNewSpecialID(); + void performUserChecks(); + void moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWorkspace); + [[nodiscard]] PHLWINDOW getForceFocus(); + void scheduleMonitorStateRecheck(); + void arrangeMonitors(); + void checkMonitorOverlaps(); + void enterUnsafeState(); + void leaveUnsafeState(); + void setPreferredScaleForSurface(SP pSurface, double scale); + void setPreferredTransformForSurface(SP pSurface, wl_output_transform transform); + void updateSuspendedStates(); + void onNewMonitor(SP output); + void ensurePersistentWorkspacesPresent(const std::vector& rules, PHLWORKSPACE pWorkspace = nullptr); + void ensurePersistentWorkspacesPresent(PHLWORKSPACE pWorkspace = nullptr); + void ensureWorkspacesOnAssignedMonitors(); + [[nodiscard]] std::optional getVTNr(); + [[nodiscard]] bool isVRRActiveOnAnyMonitor() const; - NColorManagement::PImageDescription getPreferredImageDescription(); - NColorManagement::PImageDescription getHDRImageDescription(); - bool shouldChangePreferredImageDescription(); + [[nodiscard]] NColorManagement::PImageDescription getPreferredImageDescription(); + [[nodiscard]] NColorManagement::PImageDescription getHDRImageDescription(); + bool shouldChangePreferredImageDescription(); - bool supportsDrmSyncobjTimeline() const; - std::string m_explicitConfigPath; + [[nodiscard]] bool supportsDrmSyncobjTimeline() const; + std::string m_explicitConfigPath; private: void initAllSignals(); diff --git a/src/config/lua/ConfigManager.hpp b/src/config/lua/ConfigManager.hpp index 773877583..4c901284f 100644 --- a/src/config/lua/ConfigManager.hpp +++ b/src/config/lua/ConfigManager.hpp @@ -72,7 +72,7 @@ namespace Config::Lua { virtual std::expected generateDefaultConfig(const std::filesystem::path&, bool safeMode) override; virtual void handlePluginLoads() override; - virtual bool configVerifPassed() override; + [[nodiscard]] virtual bool configVerifPassed() override; virtual std::expected registerPluginValue(void* handle, SP value) override; virtual void onPluginUnload(void* handle) override; @@ -89,27 +89,27 @@ namespace Config::Lua { void callLuaFn(int ref); // execute an arbitrary lua string on the current state. - std::optional eval(const std::string& code); + [[nodiscard]] std::optional eval(const std::string& code); - int guardedPCall(int nargs, int nresults, int errfunc, int timeoutMs, std::string_view context); + int guardedPCall(int nargs, int nresults, int errfunc, int timeoutMs, std::string_view context); - static CConfigManager* fromLuaState(lua_State* L); + static CConfigManager* fromLuaState(lua_State* L); - static constexpr int LUA_WATCHDOG_INSTRUCTION_INTERVAL = 10000; - static constexpr int LUA_TIMEOUT_CONFIG_RELOAD_MS = 1500; - static constexpr int LUA_TIMEOUT_EVENT_CALLBACK_MS = 50; - static constexpr int LUA_TIMEOUT_KEYBIND_CALLBACK_MS = 100; - static constexpr int LUA_TIMEOUT_TIMER_CALLBACK_MS = 50; - static constexpr int LUA_TIMEOUT_EVAL_MS = 250; - static constexpr int LUA_TIMEOUT_DISPATCH_MS = 100; + static constexpr int LUA_WATCHDOG_INSTRUCTION_INTERVAL = 10000; + static constexpr int LUA_TIMEOUT_CONFIG_RELOAD_MS = 1500; + static constexpr int LUA_TIMEOUT_EVENT_CALLBACK_MS = 50; + static constexpr int LUA_TIMEOUT_KEYBIND_CALLBACK_MS = 100; + static constexpr int LUA_TIMEOUT_TIMER_CALLBACK_MS = 50; + static constexpr int LUA_TIMEOUT_EVAL_MS = 250; + static constexpr int LUA_TIMEOUT_DISPATCH_MS = 100; - bool isFirstLaunch() const; - bool isDynamicParse() const; + [[nodiscard]] bool isFirstLaunch() const; + [[nodiscard]] bool isDynamicParse() const; - std::string m_currentSubmap; - std::string m_currentSubmapReset; + std::string m_currentSubmap; + std::string m_currentSubmapReset; - UP m_eventHandler; + UP m_eventHandler; struct SLuaTimer { SP timer; diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index f49db8b78..fd0f3005a 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -93,7 +93,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) { local = (TOUCH_COORDS - m_touchData.touchFocusWindow->m_realPosition->goal()) * m_touchData.touchFocusWindow->m_X11SurfaceScaledBy; m_touchData.touchSurfaceOrigin = m_touchData.touchFocusWindow->m_realPosition->goal(); } else { - g_pCompositor->vectorWindowToSurface(TOUCH_COORDS, m_touchData.touchFocusWindow.lock(), local); + m_touchData.touchFocusSurface = g_pCompositor->vectorWindowToSurface(TOUCH_COORDS, m_touchData.touchFocusWindow.lock(), local); m_touchData.touchSurfaceOrigin = TOUCH_COORDS - local; } } else if (!m_touchData.touchFocusLS.expired()) { diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 5321c8db1..5fe21d791 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -187,7 +187,7 @@ namespace HyprlandAPI { returns: the output (as in hyprctl) */ - APICALL std::string invokeHyprctlCommand(const std::string& call, const std::string& args, const std::string& format = ""); + APICALL [[nodiscard]] std::string invokeHyprctlCommand(const std::string& call, const std::string& args, const std::string& format = ""); /* Adds a layout to Hyprland. @@ -210,23 +210,23 @@ namespace HyprlandAPI { /* Algorithm fns. Used for registering and removing. Return success. */ - APICALL bool addTiledAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function()>&& factory); - APICALL bool addFloatingAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function()>&& factory); - APICALL bool removeAlgo(HANDLE handle, const std::string& name); + APICALL [[nodiscard]] bool addTiledAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function()>&& factory); + APICALL [[nodiscard]] bool addFloatingAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function()>&& factory); + APICALL [[nodiscard]] bool removeAlgo(HANDLE handle, const std::string& name); /* Queues a config reload. Does not take effect immediately. returns: true on success. False otherwise. */ - APICALL bool reloadConfig(); + APICALL [[nodiscard]] bool reloadConfig(); /* Adds a notification. returns: true on success. False otherwise. */ - APICALL bool addNotification(HANDLE handle, const std::string& text, const CHyprColor& color, const float timeMs); + APICALL [[nodiscard]] bool addNotification(HANDLE handle, const std::string& text, const CHyprColor& color, const float timeMs); /* Creates a trampoline function hook to an internal hl func. @@ -235,7 +235,7 @@ namespace HyprlandAPI { !WARNING! Hooks are *not* guaranteed any API stability. Internal methods may be removed, added, or renamed. Consider preferring the API whenever possible. */ - APICALL CFunctionHook* createFunctionHook(HANDLE handle, const void* source, const void* destination); + APICALL [[nodiscard]] CFunctionHook* createFunctionHook(HANDLE handle, const void* source, const void* destination); /* Removes a trampoline function hook. Will unhook if still hooked. @@ -244,7 +244,7 @@ namespace HyprlandAPI { !WARNING! Hooks are *not* guaranteed any API stability. Internal methods may be removed, added, or renamed. Consider preferring the API whenever possible. */ - APICALL bool removeFunctionHook(HANDLE handle, CFunctionHook* hook); + APICALL [[nodiscard]] bool removeFunctionHook(HANDLE handle, CFunctionHook* hook); /* Gets a function address from a signature. @@ -261,14 +261,14 @@ namespace HyprlandAPI { returns: true on success. False otherwise. */ - APICALL bool addWindowDecoration(HANDLE handle, PHLWINDOW pWindow, UP pDecoration); + APICALL [[nodiscard]] bool addWindowDecoration(HANDLE handle, PHLWINDOW pWindow, UP pDecoration); /* Removes a window decoration returns: true on success. False otherwise. */ - APICALL bool removeWindowDecoration(HANDLE handle, IHyprWindowDecoration* pDecoration); + APICALL [[nodiscard]] bool removeWindowDecoration(HANDLE handle, IHyprWindowDecoration* pDecoration); /* Adds a keybind dispatcher. @@ -284,14 +284,14 @@ namespace HyprlandAPI { returns: true on success. False otherwise. */ - APICALL bool addDispatcherV2(HANDLE handle, const std::string& name, std::function handler); + APICALL [[nodiscard]] bool addDispatcherV2(HANDLE handle, const std::string& name, std::function handler); /* Removes a keybind dispatcher. returns: true on success. False otherwise. */ - APICALL bool removeDispatcher(HANDLE handle, const std::string& name); + APICALL [[nodiscard]] bool removeDispatcher(HANDLE handle, const std::string& name); /* Adds a notification. @@ -306,7 +306,7 @@ namespace HyprlandAPI { returns: true on success. False otherwise. */ - APICALL bool addNotificationV2(HANDLE handle, const std::unordered_map& data); + APICALL [[nodiscard]] bool addNotificationV2(HANDLE handle, const std::unordered_map& data); /* Returns a vector of found functions matching the provided name. @@ -315,27 +315,27 @@ namespace HyprlandAPI { Empty means either none found or handle was invalid */ - APICALL std::vector findFunctionsByName(HANDLE handle, const std::string& name); + APICALL [[nodiscard]] std::vector findFunctionsByName(HANDLE handle, const std::string& name); /* Returns the hyprland version data. It's highly advised to not run plugins compiled for a different hash. */ - APICALL SVersionInfo getHyprlandVersion(HANDLE handle); + APICALL [[nodiscard]] SVersionInfo getHyprlandVersion(HANDLE handle); /* Registers a hyprctl command returns: Pointer. Nullptr on fail. */ - APICALL SP registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd); + APICALL [[nodiscard]] SP registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd); /* Unregisters a hyprctl command returns: true on success. False otherwise. */ - APICALL bool unregisterHyprCtlCommand(HANDLE handle, SP cmd); + APICALL [[nodiscard]] bool unregisterHyprCtlCommand(HANDLE handle, SP cmd); /* Add a new config value. Keep the pointer, you can use it for retrieving the value. diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp index 4921f0d6d..447df8844 100644 --- a/src/plugins/PluginSystem.hpp +++ b/src/plugins/PluginSystem.hpp @@ -36,17 +36,17 @@ class CPluginSystem { public: CPluginSystem(); - SP> loadPlugin(const std::string& path, eSpecialPidTypes pidType = SPECIAL_PID_TYPE_NONE); - void unloadPlugin(const CPlugin* plugin, bool eject = false); - void unloadAllPlugins(); - void updateConfigPlugins(const std::vector& plugins, bool& changed); - CPlugin* getPluginByPath(const std::string& path); - CPlugin* getPluginByHandle(HANDLE handle); - std::vector getAllPlugins(); - size_t pluginCount(); - void sigGetPlugins(CPlugin** data, size_t len); + SP> loadPlugin(const std::string& path, eSpecialPidTypes pidType = SPECIAL_PID_TYPE_NONE); + void unloadPlugin(const CPlugin* plugin, bool eject = false); + void unloadAllPlugins(); + void updateConfigPlugins(const std::vector& plugins, bool& changed); + [[nodiscard]] CPlugin* getPluginByPath(const std::string& path); + [[nodiscard]] CPlugin* getPluginByHandle(HANDLE handle); + [[nodiscard]] std::vector getAllPlugins(); + [[nodiscard]] size_t pluginCount(); + void sigGetPlugins(CPlugin** data, size_t len); - bool m_allowConfigVars = false; + bool m_allowConfigVars = false; private: std::vector> m_loadedPlugins;