From b0f5e4ab5656fb3b72efa7ce646d4b47ae82b814 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:47:10 +0200 Subject: [PATCH] store scale and scale windows with monitor --- src/events/Monitors.cpp | 2 ++ src/helpers/MiscFunctions.cpp | 7 +++++++ src/helpers/MiscFunctions.hpp | 3 ++- src/helpers/Monitor.hpp | 1 + src/render/OpenGL.cpp | 8 ++++++-- src/render/Renderer.cpp | 11 +++-------- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 90a8b3e9..ee13cbde 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -157,6 +157,8 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { PNEWMONITOR->activeWorkspace = PNEWWORKSPACE->m_iID; + PNEWMONITOR->scale = monitorRule.scale; + g_pCompositor->deactivateAllWLRWorkspaces(); wlr_ext_workspace_handle_v1_set_active(PNEWWORKSPACE->m_pWlrHandle, true); // diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index ceb457c4..a3aa7871 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -54,4 +54,11 @@ std::string getFormat(const char *fmt, ...) { va_end(args); return std::string(buf); +} + +void scaleBox(wlr_box* box, float scale) { + box->width = std::round((box->x + box->width) * scale) - std::round(box->x * scale); + box->height = std::round((box->y + box->height) * scale) - std::round(box->y * scale); + box->x = std::round(box->x * scale); + box->y = std::round(box->y * scale); } \ No newline at end of file diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index c71df0b1..c4192ff1 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -4,4 +4,5 @@ void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString); void wlr_signal_emit_safe(struct wl_signal *signal, void *data); -std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string \ No newline at end of file +std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string +void scaleBox(wlr_box*, float); \ No newline at end of file diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 3f88bed1..fb318c17 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -14,6 +14,7 @@ struct SMonitor { uint64_t ID = -1; int activeWorkspace = -1; + float scale = 1; std::string szName = ""; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 5c3e672e..02909e36 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1,5 +1,6 @@ #include "OpenGL.hpp" #include "../Compositor.hpp" +#include "../helpers/MiscFunctions.hpp" CHyprOpenGLImpl::CHyprOpenGLImpl() { RASSERT(eglMakeCurrent(g_pCompositor->m_sWLREGL->display, EGL_NO_SURFACE, EGL_NO_SURFACE, g_pCompositor->m_sWLREGL->context), "Couldn't make the EGL current!"); @@ -140,8 +141,8 @@ void CHyprOpenGLImpl::begin(SMonitor* pMonitor, pixman_region32_t* pDamage) { m_mMonitorRenderResources[pMonitor].primaryFB.m_pStencilTex = &m_mMonitorRenderResources[pMonitor].stencilTex; m_mMonitorRenderResources[pMonitor].mirrorFB.m_pStencilTex = &m_mMonitorRenderResources[pMonitor].stencilTex; - m_mMonitorRenderResources[pMonitor].primaryFB.alloc(pMonitor->vecSize.x, pMonitor->vecSize.y); - m_mMonitorRenderResources[pMonitor].mirrorFB.alloc(pMonitor->vecSize.x, pMonitor->vecSize.y); + m_mMonitorRenderResources[pMonitor].primaryFB.alloc(pMonitor->vecSize.x * pMonitor->scale, pMonitor->vecSize.y * pMonitor->scale); + m_mMonitorRenderResources[pMonitor].mirrorFB.alloc(pMonitor->vecSize.x * pMonitor->scale, pMonitor->vecSize.y * pMonitor->scale); createBGTextureForMonitor(pMonitor); } @@ -162,6 +163,7 @@ void CHyprOpenGLImpl::end() { clear(CColor(11, 11, 11, 255)); + scaleBox(&windowBox, m_RenderData.pMonitor->scale); renderTexture(m_mMonitorRenderResources[m_RenderData.pMonitor].primaryFB.m_cTex, &windowBox, 255.f, 0); // reset our data @@ -470,6 +472,8 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int thick, i RASSERT((box->width > 0 && box->height > 0), "Tried to render rect with width/height < 0!"); RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!"); + scaleBox(box, m_RenderData.pMonitor->scale); + float matrix[9]; wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, m_RenderData.pMonitor->output->transform_matrix); // TODO: write own, don't use WLR here diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index a85f2b32..77ba17fe 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1,13 +1,6 @@ #include "Renderer.hpp" #include "../Compositor.hpp" -void scaleBox(wlr_box* box, float scale) { - box->width = std::round((box->x + box->width) * scale) - std::round(box->x * scale); - box->height = std::round((box->y + box->height) * scale) - std::round(box->y * scale); - box->x = std::round(box->x * scale); - box->y = std::round(box->y * scale); -} - void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { const auto TEXTURE = wlr_surface_get_texture(surface); const auto RDATA = (SRenderData*)data; @@ -465,12 +458,14 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { void CHyprRenderer::damageMonitor(SMonitor* pMonitor) { wlr_box damageBox = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; + scaleBox(&damageBox, pMonitor->scale); wlr_output_damage_add_box(pMonitor->damage, &damageBox); } void CHyprRenderer::damageBox(wlr_box* pBox) { - for (auto& m : g_pCompositor->m_lMonitors) + for (auto& m : g_pCompositor->m_lMonitors) { wlr_output_damage_add_box(m.damage, pBox); + } } void CHyprRenderer::renderDragIcon(SMonitor* pMonitor, timespec* time) {