From 9393a3e94d837229714e28041427709756033f5a Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:22:01 +0200 Subject: [PATCH] core: add fractional_scaling option (#456) * config: add fractional_scaling option 0 -> off 1 -> on 2 -> auto * core: default auto option for fractional_scaling * locksurface: fallback to integer scaling --- src/config/ConfigManager.cpp | 1 + src/core/LockSurface.cpp | 22 ++++++++++++++-------- src/core/hyprlock.cpp | 24 ++++++++++++------------ src/core/hyprlock.hpp | 2 ++ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b6e6dc2..425a4ea 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -49,6 +49,7 @@ void CConfigManager::init() { m_config.addConfigValue("general:ignore_empty_input", Hyprlang::INT{0}); m_config.addConfigValue("general:immediate_render", Hyprlang::INT{0}); m_config.addConfigValue("general:pam_module", Hyprlang::STRING{"hyprlock"}); + m_config.addConfigValue("general:fractional_scaling", Hyprlang::INT{2}); m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""}); diff --git a/src/core/LockSurface.cpp b/src/core/LockSurface.cpp index 006a2eb..706f844 100644 --- a/src/core/LockSurface.cpp +++ b/src/core/LockSurface.cpp @@ -3,6 +3,7 @@ #include "../helpers/Log.hpp" #include "Egl.hpp" #include "../renderer/Renderer.hpp" +#include "src/config/ConfigManager.hpp" static void handleConfigure(void* data, ext_session_lock_surface_v1* surf, uint32_t serial, uint32_t width, uint32_t height) { const auto PSURF = (CSessionLockSurface*)data; @@ -53,9 +54,13 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) { exit(1); } + const auto PFRACTIONALSCALING = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:fractional_scaling"); + const auto ENABLE_FSV1 = **PFRACTIONALSCALING == 1 || + /* auto */ (**PFRACTIONALSCALING == 2 && (g_pHyprlock->m_sCurrentDesktop == "Hyprland" || g_pHyprlock->m_sCurrentDesktop == "niri")); const auto PFRACTIONALMGR = g_pHyprlock->getFractionalMgr(); const auto PVIEWPORTER = g_pHyprlock->getViewporter(); - if (PFRACTIONALMGR && PVIEWPORTER) { + + if (ENABLE_FSV1 && PFRACTIONALMGR && PVIEWPORTER) { fractional = wp_fractional_scale_manager_v1_get_fractional_scale(PFRACTIONALMGR, surface); if (fractional) { wp_fractional_scale_v1_add_listener(fractional, &fsListener, this); @@ -63,7 +68,7 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) { } } - if (!PFRACTIONALMGR || !fractional) + if (!PFRACTIONALMGR) Debug::log(LOG, "No fractional-scale support! Oops, won't be able to scale!"); if (!PVIEWPORTER) Debug::log(LOG, "No viewporter support! Oops, won't be able to scale!"); @@ -81,7 +86,7 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) { void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) { Debug::log(LOG, "configure with serial {}", serial_); - const bool sameSerial = serial == serial_; + const bool SAMESERIAL = serial == serial_; serial = serial_; logicalSize = size_; @@ -89,16 +94,17 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) { if (fractional) { size = (size_ * fractionalScale).floor(); wp_viewport_set_destination(viewport, logicalSize.x, logicalSize.y); + wl_surface_set_buffer_scale(surface, 1); } else { - size = size_; + size = size_ * output->scale; + wl_surface_set_buffer_scale(surface, output->scale); } + if (!SAMESERIAL) + ext_session_lock_surface_v1_ack_configure(lockSurface, serial); + Debug::log(LOG, "Configuring surface for logical {} and pixel {}", logicalSize, size); - if (!sameSerial) - ext_session_lock_surface_v1_ack_configure(lockSurface, serial); - - wl_surface_set_buffer_scale(surface, 1); wl_surface_damage_buffer(surface, 0, 0, 0xFFFF, 0xFFFF); if (!eglWindow) { diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index b14bede..5fe99ca 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -41,8 +41,12 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b const auto PIMMEDIATERENDER = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:immediate_render"); m_bImmediateRender = immediateRender || **PIMMEDIATERENDER; - const auto* const PNOFADEIN = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_in"); - m_bNoFadeIn = noFadeIn || **PNOFADEIN; + const auto* const PNOFADEIN = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_in"); + m_bNoFadeIn = noFadeIn || **PNOFADEIN; + + const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); + const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; + m_sCurrentDesktop = SZCURRENTD; } CHyprlock::~CHyprlock() { @@ -380,15 +384,13 @@ void CHyprlock::run() { g_pRenderer = std::make_unique(); - const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); - const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; - static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); - const bool NOFADEOUT = **PNOFADEOUT; + static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); + const bool NOFADEOUT = **PNOFADEOUT; - Debug::log(LOG, "Running on {}", SZCURRENTD); + Debug::log(LOG, "Running on {}", m_sCurrentDesktop); // Hyprland violates the protocol a bit to allow for this. - if (SZCURRENTD != "Hyprland") { + if (m_sCurrentDesktop != "Hyprland") { while (!g_pRenderer->asyncResourceGatherer->gathered) { wl_display_flush(m_sWaylandState.display); if (wl_display_prepare_read(m_sWaylandState.display) == 0) { @@ -573,11 +575,9 @@ void CHyprlock::run() { } void CHyprlock::unlock() { - static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); - const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP"); - const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""}; + static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out"); - if (**PNOFADEOUT || SZCURRENTD != "Hyprland") { + if (**PNOFADEOUT || m_sCurrentDesktop != "Hyprland") { releaseSessionLock(); return; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 7fa7037..cbc6436 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -105,6 +105,8 @@ class CHyprlock { bool m_bNoFadeIn = false; + std::string m_sCurrentDesktop = ""; + // std::chrono::system_clock::time_point m_tGraceEnds; std::chrono::system_clock::time_point m_tFadeEnds;