hyprland-plugins/borders-plus-plus/main.cpp

78 lines
3.1 KiB
C++
Raw Normal View History

2023-02-27 15:24:28 +00:00
#define WLR_USE_UNSTABLE
#include <unistd.h>
#include <any>
2026-05-12 13:21:43 +01:00
#include <array>
#include <hyprland/src/Compositor.hpp>
2025-12-08 15:22:46 +00:00
#include <hyprland/src/desktop/view/Window.hpp>
#include <hyprland/src/config/ConfigManager.hpp>
#include <hyprland/src/render/Renderer.hpp>
2026-02-23 16:57:22 +00:00
#include <hyprland/src/event/EventBus.hpp>
2023-02-27 15:24:28 +00:00
#include "borderDeco.hpp"
#include "globals.hpp"
// Do NOT change this function.
2023-02-28 12:06:21 +00:00
APICALL EXPORT std::string PLUGIN_API_VERSION() {
return HYPRLAND_API_VERSION;
}
2023-02-27 15:24:28 +00:00
2026-02-23 16:57:22 +00:00
static void onNewWindow(PHLWINDOW window) {
HyprlandAPI::addWindowDecoration(PHANDLE, window, makeUnique<CBordersPlusPlus>(window));
2023-02-27 15:24:28 +00:00
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
2025-10-23 20:54:45 +01:00
const std::string HASH = __hyprland_api_get_hash();
const std::string CLIENT_HASH = __hyprland_api_get_client_hash();
2023-10-19 14:12:55 +01:00
2025-10-23 20:54:45 +01:00
if (HASH != CLIENT_HASH) {
2023-10-19 14:12:55 +01:00
HyprlandAPI::addNotification(PHANDLE, "[borders-plus-plus] Failure in initialization: Version mismatch (headers ver is not equal to running hyprland ver)",
2024-12-04 09:58:09 -05:00
CHyprColor{1.0, 0.2, 0.2, 1.0}, 5000);
2023-10-19 14:12:55 +01:00
throw std::runtime_error("[bpp] Version mismatch");
}
2026-05-12 13:21:43 +01:00
vars.addBorders =
makeShared<Config::Values::CIntValue>("plugin:borders-plus-plus:add_borders", "How many extra borders to draw", 1, Config::Values::SIntValueOptions{.min = 0, .max = 9});
vars.naturalRounding = makeShared<Config::Values::CBoolValue>("plugin:borders-plus-plus:natural_rounding", "Use the window's original rounding", true);
HyprlandAPI::addConfigValueV2(PHANDLE, vars.addBorders);
HyprlandAPI::addConfigValueV2(PHANDLE, vars.naturalRounding);
static std::array<std::string, 9> borderColorNames;
static std::array<std::string, 9> borderSizeNames;
for (size_t i = 0; i < 9; ++i) {
2026-05-12 13:21:43 +01:00
borderColorNames[i] = "plugin:borders-plus-plus:col.border_" + std::to_string(i + 1);
borderSizeNames[i] = "plugin:borders-plus-plus:border_size_" + std::to_string(i + 1);
vars.borderColors[i] = makeShared<Config::Values::CColorValue>(borderColorNames[i].c_str(), "Color of the extra border", 0xee000000);
vars.borderSizes[i] = makeShared<Config::Values::CIntValue>(borderSizeNames[i].c_str(), "Size of the extra border", -1);
HyprlandAPI::addConfigValueV2(PHANDLE, vars.borderColors[i]);
HyprlandAPI::addConfigValueV2(PHANDLE, vars.borderSizes[i]);
}
2023-02-27 15:24:28 +00:00
2023-11-11 14:39:46 +00:00
HyprlandAPI::reloadConfig();
2026-02-23 16:57:22 +00:00
static auto P = Event::bus()->m_events.window.open.listen([&](PHLWINDOW w) { onNewWindow(w); });
2023-02-27 15:24:28 +00:00
// add deco to existing windows
for (auto& w : g_pCompositor->m_windows) {
2025-04-29 14:21:14 +01:00
if (w->isHidden() || !w->m_isMapped)
2023-02-27 15:24:28 +00:00
continue;
2025-01-24 01:30:43 +00:00
HyprlandAPI::addWindowDecoration(PHANDLE, w, makeUnique<CBordersPlusPlus>(w));
2023-02-27 15:24:28 +00:00
}
2024-12-04 09:58:09 -05:00
HyprlandAPI::addNotification(PHANDLE, "[borders-plus-plus] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);
2023-02-27 15:24:28 +00:00
2023-02-28 12:06:21 +00:00
return {"borders-plus-plus", "A plugin to add more borders to windows.", "Vaxry", "1.0"};
2023-02-27 15:24:28 +00:00
}
2023-02-28 12:06:21 +00:00
APICALL EXPORT void PLUGIN_EXIT() {
g_pHyprRenderer->m_renderPass.removeAllOfType("CBorderPPPassElement");
}