@@ -66,7 +66,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
6666 Desktop::focusState ()->rawMonitorFocus (g_pCompositor->getMonitorFromVector ({}));
6767 PMONITOR = Desktop::focusState ()->monitor ();
6868 }
69- auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace ;
69+ auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace ;
70+ bool workspacePreviouslyEmpty = !PWORKSPACE->hasWindow ();
71+
7072 PWINDOW->m_monitor = PMONITOR;
7173 PWINDOW->m_workspace = PWORKSPACE;
7274 PWINDOW->m_isMapped = true ;
@@ -370,6 +372,10 @@ void Events::listener_mapWindow(void* owner, void* data) {
370372 // emit the IPC event before the layout might focus the window to avoid a focus event first
371373 g_pEventManager->postEvent (SHyprIPCEvent{" openwindow" , std::format (" {:x},{},{},{}" , PWINDOW, PWORKSPACE->m_name , PWINDOW->m_class , PWINDOW->m_title )});
372374 EMIT_HOOK_EVENT (" openWindowEarly" , PWINDOW);
375+ if (workspacePreviouslyEmpty) {
376+ g_pEventManager->postEvent (SHyprIPCEvent{" populateworkspace" , PWORKSPACE->m_name });
377+ g_pEventManager->postEvent (SHyprIPCEvent{" populateworkspacev2" , std::format (" {},{}" , PWORKSPACE->m_id , PWORKSPACE->m_name )});
378+ }
373379
374380 if (PWINDOW->m_isFloating ) {
375381 g_pLayoutManager->getCurrentLayout ()->onWindowCreated (PWINDOW);
@@ -510,6 +516,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
510516
511517 // emit the hook event here after basic stuff has been initialized
512518 EMIT_HOOK_EVENT (" openWindow" , PWINDOW);
519+ if (workspacePreviouslyEmpty) {
520+ EMIT_HOOK_EVENT (" populateWorkspace" , PWORKSPACE);
521+ }
513522
514523 // apply data from default decos. Borders, shadows.
515524 g_pDecorationPositioner->forceRecalcFor (PWINDOW);
@@ -627,6 +636,12 @@ void Events::listener_unmapWindow(void* owner, void* data) {
627636 // do this after onWindowRemoved because otherwise it'll think the window is invalid
628637 PWINDOW->m_isMapped = false ;
629638
639+ if (!PWINDOW->m_workspace ->hasWindow ()) {
640+ g_pEventManager->postEvent (SHyprIPCEvent{" depopulateworkspace" , PWINDOW->m_workspace ->m_name });
641+ g_pEventManager->postEvent (SHyprIPCEvent{" depopulateworkspacev2" , std::format (" {},{}" , PWINDOW->m_workspace ->m_id , PWINDOW->m_workspace ->m_name )});
642+ EMIT_HOOK_EVENT (" depopulateWorkspace" , PWINDOW->m_workspace );
643+ }
644+
630645 // refocus on a new window if needed
631646 if (wasLastWindow) {
632647 static auto FOCUSONCLOSE = CConfigValue<Hyprlang::INT>(" input:focus_on_close" );
0 commit comments