diff --git a/src/events/Events.cpp b/src/events/Events.cpp index d5eedb1..6c1828d 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -276,7 +276,8 @@ void Events::handleBufferRelease(void* data, struct wl_buffer* wl_buffer) { void Events::handleSCBuffer(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) { const auto PLS = (CLayerSurface*)data; - g_pHyprpicker->createBuffer(&PLS->screenBuffer, width, height, format, stride); + if (!PLS->screenBuffer.buffer) + g_pHyprpicker->createBuffer(&PLS->screenBuffer, width, height, format, stride); zwlr_screencopy_frame_v1_copy(frame, PLS->screenBuffer.buffer); } diff --git a/src/helpers/LayerSurface.cpp b/src/helpers/LayerSurface.cpp index aaacca8..50ff3cb 100644 --- a/src/helpers/LayerSurface.cpp +++ b/src/helpers/LayerSurface.cpp @@ -23,7 +23,8 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) { } zwlr_layer_surface_v1_set_size(pLayerSurface, 0, 0); - zwlr_layer_surface_v1_set_anchor(pLayerSurface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); + zwlr_layer_surface_v1_set_anchor( + pLayerSurface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); zwlr_layer_surface_v1_set_exclusive_zone(pLayerSurface, -1); zwlr_layer_surface_v1_set_keyboard_interactivity(pLayerSurface, true); zwlr_layer_surface_v1_add_listener(pLayerSurface, &Events::layersurfaceListener, this); @@ -38,4 +39,8 @@ CLayerSurface::~CLayerSurface() { if (g_pHyprpicker->m_pWLDisplay) wl_display_flush(g_pHyprpicker->m_pWLDisplay); + + g_pHyprpicker->destroyBuffer(&buffers[0]); + g_pHyprpicker->destroyBuffer(&buffers[1]); + g_pHyprpicker->destroyBuffer(&screenBuffer); } \ No newline at end of file diff --git a/src/hyprpicker.cpp b/src/hyprpicker.cpp index 8ff968d..282b891 100644 --- a/src/hyprpicker.cpp +++ b/src/hyprpicker.cpp @@ -1,7 +1,12 @@ #include "hyprpicker.hpp" - +#include #include "events/Events.hpp" +void sigHandler(int sig) { + g_pHyprpicker->m_vLayerSurfaces.clear(); + exit(0); +} + void CHyprpicker::init() { m_pWLDisplay = wl_display_connect(nullptr); @@ -11,6 +16,8 @@ void CHyprpicker::init() { return; } + signal(SIGTERM, sigHandler); + m_pWLRegistry = wl_display_get_registry(m_pWLDisplay); wl_registry_add_listener(m_pWLRegistry, &Events::registryListener, nullptr); @@ -42,12 +49,6 @@ void CHyprpicker::init() { } void CHyprpicker::finish(int code) { - for (auto& ls : m_vLayerSurfaces) { - destroyBuffer(&ls->buffers[0]); - destroyBuffer(&ls->buffers[1]); - destroyBuffer(&ls->screenBuffer); - } - m_vLayerSurfaces.clear(); if (m_pWLDisplay) {