summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
authorIkalco <73481042+ikalco@users.noreply.github.com>2024-07-24 12:07:36 -0500
committerGitHub <noreply@github.com>2024-07-24 19:07:36 +0200
commit3e543d2ce8ba64abb4d226dbb88c4513474501cf (patch)
treed340935c65520e293a73623c148219993e38779b /src/protocols
parent735e3c6c56d22059ee6340c0327e4b5a9154f013 (diff)
core: Properly shutdown wl display (#7018)
* correctly destroy wayland globals * properly shutdown and cleanup hyprland * appease the nitpick gods and some comments
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/GlobalShortcuts.cpp11
-rw-r--r--src/protocols/GlobalShortcuts.hpp7
-rw-r--r--src/protocols/Screencopy.cpp9
-rw-r--r--src/protocols/Screencopy.hpp21
-rw-r--r--src/protocols/TextInputV1.cpp11
-rw-r--r--src/protocols/TextInputV1.hpp28
-rw-r--r--src/protocols/ToplevelExport.cpp9
-rw-r--r--src/protocols/ToplevelExport.hpp23
-rw-r--r--src/protocols/WaylandProtocol.cpp3
-rw-r--r--src/protocols/WaylandProtocol.hpp5
10 files changed, 82 insertions, 45 deletions
diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp
index b376cae3..898f0e07 100644
--- a/src/protocols/GlobalShortcuts.cpp
+++ b/src/protocols/GlobalShortcuts.cpp
@@ -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; });
}
-} \ No newline at end of file
+}
diff --git a/src/protocols/GlobalShortcuts.hpp b/src/protocols/GlobalShortcuts.hpp
index 07c484c6..5fd03465 100644
--- a/src/protocols/GlobalShortcuts.hpp
+++ b/src/protocols/GlobalShortcuts.hpp
@@ -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;
-}; \ No newline at end of file
+};
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp
index 5d1c9332..98cb0be9 100644
--- a/src/protocols/Screencopy.cpp
+++ b/src/protocols/Screencopy.cpp
@@ -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);
diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp
index 4999773b..d564e432 100644
--- a/src/protocols/Screencopy.hpp
+++ b/src/protocols/Screencopy.hpp
@@ -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;
-}; \ No newline at end of file
+};
diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp
index 7c16ef8c..12068671 100644
--- a/src/protocols/TextInputV1.cpp
+++ b/src/protocols/TextInputV1.cpp
@@ -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) {
;
-} \ No newline at end of file
+}
diff --git a/src/protocols/TextInputV1.hpp b/src/protocols/TextInputV1.hpp
index 0a1203f0..e56a8990 100644
--- a/src/protocols/TextInputV1.hpp
+++ b/src/protocols/TextInputV1.hpp
@@ -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;
-}; \ No newline at end of file
+};
diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp
index e982ad6f..28f49c6a 100644
--- a/src/protocols/ToplevelExport.cpp
+++ b/src/protocols/ToplevelExport.cpp
@@ -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
diff --git a/src/protocols/ToplevelExport.hpp b/src/protocols/ToplevelExport.hpp
index c3620d41..71a6df18 100644
--- a/src/protocols/ToplevelExport.hpp
+++ b/src/protocols/ToplevelExport.hpp
@@ -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;
-}; \ No newline at end of file
+};
diff --git a/src/protocols/WaylandProtocol.cpp b/src/protocols/WaylandProtocol.cpp
index 23a6721c..71c43300 100644
--- a/src/protocols/WaylandProtocol.cpp
+++ b/src/protocols/WaylandProtocol.cpp
@@ -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() {
diff --git a/src/protocols/WaylandProtocol.hpp b/src/protocols/WaylandProtocol.hpp
index b443e253..6154fa30 100644
--- a/src/protocols/WaylandProtocol.hpp
+++ b/src/protocols/WaylandProtocol.hpp
@@ -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;
-}; \ No newline at end of file
+};