From bd3ea8dcb5f7803b0cc05e25f84200102c0fad21 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Tue, 2 Jan 2024 14:25:18 +0100 Subject: [PATCH] examples: remove example plugin closes #4329 --- example/examplePlugin/Makefile | 8 -- example/examplePlugin/customDecoration.cpp | 74 ---------------- example/examplePlugin/customDecoration.hpp | 29 ------- example/examplePlugin/customLayout.cpp | 80 ----------------- example/examplePlugin/customLayout.hpp | 32 ------- example/examplePlugin/globals.hpp | 5 -- example/examplePlugin/main.cpp | 99 ---------------------- 7 files changed, 327 deletions(-) delete mode 100644 example/examplePlugin/Makefile delete mode 100644 example/examplePlugin/customDecoration.cpp delete mode 100644 example/examplePlugin/customDecoration.hpp delete mode 100644 example/examplePlugin/customLayout.cpp delete mode 100644 example/examplePlugin/customLayout.hpp delete mode 100644 example/examplePlugin/globals.hpp delete mode 100644 example/examplePlugin/main.cpp diff --git a/example/examplePlugin/Makefile b/example/examplePlugin/Makefile deleted file mode 100644 index bb79532a..00000000 --- a/example/examplePlugin/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# compile with HYPRLAND_HEADERS= make all -# make sure that the path above is to the root hl repo directory, NOT src/ -# and that you have ran `make protocols` in the hl dir. - -all: - $(CXX) -shared -fPIC --no-gnu-unique main.cpp customLayout.cpp customDecoration.cpp -o examplePlugin.so -g `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++2b -clean: - rm ./examplePlugin.so diff --git a/example/examplePlugin/customDecoration.cpp b/example/examplePlugin/customDecoration.cpp deleted file mode 100644 index e2b5d136..00000000 --- a/example/examplePlugin/customDecoration.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "customDecoration.hpp" -#include -#include -#include "globals.hpp" - -CCustomDecoration::CCustomDecoration(CWindow* pWindow) { - m_pWindow = pWindow; - m_vLastWindowPos = pWindow->m_vRealPosition.vec(); - m_vLastWindowSize = pWindow->m_vRealSize.vec(); -} - -CCustomDecoration::~CCustomDecoration() { - damageEntire(); -} - -SWindowDecorationExtents CCustomDecoration::getWindowDecorationExtents() { - return m_seExtents; -} - -void CCustomDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) { - if (!g_pCompositor->windowValidMapped(m_pWindow)) - return; - - if (!m_pWindow->m_sSpecialRenderData.decorate) - return; - - static auto* const PCOLOR = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:example:border_color")->intValue; - static auto* const PROUNDING = &HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue; - static auto* const PBORDERSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue; - - const auto ROUNDING = !m_pWindow->m_sSpecialRenderData.rounding ? - 0 : - (m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying() == -1 ? *PROUNDING : m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying()); - - // draw the border - CBox fullBox = {(int)(m_vLastWindowPos.x - *PBORDERSIZE), (int)(m_vLastWindowPos.y - *PBORDERSIZE), (int)(m_vLastWindowSize.x + 2.0 * *PBORDERSIZE), - (int)(m_vLastWindowSize.y + 2.0 * *PBORDERSIZE)}; - - fullBox.x -= pMonitor->vecPosition.x; - fullBox.y -= pMonitor->vecPosition.y; - - m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2}, - {fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2, - fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}}; - - fullBox.x += offset.x; - fullBox.y += offset.y; - - if (fullBox.width < 1 || fullBox.height < 1) - return; // don't draw invisible shadows - - g_pHyprOpenGL->scissor((CBox*)nullptr); - - fullBox.scale(pMonitor->scale); - g_pHyprOpenGL->renderBorder(&fullBox, CColor(*PCOLOR), *PROUNDING * pMonitor->scale + *PBORDERSIZE * 2, a); -} - -eDecorationType CCustomDecoration::getDecorationType() { - return DECORATION_CUSTOM; -} - -void CCustomDecoration::updateWindow(CWindow* pWindow) { - - m_vLastWindowPos = pWindow->m_vRealPosition.vec(); - m_vLastWindowSize = pWindow->m_vRealSize.vec(); - - damageEntire(); -} - -void CCustomDecoration::damageEntire() { - CBox dm = {(int)(m_vLastWindowPos.x - m_seExtents.topLeft.x), (int)(m_vLastWindowPos.y - m_seExtents.topLeft.y), - (int)(m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x), (int)m_seExtents.topLeft.y}; - g_pHyprRenderer->damageBox(&dm); -} \ No newline at end of file diff --git a/example/examplePlugin/customDecoration.hpp b/example/examplePlugin/customDecoration.hpp deleted file mode 100644 index dbb0c0e2..00000000 --- a/example/examplePlugin/customDecoration.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#define WLR_USE_UNSTABLE - -#include - -class CCustomDecoration : public IHyprWindowDecoration { - public: - CCustomDecoration(CWindow*); - virtual ~CCustomDecoration(); - - virtual SWindowDecorationExtents getWindowDecorationExtents(); - - virtual void draw(CMonitor*, float a, const Vector2D& offset); - - virtual eDecorationType getDecorationType(); - - virtual void updateWindow(CWindow*); - - virtual void damageEntire(); - - private: - SWindowDecorationExtents m_seExtents; - - CWindow* m_pWindow = nullptr; - - Vector2D m_vLastWindowPos; - Vector2D m_vLastWindowSize; -}; \ No newline at end of file diff --git a/example/examplePlugin/customLayout.cpp b/example/examplePlugin/customLayout.cpp deleted file mode 100644 index 8001c72d..00000000 --- a/example/examplePlugin/customLayout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "customLayout.hpp" -#include -#include "globals.hpp" - -void CHyprCustomLayout::onWindowCreatedTiling(CWindow* pWindow) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto SIZE = PMONITOR->vecSize; - - // these are used for focus and move calculations, and are *required* to touch for moving focus to work properly. - pWindow->m_vPosition = Vector2D{(SIZE.x / 2.0) * (m_vWindowData.size() % 2), (SIZE.y / 2.0) * (int)(m_vWindowData.size() > 1)}; - pWindow->m_vSize = SIZE / 2.0; - - // this is the actual pos and size of the window (where it's rendered) - pWindow->m_vRealPosition = pWindow->m_vPosition + Vector2D{10, 10}; - pWindow->m_vRealSize = pWindow->m_vSize - Vector2D{20, 20}; - - const auto PDATA = &m_vWindowData.emplace_back(); - PDATA->pWindow = pWindow; -} - -void CHyprCustomLayout::onWindowRemovedTiling(CWindow* pWindow) { - std::erase_if(m_vWindowData, [&](const auto& other) { return other.pWindow == pWindow; }); -} - -bool CHyprCustomLayout::isWindowTiled(CWindow* pWindow) { - return std::find_if(m_vWindowData.begin(), m_vWindowData.end(), [&](const auto& other) { return other.pWindow == pWindow; }) != m_vWindowData.end(); -} - -void CHyprCustomLayout::recalculateMonitor(const int& eIdleInhibitMode) { - ; // empty -} - -void CHyprCustomLayout::recalculateWindow(CWindow* pWindow) { - ; // empty -} - -void CHyprCustomLayout::resizeActiveWindow(const Vector2D& delta, CWindow* pWindow) { - ; // empty -} - -void CHyprCustomLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreenMode mode, bool on) { - ; // empty -} - -std::any CHyprCustomLayout::layoutMessage(SLayoutMessageHeader header, std::string content) { - return ""; -} - -SWindowRenderLayoutHints CHyprCustomLayout::requestRenderHints(CWindow* pWindow) { - return {}; -} - -void CHyprCustomLayout::switchWindows(CWindow* pWindowA, CWindow* pWindowB) { - ; // empty -} - -void CHyprCustomLayout::alterSplitRatio(CWindow* pWindow, float delta, bool exact) { - ; // empty -} - -std::string CHyprCustomLayout::getLayoutName() { - return "custom"; -} - -void CHyprCustomLayout::replaceWindowDataWith(CWindow* from, CWindow* to) { - ; // empty -} - -void CHyprCustomLayout::onEnable() { - for (auto& w : g_pCompositor->m_vWindows) { - if (w->isHidden() || !w->m_bIsMapped || w->m_bFadingOut || w->m_bIsFloating) - continue; - - onWindowCreatedTiling(w.get()); - } -} - -void CHyprCustomLayout::onDisable() { - m_vWindowData.clear(); -} \ No newline at end of file diff --git a/example/examplePlugin/customLayout.hpp b/example/examplePlugin/customLayout.hpp deleted file mode 100644 index 44797ccc..00000000 --- a/example/examplePlugin/customLayout.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#define WLR_USE_UNSTABLE - -#include - -struct SWindowData { - CWindow* pWindow = nullptr; -}; - -class CHyprCustomLayout : public IHyprLayout { - public: - virtual void onWindowCreatedTiling(CWindow*); - virtual void onWindowRemovedTiling(CWindow*); - virtual bool isWindowTiled(CWindow*); - virtual void recalculateMonitor(const int&); - virtual void recalculateWindow(CWindow*); - virtual void resizeActiveWindow(const Vector2D&, CWindow* pWindow = nullptr); - virtual void fullscreenRequestForWindow(CWindow*, eFullscreenMode, bool); - virtual std::any layoutMessage(SLayoutMessageHeader, std::string); - virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); - virtual void switchWindows(CWindow*, CWindow*); - virtual void alterSplitRatio(CWindow*, float, bool); - virtual std::string getLayoutName(); - virtual void replaceWindowDataWith(CWindow* from, CWindow* to); - - virtual void onEnable(); - virtual void onDisable(); - - private: - std::vector m_vWindowData; -}; \ No newline at end of file diff --git a/example/examplePlugin/globals.hpp b/example/examplePlugin/globals.hpp deleted file mode 100644 index 22574754..00000000 --- a/example/examplePlugin/globals.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -inline HANDLE PHANDLE = nullptr; \ No newline at end of file diff --git a/example/examplePlugin/main.cpp b/example/examplePlugin/main.cpp deleted file mode 100644 index f2cd1075..00000000 --- a/example/examplePlugin/main.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#define WLR_USE_UNSTABLE - -#include "globals.hpp" - -#include -#include -#include "customLayout.hpp" -#include "customDecoration.hpp" - -#include -#include - -// Methods -inline std::unique_ptr g_pCustomLayout; -inline CFunctionHook* g_pFocusHook = nullptr; -inline CFunctionHook* g_pMotionHook = nullptr; -inline CFunctionHook* g_pMouseDownHook = nullptr; -typedef void (*origFocusWindow)(void*, CWindow*, wlr_surface*); -typedef void (*origMotion)(wlr_seat*, uint32_t, double, double); -typedef void (*origMouseDownNormal)(void*, wlr_pointer_button_event*); - -// Do NOT change this function. -APICALL EXPORT std::string PLUGIN_API_VERSION() { - return HYPRLAND_API_VERSION; -} - -static void onActiveWindowChange(void* self, std::any data) { - try { - auto* const PWINDOW = std::any_cast(data); - - HyprlandAPI::addNotification(PHANDLE, "[ExamplePlugin] Active window: " + (PWINDOW ? PWINDOW->m_szTitle : "None"), CColor{0.f, 0.5f, 1.f, 1.f}, 5000); - } catch (std::bad_any_cast& e) { HyprlandAPI::addNotification(PHANDLE, "[ExamplePlugin] Active window: None", CColor{0.f, 0.5f, 1.f, 1.f}, 5000); } -} - -static void onNewWindow(void* self, std::any data) { - auto* const PWINDOW = std::any_cast(data); - - HyprlandAPI::addWindowDecoration(PHANDLE, PWINDOW, new CCustomDecoration(PWINDOW)); -} - -void hkFocusWindow(void* thisptr, CWindow* pWindow, wlr_surface* pSurface) { - // HyprlandAPI::addNotification(PHANDLE, getFormat("FocusWindow with %lx %lx", pWindow, pSurface), CColor{0.f, 1.f, 1.f, 1.f}, 5000); - (*(origFocusWindow)g_pFocusHook->m_pOriginal)(thisptr, pWindow, pSurface); -} - -void hkNotifyMotion(wlr_seat* wlr_seat, uint32_t time_msec, double sx, double sy) { - // HyprlandAPI::addNotification(PHANDLE, getFormat("NotifyMotion with %lf %lf", sx, sy), CColor{0.f, 1.f, 1.f, 1.f}, 5000); - (*(origMotion)g_pMotionHook->m_pOriginal)(wlr_seat, time_msec, sx, sy); -} - -void hkProcessMouseDownNormal(void* thisptr, wlr_pointer_button_event* e) { - // HyprlandAPI::addNotification(PHANDLE, "Mouse down normal!", CColor{0.8f, 0.2f, 0.5f, 1.0f}, 5000); - (*(origMouseDownNormal)g_pMouseDownHook->m_pOriginal)(thisptr, e); -} - -APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { - PHANDLE = handle; - - HyprlandAPI::addNotification(PHANDLE, "Hello World from an example plugin!", CColor{0.f, 1.f, 1.f, 1.f}, 5000); - - HyprlandAPI::registerCallbackDynamic(PHANDLE, "activeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onActiveWindowChange(self, data); }); - HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); - - g_pCustomLayout = std::make_unique(); - - HyprlandAPI::addLayout(PHANDLE, "custom", g_pCustomLayout.get()); - - HyprlandAPI::addConfigValue(PHANDLE, "plugin:example:border_color", SConfigValue{.intValue = configStringToInt("rgb(44ee44)")}); - - HyprlandAPI::addDispatcher(PHANDLE, "example", [](std::string arg) { HyprlandAPI::addNotification(PHANDLE, "Arg passed: " + arg, CColor{0.5f, 0.5f, 0.7f, 1.0f}, 5000); }); - - // Hook a public member - g_pFocusHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CCompositor::focusWindow, (void*)&hkFocusWindow); - // Hook a public non-member - g_pMotionHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_seat_pointer_notify_motion, (void*)&hkNotifyMotion); - // Hook a private member - static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "processMouseDownNormal"); - g_pMouseDownHook = HyprlandAPI::createFunctionHook(PHANDLE, METHODS[0].address, (void*)&hkProcessMouseDownNormal); - - static auto* const PBORDERCOLOR = HyprlandAPI::getConfigValue(PHANDLE, "plugin:example:border_color"); - - // fancy notifications - HyprlandAPI::addNotificationV2( - PHANDLE, - {{"text", "Example hint, color " + std::to_string(PBORDERCOLOR->intValue)}, {"time", (uint64_t)10000}, {"color", CColor{PBORDERCOLOR->intValue}}, {"icon", ICON_HINT}}); - - // Enable our hooks - g_pFocusHook->hook(); - g_pMotionHook->hook(); - g_pMouseDownHook->hook(); - - HyprlandAPI::reloadConfig(); - - return {"ExamplePlugin", "An example plugin", "Vaxry", "1.0"}; -} - -APICALL EXPORT void PLUGIN_EXIT() { - HyprlandAPI::invokeHyprctlCommand("seterror", "disable"); -} \ No newline at end of file