From cd2b2c4fbad70118918bb362919580ca7cc29275 Mon Sep 17 00:00:00 2001 From: Felix Dick Date: Mon, 26 Sep 2022 17:38:08 +0200 Subject: [PATCH 1/5] Scale the border size, revert the window scaling according to border --- src/layout/DwindleLayout.cpp | 9 ++++----- src/layout/MasterLayout.cpp | 10 ++++------ src/render/OpenGL.cpp | 22 ++++++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 4e4f0829..60a45555 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -182,16 +182,15 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->m_vPosition = pNode->position; static auto *const PNOGAPSWHENONLY = &g_pConfigManager->getConfigValuePtr("dwindle:no_gaps_when_only")->intValue; - float scaledBorderSize = *PBORDERSIZE / PMONITOR->scale; - auto calcPos = PWINDOW->m_vPosition + Vector2D(scaledBorderSize, scaledBorderSize); - auto calcSize = PWINDOW->m_vSize - Vector2D(2 * scaledBorderSize, 2 * scaledBorderSize); + auto calcPos = PWINDOW->m_vPosition + Vector2D(*PBORDERSIZE, *PBORDERSIZE); + auto calcSize = PWINDOW->m_vSize - Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE); const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID); if (*PNOGAPSWHENONLY && PWINDOW->m_iWorkspaceID != SPECIAL_WORKSPACE_ID && (NODESONWORKSPACE == 1 || (pNode->isGroupMember() && pNode->getGroupMemberCount() == NODESONWORKSPACE))) { - PWINDOW->m_vRealPosition = calcPos - Vector2D(scaledBorderSize, scaledBorderSize); - PWINDOW->m_vRealSize = calcSize + Vector2D(2 * scaledBorderSize, 2 * scaledBorderSize); + PWINDOW->m_vRealPosition = calcPos - Vector2D(*PBORDERSIZE, *PBORDERSIZE); + PWINDOW->m_vRealSize = calcSize + Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE); PWINDOW->updateWindowDecos(); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 0a1c5179..d5957e6a 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -241,14 +241,12 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->m_vSize = pNode->size; PWINDOW->m_vPosition = pNode->position; - float scaledBorderSize = *PBORDERSIZE / PMONITOR->scale; - - auto calcPos = PWINDOW->m_vPosition + Vector2D(scaledBorderSize, scaledBorderSize); - auto calcSize = PWINDOW->m_vSize - Vector2D(2 * scaledBorderSize, 2 * scaledBorderSize); + auto calcPos = PWINDOW->m_vPosition + Vector2D(*PBORDERSIZE, *PBORDERSIZE); + auto calcSize = PWINDOW->m_vSize - Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE); if (*PNOGAPSWHENONLY && PWINDOW->m_iWorkspaceID != SPECIAL_WORKSPACE_ID && getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1) { - PWINDOW->m_vRealPosition = calcPos - Vector2D(scaledBorderSize, scaledBorderSize); - PWINDOW->m_vRealSize = calcSize + Vector2D(2 * scaledBorderSize, 2 * scaledBorderSize); + PWINDOW->m_vRealPosition = calcPos - Vector2D(*PBORDERSIZE, *PBORDERSIZE); + PWINDOW->m_vRealSize = calcSize + Vector2D(2 * *PBORDERSIZE, 2 * *PBORDERSIZE); PWINDOW->updateWindowDecos(); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 2ae8d747..e4bbfd68 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -780,27 +780,29 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) { if (*PBORDERSIZE < 1) return; + float scaledBorderSize = *PBORDERSIZE * m_RenderData.pMonitor->scale; + if (round < 1) { // zero rounding, just lines - wlr_box borderbox = {box->x - *PBORDERSIZE, box->y - *PBORDERSIZE, *PBORDERSIZE, box->height + 2 * *PBORDERSIZE}; + wlr_box borderbox = {box->x - scaledBorderSize, box->y - scaledBorderSize, scaledBorderSize, box->height + 2 * scaledBorderSize}; renderRect(&borderbox, col, 0); // left - borderbox = {box->x, box->y - (int)*PBORDERSIZE, box->width + (int)*PBORDERSIZE, (int)*PBORDERSIZE}; + borderbox = {box->x, box->y - (int)scaledBorderSize, box->width + (int)scaledBorderSize, (int)scaledBorderSize}; renderRect(&borderbox, col, 0); // top - borderbox = {box->x + box->width, box->y, (int)*PBORDERSIZE, box->height + (int)*PBORDERSIZE}; + borderbox = {box->x + box->width, box->y, (int)scaledBorderSize, box->height + (int)scaledBorderSize}; renderRect(&borderbox, col, 0); // right - borderbox = {box->x, box->y + box->height, box->width, (int)*PBORDERSIZE}; + borderbox = {box->x, box->y + box->height, box->width, (int)scaledBorderSize}; renderRect(&borderbox, col, 0); // bottom return; } // adjust box - box->x -= *PBORDERSIZE; - box->y -= *PBORDERSIZE; - box->width += 2 * *PBORDERSIZE; - box->height += 2 * *PBORDERSIZE; + box->x -= scaledBorderSize; + box->y -= scaledBorderSize; + box->width += 2 * scaledBorderSize; + box->height += 2 * scaledBorderSize; - round += *PBORDERSIZE; + round += scaledBorderSize; float matrix[9]; wlr_matrix_project_box(matrix, box, wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, m_RenderData.pMonitor->output->transform_matrix); // TODO: write own, don't use WLR here @@ -827,7 +829,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) { glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y); glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y); glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.radius, round); - glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.thick, *PBORDERSIZE); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.thick, scaledBorderSize); glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.primitiveMultisample, *PMULTISAMPLE); glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); From 5233746ac5d1a9d00462662b7778ebbacdc523dd Mon Sep 17 00:00:00 2001 From: Felix Dick Date: Thu, 29 Sep 2022 01:40:19 +0200 Subject: [PATCH 2/5] Change scaledBorderSize to int. --- src/render/OpenGL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index e4bbfd68..e49be083 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -780,7 +780,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) { if (*PBORDERSIZE < 1) return; - float scaledBorderSize = *PBORDERSIZE * m_RenderData.pMonitor->scale; + int scaledBorderSize = *PBORDERSIZE * m_RenderData.pMonitor->scale; if (round < 1) { // zero rounding, just lines From b38e7b596f03dc6f7f6adec36df5bea2325642b5 Mon Sep 17 00:00:00 2001 From: Felix Dick Date: Thu, 29 Sep 2022 21:10:05 +0200 Subject: [PATCH 3/5] Don't pass bottomRight to textureShaders compute it within. --- src/render/OpenGL.cpp | 4 ---- src/render/shaders/Textures.hpp | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index faf91d37..02100b38 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -152,7 +152,6 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shQUAD.posAttrib = glGetAttribLocation(prog, "pos"); m_RenderData.pCurrentMonData->m_shQUAD.texAttrib = glGetAttribLocation(prog, "texcoord"); m_RenderData.pCurrentMonData->m_shQUAD.topLeft = glGetUniformLocation(prog, "topLeft"); - m_RenderData.pCurrentMonData->m_shQUAD.bottomRight = glGetUniformLocation(prog, "bottomRight"); m_RenderData.pCurrentMonData->m_shQUAD.fullSize = glGetUniformLocation(prog, "fullSize"); m_RenderData.pCurrentMonData->m_shQUAD.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shQUAD.primitiveMultisample = glGetUniformLocation(prog, "primitiveMultisample"); @@ -166,7 +165,6 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shRGBA.posAttrib = glGetAttribLocation(prog, "pos"); m_RenderData.pCurrentMonData->m_shRGBA.discardOpaque = glGetUniformLocation(prog, "discardOpaque"); m_RenderData.pCurrentMonData->m_shRGBA.topLeft = glGetUniformLocation(prog, "topLeft"); - m_RenderData.pCurrentMonData->m_shRGBA.bottomRight = glGetUniformLocation(prog, "bottomRight"); m_RenderData.pCurrentMonData->m_shRGBA.fullSize = glGetUniformLocation(prog, "fullSize"); m_RenderData.pCurrentMonData->m_shRGBA.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shRGBA.primitiveMultisample = glGetUniformLocation(prog, "primitiveMultisample"); @@ -182,7 +180,6 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shRGBX.posAttrib = glGetAttribLocation(prog, "pos"); m_RenderData.pCurrentMonData->m_shRGBX.discardOpaque = glGetUniformLocation(prog, "discardOpaque"); m_RenderData.pCurrentMonData->m_shRGBX.topLeft = glGetUniformLocation(prog, "topLeft"); - m_RenderData.pCurrentMonData->m_shRGBX.bottomRight = glGetUniformLocation(prog, "bottomRight"); m_RenderData.pCurrentMonData->m_shRGBX.fullSize = glGetUniformLocation(prog, "fullSize"); m_RenderData.pCurrentMonData->m_shRGBX.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shRGBX.primitiveMultisample = glGetUniformLocation(prog, "primitiveMultisample"); @@ -198,7 +195,6 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shEXT.texAttrib = glGetAttribLocation(prog, "texcoord"); m_RenderData.pCurrentMonData->m_shEXT.discardOpaque = glGetUniformLocation(prog, "discardOpaque"); m_RenderData.pCurrentMonData->m_shEXT.topLeft = glGetUniformLocation(prog, "topLeft"); - m_RenderData.pCurrentMonData->m_shEXT.bottomRight = glGetUniformLocation(prog, "bottomRight"); m_RenderData.pCurrentMonData->m_shEXT.fullSize = glGetUniformLocation(prog, "fullSize"); m_RenderData.pCurrentMonData->m_shEXT.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shEXT.primitiveMultisample = glGetUniformLocation(prog, "primitiveMultisample"); diff --git a/src/render/shaders/Textures.hpp b/src/render/shaders/Textures.hpp index a541ec0a..42bd0856 100644 --- a/src/render/shaders/Textures.hpp +++ b/src/render/shaders/Textures.hpp @@ -6,6 +6,7 @@ inline static constexpr auto ROUNDED_SHADER_FUNC = [](const std::string colorVar return R"#( // branchless baby! + vec2 bottomRight = fullSize - radius; vec2 pixCoord = v_texcoord - vec2(0.5); pixCoord *= (vec2(lessThan(pixCoord, vec2(0.0))) * vec2(-2.0) + vec2(1.0)) * fullSize; pixCoord -= (bottomRight - topLeft) * vec2(0.5); @@ -59,7 +60,6 @@ varying vec4 v_color; varying vec2 v_texcoord; uniform vec2 topLeft; -uniform vec2 bottomRight; uniform vec2 fullSize; uniform float radius; @@ -88,7 +88,6 @@ void main() { v_texcoord = texcoord; })#"; -// this is texture rendering!! inline const std::string TEXFRAGSRCRGBA = R"#( precision mediump float; varying vec2 v_texcoord; // is in 0-1 @@ -96,7 +95,6 @@ uniform sampler2D tex; uniform float alpha; uniform vec2 topLeft; -uniform vec2 bottomRight; uniform vec2 fullSize; uniform float radius; @@ -134,7 +132,6 @@ uniform sampler2D tex; uniform float alpha; uniform vec2 topLeft; -uniform vec2 bottomRight; uniform vec2 fullSize; uniform float radius; @@ -221,7 +218,6 @@ uniform samplerExternalOES texture0; uniform float alpha; uniform vec2 topLeft; -uniform vec2 bottomRight; uniform vec2 fullSize; uniform float radius; From 2d73da1a79fc32bca62da6e9b79b8525ec42fa9c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 29 Sep 2022 22:16:37 +0100 Subject: [PATCH 4/5] enter outputs for non-interactive ls-es too --- src/events/Layers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 975f2d20..daa69fce 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -133,8 +133,9 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID); + wlr_surface_send_enter(layersurface->layerSurface->surface, layersurface->layerSurface->output); + if (layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint)) { // don't focus if constrained - wlr_surface_send_enter(layersurface->layerSurface->surface, layersurface->layerSurface->output); g_pCompositor->focusSurface(layersurface->layerSurface->surface); const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y); From 6eb7d0038644fab09c8512ad34cdcbde1882ffc0 Mon Sep 17 00:00:00 2001 From: Felix Dick Date: Thu, 29 Sep 2022 23:19:56 +0200 Subject: [PATCH 5/5] Send absolute screen coordinates to texture shaders. --- src/render/OpenGL.cpp | 9 +++------ src/render/shaders/Textures.hpp | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 02100b38..29b479b6 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -334,15 +334,13 @@ void CHyprOpenGLImpl::renderRectWithDamage(wlr_box* box, const CColor& col, pixm glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shQUAD.proj, 1, GL_FALSE, glMatrix); glUniform4f(m_RenderData.pCurrentMonData->m_shQUAD.color, col.r / 255.f, col.g / 255.f, col.b / 255.f, col.a / 255.f); - const auto TOPLEFT = Vector2D(round, round); - const auto BOTTOMRIGHT = Vector2D(box->width - round, box->height - round); + const auto TOPLEFT = Vector2D(box->x, box->y); const auto FULLSIZE = Vector2D(box->width, box->height); static auto *const PMULTISAMPLEEDGES = &g_pConfigManager->getConfigValuePtr("decoration:multisample_edges")->intValue; // Rounded corners glUniform2f(m_RenderData.pCurrentMonData->m_shQUAD.topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y); - glUniform2f(m_RenderData.pCurrentMonData->m_shQUAD.bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y); glUniform2f(m_RenderData.pCurrentMonData->m_shQUAD.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y); glUniform1f(m_RenderData.pCurrentMonData->m_shQUAD.radius, round); glUniform1i(m_RenderData.pCurrentMonData->m_shQUAD.primitiveMultisample, (int)(*PMULTISAMPLEEDGES == 1 && round != 0)); @@ -438,9 +436,8 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b static auto *const PMULTISAMPLEEDGES = &g_pConfigManager->getConfigValuePtr("decoration:multisample_edges")->intValue; // Rounded corners - glUniform2f(shader->topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y); - glUniform2f(shader->bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y); - glUniform2f(shader->fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y); + glUniform2f(shader->topLeft, pBox->x, pBox->y); + glUniform2f(shader->fullSize, pBox->width, pBox->height); glUniform1f(shader->radius, round); glUniform1i(shader->primitiveMultisample, (int)(*PMULTISAMPLEEDGES == 1 && round != 0 && !noAA)); diff --git a/src/render/shaders/Textures.hpp b/src/render/shaders/Textures.hpp index 42bd0856..a7c53aea 100644 --- a/src/render/shaders/Textures.hpp +++ b/src/render/shaders/Textures.hpp @@ -6,10 +6,10 @@ inline static constexpr auto ROUNDED_SHADER_FUNC = [](const std::string colorVar return R"#( // branchless baby! - vec2 bottomRight = fullSize - radius; - vec2 pixCoord = v_texcoord - vec2(0.5); - pixCoord *= (vec2(lessThan(pixCoord, vec2(0.0))) * vec2(-2.0) + vec2(1.0)) * fullSize; - pixCoord -= (bottomRight - topLeft) * vec2(0.5); + highp vec2 pixCoord = vec2(gl_FragCoord); + pixCoord -= (topLeft + fullSize / vec2(2.0)); + pixCoord *= (vec2(lessThan(pixCoord, vec2(0.0))) * vec2(-2.0) + vec2(1.0)); + pixCoord -= fullSize * vec2(0.5) - vec2(radius); if (all(greaterThan(pixCoord, vec2(0.0)))) {