make LSes transparent on not-selecting displays

This commit is contained in:
vaxerski 2022-09-02 21:24:01 +02:00
parent a110c397e2
commit ceae5d7357
3 changed files with 68 additions and 54 deletions

View file

@ -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) { 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) { for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) {
if (ls->pSurface == surface) { if (ls->pSurface == surface) {
g_pHyprpicker->m_pLastSurface = ls.get(); 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) { 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) { void Events::handlePointerAxis(void *data, wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {

View file

@ -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); const auto PBUFFER = getBufferForLS(pSurface);
if (!PBUFFER || !pSurface->screenBuffer.buffer) 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_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); cairo_fill(PCAIRO);
const auto SCALEBUFS = Vector2D { pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y }; if (pSurface == g_pHyprpicker->m_pLastSurface && !forceInactive) {
const auto SCALECURSOR = Vector2D{ const auto SCALEBUFS = Vector2D{pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y};
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale), const auto SCALECURSOR = Vector2D{
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.y / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.y / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale)}; g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / 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}; 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); const auto PATTERNPRE = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface);
cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR); cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR);
cairo_matrix_t matrixPre; cairo_matrix_t matrixPre;
cairo_matrix_init_identity(&matrixPre); cairo_matrix_init_identity(&matrixPre);
cairo_matrix_scale(&matrixPre, SCALEBUFS.x, SCALEBUFS.y); cairo_matrix_scale(&matrixPre, SCALEBUFS.x, SCALEBUFS.y);
cairo_pattern_set_matrix(PATTERNPRE, &matrixPre); cairo_pattern_set_matrix(PATTERNPRE, &matrixPre);
cairo_set_source(PCAIRO, PATTERNPRE); cairo_set_source(PCAIRO, PATTERNPRE);
cairo_paint(PCAIRO); 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 // we draw the preview like this
// //
// 200px ZOOM: 10x // 200px ZOOM: 10x
// | --------- | // | --------- |
// | | // | |
// | x | 200px // | x | 200px
// | | // | |
// | --------- | // | --------- |
// //
cairo_restore(PCAIRO);
cairo_save(PCAIRO); cairo_restore(PCAIRO);
cairo_save(PCAIRO);
const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS); 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_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_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_clip(PCAIRO);
cairo_fill(PCAIRO); cairo_fill(PCAIRO);
cairo_paint(PCAIRO); cairo_paint(PCAIRO);
cairo_surface_flush(PBUFFER->surface); cairo_surface_flush(PBUFFER->surface);
cairo_restore(PCAIRO); cairo_restore(PCAIRO);
cairo_save(PCAIRO); cairo_save(PCAIRO);
const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface); const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface);
cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST); cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST);
cairo_matrix_t matrix; cairo_matrix_t matrix;
cairo_matrix_init_identity(&matrix); cairo_matrix_init_identity(&matrix);
cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f); cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f);
cairo_matrix_scale(&matrix, 0.1f, 0.1f); 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_matrix_translate(&matrix, -CLICKPOS.x / SCALEBUFS.x - 0.5f, -CLICKPOS.y / SCALEBUFS.y - 0.5f);
cairo_pattern_set_matrix(PATTERN, &matrix); cairo_pattern_set_matrix(PATTERN, &matrix);
cairo_set_source(PCAIRO, PATTERN); 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_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_clip(PCAIRO);
cairo_paint(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); sendFrame(pSurface);
cairo_destroy(PCAIRO); cairo_destroy(PCAIRO);

View file

@ -37,7 +37,7 @@ public:
Vector2D m_vLastCoords; Vector2D m_vLastCoords;
void renderSurface(CLayerSurface*); void renderSurface(CLayerSurface*, bool forceInactive = false);
void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t); void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t);
void destroyBuffer(SPoolBuffer*); void destroyBuffer(SPoolBuffer*);