From 34da16b7e626be4d96c3098b5265e2c008fb2d65 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:23:25 +0000 Subject: plugin api: add addNotificationV2 Allows for issuing fancy notifs via api --- src/plugins/PluginAPI.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/plugins/PluginAPI.cpp') diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 8c816546..c878516b 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -193,3 +193,51 @@ APICALL bool HyprlandAPI::removeDispatcher(HANDLE handle, const std::string& nam return true; } + +APICALL bool addNotificationV2(HANDLE handle, const std::unordered_map& data) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return false; + + try { + auto iterator = data.find("text"); + if (iterator == data.end()) + return false; + + // mandatory + std::string text; + try { + text = std::any_cast(iterator->second); + } catch (std::exception& e) { + // attempt const char* + text = std::any_cast(iterator->second); + } + + iterator = data.find("time"); + if (iterator == data.end()) + return false; + + const auto TIME = std::any_cast(iterator->second); + + iterator = data.find("color"); + if (iterator == data.end()) + return false; + + const auto COLOR = std::any_cast(iterator->second); + + // optional + eIcons icon = ICON_NONE; + iterator = data.find("icon"); + if (iterator != data.end()) + icon = std::any_cast(iterator->second); + + g_pHyprNotificationOverlay->addNotification(text, COLOR, TIME, icon); + + } catch (std::exception& e) { + // bad any_cast most likely, plugin error + return false; + } + + return true; +} \ No newline at end of file -- cgit v1.2.3