From 5f65946c84ed6ba3703e865d9a70f98cbb1ae479 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:38:16 +0000 Subject: [PATCH] hyprctl: add decorations (#4275) * add hyprctl decorations modified: hyprctl/main.cpp modified: src/debug/HyprCtl.cpp modified: src/render/decorations/CHyprBorderDecoration.cpp modified: src/render/decorations/CHyprBorderDecoration.hpp modified: src/render/decorations/CHyprDropShadowDecoration.cpp modified: src/render/decorations/CHyprDropShadowDecoration.hpp modified: src/render/decorations/CHyprGroupBarDecoration.cpp modified: src/render/decorations/CHyprGroupBarDecoration.hpp modified: src/render/decorations/IHyprWindowDecoration.cpp modified: src/render/decorations/IHyprWindowDecoration.hpp * fixes modified: hyprctl/main.cpp modified: src/render/decorations/IHyprWindowDecoration.cpp --- hyprctl/main.cpp | 3 ++ src/debug/HyprCtl.cpp | 28 +++++++++++++++++++ .../decorations/CHyprBorderDecoration.cpp | 6 +++- .../decorations/CHyprBorderDecoration.hpp | 4 ++- .../decorations/CHyprDropShadowDecoration.cpp | 4 +++ .../decorations/CHyprDropShadowDecoration.hpp | 4 ++- .../decorations/CHyprGroupBarDecoration.cpp | 4 +++ .../decorations/CHyprGroupBarDecoration.hpp | 2 ++ .../decorations/IHyprWindowDecoration.cpp | 6 +++- .../decorations/IHyprWindowDecoration.hpp | 2 ++ 10 files changed, 59 insertions(+), 4 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 2f0e08ed..7285f5b8 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -31,6 +31,7 @@ commands: binds clients cursorpos + decorations devices dispatch getoption @@ -423,6 +424,8 @@ int main(int argc, char** argv) { request(fullRequest, 1); else if (fullRequest.contains("/keyword")) request(fullRequest, 2); + else if (fullRequest.contains("/decorations")) + request(fullRequest, 1); else if (fullRequest.contains("/hyprpaper")) requestHyprpaper(fullRequest); else if (fullRequest.contains("/layouts")) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 11f293a5..72d3f6b5 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1174,6 +1174,32 @@ std::string dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat } } +std::string decorationRequest(std::string request, HyprCtl::eHyprCtlOutputFormat format) { + CVarList vars(request, 0, ' '); + const auto PWINDOW = g_pCompositor->getWindowByRegex(vars[1]); + + if (!PWINDOW) + return "none"; + + std::string result = ""; + if (format == HyprCtl::FORMAT_JSON) { + result += "["; + for (auto& wd : PWINDOW->m_dWindowDecorations) { + result += "{\n\"decorationName\": \"" + wd->getDisplayName() + "\",\n\"priority\": " + std::to_string(wd->getPositioningInfo().priority) + "\n},"; + } + + trimTrailingComma(result); + result += "]"; + } else { + result = +"Decoration\tPriority\n"; + for (auto& wd : PWINDOW->m_dWindowDecorations) { + result += wd->getDisplayName() + "\t" + std::to_string(wd->getPositioningInfo().priority) + "\n"; + } + } + + return result; +} + void createOutputIter(wlr_backend* backend, void* data) { const auto DATA = (std::pair*)data; @@ -1415,6 +1441,8 @@ std::string getReply(std::string request) { return dispatchSetCursor(request); else if (request.starts_with("getoption")) return dispatchGetOption(request, format); + else if (request.starts_with("decorations")) + return decorationRequest(request, format); else if (request.starts_with("[[BATCH]]")) return dispatchBatch(request); diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 62e3ba7f..4e3e824e 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -99,6 +99,10 @@ uint64_t CHyprBorderDecoration::getDecorationFlags() { return *PPARTOFWINDOW && !doesntWantBorders() ? DECORATION_PART_OF_MAIN_WINDOW : 0; } +std::string CHyprBorderDecoration::getDisplayName() { + return "Border"; +} + bool CHyprBorderDecoration::doesntWantBorders() { return !m_pWindow->m_sSpecialRenderData.border || m_pWindow->m_bX11DoesntWantBorders; -} \ No newline at end of file +} diff --git a/src/render/decorations/CHyprBorderDecoration.hpp b/src/render/decorations/CHyprBorderDecoration.hpp index 770d1291..9c0bcc33 100644 --- a/src/render/decorations/CHyprBorderDecoration.hpp +++ b/src/render/decorations/CHyprBorderDecoration.hpp @@ -23,6 +23,8 @@ class CHyprBorderDecoration : public IHyprWindowDecoration { virtual uint64_t getDecorationFlags(); + virtual std::string getDisplayName(); + private: SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seReportedExtents; @@ -36,4 +38,4 @@ class CHyprBorderDecoration : public IHyprWindowDecoration { CBox assignedBoxGlobal(); bool doesntWantBorders(); -}; \ No newline at end of file +}; diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index af4ece0b..0e5e9d94 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -30,6 +30,10 @@ uint64_t CHyprDropShadowDecoration::getDecorationFlags() { return DECORATION_NON_SOLID; } +std::string CHyprDropShadowDecoration::getDisplayName() { + return "Drop Shadow"; +} + void CHyprDropShadowDecoration::damageEntire() { static auto* const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp index 7820a76c..3b389550 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.hpp +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -23,6 +23,8 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration { virtual uint64_t getDecorationFlags(); + virtual std::string getDisplayName(); + private: SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seReportedExtents; @@ -34,4 +36,4 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration { CBox m_bLastWindowBox = {0}; CBox m_bLastWindowBoxWithDecos = {0}; -}; \ No newline at end of file +}; diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 06e84abb..3bc819bf 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -414,6 +414,10 @@ uint64_t CHyprGroupBarDecoration::getDecorationFlags() { return DECORATION_ALLOWS_MOUSE_INPUT; } +std::string CHyprGroupBarDecoration::getDisplayName() { + return "GroupBar"; +} + CBox CHyprGroupBarDecoration::assignedBoxGlobal() { CBox box = m_bAssignedBox; box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow)); diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp index 78edbeae..a0242e2f 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.hpp +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -45,6 +45,8 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration { virtual uint64_t getDecorationFlags(); + virtual std::string getDisplayName(); + private: SWindowDecorationExtents m_seExtents; diff --git a/src/render/decorations/IHyprWindowDecoration.cpp b/src/render/decorations/IHyprWindowDecoration.cpp index 7a4906b5..24acdc47 100644 --- a/src/render/decorations/IHyprWindowDecoration.cpp +++ b/src/render/decorations/IHyprWindowDecoration.cpp @@ -26,4 +26,8 @@ eDecorationLayer IHyprWindowDecoration::getDecorationLayer() { uint64_t IHyprWindowDecoration::getDecorationFlags() { return 0; -} \ No newline at end of file +} + +std::string IHyprWindowDecoration::getDisplayName() { + return "Unknown Decoration"; +} diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index e0a34016..2203304b 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -56,6 +56,8 @@ class IHyprWindowDecoration { virtual uint64_t getDecorationFlags(); + virtual std::string getDisplayName(); + private: CWindow* m_pWindow = nullptr;