2024-05-05 04:14:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "WaylandProtocol.hpp"
|
|
|
|
#include "hyprland-focus-grab-v1.hpp"
|
|
|
|
#include "macros.hpp"
|
|
|
|
#include <cstdint>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
2024-06-11 17:17:45 +02:00
|
|
|
#include "../helpers/signal/Signal.hpp"
|
2024-05-05 04:14:35 +02:00
|
|
|
|
|
|
|
class CFocusGrab;
|
2024-05-11 02:02:57 +02:00
|
|
|
class CSeatGrab;
|
2024-06-08 10:07:59 +02:00
|
|
|
class CWLSurfaceResource;
|
2024-05-05 04:14:35 +02:00
|
|
|
|
|
|
|
class CFocusGrabSurfaceState {
|
|
|
|
public:
|
2024-06-08 10:07:59 +02:00
|
|
|
CFocusGrabSurfaceState(CFocusGrab* grab, SP<CWLSurfaceResource> surface);
|
2024-05-05 04:14:35 +02:00
|
|
|
~CFocusGrabSurfaceState();
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
PendingAddition,
|
|
|
|
PendingRemoval,
|
|
|
|
Comitted,
|
|
|
|
} state = PendingAddition;
|
|
|
|
|
|
|
|
private:
|
2024-06-08 10:07:59 +02:00
|
|
|
struct {
|
|
|
|
CHyprSignalListener destroy;
|
|
|
|
} listeners;
|
2024-05-05 04:14:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CFocusGrab {
|
|
|
|
public:
|
|
|
|
CFocusGrab(SP<CHyprlandFocusGrabV1> resource_);
|
|
|
|
~CFocusGrab();
|
|
|
|
|
|
|
|
bool good();
|
2024-06-08 10:07:59 +02:00
|
|
|
bool isSurfaceComitted(SP<CWLSurfaceResource> surface);
|
2024-05-05 04:14:35 +02:00
|
|
|
|
|
|
|
void start();
|
|
|
|
void finish(bool sendCleared);
|
|
|
|
|
|
|
|
private:
|
2024-06-08 10:07:59 +02:00
|
|
|
void addSurface(SP<CWLSurfaceResource> surface);
|
|
|
|
void removeSurface(SP<CWLSurfaceResource> surface);
|
|
|
|
void eraseSurface(SP<CWLSurfaceResource> surface);
|
|
|
|
void refocusKeyboard();
|
|
|
|
void commit(bool removeOnly = false);
|
2024-05-05 04:14:35 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CHyprlandFocusGrabV1> resource;
|
|
|
|
std::unordered_map<WP<CWLSurfaceResource>, UP<CFocusGrabSurfaceState>> m_mSurfaces;
|
|
|
|
SP<CSeatGrab> grab;
|
2024-05-11 02:02:57 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
bool m_bGrabActive = false;
|
2024-05-05 04:14:35 +02:00
|
|
|
|
|
|
|
friend class CFocusGrabSurfaceState;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CFocusGrabProtocol : public IWaylandProtocol {
|
|
|
|
public:
|
|
|
|
CFocusGrabProtocol(const wl_interface* iface, const int& var, const std::string& name);
|
|
|
|
|
|
|
|
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onManagerResourceDestroy(wl_resource* res);
|
|
|
|
void destroyGrab(CFocusGrab* grab);
|
|
|
|
void onCreateGrab(CHyprlandFocusGrabManagerV1* pMgr, uint32_t id);
|
|
|
|
|
|
|
|
std::vector<UP<CHyprlandFocusGrabManagerV1>> m_vManagers;
|
|
|
|
std::vector<UP<CFocusGrab>> m_vGrabs;
|
|
|
|
|
|
|
|
friend class CFocusGrab;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace PROTO {
|
|
|
|
inline UP<CFocusGrabProtocol> focusGrab;
|
|
|
|
}
|