fix the bar dying on config reload

use no_tray_saving=1 in bar {} (defaults to 1)
This commit is contained in:
vaxerski 2021-12-26 00:00:38 +01:00
parent 537ea4e619
commit 89f6421532
7 changed files with 33 additions and 12 deletions

View file

@ -24,6 +24,7 @@ Bar {
monitor=0 monitor=0
enabled=1 enabled=1
mod_pad_in=8 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.main=Noto Sans
font.secondary=Noto Sans font.secondary=Noto Sans

View file

@ -165,7 +165,7 @@ void CStatusBar::setupTray() {
values); values);
xcb_atom_t dockAtom[] = {HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"]}; 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 const uint32_t ORIENTATION = 0; // Horizontal
xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, trayWindowID, xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, trayWindowID,
@ -253,9 +253,9 @@ void CStatusBar::setupTray() {
} }
void CStatusBar::fixTrayOnCreate() { void CStatusBar::fixTrayOnCreate() {
if (m_bHasTray) { if (m_bHasTray && ConfigManager::getInt("bar:no_tray_saving") == 0) {
for (auto& tray : g_pWindowManager->trayclients) { 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); xcb_map_window(g_pWindowManager->DisplayConnection, tray.window);
tray.hidden = false; tray.hidden = false;
} }
@ -278,8 +278,14 @@ void CStatusBar::fixTrayOnCreate() {
} }
void CStatusBar::saveTrayOnDestroy() { 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) { 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]; const auto MONITOR = g_pWindowManager->monitors[MonitorID];
Debug::log(LOG, "Bar monitor found to be " + std::to_string(MONITOR.ID));
m_iMonitorID = MonitorID; m_iMonitorID = MonitorID;
m_vecPosition = MONITOR.vecPosition; m_vecPosition = MONITOR.vecPosition;
m_vecSize = Vector2D(MONITOR.vecSize.x, ConfigManager::getInt("bar:height")); m_vecSize = Vector2D(MONITOR.vecSize.x, ConfigManager::getInt("bar:height"));
@ -331,6 +339,7 @@ void CStatusBar::setup(int MonitorID) {
// map // map
xcb_map_window(g_pWindowManager->DisplayConnection, m_iWindowID); xcb_map_window(g_pWindowManager->DisplayConnection, m_iWindowID);
Debug::log(LOG, "Bar mapping!");
// Create a pixmap for writing to. // Create a pixmap for writing to.
m_iPixmap = xcb_generate_id(g_pWindowManager->DisplayConnection); m_iPixmap = xcb_generate_id(g_pWindowManager->DisplayConnection);
@ -356,6 +365,7 @@ void CStatusBar::setup(int MonitorID) {
// fix tray // fix tray
fixTrayOnCreate(); fixTrayOnCreate();
Debug::log(LOG, "Bar setup done!");
m_bIsDestroyed = false; m_bIsDestroyed = false;
} }

View file

@ -63,6 +63,8 @@ public:
std::vector<SBarModule> modules; std::vector<SBarModule> modules;
xcb_window_t trayWindowID = 0;
private: private:
// for not deleting nulls // for not deleting nulls
bool m_bIsDestroyed = true; bool m_bIsDestroyed = true;
@ -92,7 +94,6 @@ private:
void fixTrayOnCreate(); void fixTrayOnCreate();
void saveTrayOnDestroy(); void saveTrayOnDestroy();
int drawTrayModule(SBarModule*, int); 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. // Main thread for the bar. Is only initted once in main.cpp so we can do this.

View file

@ -31,6 +31,7 @@ void ConfigManager::init() {
configValues["bar:font.main"].strValue = "Noto Sans"; configValues["bar:font.main"].strValue = "Noto Sans";
configValues["bar:font.secondary"].strValue = "Noto Sans"; configValues["bar:font.secondary"].strValue = "Noto Sans";
configValues["bar:mod_pad_in"].intValue = 4; configValues["bar:mod_pad_in"].intValue = 4;
configValues["bar:no_tray_saving"].intValue = 1;
configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time // Deprecated configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time // Deprecated

View file

@ -393,6 +393,12 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) {
return nullptr; return nullptr;
} }
if (PWINDOWINARR->getClassName() == "Error") {
Debug::log(LOG, "Class error -> force float");
return remapFloatingWindow(windowID, forcemonitor);
}
PWINDOWINARR->setIsFloating(false); PWINDOWINARR->setIsFloating(false);
PWINDOWINARR->setDirty(true); PWINDOWINARR->setDirty(true);
@ -568,10 +574,6 @@ void Events::eventMapWindow(xcb_generic_event_t* event) {
// Map the window // Map the window
xcb_map_window(g_pWindowManager->DisplayConnection, E->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 // Check if it's not unmapped
if (g_pWindowManager->isWindowUnmapped(E->window)) { if (g_pWindowManager->isWindowUnmapped(E->window)) {
g_pWindowManager->moveWindowToMapped(E->window); g_pWindowManager->moveWindowToMapped(E->window);
@ -782,7 +784,7 @@ void Events::eventClientMessage(xcb_generic_event_t* event) {
free(XEMBEDREPLY); 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 // icon sizes are barY - 2 - pad: 1
values[0] = ConfigManager::getInt("bar:height") - 2 < 1 ? 1 : ConfigManager::getInt("bar:height") - 2; 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->format = 32;
event->data.data32[0] = XCB_CURRENT_TIME; event->data.data32[0] = XCB_CURRENT_TIME;
event->data.data32[1] = 0; 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; event->data.data32[3] = XEMBEDVERSION;
xcb_send_event(g_pWindowManager->DisplayConnection, 0, CLIENT, XCB_EVENT_MASK_NO_EVENT, (char*)event); xcb_send_event(g_pWindowManager->DisplayConnection, 0, CLIENT, XCB_EVENT_MASK_NO_EVENT, (char*)event);

View file

@ -1799,6 +1799,12 @@ bool CWindowManager::shouldBeFloatedOnInit(int64_t window) {
Debug::log(ERR, "shouldBeFloatedOnInit with an invalid window!"); Debug::log(ERR, "shouldBeFloatedOnInit with an invalid window!");
return true; return true;
} }
if (window == barWindowID) {
PWINDOW->setDock(true);
PWINDOW->setDockAlign(DOCK_TOP);
}
const auto WINCLASS = getClassName(window); const auto WINCLASS = getClassName(window);
const auto CLASSNAME = WINCLASS.second; const auto CLASSNAME = WINCLASS.second;

View file

@ -53,7 +53,7 @@ public:
SIPCPipe m_sIPCBarPipeOut = {ISDEBUG ? "/tmp/hypr/hyprbaroutd" : "/tmp/hypr/hyprbarout", 0}; SIPCPipe m_sIPCBarPipeOut = {ISDEBUG ? "/tmp/hypr/hyprbaroutd" : "/tmp/hypr/hyprbarout", 0};
CStatusBar* statusBar = nullptr; CStatusBar* statusBar = nullptr;
Vector2D lastKnownBarPosition = {-1,-1}; Vector2D lastKnownBarPosition = {-1,-1};
uint64_t barWindowID = 0; int64_t barWindowID = 0;
GThread* barThread; /* Well right now anything but the bar but lol */ GThread* barThread; /* Well right now anything but the bar but lol */
std::deque<CTrayClient> trayclients; std::deque<CTrayClient> trayclients;