ext-idle-notify: move to new impl

This commit is contained in:
Vaxry 2024-04-29 17:42:07 +01:00
parent 86133983a9
commit f2b03e9679
13 changed files with 186 additions and 82 deletions

View file

@ -237,8 +237,6 @@ void CCompositor::initServer() {
m_sWLRPresentation = wlr_presentation_create(m_sWLDisplay, m_sWLRBackend);
m_sWLRIdleNotifier = wlr_idle_notifier_v1_create(m_sWLDisplay);
m_sWLRLayerShell = wlr_layer_shell_v1_create(m_sWLDisplay, 4);
m_sWLRServerDecoMgr = wlr_server_decoration_manager_create(m_sWLDisplay);
@ -2701,13 +2699,6 @@ PHLWINDOW CCompositor::getForceFocus() {
return nullptr;
}
void CCompositor::notifyIdleActivity() {
wlr_idle_notifier_v1_notify_activity(g_pCompositor->m_sWLRIdleNotifier, g_pCompositor->m_sSeat.seat);
}
void CCompositor::setIdleActivityInhibit(bool enabled) {
wlr_idle_notifier_v1_set_inhibited(g_pCompositor->m_sWLRIdleNotifier, !enabled);
}
void CCompositor::arrangeMonitors() {
static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling");

View file

@ -52,7 +52,6 @@ class CCompositor {
wlr_drm* m_sWRLDRM;
wlr_drm_lease_v1_manager* m_sWRLDRMLeaseMgr;
wlr_output_layout* m_sWLROutputLayout;
wlr_idle_notifier_v1* m_sWLRIdleNotifier;
wlr_layer_shell_v1* m_sWLRLayerShell;
wlr_xdg_shell* m_sWLRXDGShell;
wlr_cursor* m_sWLRCursor;
@ -185,8 +184,6 @@ class CCompositor {
void performUserChecks();
void moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWorkspace);
PHLWINDOW getForceFocus();
void notifyIdleActivity();
void setIdleActivityInhibit(bool inhibit);
void arrangeMonitors();
void enterUnsafeState();
void leaveUnsafeState();

View file

@ -92,7 +92,6 @@ extern "C" {
#include <wlr/backend/wayland.h>
#include <wlr/types/wlr_session_lock_v1.h>
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/util/box.h>
#include <wlr/util/transform.h>
#include <wlr/render/swapchain.h>

View file

@ -17,6 +17,7 @@
#include "../protocols/PointerConstraints.hpp"
#include "../protocols/OutputPower.hpp"
#include "../protocols/XDGActivation.hpp"
#include "../protocols/IdleNotify.hpp"
#include "tearing-control-v1.hpp"
#include "fractional-scale-v1.hpp"
@ -35,6 +36,7 @@
#include "pointer-constraints-unstable-v1.hpp"
#include "wlr-output-power-management-unstable-v1.hpp"
#include "xdg-activation-v1.hpp"
#include "ext-idle-notify-v1.hpp"
CProtocolManager::CProtocolManager() {
@ -55,6 +57,7 @@ CProtocolManager::CProtocolManager() {
PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints");
PROTO::outputPower = std::make_unique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower");
PROTO::activation = std::make_unique<CXDGActivationProtocol>(&xdg_activation_v1_interface, 1, "XDGActivation");
PROTO::idle = std::make_unique<CIdleNotifyProtocol>(&ext_idle_notifier_v1_interface, 1, "IdleNotify");
// Old protocol implementations.
// TODO: rewrite them to use hyprwayland-scanner.

View file

@ -1,6 +1,7 @@
#include "InputManager.hpp"
#include "../../Compositor.hpp"
#include "../../protocols/IdleInhibit.hpp"
#include "../../protocols/IdleNotify.hpp"
void CInputManager::newIdleInhibitor(std::any inhibitor) {
const auto PINHIBIT = m_vIdleInhibitors.emplace_back(std::make_unique<SIdleInhibitor>()).get();
@ -29,11 +30,11 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) {
void CInputManager::recheckIdleInhibitorStatus() {
for (auto& ii : m_vIdleInhibitors) {
if (ii->pWindow.expired()) {
g_pCompositor->setIdleActivityInhibit(false);
return;
} else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) {
g_pCompositor->setIdleActivityInhibit(false);
if (ii->pWindow.expired())
continue;
if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) {
PROTO::idle->setInhibit(true);
return;
}
}
@ -44,21 +45,21 @@ void CInputManager::recheckIdleInhibitorStatus() {
continue;
if (w->m_eIdleInhibitMode == IDLEINHIBIT_ALWAYS) {
g_pCompositor->setIdleActivityInhibit(false);
PROTO::idle->setInhibit(true);
return;
}
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w)) {
g_pCompositor->setIdleActivityInhibit(false);
PROTO::idle->setInhibit(true);
return;
}
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->m_pWorkspace)) {
g_pCompositor->setIdleActivityInhibit(false);
PROTO::idle->setInhibit(true);
return;
}
}
g_pCompositor->setIdleActivityInhibit(true);
PROTO::idle->setInhibit(false);
return;
}

View file

@ -8,6 +8,7 @@
#include "../../protocols/IdleInhibit.hpp"
#include "../../protocols/RelativePointer.hpp"
#include "../../protocols/PointerConstraints.hpp"
#include "../../protocols/IdleNotify.hpp"
CInputManager::CInputManager() {
m_sListeners.setCursorShape = PROTO::cursorShape->events.setShape.registerListener([this](std::any data) {
@ -144,7 +145,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
EMIT_HOOK_EVENT_CANCELLABLE("mouseMove", MOUSECOORDSFLOORED);
if (time)
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
m_vLastCursorPosFloored = MOUSECOORDSFLOORED;
@ -480,7 +481,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
void CInputManager::onMouseButton(wlr_pointer_button_event* e) {
EMIT_HOOK_EVENT_CANCELLABLE("mouseButton", e);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
m_tmrLastCursorMovement.reset();
@ -705,7 +706,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) {
bool passEvent = g_pKeybindManager->onAxisEvent(e);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
if (!passEvent)
return;
@ -1216,7 +1217,7 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar
bool passEvent = g_pKeybindManager->onKeyEvent(e, pKeyboard);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
if (passEvent) {

View file

@ -1,5 +1,6 @@
#include "InputManager.hpp"
#include "../../Compositor.hpp"
#include "../../protocols/IdleNotify.hpp"
void CInputManager::newTabletTool(wlr_input_device* pDevice) {
const auto PNEWTABLET = &m_lTablets.emplace_back();
@ -99,7 +100,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y))
wlr_tablet_v2_tablet_tool_notify_tilt(PTOOL->wlrTabletToolV2, PTOOL->tiltX, PTOOL->tiltY);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
},
PNEWTABLET, "Tablet");
@ -120,7 +121,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
wlr_send_tablet_v2_tablet_tool_up(PTOOL->wlrTabletToolV2);
}
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
},
PNEWTABLET, "Tablet");
@ -132,7 +133,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
const auto PTOOL = g_pInputManager->ensureTabletToolPresent(EVENT->tool);
wlr_tablet_v2_tablet_tool_notify_button(PTOOL->wlrTabletToolV2, (zwp_tablet_pad_v2_button_state)EVENT->button, (zwp_tablet_pad_v2_button_state)EVENT->state);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
},
PNEWTABLET, "Tablet");
@ -158,7 +159,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
g_pInputManager->focusTablet(PTAB, EVENT->tool);
}
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
},
PNEWTABLET, "Tablet");

View file

@ -1,6 +1,7 @@
#include "InputManager.hpp"
#include "../../Compositor.hpp"
#include "../../config/ConfigValue.hpp"
#include "../../protocols/IdleNotify.hpp"
void CInputManager::onTouchDown(wlr_touch_down_event* e) {
static auto PSWIPETOUCH = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch");
@ -83,7 +84,7 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) {
wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, m_sTouchData.touchFocusSurface, e->time_msec, e->touch_id, local.x, local.y);
g_pCompositor->notifyIdleActivity();
PROTO::idle->onActivity();
}
void CInputManager::onTouchUp(wlr_touch_up_event* e) {

View file

@ -0,0 +1,104 @@
#include "IdleNotify.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#define LOGM PROTO::idle->protoLog
static int onTimer(std::shared_ptr<CEventLoopTimer> self, void* data) {
const auto NOTIF = (CExtIdleNotification*)data;
NOTIF->onTimerFired();
return 0;
}
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_) : resource(resource_), timeoutMs(timeoutMs_) {
if (!resource_->resource())
return;
resource->setDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
resource->setOnDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
timer = std::make_shared<CEventLoopTimer>(std::nullopt, onTimer, this);
g_pEventLoopManager->addTimer(timer);
updateTimer();
LOGM(LOG, "Registered idle-notification for {}ms", timeoutMs_);
}
CExtIdleNotification::~CExtIdleNotification() {
g_pEventLoopManager->removeTimer(timer);
timer.reset();
}
bool CExtIdleNotification::good() {
return resource->resource();
}
void CExtIdleNotification::updateTimer() {
if (PROTO::idle->isInhibited)
timer->updateTimeout(std::nullopt);
else
timer->updateTimeout(std::chrono::milliseconds(timeoutMs));
}
void CExtIdleNotification::onTimerFired() {
resource->sendIdled();
idled = true;
}
void CExtIdleNotification::onActivity() {
if (idled)
resource->sendResumed();
idled = false;
updateTimer();
}
CIdleNotifyProtocol::CIdleNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}
void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CExtIdleNotifierV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CExtIdleNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
RESOURCE->setGetIdleNotification([this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat); });
}
void CIdleNotifyProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
}
void CIdleNotifyProtocol::destroyNotification(CExtIdleNotification* notif) {
std::erase_if(m_vNotifications, [&](const auto& other) { return other.get() == notif; });
}
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) {
const auto CLIENT = wl_resource_get_client(pMgr->resource());
const auto RESOURCE =
m_vNotifications
.emplace_back(std::make_unique<CExtIdleNotification>(std::make_shared<CExtIdleNotificationV1>(CLIENT, wl_resource_get_version(pMgr->resource()), id), timeout))
.get();
if (!RESOURCE->good()) {
wl_resource_post_no_memory(pMgr->resource());
m_vNotifications.pop_back();
return;
}
}
void CIdleNotifyProtocol::onActivity() {
for (auto& n : m_vNotifications) {
n->onActivity();
}
}
void CIdleNotifyProtocol::setInhibit(bool inhibited) {
isInhibited = inhibited;
for (auto& n : m_vNotifications) {
n->onActivity();
}
}

View file

@ -0,0 +1,55 @@
#pragma once
#include <memory>
#include <vector>
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "ext-idle-notify-v1.hpp"
class CEventLoopTimer;
class CExtIdleNotification {
public:
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs);
~CExtIdleNotification();
bool good();
void onTimerFired();
void onActivity();
private:
SP<CExtIdleNotificationV1> resource;
uint32_t timeoutMs = 0;
std::shared_ptr<CEventLoopTimer> timer;
bool idled = false;
void updateTimer();
};
class CIdleNotifyProtocol : public IWaylandProtocol {
public:
CIdleNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name);
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void onActivity();
void setInhibit(bool inhibited);
private:
void onManagerResourceDestroy(wl_resource* res);
void destroyNotification(CExtIdleNotification* notif);
void onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat);
bool isInhibited = false;
//
std::vector<UP<CExtIdleNotifierV1>> m_vManagers;
std::vector<SP<CExtIdleNotification>> m_vNotifications;
friend class CExtIdleNotification;
};
namespace PROTO {
inline UP<CIdleNotifyProtocol> idle;
};