From ceae5d7357f47aeca2c9d879d72661c76dd58b74 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 2 Sep 2022 21:24:01 +0200 Subject: [PATCH] make LSes transparent on not-selecting displays --- src/events/Events.cpp | 8 ++- src/hyprpicker.cpp | 112 ++++++++++++++++++++++-------------------- src/hyprpicker.hpp | 2 +- 3 files changed, 68 insertions(+), 54 deletions(-) diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 808c815..de52ec8 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -81,6 +81,8 @@ void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilit } void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { + g_pHyprpicker->markDirty(); + for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) { if (ls->pSurface == surface) { g_pHyprpicker->m_pLastSurface = ls.get(); @@ -94,7 +96,11 @@ void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint3 } void Events::handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) { - // ignored + for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) { + if (ls->pSurface == surface) { + g_pHyprpicker->renderSurface(ls.get(), true); + } + } } void Events::handlePointerAxis(void *data, wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { diff --git a/src/hyprpicker.cpp b/src/hyprpicker.cpp index 18343ba..4c1802b 100644 --- a/src/hyprpicker.cpp +++ b/src/hyprpicker.cpp @@ -219,7 +219,7 @@ void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) { } } -void CHyprpicker::renderSurface(CLayerSurface* pSurface) { +void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) { const auto PBUFFER = getBufferForLS(pSurface); if (!PBUFFER || !pSurface->screenBuffer.buffer) @@ -241,72 +241,80 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface) { cairo_rectangle(PCAIRO, 0, 0, pSurface->m_pMonitor->size.x * pSurface->m_pMonitor->scale, pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale); cairo_fill(PCAIRO); - const auto SCALEBUFS = Vector2D { pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y }; - const auto SCALECURSOR = Vector2D{ - g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale), - g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.y / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.y / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale)}; - const auto CLICKPOS = Vector2D{g_pHyprpicker->m_vLastCoords.floor().x * SCALECURSOR.x, g_pHyprpicker->m_vLastCoords.floor().y * SCALECURSOR.y}; + if (pSurface == g_pHyprpicker->m_pLastSurface && !forceInactive) { + const auto SCALEBUFS = Vector2D{pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y}; + const auto SCALECURSOR = Vector2D{ + g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale), + g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.y / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.y / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale)}; + const auto CLICKPOS = Vector2D{g_pHyprpicker->m_vLastCoords.floor().x * SCALECURSOR.x, g_pHyprpicker->m_vLastCoords.floor().y * SCALECURSOR.y}; - const auto PATTERNPRE = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface); - cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR); - cairo_matrix_t matrixPre; - cairo_matrix_init_identity(&matrixPre); - cairo_matrix_scale(&matrixPre, SCALEBUFS.x, SCALEBUFS.y); - cairo_pattern_set_matrix(PATTERNPRE, &matrixPre); - cairo_set_source(PCAIRO, PATTERNPRE); - cairo_paint(PCAIRO); + const auto PATTERNPRE = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface); + cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR); + cairo_matrix_t matrixPre; + cairo_matrix_init_identity(&matrixPre); + cairo_matrix_scale(&matrixPre, SCALEBUFS.x, SCALEBUFS.y); + cairo_pattern_set_matrix(PATTERNPRE, &matrixPre); + cairo_set_source(PCAIRO, PATTERNPRE); + cairo_paint(PCAIRO); - cairo_surface_flush(PBUFFER->surface); + cairo_surface_flush(PBUFFER->surface); - cairo_pattern_destroy(PATTERNPRE); + cairo_pattern_destroy(PATTERNPRE); - // we draw the preview like this - // - // 200px ZOOM: 10x - // | --------- | - // | | - // | x | 200px - // | | - // | --------- | - // + // we draw the preview like this + // + // 200px ZOOM: 10x + // | --------- | + // | | + // | x | 200px + // | | + // | --------- | + // - cairo_restore(PCAIRO); - cairo_save(PCAIRO); + + cairo_restore(PCAIRO); + cairo_save(PCAIRO); - const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS); - cairo_set_source_rgba(PCAIRO, PIXCOLOR.r / 255.f, PIXCOLOR.g / 255.f, PIXCOLOR.b / 255.f, PIXCOLOR.a / 255.f); + const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS); + cairo_set_source_rgba(PCAIRO, PIXCOLOR.r / 255.f, PIXCOLOR.g / 255.f, PIXCOLOR.b / 255.f, PIXCOLOR.a / 255.f); - cairo_scale(PCAIRO, 1, 1); + cairo_scale(PCAIRO, 1, 1); - cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 105 / SCALEBUFS.x, 0, 2 * M_PI); - cairo_clip(PCAIRO); + cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 105 / SCALEBUFS.x, 0, 2 * M_PI); + cairo_clip(PCAIRO); - cairo_fill(PCAIRO); - cairo_paint(PCAIRO); + cairo_fill(PCAIRO); + cairo_paint(PCAIRO); - cairo_surface_flush(PBUFFER->surface); + cairo_surface_flush(PBUFFER->surface); - cairo_restore(PCAIRO); - cairo_save(PCAIRO); + cairo_restore(PCAIRO); + cairo_save(PCAIRO); - const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface); - cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST); - cairo_matrix_t matrix; - cairo_matrix_init_identity(&matrix); - cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f); - cairo_matrix_scale(&matrix, 0.1f, 0.1f); - cairo_matrix_translate(&matrix, - CLICKPOS.x / SCALEBUFS.x - 0.5f, - CLICKPOS.y / SCALEBUFS.y - 0.5f); - cairo_pattern_set_matrix(PATTERN, &matrix); - cairo_set_source(PCAIRO, PATTERN); - cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 100 / SCALEBUFS.x, 0, 2 * M_PI); - cairo_clip(PCAIRO); - cairo_paint(PCAIRO); + const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface); + cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST); + cairo_matrix_t matrix; + cairo_matrix_init_identity(&matrix); + cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f); + cairo_matrix_scale(&matrix, 0.1f, 0.1f); + cairo_matrix_translate(&matrix, -CLICKPOS.x / SCALEBUFS.x - 0.5f, -CLICKPOS.y / SCALEBUFS.y - 0.5f); + cairo_pattern_set_matrix(PATTERN, &matrix); + cairo_set_source(PCAIRO, PATTERN); + cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 100 / SCALEBUFS.x, 0, 2 * M_PI); + cairo_clip(PCAIRO); + cairo_paint(PCAIRO); - cairo_surface_flush(PBUFFER->surface); + cairo_surface_flush(PBUFFER->surface); - cairo_restore(PCAIRO); + cairo_restore(PCAIRO); - cairo_pattern_destroy(PATTERN); + cairo_pattern_destroy(PATTERN); + } else { + cairo_set_operator(PCAIRO, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgba(PCAIRO, 0, 0, 0, 0); + cairo_rectangle(PCAIRO, 0, 0, pSurface->m_pMonitor->size.x * pSurface->m_pMonitor->scale, pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale); + cairo_fill(PCAIRO); + } sendFrame(pSurface); cairo_destroy(PCAIRO); diff --git a/src/hyprpicker.hpp b/src/hyprpicker.hpp index 9ef6563..c04be90 100644 --- a/src/hyprpicker.hpp +++ b/src/hyprpicker.hpp @@ -37,7 +37,7 @@ public: Vector2D m_vLastCoords; - void renderSurface(CLayerSurface*); + void renderSurface(CLayerSurface*, bool forceInactive = false); void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t); void destroyBuffer(SPoolBuffer*);