core: Properly shutdown wl display (#7018)

* correctly destroy wayland globals

* properly shutdown and cleanup hyprland

* appease the nitpick gods and some comments
This commit is contained in:
Ikalco
2024-07-24 12:07:36 -05:00
committed by GitHub
parent 735e3c6c56
commit 3e543d2ce8
17 changed files with 161 additions and 60 deletions

View File

@@ -8,13 +8,20 @@ static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint
}
static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->displayDestroy();
CGlobalShortcutsProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
proto->displayDestroy();
}
void CGlobalShortcutsProtocolManager::displayDestroy() {
wl_list_remove(&m_liDisplayDestroy.link);
wl_list_init(&m_liDisplayDestroy.link);
wl_global_destroy(m_pGlobal);
}
CGlobalShortcutsProtocolManager::~CGlobalShortcutsProtocolManager() {
displayDestroy();
}
CGlobalShortcutsProtocolManager::CGlobalShortcutsProtocolManager() {
m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, &hyprland_global_shortcuts_manager_v1_interface, GLOBAL_SHORTCUTS_VERSION, this, bindManagerInt);
@@ -148,4 +155,4 @@ void CGlobalShortcutsProtocolManager::destroyShortcut(wl_resource* resource) {
for (auto& c : m_vClients) {
std::erase_if(c->shortcuts, [&](const auto& other) { return other->resource == resource; });
}
}
}

View File

@@ -17,6 +17,8 @@ struct SShortcutClient {
class CGlobalShortcutsProtocolManager {
public:
CGlobalShortcutsProtocolManager();
~CGlobalShortcutsProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void displayDestroy();
@@ -29,11 +31,12 @@ class CGlobalShortcutsProtocolManager {
std::vector<SShortcut> getAllShortcuts();
wl_listener m_liDisplayDestroy;
private:
std::vector<std::unique_ptr<SShortcutClient>> m_vClients;
SShortcutClient* clientFromWlClient(wl_client* client);
wl_global* m_pGlobal = nullptr;
wl_listener m_liDisplayDestroy;
};
};

View File

@@ -16,15 +16,22 @@ static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint
}
static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
g_pProtocolManager->m_pScreencopyProtocolManager->displayDestroy();
CScreencopyProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
proto->displayDestroy();
}
void CScreencopyProtocolManager::displayDestroy() {
wl_list_remove(&m_liDisplayDestroy.link);
wl_list_init(&m_liDisplayDestroy.link);
wl_global_destroy(m_pGlobal);
}
static SScreencopyFrame* frameFromResource(wl_resource*);
CScreencopyProtocolManager::~CScreencopyProtocolManager() {
displayDestroy();
}
CScreencopyProtocolManager::CScreencopyProtocolManager() {
m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, &zwlr_screencopy_manager_v1_interface, SCREENCOPY_VERSION, this, bindManagerInt);

View File

@@ -70,17 +70,20 @@ struct SScreencopyFrame {
class CScreencopyProtocolManager {
public:
CScreencopyProtocolManager();
~CScreencopyProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void removeClient(CScreencopyClient* client, bool force = false);
void removeFrame(SScreencopyFrame* frame, bool force = false);
void displayDestroy();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void removeClient(CScreencopyClient* client, bool force = false);
void removeFrame(SScreencopyFrame* frame, bool force = false);
void displayDestroy();
void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box = {0, 0, 0, 0});
void captureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output, CBox box = {0, 0, 0, 0});
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer);
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer);
void onOutputCommit(CMonitor* pMonitor);
void onOutputCommit(CMonitor* pMonitor);
wl_listener m_liDisplayDestroy;
private:
wl_global* m_pGlobal = nullptr;
@@ -90,8 +93,6 @@ class CScreencopyProtocolManager {
SP<CEventLoopTimer> m_pSoftwareCursorTimer;
bool m_bTimerArmed = false;
wl_listener m_liDisplayDestroy;
std::vector<SScreencopyFrame*> m_vFramesAwaitingWrite;
SP<Aquamarine::IBuffer> m_pLastMonitorBackBuffer;
@@ -103,4 +104,4 @@ class CScreencopyProtocolManager {
bool copyFrameShm(SScreencopyFrame* frame, timespec* now);
friend class CScreencopyClient;
};
};

View File

@@ -10,13 +10,20 @@ static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint
}
static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->displayDestroy();
CTextInputV1ProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
proto->displayDestroy();
}
void CTextInputV1ProtocolManager::displayDestroy() {
wl_list_remove(&m_liDisplayDestroy.link);
wl_list_init(&m_liDisplayDestroy.link);
wl_global_destroy(m_pGlobal);
}
CTextInputV1ProtocolManager::~CTextInputV1ProtocolManager() {
displayDestroy();
}
CTextInputV1ProtocolManager::CTextInputV1ProtocolManager() {
m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, &zwp_text_input_manager_v1_interface, TEXT_INPUT_VERSION, this, bindManagerInt);
@@ -220,4 +227,4 @@ void CTextInputV1ProtocolManager::handleCommitState(wl_client* client, wl_resour
void CTextInputV1ProtocolManager::handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) {
;
}
}

View File

@@ -47,6 +47,7 @@ struct STextInputV1 {
class CTextInputV1ProtocolManager {
public:
CTextInputV1ProtocolManager();
~CTextInputV1ProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void createTI(wl_client* client, wl_resource* resource, uint32_t id);
@@ -55,21 +56,22 @@ class CTextInputV1ProtocolManager {
void displayDestroy();
// handlers for tiv1
void handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface);
void handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat);
void handleShowInputPanel(wl_client* client, wl_resource* resource);
void handleHideInputPanel(wl_client* client, wl_resource* resource);
void handleReset(wl_client* client, wl_resource* resource);
void handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor);
void handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose);
void handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height);
void handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language);
void handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial);
void handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index);
void handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface);
void handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat);
void handleShowInputPanel(wl_client* client, wl_resource* resource);
void handleHideInputPanel(wl_client* client, wl_resource* resource);
void handleReset(wl_client* client, wl_resource* resource);
void handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor);
void handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose);
void handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height);
void handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language);
void handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial);
void handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index);
wl_listener m_liDisplayDestroy;
private:
wl_global* m_pGlobal = nullptr;
wl_listener m_liDisplayDestroy;
std::vector<std::unique_ptr<STextInputV1>> m_pClients;
};
};

View File

@@ -15,13 +15,20 @@ static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint
}
static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
g_pProtocolManager->m_pToplevelExportProtocolManager->displayDestroy();
CToplevelExportProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
proto->displayDestroy();
}
void CToplevelExportProtocolManager::displayDestroy() {
wl_list_remove(&m_liDisplayDestroy.link);
wl_list_init(&m_liDisplayDestroy.link);
wl_global_destroy(m_pGlobal);
}
CToplevelExportProtocolManager::~CToplevelExportProtocolManager() {
displayDestroy();
}
CToplevelExportProtocolManager::CToplevelExportProtocolManager() {
#ifndef GLES32

View File

@@ -13,23 +13,24 @@ class CWindow;
class CToplevelExportProtocolManager {
public:
CToplevelExportProtocolManager();
~CToplevelExportProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void captureToplevel(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, PHLWINDOW handle);
void removeClient(CScreencopyClient* client, bool force = false);
void removeFrame(SScreencopyFrame* frame, bool force = false);
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage);
void displayDestroy();
void onWindowUnmap(PHLWINDOW pWindow);
void onOutputCommit(CMonitor* pMonitor);
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void captureToplevel(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, PHLWINDOW handle);
void removeClient(CScreencopyClient* client, bool force = false);
void removeFrame(SScreencopyFrame* frame, bool force = false);
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage);
void displayDestroy();
void onWindowUnmap(PHLWINDOW pWindow);
void onOutputCommit(CMonitor* pMonitor);
wl_listener m_liDisplayDestroy;
private:
wl_global* m_pGlobal = nullptr;
std::list<SScreencopyFrame> m_lFrames;
std::list<CScreencopyClient> m_lClients;
wl_listener m_liDisplayDestroy;
std::vector<SScreencopyFrame*> m_vFramesAwaitingWrite;
void shareFrame(SScreencopyFrame* frame);
@@ -38,4 +39,4 @@ class CToplevelExportProtocolManager {
void sendDamage(SScreencopyFrame* frame);
friend class CScreencopyClient;
};
};

View File

@@ -6,7 +6,8 @@ static void bindManagerInternal(wl_client* client, void* data, uint32_t ver, uin
}
static void displayDestroyInternal(struct wl_listener* listener, void* data) {
((IWaylandProtocol*)data)->onDisplayDestroy();
IWaylandProtocol* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
proto->onDisplayDestroy();
}
void IWaylandProtocol::onDisplayDestroy() {

View File

@@ -26,8 +26,9 @@ class IWaylandProtocol {
Debug::log(level, std::format("[{}] ", m_szName) + std::vformat(fmt.get(), std::make_format_args(args...)));
};
wl_listener m_liDisplayDestroy;
private:
std::string m_szName;
wl_global* m_pGlobal = nullptr;
wl_listener m_liDisplayDestroy;
};
};