2022-09-02 18:06:00 +02:00
|
|
|
#include "LayerSurface.hpp"
|
|
|
|
|
|
2023-02-03 10:46:18 +00:00
|
|
|
#include "../hyprpicker.hpp"
|
2022-09-02 18:06:00 +02:00
|
|
|
|
2025-02-22 01:32:08 +05:00
|
|
|
CLayerSurface::CLayerSurface(SMonitor* pMonitor) : m_pMonitor(pMonitor) {
|
2024-09-26 12:58:43 +01:00
|
|
|
pSurface = makeShared<CCWlSurface>(g_pHyprpicker->m_pCompositor->sendCreateSurface());
|
2022-09-02 18:06:00 +02:00
|
|
|
|
|
|
|
|
if (!pSurface) {
|
|
|
|
|
Debug::log(CRIT, "The compositor did not allow hyprpicker a surface!");
|
|
|
|
|
g_pHyprpicker->finish(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-29 18:12:50 +01:00
|
|
|
if (!g_pHyprpicker->m_bNoFractional) {
|
|
|
|
|
pViewport = makeShared<CCWpViewport>(g_pHyprpicker->m_pViewporter->sendGetViewport(pSurface->resource()));
|
|
|
|
|
|
|
|
|
|
// this will not actually be used, as we assume we'll be fullscreen and we can get the real dimensions from screencopy, but we'll have
|
|
|
|
|
// this for if we need it in the future
|
|
|
|
|
pFractionalScale = makeShared<CCWpFractionalScaleV1>(g_pHyprpicker->m_pFractionalMgr->sendGetFractionalScale(pSurface->resource()));
|
|
|
|
|
pFractionalScale->setPreferredScale([this](CCWpFractionalScaleV1* r, uint32_t scale120) { //
|
|
|
|
|
Debug::log(TRACE, "Received a preferredScale for %s: %.2f", m_pMonitor->name.c_str(), scale120 / 120.F);
|
2024-11-09 23:02:33 +00:00
|
|
|
fractionalScale = scale120 / 120.F;
|
|
|
|
|
wantsReload = true;
|
|
|
|
|
g_pHyprpicker->recheckACK();
|
2024-09-29 18:12:50 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 12:58:43 +01:00
|
|
|
pLayerSurface = makeShared<CCZwlrLayerSurfaceV1>(
|
|
|
|
|
g_pHyprpicker->m_pLayerShell->sendGetLayerSurface(pSurface->resource(), pMonitor->output->resource(), ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "hyprpicker"));
|
2022-09-02 18:06:00 +02:00
|
|
|
|
|
|
|
|
if (!pLayerSurface) {
|
|
|
|
|
Debug::log(CRIT, "The compositor did not allow hyprpicker a layersurface!");
|
|
|
|
|
g_pHyprpicker->finish(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 12:58:43 +01:00
|
|
|
pLayerSurface->setConfigure([this](CCZwlrLayerSurfaceV1* r, uint32_t serial, uint32_t width, uint32_t height) {
|
|
|
|
|
m_pMonitor->size = {(double)width, (double)height};
|
|
|
|
|
ACKSerial = serial;
|
|
|
|
|
wantsACK = true;
|
|
|
|
|
working = true;
|
|
|
|
|
|
|
|
|
|
g_pHyprpicker->recheckACK();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pLayerSurface->sendSetSize(0, 0);
|
|
|
|
|
pLayerSurface->sendSetAnchor((zwlrLayerSurfaceV1Anchor)(ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
|
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT));
|
|
|
|
|
pLayerSurface->sendSetExclusiveZone(-1);
|
|
|
|
|
pLayerSurface->sendSetKeyboardInteractivity(1);
|
|
|
|
|
pSurface->sendCommit();
|
2022-09-02 18:06:00 +02:00
|
|
|
|
|
|
|
|
wl_display_flush(g_pHyprpicker->m_pWLDisplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLayerSurface::~CLayerSurface() {
|
2024-09-26 12:58:43 +01:00
|
|
|
pLayerSurface.reset();
|
|
|
|
|
pSurface.reset();
|
|
|
|
|
frameCallback.reset();
|
2022-09-02 18:06:00 +02:00
|
|
|
|
2023-02-03 10:46:18 +00:00
|
|
|
if (g_pHyprpicker->m_pWLDisplay)
|
|
|
|
|
wl_display_flush(g_pHyprpicker->m_pWLDisplay);
|
2024-09-26 12:58:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this has to be a separate function because frameCallback.reset() will destroy the listener func
|
|
|
|
|
static void onCallbackDone(CLayerSurface* surf, uint32_t when) {
|
|
|
|
|
surf->frameCallback.reset();
|
|
|
|
|
|
|
|
|
|
if (surf->dirty || !surf->rendered)
|
|
|
|
|
g_pHyprpicker->renderSurface(g_pHyprpicker->m_pLastSurface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLayerSurface::sendFrame() {
|
2025-03-21 04:35:34 -04:00
|
|
|
lastBuffer = lastBuffer == 0 ? 1 : 0;
|
|
|
|
|
const auto& PBUFFER = buffers[lastBuffer];
|
|
|
|
|
|
2024-09-26 12:58:43 +01:00
|
|
|
frameCallback = makeShared<CCWlCallback>(pSurface->sendFrame());
|
|
|
|
|
frameCallback->setDone([this](CCWlCallback* r, uint32_t when) { onCallbackDone(this, when); });
|
2023-05-29 19:09:55 +02:00
|
|
|
|
2024-09-29 18:12:50 +01:00
|
|
|
pSurface->sendAttach(PBUFFER->buffer.get(), 0, 0);
|
|
|
|
|
if (!g_pHyprpicker->m_bNoFractional) {
|
|
|
|
|
pSurface->sendSetBufferScale(1);
|
|
|
|
|
pViewport->sendSetDestination(m_pMonitor->size.x, m_pMonitor->size.y);
|
|
|
|
|
} else
|
|
|
|
|
pSurface->sendSetBufferScale(m_pMonitor->scale);
|
|
|
|
|
|
2024-09-26 12:58:43 +01:00
|
|
|
pSurface->sendCommit();
|
|
|
|
|
|
|
|
|
|
dirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLayerSurface::markDirty() {
|
|
|
|
|
frameCallback = makeShared<CCWlCallback>(pSurface->sendFrame());
|
2024-09-30 15:05:42 +01:00
|
|
|
frameCallback->setDone([this](CCWlCallback* r, uint32_t when) { onCallbackDone(this, when); });
|
2025-03-21 04:35:34 -04:00
|
|
|
|
|
|
|
|
pSurface->sendDamageBuffer(0, 0, 0xFFFF, 0xFFFF);
|
|
|
|
|
|
|
|
|
|
if (buffers[lastBuffer])
|
|
|
|
|
pSurface->sendAttach(buffers[lastBuffer]->buffer.get(), 0, 0);
|
|
|
|
|
|
2024-09-26 12:58:43 +01:00
|
|
|
pSurface->sendCommit();
|
|
|
|
|
|
|
|
|
|
dirty = true;
|
|
|
|
|
}
|