Skip to content

Commit

Permalink
inhibitor: always destroy on window unmap
Browse files Browse the repository at this point in the history
ref #5555
  • Loading branch information
vaxerski committed Apr 11, 2024
1 parent e0a7cf5 commit b1a9430
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/helpers/WLClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ struct STabletPad {
};

struct SIdleInhibitor {
wlr_idle_inhibitor_v1* pWlrInhibitor = nullptr;
CWindow* pWindow = nullptr;
wlr_idle_inhibitor_v1* pWlrInhibitor = nullptr;
CWindow* pWindow = nullptr;
HOOK_CALLBACK_FN* onWindowDestroy = nullptr;

DYNLISTENER(Destroy);

Expand Down
21 changes: 16 additions & 5 deletions src/managers/input/IdleInhibitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ void Events::listener_newIdleInhibitor(wl_listener* listener, void* data) {
g_pInputManager->newIdleInhibitor(WLRIDLEINHIBITOR);
}

static void destroyInhibitor(SIdleInhibitor* inhibitor) {
g_pHookSystem->unhook(inhibitor->onWindowDestroy);

g_pInputManager->m_lIdleInhibitors.remove(*inhibitor);

Debug::log(LOG, "Destroyed an idleinhibitor");

g_pInputManager->recheckIdleInhibitorStatus();
}

void CInputManager::newIdleInhibitor(wlr_idle_inhibitor_v1* pInhibitor) {
const auto PINHIBIT = &m_lIdleInhibitors.emplace_back();

Debug::log(LOG, "New idle inhibitor registered");

PINHIBIT->pWlrInhibitor = pInhibitor;

PINHIBIT->onWindowDestroy = g_pHookSystem->hookDynamic("closeWindow", [PINHIBIT](void* self, SCallbackInfo& info, std::any data) {
if (PINHIBIT->pWindow == std::any_cast<CWindow*>(data))
destroyInhibitor(PINHIBIT);
});

PINHIBIT->hyprListener_Destroy.initCallback(
&pInhibitor->events.destroy,
[](void* owner, void* data) {
const auto PINH = (SIdleInhibitor*)owner;

g_pInputManager->m_lIdleInhibitors.remove(*PINH);

Debug::log(LOG, "Destroyed an idleinhibitor");

g_pInputManager->recheckIdleInhibitorStatus();
destroyInhibitor(PINH);
},
PINHIBIT, "IdleInhibitor");

Expand Down

0 comments on commit b1a9430

Please sign in to comment.