idle-inhibit: move to new impl
This commit is contained in:
parent
e823b5d693
commit
d9fe1d0f58
14 changed files with 154 additions and 68 deletions
|
|
@ -4,11 +4,13 @@
|
|||
#include "../protocols/FractionalScale.hpp"
|
||||
#include "../protocols/XDGOutput.hpp"
|
||||
#include "../protocols/CursorShape.hpp"
|
||||
#include "../protocols/IdleInhibit.hpp"
|
||||
|
||||
#include "tearing-control-v1.hpp"
|
||||
#include "fractional-scale-v1.hpp"
|
||||
#include "xdg-output-unstable-v1.hpp"
|
||||
#include "cursor-shape-v1.hpp"
|
||||
#include "idle-inhibit-unstable-v1.hpp"
|
||||
|
||||
CProtocolManager::CProtocolManager() {
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ CProtocolManager::CProtocolManager() {
|
|||
PROTO::fractional = std::make_unique<CFractionalScaleProtocol>(&wp_fractional_scale_manager_v1_interface, 1, "FractionalScale");
|
||||
PROTO::xdgOutput = std::make_unique<CXDGOutputProtocol>(&zxdg_output_manager_v1_interface, 3, "XDGOutput");
|
||||
PROTO::cursorShape = std::make_unique<CCursorShapeProtocol>(&wp_cursor_shape_manager_v1_interface, 1, "CursorShape");
|
||||
PROTO::idleInhibit = std::make_unique<CIdleInhibitProtocol>(&zwp_idle_inhibit_manager_v1_interface, 1, "IdleInhibit");
|
||||
|
||||
// Old protocol implementations.
|
||||
// TODO: rewrite them to use hyprwayland-scanner.
|
||||
|
|
|
|||
|
|
@ -1,61 +1,39 @@
|
|||
#include "InputManager.hpp"
|
||||
#include "../../Compositor.hpp"
|
||||
#include "../../protocols/IdleInhibit.hpp"
|
||||
|
||||
void Events::listener_newIdleInhibitor(wl_listener* listener, void* data) {
|
||||
const auto WLRIDLEINHIBITOR = (wlr_idle_inhibitor_v1*)data;
|
||||
void CInputManager::newIdleInhibitor(std::any inhibitor) {
|
||||
const auto PINHIBIT = m_vIdleInhibitors.emplace_back(std::make_unique<SIdleInhibitor>()).get();
|
||||
PINHIBIT->inhibitor = std::any_cast<std::shared_ptr<CIdleInhibitor>>(inhibitor);
|
||||
|
||||
if (!WLRIDLEINHIBITOR)
|
||||
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface);
|
||||
|
||||
PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource.lock()->events.destroy.registerListener(
|
||||
[this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); });
|
||||
|
||||
const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface);
|
||||
|
||||
if (!PWINDOW) {
|
||||
Debug::log(WARN, "Inhibitor is for no window?");
|
||||
return;
|
||||
}
|
||||
|
||||
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->pWindow = PWINDOW;
|
||||
PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) {
|
||||
Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource.");
|
||||
PINHIBIT->pWindow = nullptr;
|
||||
});
|
||||
|
||||
PINHIBIT->hyprListener_Destroy.initCallback(
|
||||
&pInhibitor->events.destroy,
|
||||
[](void* owner, void* data) {
|
||||
const auto PINH = (SIdleInhibitor*)owner;
|
||||
|
||||
destroyInhibitor(PINH);
|
||||
},
|
||||
PINHIBIT, "IdleInhibitor");
|
||||
|
||||
PINHIBIT->pWindow = g_pCompositor->getWindowFromSurface(pInhibitor->surface);
|
||||
|
||||
if (PINHIBIT->pWindow)
|
||||
Debug::log(LOG, "IdleInhibitor got window {}", PINHIBIT->pWindow);
|
||||
|
||||
recheckIdleInhibitorStatus();
|
||||
}
|
||||
|
||||
void CInputManager::recheckIdleInhibitorStatus() {
|
||||
|
||||
for (auto& ii : m_lIdleInhibitors) {
|
||||
if (!ii.pWindow) {
|
||||
for (auto& ii : m_vIdleInhibitors) {
|
||||
if (!ii->pWindow) {
|
||||
g_pCompositor->setIdleActivityInhibit(false);
|
||||
return;
|
||||
} else if (g_pHyprRenderer->shouldRenderWindow(ii.pWindow)) {
|
||||
} else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow)) {
|
||||
g_pCompositor->setIdleActivityInhibit(false);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "../../config/ConfigValue.hpp"
|
||||
#include "../../desktop/Window.hpp"
|
||||
#include "../../protocols/CursorShape.hpp"
|
||||
#include "../../protocols/IdleInhibit.hpp"
|
||||
|
||||
CInputManager::CInputManager() {
|
||||
m_sListeners.setCursorShape = PROTO::cursorShape->events.setShape.registerListener([this](std::any data) {
|
||||
|
|
@ -29,6 +30,8 @@ CInputManager::CInputManager() {
|
|||
m_sCursorSurfaceInfo.inUse = true;
|
||||
g_pHyprRenderer->setCursorFromName(m_sCursorSurfaceInfo.name);
|
||||
});
|
||||
|
||||
m_sListeners.newIdleInhibitor = PROTO::idleInhibit->events.newIdleInhibitor.registerListener([this](std::any data) { this->newIdleInhibitor(data); });
|
||||
}
|
||||
|
||||
CInputManager::~CInputManager() {
|
||||
|
|
@ -38,7 +41,7 @@ CInputManager::~CInputManager() {
|
|||
m_lTablets.clear();
|
||||
m_lTabletTools.clear();
|
||||
m_lTabletPads.clear();
|
||||
m_lIdleInhibitors.clear();
|
||||
m_vIdleInhibitors.clear();
|
||||
m_lTouchDevices.clear();
|
||||
m_lSwitches.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "../../defines.hpp"
|
||||
#include <list>
|
||||
#include <any>
|
||||
#include "../../helpers/WLClasses.hpp"
|
||||
#include "../../helpers/Timer.hpp"
|
||||
#include "InputMethodRelay.hpp"
|
||||
|
|
@ -9,6 +10,7 @@
|
|||
|
||||
class CConstraint;
|
||||
class CWindow;
|
||||
class CIdleInhibitor;
|
||||
|
||||
enum eClickBehaviorMode {
|
||||
CLICKMODE_DEFAULT = 0,
|
||||
|
|
@ -132,9 +134,6 @@ class CInputManager {
|
|||
std::list<STabletTool> m_lTabletTools;
|
||||
std::list<STabletPad> m_lTabletPads;
|
||||
|
||||
// idle inhibitors
|
||||
std::list<SIdleInhibitor> m_lIdleInhibitors;
|
||||
|
||||
// Touch devices
|
||||
std::list<STouchDevice> m_lTouchDevices;
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ class CInputManager {
|
|||
void newTabletTool(wlr_input_device*);
|
||||
void newTabletPad(wlr_input_device*);
|
||||
void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false);
|
||||
void newIdleInhibitor(wlr_idle_inhibitor_v1*);
|
||||
void newIdleInhibitor(std::any);
|
||||
void recheckIdleInhibitorStatus();
|
||||
|
||||
void onSwipeBegin(wlr_pointer_swipe_begin_event*);
|
||||
|
|
@ -201,6 +200,7 @@ class CInputManager {
|
|||
// Listeners
|
||||
struct {
|
||||
CHyprSignalListener setCursorShape;
|
||||
CHyprSignalListener newIdleInhibitor;
|
||||
} m_sListeners;
|
||||
|
||||
bool m_bCursorImageOverridden = false;
|
||||
|
|
@ -237,6 +237,14 @@ class CInputManager {
|
|||
// for releasing mouse buttons
|
||||
std::list<uint32_t> m_lCurrentlyHeldButtons;
|
||||
|
||||
// idle inhibitors
|
||||
struct SIdleInhibitor {
|
||||
std::shared_ptr<CIdleInhibitor> inhibitor;
|
||||
CWindow* pWindow = nullptr;
|
||||
CHyprSignalListener windowDestroyListener;
|
||||
};
|
||||
std::vector<std::unique_ptr<SIdleInhibitor>> m_vIdleInhibitors;
|
||||
|
||||
// swipe
|
||||
void beginWorkspaceSwipe();
|
||||
void updateWorkspaceSwipe(double);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue