Skip to content

Commit 9db6337

Browse files
committed
socket2: add {,de}populateworkspace events
1 parent 5207a1d commit 9db6337

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/desktop/Window.cpp

Lines changed: 12 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,16 @@ 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 = std::format("{},{}", OLDWORKSPACE->m_id, OLDWORKSPACE->m_name)});
470+
EMIT_HOOK_EVENT("depopulateWorkspace", OLDWORKSPACE);
471+
}
472+
473+
if (previouslyEmpty) {
474+
g_pEventManager->postEvent(SHyprIPCEvent{.event = "populateworkspace", .data = std::format("{},{}", pWorkspace->m_id, pWorkspace->m_name)});
475+
EMIT_HOOK_EVENT("populateWorkspace", pWorkspace);
476+
}
465477
}
466478

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

src/events/Windows.cpp

Lines changed: 14 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,9 @@ 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", std::format("{},{}", PWORKSPACE->m_id, PWORKSPACE->m_name)});
377+
}
373378

374379
if (PWINDOW->m_isFloating) {
375380
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
@@ -510,6 +515,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
510515

511516
// emit the hook event here after basic stuff has been initialized
512517
EMIT_HOOK_EVENT("openWindow", PWINDOW);
518+
if (workspacePreviouslyEmpty) {
519+
EMIT_HOOK_EVENT("populateWorkspace", PWORKSPACE);
520+
}
513521

514522
// apply data from default decos. Borders, shadows.
515523
g_pDecorationPositioner->forceRecalcFor(PWINDOW);
@@ -627,6 +635,11 @@ void Events::listener_unmapWindow(void* owner, void* data) {
627635
// do this after onWindowRemoved because otherwise it'll think the window is invalid
628636
PWINDOW->m_isMapped = false;
629637

638+
if (!PWINDOW->m_workspace->hasWindow()) {
639+
g_pEventManager->postEvent(SHyprIPCEvent{"depopulateworkspace", std::format("{},{}", PWINDOW->m_workspace->m_id, PWINDOW->m_workspace->m_name)});
640+
EMIT_HOOK_EVENT("depopulateWorkspace", PWINDOW->m_workspace);
641+
}
642+
630643
// refocus on a new window if needed
631644
if (wasLastWindow) {
632645
static auto FOCUSONCLOSE = CConfigValue<Hyprlang::INT>("input:focus_on_close");

0 commit comments

Comments
 (0)