hyprbars: remove deco on unmap

fixes #71
This commit is contained in:
Vaxry 2024-03-21 18:58:10 +00:00
parent 4a92466e3b
commit adec334acf
3 changed files with 22 additions and 2 deletions

View File

@ -518,4 +518,8 @@ CBox CHyprBar::assignedBoxGlobal() {
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
return box.translate(WORKSPACEOFFSET);
}
}
CWindow* CHyprBar::getOwner() {
return m_pWindow;
}

View File

@ -31,6 +31,8 @@ class CHyprBar : public IHyprWindowDecoration {
virtual std::string getDisplayName();
CWindow* getOwner();
private:
SWindowDecorationExtents m_seExtents;

View File

@ -15,7 +15,7 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
return HYPRLAND_API_VERSION;
}
void onNewWindow(void* self, std::any data) {
static void onNewWindow(void* self, std::any data) {
// data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data);
@ -26,6 +26,19 @@ void onNewWindow(void* self, std::any data) {
}
}
static void onCloseWindow(void* self, std::any data) {
// data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data);
const auto BARIT = std::find_if(g_pGlobalState->bars.begin(), g_pGlobalState->bars.end(), [PWINDOW](const auto& bar) { return bar->getOwner() == PWINDOW; });
if (BARIT == g_pGlobalState->bars.end())
return;
// we could use the API but this is faster + it doesn't matter here that much.
PWINDOW->removeWindowDeco(*BARIT);
}
void onPreConfigReload() {
g_pGlobalState->buttons.clear();
}
@ -74,6 +87,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
g_pGlobalState = std::make_unique<SGlobalState>();
HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(self, data); });
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_color", Hyprlang::INT{configStringToInt("rgba(33333388)")});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_height", Hyprlang::INT{15});