From 89f64215326539297f3e4e0d0957b4bfd5127995 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Dec 2021 00:00:38 +0100 Subject: [PATCH] fix the bar dying on config reload use no_tray_saving=1 in bar {} (defaults to 1) --- example/hypr.conf | 1 + src/bar/Bar.cpp | 18 ++++++++++++++---- src/bar/Bar.hpp | 3 ++- src/config/ConfigManager.cpp | 1 + src/events/events.cpp | 14 ++++++++------ src/windowManager.cpp | 6 ++++++ src/windowManager.hpp | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/example/hypr.conf b/example/hypr.conf index bd065b0..86db3f8 100644 --- a/example/hypr.conf +++ b/example/hypr.conf @@ -24,6 +24,7 @@ Bar { monitor=0 enabled=1 mod_pad_in=8 + no_tray_saving=1 # using this doesnt save the tray between reloads but fixes an issue with the bar disappearing. font.main=Noto Sans font.secondary=Noto Sans diff --git a/src/bar/Bar.cpp b/src/bar/Bar.cpp index af4e0ca..78a8776 100644 --- a/src/bar/Bar.cpp +++ b/src/bar/Bar.cpp @@ -165,7 +165,7 @@ void CStatusBar::setupTray() { values); xcb_atom_t dockAtom[] = {HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"]}; - xcb_ewmh_set_wm_window_type(g_pWindowManager->EWMHConnection, m_iWindowID, 1, dockAtom); + xcb_ewmh_set_wm_window_type(g_pWindowManager->EWMHConnection, trayWindowID, 1, dockAtom); const uint32_t ORIENTATION = 0; // Horizontal xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, trayWindowID, @@ -253,9 +253,9 @@ void CStatusBar::setupTray() { } void CStatusBar::fixTrayOnCreate() { - if (m_bHasTray) { + if (m_bHasTray && ConfigManager::getInt("bar:no_tray_saving") == 0) { for (auto& tray : g_pWindowManager->trayclients) { - xcb_reparent_window(g_pWindowManager->DisplayConnection, tray.window, g_pWindowManager->statusBar->getWindowID(), 0, 0); + xcb_reparent_window(g_pWindowManager->DisplayConnection, tray.window, g_pWindowManager->statusBar->trayWindowID, 0, 0); xcb_map_window(g_pWindowManager->DisplayConnection, tray.window); tray.hidden = false; } @@ -278,8 +278,14 @@ void CStatusBar::fixTrayOnCreate() { } void CStatusBar::saveTrayOnDestroy() { + + // TODO: fix this instead of disabling it. + + if (ConfigManager::getInt("bar:no_tray_saving") == 1) + return; + for (auto& tray : g_pWindowManager->trayclients) { - xcb_reparent_window(g_pWindowManager->DisplayConnection, tray.window, g_pWindowManager->Screen->root, -999, -999); + xcb_reparent_window(g_pWindowManager->DisplayConnection, tray.window, g_pWindowManager->Screen->root, 30000, 30000); } } @@ -301,6 +307,8 @@ void CStatusBar::setup(int MonitorID) { const auto MONITOR = g_pWindowManager->monitors[MonitorID]; + Debug::log(LOG, "Bar monitor found to be " + std::to_string(MONITOR.ID)); + m_iMonitorID = MonitorID; m_vecPosition = MONITOR.vecPosition; m_vecSize = Vector2D(MONITOR.vecSize.x, ConfigManager::getInt("bar:height")); @@ -331,6 +339,7 @@ void CStatusBar::setup(int MonitorID) { // map xcb_map_window(g_pWindowManager->DisplayConnection, m_iWindowID); + Debug::log(LOG, "Bar mapping!"); // Create a pixmap for writing to. m_iPixmap = xcb_generate_id(g_pWindowManager->DisplayConnection); @@ -356,6 +365,7 @@ void CStatusBar::setup(int MonitorID) { // fix tray fixTrayOnCreate(); + Debug::log(LOG, "Bar setup done!"); m_bIsDestroyed = false; } diff --git a/src/bar/Bar.hpp b/src/bar/Bar.hpp index ffdc205..647a862 100644 --- a/src/bar/Bar.hpp +++ b/src/bar/Bar.hpp @@ -63,6 +63,8 @@ public: std::vector modules; + xcb_window_t trayWindowID = 0; + private: // for not deleting nulls bool m_bIsDestroyed = true; @@ -92,7 +94,6 @@ private: void fixTrayOnCreate(); void saveTrayOnDestroy(); int drawTrayModule(SBarModule*, int); - xcb_window_t trayWindowID = 0; }; // Main thread for the bar. Is only initted once in main.cpp so we can do this. diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f34a05c..3f5caa8 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -31,6 +31,7 @@ void ConfigManager::init() { configValues["bar:font.main"].strValue = "Noto Sans"; configValues["bar:font.secondary"].strValue = "Noto Sans"; configValues["bar:mod_pad_in"].intValue = 4; + configValues["bar:no_tray_saving"].intValue = 1; configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time // Deprecated diff --git a/src/events/events.cpp b/src/events/events.cpp index d8e9d7b..2e33112 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -393,6 +393,12 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) { return nullptr; } + if (PWINDOWINARR->getClassName() == "Error") { + Debug::log(LOG, "Class error -> force float"); + return remapFloatingWindow(windowID, forcemonitor); + } + + PWINDOWINARR->setIsFloating(false); PWINDOWINARR->setDirty(true); @@ -568,10 +574,6 @@ void Events::eventMapWindow(xcb_generic_event_t* event) { // Map the window xcb_map_window(g_pWindowManager->DisplayConnection, E->window); - // make sure it's not the bar! - if (E->window == g_pWindowManager->barWindowID) - return; - // Check if it's not unmapped if (g_pWindowManager->isWindowUnmapped(E->window)) { g_pWindowManager->moveWindowToMapped(E->window); @@ -782,7 +784,7 @@ void Events::eventClientMessage(xcb_generic_event_t* event) { free(XEMBEDREPLY); - xcb_reparent_window(g_pWindowManager->DisplayConnection, CLIENT, g_pWindowManager->statusBar->getWindowID(), 0, 0); + xcb_reparent_window(g_pWindowManager->DisplayConnection, CLIENT, g_pWindowManager->statusBar->trayWindowID, 0, 0); // icon sizes are barY - 2 - pad: 1 values[0] = ConfigManager::getInt("bar:height") - 2 < 1 ? 1 : ConfigManager::getInt("bar:height") - 2; @@ -800,7 +802,7 @@ void Events::eventClientMessage(xcb_generic_event_t* event) { event->format = 32; event->data.data32[0] = XCB_CURRENT_TIME; event->data.data32[1] = 0; - event->data.data32[2] = g_pWindowManager->statusBar->getWindowID(); + event->data.data32[2] = g_pWindowManager->statusBar->trayWindowID; event->data.data32[3] = XEMBEDVERSION; xcb_send_event(g_pWindowManager->DisplayConnection, 0, CLIENT, XCB_EVENT_MASK_NO_EVENT, (char*)event); diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 73a5d3a..777a8f5 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -1799,6 +1799,12 @@ bool CWindowManager::shouldBeFloatedOnInit(int64_t window) { Debug::log(ERR, "shouldBeFloatedOnInit with an invalid window!"); return true; } + + if (window == barWindowID) { + PWINDOW->setDock(true); + PWINDOW->setDockAlign(DOCK_TOP); + } + const auto WINCLASS = getClassName(window); const auto CLASSNAME = WINCLASS.second; diff --git a/src/windowManager.hpp b/src/windowManager.hpp index 19fe6d7..3fe9e96 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -53,7 +53,7 @@ public: SIPCPipe m_sIPCBarPipeOut = {ISDEBUG ? "/tmp/hypr/hyprbaroutd" : "/tmp/hypr/hyprbarout", 0}; CStatusBar* statusBar = nullptr; Vector2D lastKnownBarPosition = {-1,-1}; - uint64_t barWindowID = 0; + int64_t barWindowID = 0; GThread* barThread; /* Well right now anything but the bar but lol */ std::deque trayclients;