Skip to content

Commit 4d50b91

Browse files
committed
socket2: add {,de}populateworkspace{,v2} events
1 parent 5207a1d commit 4d50b91

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/desktop/Window.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
437437

438438
const auto OLDWORKSPACE = m_workspace;
439439

440+
bool previouslyEmpty = !pWorkspace->hasWindow();
441+
440442
if (OLDWORKSPACE->isVisible()) {
441443
m_movingToWorkspaceAlpha->setValueAndWarp(1.F);
442444
*m_movingToWorkspaceAlpha = 0.F;
@@ -462,6 +464,18 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
462464
g_pEventManager->postEvent(SHyprIPCEvent{.event = "movewindow", .data = std::format("{:x},{}", rc<uintptr_t>(this), pWorkspace->m_name)});
463465
g_pEventManager->postEvent(SHyprIPCEvent{.event = "movewindowv2", .data = std::format("{:x},{},{}", rc<uintptr_t>(this), pWorkspace->m_id, pWorkspace->m_name)});
464466
EMIT_HOOK_EVENT("moveWindow", (std::vector<std::any>{m_self.lock(), pWorkspace}));
467+
468+
if (!OLDWORKSPACE->hasWindow()) {
469+
g_pEventManager->postEvent(SHyprIPCEvent{.event = "depopulateworkspace", .data = OLDWORKSPACE->m_name});
470+
g_pEventManager->postEvent(SHyprIPCEvent{.event = "depopulateworkspacev2", .data = std::format("{},{}", OLDWORKSPACE->m_id, OLDWORKSPACE->m_name)});
471+
EMIT_HOOK_EVENT("depopulateWorkspace", OLDWORKSPACE);
472+
}
473+
474+
if (previouslyEmpty) {
475+
g_pEventManager->postEvent(SHyprIPCEvent{.event = "populateworkspace", .data = pWorkspace->m_name});
476+
g_pEventManager->postEvent(SHyprIPCEvent{.event = "populateworkspacev2", .data = std::format("{},{}", pWorkspace->m_id, pWorkspace->m_name)});
477+
EMIT_HOOK_EVENT("populateWorkspace", pWorkspace);
478+
}
465479
}
466480

467481
if (const auto SWALLOWED = m_swallowed.lock()) {

src/events/Windows.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)