Skip to content

Commit

Permalink
wayland: implement keyboard_shortcuts_inhibit_v1
Browse files Browse the repository at this point in the history
fixes #4568
  • Loading branch information
vaxerski committed Feb 27, 2024
1 parent f26d7aa commit e337366
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ void CCompositor::initAllSignals() {
addWLSignal(&m_sWLRGammaCtrlMgr->events.set_gamma, &Events::listen_setGamma, m_sWLRGammaCtrlMgr, "GammaCtrlMgr");
addWLSignal(&m_sWLRCursorShapeMgr->events.request_set_shape, &Events::listen_setCursorShape, m_sWLRCursorShapeMgr, "CursorShapeMgr");
addWLSignal(&m_sWLRTearingControlMgr->events.new_object, &Events::listen_newTearingHint, m_sWLRTearingControlMgr, "TearingControlMgr");
addWLSignal(&m_sWLRKbShInhibitMgr->events.new_inhibitor, &Events::listen_newShortcutInhibitor, m_sWLRKbShInhibitMgr, "ShortcutInhibitMgr");

if (m_sWRLDRMLeaseMgr)
addWLSignal(&m_sWRLDRMLeaseMgr->events.request, &Events::listen_leaseRequest, &m_sWRLDRMLeaseMgr, "DRM");
Expand Down Expand Up @@ -360,6 +361,7 @@ void CCompositor::removeAllSignals() {
removeWLSignal(&Events::listen_setGamma);
removeWLSignal(&Events::listen_setCursorShape);
removeWLSignal(&Events::listen_newTearingHint);
removeWLSignal(&Events::listen_newShortcutInhibitor);

if (m_sWRLDRMLeaseMgr)
removeWLSignal(&Events::listen_leaseRequest);
Expand Down
3 changes: 3 additions & 0 deletions src/events/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ namespace Events {

// Tearing hints
LISTENER(newTearingHint);

// Shortcut inhibitor
LISTENER(newShortcutInhibitor);
};
17 changes: 17 additions & 0 deletions src/events/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,20 @@ void Events::listener_newTearingHint(wl_listener* listener, void* data) {
},
NEWCTRL, "TearingController");
}

void Events::listener_newShortcutInhibitor(wl_listener* listener, void* data) {
const auto INHIBITOR = (wlr_keyboard_shortcuts_inhibitor_v1*)data;

const auto PINH = &g_pKeybindManager->m_lShortcutInhibitors.emplace_back();
PINH->hyprListener_destroy.initCallback(
&INHIBITOR->events.destroy,
[](void* owner, void* data) {
const auto OWNER = (SShortcutInhibitor*)owner;
g_pKeybindManager->m_lShortcutInhibitors.remove(*OWNER);
},
PINH, "ShortcutInhibitor");

PINH->pWlrInhibitor = INHIBITOR;

Debug::log(LOG, "New shortcut inhibitor for surface {:x}", (uintptr_t)INHIBITOR->surface);
}
10 changes: 10 additions & 0 deletions src/helpers/WLClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,13 @@ struct STearingController {
return pWlrHint == other.pWlrHint;
}
};

struct SShortcutInhibitor {
wlr_keyboard_shortcuts_inhibitor_v1* pWlrInhibitor = nullptr;

DYNLISTENER(destroy);

bool operator==(const SShortcutInhibitor& other) {
return pWlrInhibitor == other.pWlrInhibitor;
}
};
9 changes: 9 additions & 0 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi
if (g_pCompositor->m_sSeat.exclusiveClient)
Debug::log(LOG, "Keybind handling only locked (inhibitor)");

if (!m_lShortcutInhibitors.empty()) {
for (auto& i : m_lShortcutInhibitors) {
if (i.pWlrInhibitor->surface == g_pCompositor->m_pLastFocus) {
Debug::log(LOG, "Keybind handling is disabled due to an inhibitor for surface {:x}", (uintptr_t)i.pWlrInhibitor->surface);
return false;
}
}
}

for (auto& k : m_lKeybinds) {
const bool SPECIALDISPATCHER = k.handler == "global" || k.handler == "pass" || k.handler == "mouse";
const bool SPECIALTRIGGERED =
Expand Down
1 change: 1 addition & 0 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CKeybindManager {
bool m_bGroupsLocked = false;

std::list<SKeybind> m_lKeybinds;
std::list<SShortcutInhibitor> m_lShortcutInhibitors;

private:
std::deque<SPressedKeyWithMods> m_dPressedKeys;
Expand Down

0 comments on commit e337366

Please sign in to comment.