From 9e735ad2f5c1c7e29a2f27e2be2a1daa5bf8cc8c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 19 Mar 2022 16:13:19 +0100 Subject: [PATCH] added borders --- example/hyprland.conf | 2 ++ src/config/ConfigManager.cpp | 4 +++- src/defines.hpp | 7 ++++++- src/render/Renderer.cpp | 33 +++++++++++++++++++++++++++++++++ src/render/Renderer.hpp | 2 ++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index 46bc1a1b..eb5d19f0 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -10,4 +10,6 @@ general { gaps_in=5 gaps_out=20 border_size=1 + col.active_border=0x66ee1111 + col.inactive_border=0x66333333 } \ No newline at end of file diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4cd9c007..f48f1dcd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -15,6 +15,8 @@ CConfigManager::CConfigManager() { configValues["general:border_size"].intValue = 1; configValues["general:gaps_in"].intValue = 5; configValues["general:gaps_out"].intValue = 20; + configValues["general:col.active_border"].intValue = 0xffffffff; + configValues["general:col.inactive_border"].intValue = 0xff444444; } void CConfigManager::init() { @@ -216,7 +218,7 @@ void CConfigManager::loadConfigLoadVars() { void CConfigManager::tick() { const char* const ENVHOME = getenv("HOME"); - const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprd.conf" : (std::string) "/.config/hypr/hypr.conf"); + const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); struct stat fileStat; int err = stat(CONFIGPATH.c_str(), &fileStat); diff --git a/src/defines.hpp b/src/defines.hpp index 9c3856aa..d048c658 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -15,4 +15,9 @@ #define interface class -#define STICKS(a, b) abs((a) - (b)) < 2 \ No newline at end of file +#define STICKS(a, b) abs((a) - (b)) < 2 + +#define ALPHA(c) ((double)(((c) >> 24) & 0xff) / 255.0) +#define RED(c) ((double)(((c) >> 16) & 0xff) / 255.0) +#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0) +#define BLUE(c) ((double)(((c)) & 0xff) / 255.0) \ No newline at end of file diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index aeb19008..96276c76 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -59,6 +59,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) { continue; // render the bad boy + + // border + drawBorderForWindow(&w, PMONITOR); + wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, PMONITOR->output, &w.m_vRealPosition.x, &w.m_vRealPosition.y); SRenderData renderdata = {PMONITOR->output, time, w.m_vRealPosition.x, w.m_vRealPosition.y}; @@ -81,6 +85,10 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) { continue; // render the bad boy + + // border + drawBorderForWindow(&w, PMONITOR); + wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, PMONITOR->output, &w.m_vRealPosition.x, &w.m_vRealPosition.y); SRenderData renderdata = {PMONITOR->output, time, w.m_vRealPosition.x, w.m_vRealPosition.y}; @@ -205,4 +213,29 @@ void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) { for (auto& la : PMONITOR->m_aLayerSurfaceLists) arrangeLayerArray(PMONITOR, la); +} + +void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) { + const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); + const auto BORDERCOL = pWindow == g_pCompositor->m_pLastFocus ? g_pConfigManager->getInt("general:col.active_border") : g_pConfigManager->getInt("general:col.inactive_border"); + + const float BORDERWLRCOL[4] = {RED(BORDERCOL), GREEN(BORDERCOL), BLUE(BORDERCOL), ALPHA(BORDERCOL)}; + + // top + wlr_box border = {pWindow->m_vRealPosition.x - BORDERSIZE, pWindow->m_vRealPosition.y - BORDERSIZE, pWindow->m_vRealSize.x + 2 * BORDERSIZE, BORDERSIZE }; + wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); + + // bottom + border.y = pWindow->m_vRealPosition.y + pWindow->m_vRealSize.y; + wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); + + // left + border.y = pWindow->m_vRealPosition.y; + border.width = BORDERSIZE; + border.height = pWindow->m_vRealSize.y; + wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); + + // right + border.x = pWindow->m_vRealPosition.x + pWindow->m_vRealSize.x; + wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); } \ No newline at end of file diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 21a32975..b6172ce8 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -3,6 +3,7 @@ #include "../defines.hpp" #include #include "../helpers/Monitor.hpp" +#include "../Window.hpp" class CHyprRenderer { public: @@ -13,6 +14,7 @@ public: private: void arrangeLayerArray(SMonitor*, const std::list&); + void drawBorderForWindow(CWindow*, SMonitor*); }; inline std::unique_ptr g_pHyprRenderer;