mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-19 08:09:50 +01:00
1ed1ce9506
moves std::shared_ptrs to a new implementation Advantages: - you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired. - this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.) - weak_ptrs are still valid while the SP is being destroyed. - reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection) - this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though. - this is useful in destructors and callbacks.
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#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;
|
|
SP<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;
|
|
};
|