From dca75db127fedc58fc85ae0e6e47162e3d5d16f9 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Nov 2024 16:56:43 +0000 Subject: [PATCH 0001/1566] defaultConfig: fixup smart gaps rules --- example/hyprland.conf | 9 +++------ src/config/defaultConfig.hpp | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index edeeac01..fe1a831a 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -136,13 +136,10 @@ animations { # Ref https://wiki.hyprland.org/Configuring/Workspace-Rules/ # "Smart gaps" / "No gaps when only" # uncomment all if you wish to use that. -# workspace = w[t1], gapsout:0, gapsin:0 -# workspace = w[tg1], gapsout:0, gapsin:0 +# workspace = w[tv1], gapsout:0, gapsin:0 # workspace = f[1], gapsout:0, gapsin:0 -# windowrulev2 = bordersize 0, floating:0, onworkspace:w[t1] -# windowrulev2 = rounding 0, floating:0, onworkspace:w[t1] -# windowrulev2 = bordersize 0, floating:0, onworkspace:w[tg1] -# windowrulev2 = rounding 0, floating:0, onworkspace:w[tg1] +# windowrulev2 = bordersize 0, floating:0, onworkspace:w[tv1] +# windowrulev2 = rounding 0, floating:0, onworkspace:w[tv1] # windowrulev2 = bordersize 0, floating:0, onworkspace:f[1] # windowrulev2 = rounding 0, floating:0, onworkspace:f[1] diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 02781770..d680e92b 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -149,13 +149,10 @@ animations { # Ref https://wiki.hyprland.org/Configuring/Workspace-Rules/ # "Smart gaps" / "No gaps when only" # uncomment all if you wish to use that. -# workspace = w[t1], gapsout:0, gapsin:0 -# workspace = w[tg1], gapsout:0, gapsin:0 +# workspace = w[tv1], gapsout:0, gapsin:0 # workspace = f[1], gapsout:0, gapsin:0 -# windowrulev2 = bordersize 0, floating:0, onworkspace:w[t1] -# windowrulev2 = rounding 0, floating:0, onworkspace:w[t1] -# windowrulev2 = bordersize 0, floating:0, onworkspace:w[tg1] -# windowrulev2 = rounding 0, floating:0, onworkspace:w[tg1] +# windowrulev2 = bordersize 0, floating:0, onworkspace:w[tv1] +# windowrulev2 = rounding 0, floating:0, onworkspace:w[tv1] # windowrulev2 = bordersize 0, floating:0, onworkspace:f[1] # windowrulev2 = rounding 0, floating:0, onworkspace:f[1] From a8ff3a452c1c445d24bdd9e7e4fcd66c8ef2a147 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Nov 2024 17:11:38 +0000 Subject: [PATCH 0002/1566] core: move to os/Process from hyprutils nix bump too --- CMakeLists.txt | 2 +- flake.lock | 6 +++--- hyprpm/CMakeLists.txt | 2 +- hyprpm/src/core/PluginManager.cpp | 19 ++++++++----------- src/helpers/MiscFunctions.cpp | 20 ++++++++------------ 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 877ba461..1ac2e10f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ else() endif() find_package(OpenGL REQUIRED COMPONENTS ${GLES_VERSION}) -pkg_check_modules(hyprctl_deps REQUIRED IMPORTED_TARGET hyprutils>=0.2.1) +pkg_check_modules(hyprctl_deps REQUIRED IMPORTED_TARGET hyprutils>=0.2.4) pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.2) diff --git a/flake.lock b/flake.lock index b9055015..47254052 100644 --- a/flake.lock +++ b/flake.lock @@ -151,11 +151,11 @@ ] }, "locked": { - "lastModified": 1730968903, - "narHash": "sha256-zFvzLXcSm0Ia4XI1SE4FQ9KE63hlGrRWhLtwMolWuR8=", + "lastModified": 1731163338, + "narHash": "sha256-Qflei0JBeqQ0c8jxA8e982xAxJvfMwfx4Aci2eJi84s=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "3ce0cde8709cdacbfba471f8e828433b58a561e9", + "rev": "60d3dece30f98e8ad85131829c8529950630d6bc", "type": "github" }, "original": { diff --git a/hyprpm/CMakeLists.txt b/hyprpm/CMakeLists.txt index 692e8da1..65935638 100644 --- a/hyprpm/CMakeLists.txt +++ b/hyprpm/CMakeLists.txt @@ -9,7 +9,7 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") set(CMAKE_CXX_STANDARD 23) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.1.1) +pkg_check_modules(deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.2.4) add_executable(hyprpm ${SRCFILES}) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 57c67641..159b9cd6 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -23,22 +23,19 @@ #include #include +#include using namespace Hyprutils::String; +using namespace Hyprutils::OS; static std::string execAndGet(std::string cmd) { cmd += " 2>&1"; - std::array buffer; - std::string result; - using PcloseType = int (*)(FILE*); - const std::unique_ptr pipe(popen(cmd.c_str(), "r"), static_cast(pclose)); - if (!pipe) - return ""; - result.reserve(buffer.size()); - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; + CProcess proc("/bin/sh", {cmd}); + + if (!proc.runSync()) + return "error"; + + return proc.stdOut(); } SHyprlandVersion CPluginManager::getHyprlandVersion() { diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 878f5ca1..75154796 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -17,7 +17,9 @@ #include #endif #include +#include using namespace Hyprutils::String; +using namespace Hyprutils::OS; #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #include @@ -583,18 +585,12 @@ float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Ve // Execute a shell command and get the output std::string execAndGet(const char* cmd) { - std::array buffer; - std::string result; - using PcloseType = int (*)(FILE*); - const std::unique_ptr pipe(popen(cmd, "r"), static_cast(pclose)); - if (!pipe) { - Debug::log(ERR, "execAndGet: failed in pipe"); - return ""; - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; + CProcess proc("/bin/sh", {cmd}); + + if (!proc.runSync()) + return "error"; + + return proc.stdOut(); } void logSystemInfo() { From 99b01c5d124d08648d4c9e6754485ea585c42707 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Nov 2024 15:54:00 +0000 Subject: [PATCH 0003/1566] hyprpm: fix format --- hyprpm/src/core/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 159b9cd6..ef77f540 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -31,7 +31,7 @@ static std::string execAndGet(std::string cmd) { cmd += " 2>&1"; CProcess proc("/bin/sh", {cmd}); - + if (!proc.runSync()) return "error"; From 9e628067fc54851dc9138c2882abb21f72c5a5a6 Mon Sep 17 00:00:00 2001 From: WavyEbuilder Date: Sun, 10 Nov 2024 15:54:15 +0000 Subject: [PATCH 0004/1566] debug: clean up opening of files in HyprCtl (#8401) `std::ifstream` is more suited than `execAndGet` here. --- src/debug/HyprCtl.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 3e0c75a6..709d8b69 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1,6 +1,7 @@ #include "HyprCtl.hpp" #include +#include #include #include #include @@ -949,11 +950,27 @@ std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request) const std::string GPUINFO = execAndGet("lspci -vnn | grep VGA"); #endif result += "GPU information: \n" + GPUINFO; - if (GPUINFO.contains("NVIDIA") && std::filesystem::exists("/proc/driver/nvidia/version")) - result += execAndGet("cat /proc/driver/nvidia/version | grep NVRM"); + if (GPUINFO.contains("NVIDIA") && std::filesystem::exists("/proc/driver/nvidia/version")) { + std::ifstream file("/proc/driver/nvidia/version"); + std::string line; + if (file.is_open()) { + while (std::getline(file, line)) { + if (!line.contains("NVRM")) + continue; + result += line; + result += "\n"; + } + } else + result += "error"; + } result += "\n\n"; - result += "os-release: " + execAndGet("cat /etc/os-release") + "\n\n"; + if (std::ifstream file("/etc/os-release"); file.is_open()) { + std::stringstream buffer; + buffer << file.rdbuf(); + result += "os-release: " + buffer.str() + "\n\n"; + } else + result += "os-release: error\n\n"; result += "plugins:\n"; if (g_pPluginSystem) { From c10739e6e35c30ef5f273bfe5d219d361a31e226 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Nov 2024 22:53:11 +0000 Subject: [PATCH 0005/1566] core: fixup execAndGet fixes #8410 --- hyprpm/src/core/PluginManager.cpp | 2 +- src/helpers/MiscFunctions.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index ef77f540..051ad500 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -30,7 +30,7 @@ using namespace Hyprutils::OS; static std::string execAndGet(std::string cmd) { cmd += " 2>&1"; - CProcess proc("/bin/sh", {cmd}); + CProcess proc("/bin/sh", {"-c", cmd}); if (!proc.runSync()) return "error"; diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 75154796..7b4d63a7 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -585,7 +585,7 @@ float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Ve // Execute a shell command and get the output std::string execAndGet(const char* cmd) { - CProcess proc("/bin/sh", {cmd}); + CProcess proc("/bin/sh", {"-c", cmd}); if (!proc.runSync()) return "error"; From 1fa0cd7a7574c8e93c567bf0453c155285dd3960 Mon Sep 17 00:00:00 2001 From: WavyEbuilder Date: Mon, 11 Nov 2024 13:44:41 +0000 Subject: [PATCH 0006/1566] debug: clean up fetching of the contents of /proc/device-tree (#8413) --- src/debug/HyprCtl.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 709d8b69..6429e781 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1,7 +1,9 @@ #include "HyprCtl.hpp" +#include #include #include +#include #include #include #include @@ -945,7 +947,24 @@ std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request) #if defined(__DragonFly__) || defined(__FreeBSD__) const std::string GPUINFO = execAndGet("pciconf -lv | fgrep -A4 vga"); #elif defined(__arm__) || defined(__aarch64__) - const std::string GPUINFO = execAndGet("cat /proc/device-tree/soc*/gpu*/compatible"); + std::string GPUINFO; + const std::filesystem::path dev_tree = "/proc/device-tree"; + try { + if (std::filesystem::exists(dev_tree) && std::filesystem::is_directory(dev_tree)) { + std::for_each(std::filesystem::directory_iterator(dev_tree), std::filesystem::directory_iterator{}, [&](const std::filesystem::directory_entry& entry) { + if (std::filesystem::is_directory(entry) && entry.path().filename().string().starts_with("soc")) { + std::for_each(std::filesystem::directory_iterator(entry.path()), std::filesystem::directory_iterator{}, [&](const std::filesystem::directory_entry& sub_entry) { + if (std::filesystem::is_directory(sub_entry) && sub_entry.path().filename().string().starts_with("gpu")) { + std::filesystem::path file_path = sub_entry.path() / "compatible"; + std::ifstream file(file_path); + if (file) + GPUINFO.append(std::istreambuf_iterator(file), std::istreambuf_iterator()); + } + }); + } + }); + } + } catch (...) { GPUINFO = "error"; } #else const std::string GPUINFO = execAndGet("lspci -vnn | grep VGA"); #endif From 07052a515bea46e8b01d3ca5b2c284c272c5ed34 Mon Sep 17 00:00:00 2001 From: JManch <61563764+JManch@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:45:33 +0000 Subject: [PATCH 0007/1566] pointer: map devices across all outputs by default (#8352) --- src/config/ConfigDescriptions.hpp | 10 +++- src/config/ConfigManager.cpp | 2 + src/devices/Tablet.hpp | 3 +- src/devices/VirtualPointer.cpp | 2 +- src/managers/PointerManager.cpp | 76 ++++++++++++++--------------- src/managers/input/InputManager.cpp | 3 ++ 6 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 12e81f2a..fde8173d 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -620,16 +620,22 @@ inline static const std::vector CONFIG_OPTIONS = { }, SConfigOptionDescription{ .value = "input:tablet:output", - .description = "the monitor to bind tablets. Empty means unbound..", + .description = "the monitor to bind tablets. Can be current or a monitor name. Leave empty to map across all monitors.", .type = CONFIG_OPTION_STRING_SHORT, .data = SConfigOptionDescription::SStringData{""}, //##TODO UNSET? }, SConfigOptionDescription{ .value = "input:tablet:region_position", - .description = "position of the mapped region in monitor layout.", + .description = "position of the mapped region in monitor layout relative to the top left corner of the bound monitor or all monitors.", .type = CONFIG_OPTION_VECTOR, .data = SConfigOptionDescription::SVectorData{{}, {-20000, -20000}, {20000, 20000}}, }, + SConfigOptionDescription{ + .value = "input:tablet:absolute_region_position", + .description = "whether to treat the region_position as an absolute position in monitor layout. Only applies when output is empty.", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{false}, + }, SConfigOptionDescription{ .value = "input:tablet:region_size", .description = "size of the mapped region. When this variable is set, tablet input will be mapped to the region. [0, 0] or invalid size means unset.", diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 769a7525..fbbc8dbd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -516,6 +516,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("input:tablet:transform", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:tablet:output", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:tablet:region_position", Hyprlang::VEC2{0, 0}); + m_pConfig->addConfigValue("input:tablet:absolute_region_position", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:tablet:region_size", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("input:tablet:relative_input", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:tablet:left_handed", Hyprlang::INT{0}); @@ -625,6 +626,7 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY}); m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "absolute_region_position", Hyprlang::INT{0}); // only for tablets m_pConfig->addSpecialConfigValue("device", "region_size", Hyprlang::VEC2{0, 0}); // only for tablets m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets m_pConfig->addSpecialConfigValue("device", "active_area_position", Hyprlang::VEC2{0, 0}); // only for tablets diff --git a/src/devices/Tablet.hpp b/src/devices/Tablet.hpp index 4894ac8e..8f49c984 100644 --- a/src/devices/Tablet.hpp +++ b/src/devices/Tablet.hpp @@ -92,9 +92,10 @@ class CTablet : public IHID { WP self; bool relativeInput = false; + bool absolutePos = false; std::string boundOutput = ""; CBox activeArea; - CBox boundBox; // output-local + CBox boundBox; private: CTablet(SP tablet); diff --git a/src/devices/VirtualPointer.cpp b/src/devices/VirtualPointer.cpp index 7ad18775..514c8c32 100644 --- a/src/devices/VirtualPointer.cpp +++ b/src/devices/VirtualPointer.cpp @@ -38,7 +38,7 @@ CVirtualPointer::CVirtualPointer(SP resource) : point listeners.holdBegin = pointer->events.holdBegin.registerListener([this](std::any d) { pointerEvents.holdBegin.emit(d); }); listeners.holdEnd = pointer->events.holdEnd.registerListener([this](std::any d) { pointerEvents.holdEnd.emit(d); }); - boundOutput = resource->boundOutput ? resource->boundOutput->szName : "entire"; + boundOutput = resource->boundOutput ? resource->boundOutput->szName : ""; deviceName = pointer->name; } diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index b309ba82..75be235f 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -668,9 +668,7 @@ void CPointerManager::move(const Vector2D& deltaLogical) { } void CPointerManager::warpAbsolute(Vector2D abs, SP dev) { - - PHLMONITOR currentMonitor = g_pCompositor->m_pLastMonitor.lock(); - if (!currentMonitor || !dev) + if (!dev) return; if (!std::isnan(abs.x)) @@ -678,20 +676,44 @@ void CPointerManager::warpAbsolute(Vector2D abs, SP dev) { if (!std::isnan(abs.y)) abs.y = std::clamp(abs.y, 0.0, 1.0); - // in logical global - CBox mappedArea = currentMonitor->logicalBox(); + // find x and y size of the entire space + const auto& MONITORS = g_pCompositor->m_vMonitors; + Vector2D topLeft = MONITORS.at(0)->vecPosition, bottomRight = MONITORS.at(0)->vecPosition + MONITORS.at(0)->vecSize; + for (size_t i = 1; i < MONITORS.size(); ++i) { + const auto EXTENT = MONITORS[i]->logicalBox().extent(); + const auto POS = MONITORS[i]->logicalBox().pos(); + if (EXTENT.x > bottomRight.x) + bottomRight.x = EXTENT.x; + if (EXTENT.y > bottomRight.y) + bottomRight.y = EXTENT.y; + if (POS.x < topLeft.x) + topLeft.x = POS.x; + if (POS.y < topLeft.y) + topLeft.y = POS.y; + } + CBox mappedArea = {topLeft, bottomRight - topLeft}; + + auto outputMappedArea = [&mappedArea](const std::string& output) { + if (output == "current") { + if (const auto PLASTMONITOR = g_pCompositor->m_pLastMonitor.lock(); PLASTMONITOR) + return PLASTMONITOR->logicalBox(); + } else if (const auto PMONITOR = g_pCompositor->getMonitorFromString(output); PMONITOR) + return PMONITOR->logicalBox(); + return mappedArea; + }; switch (dev->getType()) { case HID_TYPE_TABLET: { CTablet* TAB = reinterpret_cast(dev.get()); if (!TAB->boundOutput.empty()) { - if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TAB->boundOutput); PMONITOR) { - currentMonitor = PMONITOR->self.lock(); - mappedArea = currentMonitor->logicalBox(); - } - } + mappedArea = outputMappedArea(TAB->boundOutput); + mappedArea.translate(TAB->boundBox.pos()); + } else if (TAB->absolutePos) { + mappedArea.x = TAB->boundBox.x; + mappedArea.y = TAB->boundBox.y; + } else + mappedArea.translate(TAB->boundBox.pos()); - mappedArea.translate(TAB->boundBox.pos()); if (!TAB->boundBox.empty()) { mappedArea.w = TAB->boundBox.w; mappedArea.h = TAB->boundBox.h; @@ -700,38 +722,14 @@ void CPointerManager::warpAbsolute(Vector2D abs, SP dev) { } case HID_TYPE_TOUCH: { ITouch* TOUCH = reinterpret_cast(dev.get()); - if (!TOUCH->boundOutput.empty()) { - if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TOUCH->boundOutput); PMONITOR) { - currentMonitor = PMONITOR->self.lock(); - mappedArea = currentMonitor->logicalBox(); - } - } + if (!TOUCH->boundOutput.empty()) + mappedArea = outputMappedArea(TOUCH->boundOutput); break; } case HID_TYPE_POINTER: { IPointer* POINTER = reinterpret_cast(dev.get()); - if (!POINTER->boundOutput.empty()) { - if (POINTER->boundOutput == "entire") { - // find x and y size of the entire space - Vector2D bottomRight = {-9999999, -9999999}, topLeft = {9999999, 9999999}; - for (auto const& m : g_pCompositor->m_vMonitors) { - const auto EXTENT = m->logicalBox().extent(); - const auto POS = m->logicalBox().pos(); - if (EXTENT.x > bottomRight.x) - bottomRight.x = EXTENT.x; - if (EXTENT.y > bottomRight.y) - bottomRight.y = EXTENT.y; - if (POS.x < topLeft.x) - topLeft.x = POS.x; - if (POS.y < topLeft.y) - topLeft.y = POS.y; - } - mappedArea = {topLeft, bottomRight - topLeft}; - } else if (const auto PMONITOR = g_pCompositor->getMonitorFromString(POINTER->boundOutput); PMONITOR) { - currentMonitor = PMONITOR->self.lock(); - mappedArea = currentMonitor->logicalBox(); - } - } + if (!POINTER->boundOutput.empty()) + mappedArea = outputMappedArea(POINTER->boundOutput); break; } default: break; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c190f589..9110cd15 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1595,6 +1595,9 @@ void CInputManager::setTabletConfigs() { const auto REGION_SIZE = g_pConfigManager->getDeviceVec(NAME, "region_size", "input:tablet:region_size"); t->boundBox = {REGION_POS, REGION_SIZE}; + const auto ABSOLUTE_REGION_POS = g_pConfigManager->getDeviceInt(NAME, "absolute_region_position", "input:tablet:absolute_region_position"); + t->absolutePos = ABSOLUTE_REGION_POS; + const auto ACTIVE_AREA_SIZE = g_pConfigManager->getDeviceVec(NAME, "active_area_size", "input:tablet:active_area_size"); const auto ACTIVE_AREA_POS = g_pConfigManager->getDeviceVec(NAME, "active_area_position", "input:tablet:active_area_position"); if (ACTIVE_AREA_SIZE.x != 0 || ACTIVE_AREA_SIZE.y != 0) { From a551f85b9129eac76a5f295ecfe4fb39f96f435c Mon Sep 17 00:00:00 2001 From: dawsers <47487972+dawsers@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:48:50 +0100 Subject: [PATCH 0008/1566] renderer: scaled surfaces could have zero area (#8423) --- src/render/Renderer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 469acda9..d98e32a9 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -222,6 +222,11 @@ static void renderSurface(SP surface, int x, int y, void* da windowBox.height = RDATA->h - y; } + const auto PROJSIZEUNSCALED = windowBox.size(); + + windowBox.scale(RDATA->pMonitor->scale); + windowBox.round(); + if (windowBox.width <= 1 || windowBox.height <= 1) { if (!g_pHyprRenderer->m_bBlockSurfaceFeedback) { Debug::log(TRACE, "presentFeedback for invisible surface"); @@ -231,11 +236,6 @@ static void renderSurface(SP surface, int x, int y, void* da return; // invisible } - const auto PROJSIZEUNSCALED = windowBox.size(); - - windowBox.scale(RDATA->pMonitor->scale); - windowBox.round(); - const bool MISALIGNEDFSV1 = std::floor(RDATA->pMonitor->scale) != RDATA->pMonitor->scale /* Fractional */ && surface->current.scale == 1 /* fs protocol */ && windowBox.size() != surface->current.bufferSize /* misaligned */ && DELTALESSTHAN(windowBox.width, surface->current.bufferSize.x, 3) && DELTALESSTHAN(windowBox.height, surface->current.bufferSize.y, 3) /* off by one-or-two */ && From 8fa4cfb7dfa0be52a66db5f3b13e0ecde3d78b41 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 11 Nov 2024 13:55:32 +0000 Subject: [PATCH 0009/1566] keybinds: don't animate fullscreen size/pos changes coming in when fullscreen, don't animate the pos/size when switching to another fullscreen window, as they can look weird and distracting. Ideally we would do it differently but it's not really possible to do well without reading minds --- src/managers/KeybindManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 5be6a1d9..f2fdab53 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -338,6 +338,10 @@ void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO) { if (!PWINDOWTOCHANGETO->m_bPinned) g_pCompositor->setWindowFullscreenInternal(PWINDOWTOCHANGETO, MODE); + + // warp the position + size animation, otherwise it looks weird. + PWINDOWTOCHANGETO->m_vRealPosition.warp(); + PWINDOWTOCHANGETO->m_vRealSize.warp(); } else { updateRelativeCursorCoords(); g_pCompositor->focusWindow(PWINDOWTOCHANGETO); @@ -2110,6 +2114,10 @@ SDispatchResult CKeybindManager::focusWindow(std::string regexp) { if (FSWINDOW != PWINDOW && !PWINDOW->m_bPinned) g_pCompositor->setWindowFullscreenClient(PWINDOW, FSMODE); + + // warp the position + size animation, otherwise it looks weird. + PWINDOW->m_vRealPosition.warp(); + PWINDOW->m_vRealSize.warp(); } } else g_pCompositor->focusWindow(PWINDOW); From 430b5c302a358faf888a015a7a7009a824e62d99 Mon Sep 17 00:00:00 2001 From: izmyname <135810812+izmyname@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:35:01 +0500 Subject: [PATCH 0010/1566] systemd: hyprland-systemd.desktop -> hyprland-uwsm.desktop Remove hyprland-session.service. --- systemd/hyprland-systemd.desktop | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/systemd/hyprland-systemd.desktop b/systemd/hyprland-systemd.desktop index 64ebbd47..2ed1031b 100644 --- a/systemd/hyprland-systemd.desktop +++ b/systemd/hyprland-systemd.desktop @@ -1,7 +1,6 @@ [Desktop Entry] -Name=Hyprland (systemd session) +Name=Hyprland (uwsm-managed) Comment=An intelligent dynamic tiling Wayland compositor -Exec=systemctl --user start --wait hyprland-session -Type=Application +Exec=uwsm start -N Hyprland -D Hyprland -C An_intelligent_dynamic_tiling_Wayland_compositor -- Hyprland DesktopNames=Hyprland -Keywords=tiling;wayland;compositor; +Type=Application From ccfae82ad1c1a97d06efe980d6ba0dd72be4116c Mon Sep 17 00:00:00 2001 From: Izmyname Date: Thu, 7 Nov 2024 21:01:12 +0500 Subject: [PATCH 0011/1566] rename hyprland-systemd.desktop and remove hyprland-session.service --- CMakeLists.txt | 10 ++-------- systemd/hyprland-session.service.in | 16 ---------------- ...and-systemd.desktop => hyprland-uwsm.desktop} | 0 systemd/meson.build | 14 +------------- 4 files changed, 3 insertions(+), 37 deletions(-) delete mode 100644 systemd/hyprland-session.service.in rename systemd/{hyprland-systemd.desktop => hyprland-uwsm.desktop} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ac2e10f..d337680f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,16 +222,10 @@ if(NO_SYSTEMD) else() message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined)...") add_compile_definitions(USES_SYSTEMD) - configure_file(systemd/hyprland-session.service.in - systemd/hyprland-session.service @ONLY) - # session file -systemd - install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-systemd.desktop + # session file -uwsm + install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-uwsm.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/wayland-sessions) - - # install systemd service - install(FILES ${CMAKE_BINARY_DIR}/systemd/hyprland-session.service - DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user) endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/systemd/hyprland-session.service.in b/systemd/hyprland-session.service.in deleted file mode 100644 index dafdc141..00000000 --- a/systemd/hyprland-session.service.in +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Hyprland - Tiling compositor with the looks -Documentation=man:Hyprland(1) -BindsTo=graphical-session.target -Before=graphical-session.target -Wants=xdg-desktop-autostart.target -Wants=graphical-session-pre.target -After=graphical-session-pre.target - -[Service] -Type=notify -ExecStart=@PREFIX@/@BINDIR@/Hyprland -ExecStop=@PREFIX@/@BINDIR@/hyprctl dispatch exit -ExecStopPost=systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP -Restart=on-failure -Slice=session.slice diff --git a/systemd/hyprland-systemd.desktop b/systemd/hyprland-uwsm.desktop similarity index 100% rename from systemd/hyprland-systemd.desktop rename to systemd/hyprland-uwsm.desktop diff --git a/systemd/meson.build b/systemd/meson.build index 2cd5312a..731f04e3 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -1,17 +1,5 @@ install_data( - 'hyprland-systemd.desktop', + 'hyprland-uwsm.desktop', install_dir: join_paths(get_option('datadir'), 'wayland-sessions'), install_tag: 'runtime', ) - -conf_data = configuration_data() -conf_data.set('PREFIX', get_option('prefix')) -conf_data.set('BINDIR', get_option('bindir')) -user_unit_dir = systemd.get_variable(pkgconfig: 'systemduserunitdir', - pkgconfig_define: ['prefix', get_option('prefix')]) - -configure_file( - configuration: conf_data, - input: 'hyprland-session.service.in', - output: '@BASENAME@', - install_dir: user_unit_dir ) From 943c7d18cc7c9300e1a6b4b859558b8c7ac540cd Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Mon, 11 Nov 2024 09:36:15 +0200 Subject: [PATCH 0012/1566] meson: autodetect systemd --- meson.build | 8 ++++++-- nix/default.nix | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 76765645..e4abad36 100644 --- a/meson.build +++ b/meson.build @@ -52,8 +52,12 @@ backtrace_dep = cpp_compiler.find_library('execinfo', required: false) epoll_dep = dependency('epoll-shim', required: false) # timerfd on BSDs # Handle options -if get_option('systemd').enabled() - systemd = dependency('systemd') +systemd_option = get_option('systemd') +systemd = dependency('systemd', required: systemd_option) +systemd_option.enable_auto_if(systemd.found()) + +if (systemd_option.enabled()) + message('Enabling systemd integration') add_project_arguments('-DUSES_SYSTEMD', language: 'cpp') subdir('systemd') endif diff --git a/nix/default.nix b/nix/default.nix index 29d31485..90c92272 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -152,7 +152,6 @@ in (mapAttrsToList mesonEnable { "xwayland" = enableXWayland; "legacy_renderer" = legacyRenderer; - "systemd" = withSystemd; }) (mapAttrsToList mesonBool { "b_pch" = false; From ff411658e8b217cadf69887f7313d6fd2fc417f2 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Mon, 11 Nov 2024 10:05:01 +0200 Subject: [PATCH 0013/1566] Lock uwsm desktop file behind feature flag The file in the repo cannot be used in NixOS due to missing full paths, and the fact that `uwsm` does not have access to `PATH` to find the listed binaries. Might be useful in other situations as well. --- CMakeLists.txt | 9 +++++++-- meson_options.txt | 1 + systemd/meson.build | 12 +++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d337680f..117932d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,8 +224,13 @@ else() add_compile_definitions(USES_SYSTEMD) # session file -uwsm - install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-uwsm.desktop - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/wayland-sessions) + if(NO_UWSM) + message(STATUS "UWSM support is disabled...") + else() + message(STATUS "UWSM support is enabled (NO_UWSM not defined)...") + install(FILES ${CMAKE_SOURCE_DIR}/systemd/hyprland-uwsm.desktop + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/wayland-sessions) + endif() endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/meson_options.txt b/meson_options.txt index d8c9d5e6..9b64fb32 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ option('xwayland', type: 'feature', value: 'auto', description: 'Enable support for X11 applications') option('systemd', type: 'feature', value: 'auto', description: 'Enable systemd integration') +option('uwsm', type: 'feature', value: 'enabled', description: 'Enable uwsm integration (only if systemd is enabled)') option('legacy_renderer', type: 'feature', value: 'disabled', description: 'Enable legacy renderer') option('tracy_enable', type: 'boolean', value: false , description: 'Enable profiling') diff --git a/systemd/meson.build b/systemd/meson.build index 731f04e3..bc62e95a 100644 --- a/systemd/meson.build +++ b/systemd/meson.build @@ -1,5 +1,7 @@ -install_data( - 'hyprland-uwsm.desktop', - install_dir: join_paths(get_option('datadir'), 'wayland-sessions'), - install_tag: 'runtime', -) +if (get_option('uwsm').allowed()) + install_data( + 'hyprland-uwsm.desktop', + install_dir: join_paths(get_option('datadir'), 'wayland-sessions'), + install_tag: 'runtime', + ) +endif From b88e4a1a9a8a240d54a5006b35964c9e02f86f6b Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Mon, 11 Nov 2024 10:15:58 +0200 Subject: [PATCH 0014/1566] Nix: disable uwsm desktop file installation Will be enabled in the NixOS module. --- nix/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/default.nix b/nix/default.nix index 90c92272..69174d4d 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -152,6 +152,7 @@ in (mapAttrsToList mesonEnable { "xwayland" = enableXWayland; "legacy_renderer" = legacyRenderer; + "uwsm" = false; }) (mapAttrsToList mesonBool { "b_pch" = false; From f5fa84554ffe55e29a397014964238be89ffa54d Mon Sep 17 00:00:00 2001 From: nnra <104775644+nnra6864@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:49:35 +0100 Subject: [PATCH 0015/1566] config: Changed the default value of decoration:blur:ignore_opacity to true (#8418) This change is made in order to deliver the blur look majority of people expect by default. --- src/config/ConfigDescriptions.hpp | 2 +- src/config/ConfigManager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index fde8173d..27bc3c2d 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -268,7 +268,7 @@ inline static const std::vector CONFIG_OPTIONS = { .value = "blur:ignore_opacity", .description = "make the blur layer ignore the opacity of the window", .type = CONFIG_OPTION_BOOL, - .data = SConfigOptionDescription::SBoolData{false}, + .data = SConfigOptionDescription::SBoolData{true}, }, SConfigOptionDescription{ .value = "blur:new_optimizations", diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index fbbc8dbd..b768fda3 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -417,7 +417,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:blur:size", Hyprlang::INT{8}); m_pConfig->addConfigValue("decoration:blur:passes", Hyprlang::INT{1}); - m_pConfig->addConfigValue("decoration:blur:ignore_opacity", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:blur:ignore_opacity", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:blur:new_optimizations", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:blur:xray", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:contrast", {0.8916F}); From a29cfa78431a054a093f3c843228bac6783a6d33 Mon Sep 17 00:00:00 2001 From: SoSeDiK Date: Tue, 12 Nov 2024 02:53:55 +0200 Subject: [PATCH 0016/1566] logging: Add some context to config error logs (#8326) --- src/config/ConfigManager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b768fda3..e3d59874 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1851,7 +1851,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { if (it != flagsmap.end()) mode.flags |= it->second; else - Debug::log(ERR, "invalid flag {} in modeline", key); + Debug::log(ERR, "Invalid flag {} in modeline", key); } snprintf(mode.name, sizeof(mode.name), "%dx%d@%d", mode.hdisplay, mode.vdisplay, mode.vrefresh / 1000); @@ -1874,7 +1874,7 @@ std::optional CConfigManager::handleMonitor(const std::string& comm else if (ARGS[1] == "transform") { const auto TSF = std::stoi(ARGS[2]); if (std::clamp(TSF, 0, 7) != TSF) { - Debug::log(ERR, "invalid transform {} in monitor", TSF); + Debug::log(ERR, "Invalid transform {} in monitor", TSF); return "invalid transform"; } @@ -2027,7 +2027,7 @@ std::optional CConfigManager::handleMonitor(const std::string& comm m_dWorkspaceRules.emplace_back(wsRule); argno++; } else { - Debug::log(ERR, "Config error: invalid monitor syntax"); + Debug::log(ERR, "Config error: invalid monitor syntax at \"{}\"", ARGS[argno]); return "invalid syntax at \"" + ARGS[argno] + "\""; } @@ -2247,12 +2247,12 @@ std::optional CConfigManager::handleBind(const std::string& command const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(HANDLER); if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end()) { - Debug::log(ERR, "Invalid dispatcher!"); + Debug::log(ERR, "Invalid dispatcher: {}", HANDLER); return "Invalid dispatcher, requested \"" + HANDLER + "\" does not exist"; } if (MOD == 0 && MODSTR != "") { - Debug::log(ERR, "Invalid mod!"); + Debug::log(ERR, "Invalid mod: {}", MODSTR); return "Invalid mod, requested mod \"" + MODSTR + "\" is not a valid mod."; } @@ -2696,7 +2696,7 @@ std::optional CConfigManager::handleSubmap(const std::string& comma std::optional CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { if (rawpath.length() < 2) { Debug::log(ERR, "source= path garbage"); - return "source path " + rawpath + " bogus!"; + return "source= path " + rawpath + " bogus!"; } std::unique_ptr glob_buf{new glob_t, [](glob_t* g) { globfree(g); }}; memset(glob_buf.get(), 0, sizeof(glob_t)); @@ -2718,8 +2718,8 @@ std::optional CConfigManager::handleSource(const std::string& comma continue; } - Debug::log(ERR, "source= file doesnt exist"); - return "source file " + value + " doesn't exist!"; + Debug::log(ERR, "source= file doesn't exist: {}", value); + return "source= file " + value + " doesn't exist!"; } configPaths.push_back(value); From bb160cfe377da2d2b2e4431a3399fa60114f3911 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 12 Nov 2024 15:26:25 +0000 Subject: [PATCH 0017/1566] makefile: add stub to discourage direct make --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 7cf21119..6c79b8db 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ PREFIX = /usr/local +stub: + @echo "Do not run $(MAKE) directly without any arguments. Please refer to the wiki on how to compile Hyprland." + legacyrenderer: cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING=${PREFIX} -DLEGACY_RENDERER:BOOL=true -S . -B ./build cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` From 3fb47372b79265ebdabeeefdad10359d5b18377a Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Wed, 13 Nov 2024 21:34:52 +0200 Subject: [PATCH 0018/1566] flake.lock: update --- flake.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 47254052..c1fcb70d 100644 --- a/flake.lock +++ b/flake.lock @@ -16,11 +16,11 @@ ] }, "locked": { - "lastModified": 1730968822, - "narHash": "sha256-NocDjINsh6ismkhb0Xr6xPRksmhuB2WGf8ZmXMhxu7Y=", + "lastModified": 1731496216, + "narHash": "sha256-nlQrNN+tmJ+iP6Ck/czwZI0Hxz3oNvUyGkVruxJwgwA=", "owner": "hyprwm", "repo": "aquamarine", - "rev": "a49bc3583ff223f426cb3526fdaa4bcaa247ec14", + "rev": "3b00e96f90cb0040de6d88ad99bf5f4d443f0c59", "type": "github" }, "original": { @@ -151,11 +151,11 @@ ] }, "locked": { - "lastModified": 1731163338, - "narHash": "sha256-Qflei0JBeqQ0c8jxA8e982xAxJvfMwfx4Aci2eJi84s=", + "lastModified": 1731518387, + "narHash": "sha256-aZZw1ZvTMLkcA6udlvkA3hrCkuipoWLy8s/JNnIclxY=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "60d3dece30f98e8ad85131829c8529950630d6bc", + "rev": "315fba5d21d87ddb756d4bebdb49f99d86b0ffe8", "type": "github" }, "original": { @@ -189,11 +189,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1730785428, - "narHash": "sha256-Zwl8YgTVJTEum+L+0zVAWvXAGbWAuXHax3KzuejaDyo=", + "lastModified": 1731139594, + "narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4aa36568d413aca0ea84a1684d2d46f55dbabad7", + "rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", "type": "github" }, "original": { @@ -229,11 +229,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1730814269, - "narHash": "sha256-fWPHyhYE6xvMI1eGY3pwBTq85wcy1YXqdzTZF+06nOg=", + "lastModified": 1731363552, + "narHash": "sha256-vFta1uHnD29VUY4HJOO/D6p6rxyObnf+InnSMT4jlMU=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "d70155fdc00df4628446352fc58adc640cd705c2", + "rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0", "type": "github" }, "original": { From 20031cea92417a852410827a5cdb4adbcaee4342 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:15:51 +0000 Subject: [PATCH 0019/1566] pointer: add drm dumb buffers for cursors (#8399) --------- Co-authored-by: Mihai Fufezan --- CMakeLists.txt | 2 +- meson.build | 2 +- src/config/ConfigManager.cpp | 2 +- src/managers/PointerManager.cpp | 132 ++++++++++++++++++------------ src/protocols/core/Compositor.cpp | 26 ++++-- src/protocols/core/Compositor.hpp | 2 +- src/render/Texture.cpp | 21 ++++- src/render/Texture.hpp | 34 ++++---- 8 files changed, 142 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 117932d0..1cbd8b0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ find_package(OpenGL REQUIRED COMPONENTS ${GLES_VERSION}) pkg_check_modules(hyprctl_deps REQUIRED IMPORTED_TARGET hyprutils>=0.2.4) -pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.2) +pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.5) add_compile_definitions(AQUAMARINE_VERSION="${aquamarine_dep_VERSION}") diff --git a/meson.build b/meson.build index e4abad36..d825f184 100644 --- a/meson.build +++ b/meson.build @@ -31,7 +31,7 @@ if cpp_compiler.check_header('execinfo.h') add_project_arguments('-DHAS_EXECINFO', language: 'cpp') endif -aquamarine = dependency('aquamarine', version: '>=0.4.2') +aquamarine = dependency('aquamarine', version: '>=0.4.5') add_project_arguments(['-DAQUAMARINE_VERSION="@0@"'.format(aquamarine.version())], language: 'cpp') xcb_dep = dependency('xcb', required: get_option('xwayland')) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index e3d59874..10299277 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -571,7 +571,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("cursor:sync_gsettings_theme", Hyprlang::INT{1}); m_pConfig->addConfigValue("cursor:hide_on_key_press", Hyprlang::INT{0}); m_pConfig->addConfigValue("cursor:hide_on_touch", Hyprlang::INT{1}); - m_pConfig->addConfigValue("cursor:allow_dumb_copy", Hyprlang::INT{0}); + m_pConfig->addConfigValue("cursor:use_cpu_buffer", Hyprlang::INT{0}); m_pConfig->addConfigValue("autogenerated", Hyprlang::INT{0}); diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 75be235f..0580c9be 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -375,6 +375,8 @@ SP CPointerManager::renderHWCursorBuffer(SPmonitor->output->cursorPlaneSize(); auto const& cursorSize = currentCursorImage.size; + static auto PDUMB = CConfigValue("cursor:use_cpu_buffer"); + if (maxSize == Vector2D{}) return nullptr; @@ -386,10 +388,23 @@ SP CPointerManager::renderHWCursorBuffer(SPmonitor->cursorSwapchain || maxSize != state->monitor->cursorSwapchain->currentOptions().size) { + if (!state->monitor->cursorSwapchain || maxSize != state->monitor->cursorSwapchain->currentOptions().size || + *PDUMB != (state->monitor->cursorSwapchain->getAllocator()->type() != Aquamarine::AQ_ALLOCATOR_TYPE_GBM)) { - if (!state->monitor->cursorSwapchain) - state->monitor->cursorSwapchain = Aquamarine::CSwapchain::create(state->monitor->output->getBackend()->preferredAllocator(), state->monitor->output->getBackend()); + if (!state->monitor->cursorSwapchain || *PDUMB != (state->monitor->cursorSwapchain->getAllocator()->type() != Aquamarine::AQ_ALLOCATOR_TYPE_GBM)) { + + auto allocator = state->monitor->output->getBackend()->preferredAllocator(); + if (*PDUMB) { + for (const auto& a : state->monitor->output->getBackend()->getAllocators()) { + if (a->type() == Aquamarine::AQ_ALLOCATOR_TYPE_DRM_DUMB) { + allocator = a; + break; + } + } + } + + state->monitor->cursorSwapchain = Aquamarine::CSwapchain::create(allocator, state->monitor->output->getBackend()); + } auto options = state->monitor->cursorSwapchain->currentOptions(); options.size = maxSize; @@ -397,8 +412,10 @@ SP CPointerManager::renderHWCursorBuffer(SPmonitor->output->getBackend()->preferredAllocator()->drmFD() != g_pCompositor->m_iDRMFD; - // We do not set the format. If it's unset (DRM_FORMAT_INVALID) then the swapchain will pick for us, + // We do not set the format (unless shm). If it's unset (DRM_FORMAT_INVALID) then the swapchain will pick for us, // but if it's set, we don't wanna change it. + if (*PDUMB) + options.format = DRM_FORMAT_ARGB8888; if (!state->monitor->cursorSwapchain->reconfigure(options)) { Debug::log(TRACE, "Failed to reconfigure cursor swapchain"); @@ -420,60 +437,69 @@ SP CPointerManager::renderHWCursorBuffer(SPdataCopy(); + if (texData.empty()) { + if (currentCursorImage.surface && currentCursorImage.surface->resource()->role->role() == SURFACE_ROLE_CURSOR) { + const auto SURFACE = currentCursorImage.surface->resource(); + auto& shmBuffer = CCursorSurfaceRole::cursorPixelData(SURFACE); + + bool flipRB = false; + + if (SURFACE->current.texture) { + Debug::log(TRACE, "Cursor CPU surface: format {}, expecting AR24", FormatUtils::drmFormatName(SURFACE->current.texture->m_iDrmFormat)); + if (SURFACE->current.texture->m_iDrmFormat == DRM_FORMAT_ABGR8888) { + Debug::log(TRACE, "Cursor CPU surface format AB24, will flip. WARNING: this will break on big endian!"); + flipRB = true; + } else if (SURFACE->current.texture->m_iDrmFormat != DRM_FORMAT_ARGB8888) { + Debug::log(TRACE, "Cursor CPU surface format rejected, falling back to sw"); + return nullptr; + } + } + + if (shmBuffer.data()) + texData = shmBuffer; + else { + texData.resize(texture->m_vSize.x * 4 * texture->m_vSize.y); + memset(texData.data(), 0x00, texData.size()); + } + + if (flipRB) { + for (size_t i = 0; i < shmBuffer.size(); i += 4) { + std::swap(shmBuffer.at(i), shmBuffer.at(i + 2)); // little-endian!!!!!! + } + } + } else { + Debug::log(TRACE, "Cannot use dumb copy on dmabuf cursor buffers"); + return nullptr; + } + } + + // then, we just yeet it into the dumb buffer + + auto [data, fmt, size] = buf->beginDataPtr(0); + + memset(data, 0, size); + if (buf->dmabuf().size.x > texture->m_vSize.x) { + size_t STRIDE = 4 * texture->m_vSize.x; + for (int i = 0; i < texture->m_vSize.y; i++) + memcpy(data + i * buf->dmabuf().strides[0], texData.data() + i * STRIDE, STRIDE); + } else + memcpy(data, texData.data(), std::min(size, texData.size())); + + buf->endDataPtr(); + + return buf; + } + g_pHyprRenderer->makeEGLCurrent(); g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor; auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, state->monitor->cursorSwapchain->currentOptions().format); if (!RBO) { Debug::log(TRACE, "Failed to create cursor RB with format {}, mod {}", buf->dmabuf().format, buf->dmabuf().modifier); - static auto PDUMB = CConfigValue("cursor:allow_dumb_copy"); - if (!*PDUMB) - return nullptr; - - auto bufData = buf->beginDataPtr(0); - auto bufPtr = std::get<0>(bufData); - - // clear buffer - memset(bufPtr, 0, std::get<2>(bufData)); - - if (currentCursorImage.pBuffer) { - auto texAttrs = currentCursorImage.pBuffer->shm(); - - if (!texAttrs.success) { - Debug::log(TRACE, "Cannot use dumb copy on dmabuf cursor buffers"); - return nullptr; - } - - auto texData = currentCursorImage.pBuffer->beginDataPtr(GBM_BO_TRANSFER_WRITE); - auto texPtr = std::get<0>(texData); - Debug::log(TRACE, "cursor texture {}x{} {} {} {}", texAttrs.size.x, texAttrs.size.y, (void*)texPtr, texAttrs.format, texAttrs.stride); - // copy cursor texture - for (int i = 0; i < texAttrs.size.y; i++) - memcpy(bufPtr + i * buf->dmabuf().strides[0], texPtr + i * texAttrs.stride, texAttrs.stride); - } else if (currentCursorImage.surface && currentCursorImage.surface->resource()->role->role() == SURFACE_ROLE_CURSOR) { - const auto SURFACE = currentCursorImage.surface->resource(); - auto& shmBuffer = CCursorSurfaceRole::cursorPixelData(SURFACE); - Debug::log(TRACE, "cursor texture pixel data length: {}B", shmBuffer.size()); - - if (shmBuffer.data()) { - // copy cursor texture - // assume format is 32bpp - size_t STRIDE = 4 * SURFACE->current.bufferSize.x; - for (int i = 0; i < SURFACE->current.bufferSize.y; i++) - memcpy(bufPtr + i * buf->dmabuf().strides[0], shmBuffer.data() + i * STRIDE, STRIDE); - } else { - // if there is no data, hide the cursor - memset(bufPtr, '\0', buf->size.x * buf->size.y * 4 /* assume 32bpp */); - } - - } else { - Debug::log(TRACE, "Unsupported cursor buffer/surface, falling back to sw (can't dumb copy)"); - return nullptr; - } - - buf->endDataPtr(); - - return buf; + return nullptr; } RBO->bind(); @@ -773,7 +799,7 @@ SP CPointerManager::getCurrentCursorTexture() { if (currentCursorImage.pBuffer) { if (!currentCursorImage.bufferTex) - currentCursorImage.bufferTex = makeShared(currentCursorImage.pBuffer); + currentCursorImage.bufferTex = makeShared(currentCursorImage.pBuffer, true); return currentCursorImage.bufferTex; } diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index 57f61f87..89f2a4cb 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -438,12 +438,13 @@ void CWLSurfaceResource::commitPendingState() { current.texture->m_eTransform = wlTransformToHyprutils(current.transform); if (current.buffer && current.buffer->buffer) { - current.buffer->buffer->update(accumulateCurrentBufferDamage()); + const auto DAMAGE = accumulateCurrentBufferDamage(); + current.buffer->buffer->update(DAMAGE); // if the surface is a cursor, update the shm buffer // TODO: don't update the entire texture - if (role->role() == SURFACE_ROLE_CURSOR) - updateCursorShm(); + if (role->role() == SURFACE_ROLE_CURSOR && !DAMAGE.empty()) + updateCursorShm(DAMAGE); // release the buffer if it's synchronous as update() has done everything thats needed // so we can let the app know we're done. @@ -486,13 +487,12 @@ void CWLSurfaceResource::commitPendingState() { lastBuffer = current.buffer ? current.buffer->buffer : WP{}; } -void CWLSurfaceResource::updateCursorShm() { +void CWLSurfaceResource::updateCursorShm(CRegion damage) { auto buf = current.buffer ? current.buffer->buffer : lastBuffer; if (!buf) return; - // TODO: actually use damage auto& shmData = CCursorSurfaceRole::cursorPixelData(self.lock()); auto shmAttrs = buf->shm(); @@ -501,11 +501,25 @@ void CWLSurfaceResource::updateCursorShm() { return; } + damage.intersect(CBox{0, 0, buf->size.x, buf->size.y}); + // no need to end, shm. auto [pixelData, fmt, bufLen] = buf->beginDataPtr(0); shmData.resize(bufLen); - memcpy(shmData.data(), pixelData, bufLen); + + if (const auto RECTS = damage.getRects(); RECTS.size() == 1 && RECTS.at(0).x2 == buf->size.x && RECTS.at(0).y2 == buf->size.y) + memcpy(shmData.data(), pixelData, bufLen); + else { + for (auto& box : damage.getRects()) { + for (auto y = box.y1; y < box.y2; ++y) { + // bpp is 32 INSALLAH + auto begin = 4 * box.y1 * (box.x2 - box.x1) + box.x1; + auto len = 4 * (box.x2 - box.x1); + memcpy((uint8_t*)shmData.data() + begin, (uint8_t*)pixelData + begin, len); + } + } + } } void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor) { diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp index e5bdf082..c036041a 100644 --- a/src/protocols/core/Compositor.hpp +++ b/src/protocols/core/Compositor.hpp @@ -148,7 +148,7 @@ class CWLSurfaceResource { void dropCurrentBuffer(); void commitPendingState(); void bfHelper(std::vector> const& nodes, std::function, const Vector2D&, void*)> fn, void* data); - void updateCursorShm(); + void updateCursorShm(CRegion damage = CBox{0, 0, INT16_MAX, INT16_MAX}); friend class CWLPointerResource; }; diff --git a/src/render/Texture.cpp b/src/render/Texture.cpp index 91e70afa..633f0212 100644 --- a/src/render/Texture.cpp +++ b/src/render/Texture.cpp @@ -3,6 +3,7 @@ #include "../Compositor.hpp" #include "../protocols/types/Buffer.hpp" #include "../helpers/Format.hpp" +#include CTexture::CTexture() { // naffin' @@ -16,7 +17,7 @@ CTexture::~CTexture() { destroyTexture(); } -CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_) { +CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_, bool keepDataCopy) : m_iDrmFormat(drmFormat), m_bKeepDataCopy(keepDataCopy) { createFromShm(drmFormat, pixels, stride, size_); } @@ -24,7 +25,7 @@ CTexture::CTexture(const Aquamarine::SDMABUFAttrs& attrs, void* image) { createFromDma(attrs, image); } -CTexture::CTexture(const SP buffer) { +CTexture::CTexture(const SP buffer, bool keepDataCopy) : m_bKeepDataCopy(keepDataCopy) { if (!buffer) return; @@ -43,6 +44,8 @@ CTexture::CTexture(const SP buffer) { auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); + m_iDrmFormat = fmt; + createFromShm(fmt, pixelData, bufLen, shm.size); return; } @@ -80,6 +83,11 @@ void CTexture::createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t strid GLCALL(glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, size_.x, size_.y, 0, format->glFormat, format->glType, pixels)); GLCALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0)); GLCALL(glBindTexture(GL_TEXTURE_2D, 0)); + + if (m_bKeepDataCopy) { + m_vDataCopy.resize(stride * size_.y); + memcpy(m_vDataCopy.data(), pixels, stride * size_.y); + } } void CTexture::createFromDma(const Aquamarine::SDMABUFAttrs& attrs, void* image) { @@ -135,6 +143,11 @@ void CTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, cons GLCALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0)); glBindTexture(GL_TEXTURE_2D, 0); + + if (m_bKeepDataCopy) { + m_vDataCopy.resize(stride * m_vSize.y); + memcpy(m_vDataCopy.data(), pixels, stride * m_vSize.y); + } } void CTexture::destroyTexture() { @@ -152,3 +165,7 @@ void CTexture::allocate() { if (!m_iTexID) GLCALL(glGenTextures(1, &m_iTexID)); } + +const std::vector& CTexture::dataCopy() { + return m_vDataCopy; +} diff --git a/src/render/Texture.hpp b/src/render/Texture.hpp index e0ef5503..ae949d5f 100644 --- a/src/render/Texture.hpp +++ b/src/render/Texture.hpp @@ -24,26 +24,32 @@ class CTexture { CTexture(const CTexture&&) = delete; CTexture(const CTexture&) = delete; - CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size); + CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size, bool keepDataCopy = false); - CTexture(const SP buffer); + CTexture(const SP buffer, bool keepDataCopy = false); // this ctor takes ownership of the eglImage. CTexture(const Aquamarine::SDMABUFAttrs&, void* image); ~CTexture(); - void destroyTexture(); - void allocate(); - void update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const CRegion& damage); + void destroyTexture(); + void allocate(); + void update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const CRegion& damage); + const std::vector& dataCopy(); - TEXTURETYPE m_iType = TEXTURE_RGBA; - GLenum m_iTarget = GL_TEXTURE_2D; - GLuint m_iTexID = 0; - Vector2D m_vSize = {}; - void* m_pEglImage = nullptr; - eTransform m_eTransform = HYPRUTILS_TRANSFORM_NORMAL; - bool m_bOpaque = false; + TEXTURETYPE m_iType = TEXTURE_RGBA; + GLenum m_iTarget = GL_TEXTURE_2D; + GLuint m_iTexID = 0; + Vector2D m_vSize = {}; + void* m_pEglImage = nullptr; + eTransform m_eTransform = HYPRUTILS_TRANSFORM_NORMAL; + bool m_bOpaque = false; + uint32_t m_iDrmFormat = 0; // for shm private: - void createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size); - void createFromDma(const Aquamarine::SDMABUFAttrs&, void* image); + void createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size); + void createFromDma(const Aquamarine::SDMABUFAttrs&, void* image); + + bool m_bKeepDataCopy = false; + + std::vector m_vDataCopy; }; \ No newline at end of file From 6f7280a6901aeba0fd1768ccf78fea152fe41f4f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 14 Nov 2024 20:20:51 +0000 Subject: [PATCH 0020/1566] descriptions: add use_cpu_buffer --- src/config/ConfigDescriptions.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 27bc3c2d..969ec66f 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1350,8 +1350,8 @@ inline static const std::vector CONFIG_OPTIONS = { .data = SConfigOptionDescription::SBoolData{true}, }, SConfigOptionDescription{ - .value = "cursor:allow_dumb_copy", - .description = "Makes HW cursors work on Nvidia, at the cost of a possible hitch whenever the image changes", + .value = "cursor:use_cpu_buffer", + .description = "Makes HW cursors use a CPU buffer. Required on Nvidia to have HW cursors. Experimental", .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{false}, }, From 940ed3d525d838bc255070bd8cfc2f75df04229a Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Thu, 14 Nov 2024 21:38:16 +0100 Subject: [PATCH 0021/1566] xcursors: store themes in a std:set to order it (#8474) using a unordered_set means its store based on a hash_value meaning currently it can end up loading inherited themes before the actual theme itself depending on the hash of the theme name used, reason for using set at all over vector is to keep unique members and not foreverever looping broken inherit themeing. --- src/managers/XCursorManager.cpp | 8 ++++---- src/managers/XCursorManager.hpp | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/managers/XCursorManager.cpp b/src/managers/XCursorManager.cpp index 93ee7965..5c3053c7 100644 --- a/src/managers/XCursorManager.cpp +++ b/src/managers/XCursorManager.cpp @@ -197,7 +197,7 @@ SP CXCursorManager::createCursor(std::string const& shape, XcursorIma return xcursor; } -std::unordered_set CXCursorManager::themePaths(std::string const& theme) { +std::set CXCursorManager::themePaths(std::string const& theme) { auto const* path = XcursorLibraryPath(); auto expandTilde = [](std::string const& path) { @@ -276,10 +276,10 @@ std::unordered_set CXCursorManager::themePaths(std::string const& t return themes; }; - std::unordered_set paths; - std::unordered_set inherits; + std::set paths; + std::set inherits; - auto scanTheme = [&path, &paths, &expandTilde, &inherits, &getInheritThemes](auto const& t) { + auto scanTheme = [&path, &paths, &expandTilde, &inherits, &getInheritThemes](auto const& t) { std::stringstream ss(path); std::string line; diff --git a/src/managers/XCursorManager.hpp b/src/managers/XCursorManager.hpp index 1f3c24db..2517e85e 100644 --- a/src/managers/XCursorManager.hpp +++ b/src/managers/XCursorManager.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#include #include #include #include @@ -34,16 +34,16 @@ class CXCursorManager { void syncGsettings(); private: - SP createCursor(std::string const& shape, XcursorImages* xImages); - std::unordered_set themePaths(std::string const& theme); - std::string getLegacyShapeName(std::string const& shape); - std::vector> loadStandardCursors(std::string const& name, int size); - std::vector> loadAllFromDir(std::string const& path, int size); + SP createCursor(std::string const& shape, XcursorImages* xImages); + std::set themePaths(std::string const& theme); + std::string getLegacyShapeName(std::string const& shape); + std::vector> loadStandardCursors(std::string const& name, int size); + std::vector> loadAllFromDir(std::string const& path, int size); - int lastLoadSize = 0; - float lastLoadScale = 0; - std::string themeName = ""; - SP defaultCursor; - SP hyprCursor; - std::vector> cursors; + int lastLoadSize = 0; + float lastLoadScale = 0; + std::string themeName = ""; + SP defaultCursor; + SP hyprCursor; + std::vector> cursors; }; From 967fe76a60ec6b2928b495ed202f772beca05275 Mon Sep 17 00:00:00 2001 From: UjinT34 <41110182+UjinT34@users.noreply.github.com> Date: Fri, 15 Nov 2024 03:45:13 +0300 Subject: [PATCH 0022/1566] drm: enable explit out fence in AQ (#8431) --- src/render/Renderer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index d98e32a9..37e6f81e 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1507,6 +1507,9 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) { pMonitor->output->state->resetExplicitFences(); if (inFD >= 0) pMonitor->output->state->setExplicitInFence(inFD); + auto explicitOptions = getExplicitSyncSettings(); + if (explicitOptions.explicitEnabled && explicitOptions.explicitKMSEnabled) + pMonitor->output->state->enableExplicitOutFenceForNextCommit(); if (pMonitor->ctmUpdated) { pMonitor->ctmUpdated = false; @@ -1530,8 +1533,6 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) { } } - auto explicitOptions = getExplicitSyncSettings(); - if (!explicitOptions.explicitEnabled) return ok; From 098e491a43e8b26f4382b48651a4131464bf6a2f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Nov 2024 00:47:34 +0000 Subject: [PATCH 0023/1566] protocols: mark primarySelection as not privileged fixes #8479 --- src/managers/ProtocolManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index 601e564d..cf517b22 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -281,6 +281,7 @@ bool CProtocolManager::isGlobalPrivileged(const wl_global* global) { PROTO::xdgShell->getGlobal(), PROTO::xdgDialog->getGlobal(), PROTO::singlePixel->getGlobal(), + PROTO::primarySelection->getGlobal(), PROTO::sync ? PROTO::sync->getGlobal() : nullptr, PROTO::mesaDRM ? PROTO::mesaDRM->getGlobal() : nullptr, PROTO::linuxDma ? PROTO::linuxDma->getGlobal() : nullptr, From 7affc34ab43c5d5cbf670759b839a9e990d8bbea Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 16 Nov 2024 07:21:59 +0800 Subject: [PATCH 0024/1566] bind: new long press option (#8302) --------- Co-authored-by: Vaxry --- src/config/ConfigManager.cpp | 13 ++++++----- src/debug/HyprCtl.cpp | 7 +++--- src/managers/KeybindManager.cpp | 40 ++++++++++++++++++++++++++++++--- src/managers/KeybindManager.hpp | 5 ++++- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 10299277..58db00e9 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2171,6 +2171,7 @@ std::optional CConfigManager::handleBind(const std::string& command bool transparent = false; bool ignoreMods = false; bool multiKey = false; + bool longPress = false; bool hasDescription = false; bool dontInhibit = false; const auto BINDARGS = command.substr(4); @@ -2192,6 +2193,8 @@ std::optional CConfigManager::handleBind(const std::string& command ignoreMods = true; } else if (arg == 's') { multiKey = true; + } else if (arg == 'o') { + longPress = true; } else if (arg == 'd') { hasDescription = true; } else if (arg == 'p') { @@ -2201,8 +2204,8 @@ std::optional CConfigManager::handleBind(const std::string& command } } - if (release && repeat) - return "flags r and e are mutually exclusive"; + if ((longPress || release) && repeat) + return "flags e is mutually exclusive with r and o"; if (mouse && (repeat || release || locked)) return "flag m is exclusive"; @@ -2264,9 +2267,9 @@ std::optional CConfigManager::handleBind(const std::string& command return "Invalid catchall, catchall keybinds are only allowed in submaps."; } - g_pKeybindManager->addKeybind(SKeybind{ - parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, DESCRIPTION, release, - repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey, hasDescription, dontInhibit}); + g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, + COMMAND, locked, m_szCurrentSubmap, DESCRIPTION, release, repeat, longPress, + mouse, nonConsuming, transparent, ignoreMods, multiKey, hasDescription, dontInhibit}); } return {}; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 6429e781..c5eba0a7 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -843,6 +843,7 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { "mouse": {}, "release": {}, "repeat": {}, + "longPress": {}, "non_consuming": {}, "has_description": {}, "modmask": {}, @@ -854,9 +855,9 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { "dispatcher": "{}", "arg": "{}" }},)#", - kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.nonConsuming ? "true" : "false", - kb.hasDescription ? "true" : "false", kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, kb.catchAll ? "true" : "false", - escapeJSONStrings(kb.description), escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg)); + kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.longPress ? "true" : "false", + kb.nonConsuming ? "true" : "false", kb.hasDescription ? "true" : "false", kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, + kb.catchAll ? "true" : "false", escapeJSONStrings(kb.description), escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg)); } trimTrailingComma(ret); ret += "]"; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index f2fdab53..b14637f7 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -13,6 +13,7 @@ #include "eventLoop/EventLoopManager.hpp" #include "debug/Log.hpp" #include "helpers/varlist/VarList.hpp" +#include "eventLoop/EventLoopManager.hpp" #include #include @@ -130,9 +131,25 @@ CKeybindManager::CKeybindManager() { m_tScrollTimer.reset(); + m_pLongPressTimer = makeShared( + std::nullopt, + [this](SP self, void* data) { + if (!m_pLastLongPressKeybind || g_pSeatManager->keyboard.expired()) + return; + + const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(m_pLastLongPressKeybind->handler); + + Debug::log(LOG, "Long press timeout passed, calling dispatcher."); + DISPATCHER->second(m_pLastLongPressKeybind->arg); + }, + nullptr); + + g_pEventLoopManager->addTimer(m_pLongPressTimer); + static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd - m_pActiveKeybind = nullptr; + m_pActiveKeybind = nullptr; + m_pLastLongPressKeybind = nullptr; m_vPressedSpecialBinds.clear(); }); } @@ -140,12 +157,17 @@ CKeybindManager::CKeybindManager() { CKeybindManager::~CKeybindManager() { if (m_pXKBTranslationState) xkb_state_unref(m_pXKBTranslationState); + if (m_pLongPressTimer && g_pEventLoopManager) { + g_pEventLoopManager->removeTimer(m_pLongPressTimer); + m_pLongPressTimer.reset(); + } } void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); - m_pActiveKeybind = nullptr; + m_pActiveKeybind = nullptr; + m_pLastLongPressKeybind = nullptr; } void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { @@ -158,7 +180,8 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { } } - m_pActiveKeybind = nullptr; + m_pActiveKeybind = nullptr; + m_pLastLongPressKeybind = nullptr; } uint32_t CKeybindManager::stringToModMask(std::string mods) { @@ -409,6 +432,8 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { m_pActiveKeybind = nullptr; } + m_pLastLongPressKeybind = nullptr; + bool suppressEvent = false; if (e.state == WL_KEYBOARD_KEY_STATE_PRESSED) { @@ -705,6 +730,15 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP } } + if (k.longPress) { + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + + m_pLongPressTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); + m_pLastLongPressKeybind = &k; + + continue; + } + const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); if (SPECIALTRIGGERED && !pressed) diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 24a09836..4a0af6e9 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -8,6 +8,7 @@ #include #include #include "../devices/IPointer.hpp" +#include "eventLoop/EventLoopTimer.hpp" class CInputManager; class CConfigManager; @@ -28,6 +29,7 @@ struct SKeybind { std::string description = ""; bool release = false; bool repeat = false; + bool longPress = false; bool mouse = false; bool nonConsuming = false; bool transparent = false; @@ -119,7 +121,8 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; - SKeybind* m_pActiveKeybind = nullptr; + SKeybind * m_pActiveKeybind = nullptr, *m_pLastLongPressKeybind = nullptr; + SP m_pLongPressTimer; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0; From 83be2480c45bdead9110fdf137a1cd2f5a203378 Mon Sep 17 00:00:00 2001 From: sslater11 <43177940+sslater11@users.noreply.github.com> Date: Sat, 16 Nov 2024 16:39:58 +0000 Subject: [PATCH 0025/1566] workspace: fix missing name via focusworkspaceoncurrentmonitor (#8484) --- src/managers/KeybindManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index b14637f7..4d2f4dcc 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1887,7 +1887,7 @@ SDispatchResult CKeybindManager::moveWorkspaceToMonitor(std::string args) { } SDispatchResult CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { - auto workspaceID = getWorkspaceIDNameFromString(args).id; + auto [workspaceID, workspaceName] = getWorkspaceIDNameFromString(args); if (workspaceID == WORKSPACE_INVALID) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!"); return {.success = false, .error = "focusWorkspaceOnCurrentMonitor invalid workspace!"}; @@ -1903,7 +1903,7 @@ SDispatchResult CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args auto pWorkspace = g_pCompositor->getWorkspaceByID(workspaceID); if (!pWorkspace) { - pWorkspace = g_pCompositor->createNewWorkspace(workspaceID, PCURRMONITOR->ID); + pWorkspace = g_pCompositor->createNewWorkspace(workspaceID, PCURRMONITOR->ID, workspaceName); // we can skip the moving, since it's already on the current monitor changeworkspace(pWorkspace->getConfigName()); return {}; From ec1e6be00377c26dd25497b1544091b3f643c4bc Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 16 Nov 2024 23:04:57 +0000 Subject: [PATCH 0026/1566] core: guard pmonitor in focuswindow may be null fixes #8483 --- src/Compositor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index da20c5cf..fbbfd7e7 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1077,7 +1077,7 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP pSurface PWORKSPACE->rememberPrevWorkspace(m_pLastMonitor->activeWorkspace); if (PWORKSPACE->m_bIsSpecialWorkspace) m_pLastMonitor->changeWorkspace(PWORKSPACE, false, true); // if special ws, open on current monitor - else + else if (PMONITOR) PMONITOR->changeWorkspace(PWORKSPACE, false, true); // changeworkspace already calls focusWindow return; @@ -1088,7 +1088,7 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP pSurface /* If special fallthrough is enabled, this behavior will be disabled, as I have no better idea of nicely tracking which window focuses are "via keybinds" and which ones aren't. */ - if (PMONITOR->activeSpecialWorkspace && PMONITOR->activeSpecialWorkspace != pWindow->m_pWorkspace && !pWindow->m_bPinned && !*PSPECIALFALLTHROUGH) + if (PMONITOR && PMONITOR->activeSpecialWorkspace && PMONITOR->activeSpecialWorkspace != pWindow->m_pWorkspace && !pWindow->m_bPinned && !*PSPECIALFALLTHROUGH) PMONITOR->setSpecialWorkspace(nullptr); // we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window From cf18eca86d21c28b127d58938b3a1004800b85c9 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sat, 16 Nov 2024 23:06:35 +0000 Subject: [PATCH 0027/1566] [gha] Nix: update inputs --- flake.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index c1fcb70d..969bc157 100644 --- a/flake.lock +++ b/flake.lock @@ -16,11 +16,11 @@ ] }, "locked": { - "lastModified": 1731496216, - "narHash": "sha256-nlQrNN+tmJ+iP6Ck/czwZI0Hxz3oNvUyGkVruxJwgwA=", + "lastModified": 1731774881, + "narHash": "sha256-1Dxryiw8u2ejntxrrv3sMtIE8WHKxmlN4KeH+uMGbmc=", "owner": "hyprwm", "repo": "aquamarine", - "rev": "3b00e96f90cb0040de6d88ad99bf5f4d443f0c59", + "rev": "b31a6a4da8199ae3489057db7d36069a70749a56", "type": "github" }, "original": { @@ -151,11 +151,11 @@ ] }, "locked": { - "lastModified": 1731518387, - "narHash": "sha256-aZZw1ZvTMLkcA6udlvkA3hrCkuipoWLy8s/JNnIclxY=", + "lastModified": 1731702627, + "narHash": "sha256-+JeO9gevnXannQxMfR5xzZtF4sYmSlWkX/BPmPx0mWk=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "315fba5d21d87ddb756d4bebdb49f99d86b0ffe8", + "rev": "e911361a687753bbbdfe3b6a9eab755ecaf1d9e1", "type": "github" }, "original": { @@ -189,11 +189,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1731139594, - "narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", "type": "github" }, "original": { @@ -293,11 +293,11 @@ ] }, "locked": { - "lastModified": 1730743262, - "narHash": "sha256-iTLqj3lU8kFehPm5tXpctzkD274t/k1nwSSq3qCWXeg=", + "lastModified": 1731703417, + "narHash": "sha256-rheDc/7C+yI+QspYr9J2z9kQ5P9F4ATapI7qyFAe1XA=", "owner": "hyprwm", "repo": "xdg-desktop-portal-hyprland", - "rev": "09b23cef06fe248e61cec8862c04b9bcb62f4b6d", + "rev": "8070f36deec723de71e7557441acb17e478204d3", "type": "github" }, "original": { From 9d37b1b07339b1b222ceab5952cd9b927fbf6d73 Mon Sep 17 00:00:00 2001 From: staz Date: Sun, 17 Nov 2024 04:07:33 +0500 Subject: [PATCH 0028/1566] workspacerules: Do not check 'on-created-empty' if using a workspace windowrule (#8486) --- src/events/Windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index f946ce03..77df7373 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -296,7 +296,7 @@ void Events::listener_mapWindow(void* owner, void* data) { auto pWorkspace = g_pCompositor->getWorkspaceByID(REQUESTEDWORKSPACEID); if (!pWorkspace) - pWorkspace = g_pCompositor->createNewWorkspace(REQUESTEDWORKSPACEID, PWINDOW->monitorID(), requestedWorkspaceName); + pWorkspace = g_pCompositor->createNewWorkspace(REQUESTEDWORKSPACEID, PWINDOW->monitorID(), requestedWorkspaceName, false); PWORKSPACE = pWorkspace; From af83c825138386d269d69b3ef755b844a2eacb22 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Sun, 17 Nov 2024 02:18:30 +0300 Subject: [PATCH 0029/1566] hyprctl: add json output on hyprctl -j plugins list (#8480) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Руслан Новокшонов --- src/debug/HyprCtl.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index c5eba0a7..964a193b 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1472,17 +1472,40 @@ std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) { g_pPluginSystem->unloadPlugin(PLUGIN); } else if (OPERATION == "list") { - const auto PLUGINS = g_pPluginSystem->getAllPlugins(); + const auto PLUGINS = g_pPluginSystem->getAllPlugins(); + std::string result = ""; - if (PLUGINS.size() == 0) - return "no plugins loaded"; + if (format == eHyprCtlOutputFormat::FORMAT_JSON) { + result += "["; - std::string list = ""; - for (auto const& p : PLUGINS) { - list += std::format("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description); + if (PLUGINS.size() == 0) + return "[]"; + + for (auto const& p : PLUGINS) { + result += std::format( + R"#( +{{ + "name": "{}", + "author": "{}", + "handle": "{:x}", + "version": "{}", + "description": "{}" +}},)#", + escapeJSONStrings(p->name), escapeJSONStrings(p->author), (uintptr_t)p->m_pHandle, escapeJSONStrings(p->version), escapeJSONStrings(p->description)); + } + trimTrailingComma(result); + result += "]"; + } else { + if (PLUGINS.size() == 0) + return "no plugins loaded"; + + for (auto const& p : PLUGINS) { + result += + std::format("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description); + } } - return list; + return result; } else { return "unknown opt"; } From 0ddbd1c3a40f921816a2c512f871f1e51aca8fe2 Mon Sep 17 00:00:00 2001 From: Alexandre Acebedo Date: Sun, 17 Nov 2024 15:58:18 +0000 Subject: [PATCH 0030/1566] renderer: add lockdead_screen_delay (#8467) --- src/config/ConfigDescriptions.hpp | 6 ++++++ src/config/ConfigManager.cpp | 1 + src/managers/SessionLockManager.cpp | 10 ++++++++++ src/managers/SessionLockManager.hpp | 3 +++ src/render/Renderer.cpp | 9 +++++---- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 969ec66f..2e3a6720 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1121,6 +1121,12 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{false}, }, + SConfigOptionDescription{ + .value = "misc:lockdead_screen_delay", + .description = "the delay in ms after the lockdead screen appears if the lock screen did not appear after a lock event occurred.", + .type = CONFIG_OPTION_INT, + .data = SConfigOptionDescription::SRangeData{1000, 0, 5000}, + }, /* * binds: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 58db00e9..1c025179 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -377,6 +377,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:middle_click_paste", Hyprlang::INT{1}); m_pConfig->addConfigValue("misc:render_unfocused_fps", Hyprlang::INT{15}); m_pConfig->addConfigValue("misc:disable_xdg_env_checks", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:lockdead_screen_delay", Hyprlang::INT{1000}); m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 1b28cc27..c7a5934a 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -57,6 +57,7 @@ void CSessionLockManager::onNewSessionLock(SP pLock) { m_pSessionLock = std::make_unique(); m_pSessionLock->lock = pLock; + m_pSessionLock->mLockTimer.reset(); m_pSessionLock->listeners.newSurface = pLock->events.newLockSurface.registerListener([this](std::any data) { auto SURFACE = std::any_cast>(data); @@ -176,3 +177,12 @@ bool CSessionLockManager::isSessionLockPresent() { bool CSessionLockManager::anySessionLockSurfacesPresent() { return m_pSessionLock && std::ranges::any_of(m_pSessionLock->vSessionLockSurfaces, [](const auto& surf) { return surf->mapped; }); } + +bool CSessionLockManager::shallConsiderLockMissing() { + if (!m_pSessionLock) + return false; + + static auto LOCKDEAD_SCREEN_DELAY = CConfigValue("misc:lockdead_screen_delay"); + + return m_pSessionLock->mLockTimer.getMillis() > *LOCKDEAD_SCREEN_DELAY; +} \ No newline at end of file diff --git a/src/managers/SessionLockManager.hpp b/src/managers/SessionLockManager.hpp index 9b3b882c..59090605 100644 --- a/src/managers/SessionLockManager.hpp +++ b/src/managers/SessionLockManager.hpp @@ -29,6 +29,7 @@ struct SSessionLockSurface { struct SSessionLock { WP lock; + CTimer mLockTimer; std::vector> vSessionLockSurfaces; std::unordered_map mMonitorsWithoutMappedSurfaceTimers; @@ -61,6 +62,8 @@ class CSessionLockManager { void onLockscreenRenderedOnMonitor(uint64_t id); + bool shallConsiderLockMissing(); + private: UP m_pSessionLock; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 37e6f81e..3eba8458 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1045,9 +1045,10 @@ void CHyprRenderer::renderLockscreen(PHLMONITOR pMonitor, timespec* now, const C Vector2D translate = {geometry.x, geometry.y}; const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID); - if (!PSLS) - renderSessionLockMissing(pMonitor); - else { + if (!PSLS) { + if (g_pSessionLockManager->shallConsiderLockMissing()) + renderSessionLockMissing(pMonitor); + } else { renderSessionLockSurface(PSLS, pMonitor, now); g_pSessionLockManager->onLockscreenRenderedOnMonitor(pMonitor->ID); } @@ -2726,7 +2727,7 @@ bool CHyprRenderer::beginRender(PHLMONITOR pMonitor, CRegion& damage, eRenderMod return true; } - /* This is a constant expression, as we always use double-buffering in our swapchain + /* This is a constant expression, as we always use double-buffering in our swapchain TODO: Rewrite the CDamageRing to take advantage of that maybe? It's made to support longer swapchains atm because we used to do wlroots */ static constexpr const int HL_BUFFER_AGE = 2; From fb91c2550f5184785680f6af7b069cb857568104 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 16:16:49 +0000 Subject: [PATCH 0031/1566] renderer: don't render unmapped popups fixes #8485 --- src/desktop/Popup.hpp | 4 ++-- src/render/Renderer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index f34b8a2c..e9b3e0f0 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -41,6 +41,7 @@ class CPopup { // SP m_pWLSurface; + bool m_bMapped = false; private: // T1 owners, each popup has to have one of these @@ -57,8 +58,7 @@ class CPopup { bool m_bRequestedReposition = false; - bool m_bInert = false; - bool m_bMapped = false; + bool m_bInert = false; // std::vector> m_vChildren; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 3eba8458..6067a7f2 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -732,7 +732,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe pWindow->m_pPopupHead->breadthfirst( [](CPopup* popup, void* data) { - if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource()) + if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped) return; auto pos = popup->coordsRelativeToParent(); auto rd = (SRenderData*)data; @@ -822,7 +822,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim if (popups) { pLayer->popupHead->breadthfirst( [](CPopup* popup, void* data) { - if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource()) + if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped) return; Vector2D pos = popup->coordsRelativeToParent(); From 4f591e807abe1865d8f8135a1a64932cc418d0f0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 16:42:30 +0000 Subject: [PATCH 0032/1566] renderer: simplify blur enabling logic --- src/render/OpenGL.cpp | 4 +--- src/render/Renderer.cpp | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 63a7e822..9c00daee 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -2036,7 +2036,6 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWin void CHyprOpenGLImpl::renderTextureWithBlur(SP tex, CBox* pBox, float a, SP pSurface, int round, bool blockBlurOptimization, float blurA) { RASSERT(m_RenderData.pMonitor, "Tried to render texture with blur without begin()!"); - static auto PBLURENABLED = CConfigValue("decoration:blur:enabled"); static auto PNOBLUROVERSIZED = CConfigValue("decoration:no_blur_on_oversized"); TRACY_GPU_ZONE("RenderTextureWithBlur"); @@ -2050,8 +2049,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(SP tex, CBox* pBox, float m_RenderData.renderModif.applyToRegion(texDamage); - if (*PBLURENABLED == 0 || (*PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) || - (m_pCurrentWindow.lock() && (m_pCurrentWindow->m_sWindowData.noBlur.valueOrDefault() || m_pCurrentWindow->m_sWindowData.RGBX.valueOrDefault()))) { + if (*PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) { renderTexture(tex, pBox, a, round, false, true); return; } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 6067a7f2..fc17ef9f 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -174,6 +174,7 @@ static void renderSurface(SP surface, int x, int y, void* da } const auto RDATA = (SRenderData*)data; + const bool BLUR = RDATA->blur && !TEXTURE->m_bOpaque; const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow && g_pInputManager->dragMode == MBIND_RESIZE; TRACY_GPU_ZONE("RenderSurface"); @@ -270,12 +271,12 @@ static void renderSurface(SP surface, int x, int y, void* da // is a subsurface that does NOT cover the entire frame. In such cases, we probably should fall back // to what we do for misaligned surfaces (blur the entire thing and then render shit without blur) if (RDATA->surfaceCounter == 0 && !RDATA->popup) { - if (RDATA->blur) + if (BLUR) g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, surface, rounding, RDATA->blockBlurOptimization, RDATA->fadeAlpha); else g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA, rounding, false, true); } else { - if (RDATA->blur && RDATA->popup) + if (BLUR && RDATA->popup) g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, surface, rounding, true, RDATA->fadeAlpha); else g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA, rounding, false, true); @@ -591,6 +592,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe // whether to use m_fMovingToWorkspaceAlpha, only if fading out into an invisible ws const bool USE_WORKSPACE_FADE_ALPHA = pWindow->m_iMonitorMovedFrom != -1 && !g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace); + const bool DONT_BLUR = pWindow->m_sWindowData.noBlur.valueOrDefault() || pWindow->m_sWindowData.RGBX.valueOrDefault() || pWindow->opaque(); renderdata.surface = pWindow->m_pWLSurface->resource(); renderdata.dontRound = pWindow->isEffectiveInternalFSMode(FSMODE_FULLSCREEN) || pWindow->m_sWindowData.noRounding.valueOrDefault(); @@ -599,7 +601,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe renderdata.alpha = pWindow->m_fActiveInactiveAlpha.value(); renderdata.decorate = decorate && !pWindow->m_bX11DoesntWantBorders && !pWindow->isEffectiveInternalFSMode(FSMODE_FULLSCREEN); renderdata.rounding = ignoreAllGeometry || renderdata.dontRound ? 0 : pWindow->rounding() * pMonitor->scale; - renderdata.blur = !ignoreAllGeometry; // if it shouldn't, it will be ignored later + renderdata.blur = !ignoreAllGeometry && *PBLUR && !DONT_BLUR; renderdata.pWindow = pWindow; if (ignoreAllGeometry) { @@ -715,7 +717,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe static CConfigValue PBLURPOPUPS = CConfigValue("decoration:blur:popups"); static CConfigValue PBLURIGNOREA = CConfigValue("decoration:blur:popups_ignorealpha"); - renderdata.blur = *PBLURPOPUPS; + renderdata.blur = *PBLURPOPUPS && *PBLUR; const auto DM = g_pHyprOpenGL->m_RenderData.discardMode; const auto DA = g_pHyprOpenGL->m_RenderData.discardOpacity; @@ -734,13 +736,15 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe [](CPopup* popup, void* data) { if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped) return; - auto pos = popup->coordsRelativeToParent(); - auto rd = (SRenderData*)data; - Vector2D oldPos = {rd->x, rd->y}; + const auto pos = popup->coordsRelativeToParent(); + auto rd = (SRenderData*)data; + const Vector2D oldPos = {rd->x, rd->y}; rd->x += pos.x; rd->y += pos.y; + popup->m_pWLSurface->resource()->breadthfirst([](SP s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, data); + rd->x = oldPos.x; rd->y = oldPos.y; }, @@ -785,6 +789,8 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim return; } + static auto PBLUR = CConfigValue("decoration:blur:enabled"); + TRACY_GPU_ZONE("RenderLayer"); const auto REALPOS = pLayer->realPosition.value(); @@ -792,7 +798,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim SRenderData renderdata = {pMonitor, time, REALPOS.x, REALPOS.y}; renderdata.fadeAlpha = pLayer->alpha.value(); - renderdata.blur = pLayer->forceBlur; + renderdata.blur = pLayer->forceBlur && *PBLUR; renderdata.surface = pLayer->surface->resource(); renderdata.decorate = false; renderdata.w = REALSIZ.x; From 8d5cdedbd350b4730a1aa57dc5491c88dff3415e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 16:46:49 +0000 Subject: [PATCH 0033/1566] hyprpm: fix format crash ref #8487 --- hyprpm/src/core/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 051ad500..db315193 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -272,7 +272,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& } if (m_bVerbose) - std::println("{}", verboseString("shell returned: " + out)); + std::println("{}", verboseString("shell returned: {}", out)); if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/" + p.output)) { progress.printMessageAbove(failureString("Plugin {} failed to build.\n" From b735295d2b0025b26f88852c06f65514a963c711 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 19:31:54 +0000 Subject: [PATCH 0034/1566] windows/xdg: minor cleanup of min/max size calculations fixes #8495 --- src/desktop/Window.cpp | 26 ++++++++++++++++++++++++++ src/desktop/Window.hpp | 19 +++++++++---------- src/events/Windows.cpp | 8 ++++---- src/layout/DwindleLayout.cpp | 2 +- src/layout/IHyprLayout.cpp | 8 ++++---- src/layout/MasterLayout.cpp | 4 ++-- src/managers/XWaylandManager.cpp | 30 ------------------------------ src/managers/XWaylandManager.hpp | 2 -- src/protocols/XDGShell.cpp | 8 ++++++++ src/protocols/XDGShell.hpp | 3 +++ 10 files changed, 57 insertions(+), 53 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 20fed565..e74e13a2 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1601,3 +1601,29 @@ bool CWindow::isX11OverrideRedirect() { bool CWindow::isModal() { return (m_pXWaylandSurface && m_pXWaylandSurface->modal); } + +Vector2D CWindow::requestedMinSize() { + if ((m_bIsX11 && !m_pXWaylandSurface->sizeHints) || (!m_bIsX11 && !m_pXDGSurface->toplevel)) + return Vector2D(1, 1); + + Vector2D minSize = m_bIsX11 ? Vector2D(m_pXWaylandSurface->sizeHints->min_width, m_pXWaylandSurface->sizeHints->min_height) : m_pXDGSurface->toplevel->layoutMinSize(); + + minSize = minSize.clamp({1, 1}); + + return minSize; +} + +Vector2D CWindow::requestedMaxSize() { + constexpr int NO_MAX_SIZE_LIMIT = 99999; + if (((m_bIsX11 && !m_pXWaylandSurface->sizeHints) || (!m_bIsX11 && !m_pXDGSurface->toplevel) || m_sWindowData.noMaxSize.valueOrDefault())) + return Vector2D(NO_MAX_SIZE_LIMIT, NO_MAX_SIZE_LIMIT); + + Vector2D maxSize = m_bIsX11 ? Vector2D(m_pXWaylandSurface->sizeHints->max_width, m_pXWaylandSurface->sizeHints->max_height) : m_pXDGSurface->toplevel->layoutMaxSize(); + + if (maxSize.x < 5) + maxSize.x = NO_MAX_SIZE_LIMIT; + if (maxSize.y < 5) + maxSize.y = NO_MAX_SIZE_LIMIT; + + return maxSize; +} diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index b8dd3cf7..ac81e5ef 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -403,12 +403,9 @@ class CWindow { } // methods - CBox getFullWindowBoundingBox(); - SBoxExtents getFullWindowExtents(); - CBox getWindowBoxUnified(uint64_t props); - inline CBox getWindowMainSurfaceBox() const { - return {m_vRealPosition.value().x, m_vRealPosition.value().y, m_vRealSize.value().x, m_vRealSize.value().y}; - } + CBox getFullWindowBoundingBox(); + SBoxExtents getFullWindowExtents(); + CBox getWindowBoxUnified(uint64_t props); CBox getWindowIdealBoundingBoxIgnoreReserved(); void addWindowDeco(std::unique_ptr deco); void updateWindowDecos(); @@ -441,19 +438,15 @@ class CWindow { void activate(bool force = false); int surfacesCount(); void clampWindowSize(const std::optional minSize, const std::optional maxSize); - bool isFullscreen(); bool isEffectiveInternalFSMode(const eFullscreenMode); - int getRealBorderSize(); void updateWindowData(); void updateWindowData(const struct SWorkspaceRule&); - void onBorderAngleAnimEnd(void* ptr); bool isInCurvedCorner(double x, double y); bool hasPopupAt(const Vector2D& pos); int popupsCount(); - void applyGroupRules(); void createGroup(); void destroyGroup(); @@ -481,6 +474,12 @@ class CWindow { void unsetWindowData(eOverridePriority priority); bool isX11OverrideRedirect(); bool isModal(); + Vector2D requestedMinSize(); + Vector2D requestedMaxSize(); + + inline CBox getWindowMainSurfaceBox() const { + return {m_vRealPosition.value().x, m_vRealPosition.value().y, m_vRealSize.value().x, m_vRealSize.value().y}; + } // listeners void onAck(uint32_t serial); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 77df7373..73ab45c1 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -346,7 +346,7 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); - const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW); + const auto MAXSIZE = PWINDOW->requestedMaxSize(); const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, PMONITOR->vecSize.x) : stringToFloatClamp(SIZEXSTR, PWINDOW->m_vRealSize.goal().x, PMONITOR->vecSize.x); @@ -469,7 +469,7 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); - const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW); + const auto MAXSIZE = PWINDOW->requestedMaxSize(); const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, PMONITOR->vecSize.x) : stringToPercentage(SIZEXSTR, PMONITOR->vecSize.x); @@ -753,8 +753,8 @@ void Events::listener_commitWindow(void* owner, void* data) { PWINDOW->m_vReportedSize = PWINDOW->m_vPendingReportedSize; // apply pending size. We pinged, the window ponged. if (!PWINDOW->m_bIsX11 && !PWINDOW->isFullscreen() && PWINDOW->m_bIsFloating) { - const auto MINSIZE = PWINDOW->m_pXDGSurface->toplevel->current.minSize; - const auto MAXSIZE = PWINDOW->m_pXDGSurface->toplevel->current.maxSize; + const auto MINSIZE = PWINDOW->m_pXDGSurface->toplevel->layoutMinSize(); + const auto MAXSIZE = PWINDOW->m_pXDGSurface->toplevel->layoutMaxSize(); PWINDOW->clampWindowSize(MINSIZE, MAXSIZE > Vector2D{1, 1} ? std::optional{MAXSIZE} : std::nullopt); g_pHyprRenderer->damageWindow(PWINDOW); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index e6e9090f..c3e394f3 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -283,7 +283,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir // first, check if OPENINGON isn't too big. const auto PREDSIZEMAX = OPENINGON ? Vector2D(OPENINGON->box.w, OPENINGON->box.h) : PMONITOR->vecSize; - if (const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); MAXSIZE.x < PREDSIZEMAX.x || MAXSIZE.y < PREDSIZEMAX.y) { + if (const auto MAXSIZE = pWindow->requestedMaxSize(); MAXSIZE.x < PREDSIZEMAX.x || MAXSIZE.y < PREDSIZEMAX.y) { // we can't continue. make it floating. pWindow->m_bIsFloating = true; m_lDwindleNodesData.remove(*PNODE); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index a312555f..af8b907c 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -597,12 +597,12 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { } else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) { if (DRAGGINGWINDOW->m_bIsFloating) { - Vector2D MINSIZE = g_pXWaylandManager->getMinSizeForWindow(DRAGGINGWINDOW).clamp(DRAGGINGWINDOW->m_sWindowData.minSize.valueOr(Vector2D(20, 20))); + Vector2D MINSIZE = DRAGGINGWINDOW->requestedMinSize().clamp(DRAGGINGWINDOW->m_sWindowData.minSize.valueOr(Vector2D(20, 20))); Vector2D MAXSIZE; if (DRAGGINGWINDOW->m_sWindowData.maxSize.hasValue()) - MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW).clamp({}, DRAGGINGWINDOW->m_sWindowData.maxSize.value()); + MAXSIZE = DRAGGINGWINDOW->requestedMaxSize().clamp({}, DRAGGINGWINDOW->m_sWindowData.maxSize.value()); else - MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW).clamp({}, Vector2D(std::numeric_limits::max(), std::numeric_limits::max())); + MAXSIZE = DRAGGINGWINDOW->requestedMaxSize().clamp({}, Vector2D(std::numeric_limits::max(), std::numeric_limits::max())); Vector2D newSize = m_vBeginDragSizeXY; Vector2D newPos = m_vBeginDragPositionXY; @@ -884,7 +884,7 @@ Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // ge const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); - const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); + const auto MAXSIZE = pWindow->requestedMaxSize(); const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, g_pCompositor->m_pLastMonitor->vecSize.x) : stringToPercentage(SIZEXSTR, g_pCompositor->m_pLastMonitor->vecSize.x); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index b8b3efea..695dcc99 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -200,7 +200,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dire PNODE->percMaster = lastSplitPercent; // first, check if it isn't too big. - if (const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); MAXSIZE.x < PMONITOR->vecSize.x * lastSplitPercent || MAXSIZE.y < PMONITOR->vecSize.y) { + if (const auto MAXSIZE = pWindow->requestedMaxSize(); MAXSIZE.x < PMONITOR->vecSize.x * lastSplitPercent || MAXSIZE.y < PMONITOR->vecSize.y) { // we can't continue. make it floating. pWindow->m_bIsFloating = true; m_lMasterNodesData.remove(*PNODE); @@ -212,7 +212,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dire PNODE->percMaster = lastSplitPercent; // first, check if it isn't too big. - if (const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); + if (const auto MAXSIZE = pWindow->requestedMaxSize(); MAXSIZE.x < PMONITOR->vecSize.x * (1 - lastSplitPercent) || MAXSIZE.y < PMONITOR->vecSize.y * (1.f / (WINDOWSONWORKSPACE - 1))) { // we can't continue. make it floating. pWindow->m_bIsFloating = true; diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index d0dda8e6..832173eb 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -213,36 +213,6 @@ void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscree pWindow->m_pXDGSurface->toplevel->setFullscreen(fullscreen); } -Vector2D CHyprXWaylandManager::getMaxSizeForWindow(PHLWINDOW pWindow) { - constexpr int NO_MAX_SIZE_LIMIT = 99999; - if (!validMapped(pWindow) || - ((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel) || - pWindow->m_sWindowData.noMaxSize.valueOrDefault())) - return Vector2D(NO_MAX_SIZE_LIMIT, NO_MAX_SIZE_LIMIT); - - Vector2D maxSize = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->max_width, pWindow->m_pXWaylandSurface->sizeHints->max_height) : - pWindow->m_pXDGSurface->toplevel->current.maxSize; - - if (maxSize.x < 5) - maxSize.x = NO_MAX_SIZE_LIMIT; - if (maxSize.y < 5) - maxSize.y = NO_MAX_SIZE_LIMIT; - - return maxSize; -} - -Vector2D CHyprXWaylandManager::getMinSizeForWindow(PHLWINDOW pWindow) { - if (!validMapped(pWindow) || ((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel))) - return Vector2D(0, 0); - - Vector2D minSize = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->min_width, pWindow->m_pXWaylandSurface->sizeHints->min_height) : - pWindow->m_pXDGSurface->toplevel->current.minSize; - - minSize = minSize.clamp({1, 1}); - - return minSize; -} - Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index a9f95974..508a20d6 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -21,8 +21,6 @@ class CHyprXWaylandManager { void setWindowFullscreen(PHLWINDOW, bool); bool shouldBeFloated(PHLWINDOW, bool pending = false); void checkBorders(PHLWINDOW); - Vector2D getMaxSizeForWindow(PHLWINDOW); - Vector2D getMinSizeForWindow(PHLWINDOW); Vector2D xwaylandToWaylandCoords(const Vector2D&); }; diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 25d8b1ba..932882e9 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -323,6 +323,14 @@ void CXDGToplevelResource::close() { resource->sendClose(); } +Vector2D CXDGToplevelResource::layoutMinSize() { + return owner ? current.minSize + owner->current.geometry.pos() : current.minSize; +} + +Vector2D CXDGToplevelResource::layoutMaxSize() { + return owner ? current.maxSize + owner->current.geometry.pos() : current.maxSize; +} + CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SP owner_, SP surface_) : owner(owner_), surface(surface_), resource(resource_) { if (!good()) diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp index 9c766c20..ef847f3b 100644 --- a/src/protocols/XDGShell.hpp +++ b/src/protocols/XDGShell.hpp @@ -99,6 +99,9 @@ class CXDGToplevelResource { bool good(); + Vector2D layoutMinSize(); + Vector2D layoutMaxSize(); + // schedule a configure event uint32_t setSize(const Vector2D& size); uint32_t setMaximized(bool maximized); From 9b03307653c179a86a8dfdb4e5d16446d0cf6e23 Mon Sep 17 00:00:00 2001 From: Alessio Molinari Date: Sun, 17 Nov 2024 20:34:03 +0100 Subject: [PATCH 0035/1566] hooks: add pre connected/disconnected monitor events (#8503) --- src/helpers/Monitor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index bfab2fd3..9ac48220 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -39,6 +39,7 @@ CMonitor::~CMonitor() { } void CMonitor::onConnect(bool noRule) { + EMIT_HOOK_EVENT("preMonitorAdded", self.lock()); CScopeGuard x = {[]() { g_pCompositor->arrangeMonitors(); }}; if (output->supportsExplicit) { @@ -238,6 +239,7 @@ void CMonitor::onConnect(bool noRule) { } void CMonitor::onDisconnect(bool destroy) { + EMIT_HOOK_EVENT("preMonitorRemoved", self.lock()); CScopeGuard x = {[this]() { if (g_pCompositor->m_bIsShuttingDown) return; From e8717a4fce1eafa44d5b106b8159d56e8d368840 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 21:57:00 +0000 Subject: [PATCH 0036/1566] shell: don't use fgrep, prefer grep -F --- src/debug/CrashReporter.cpp | 2 +- src/debug/HyprCtl.cpp | 2 +- src/helpers/MiscFunctions.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp index 000d8c5d..319c1414 100644 --- a/src/debug/CrashReporter.cpp +++ b/src/debug/CrashReporter.cpp @@ -159,7 +159,7 @@ void CrashReporter::createAndSaveCrash(int sig) { finalCrashReport += "GPU:\n\t"; #if defined(__DragonFly__) || defined(__FreeBSD__) - finalCrashReport.writeCmdOutput("pciconf -lv | fgrep -A4 vga"); + finalCrashReport.writeCmdOutput("pciconf -lv | grep -F -A4 vga"); #else finalCrashReport.writeCmdOutput("lspci -vnn | grep VGA"); #endif diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 964a193b..6c9c2b75 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -946,7 +946,7 @@ std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request) result += "\n\n"; #if defined(__DragonFly__) || defined(__FreeBSD__) - const std::string GPUINFO = execAndGet("pciconf -lv | fgrep -A4 vga"); + const std::string GPUINFO = execAndGet("pciconf -lv | grep -F -A4 vga"); #elif defined(__arm__) || defined(__aarch64__) std::string GPUINFO; const std::filesystem::path dev_tree = "/proc/device-tree"; diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 7b4d63a7..cfaae542 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -606,7 +606,7 @@ void logSystemInfo() { Debug::log(NONE, "\n"); #if defined(__DragonFly__) || defined(__FreeBSD__) - const std::string GPUINFO = execAndGet("pciconf -lv | fgrep -A4 vga"); + const std::string GPUINFO = execAndGet("pciconf -lv | grep -F -A4 vga"); #elif defined(__arm__) || defined(__aarch64__) const std::string GPUINFO = execAndGet("cat /proc/device-tree/soc*/gpu*/compatible"); #else From 1ba050d603dca644aca48872f62388d794c030b9 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Nov 2024 21:58:00 +0000 Subject: [PATCH 0037/1566] shell: propagate new machanism from hyprctl to miscfunctions --- src/helpers/MiscFunctions.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index cfaae542..6ad1b37a 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -608,7 +608,24 @@ void logSystemInfo() { #if defined(__DragonFly__) || defined(__FreeBSD__) const std::string GPUINFO = execAndGet("pciconf -lv | grep -F -A4 vga"); #elif defined(__arm__) || defined(__aarch64__) - const std::string GPUINFO = execAndGet("cat /proc/device-tree/soc*/gpu*/compatible"); + const std::string GPUINFO; + const std::filesystem::path dev_tree = "/proc/device-tree"; + try { + if (std::filesystem::exists(dev_tree) && std::filesystem::is_directory(dev_tree)) { + std::for_each(std::filesystem::directory_iterator(dev_tree), std::filesystem::directory_iterator{}, [&](const std::filesystem::directory_entry& entry) { + if (std::filesystem::is_directory(entry) && entry.path().filename().string().starts_with("soc")) { + std::for_each(std::filesystem::directory_iterator(entry.path()), std::filesystem::directory_iterator{}, [&](const std::filesystem::directory_entry& sub_entry) { + if (std::filesystem::is_directory(sub_entry) && sub_entry.path().filename().string().starts_with("gpu")) { + std::filesystem::path file_path = sub_entry.path() / "compatible"; + std::ifstream file(file_path); + if (file) + GPUINFO.append(std::istreambuf_iterator(file), std::istreambuf_iterator()); + } + }); + } + }); + } + } catch (...) { GPUINFO = "error"; } #else const std::string GPUINFO = execAndGet("lspci -vnn | grep VGA"); #endif From 2259a885513e8ec793210ceb9d40ca096161849d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Nov 2024 13:59:57 +0000 Subject: [PATCH 0038/1566] miscfunctions: add missing include --- src/helpers/MiscFunctions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 6ad1b37a..c7cd9ed4 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include From 6744bb57c639d5359a414eea2566328bb05c7065 Mon Sep 17 00:00:00 2001 From: johannes hanika Date: Mon, 18 Nov 2024 15:02:34 +0100 Subject: [PATCH 0039/1566] constraints: don't warp pointer position on release (#8491) this was annoying for nuklear properties/ui slider elements that grab the pointer via GLFW_CURSOR_DISABLE to allow more range and finer control. upon mouse release, the pointer is reset to the middle of the window without this patch, making long mouse movements necessary to go back to the original position for readjustments. fwiw the new behaviour is consistent with x11 and weston. --- src/protocols/PointerConstraints.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp index 0f2dd991..7f08a7df 100644 --- a/src/protocols/PointerConstraints.cpp +++ b/src/protocols/PointerConstraints.cpp @@ -188,7 +188,7 @@ Vector2D CPointerConstraint::logicPositionHint() { const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal(); const auto CONSTRAINTPOS = SURFBOX.has_value() ? SURFBOX->pos() : Vector2D{}; - return hintSet ? CONSTRAINTPOS + positionHint : (locked ? CONSTRAINTPOS + SURFBOX->size() / 2.f : cursorPosOnActivate); + return hintSet ? CONSTRAINTPOS + positionHint : cursorPosOnActivate; } CPointerConstraintsProtocol::CPointerConstraintsProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { From 505c1f8f4a5a4a97534f1906a47c11de638d970d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Nov 2024 14:35:09 +0000 Subject: [PATCH 0040/1566] miscfunctions: fix cross build --- src/helpers/MiscFunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index c7cd9ed4..c8b3bef4 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -609,7 +609,7 @@ void logSystemInfo() { #if defined(__DragonFly__) || defined(__FreeBSD__) const std::string GPUINFO = execAndGet("pciconf -lv | grep -F -A4 vga"); #elif defined(__arm__) || defined(__aarch64__) - const std::string GPUINFO; + std::string GPUINFO; const std::filesystem::path dev_tree = "/proc/device-tree"; try { if (std::filesystem::exists(dev_tree) && std::filesystem::is_directory(dev_tree)) { From 97493511f96af288e1f7b2bd3a119e47d75541fc Mon Sep 17 00:00:00 2001 From: Aqa-Ib Date: Mon, 18 Nov 2024 15:44:15 +0100 Subject: [PATCH 0041/1566] internal: fix changeWindowZOrder reordering incorrectly (#8494) --- src/Compositor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index fbbfd7e7..0e0c75a1 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1389,6 +1389,9 @@ void CCompositor::changeWindowZOrder(PHLWINDOW pWindow, bool top) { if (!validMapped(pWindow)) return; + if (top) + pWindow->m_bCreatedOverFullscreen = true; + if (pWindow == (top ? m_vWindows.back() : m_vWindows.front())) return; @@ -1413,9 +1416,6 @@ void CCompositor::changeWindowZOrder(PHLWINDOW pWindow, bool top) { g_pHyprRenderer->damageMonitor(pw->m_pMonitor.lock()); }; - if (top) - pWindow->m_bCreatedOverFullscreen = true; - if (!pWindow->m_bIsX11) moveToZ(pWindow, top); else { From df9ff4489973afa9e29bb94ac47c946db745b460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=87=BA=F0=9F=87=A6=20Sviatoslav=20Sydorenko=20=28?= =?UTF-8?q?=D0=A1=D0=B2=D1=8F=D1=82=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A1?= =?UTF-8?q?=D0=B8=D0=B4=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE=29?= Date: Mon, 18 Nov 2024 16:54:18 +0100 Subject: [PATCH 0042/1566] Fix example config name in auto-generated cfg header (#8509) Previously, it was suggesting to find `hypr.conf` in the `examples/` folder which doesn't exist. This patch fixed that to point to the existing file. Additionally, the change updates `HYPR` to `HYPRLAND` in the same header. --- src/config/defaultConfig.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index d680e92b..c4eb3385 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -4,8 +4,8 @@ inline const std::string AUTOCONFIG = R"#( # ####################################################################################### -# AUTOGENERATED HYPR CONFIG. -# PLEASE USE THE CONFIG PROVIDED IN THE GIT REPO /examples/hypr.conf AND EDIT IT, +# AUTOGENERATED HYPRLAND CONFIG. +# PLEASE USE THE CONFIG PROVIDED IN THE GIT REPO /examples/hyprland.conf AND EDIT IT, # OR EDIT THIS ONE ACCORDING TO THE WIKI INSTRUCTIONS. # ####################################################################################### From cc923ad031579a5d1ebe07269d5ecb291331ee51 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:45:22 +0100 Subject: [PATCH 0043/1566] config: update the configStringToInt implementation (#8476) Copied from hyprlang and removed std::expected. --- src/helpers/MiscFunctions.cpp | 74 ++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index c8b3bef4..80681826 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -692,43 +692,79 @@ int64_t getPPIDof(int64_t pid) { } int64_t configStringToInt(const std::string& VALUE) { + auto parseHex = [](const std::string& value) -> int64_t { + try { + size_t position; + auto result = stoll(value, &position, 16); + if (position == value.size()) + return result; + } catch (const std::exception&) {} + throw std::invalid_argument("invalid hex " + value); + }; if (VALUE.starts_with("0x")) { // Values with 0x are hex - const auto VALUEWITHOUTHEX = VALUE.substr(2); - return stol(VALUEWITHOUTHEX, nullptr, 16); + return parseHex(VALUE); } else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) { - const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6); + const auto VALUEWITHOUTFUNC = trim(VALUE.substr(5, VALUE.length() - 6)); - if (trim(VALUEWITHOUTFUNC).length() != 8) { - Debug::log(WARN, "invalid length {} for rgba", VALUEWITHOUTFUNC.length()); - throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)"); + // try doing it the comma way first + if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 3) { + // cool + std::string rolling = VALUEWITHOUTFUNC; + auto r = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + rolling = rolling.substr(rolling.find(',') + 1); + auto g = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + rolling = rolling.substr(rolling.find(',') + 1); + auto b = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + rolling = rolling.substr(rolling.find(',') + 1); + uint8_t a = 0; + try { + a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f); + } catch (std::exception& e) { throw std::invalid_argument("failed parsing " + VALUEWITHOUTFUNC); } + + return a * (Hyprlang::INT)0x1000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b; + } else if (VALUEWITHOUTFUNC.length() == 8) { + const auto RGBA = parseHex(VALUEWITHOUTFUNC); + // now we need to RGBA -> ARGB. The config holds ARGB only. + return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF); } - const auto RGBA = std::stol(VALUEWITHOUTFUNC, nullptr, 16); + throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values"); - // now we need to RGBA -> ARGB. The config holds ARGB only. - return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF); } else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) { - const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5); + const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5)); - if (trim(VALUEWITHOUTFUNC).length() != 6) { - Debug::log(WARN, "invalid length {} for rgb", VALUEWITHOUTFUNC.length()); - throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)"); + // try doing it the comma way first + if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 2) { + // cool + std::string rolling = VALUEWITHOUTFUNC; + auto r = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + rolling = rolling.substr(rolling.find(',') + 1); + auto g = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + rolling = rolling.substr(rolling.find(',') + 1); + auto b = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); + + return (Hyprlang::INT)0xFF000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b; + } else if (VALUEWITHOUTFUNC.length() == 6) { + return parseHex(VALUEWITHOUTFUNC) + 0xFF000000; } - const auto RGB = std::stol(VALUEWITHOUTFUNC, nullptr, 16); - - return RGB + 0xFF000000; // 0xFF for opaque + throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values"); } else if (VALUE.starts_with("true") || VALUE.starts_with("on") || VALUE.starts_with("yes")) { return 1; } else if (VALUE.starts_with("false") || VALUE.starts_with("off") || VALUE.starts_with("no")) { return 0; } - if (VALUE.empty() || !isNumber(VALUE)) - return 0; + if (VALUE.empty() || !isNumber(VALUE, false)) + throw std::invalid_argument("cannot parse \"" + VALUE + "\" as an int."); - return std::stoll(VALUE); + try { + const auto RES = std::stoll(VALUE); + return RES; + } catch (std::exception& e) { throw std::invalid_argument(std::string{"stoll threw: "} + e.what()); } + + return 0; } Vector2D configStringToVector2D(const std::string& VALUE) { From 6113f4da7fa9839645525e57ff841db5bb00e475 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:48:13 +0000 Subject: [PATCH 0044/1566] keybinds: allow repeating multiple binds (#8290) --- src/managers/KeybindManager.cpp | 69 +++++++++++++++------------------ src/managers/KeybindManager.hpp | 7 ++-- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 4d2f4dcc..a0cd01a9 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -144,11 +144,30 @@ CKeybindManager::CKeybindManager() { }, nullptr); + m_pRepeatKeyTimer = makeShared( + std::nullopt, + [this](SP self, void* data) { + if (m_vActiveKeybinds.size() == 0 || g_pSeatManager->keyboard.expired()) + return; + + for (SKeybind* k : m_vActiveKeybinds) { + const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); + + Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); + DISPATCHER->second(k->arg); + } + + const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); + self->updateTimeout(std::chrono::milliseconds(1000 / PACTIVEKEEB->repeatRate)); + }, + nullptr); + g_pEventLoopManager->addTimer(m_pLongPressTimer); + g_pEventLoopManager->addTimer(m_pRepeatKeyTimer); static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd - m_pActiveKeybind = nullptr; + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; m_vPressedSpecialBinds.clear(); }); @@ -161,12 +180,16 @@ CKeybindManager::~CKeybindManager() { g_pEventLoopManager->removeTimer(m_pLongPressTimer); m_pLongPressTimer.reset(); } + if (m_pRepeatKeyTimer && g_pEventLoopManager) { + g_pEventLoopManager->removeTimer(m_pRepeatKeyTimer); + m_pRepeatKeyTimer.reset(); + } } void CKeybindManager::addKeybind(SKeybind kb) { m_lKeybinds.push_back(kb); - m_pActiveKeybind = nullptr; + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; } @@ -180,7 +203,7 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { } } - m_pActiveKeybind = nullptr; + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; } @@ -426,11 +449,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { .submapAtPress = m_szCurrentSelectedSubmap, }; - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; - } + m_vActiveKeybinds.clear(); m_pLastLongPressKeybind = nullptr; @@ -482,11 +501,7 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { m_tScrollTimer.reset(); - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; - } + m_vActiveKeybinds.clear(); bool found = false; if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { @@ -525,11 +540,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { .modmaskAtPressTime = MODS, }; - if (m_pActiveKeybindEventSource) { - wl_event_source_remove(m_pActiveKeybindEventSource); - m_pActiveKeybindEventSource = nullptr; - m_pActiveKeybind = nullptr; - } + m_vActiveKeybinds.clear(); if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) { m_dPressedKeys.push_back(KEY); @@ -580,22 +591,6 @@ void CKeybindManager::onSwitchOffEvent(const std::string& switchName) { handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:off:" + switchName}, true); } -int repeatKeyHandler(void* data) { - SKeybind** ppActiveKeybind = (SKeybind**)data; - - if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired()) - return 0; - - const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler); - - Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); - DISPATCHER->second((*ppActiveKeybind)->arg); - - wl_event_source_timer_update(g_pKeybindManager->m_pActiveKeybindEventSource, 1000 / g_pSeatManager->keyboard->repeatRate); - - return 0; -} - eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set keybindKeysyms, const std::set pressedKeysyms) { // Returns whether two sets of keysyms are equal, partially equal, or not // matching. (Partially matching means that pressed is a subset of bound) @@ -770,12 +765,10 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP } if (k.repeat) { - m_pActiveKeybind = &k; - m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, repeatKeyHandler, &m_pActiveKeybind); - const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); + m_vActiveKeybinds.push_back(&k); + m_pRepeatKeyTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); } if (!k.nonConsuming) diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 4a0af6e9..d375db0f 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -102,8 +102,6 @@ class CKeybindManager { std::unordered_map> m_mDispatchers; - wl_event_source* m_pActiveKeybindEventSource = nullptr; - bool m_bGroupsLocked = false; std::list m_lKeybinds; @@ -121,8 +119,9 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; - SKeybind * m_pActiveKeybind = nullptr, *m_pLastLongPressKeybind = nullptr; - SP m_pLongPressTimer; + std::vector m_vActiveKeybinds; + SKeybind* m_pLastLongPressKeybind = nullptr; + SP m_pLongPressTimer, m_pRepeatKeyTimer; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0; From 936dfedbadbae761cd307ba7509467b55ac5e1ae Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Nov 2024 19:56:26 +0000 Subject: [PATCH 0045/1566] keybinds: move to managed pointers --- src/debug/HyprCtl.cpp | 26 ++++---- src/managers/KeybindManager.cpp | 107 +++++++++++++++----------------- src/managers/KeybindManager.hpp | 10 +-- 3 files changed, 68 insertions(+), 75 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 6c9c2b75..1b94296f 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -814,28 +814,28 @@ std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string requ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { std::string ret = ""; if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { - for (auto const& kb : g_pKeybindManager->m_lKeybinds) { + for (auto const& kb : g_pKeybindManager->m_vKeybinds) { ret += "bind"; - if (kb.locked) + if (kb->locked) ret += "l"; - if (kb.mouse) + if (kb->mouse) ret += "m"; - if (kb.release) + if (kb->release) ret += "r"; - if (kb.repeat) + if (kb->repeat) ret += "e"; - if (kb.nonConsuming) + if (kb->nonConsuming) ret += "n"; - if (kb.hasDescription) + if (kb->hasDescription) ret += "d"; - ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdescription: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, - kb.key, kb.keycode, kb.catchAll, kb.description, kb.handler, kb.arg); + ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdescription: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb->modmask, + kb->submap, kb->key, kb->keycode, kb->catchAll, kb->description, kb->handler, kb->arg); } } else { // json ret += "["; - for (auto const& kb : g_pKeybindManager->m_lKeybinds) { + for (auto const& kb : g_pKeybindManager->m_vKeybinds) { ret += std::format( R"#( {{ @@ -855,9 +855,9 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { "dispatcher": "{}", "arg": "{}" }},)#", - kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.longPress ? "true" : "false", - kb.nonConsuming ? "true" : "false", kb.hasDescription ? "true" : "false", kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, - kb.catchAll ? "true" : "false", escapeJSONStrings(kb.description), escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg)); + kb->locked ? "true" : "false", kb->mouse ? "true" : "false", kb->release ? "true" : "false", kb->repeat ? "true" : "false", kb->longPress ? "true" : "false", + kb->nonConsuming ? "true" : "false", kb->hasDescription ? "true" : "false", kb->modmask, escapeJSONStrings(kb->submap), escapeJSONStrings(kb->key), kb->keycode, + kb->catchAll ? "true" : "false", escapeJSONStrings(kb->description), escapeJSONStrings(kb->handler), escapeJSONStrings(kb->arg)); } trimTrailingComma(ret); ret += "]"; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index a0cd01a9..995fee17 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -150,7 +150,7 @@ CKeybindManager::CKeybindManager() { if (m_vActiveKeybinds.size() == 0 || g_pSeatManager->keyboard.expired()) return; - for (SKeybind* k : m_vActiveKeybinds) { + for (const auto& k : m_vActiveKeybinds) { const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(k->handler); Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); @@ -168,7 +168,7 @@ CKeybindManager::CKeybindManager() { static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { // clear cuz realloc'd m_vActiveKeybinds.clear(); - m_pLastLongPressKeybind = nullptr; + m_pLastLongPressKeybind.reset(); m_vPressedSpecialBinds.clear(); }); } @@ -187,24 +187,17 @@ CKeybindManager::~CKeybindManager() { } void CKeybindManager::addKeybind(SKeybind kb) { - m_lKeybinds.push_back(kb); + m_vKeybinds.emplace_back(makeShared(kb)); m_vActiveKeybinds.clear(); - m_pLastLongPressKeybind = nullptr; + m_pLastLongPressKeybind.reset(); } void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { - for (auto it = m_lKeybinds.begin(); it != m_lKeybinds.end(); ++it) { - if (it->modmask == mod && it->key == key.key && it->keycode == key.keycode && it->catchAll == key.catchAll) { - it = m_lKeybinds.erase(it); - - if (it == m_lKeybinds.end()) - break; - } - } + std::erase_if(m_vKeybinds, [&mod, &key](const auto& el) { return el->modmask == mod && el->key == key.key && el->keycode == key.keycode && el->catchAll == key.catchAll; }); m_vActiveKeybinds.clear(); - m_pLastLongPressKeybind = nullptr; + m_pLastLongPressKeybind.reset(); } uint32_t CKeybindManager::stringToModMask(std::string mods) { @@ -451,7 +444,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { m_vActiveKeybinds.clear(); - m_pLastLongPressKeybind = nullptr; + m_pLastLongPressKeybind.reset(); bool suppressEvent = false; if (e.state == WL_KEYBOARD_KEY_STATE_PRESSED) { @@ -612,11 +605,11 @@ eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set k return MK_NO_MATCH; } -eMultiKeyCase CKeybindManager::mkBindMatches(const SKeybind keybind) { - if (mkKeysymSetMatches(keybind.sMkMods, m_sMkMods) != MK_FULL_MATCH) +eMultiKeyCase CKeybindManager::mkBindMatches(const SP keybind) { + if (mkKeysymSetMatches(keybind->sMkMods, m_sMkMods) != MK_FULL_MATCH) return MK_NO_MATCH; - return mkKeysymSetMatches(keybind.sMkKeys, m_sMkKeys); + return mkKeysymSetMatches(keybind->sMkKeys, m_sMkKeys); } std::string CKeybindManager::getCurrentSubmap() { @@ -640,35 +633,35 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP m_sMkKeys.erase(key.keysym); } - for (auto& k : m_lKeybinds) { - const bool SPECIALDISPATCHER = k.handler == "global" || k.handler == "pass" || k.handler == "sendshortcut" || k.handler == "mouse"; + for (auto& k : m_vKeybinds) { + const bool SPECIALDISPATCHER = k->handler == "global" || k->handler == "pass" || k->handler == "sendshortcut" || k->handler == "mouse"; const bool SPECIALTRIGGERED = - std::find_if(m_vPressedSpecialBinds.begin(), m_vPressedSpecialBinds.end(), [&](const auto& other) { return other == &k; }) != m_vPressedSpecialBinds.end(); + std::find_if(m_vPressedSpecialBinds.begin(), m_vPressedSpecialBinds.end(), [&](const auto& other) { return other == k; }) != m_vPressedSpecialBinds.end(); const bool IGNORECONDITIONS = SPECIALDISPATCHER && !pressed && SPECIALTRIGGERED; // ignore mods. Pass, global dispatchers should be released immediately once the key is released. - if (!k.dontInhibit && !*PDISABLEINHIBIT && PROTO::shortcutsInhibit->isInhibited()) + if (!k->dontInhibit && !*PDISABLEINHIBIT && PROTO::shortcutsInhibit->isInhibited()) continue; - if (!k.locked && g_pSessionLockManager->isSessionLocked()) + if (!k->locked && g_pSessionLockManager->isSessionLocked()) continue; - if (!IGNORECONDITIONS && ((modmask != k.modmask && !k.ignoreMods) || k.submap != m_szCurrentSelectedSubmap || k.shadowed)) + if (!IGNORECONDITIONS && ((modmask != k->modmask && !k->ignoreMods) || k->submap != m_szCurrentSelectedSubmap || k->shadowed)) continue; - if (k.multiKey) { + if (k->multiKey) { switch (mkBindMatches(k)) { case MK_NO_MATCH: continue; case MK_PARTIAL_MATCH: found = true; continue; case MK_FULL_MATCH: found = true; } } else if (!key.keyName.empty()) { - if (key.keyName != k.key) + if (key.keyName != k->key) continue; - } else if (k.keycode != 0) { - if (key.keycode != k.keycode) + } else if (k->keycode != 0) { + if (key.keycode != k->keycode) continue; - } else if (k.catchAll) { + } else if (k->catchAll) { if (found || key.submapAtPress != m_szCurrentSelectedSubmap) continue; } else { @@ -679,8 +672,8 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP // oMg such performance hit!!11! // this little maneouver is gonna cost us 4µs - const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_NO_FLAGS); - const auto KBKEYLOWER = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); + const auto KBKEY = xkb_keysym_from_name(k->key.c_str(), XKB_KEYSYM_NO_FLAGS); + const auto KBKEYLOWER = xkb_keysym_from_name(k->key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); if (KBKEY == XKB_KEY_NoSymbol && KBKEYLOWER == XKB_KEY_NoSymbol) { // Keysym failed to resolve from the key name of the currently iterated bind. @@ -697,8 +690,8 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP continue; } - if (pressed && k.release && !SPECIALDISPATCHER) { - if (k.nonConsuming) + if (pressed && k->release && !SPECIALDISPATCHER) { + if (k->nonConsuming) continue; found = true; // suppress the event @@ -707,7 +700,7 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP if (!pressed) { // Require mods to be matching when the key was first pressed. - if (key.modmaskAtPressTime != modmask && !k.ignoreMods) { + if (key.modmaskAtPressTime != modmask && !k->ignoreMods) { // Handle properly `bindr` where a key is itself a bind mod for example: // "bindr = SUPER, SUPER_L, exec, $launcher". // This needs to be handled separately for the above case, because `key.modmaskAtPressTime` is set @@ -716,8 +709,8 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP if (keycodeToModifier(key.keycode) == key.modmaskAtPressTime) continue; - } else if (!k.release && !SPECIALDISPATCHER) { - if (k.nonConsuming) + } else if (!k->release && !SPECIALDISPATCHER) { + if (k->nonConsuming) continue; found = true; // suppress the event @@ -725,25 +718,25 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP } } - if (k.longPress) { + if (k->longPress) { const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); m_pLongPressTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); - m_pLastLongPressKeybind = &k; + m_pLastLongPressKeybind = k; continue; } - const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); + const auto DISPATCHER = m_mDispatchers.find(k->mouse ? "mouse" : k->handler); if (SPECIALTRIGGERED && !pressed) - std::erase_if(m_vPressedSpecialBinds, [&](const auto& other) { return other == &k; }); + std::erase_if(m_vPressedSpecialBinds, [&](const auto& other) { return other == k; }); else if (SPECIALDISPATCHER && pressed) - m_vPressedSpecialBinds.push_back(&k); + m_vPressedSpecialBinds.push_back(k); // Should never happen, as we check in the ConfigManager, but oh well if (DISPATCHER == m_mDispatchers.end()) { - Debug::log(ERR, "Invalid handler in a keybind! (handler {} does not exist)", k.handler); + Debug::log(ERR, "Invalid handler in a keybind! (handler {} does not exist)", k->handler); } else { // call the dispatcher Debug::log(LOG, "Keybind triggered, calling dispatcher ({}, {}, {})", modmask, key.keyName, key.keysym); @@ -751,27 +744,27 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP m_iPassPressed = (int)pressed; // if the dispatchers says to pass event then we will - if (k.handler == "mouse") - res = DISPATCHER->second((pressed ? "1" : "0") + k.arg); + if (k->handler == "mouse") + res = DISPATCHER->second((pressed ? "1" : "0") + k->arg); else - res = DISPATCHER->second(k.arg); + res = DISPATCHER->second(k->arg); m_iPassPressed = -1; - if (k.handler == "submap") { + if (k->handler == "submap") { found = true; // don't process keybinds on submap change. break; } } - if (k.repeat) { + if (k->repeat) { const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock(); - m_vActiveKeybinds.push_back(&k); + m_vActiveKeybinds.push_back(k); m_pRepeatKeyTimer->updateTimeout(std::chrono::milliseconds(PACTIVEKEEB->repeatDelay)); } - if (!k.nonConsuming) + if (!k->nonConsuming) found = true; } @@ -792,17 +785,17 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP void CKeybindManager::shadowKeybinds(const xkb_keysym_t& doesntHave, const uint32_t doesntHaveCode) { // shadow disables keybinds after one has been triggered - for (auto& k : m_lKeybinds) { + for (auto& k : m_vKeybinds) { bool shadow = false; - if (k.handler == "global" || k.transparent) + if (k->handler == "global" || k->transparent) continue; // can't be shadowed - if (k.multiKey && (mkBindMatches(k) == MK_FULL_MATCH)) + if (k->multiKey && (mkBindMatches(k) == MK_FULL_MATCH)) shadow = true; else { - const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); + const auto KBKEY = xkb_keysym_from_name(k->key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY); for (auto const& pk : m_dPressedKeys) { @@ -815,7 +808,7 @@ void CKeybindManager::shadowKeybinds(const xkb_keysym_t& doesntHave, const uint3 } } - if (pk.keycode != 0 && pk.keycode == k.keycode) { + if (pk.keycode != 0 && pk.keycode == k->keycode) { shadow = true; if (pk.keycode == doesntHaveCode && doesntHaveCode != 0) { @@ -826,7 +819,7 @@ void CKeybindManager::shadowKeybinds(const xkb_keysym_t& doesntHave, const uint3 } } - k.shadowed = shadow; + k->shadowed = shadow; } } @@ -1004,7 +997,7 @@ SDispatchResult CKeybindManager::kill(std::string args) { } void CKeybindManager::clearKeybinds() { - m_lKeybinds.clear(); + m_vKeybinds.clear(); } static SDispatchResult toggleActiveFloatingCore(std::string args, std::optional floatState) { @@ -2182,8 +2175,8 @@ SDispatchResult CKeybindManager::setSubmap(std::string submap) { return {}; } - for (auto const& k : g_pKeybindManager->m_lKeybinds) { - if (k.submap == submap) { + for (const auto& k : g_pKeybindManager->m_vKeybinds) { + if (k->submap == submap) { m_szCurrentSelectedSubmap = submap; Debug::log(LOG, "Changed keybind submap to {}", submap); g_pEventManager->postEvent(SHyprIPCEvent{"submap", submap}); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index d375db0f..1f60fdd2 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -104,7 +104,7 @@ class CKeybindManager { bool m_bGroupsLocked = false; - std::list m_lKeybinds; + std::vector> m_vKeybinds; //since we cant find keycode through keyname in xkb: //on sendshortcut call, we once search for keyname (e.g. "g") the correct keycode (e.g. 42) @@ -119,15 +119,15 @@ class CKeybindManager { inline static std::string m_szCurrentSelectedSubmap = ""; - std::vector m_vActiveKeybinds; - SKeybind* m_pLastLongPressKeybind = nullptr; + std::vector> m_vActiveKeybinds; + WP m_pLastLongPressKeybind; SP m_pLongPressTimer, m_pRepeatKeyTimer; uint32_t m_uTimeLastMs = 0; uint32_t m_uLastCode = 0; uint32_t m_uLastMouseCode = 0; - std::vector m_vPressedSpecialBinds; + std::vector> m_vPressedSpecialBinds; int m_iPassPressed = -1; // used for pass @@ -137,7 +137,7 @@ class CKeybindManager { std::set m_sMkKeys = {}; std::set m_sMkMods = {}; - eMultiKeyCase mkBindMatches(const SKeybind); + eMultiKeyCase mkBindMatches(const SP); eMultiKeyCase mkKeysymSetMatches(const std::set, const std::set); bool handleInternalKeybinds(xkb_keysym_t); From 47a1650c4810ad3cb3e9f125cb0addf18aa7395c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Nov 2024 23:53:38 +0000 Subject: [PATCH 0046/1566] miscfunctions: move configStringToInt to std::expected --- src/config/ConfigManager.cpp | 54 +++++++++++++++++++++------------ src/debug/HyprCtl.cpp | 4 +-- src/desktop/LayerSurface.cpp | 2 +- src/desktop/Window.cpp | 8 ++--- src/helpers/MiscFunctions.cpp | 37 ++++++++++++++-------- src/helpers/MiscFunctions.hpp | 45 +++++++++++++-------------- src/managers/KeybindManager.cpp | 15 +++++---- src/plugins/HookSystem.cpp | 13 +++++--- 8 files changed, 106 insertions(+), 72 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1c025179..fe80a5ab 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -67,7 +67,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** } try { - DATA->m_vColors.push_back(CColor(configStringToInt(var))); + DATA->m_vColors.push_back(CColor(*configStringToInt(var))); } catch (std::exception& e) { Debug::log(WARN, "Error parsing gradient {}", V); parseError = "Error parsing gradient " + V + ": " + e.what(); @@ -2615,7 +2615,14 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin const static std::string ruleOnCreatedEmpty = "on-created-empty:"; const static auto ruleOnCreatedEmptyLen = ruleOnCreatedEmpty.length(); - auto assignRule = [&](std::string rule) -> std::optional { +#define CHECK_OR_THROW(expr) \ + \ + auto X = expr; \ + if (!X) { \ + return "Failed parsing a workspace rule"; \ + } + + auto assignRule = [&](std::string rule) -> std::optional { size_t delim = std::string::npos; if ((delim = rule.find("gapsin:")) != std::string::npos) { CVarList varlist = CVarList(rule.substr(delim + 7), 0, ' '); @@ -2633,25 +2640,32 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin try { wsRule.borderSize = std::stoi(rule.substr(delim + 11)); } catch (...) { return "Error parsing workspace rule bordersize: {}", rule.substr(delim + 11); } - else if ((delim = rule.find("border:")) != std::string::npos) - wsRule.noBorder = !configStringToInt(rule.substr(delim + 7)); - else if ((delim = rule.find("shadow:")) != std::string::npos) - wsRule.noShadow = !configStringToInt(rule.substr(delim + 7)); - else if ((delim = rule.find("rounding:")) != std::string::npos) - wsRule.noRounding = !configStringToInt(rule.substr(delim + 9)); - else if ((delim = rule.find("decorate:")) != std::string::npos) - wsRule.decorate = configStringToInt(rule.substr(delim + 9)); - else if ((delim = rule.find("monitor:")) != std::string::npos) + else if ((delim = rule.find("border:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 7))) + wsRule.noBorder = !*X; + } else if ((delim = rule.find("shadow:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 7))) + wsRule.noShadow = !*X; + } else if ((delim = rule.find("rounding:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 9))) + wsRule.noRounding = !*X; + } else if ((delim = rule.find("decorate:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 9))) + wsRule.decorate = *X; + } else if ((delim = rule.find("monitor:")) != std::string::npos) wsRule.monitor = rule.substr(delim + 8); - else if ((delim = rule.find("default:")) != std::string::npos) - wsRule.isDefault = configStringToInt(rule.substr(delim + 8)); - else if ((delim = rule.find("persistent:")) != std::string::npos) - wsRule.isPersistent = configStringToInt(rule.substr(delim + 11)); - else if ((delim = rule.find("defaultName:")) != std::string::npos) + else if ((delim = rule.find("default:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 8))) + wsRule.isDefault = *X; + } else if ((delim = rule.find("persistent:")) != std::string::npos) { + CHECK_OR_THROW(configStringToInt(rule.substr(delim + 11))) + wsRule.isPersistent = *X; + } else if ((delim = rule.find("defaultName:")) != std::string::npos) wsRule.defaultName = rule.substr(delim + 12); - else if ((delim = rule.find(ruleOnCreatedEmpty)) != std::string::npos) - wsRule.onCreatedEmptyRunCmd = cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmptyLen)); - else if ((delim = rule.find("layoutopt:")) != std::string::npos) { + else if ((delim = rule.find(ruleOnCreatedEmpty)) != std::string::npos) { + CHECK_OR_THROW(cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmptyLen))) + wsRule.onCreatedEmptyRunCmd = *X; + } else if ((delim = rule.find("layoutopt:")) != std::string::npos) { std::string opt = rule.substr(delim + 10); if (!opt.contains(":")) { // invalid @@ -2668,6 +2682,8 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin return {}; }; +#undef CHECK_OR_THROW + CVarList rulesList{rules, 0, ',', true}; for (auto const& r : rulesList) { const auto R = assignRule(r); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 1b94296f..4d3c2be4 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1286,7 +1286,7 @@ std::string dispatchSeterror(eHyprCtlOutputFormat format, std::string request) { return "ok"; } - const CColor COLOR = configStringToInt(vars[1]); + const CColor COLOR = configStringToInt(vars[1]).value_or(0); for (size_t i = 2; i < vars.size(); ++i) errorMessage += vars[i] + ' '; @@ -1539,7 +1539,7 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { time = std::stoi(TIME); } catch (std::exception& e) { return "invalid arg 2"; } - CColor color = configStringToInt(vars[3]); + CColor color = configStringToInt(vars[3]).value_or(0); size_t msgidx = 4; float fontsize = 13.f; diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/LayerSurface.cpp index cd1c4742..40491123 100644 --- a/src/desktop/LayerSurface.cpp +++ b/src/desktop/LayerSurface.cpp @@ -400,7 +400,7 @@ void CLayerSurface::applyRules() { } else if (rule.rule.starts_with("xray")) { CVarList vars{rule.rule, 0, ' '}; try { - xray = configStringToInt(vars[1]); + xray = configStringToInt(vars[1]).value_or(false); } catch (...) {} } else if (rule.rule.starts_with("animation")) { CVarList vars{rule.rule, 2, 's'}; diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index e74e13a2..33e6a5f8 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -672,8 +672,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { // Basic form has only two colors, everything else can be parsed as a gradient if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) { - m_sWindowData.activeBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[0]))), priority); - m_sWindowData.inactiveBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[1]))), priority); + m_sWindowData.activeBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[0]).value_or(0))), priority); + m_sWindowData.inactiveBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[1]).value_or(0))), priority); return; } @@ -685,9 +685,9 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { } else if (token.contains("deg")) inactiveBorderGradient.m_fAngle = std::stoi(token.substr(0, token.size() - 3)) * (PI / 180.0); else if (active) - activeBorderGradient.m_vColors.push_back(configStringToInt(token)); + activeBorderGradient.m_vColors.push_back(configStringToInt(token).value_or(0)); else - inactiveBorderGradient.m_vColors.push_back(configStringToInt(token)); + inactiveBorderGradient.m_vColors.push_back(configStringToInt(token).value_or(0)); } // Includes sanity checks for the number of colors in each gradient diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 80681826..fa2f84ab 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -691,15 +691,15 @@ int64_t getPPIDof(int64_t pid) { #endif } -int64_t configStringToInt(const std::string& VALUE) { - auto parseHex = [](const std::string& value) -> int64_t { +std::expected configStringToInt(const std::string& VALUE) { + auto parseHex = [](const std::string& value) -> std::expected { try { size_t position; auto result = stoll(value, &position, 16); if (position == value.size()) return result; } catch (const std::exception&) {} - throw std::invalid_argument("invalid hex " + value); + return std::unexpected("invalid hex " + value); }; if (VALUE.starts_with("0x")) { // Values with 0x are hex @@ -718,18 +718,25 @@ int64_t configStringToInt(const std::string& VALUE) { auto b = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); rolling = rolling.substr(rolling.find(',') + 1); uint8_t a = 0; + + if (!r || !g || !b) + return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); + try { a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f); - } catch (std::exception& e) { throw std::invalid_argument("failed parsing " + VALUEWITHOUTFUNC); } + } catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); } - return a * (Hyprlang::INT)0x1000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b; + return a * (Hyprlang::INT)0x1000000 + *r * (Hyprlang::INT)0x10000 + *g * (Hyprlang::INT)0x100 + *b; } else if (VALUEWITHOUTFUNC.length() == 8) { const auto RGBA = parseHex(VALUEWITHOUTFUNC); + + if (!RGBA) + return RGBA; // now we need to RGBA -> ARGB. The config holds ARGB only. - return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF); + return (*RGBA >> 8) + 0x1000000 * (*RGBA & 0xFF); } - throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values"); + return std::unexpected("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values"); } else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) { const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5)); @@ -744,12 +751,16 @@ int64_t configStringToInt(const std::string& VALUE) { rolling = rolling.substr(rolling.find(',') + 1); auto b = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); - return (Hyprlang::INT)0xFF000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b; + if (!r || !g || !b) + return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); + + return (Hyprlang::INT)0xFF000000 + *r * (Hyprlang::INT)0x10000 + *g * (Hyprlang::INT)0x100 + *b; } else if (VALUEWITHOUTFUNC.length() == 6) { - return parseHex(VALUEWITHOUTFUNC) + 0xFF000000; + auto r = parseHex(VALUEWITHOUTFUNC); + return r ? *r + 0xFF000000 : r; } - throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values"); + return std::unexpected("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values"); } else if (VALUE.starts_with("true") || VALUE.starts_with("on") || VALUE.starts_with("yes")) { return 1; } else if (VALUE.starts_with("false") || VALUE.starts_with("off") || VALUE.starts_with("no")) { @@ -757,14 +768,14 @@ int64_t configStringToInt(const std::string& VALUE) { } if (VALUE.empty() || !isNumber(VALUE, false)) - throw std::invalid_argument("cannot parse \"" + VALUE + "\" as an int."); + return std::unexpected("cannot parse \"" + VALUE + "\" as an int."); try { const auto RES = std::stoll(VALUE); return RES; - } catch (std::exception& e) { throw std::invalid_argument(std::string{"stoll threw: "} + e.what()); } + } catch (std::exception& e) { return std::unexpected(std::string{"stoll threw: "} + e.what()); } - return 0; + return std::unexpected("parse error"); } Vector2D configStringToVector2D(const std::string& VALUE) { diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index 34b23746..bb686df4 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -6,6 +6,7 @@ #include "math/Math.hpp" #include #include +#include #include "../SharedDefs.hpp" #include "../macros.hpp" @@ -19,28 +20,28 @@ struct SWorkspaceIDName { std::string name; }; -std::string absolutePath(const std::string&, const std::string&); -void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString); -void removeWLSignal(wl_listener*); -std::string escapeJSONStrings(const std::string& str); -bool isDirection(const std::string&); -bool isDirection(const char&); -SWorkspaceIDName getWorkspaceIDNameFromString(const std::string&); -std::optional cleanCmdForWorkspace(const std::string&, std::string); -float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2); -void logSystemInfo(); -std::string execAndGet(const char*); -int64_t getPPIDof(int64_t pid); -int64_t configStringToInt(const std::string&); -Vector2D configStringToVector2D(const std::string&); -std::optional getPlusMinusKeywordResult(std::string in, float relative); -double normalizeAngleRad(double ang); -std::vector getBacktrace(); -void throwError(const std::string& err); -bool envEnabled(const std::string& env); -int allocateSHMFile(size_t len); -bool allocateSHMFilePair(size_t size, int* rw_fd_ptr, int* ro_fd_ptr); -float stringToPercentage(const std::string& VALUE, const float REL); +std::string absolutePath(const std::string&, const std::string&); +void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString); +void removeWLSignal(wl_listener*); +std::string escapeJSONStrings(const std::string& str); +bool isDirection(const std::string&); +bool isDirection(const char&); +SWorkspaceIDName getWorkspaceIDNameFromString(const std::string&); +std::optional cleanCmdForWorkspace(const std::string&, std::string); +float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2); +void logSystemInfo(); +std::string execAndGet(const char*); +int64_t getPPIDof(int64_t pid); +std::expected configStringToInt(const std::string&); +Vector2D configStringToVector2D(const std::string&); +std::optional getPlusMinusKeywordResult(std::string in, float relative); +double normalizeAngleRad(double ang); +std::vector getBacktrace(); +void throwError(const std::string& err); +bool envEnabled(const std::string& env); +int allocateSHMFile(size_t len); +bool allocateSHMFilePair(size_t size, int* rw_fd_ptr, int* ro_fd_ptr); +float stringToPercentage(const std::string& VALUE, const float REL); template [[deprecated("use std::format instead")]] std::string getFormat(std::format_string fmt, Args&&... args) { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 995fee17..c9ca90e5 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2972,11 +2972,14 @@ SDispatchResult CKeybindManager::setProp(std::string args) { const auto TOKEN = vars[i]; if (TOKEN.ends_with("deg")) colorData.m_fAngle = std::stoi(TOKEN.substr(0, TOKEN.size() - 3)) * (PI / 180.0); - else - colorData.m_vColors.push_back(configStringToInt(TOKEN)); + else if (const auto V = configStringToInt(TOKEN); V) + colorData.m_vColors.push_back(*V); } - } else if (VAL != "-1") - colorData.m_vColors.push_back(configStringToInt(VAL)); + } else if (VAL != "-1") { + const auto V = configStringToInt(VAL); + if (V) + colorData.m_vColors.push_back(*V); + } if (PROP == "activebordercolor") PWINDOW->m_sWindowData.activeBorderColor = CWindowOverridableVar(colorData, PRIORITY_SET_PROP); @@ -2993,8 +2996,8 @@ SDispatchResult CKeybindManager::setProp(std::string args) { } else if (auto search = g_pConfigManager->miWindowProperties.find(PROP); search != g_pConfigManager->miWindowProperties.end()) { if (VAL == "unset") search->second(PWINDOW)->unset(PRIORITY_SET_PROP); - else - *(search->second(PWINDOW)) = CWindowOverridableVar((int)configStringToInt(VAL), PRIORITY_SET_PROP); + else if (const auto V = configStringToInt(VAL); V) + *(search->second(PWINDOW)) = CWindowOverridableVar((int)*V, PRIORITY_SET_PROP); } else { return {.success = false, .error = "Prop not found"}; } diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp index 745b2593..69ca81cb 100644 --- a/src/plugins/HookSystem.cpp +++ b/src/plugins/HookSystem.cpp @@ -90,11 +90,14 @@ CFunctionHook::SAssembly CFunctionHook::fixInstructionProbeRIPCalls(const SInstr std::string code = probe.assembly.substr(lastAsmNewline, probe.assembly.find("\n", lastAsmNewline) - lastAsmNewline); if (code.contains("%rip")) { - CVarList tokens{code, 0, 's'}; - size_t plusPresent = tokens[1][0] == '+' ? 1 : 0; - size_t minusPresent = tokens[1][0] == '-' ? 1 : 0; - std::string addr = tokens[1].substr((plusPresent || minusPresent), tokens[1].find("(%rip)") - (plusPresent || minusPresent)); - const int32_t OFFSET = (minusPresent ? -1 : 1) * configStringToInt(addr); + CVarList tokens{code, 0, 's'}; + size_t plusPresent = tokens[1][0] == '+' ? 1 : 0; + size_t minusPresent = tokens[1][0] == '-' ? 1 : 0; + std::string addr = tokens[1].substr((plusPresent || minusPresent), tokens[1].find("(%rip)") - (plusPresent || minusPresent)); + auto addrResult = configStringToInt(addr); + if (!addrResult) + return {}; + const int32_t OFFSET = (minusPresent ? -1 : 1) * *addrResult; if (OFFSET == 0) return {}; const uint64_t DESTINATION = currentAddress + OFFSET + len; From 67cee430061626ccd73dc6d30eed9db289053608 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Nov 2024 01:16:11 +0000 Subject: [PATCH 0047/1566] internal: minor cleanups for color results --- src/debug/HyprCtl.cpp | 8 +++++--- src/managers/KeybindManager.cpp | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 4d3c2be4..7c0a9417 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1529,9 +1529,8 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { icon = std::stoi(ICON); } catch (std::exception& e) { return "invalid arg 1"; } - if (icon > ICON_NONE || icon < 0) { + if (icon > ICON_NONE || icon < 0) icon = ICON_NONE; - } const auto TIME = vars[2]; int time = 0; @@ -1539,7 +1538,10 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { time = std::stoi(TIME); } catch (std::exception& e) { return "invalid arg 2"; } - CColor color = configStringToInt(vars[3]).value_or(0); + const auto COLOR_RESULT = configStringToInt(vars[3]); + if (!COLOR_RESULT) + return "invalid arg 3"; + CColor color = *COLOR_RESULT; size_t msgidx = 4; float fontsize = 13.f; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index c9ca90e5..75e2a7b3 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2920,6 +2920,9 @@ SDispatchResult CKeybindManager::event(std::string args) { return {}; } +#include +#include + SDispatchResult CKeybindManager::setProp(std::string args) { CVarList vars(args, 3, ' '); @@ -2972,14 +2975,17 @@ SDispatchResult CKeybindManager::setProp(std::string args) { const auto TOKEN = vars[i]; if (TOKEN.ends_with("deg")) colorData.m_fAngle = std::stoi(TOKEN.substr(0, TOKEN.size() - 3)) * (PI / 180.0); - else if (const auto V = configStringToInt(TOKEN); V) - colorData.m_vColors.push_back(*V); + else + configStringToInt(TOKEN).and_then([&colorData](const auto& e) { + colorData.m_vColors.push_back(e); + return std::result_of::type(1); + }); } - } else if (VAL != "-1") { - const auto V = configStringToInt(VAL); - if (V) - colorData.m_vColors.push_back(*V); - } + } else if (VAL != "-1") + configStringToInt(VAL).and_then([&colorData](const auto& e) { + colorData.m_vColors.push_back(e); + return std::result_of::type(1); + }); if (PROP == "activebordercolor") PWINDOW->m_sWindowData.activeBorderColor = CWindowOverridableVar(colorData, PRIORITY_SET_PROP); @@ -2998,9 +3004,8 @@ SDispatchResult CKeybindManager::setProp(std::string args) { search->second(PWINDOW)->unset(PRIORITY_SET_PROP); else if (const auto V = configStringToInt(VAL); V) *(search->second(PWINDOW)) = CWindowOverridableVar((int)*V, PRIORITY_SET_PROP); - } else { + } else return {.success = false, .error = "Prop not found"}; - } } catch (std::exception& e) { return {.success = false, .error = std::format("Error parsing prop value: {}", std::string(e.what()))}; } g_pCompositor->updateAllWindowsAnimatedDecorationValues(); From aa067a4cf12522ede1752dd2048ce67d07e903f1 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Nov 2024 21:40:16 +0000 Subject: [PATCH 0048/1566] xdg-shell: don't report invalid min/max sizes on unset fixes #8522 --- src/protocols/XDGShell.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 932882e9..f121070d 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -324,10 +324,14 @@ void CXDGToplevelResource::close() { } Vector2D CXDGToplevelResource::layoutMinSize() { + if (current.minSize.x <= 1 && current.minSize.y <= 1) + return {0, 0}; return owner ? current.minSize + owner->current.geometry.pos() : current.minSize; } Vector2D CXDGToplevelResource::layoutMaxSize() { + if (current.maxSize.x <= 1 && current.maxSize.y <= 1) + return {0, 0}; return owner ? current.maxSize + owner->current.geometry.pos() : current.maxSize; } From c4eda46d0ef022a17348623beec4154ba34af691 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Nov 2024 22:07:25 +0000 Subject: [PATCH 0049/1566] xdg-shell: even more robust layout min/max size although I don't think any apps use this, but better safe than sorry --- src/protocols/XDGShell.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index f121070d..688d0006 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -324,15 +324,21 @@ void CXDGToplevelResource::close() { } Vector2D CXDGToplevelResource::layoutMinSize() { - if (current.minSize.x <= 1 && current.minSize.y <= 1) - return {0, 0}; - return owner ? current.minSize + owner->current.geometry.pos() : current.minSize; + Vector2D minSize; + if (current.minSize.x > 1) + minSize.x = owner ? current.minSize.x + owner->current.geometry.pos().x : current.minSize.x; + if (current.minSize.y > 1) + minSize.y = owner ? current.minSize.y + owner->current.geometry.pos().y : current.minSize.y; + return minSize; } Vector2D CXDGToplevelResource::layoutMaxSize() { - if (current.maxSize.x <= 1 && current.maxSize.y <= 1) - return {0, 0}; - return owner ? current.maxSize + owner->current.geometry.pos() : current.maxSize; + Vector2D maxSize; + if (current.maxSize.x > 1) + maxSize.x = owner ? current.maxSize.x + owner->current.geometry.pos().x : current.maxSize.x; + if (current.maxSize.y > 1) + maxSize.y = owner ? current.maxSize.y + owner->current.geometry.pos().y : current.maxSize.y; + return maxSize; } CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SP owner_, SP surface_) : From e5fa017172156fa5c70fedeaee5f51eace9577c0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 20 Nov 2024 10:32:50 +0000 Subject: [PATCH 0050/1566] internal: fix some misused configStringToInt conversions fixes #8523 --- src/config/ConfigManager.cpp | 4 ++-- src/desktop/Window.cpp | 2 +- src/desktop/Workspace.cpp | 4 ++-- src/managers/KeybindManager.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index fe80a5ab..357e7a60 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2101,13 +2101,13 @@ std::optional CConfigManager::handleAnimation(const std::string& co PANIM->second.pValues = &PANIM->second; // This helper casts strings like "1", "true", "off", "yes"... to int. - int64_t enabledInt = configStringToInt(ARGS[1]) == 1; + int64_t enabledInt = configStringToInt(ARGS[1]).value_or(0) == 1; // Checking that the int is 1 or 0 because the helper can return integers out of range. if (enabledInt != 0 && enabledInt != 1) return "invalid animation on/off state"; - PANIM->second.internalEnabled = configStringToInt(ARGS[1]) == 1; + PANIM->second.internalEnabled = configStringToInt(ARGS[1]).value_or(0) == 1; if (PANIM->second.internalEnabled) { // speed diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 33e6a5f8..117d301c 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -707,7 +707,7 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { *(search->second(m_pSelf.lock())) = CWindowOverridableVar(true, priority); } else { try { - *(search->second(m_pSelf.lock())) = CWindowOverridableVar((bool)configStringToInt(VARS[1]), priority); + *(search->second(m_pSelf.lock())) = CWindowOverridableVar((bool)configStringToInt(VARS[1]).value_or(0), priority); } catch (...) {} } } else if (auto search = g_pConfigManager->miWindowProperties.find(VARS[0]); search != g_pConfigManager->miWindowProperties.end()) { diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 2e1e91f2..8cddbb6b 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -332,7 +332,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { const auto SHOULDBESPECIAL = configStringToInt(prop); - if ((bool)SHOULDBESPECIAL != m_bIsSpecialWorkspace) + if (SHOULDBESPECIAL && (bool)*SHOULDBESPECIAL != m_bIsSpecialWorkspace) return false; continue; } @@ -367,7 +367,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { const auto WANTSNAMED = configStringToInt(prop); - if (WANTSNAMED != (m_iID <= -1337)) + if (WANTSNAMED && *WANTSNAMED != (m_iID <= -1337)) return false; continue; } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 75e2a7b3..be1e9534 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2961,13 +2961,13 @@ SDispatchResult CKeybindManager::setProp(std::string args) { CWindowOverridableVar(SAlphaValue{std::stof(VAL), PWINDOW->m_sWindowData.alphaFullscreen.valueOrDefault().m_bOverride}, PRIORITY_SET_PROP); } else if (PROP == "alphaoverride") { PWINDOW->m_sWindowData.alpha = - CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alpha.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL)}, PRIORITY_SET_PROP); + CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alpha.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL).value_or(0)}, PRIORITY_SET_PROP); } else if (PROP == "alphainactiveoverride") { PWINDOW->m_sWindowData.alphaInactive = - CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alphaInactive.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL)}, PRIORITY_SET_PROP); + CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alphaInactive.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL).value_or(0)}, PRIORITY_SET_PROP); } else if (PROP == "alphafullscreenoverride") { PWINDOW->m_sWindowData.alphaFullscreen = - CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alphaFullscreen.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL)}, PRIORITY_SET_PROP); + CWindowOverridableVar(SAlphaValue{PWINDOW->m_sWindowData.alphaFullscreen.valueOrDefault().m_fAlpha, (bool)configStringToInt(VAL).value_or(0)}, PRIORITY_SET_PROP); } else if (PROP == "activebordercolor" || PROP == "inactivebordercolor") { CGradientValueData colorData = {}; if (vars.size() > 4) { @@ -2998,7 +2998,7 @@ SDispatchResult CKeybindManager::setProp(std::string args) { else if (VAL == "unset") pWindowDataElement->unset(PRIORITY_SET_PROP); else - *pWindowDataElement = CWindowOverridableVar((bool)configStringToInt(VAL), PRIORITY_SET_PROP); + *pWindowDataElement = CWindowOverridableVar((bool)configStringToInt(VAL).value_or(0), PRIORITY_SET_PROP); } else if (auto search = g_pConfigManager->miWindowProperties.find(PROP); search != g_pConfigManager->miWindowProperties.end()) { if (VAL == "unset") search->second(PWINDOW)->unset(PRIORITY_SET_PROP); From 940f7aa990dbc99815bab8d355999d8277534b17 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 20 Nov 2024 11:02:21 +0000 Subject: [PATCH 0051/1566] renderer: fixup blur optimization considitons fixes #8531 --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index fc17ef9f..42545bc1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -174,7 +174,6 @@ static void renderSurface(SP surface, int x, int y, void* da } const auto RDATA = (SRenderData*)data; - const bool BLUR = RDATA->blur && !TEXTURE->m_bOpaque; const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow && g_pInputManager->dragMode == MBIND_RESIZE; TRACY_GPU_ZONE("RenderSurface"); @@ -183,6 +182,7 @@ static void renderSurface(SP surface, int x, int y, void* da auto PSURFACE = CWLSurface::fromResource(surface); const float ALPHA = RDATA->alpha * RDATA->fadeAlpha * (PSURFACE ? PSURFACE->m_pAlphaModifier : 1.F); + const bool BLUR = RDATA->blur && (!TEXTURE->m_bOpaque || ALPHA < 1.F); CBox windowBox; if (RDATA->surface && surface == RDATA->surface) { From 943b3d467b0a77a6b67df01e78f5e4977486824f Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 22 Nov 2024 02:47:51 +0100 Subject: [PATCH 0052/1566] bezier: optimize setup of bezier curves (#8528) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit avoid reallocations by resizing and copy the pVec into the resized m_dPoints, reduce the amount of calculations in baking to only do it once per iteration instead of twice. precompute in getYforT and getXforT return early in getYForPoint if x is equal or below 0. and use const references where we can. these changes we are now down to an average of "time to bake: 2.50µs." on my machine compared to before average of "time to bake: 11.15µs" --- src/helpers/BezierCurve.cpp | 39 ++++++++++++++++++++++++------------- src/helpers/BezierCurve.hpp | 8 ++++---- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/helpers/BezierCurve.cpp b/src/helpers/BezierCurve.cpp index ea567ad6..23fcd691 100644 --- a/src/helpers/BezierCurve.cpp +++ b/src/helpers/BezierCurve.cpp @@ -6,24 +6,27 @@ #include void CBezierCurve::setup(std::vector* pVec) { - m_dPoints.clear(); - const auto BEGIN = std::chrono::high_resolution_clock::now(); - m_dPoints.emplace_back(Vector2D(0, 0)); - - for (auto const& p : *pVec) { - m_dPoints.push_back(p); + // Avoid reallocations by reserving enough memory upfront + m_dPoints.resize(pVec->size() + 2); + m_dPoints[0] = Vector2D(0, 0); // Start point + size_t index = 1; // Start after the first element + for (const auto& vec : *pVec) { + if (index < m_dPoints.size() - 1) { // Bounds check to ensure safety + m_dPoints[index] = vec; + ++index; + } } - - m_dPoints.emplace_back(Vector2D(1, 1)); + m_dPoints.back() = Vector2D(1, 1); // End point RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: {})", m_dPoints.size()); // bake BAKEDPOINTS points for faster lookups // T -> X ( / BAKEDPOINTS ) for (int i = 0; i < BAKEDPOINTS; ++i) { - m_aPointsBaked[i] = Vector2D(getXForT((i + 1) / (float)BAKEDPOINTS), getYForT((i + 1) / (float)BAKEDPOINTS)); + float const t = (i + 1) / (float)BAKEDPOINTS; + m_aPointsBaked[i] = Vector2D(getXForT(t), getYForT(t)); } const auto ELAPSEDUS = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - BEGIN).count() / 1000.f; @@ -40,18 +43,26 @@ void CBezierCurve::setup(std::vector* pVec) { ELAPSEDUS, ELAPSEDCALCAVG); } -float CBezierCurve::getYForT(float t) { - return 3 * t * pow(1 - t, 2) * m_dPoints[1].y + 3 * pow(t, 2) * (1 - t) * m_dPoints[2].y + pow(t, 3); +float CBezierCurve::getXForT(float const& t) { + float t2 = t * t; + float t3 = t2 * t; + + return 3 * t * (1 - t) * (1 - t) * m_dPoints[1].x + 3 * t2 * (1 - t) * m_dPoints[2].x + t3 * m_dPoints[3].x; } -float CBezierCurve::getXForT(float t) { - return 3 * t * pow(1 - t, 2) * m_dPoints[1].x + 3 * pow(t, 2) * (1 - t) * m_dPoints[2].x + pow(t, 3); +float CBezierCurve::getYForT(float const& t) { + float t2 = t * t; + float t3 = t2 * t; + + return 3 * t * (1 - t) * (1 - t) * m_dPoints[1].y + 3 * t2 * (1 - t) * m_dPoints[2].y + t3 * m_dPoints[3].y; } // Todo: this probably can be done better and faster -float CBezierCurve::getYForPoint(float x) { +float CBezierCurve::getYForPoint(float const& x) { if (x >= 1.f) return 1.f; + if (x <= 0.f) + return 0.f; int index = 0; bool below = true; diff --git a/src/helpers/BezierCurve.hpp b/src/helpers/BezierCurve.hpp index 54af46a6..1a842f5a 100644 --- a/src/helpers/BezierCurve.hpp +++ b/src/helpers/BezierCurve.hpp @@ -16,13 +16,13 @@ class CBezierCurve { // this EXCLUDES the 0,0 and 1,1 points, void setup(std::vector* points); - float getYForT(float t); - float getXForT(float t); - float getYForPoint(float x); + float getYForT(float const& t); + float getXForT(float const& t); + float getYForPoint(float const& x); private: // this INCLUDES the 0,0 and 1,1 points. - std::deque m_dPoints; + std::vector m_dPoints; std::array m_aPointsBaked; }; From b1003445953474b967464d4d0878955d37498647 Mon Sep 17 00:00:00 2001 From: may <63159454+m4rch3n1ng@users.noreply.github.com> Date: Fri, 22 Nov 2024 03:31:42 +0100 Subject: [PATCH 0053/1566] keybinds: actually suppress internal keybinds instead of passing them along (#8538) --- src/managers/KeybindManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index be1e9534..8cf39c1b 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -423,8 +423,10 @@ bool CKeybindManager::onKeyEvent(std::any event, SP pKeyboard) { const xkb_keysym_t keysym = xkb_state_key_get_one_sym(pKeyboard->resolveBindsBySym ? pKeyboard->xkbSymState : m_pXKBTranslationState, KEYCODE); const xkb_keysym_t internalKeysym = xkb_state_key_get_one_sym(pKeyboard->xkbState, KEYCODE); + // handleInternalKeybinds returns true when the key should be suppressed, + // while this function returns true when the key event should be sent if (handleInternalKeybinds(internalKeysym)) - return true; + return false; const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); From a847bc67b1efcf3a0fa9c8a3a1da1a79743940c1 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Nov 2024 15:22:28 +0000 Subject: [PATCH 0054/1566] monitor: fix default focus when switching to a fs workspace --- src/helpers/Monitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 9ac48220..63268c8a 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -629,7 +629,7 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo if (!noFocus && !g_pCompositor->m_pLastMonitor->activeSpecialWorkspace && !(g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bPinned && g_pCompositor->m_pLastWindow->m_pMonitor == self)) { static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); - auto pWindow = pWorkspace->getLastFocusedWindow(); + auto pWindow = pWorkspace->m_bHasFullscreenWindow ? g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID) : pWorkspace->getLastFocusedWindow(); if (!pWindow) { if (*PFOLLOWMOUSE == 1) From 745a82ce8ab19d958e344f5925bb1dc8ea7d6a53 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Nov 2024 16:01:02 +0000 Subject: [PATCH 0055/1566] core: workspace-related function cleanup / refactor CCompositor is massive, and has a lot of functions that could be better optimized if in CWorkspace --- src/Compositor.cpp | 182 ++++----------------------- src/Compositor.hpp | 13 -- src/config/ConfigManager.cpp | 4 +- src/debug/HyprCtl.cpp | 10 +- src/desktop/Window.cpp | 38 +++--- src/desktop/Workspace.cpp | 149 ++++++++++++++++++++-- src/desktop/Workspace.hpp | 20 +-- src/events/Windows.cpp | 12 +- src/helpers/MiscFunctions.cpp | 2 +- src/helpers/Monitor.cpp | 6 +- src/layout/DwindleLayout.cpp | 6 +- src/layout/IHyprLayout.cpp | 10 +- src/layout/MasterLayout.cpp | 2 +- src/managers/AnimationManager.cpp | 2 +- src/managers/KeybindManager.cpp | 30 +++-- src/managers/input/IdleInhibitor.cpp | 2 +- src/managers/input/InputManager.cpp | 8 +- src/managers/input/Swipe.cpp | 13 +- src/render/Renderer.cpp | 18 +-- 19 files changed, 267 insertions(+), 260 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 0e0c75a1..3fe5acec 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -833,6 +833,9 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper if (special && !w->onSpecialWorkspace()) // because special floating may creep up into regular continue; + if (!w->m_pWorkspace) + continue; + const auto PWINDOWMONITOR = w->m_pMonitor.lock(); // to avoid focusing windows behind special workspaces from other monitors @@ -844,7 +847,7 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper continue; } - if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_pWorkspace) && !w->isHidden() && !w->m_bPinned && !w->m_sWindowData.noFocus.valueOrDefault() && + if (w->m_bIsFloating && w->m_bIsMapped && w->m_pWorkspace->isVisible() && !w->isHidden() && !w->m_bPinned && !w->m_sWindowData.noFocus.valueOrDefault() && w != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) { // OR windows should add focus to parent if (w->m_bX11ShouldntFocus && !w->isX11OverrideRedirect()) @@ -887,7 +890,7 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper const auto PWORKSPACE = getWorkspaceByID(WSPID); if (PWORKSPACE->m_bHasFullscreenWindow) - return getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + return PWORKSPACE->getFullscreenWindow(); auto found = floating(false); if (found) @@ -898,6 +901,9 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper if (special != w->onSpecialWorkspace()) continue; + if (!w->m_pWorkspace) + continue; + if (!w->m_bIsX11 && !w->m_bIsFloating && w->m_bIsMapped && w->workspaceID() == WSPID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_sWindowData.noFocus.valueOrDefault() && w != pIgnoreWindow) { if (w->hasPopupAt(pos)) @@ -909,6 +915,9 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper if (special != w->onSpecialWorkspace()) continue; + if (!w->m_pWorkspace) + continue; + if (!w->m_bIsFloating && w->m_bIsMapped && w->workspaceID() == WSPID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_sWindowData.noFocus.valueOrDefault() && w != pIgnoreWindow) { CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_vPosition, w->m_vSize}; @@ -1070,7 +1079,7 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP pSurface const auto PMONITOR = pWindow->m_pMonitor.lock(); - if (!isWorkspaceVisible(pWindow->m_pWorkspace)) { + if (!pWindow->m_pWorkspace || !pWindow->m_pWorkspace->isVisible()) { const auto PWORKSPACE = pWindow->m_pWorkspace; // This is to fix incorrect feedback on the focus history. PWORKSPACE->m_pLastFocusedWindow = pWindow; @@ -1247,30 +1256,6 @@ PHLWINDOW CCompositor::getWindowFromHandle(uint32_t handle) { return nullptr; } -PHLWINDOW CCompositor::getFullscreenWindowOnWorkspace(const WORKSPACEID& ID) { - for (auto const& w : m_vWindows) { - if (w->workspaceID() == ID && w->isFullscreen()) - return w; - } - - return nullptr; -} - -bool CCompositor::isWorkspaceVisible(PHLWORKSPACE w) { - return valid(w) && w->m_bVisible; -} - -bool CCompositor::isWorkspaceVisibleNotCovered(PHLWORKSPACE w) { - if (!valid(w)) - return false; - - const auto PMONITOR = w->m_pMonitor.lock(); - if (PMONITOR->activeSpecialWorkspace) - return PMONITOR->activeSpecialWorkspace->m_iID == w->m_iID; - - return PMONITOR->activeWorkspace->m_iID == w->m_iID; -} - PHLWORKSPACE CCompositor::getWorkspaceByID(const WORKSPACEID& id) { for (auto const& w : m_vWorkspaces) { if (w->m_iID == id && !w->inert()) @@ -1295,37 +1280,6 @@ void CCompositor::sanityCheckWorkspaces() { } } -int CCompositor::getWindowsOnWorkspace(const WORKSPACEID& id, std::optional onlyTiled, std::optional onlyVisible) { - int no = 0; - for (auto const& w : m_vWindows) { - if (w->workspaceID() != id || !w->m_bIsMapped) - continue; - if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) - continue; - if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) - continue; - no++; - } - - return no; -} - -int CCompositor::getGroupsOnWorkspace(const WORKSPACEID& id, std::optional onlyTiled, std::optional onlyVisible) { - int no = 0; - for (auto const& w : m_vWindows) { - if (w->workspaceID() != id || !w->m_bIsMapped) - continue; - if (!w->m_sGroupData.head) - continue; - if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) - continue; - if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) - continue; - no++; - } - return no; -} - PHLWINDOW CCompositor::getUrgentWindow() { for (auto const& w : m_vWindows) { if (w->m_bIsMapped && w->m_bIsUrgent) @@ -1335,44 +1289,6 @@ PHLWINDOW CCompositor::getUrgentWindow() { return nullptr; } -bool CCompositor::hasUrgentWindowOnWorkspace(const WORKSPACEID& id) { - for (auto const& w : m_vWindows) { - if (w->workspaceID() == id && w->m_bIsMapped && w->m_bIsUrgent) - return true; - } - - return false; -} - -PHLWINDOW CCompositor::getFirstWindowOnWorkspace(const WORKSPACEID& id) { - for (auto const& w : m_vWindows) { - if (w->workspaceID() == id && w->m_bIsMapped && !w->isHidden()) - return w; - } - - return nullptr; -} - -PHLWINDOW CCompositor::getTopLeftWindowOnWorkspace(const WORKSPACEID& id) { - const auto PWORKSPACE = getWorkspaceByID(id); - - if (!PWORKSPACE) - return nullptr; - - const auto PMONITOR = PWORKSPACE->m_pMonitor.lock(); - - for (auto const& w : m_vWindows) { - if (w->workspaceID() != id || !w->m_bIsMapped || w->isHidden()) - continue; - - const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); - - if (WINDOWIDEALBB.x <= PMONITOR->vecPosition.x + 1 && WINDOWIDEALBB.y <= PMONITOR->vecPosition.y + 1) - return w; - } - return nullptr; -} - bool CCompositor::isWindowActive(PHLWINDOW pWindow) { if (m_pLastWindow.expired() && !m_pLastFocus) return false; @@ -1560,7 +1476,7 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { // for tiled windows, we calc edges for (auto const& w : m_vWindows) { - if (w == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->isFullscreen() && w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace)) + if (w == pWindow || !w->m_pWorkspace || !w->m_bIsMapped || w->isHidden() || (!w->isFullscreen() && w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) continue; if (pWindow->m_pMonitor == w->m_pMonitor && pWindow->m_pWorkspace != w->m_pWorkspace) @@ -1652,7 +1568,7 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { constexpr float THRESHOLD = 0.3 * M_PI; for (auto const& w : m_vWindows) { - if (w == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->isFullscreen() && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace)) + if (w == pWindow || !w->m_bIsMapped || !w->m_pWorkspace || w->isHidden() || (!w->isFullscreen() && !w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) continue; if (pWindow->m_pMonitor == w->m_pMonitor && pWindow->m_pWorkspace != w->m_pWorkspace) @@ -1678,7 +1594,7 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { } if (!leaderWindow && PWORKSPACE->m_bHasFullscreenWindow) - leaderWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + leaderWindow = PWORKSPACE->getFullscreenWindow(); } if (leaderValue != -1) @@ -1871,15 +1787,6 @@ void CCompositor::updateAllWindowsAnimatedDecorationValues() { } } -void CCompositor::updateWorkspaceWindows(const int64_t& id) { - for (auto const& w : m_vWindows) { - if (!w->m_bIsMapped || w->workspaceID() != id) - continue; - - w->updateDynamicRules(); - } -} - void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) { // optimization static auto PACTIVECOL = CConfigValue("general:col.active_border"); @@ -2391,7 +2298,7 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, sFullscreenS g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal(), true); - forceReportSizesToWindowsOnWorkspace(PWINDOW->workspaceID()); + PWORKSPACE->forceReportSizesToWindows(); g_pInputManager->recheckIdleInhibitorStatus(); @@ -2422,27 +2329,6 @@ PHLWINDOW CCompositor::getX11Parent(PHLWINDOW pWindow) { return nullptr; } -void CCompositor::updateWorkspaceWindowDecos(const WORKSPACEID& id) { - for (auto const& w : m_vWindows) { - if (w->workspaceID() != id) - continue; - - w->updateWindowDecos(); - } -} - -void CCompositor::updateWorkspaceWindowData(const WORKSPACEID& id) { - const auto PWORKSPACE = getWorkspaceByID(id); - const auto WORKSPACERULE = PWORKSPACE ? g_pConfigManager->getWorkspaceRuleFor(PWORKSPACE) : SWorkspaceRule{}; - - for (auto const& w : m_vWindows) { - if (w->workspaceID() != id) - continue; - - w->updateWindowData(WORKSPACERULE); - } -} - void CCompositor::scheduleFrameForMonitor(PHLMONITOR pMonitor, IOutput::scheduleFrameReason reason) { if ((m_pAqBackend->hasSession() && !m_pAqBackend->session->active) || !m_bSessionActive) return; @@ -2654,14 +2540,6 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con return Vector2D(X, Y); } -void CCompositor::forceReportSizesToWindowsOnWorkspace(const WORKSPACEID& wid) { - for (auto const& w : m_vWindows) { - if (w->workspaceID() == wid && w->m_bIsMapped && !w->isHidden()) { - g_pXWaylandManager->setWindowSize(w, w->m_vRealSize.value(), true); - } - } -} - PHLWORKSPACE CCompositor::createNewWorkspace(const WORKSPACEID& id, const MONITORID& monid, const std::string& name, bool isEmpty) { const auto NAME = name == "" ? std::to_string(id) : name; auto monID = monid; @@ -2679,21 +2557,6 @@ PHLWORKSPACE CCompositor::createNewWorkspace(const WORKSPACEID& id, const MONITO return PWORKSPACE; } -void CCompositor::renameWorkspace(const WORKSPACEID& id, const std::string& name) { - const auto PWORKSPACE = getWorkspaceByID(id); - - if (!PWORKSPACE) - return; - - if (isWorkspaceSpecial(id)) - return; - - Debug::log(LOG, "renameWorkspace: Renaming workspace {} to '{}'", id, name); - PWORKSPACE->m_szName = name; - - g_pEventManager->postEvent({"renameworkspace", std::to_string(PWORKSPACE->m_iID) + "," + PWORKSPACE->m_szName}); -} - void CCompositor::setActiveMonitor(PHLMONITOR pMonitor) { if (m_pLastMonitor == pMonitor) return; @@ -2758,8 +2621,8 @@ void CCompositor::moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWor if (FULLSCREEN) setWindowFullscreenInternal(pWindow, FSMODE_NONE); - const PHLWINDOW pFirstWindowOnWorkspace = g_pCompositor->getFirstWindowOnWorkspace(pWorkspace->m_iID); - const int visibleWindowsOnWorkspace = g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID, std::nullopt, true); + const PHLWINDOW pFirstWindowOnWorkspace = pWorkspace->getFirstWindow(); + const int visibleWindowsOnWorkspace = pWorkspace->getWindows(std::nullopt, true); const auto PWINDOWMONITOR = pWindow->m_pMonitor.lock(); const auto POSTOMON = pWindow->m_vRealPosition.goal() - PWINDOWMONITOR->vecPosition; const auto PWORKSPACEMONITOR = pWorkspace->m_pMonitor.lock(); @@ -2817,14 +2680,15 @@ void CCompositor::moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWor if (FULLSCREEN) setWindowFullscreenInternal(pWindow, FULLSCREENMODE); - g_pCompositor->updateWorkspaceWindows(pWorkspace->m_iID); - g_pCompositor->updateWorkspaceWindows(pWindow->workspaceID()); + pWorkspace->updateWindows(); + if (pWindow->m_pWorkspace) + pWindow->m_pWorkspace->updateWindows(); g_pCompositor->updateSuspendedStates(); } PHLWINDOW CCompositor::getForceFocus() { for (auto const& w : m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace)) + if (!w->m_bIsMapped || w->isHidden() || !w->m_pWorkspace || !w->m_pWorkspace->isVisible()) continue; if (!w->m_bStayFocused) @@ -3002,7 +2866,7 @@ void CCompositor::updateSuspendedStates() { if (!w->m_bIsMapped) continue; - w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace)); + w->setSuspended(w->isHidden() || !w->m_pWorkspace || !w->m_pWorkspace->isVisible()); } } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 208b6ecf..c02be579 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -115,21 +115,11 @@ class CCompositor { PHLMONITOR getRealMonitorFromOutput(SP); PHLWINDOW getWindowFromSurface(SP); PHLWINDOW getWindowFromHandle(uint32_t); - bool isWorkspaceVisible(PHLWORKSPACE); - bool isWorkspaceVisibleNotCovered(PHLWORKSPACE); PHLWORKSPACE getWorkspaceByID(const WORKSPACEID&); PHLWORKSPACE getWorkspaceByName(const std::string&); PHLWORKSPACE getWorkspaceByString(const std::string&); void sanityCheckWorkspaces(); - void updateWorkspaceWindowDecos(const WORKSPACEID&); - void updateWorkspaceWindowData(const WORKSPACEID&); - int getWindowsOnWorkspace(const WORKSPACEID& id, std::optional onlyTiled = {}, std::optional onlyVisible = {}); - int getGroupsOnWorkspace(const WORKSPACEID& id, std::optional onlyTiled = {}, std::optional onlyVisible = {}); PHLWINDOW getUrgentWindow(); - bool hasUrgentWindowOnWorkspace(const WORKSPACEID&); - PHLWINDOW getFirstWindowOnWorkspace(const WORKSPACEID&); - PHLWINDOW getTopLeftWindowOnWorkspace(const WORKSPACEID&); - PHLWINDOW getFullscreenWindowOnWorkspace(const WORKSPACEID&); bool isWindowActive(PHLWINDOW); void changeWindowZOrder(PHLWINDOW, bool); void cleanupFadingOut(const MONITORID& monid); @@ -142,7 +132,6 @@ class CCompositor { PHLMONITOR getMonitorInDirection(const char&); PHLMONITOR getMonitorInDirection(PHLMONITOR, const char&); void updateAllWindowsAnimatedDecorationValues(); - void updateWorkspaceWindows(const WORKSPACEID& id); void updateWindowAnimatedDecorationValues(PHLWINDOW); MONITORID getNextAvailableMonitorID(std::string const& name); void moveWorkspaceToMonitor(PHLWORKSPACE, PHLMONITOR, bool noWarpCursor = false); @@ -165,10 +154,8 @@ class CCompositor { PHLLS getLayerSurfaceFromSurface(SP); void closeWindow(PHLWINDOW); Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); - void forceReportSizesToWindowsOnWorkspace(const WORKSPACEID&); PHLWORKSPACE createNewWorkspace(const WORKSPACEID&, const MONITORID&, const std::string& name = "", bool isEmpty = true); // will be deleted next frame if left empty and unfocused! - void renameWorkspace(const WORKSPACEID&, const std::string& name = ""); void setActiveMonitor(PHLMONITOR); bool isWorkspaceSpecial(const WORKSPACEID&); WORKSPACEID getNewSpecialID(); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 357e7a60..f6734011 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -927,8 +927,8 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { for (auto const& w : g_pCompositor->m_vWorkspaces) { if (w->inert()) continue; - g_pCompositor->updateWorkspaceWindows(w->m_iID); - g_pCompositor->updateWorkspaceWindowData(w->m_iID); + w->updateWindows(); + w->updateWindowData(); } // Update window border colors diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 7c0a9417..11c16f0e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -306,12 +306,12 @@ std::string CHyprCtl::getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat form "lastwindowtitle": "{}" }})#", w->m_iID, escapeJSONStrings(w->m_szName), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?"), - escapeJSONStrings(PMONITOR ? std::to_string(PMONITOR->ID) : "null"), g_pCompositor->getWindowsOnWorkspace(w->m_iID), - ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), (uintptr_t)PLASTW.get(), PLASTW ? escapeJSONStrings(PLASTW->m_szTitle) : ""); + escapeJSONStrings(PMONITOR ? std::to_string(PMONITOR->ID) : "null"), w->getWindows(), ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), + (uintptr_t)PLASTW.get(), PLASTW ? escapeJSONStrings(PLASTW->m_szTitle) : ""); } else { return std::format("workspace ID {} ({}) on monitor {}:\n\tmonitorID: {}\n\twindows: {}\n\thasfullscreen: {}\n\tlastwindow: 0x{:x}\n\tlastwindowtitle: {}\n\n", w->m_iID, - w->m_szName, PMONITOR ? PMONITOR->szName : "?", PMONITOR ? std::to_string(PMONITOR->ID) : "null", g_pCompositor->getWindowsOnWorkspace(w->m_iID), - (int)w->m_bHasFullscreenWindow, (uintptr_t)PLASTW.get(), PLASTW ? PLASTW->m_szTitle : ""); + w->m_szName, PMONITOR ? PMONITOR->szName : "?", PMONITOR ? std::to_string(PMONITOR->ID) : "null", w->getWindows(), (int)w->m_bHasFullscreenWindow, + (uintptr_t)PLASTW.get(), PLASTW ? PLASTW->m_szTitle : ""); } } @@ -1764,7 +1764,7 @@ std::string CHyprCtl::getReply(std::string request) { } for (auto const& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || !g_pCompositor->isWorkspaceVisible(w->m_pWorkspace)) + if (!w->m_bIsMapped || !w->m_pWorkspace || !w->m_pWorkspace->isVisible()) continue; w->updateDynamicRules(); diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 117d301c..12e81b76 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -413,12 +413,12 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { setAnimationsToMove(); - g_pCompositor->updateWorkspaceWindows(OLDWORKSPACE->m_iID); - g_pCompositor->updateWorkspaceWindowData(OLDWORKSPACE->m_iID); + OLDWORKSPACE->updateWindows(); + OLDWORKSPACE->updateWindowData(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(OLDWORKSPACE->monitorID()); - g_pCompositor->updateWorkspaceWindows(workspaceID()); - g_pCompositor->updateWorkspaceWindowData(workspaceID()); + pWorkspace->updateWindows(); + pWorkspace->updateWindowData(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -437,7 +437,7 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { // update xwayland coords g_pXWaylandManager->setWindowSize(m_pSelf.lock(), m_vRealSize.value()); - if (OLDWORKSPACE && g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE->m_iID) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE->m_iID) == 0 && *PCLOSEONLASTSPECIAL) { + if (OLDWORKSPACE && g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE->m_iID) && OLDWORKSPACE->getWindows() == 0 && *PCLOSEONLASTSPECIAL) { if (const auto PMONITOR = OLDWORKSPACE->m_pMonitor.lock(); PMONITOR) PMONITOR->setSpecialWorkspace(nullptr); } @@ -516,7 +516,7 @@ void CWindow::onUnmap() { std::erase_if(g_pCompositor->m_vWindowFocusHistory, [&](const auto& other) { return other.expired() || other.lock().get() == this; }); - if (*PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(workspaceID()) == 0 && onSpecialWorkspace()) { + if (*PCLOSEONLASTSPECIAL && m_pWorkspace && m_pWorkspace->getWindows() == 0 && onSpecialWorkspace()) { const auto PMONITOR = m_pMonitor.lock(); if (PMONITOR && PMONITOR->activeSpecialWorkspace && PMONITOR->activeSpecialWorkspace == m_pWorkspace) PMONITOR->setSpecialWorkspace(nullptr); @@ -527,8 +527,10 @@ void CWindow::onUnmap() { if (PMONITOR && PMONITOR->solitaryClient.lock().get() == this) PMONITOR->solitaryClient.reset(); - g_pCompositor->updateWorkspaceWindows(workspaceID()); - g_pCompositor->updateWorkspaceWindowData(workspaceID()); + if (m_pWorkspace) { + m_pWorkspace->updateWindows(); + m_pWorkspace->updateWindowData(); + } g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -855,8 +857,10 @@ void CWindow::createGroup() { addWindowDeco(std::make_unique(m_pSelf.lock())); - g_pCompositor->updateWorkspaceWindows(workspaceID()); - g_pCompositor->updateWorkspaceWindowData(workspaceID()); + if (m_pWorkspace) { + m_pWorkspace->updateWindows(); + m_pWorkspace->updateWindowData(); + } g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -873,8 +877,10 @@ void CWindow::destroyGroup() { m_sGroupData.pNextWindow.reset(); m_sGroupData.head = false; updateWindowDecos(); - g_pCompositor->updateWorkspaceWindows(workspaceID()); - g_pCompositor->updateWorkspaceWindowData(workspaceID()); + if (m_pWorkspace) { + m_pWorkspace->updateWindows(); + m_pWorkspace->updateWindowData(); + } g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -909,8 +915,10 @@ void CWindow::destroyGroup() { } g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV; - g_pCompositor->updateWorkspaceWindows(workspaceID()); - g_pCompositor->updateWorkspaceWindowData(workspaceID()); + if (m_pWorkspace) { + m_pWorkspace->updateWindows(); + m_pWorkspace->updateWindowData(); + } g_pLayoutManager->getCurrentLayout()->recalculateMonitor(monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -1507,7 +1515,7 @@ void CWindow::onX11Configure(CBox box) { updateWindowDecos(); - if (!g_pCompositor->isWorkspaceVisible(m_pWorkspace)) + if (!m_pWorkspace || !m_pWorkspace->isVisible()) return; // further things are only for visible windows m_pWorkspace = g_pCompositor->getMonitorFromVector(m_vRealPosition.value() + m_vRealSize.value() / 2.f)->activeWorkspace; diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 8cddbb6b..7c3d47d7 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -422,11 +422,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { int count; if (wantsCountGroup) - count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), - wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); + count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); else - count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), - wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); + count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); if (count != from) return false; @@ -456,11 +456,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { WORKSPACEID count; if (wantsCountGroup) - count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), - wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); + count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); else - count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), - wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); + count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); if (std::clamp(count, from, to) != count) return false; @@ -525,3 +525,136 @@ bool CWorkspace::inert() { MONITORID CWorkspace::monitorID() { return m_pMonitor ? m_pMonitor->ID : MONITOR_INVALID; } + +PHLWINDOW CWorkspace::getFullscreenWindow() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace == m_pSelf && w->isFullscreen()) + return w; + } + + return nullptr; +} + +bool CWorkspace::isVisible() { + return m_bVisible; +} + +bool CWorkspace::isVisibleNotCovered() { + const auto PMONITOR = m_pMonitor.lock(); + if (PMONITOR->activeSpecialWorkspace) + return PMONITOR->activeSpecialWorkspace->m_iID == m_iID; + + return PMONITOR->activeWorkspace->m_iID == m_iID; +} + +int CWorkspace::getWindows(std::optional onlyTiled, std::optional onlyVisible) { + int no = 0; + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->workspaceID() != m_iID || !w->m_bIsMapped) + continue; + if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) + continue; + if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) + continue; + no++; + } + + return no; +} + +int CWorkspace::getGroups(std::optional onlyTiled, std::optional onlyVisible) { + int no = 0; + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->workspaceID() != m_iID || !w->m_bIsMapped) + continue; + if (!w->m_sGroupData.head) + continue; + if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) + continue; + if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) + continue; + no++; + } + return no; +} + +PHLWINDOW CWorkspace::getFirstWindow() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace == m_pSelf && w->m_bIsMapped && !w->isHidden()) + return w; + } + + return nullptr; +} + +PHLWINDOW CWorkspace::getTopLeftWindow() { + const auto PMONITOR = m_pMonitor.lock(); + + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace != m_pSelf || !w->m_bIsMapped || w->isHidden()) + continue; + + const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); + + if (WINDOWIDEALBB.x <= PMONITOR->vecPosition.x + 1 && WINDOWIDEALBB.y <= PMONITOR->vecPosition.y + 1) + return w; + } + return nullptr; +} + +bool CWorkspace::hasUrgentWindow() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace == m_pSelf && w->m_bIsMapped && w->m_bIsUrgent) + return true; + } + + return false; +} + +void CWorkspace::updateWindowDecos() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace != m_pSelf) + continue; + + w->updateWindowDecos(); + } +} + +void CWorkspace::updateWindowData() { + const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(m_pSelf.lock()); + + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace != m_pSelf) + continue; + + w->updateWindowData(WORKSPACERULE); + } +} + +void CWorkspace::forceReportSizesToWindows() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (w->m_pWorkspace != m_pSelf || !w->m_bIsMapped || w->isHidden()) + continue; + + g_pXWaylandManager->setWindowSize(w, w->m_vRealSize.value(), true); + } +} + +void CWorkspace::rename(const std::string& name) { + if (g_pCompositor->isWorkspaceSpecial(m_iID)) + return; + + Debug::log(LOG, "CWorkspace::rename: Renaming workspace {} to '{}'", m_iID, name); + m_szName = name; + + g_pEventManager->postEvent({"renameworkspace", std::to_string(m_iID) + "," + m_szName}); +} + +void CWorkspace::updateWindows() { + for (auto const& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_pWorkspace != m_pSelf) + continue; + + w->updateDynamicRules(); + } +} diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index 3ed9f50c..606485a2 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -63,23 +63,29 @@ class CWorkspace { // Inert: destroyed and invalid. If this is true, release the ptr you have. bool inert(); - void startAnim(bool in, bool left, bool instant = false); void setActive(bool on); - void moveToMonitor(const MONITORID&); MONITORID monitorID(); - PHLWINDOW getLastFocusedWindow(); void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace); - std::string getConfigName(); - bool matchesStaticSelector(const std::string& selector); - void markInert(); - SWorkspaceIDName getPrevWorkspaceIDName(bool perMonitor) const; + void updateWindowDecos(); + void updateWindowData(); + int getWindows(std::optional onlyTiled = {}, std::optional onlyVisible = {}); + int getGroups(std::optional onlyTiled = {}, std::optional onlyVisible = {}); + bool hasUrgentWindow(); + PHLWINDOW getFirstWindow(); + PHLWINDOW getTopLeftWindow(); + PHLWINDOW getFullscreenWindow(); + bool isVisible(); + bool isVisibleNotCovered(); + void rename(const std::string& name = ""); + void forceReportSizesToWindows(); + void updateWindows(); private: void init(PHLWORKSPACE self); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 73ab45c1..a607d7ce 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -509,7 +509,7 @@ void Events::listener_mapWindow(void* owner, void* data) { else if (*PNEWTAKESOVERFS == 1) requestedInternalFSMode = PWINDOW->m_pWorkspace->m_efFullscreenMode; else if (*PNEWTAKESOVERFS == 2) - g_pCompositor->setWindowFullscreenInternal(g_pCompositor->getFullscreenWindowOnWorkspace(PWINDOW->m_pWorkspace->m_iID), FSMODE_NONE); + g_pCompositor->setWindowFullscreenInternal(PWINDOW->m_pWorkspace->getFullscreenWindow(), FSMODE_NONE); } if (!PWINDOW->m_sWindowData.noFocus.valueOrDefault() && !PWINDOW->m_bNoInitialFocus && @@ -531,7 +531,7 @@ void Events::listener_mapWindow(void* owner, void* data) { if (!PWINDOW->m_bNoInitialFocus && (requestedInternalFSMode.has_value() || requestedClientFSMode.has_value() || requestedFSState.has_value())) { // fix fullscreen on requested (basically do a switcheroo) if (PWINDOW->m_pWorkspace->m_bHasFullscreenWindow) - g_pCompositor->setWindowFullscreenInternal(g_pCompositor->getFullscreenWindowOnWorkspace(PWINDOW->m_pWorkspace->m_iID), FSMODE_NONE); + g_pCompositor->setWindowFullscreenInternal(PWINDOW->m_pWorkspace->getFullscreenWindow(), FSMODE_NONE); PWINDOW->m_vRealPosition.warp(); PWINDOW->m_vRealSize.warp(); @@ -603,7 +603,8 @@ void Events::listener_mapWindow(void* owner, void* data) { // fix some xwayland apps that don't behave nicely PWINDOW->m_vReportedSize = PWINDOW->m_vPendingReportedSize; - g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID()); + if (PWINDOW->m_pWorkspace) + PWINDOW->m_pWorkspace->updateWindows(); if (PMONITOR && PWINDOW->isX11OverrideRedirect()) PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; @@ -699,7 +700,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { g_pCompositor->setWindowFullscreenInternal(PWINDOWCANDIDATE, CURRENTFSMODE); } - if (!PWINDOWCANDIDATE && g_pCompositor->getWindowsOnWorkspace(PWINDOW->workspaceID()) == 0) + if (!PWINDOWCANDIDATE && PWINDOW->m_pWorkspace && PWINDOW->m_pWorkspace->getWindows() == 0) g_pInputManager->refocus(); g_pInputManager->sendMotionEventsToFocused(); @@ -729,7 +730,8 @@ void Events::listener_unmapWindow(void* owner, void* data) { g_pInputManager->recheckIdleInhibitorStatus(); // force report all sizes (QT sometimes has an issue with this) - g_pCompositor->forceReportSizesToWindowsOnWorkspace(PWINDOW->workspaceID()); + if (PWINDOW->m_pWorkspace) + PWINDOW->m_pWorkspace->forceReportSizesToWindows(); // update lastwindow after focus PWINDOW->onUnmap(); diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index fa2f84ab..dc181d4f 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -264,7 +264,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { WORKSPACEID id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0; while (++id < LONG_MAX) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id); - if (!invalidWSes.contains(id) && (!PWORKSPACE || g_pCompositor->getWindowsOnWorkspace(id) == 0)) { + if (!invalidWSes.contains(id) && (!PWORKSPACE || PWORKSPACE->getWindows() == 0)) { result.id = id; return result; } diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 63268c8a..cbad959e 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -629,17 +629,17 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo if (!noFocus && !g_pCompositor->m_pLastMonitor->activeSpecialWorkspace && !(g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bPinned && g_pCompositor->m_pLastWindow->m_pMonitor == self)) { static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); - auto pWindow = pWorkspace->m_bHasFullscreenWindow ? g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID) : pWorkspace->getLastFocusedWindow(); + auto pWindow = pWorkspace->m_bHasFullscreenWindow ? pWorkspace->getFullscreenWindow() : pWorkspace->getLastFocusedWindow(); if (!pWindow) { if (*PFOLLOWMOUSE == 1) pWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindow) - pWindow = g_pCompositor->getTopLeftWindowOnWorkspace(pWorkspace->m_iID); + pWindow = pWorkspace->getTopLeftWindow(); if (!pWindow) - pWindow = g_pCompositor->getFirstWindowOnWorkspace(pWorkspace->m_iID); + pWindow = pWorkspace->getFirstWindow(); } g_pCompositor->focusWindow(pWindow); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index c3e394f3..864c8564 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -514,7 +514,7 @@ void CHyprDwindleLayout::calculateWorkspace(const PHLWORKSPACE& pWorkspace) { if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); + const auto PFULLWINDOW = pWorkspace->getFullscreenWindow(); if (pWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; @@ -1054,7 +1054,7 @@ void CHyprDwindleLayout::moveToRoot(PHLWINDOW pWindow, bool stable) { std::swap(pRoot->children[0], pRoot->children[1]); // if the workspace is visible, recalculate layout - if (g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) + if (pWindow->m_pWorkspace && pWindow->m_pWorkspace->isVisible()) pRoot->recalcSizePosRecursive(); } @@ -1094,7 +1094,7 @@ Vector2D CHyprDwindleLayout::predictSizeForNewWindowTiled() { PHLWINDOW candidate = g_pCompositor->m_pLastWindow.lock(); if (!candidate) - candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); + candidate = g_pCompositor->m_pLastMonitor->activeWorkspace->getFirstWindow(); // create a fake node SDwindleNodeData node; diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index af8b907c..22e1d947 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -187,7 +187,7 @@ bool IHyprLayout::onWindowCreatedAutoGroup(PHLWINDOW pWindow) { static auto PAUTOGROUP = CConfigValue("group:auto_group"); const PHLWINDOW OPENINGON = g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace ? g_pCompositor->m_pLastWindow.lock() : - g_pCompositor->getFirstWindowOnWorkspace(pWindow->workspaceID()); + (pWindow->m_pWorkspace ? pWindow->m_pWorkspace->getFirstWindow() : nullptr); const bool FLOATEDINTOTILED = pWindow->m_bIsFloating && !OPENINGON->m_bIsFloating; const bool SWALLOWING = pWindow->m_pSwallowed || pWindow->m_bGroupSwallowed; @@ -714,7 +714,7 @@ void IHyprLayout::changeWindowFloatingMode(PHLWINDOW pWindow) { const auto PWORKSPACE = PNEWMON->activeSpecialWorkspace ? PNEWMON->activeSpecialWorkspace : PNEWMON->activeWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) - g_pCompositor->setWindowFullscreenInternal(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), FSMODE_NONE); + g_pCompositor->setWindowFullscreenInternal(PWORKSPACE->getFullscreenWindow(), FSMODE_NONE); // save real pos cuz the func applies the default 5,5 mid const auto PSAVEDPOS = pWindow->m_vRealPosition.goal(); @@ -803,7 +803,7 @@ PHLWINDOW IHyprLayout::getNextWindowCandidate(PHLWINDOW pWindow) { // first of all, if this is a fullscreen workspace, if (PWORKSPACE->m_bHasFullscreenWindow) - return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->workspaceID()); + return PWORKSPACE->getFullscreenWindow(); if (pWindow->m_bIsFloating) { @@ -842,10 +842,10 @@ PHLWINDOW IHyprLayout::getNextWindowCandidate(PHLWINDOW pWindow) { auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->workspaceID()); + pWindowCandidate = PWORKSPACE->getTopLeftWindow(); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getFirstWindowOnWorkspace(pWindow->workspaceID()); + pWindowCandidate = PWORKSPACE->getFirstWindow(); if (!pWindowCandidate || pWindow == pWindowCandidate || !pWindowCandidate->m_bIsMapped || pWindowCandidate->isHidden() || pWindowCandidate->m_bX11ShouldntFocus || pWindowCandidate->isX11OverrideRedirect() || pWindowCandidate->m_pMonitor != g_pCompositor->m_pLastMonitor) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 695dcc99..bf808627 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -298,7 +298,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); + const auto PFULLWINDOW = pWorkspace->getFullscreenWindow(); if (pWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index ceb594aa..68dbdda1 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -149,7 +149,7 @@ void CAnimationManager::tick() { animationsDisabled = animationsDisabled || PLAYER->noAnimations; } - const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? g_pCompositor->isWorkspaceVisible(PWINDOW->m_pWorkspace) : true; + const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? PWINDOW->m_pWorkspace->isVisible() : true; // beziers are with a switch unforto // TODO: maybe do something cleaner diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 8cf39c1b..a5327149 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1036,8 +1036,12 @@ static SDispatchResult toggleActiveFloatingCore(std::string args, std::optional< g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW); } - g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID()); - g_pCompositor->updateWorkspaceWindowData(PWINDOW->workspaceID()); + + if (PWINDOW->m_pWorkspace) { + PWINDOW->m_pWorkspace->updateWindows(); + PWINDOW->m_pWorkspace->updateWindowData(); + } + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PWINDOW->monitorID()); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); @@ -1305,7 +1309,7 @@ SDispatchResult CKeybindManager::moveActiveToWorkspace(std::string args) { g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace); } - POLDWS->m_pLastFocusedWindow = g_pCompositor->getFirstWindowOnWorkspace(POLDWS->m_iID); + POLDWS->m_pLastFocusedWindow = POLDWS->getFirstWindow(); if (pWorkspace->m_bIsSpecialWorkspace) pMonitor->setSpecialWorkspace(pWorkspace); @@ -1799,10 +1803,14 @@ SDispatchResult CKeybindManager::renameWorkspace(std::string args) { if (FIRSTSPACEPOS != std::string::npos) { int workspace = std::stoi(args.substr(0, FIRSTSPACEPOS)); std::string name = args.substr(FIRSTSPACEPOS + 1); - g_pCompositor->renameWorkspace(workspace, name); - } else { - g_pCompositor->renameWorkspace(std::stoi(args), ""); - } + if (const auto& PWS = g_pCompositor->getWorkspaceByID(workspace); PWS) + PWS->rename(name); + else + return {.success = false, .error = "No such workspace"}; + } else if (const auto& PWS = g_pCompositor->getWorkspaceByID(std::stoi(args)); PWS) + PWS->rename(""); + else + return {.success = false, .error = "No such workspace"}; } catch (std::exception& e) { Debug::log(ERR, "Invalid arg in renameWorkspace, expected numeric id only or a numeric id and string name. \"{}\": \"{}\"", args, e.what()); return {.success = false, .error = std::format("Invalid arg in renameWorkspace, expected numeric id only or a numeric id and string name. \"{}\": \"{}\"", args, e.what())}; @@ -2069,9 +2077,9 @@ SDispatchResult CKeybindManager::circleNext(std::string arg) { if (g_pCompositor->m_pLastWindow.expired()) { // if we have a clear focus, find the first window and get the next focusable. - if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()) > 0) { - const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()); - + const auto PWS = g_pCompositor->m_pLastMonitor->activeWorkspace; + if (PWS && PWS->getWindows() > 0) { + const auto PWINDOW = PWS->getFirstWindow(); switchToWindow(PWINDOW); } @@ -2117,7 +2125,7 @@ SDispatchResult CKeybindManager::focusWindow(std::string regexp) { } if (PWORKSPACE->m_bHasFullscreenWindow) { - const auto FSWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto FSWINDOW = PWORKSPACE->getFullscreenWindow(); const auto FSMODE = PWORKSPACE->m_efFullscreenMode; if (PWINDOW->m_bIsFloating) { diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index a6f25142..7c91258e 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -63,7 +63,7 @@ void CInputManager::recheckIdleInhibitorStatus() { return; } - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->isFullscreen() && g_pCompositor->isWorkspaceVisible(w->m_pWorkspace)) { + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->isFullscreen() && w->m_pWorkspace && w->m_pWorkspace->isVisible()) { PROTO::idle->setInhibit(true); return; } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 9110cd15..525ca954 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -294,7 +294,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { const auto PWORKSPACE = PMONITOR->activeWorkspace; const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (PWORKSPACE->m_bHasFullscreenWindow && !foundSurface && PWORKSPACE->m_efFullscreenMode == FSMODE_FULLSCREEN) { - pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + pFoundWindow = PWORKSPACE->getFullscreenWindow(); if (!pFoundWindow) { // what the fuck, somehow happens occasionally?? @@ -325,7 +325,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (pFoundWindow && !pFoundWindow->onSpecialWorkspace()) { - pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + pFoundWindow = PWORKSPACE->getFullscreenWindow(); } } else { // if we have a maximized window, allow focusing on a bar or something if in reserved area. @@ -339,7 +339,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!(pFoundWindow && pFoundWindow->m_bIsFloating && pFoundWindow->m_bCreatedOverFullscreen)) - pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + pFoundWindow = PWORKSPACE->getFullscreenWindow(); } } } @@ -1402,7 +1402,7 @@ void CInputManager::refocusLastWindow(PHLMONITOR pMonitor) { foundSurface = nullptr; } - if (!foundSurface && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->isWorkspaceVisibleNotCovered(g_pCompositor->m_pLastWindow->m_pWorkspace)) { + if (!foundSurface && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_pWorkspace && g_pCompositor->m_pLastWindow->m_pWorkspace->isVisibleNotCovered()) { // then the last focused window if we're on the same workspace as it const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); g_pCompositor->focusWindow(PLASTWINDOW); diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index ba0783fa..6cfe5a24 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -243,8 +243,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { m_sActiveSwipe.delta = std::clamp(m_sActiveSwipe.delta, (double)-SWIPEDISTANCE, (double)SWIPEDISTANCE); if ((m_sActiveSwipe.pWorkspaceBegin->m_iID == workspaceIDLeft && *PSWIPENEW && (m_sActiveSwipe.delta < 0)) || - (m_sActiveSwipe.delta > 0 && g_pCompositor->getWindowsOnWorkspace(m_sActiveSwipe.pWorkspaceBegin->m_iID) == 0 && - workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID) || + (m_sActiveSwipe.delta > 0 && m_sActiveSwipe.pWorkspaceBegin->getWindows() == 0 && workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID) || (m_sActiveSwipe.delta < 0 && m_sActiveSwipe.pWorkspaceBegin->m_iID <= workspaceIDLeft)) { m_sActiveSwipe.delta = 0; @@ -270,7 +269,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { else m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0)); - g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); + m_sActiveSwipe.pWorkspaceBegin->updateWindowDecos(); return; } m_sActiveSwipe.delta = 0; @@ -297,7 +296,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0)); } - g_pCompositor->updateWorkspaceWindowDecos(workspaceIDLeft); + PWORKSPACE->updateWindowDecos(); } else { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDRight); @@ -310,7 +309,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { else m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0)); - g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); + m_sActiveSwipe.pWorkspaceBegin->updateWindowDecos(); return; } m_sActiveSwipe.delta = 0; @@ -337,12 +336,12 @@ void CInputManager::updateWorkspaceSwipe(double delta) { m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / SWIPEDISTANCE) * XDISTANCE, 0.0)); } - g_pCompositor->updateWorkspaceWindowDecos(workspaceIDRight); + PWORKSPACE->updateWindowDecos(); } g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor.lock()); - g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); + m_sActiveSwipe.pWorkspaceBegin->updateWindowDecos(); if (*PSWIPEFOREVER) { if (abs(m_sActiveSwipe.delta) >= SWIPEDISTANCE) { diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 42545bc1..57490d23 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -310,8 +310,8 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor) { return true; // if the window is being moved to a workspace that is not invisible, and the alpha is > 0.F, render it. - if (pWindow->m_iMonitorMovedFrom != -1 && pWindow->m_fMovingToWorkspaceAlpha.isBeingAnimated() && pWindow->m_fMovingToWorkspaceAlpha.value() > 0.F && - !g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) + if (pWindow->m_iMonitorMovedFrom != -1 && pWindow->m_fMovingToWorkspaceAlpha.isBeingAnimated() && pWindow->m_fMovingToWorkspaceAlpha.value() > 0.F && pWindow->m_pWorkspace && + !pWindow->m_pWorkspace->isVisible()) return true; const auto PWINDOWWORKSPACE = pWindow->m_pWorkspace; @@ -324,18 +324,18 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor) { pWindow->m_fAlpha.value() == 0) return false; - if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) + if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !PWINDOWWORKSPACE->isVisible()) return false; } if (pWindow->m_pMonitor == pMonitor) return true; - if (!g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace) && pWindow->m_pMonitor != pMonitor) + if (!(!pWindow->m_pWorkspace || !pWindow->m_pWorkspace->isVisible()) && pWindow->m_pMonitor != pMonitor) return false; // if not, check if it maybe is active on a different monitor. - if (g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) + if (pWindow->m_pWorkspace && pWindow->m_pWorkspace->isVisible() && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) return !pWindow->isFullscreen(); // Do not draw fullscreen windows on other monitors if (pMonitor->activeSpecialWorkspace == pWindow->m_pWorkspace) @@ -376,7 +376,7 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow) { if (pWindow->m_bPinned || PWORKSPACE->m_bForceRendering) return true; - if (g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) + if (PWORKSPACE && PWORKSPACE->isVisible()) return true; for (auto const& m : g_pCompositor->m_vMonitors) { @@ -591,7 +591,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe decorate = false; // whether to use m_fMovingToWorkspaceAlpha, only if fading out into an invisible ws - const bool USE_WORKSPACE_FADE_ALPHA = pWindow->m_iMonitorMovedFrom != -1 && !g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace); + const bool USE_WORKSPACE_FADE_ALPHA = pWindow->m_iMonitorMovedFrom != -1 && (!PWORKSPACE || !PWORKSPACE->isVisible()); const bool DONT_BLUR = pWindow->m_sWindowData.noBlur.valueOrDefault() || pWindow->m_sWindowData.RGBX.valueOrDefault() || pWindow->opaque(); renderdata.surface = pWindow->m_pWLSurface->resource(); @@ -933,7 +933,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA // Render layer surfaces below windows for monitor // if we have a fullscreen, opaque window that convers the screen, we can skip this. // TODO: check better with solitary after MR for tearing. - const auto PFULLWINDOW = pWorkspace ? g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID) : nullptr; + const auto PFULLWINDOW = pWorkspace ? pWorkspace->getFullscreenWindow() : nullptr; if (!pWorkspace->m_bHasFullscreenWindow || pWorkspace->m_efFullscreenMode != FSMODE_FULLSCREEN || !PFULLWINDOW || PFULLWINDOW->m_vRealSize.isBeingAnimated() || !PFULLWINDOW->opaque() || pWorkspace->m_vRenderOffset.value() != Vector2D{} || g_pHyprOpenGL->preBlurQueued()) { @@ -2639,7 +2639,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(PHLMONITOR pMonitor) { PWORKSPACE->m_vRenderOffset.value() != Vector2D{}) return; - const auto PCANDIDATE = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto PCANDIDATE = PWORKSPACE->getFullscreenWindow(); if (!PCANDIDATE) return; // ???? From 00d6261cc06716eac6bdfc9d4426c3a54597098c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 23 Nov 2024 14:18:13 +0000 Subject: [PATCH 0056/1566] hyprpm: move temp files to XDG_RUNTIME_DIR avoid /tmp, it's cringe --- hyprpm/src/core/PluginManager.cpp | 44 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index db315193..fb3065b4 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -38,6 +38,18 @@ static std::string execAndGet(std::string cmd) { return proc.stdOut(); } +static std::string getTempRoot() { + static auto ENV = getenv("XDG_RUNTIME_DIR"); + if (!ENV) { + std::cerr << "\nERROR: XDG_RUNTIME_DIR not set!\n"; + exit(1); + } + + const auto STR = ENV + std::string{"/hyprpm/"}; + + return STR; +} + SHyprlandVersion CPluginManager::getHyprlandVersion() { static SHyprlandVersion ver; static bool once = false; @@ -84,7 +96,7 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() { } bool CPluginManager::createSafeDirectory(const std::string& path) { - if (path.empty() || !path.starts_with("/tmp")) + if (path.empty() || !path.starts_with(getTempRoot())) return false; if (std::filesystem::exists(path)) @@ -142,17 +154,17 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& progress.print(); - if (!std::filesystem::exists("/tmp/hyprpm")) { - std::filesystem::create_directory("/tmp/hyprpm"); - std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace); - } else if (!std::filesystem::is_directory("/tmp/hyprpm")) { + if (!std::filesystem::exists(getTempRoot())) { + std::filesystem::create_directory(getTempRoot()); + std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace); + } else if (!std::filesystem::is_directory(getTempRoot())) { std::println(stderr, "\n{}", failureString("Could not prepare working dir for hyprpm")); return false; } const std::string USERNAME = getpwuid(getuid())->pw_name; - m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME; + m_szWorkingPluginDirectory = getTempRoot() + USERNAME; if (!createSafeDirectory(m_szWorkingPluginDirectory)) { std::println(stderr, "\n{}", failureString("Could not prepare working dir for repo")); @@ -161,7 +173,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& progress.printMessageAbove(infoString("Cloning {}", url)); - std::string ret = execAndGet("cd /tmp/hyprpm && git clone --recursive " + url + " " + USERNAME); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive {} {}", getTempRoot(), url, USERNAME)); if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) { std::println(stderr, "\n{}", failureString("Could not clone the plugin repository. shell returned:\n{}", ret)); @@ -413,9 +425,9 @@ bool CPluginManager::updateHeaders(bool force) { return false; } - if (!std::filesystem::exists("/tmp/hyprpm")) { - std::filesystem::create_directory("/tmp/hyprpm"); - std::filesystem::permissions("/tmp/hyprpm", std::filesystem::perms::all, std::filesystem::perm_options::replace); + if (!std::filesystem::exists(getTempRoot())) { + std::filesystem::create_directory(getTempRoot()); + std::filesystem::permissions(getTempRoot(), std::filesystem::perms::owner_all, std::filesystem::perm_options::replace); } if (!force && headersValid() == HEADERS_OK) { @@ -430,7 +442,7 @@ bool CPluginManager::updateHeaders(bool force) { progress.print(); const std::string USERNAME = getpwuid(getuid())->pw_name; - const auto WORKINGDIR = "/tmp/hyprpm/hyprland-" + USERNAME; + const auto WORKINGDIR = getTempRoot() + "hyprland-" + USERNAME; if (!createSafeDirectory(WORKINGDIR)) { std::println("\n{}", failureString("Could not prepare working dir for hl")); @@ -448,12 +460,12 @@ bool CPluginManager::updateHeaders(bool force) { if (m_bVerbose && bShallow) progress.printMessageAbove(verboseString("will shallow since: {}", SHALLOW_DATE)); - std::string ret = - execAndGet("cd /tmp/hyprpm && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-" + USERNAME + (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : "")); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive https://github.com/hyprwm/Hyprland hyprland-{}{}", getTempRoot(), USERNAME, + (bShallow ? " --shallow-since='" + SHALLOW_DATE + "'" : ""))); if (!std::filesystem::exists(WORKINGDIR)) { progress.printMessageAbove(failureString("Clone failed. Retrying without shallow.")); - ret = execAndGet("cd /tmp/hyprpm && git clone --recursive https://github.com/hyprwm/hyprland hyprland-" + USERNAME); + ret = execAndGet(std::format("cd {} && git clone --recursive https://github.com/hyprwm/hyprland hyprland-{}", getTempRoot(), USERNAME)); } if (!std::filesystem::exists(WORKINGDIR + "/.git")) { @@ -577,7 +589,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { progress.print(); const std::string USERNAME = getpwuid(getuid())->pw_name; - m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME; + m_szWorkingPluginDirectory = getTempRoot() + USERNAME; for (auto const& repo : REPOS) { bool update = forceUpdateAll; @@ -592,7 +604,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { progress.printMessageAbove(infoString("Cloning {}", repo.url)); - std::string ret = execAndGet("cd /tmp/hyprpm && git clone --recursive " + repo.url + " " + USERNAME); + std::string ret = execAndGet(std::format("cd {} && git clone --recursive {} {}", getTempRoot(), repo.url, USERNAME)); if (!std::filesystem::exists(m_szWorkingPluginDirectory + "/.git")) { std::println("{}", failureString("could not clone repo: shell returned: {}", ret)); From 451d7a41fc87529854c4116c96a7c6a46568a1ee Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 23 Nov 2024 09:29:29 -0500 Subject: [PATCH 0057/1566] renderer: add option to blur IME popups (#8521) --- src/config/ConfigDescriptions.hpp | 12 ++++++++++++ src/config/ConfigManager.cpp | 2 ++ src/render/Renderer.cpp | 11 ++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 2e3a6720..45379140 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -331,6 +331,18 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_FLOAT, .data = SConfigOptionDescription::SFloatData{0.2, 0, 1}, }, + SConfigOptionDescription{ + .value = "blur:input_methods", + .description = "whether to blur input methods (e.g. fcitx5)", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{false}, + }, + SConfigOptionDescription{ + .value = "blur:input_methods_ignorealpha", + .description = "works like ignorealpha in layer rules. If pixel opacity is below set value, will not blur. [0.0 - 1.0]", + .type = CONFIG_OPTION_FLOAT, + .data = SConfigOptionDescription::SFloatData{0.2, 0, 1}, + }, /* * animations: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f6734011..32f64f0a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -429,6 +429,8 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("decoration:blur:special", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:popups", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:popups_ignorealpha", {0.2F}); + m_pConfig->addConfigValue("decoration:blur:input_methods", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:blur:input_methods_ignorealpha", {0.2F}); m_pConfig->addConfigValue("decoration:active_opacity", {1.F}); m_pConfig->addConfigValue("decoration:inactive_opacity", {1.F}); m_pConfig->addConfigValue("decoration:fullscreen_opacity", {1.F}); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 57490d23..dae62851 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -850,12 +850,21 @@ void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, PHLMONITOR pMonitor, tim const auto SURF = pPopup->getSurface(); - renderdata.blur = false; renderdata.surface = SURF; renderdata.decorate = false; renderdata.w = SURF->current.size.x; renderdata.h = SURF->current.size.y; + static auto PBLUR = CConfigValue("decoration:blur:enabled"); + static auto PBLURIMES = CConfigValue("decoration:blur:input_methods"); + static auto PBLURIGNOREA = CConfigValue("decoration:blur:input_methods_ignorealpha"); + + renderdata.blur = *PBLURIMES && *PBLUR; + if (renderdata.blur) { + g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; + g_pHyprOpenGL->m_RenderData.discardOpacity = *PBLURIGNOREA; + } + SURF->breadthfirst([](SP s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata); } From 65f66dcf0d38533a383212ca440fdea0163be276 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 23 Nov 2024 22:32:13 +0800 Subject: [PATCH 0058/1566] binds: add option to allow fullscreening a pinned window (#8526) --- src/Compositor.cpp | 15 +++++++++++++-- src/config/ConfigDescriptions.hpp | 6 ++++++ src/config/ConfigManager.cpp | 1 + src/desktop/Window.hpp | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3fe5acec..53eaa467 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2245,7 +2245,8 @@ void CCompositor::setWindowFullscreenClient(const PHLWINDOW PWINDOW, const eFull } void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, sFullscreenState state) { - static auto PDIRECTSCANOUT = CConfigValue("render:direct_scanout"); + static auto PDIRECTSCANOUT = CConfigValue("render:direct_scanout"); + static auto PALLOWPINFULLSCREEN = CConfigValue("binds:allow_pin_fullscreen"); if (!validMapped(PWINDOW) || g_pCompositor->m_bUnsafeState) return; @@ -2259,7 +2260,17 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, sFullscreenS const eFullscreenMode CURRENT_EFFECTIVE_MODE = (eFullscreenMode)std::bit_floor((uint8_t)PWINDOW->m_sFullscreenState.internal); const eFullscreenMode EFFECTIVE_MODE = (eFullscreenMode)std::bit_floor((uint8_t)state.internal); - const bool CHANGEINTERNAL = !(PWINDOW->m_bPinned || CURRENT_EFFECTIVE_MODE == EFFECTIVE_MODE || (PWORKSPACE->m_bHasFullscreenWindow && !PWINDOW->isFullscreen())); + if (*PALLOWPINFULLSCREEN && !PWINDOW->m_bPinFullscreened && !PWINDOW->isFullscreen() && PWINDOW->m_bPinned) { + PWINDOW->m_bPinned = false; + PWINDOW->m_bPinFullscreened = true; + } + + const bool CHANGEINTERNAL = !(PWINDOW->m_bPinned || CURRENT_EFFECTIVE_MODE == EFFECTIVE_MODE || (PWORKSPACE->m_bHasFullscreenWindow && !PWINDOW->isFullscreen())); + + if (*PALLOWPINFULLSCREEN && PWINDOW->m_bPinFullscreened && PWINDOW->isFullscreen() && !PWINDOW->m_bPinned && state.internal == FSMODE_NONE) { + PWINDOW->m_bPinned = true; + PWINDOW->m_bPinFullscreened = false; + } // TODO: update the state on syncFullscreen changes if (!CHANGEINTERNAL && PWINDOW->m_sWindowData.syncFullscreen.valueOrDefault()) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 45379140..bb3d4e0e 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1206,6 +1206,12 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{true}, }, + SConfigOptionDescription{ + .value = "binds:allow_pin_fullscreen", + .description = "Allows fullscreen to pinned windows, and restore their pinned status afterwards", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{true}, + }, /* * xwayland: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 32f64f0a..3429db24 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -536,6 +536,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("binds:movefocus_cycles_fullscreen", Hyprlang::INT{1}); m_pConfig->addConfigValue("binds:disable_keybind_grabbing", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:window_direction_monitor_fallback", Hyprlang::INT{1}); + m_pConfig->addConfigValue("binds:allow_pin_fullscreen", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe_fingers", Hyprlang::INT{3}); diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index ac81e5ef..5dd59437 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -332,6 +332,9 @@ class CWindow { // For pinned (sticky) windows bool m_bPinned = false; + // For preserving pinned state when fullscreening a pinned window + bool m_bPinFullscreened = false; + // urgency hint bool m_bIsUrgent = false; From 54f57797e9d025db72777ccf4adb0ddb25125016 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Sat, 23 Nov 2024 09:36:28 -0500 Subject: [PATCH 0059/1566] snap: account for position of multiple monitors (#8543) --- src/layout/IHyprLayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 22e1d947..8ff55d10 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -484,8 +484,8 @@ static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRA const double BORDERDIFF = DRAGGINGBORDERSIZE - BORDERSIZE; const auto MON = DRAGGINGWINDOW->m_pMonitor.lock(); - SRange monX = {MON->vecPosition.x + BORDERSIZE, MON->vecSize.x - BORDERSIZE}; - SRange monY = {MON->vecPosition.y + BORDERSIZE, MON->vecSize.y - BORDERSIZE}; + SRange monX = {MON->vecPosition.x + BORDERSIZE, MON->vecPosition.x + MON->vecSize.x - BORDERSIZE}; + SRange monY = {MON->vecPosition.y + BORDERSIZE, MON->vecPosition.y + MON->vecSize.y - BORDERSIZE}; if (canSnap(sourceX.start, monX.start, GAPSIZE) || canSnap(sourceX.start, (monX.start += MON->vecReservedTopLeft.x + BORDERDIFF), GAPSIZE)) { SNAP(sourceX.start, sourceX.end, monX.start); From 55ec8bd512605a014cc322d3419a9cfa72178340 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Nov 2024 02:46:24 +0000 Subject: [PATCH 0060/1566] config: throw an error explicitly when parsing colors in gradients ref #8552 --- src/config/ConfigManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 3429db24..ba0fdd9d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -67,7 +67,10 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** } try { - DATA->m_vColors.push_back(CColor(*configStringToInt(var))); + const auto COL = configStringToInt(var); + if (!COL) + throw std::runtime_error(std::format("failed to parse {} as a color", var)); + DATA->m_vColors.push_back(CColor(COL.value())); } catch (std::exception& e) { Debug::log(WARN, "Error parsing gradient {}", V); parseError = "Error parsing gradient " + V + ": " + e.what(); From cc38e7e18fd762d5cdb34d06335223b7d7874106 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Nov 2024 14:53:36 +0000 Subject: [PATCH 0061/1566] config: don't overwrite errors in gradients --- src/config/ConfigManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index ba0fdd9d..c0f212cf 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -79,7 +79,8 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** if (DATA->m_vColors.size() == 0) { Debug::log(WARN, "Error parsing gradient {}", V); - parseError = "Error parsing gradient " + V + ": No colors?"; + if (parseError.empty()) + parseError = "Error parsing gradient " + V + ": No colors?"; DATA->m_vColors.push_back(0); // transparent } From 1930a95000d336b76d18c0c95ef77e138c9a4cd0 Mon Sep 17 00:00:00 2001 From: Nabil Otsmane <44232317+nabil-otsmane@users.noreply.github.com> Date: Mon, 25 Nov 2024 01:50:35 +0100 Subject: [PATCH 0062/1566] shm: fix shm fd size check before creating or resizing shm_pool (#8572) * protocols: fix shm fd size check before creating or resizing shm_pool * added static to function --- src/protocols/core/Shm.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp index a8c98bb0..708d41c3 100644 --- a/src/protocols/core/Shm.cpp +++ b/src/protocols/core/Shm.cpp @@ -1,6 +1,7 @@ #include "Shm.hpp" #include #include +#include #include #include "../../render/Texture.hpp" #include "../types/WLBuffer.hpp" @@ -99,10 +100,25 @@ void CSHMPool::resize(size_t size_) { LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", size, fd); } +static int shmIsSizeValid(int fd, size_t size) { + struct stat st; + if (fstat(fd, &st) == -1) { + LOGM(ERR, "Couldn't get stat for fd {} of shm client", fd); + return 0; + } + + return (size_t)st.st_size >= size; +} + CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t size_) : resource(resource_) { if (!good()) return; + if (!shmIsSizeValid(fd_, size_)) { + resource_->error(-1, "The size of the file is not big enough for the shm pool"); + return; + } + pool = makeShared(fd_, size_); resource->setDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); }); @@ -113,6 +129,11 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t r->error(-1, "Shrinking a shm pool is illegal"); return; } + if (!shmIsSizeValid(pool->fd, size_)) { + r->error(-1, "The size of the file is not big enough for the shm pool"); + return; + } + pool->resize(size_); }); From 0ddb952d7a3d102e160eea93c68f0d366186cf73 Mon Sep 17 00:00:00 2001 From: Vladimir-csp <4061903+Vladimir-csp@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:18:50 +0300 Subject: [PATCH 0063/1566] hyprland-uwsm.desktop: Just reference plain entry (#8553) --- systemd/hyprland-uwsm.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd/hyprland-uwsm.desktop b/systemd/hyprland-uwsm.desktop index 2ed1031b..e00f4aa2 100644 --- a/systemd/hyprland-uwsm.desktop +++ b/systemd/hyprland-uwsm.desktop @@ -1,6 +1,6 @@ [Desktop Entry] Name=Hyprland (uwsm-managed) Comment=An intelligent dynamic tiling Wayland compositor -Exec=uwsm start -N Hyprland -D Hyprland -C An_intelligent_dynamic_tiling_Wayland_compositor -- Hyprland +Exec=uwsm start -- hyprland.desktop DesktopNames=Hyprland Type=Application From 268778823676ef2bbda42050d78946e1fc27fc31 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 25 Nov 2024 14:42:06 +0000 Subject: [PATCH 0064/1566] hyprctl: verify runtime dir exists in instances() ref #8579 --- hyprctl/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 1f7f8d74..4ee2d598 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -66,6 +66,11 @@ std::string getRuntimeDir() { std::vector instances() { std::vector result; + try { + if (!std::filesystem::exists(getRuntimeDir())) + return {}; + } catch (std::exception& e) { return {}; } + for (const auto& el : std::filesystem::directory_iterator(getRuntimeDir())) { if (!el.is_directory() || !std::filesystem::exists(el.path().string() + "/hyprland.lock")) continue; From 1fb720b62aeb474873ba43426ddc53afde1e6cdd Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Tue, 26 Nov 2024 07:52:43 -0600 Subject: [PATCH 0065/1566] seat: fix double scrolling in some applications (#8583) --- src/managers/SeatManager.cpp | 6 ++++-- src/protocols/core/Seat.cpp | 4 ++++ src/protocols/core/Seat.hpp | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp index b40d6cad..665805f6 100644 --- a/src/managers/SeatManager.cpp +++ b/src/managers/SeatManager.cpp @@ -332,8 +332,10 @@ void CSeatManager::sendPointerAxis(uint32_t timeMs, wl_pointer_axis axis, double p->sendAxisRelativeDirection(axis, relative); if (source == 0) { - p->sendAxisValue120(axis, value120); - p->sendAxisDiscrete(axis, discrete); + if (p->version() >= 8) + p->sendAxisValue120(axis, value120); + else + p->sendAxisDiscrete(axis, discrete); } else if (value == 0) p->sendAxisStop(timeMs, axis); } diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp index d95e0e12..7c31b67c 100644 --- a/src/protocols/core/Seat.cpp +++ b/src/protocols/core/Seat.cpp @@ -136,6 +136,10 @@ CWLPointerResource::CWLPointerResource(SP resource_, SPstate.pointerFocus.lock(), {-1, -1} /* Coords don't really matter that much, they will be updated next move */); } +int CWLPointerResource::version() { + return resource->version(); +} + bool CWLPointerResource::good() { return resource->resource(); } diff --git a/src/protocols/core/Seat.hpp b/src/protocols/core/Seat.hpp index 1b43dd04..b5670237 100644 --- a/src/protocols/core/Seat.hpp +++ b/src/protocols/core/Seat.hpp @@ -73,6 +73,7 @@ class CWLPointerResource { CWLPointerResource(SP resource_, SP owner_); bool good(); + int version(); void sendEnter(SP surface, const Vector2D& local); void sendLeave(); void sendMotion(uint32_t timeMs, const Vector2D& local); From e9a7fb8f91d23f1ac2671e55f74234dcec2ee1c6 Mon Sep 17 00:00:00 2001 From: Agent00Ming <107314235+Agent00Ming@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:17:45 -0500 Subject: [PATCH 0066/1566] renderer: fix incorrect early return (#8590) Co-authored-by: Agent_00Ming --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index dae62851..ca6ceba1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -331,7 +331,7 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor) { if (pWindow->m_pMonitor == pMonitor) return true; - if (!(!pWindow->m_pWorkspace || !pWindow->m_pWorkspace->isVisible()) && pWindow->m_pMonitor != pMonitor) + if ((!pWindow->m_pWorkspace || !pWindow->m_pWorkspace->isVisible()) && pWindow->m_pMonitor != pMonitor) return false; // if not, check if it maybe is active on a different monitor. From 5329298b522e3cc1201894909443775b00aeb336 Mon Sep 17 00:00:00 2001 From: Andre Toerien Date: Wed, 27 Nov 2024 21:59:00 +0200 Subject: [PATCH 0067/1566] sessionLock: don't send motion events on every surface commit (#8584) --- src/managers/SessionLockManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index c7a5934a..b7110990 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -31,7 +31,7 @@ SSessionLockSurface::SSessionLockSurface(SP surface_) : sur listeners.commit = surface_->events.commit.registerListener([this](std::any data) { const auto PMONITOR = g_pCompositor->getMonitorFromID(iMonitorID); - if (mapped && pWlrSurface != g_pCompositor->m_pLastFocus) + if (mapped && !g_pCompositor->m_pLastFocus) g_pInputManager->simulateMouseMovement(); if (PMONITOR) From 8b51eeb7aef8b25de35a0d460f28f4d67c017866 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Nov 2024 14:31:38 +0000 Subject: [PATCH 0068/1566] core: fix compilation outside stdlibc++ fixes #8603 --- src/managers/KeybindManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index a5327149..7f10249a 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2988,13 +2988,13 @@ SDispatchResult CKeybindManager::setProp(std::string args) { else configStringToInt(TOKEN).and_then([&colorData](const auto& e) { colorData.m_vColors.push_back(e); - return std::result_of::type(1); + return std::invoke_result_t(1); }); } } else if (VAL != "-1") configStringToInt(VAL).and_then([&colorData](const auto& e) { colorData.m_vColors.push_back(e); - return std::result_of::type(1); + return std::invoke_result_t(1); }); if (PROP == "activebordercolor") From 5963970be54c92fdebdbcebdeb76cf6de5e7e717 Mon Sep 17 00:00:00 2001 From: nyx Date: Thu, 28 Nov 2024 10:25:24 -0500 Subject: [PATCH 0069/1566] descriptions: change allow_pin_fullscreen value to false (#8592) --- src/config/ConfigDescriptions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index bb3d4e0e..e5918691 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1210,7 +1210,7 @@ inline static const std::vector CONFIG_OPTIONS = { .value = "binds:allow_pin_fullscreen", .description = "Allows fullscreen to pinned windows, and restore their pinned status afterwards", .type = CONFIG_OPTION_BOOL, - .data = SConfigOptionDescription::SBoolData{true}, + .data = SConfigOptionDescription::SBoolData{false}, }, /* From 22bf2853e6271932f073961f3dbeb0f9ff48493e Mon Sep 17 00:00:00 2001 From: Daringcuteseal Date: Thu, 28 Nov 2024 21:21:55 +0700 Subject: [PATCH 0070/1566] hyprpm: fix incomplete unmet dependencies message --- hyprpm/src/core/PluginManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index fb3065b4..db3893b5 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -115,7 +115,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& const auto HLVER = getHyprlandVersion(); if (!hasDeps()) { - std::println(stderr, "\n{}", failureString("Could not clone the plugin repository. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio")); + std::println(stderr, "\n{}", failureString("Could not clone the plugin repository. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio, pkg-config")); return false; } @@ -421,7 +421,7 @@ bool CPluginManager::updateHeaders(bool force) { const auto HLVER = getHyprlandVersion(); if (!hasDeps()) { - std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio")); + std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio, pkg-config")); return false; } From 8f83d29f00bfa89d1e8fe94b4dda98fe898b6b0e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Nov 2024 23:51:53 +0000 Subject: [PATCH 0071/1566] renderer: restore discard mode after IME render pass ref #8555 --- src/render/Renderer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index ca6ceba1..bba133d9 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -859,6 +859,10 @@ void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, PHLMONITOR pMonitor, tim static auto PBLURIMES = CConfigValue("decoration:blur:input_methods"); static auto PBLURIGNOREA = CConfigValue("decoration:blur:input_methods_ignorealpha"); + // TODO: make push/pop methods for this. + const auto DM = g_pHyprOpenGL->m_RenderData.discardMode; + const auto DA = g_pHyprOpenGL->m_RenderData.discardOpacity; + renderdata.blur = *PBLURIMES && *PBLUR; if (renderdata.blur) { g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; @@ -866,6 +870,9 @@ void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, PHLMONITOR pMonitor, tim } SURF->breadthfirst([](SP s, const Vector2D& offset, void* data) { renderSurface(s, offset.x, offset.y, data); }, &renderdata); + + g_pHyprOpenGL->m_RenderData.discardMode = DM; + g_pHyprOpenGL->m_RenderData.discardOpacity = DA; } void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, PHLMONITOR pMonitor, timespec* time) { From ef6b0c81c914bdc9b56c2674273698f065518993 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 1 Dec 2024 00:40:23 +0800 Subject: [PATCH 0072/1566] cleanup: remove leftover var in ThreadManager.cpp (#8611) --- src/managers/ThreadManager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/managers/ThreadManager.cpp b/src/managers/ThreadManager.cpp index 6f8e0c9a..8666b3a6 100644 --- a/src/managers/ThreadManager.cpp +++ b/src/managers/ThreadManager.cpp @@ -3,8 +3,6 @@ #include "../Compositor.hpp" #include "../config/ConfigValue.hpp" -int slowUpdate = 0; - int handleTimer(void* data) { const auto PTM = (CThreadManager*)data; @@ -27,4 +25,4 @@ CThreadManager::CThreadManager() { CThreadManager::~CThreadManager() { if (m_esConfigTimer) wl_event_source_remove(m_esConfigTimer); -} \ No newline at end of file +} From d26439a0fe5594fb26d5a3c01571f9490a9a2d2c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 30 Nov 2024 17:42:40 +0000 Subject: [PATCH 0073/1566] nix: update flake --- flake.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 969bc157..0db2ee60 100644 --- a/flake.lock +++ b/flake.lock @@ -16,11 +16,11 @@ ] }, "locked": { - "lastModified": 1731774881, - "narHash": "sha256-1Dxryiw8u2ejntxrrv3sMtIE8WHKxmlN4KeH+uMGbmc=", + "lastModified": 1731959031, + "narHash": "sha256-TGcvIjftziC1CjuiHCzrYDwmOoSFYIhdiKmLetzB5L0=", "owner": "hyprwm", "repo": "aquamarine", - "rev": "b31a6a4da8199ae3489057db7d36069a70749a56", + "rev": "4468981c1c50999f315baa1508f0e53c4ee70c52", "type": "github" }, "original": { @@ -151,11 +151,11 @@ ] }, "locked": { - "lastModified": 1731702627, - "narHash": "sha256-+JeO9gevnXannQxMfR5xzZtF4sYmSlWkX/BPmPx0mWk=", + "lastModified": 1732288281, + "narHash": "sha256-XTU9B53IjGeJiJ7LstOhuxcRjCOFkQFl01H78sT9Lg4=", "owner": "hyprwm", "repo": "hyprutils", - "rev": "e911361a687753bbbdfe3b6a9eab755ecaf1d9e1", + "rev": "b26f33cc1c8a7fd5076e19e2cce3f062dca6351c", "type": "github" }, "original": { @@ -189,11 +189,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1731676054, - "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", + "lastModified": 1732758367, + "narHash": "sha256-RzaI1RO0UXqLjydtz3GAXSTzHkpb/lLD1JD8a0W4Wpo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", + "rev": "fa42b5a5f401aab8a32bd33c9a4de0738180dc59", "type": "github" }, "original": { @@ -229,11 +229,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1731363552, - "narHash": "sha256-vFta1uHnD29VUY4HJOO/D6p6rxyObnf+InnSMT4jlMU=", + "lastModified": 1732021966, + "narHash": "sha256-mnTbjpdqF0luOkou8ZFi2asa1N3AA2CchR/RqCNmsGE=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0", + "rev": "3308484d1a443fc5bc92012435d79e80458fe43c", "type": "github" }, "original": { From 6d7544458d0fafcae410c1978a0cabce2fb4a346 Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:14:35 -0600 Subject: [PATCH 0074/1566] cleanup: use doLater instead of adding idle event handlers (#8624) --- src/protocols/Tablet.cpp | 26 ++++++++++++-------------- src/protocols/Tablet.hpp | 7 +++---- src/protocols/XDGShell.cpp | 18 +++++++++--------- src/protocols/XDGShell.hpp | 8 ++++---- src/xwayland/Server.cpp | 12 ++++-------- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/protocols/Tablet.cpp b/src/protocols/Tablet.cpp index d7f741b9..7768402b 100644 --- a/src/protocols/Tablet.cpp +++ b/src/protocols/Tablet.cpp @@ -2,6 +2,7 @@ #include "../devices/Tablet.hpp" #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" +#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include @@ -162,11 +163,6 @@ CTabletToolV2Resource::CTabletToolV2Resource(SP resource_, SP< }); } -CTabletToolV2Resource::~CTabletToolV2Resource() { - if (frameSource) - wl_event_source_remove(frameSource); -} - bool CTabletToolV2Resource::good() { return resource->resource(); } @@ -205,20 +201,22 @@ void CTabletToolV2Resource::sendData() { } void CTabletToolV2Resource::queueFrame() { - if (frameSource) + if (frameQueued) return; - frameSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, [](void* data) { ((CTabletToolV2Resource*)data)->sendFrame(false); }, this); + frameQueued = true; + g_pEventLoopManager->doLater([this]() { + if (!frameQueued || tool.expired() || inert) + return; + + sendFrame(); + }); } -void CTabletToolV2Resource::sendFrame(bool removeSource) { - if (frameSource) { - if (removeSource) - wl_event_source_remove(frameSource); - frameSource = nullptr; - } +void CTabletToolV2Resource::sendFrame() { + frameQueued = false; - if (!current) + if (!current || !resource) return; timespec now; diff --git a/src/protocols/Tablet.hpp b/src/protocols/Tablet.hpp index 1ebcb1e5..8c99bee0 100644 --- a/src/protocols/Tablet.hpp +++ b/src/protocols/Tablet.hpp @@ -112,21 +112,20 @@ class CTabletV2Resource { class CTabletToolV2Resource { public: CTabletToolV2Resource(SP resource_, SP tool_, SP seat_); - ~CTabletToolV2Resource(); bool good(); void sendData(); void queueFrame(); - void sendFrame(bool removeSource = true); + void sendFrame(); bool current = false; WP lastSurf; WP tool; WP seat; - wl_event_source* frameSource = nullptr; - bool inert = false; // removed was sent + bool frameQueued = false; + bool inert = false; // removed was sent private: SP resource; diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 688d0006..a542c394 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -3,6 +3,7 @@ #include #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" +#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include @@ -469,8 +470,6 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPresetRole(); } @@ -484,22 +483,23 @@ SP CXDGSurfaceResource::fromResource(wl_resource* res) { return data ? data->self.lock() : nullptr; } -static void onConfigure(void* data) { - ((CXDGSurfaceResource*)data)->configure(); -} - uint32_t CXDGSurfaceResource::scheduleConfigure() { - if (configureSource) + if (configureScheduled) return scheduledSerial; - configureSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, onConfigure, this); scheduledSerial = wl_display_next_serial(g_pCompositor->m_sWLDisplay); + configureScheduled = true; + g_pEventLoopManager->doLater([this]() { configure(); }); + return scheduledSerial; } void CXDGSurfaceResource::configure() { - configureSource = nullptr; + if (!resource) + return; + + configureScheduled = false; resource->sendConfigure(scheduledSerial); } diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp index ef847f3b..3b7d2d11 100644 --- a/src/protocols/XDGShell.hpp +++ b/src/protocols/XDGShell.hpp @@ -199,12 +199,12 @@ class CXDGSurfaceResource { void configure(); private: - SP resource; + SP resource; - uint32_t lastConfigureSerial = 0; - uint32_t scheduledSerial = 0; + uint32_t lastConfigureSerial = 0; + uint32_t scheduledSerial = 0; - wl_event_source* configureSource = nullptr; + bool configureScheduled = false; // std::vector> popups; diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index f356af18..390ce1f6 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -176,11 +176,6 @@ static bool openSockets(std::array& sockets, int display) { return true; } -static void startServer(void* data) { - if (!g_pXWayland->pServer->start()) - Debug::log(ERR, "The XWayland server could not start! XWayland will not work..."); -} - static int xwaylandReady(int fd, uint32_t mask, void* data) { return g_pXWayland->pServer->ready(fd, mask); } @@ -308,9 +303,10 @@ bool CXWaylandServer::create() { setenv("DISPLAY", displayName.c_str(), true); - // TODO: lazy mode - - idleSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, ::startServer, nullptr); + g_pEventLoopManager->doLater([this]() { + if (!start()) + Debug::log(ERR, "The XWayland server could not start! XWayland will not work..."); + }); return true; } From 10a9fec7fc8e77479a599985c776a8a184311cd6 Mon Sep 17 00:00:00 2001 From: UjinT34 <41110182+UjinT34@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:32:32 +0300 Subject: [PATCH 0075/1566] master: make center ignore reserved areas (#8625) --- src/config/ConfigDescriptions.hpp | 6 ++++++ src/config/ConfigManager.cpp | 1 + src/layout/MasterLayout.cpp | 13 +++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index e5918691..b95eeab1 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1596,6 +1596,12 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{false}, }, + SConfigOptionDescription{ + .value = "master:center_ignores_reserved", + .description = "centers the master window on monitor ignoring reserved areas", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{false}, + }, SConfigOptionDescription{ .value = "master:smart_resizing", .description = diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c0f212cf..07de8c24 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -470,6 +470,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("master:mfact", {0.55f}); m_pConfig->addConfigValue("master:new_status", {"slave"}); m_pConfig->addConfigValue("master:always_center_master", Hyprlang::INT{0}); + m_pConfig->addConfigValue("master:center_ignores_reserved", Hyprlang::INT{0}); m_pConfig->addConfigValue("master:new_on_active", {"none"}); m_pConfig->addConfigValue("master:new_on_top", Hyprlang::INT{0}); m_pConfig->addConfigValue("master:orientation", {"left"}); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index bf808627..4f761973 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -328,6 +328,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { eOrientation orientation = getDynamicOrientation(pWorkspace); bool centerMasterWindow = false; static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); + static auto PIGNORERESERVED = CConfigValue("master:center_ignores_reserved"); static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); const auto MASTERS = getMastersOnWorkspace(pWorkspace->m_iID); @@ -402,7 +403,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { nextX += WIDTH; } } else { // orientation left, right or center - float WIDTH = WSSIZE.x; + float WIDTH = *PIGNORERESERVED && centerMasterWindow ? PMONITOR->vecSize.x : WSSIZE.x; float heightLeft = WSSIZE.y; int mastersLeft = MASTERS; float nextX = 0; @@ -414,7 +415,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { if (orientation == ORIENTATION_RIGHT) { nextX = WSSIZE.x - WIDTH; } else if (centerMasterWindow) { - nextX = (WSSIZE.x - WIDTH) / 2; + nextX = ((*PIGNORERESERVED && centerMasterWindow ? PMONITOR->vecSize.x : WSSIZE.x) - WIDTH) / 2; } for (auto& nd : m_lMasterNodesData) { @@ -431,7 +432,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { } nd.size = Vector2D(WIDTH, HEIGHT); - nd.position = WSPOS + Vector2D(nextX, nextY); + nd.position = (*PIGNORERESERVED && centerMasterWindow ? PMONITOR->vecPosition : WSPOS) + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); mastersLeft--; @@ -506,7 +507,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { nextY += HEIGHT; } } else { // slaves for centered master window(s) - const float WIDTH = (WSSIZE.x - PMASTERNODE->size.x) / 2.0; + const float WIDTH = ((*PIGNORERESERVED ? PMONITOR->vecSize.x : WSSIZE.x) - PMASTERNODE->size.x) / 2.0; float heightLeft = 0; float heightLeftL = WSSIZE.y; float heightLeftR = WSSIZE.y; @@ -543,7 +544,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { continue; if (onRight) { - nextX = WIDTH + PMASTERNODE->size.x; + nextX = WIDTH + PMASTERNODE->size.x - (*PIGNORERESERVED ? PMONITOR->vecReservedTopLeft.x : 0); nextY = nextYR; heightLeft = heightLeftR; slavesLeft = slavesLeftR; @@ -568,7 +569,7 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { } } - nd.size = Vector2D(WIDTH, HEIGHT); + nd.size = Vector2D(*PIGNORERESERVED ? (WIDTH - (onRight ? PMONITOR->vecReservedBottomRight.x : PMONITOR->vecReservedTopLeft.x)) : WIDTH, HEIGHT); nd.position = WSPOS + Vector2D(nextX, nextY); applyNodeDataToWindow(&nd); From 92186898c0ca1b3f72922b72c4af1723f0d9b888 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:31:22 +0000 Subject: [PATCH 0076/1566] version: add link versions for other utils (#8619) --------- Co-authored-by: Mihai Fufezan --- CMakeLists.txt | 13 ++++++++----- hyprpm/CMakeLists.txt | 4 ++-- meson.build | 6 ++++++ src/debug/HyprCtl.cpp | 10 +++++++--- src/meson.build | 6 +++--- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cbd8b0a..7e2a1fe6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,8 +104,14 @@ find_package(OpenGL REQUIRED COMPONENTS ${GLES_VERSION}) pkg_check_modules(hyprctl_deps REQUIRED IMPORTED_TARGET hyprutils>=0.2.4) pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.5) +pkg_check_modules(hyprlang_dep REQUIRED IMPORTED_TARGET hyprlang>=0.3.2) +pkg_check_modules(hyprcursor_dep REQUIRED IMPORTED_TARGET hyprcursor>=0.1.7) +pkg_check_modules(hyprutils_dep REQUIRED IMPORTED_TARGET hyprutils>=0.2.3) add_compile_definitions(AQUAMARINE_VERSION="${aquamarine_dep_VERSION}") +add_compile_definitions(HYPRLANG_VERSION="${hyprlang_dep_VERSION}") +add_compile_definitions(HYPRUTILS_VERSION="${hyprutils_dep_VERSION}") +add_compile_definitions(HYPRCURSOR_VERSION="${hyprcursor_dep_VERSION}") pkg_check_modules( deps @@ -123,10 +129,7 @@ pkg_check_modules( libdrm libinput gbm - gio-2.0 - hyprlang>=0.3.2 - hyprcursor>=0.1.7 - hyprutils>=0.2.3) + gio-2.0) find_package(hyprwayland-scanner 0.3.10 REQUIRED) @@ -244,7 +247,7 @@ target_precompile_headers(Hyprland PRIVATE message(STATUS "Setting link libraries") -target_link_libraries(Hyprland rt PkgConfig::aquamarine_dep PkgConfig::deps) +target_link_libraries(Hyprland rt PkgConfig::aquamarine_dep PkgConfig::hyprlang_dep PkgConfig::hyprutils_dep PkgConfig::hyprcursor_dep PkgConfig::deps) if(udis_dep_FOUND) target_link_libraries(Hyprland PkgConfig::udis_dep) else() diff --git a/hyprpm/CMakeLists.txt b/hyprpm/CMakeLists.txt index 65935638..22cb8caa 100644 --- a/hyprpm/CMakeLists.txt +++ b/hyprpm/CMakeLists.txt @@ -9,11 +9,11 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") set(CMAKE_CXX_STANDARD 23) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.2.4) +pkg_check_modules(hyprpm_deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.2.4) add_executable(hyprpm ${SRCFILES}) -target_link_libraries(hyprpm PUBLIC PkgConfig::deps) +target_link_libraries(hyprpm PUBLIC PkgConfig::hyprpm_deps) # binary install(TARGETS hyprpm) diff --git a/meson.build b/meson.build index d825f184..39a5a6d0 100644 --- a/meson.build +++ b/meson.build @@ -32,7 +32,13 @@ if cpp_compiler.check_header('execinfo.h') endif aquamarine = dependency('aquamarine', version: '>=0.4.5') +hyprcursor = dependency('hyprcursor', version: '>=0.1.7') +hyprlang = dependency('hyprlang', version: '>= 0.3.2') +hyprutils = dependency('hyprutils', version: '>= 0.2.3') add_project_arguments(['-DAQUAMARINE_VERSION="@0@"'.format(aquamarine.version())], language: 'cpp') +add_project_arguments(['-DHYPRCURSOR_VERSION="@0@"'.format(hyprcursor.version())], language: 'cpp') +add_project_arguments(['-DHYPRLANG_VERSION="@0@"'.format(hyprlang.version())], language: 'cpp') +add_project_arguments(['-DHYPRUTILS_VERSION="@0@"'.format(hyprutils.version())], language: 'cpp') xcb_dep = dependency('xcb', required: get_option('xwayland')) xcb_composite_dep = dependency('xcb-composite', required: get_option('xwayland')) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 11c16f0e..6b62ec8d 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -875,8 +875,9 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = std::format("Hyprland {} built from branch {} at commit {} {} ({}).\n" "Date: {}\n" "Tag: {}, commits: {}\n" - "built against aquamarine {}\n\n\n", - HYPRLAND_VERSION, GIT_BRANCH, GIT_COMMIT_HASH, GIT_DIRTY, commitMsg, GIT_COMMIT_DATE, GIT_TAG, GIT_COMMITS, AQUAMARINE_VERSION); + "built against:\n aquamarine {}\n hyprlang {}\n hyprutils {}\n hyprcursor {}\n\n\n", + HYPRLAND_VERSION, GIT_BRANCH, GIT_COMMIT_HASH, GIT_DIRTY, commitMsg, GIT_COMMIT_DATE, GIT_TAG, GIT_COMMITS, AQUAMARINE_VERSION, + HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION); #if (!defined(LEGACY_RENDERER) && !defined(ISDEBUG) && !defined(NO_XWAYLAND)) result += "no flags were set\n"; @@ -905,9 +906,12 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { "tag": "{}", "commits": "{}", "buildAquamarine": "{}", + "buildHyprlang": "{}", + "buildHyprutils": "{}", + "buildHyprcursor": "{}", "flags": [)#", GIT_BRANCH, GIT_COMMIT_HASH, HYPRLAND_VERSION, (strcmp(GIT_DIRTY, "dirty") == 0 ? "true" : "false"), escapeJSONStrings(commitMsg), GIT_COMMIT_DATE, GIT_TAG, - GIT_COMMITS, AQUAMARINE_VERSION); + GIT_COMMITS, AQUAMARINE_VERSION, HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION); #ifdef LEGACY_RENDERER result += "\"legacyrenderer\","; diff --git a/src/meson.build b/src/meson.build index 2dbe2f44..61ca06d5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -9,14 +9,14 @@ executable( dependencies: [ server_protos, aquamarine, + hyprcursor, + hyprlang, + hyprutils, dependency('gbm'), dependency('xcursor'), dependency('wayland-server'), dependency('wayland-client'), dependency('cairo'), - dependency('hyprcursor', version: '>=0.1.7'), - dependency('hyprlang', version: '>= 0.3.2'), - dependency('hyprutils', version: '>= 0.2.3'), dependency('libdrm'), dependency('egl'), dependency('xkbcommon'), From 320144ae7288fe23686935ebb235d9fe0c900862 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:58:24 +0000 Subject: [PATCH 0077/1566] core: move colorspace handling to oklab (#8635) * Meson: add hyprgraphics * Nix: add hyprgraphics * CI/setup_base: get hyprgraphics-git --------- Co-authored-by: Mihai Fufezan --- .github/actions/setup_base/action.yml | 7 + CMakeLists.txt | 4 +- flake.lock | 27 +++ flake.nix | 7 + meson.build | 2 + nix/default.nix | 2 + nix/overlays.nix | 1 + src/Compositor.cpp | 10 +- src/config/ConfigDataValues.hpp | 22 ++- src/config/ConfigManager.cpp | 23 +-- src/config/ConfigManager.hpp | 2 +- src/debug/HyprCtl.cpp | 15 +- src/debug/HyprNotificationOverlay.cpp | 4 +- src/debug/HyprNotificationOverlay.hpp | 18 +- src/desktop/Window.cpp | 4 +- src/desktop/Window.hpp | 2 +- src/helpers/AnimatedVariable.hpp | 4 +- src/helpers/Color.cpp | 56 +++++-- src/helpers/Color.hpp | 48 ++++-- src/hyprerror/HyprError.cpp | 6 +- src/hyprerror/HyprError.hpp | 4 +- src/managers/AnimationManager.cpp | 55 +++++- src/managers/AnimationManager.hpp | 4 +- src/managers/KeybindManager.cpp | 2 +- src/managers/PointerManager.cpp | 2 +- src/meson.build | 1 + src/plugins/PluginAPI.cpp | 4 +- src/plugins/PluginAPI.hpp | 4 +- src/protocols/SinglePixel.cpp | 8 +- src/protocols/SinglePixel.hpp | 4 +- src/protocols/ToplevelExport.cpp | 4 +- src/render/OpenGL.cpp | 157 +++++++++++++++--- src/render/OpenGL.hpp | 13 +- src/render/Renderer.cpp | 20 +-- src/render/Shader.hpp | 10 +- .../decorations/CHyprBorderDecoration.cpp | 11 +- .../decorations/CHyprDropShadowDecoration.cpp | 10 +- .../decorations/CHyprDropShadowDecoration.hpp | 2 +- .../decorations/CHyprGroupBarDecoration.cpp | 24 +-- src/render/shaders/Border.hpp | 62 ++++++- 40 files changed, 492 insertions(+), 173 deletions(-) diff --git a/.github/actions/setup_base/action.yml b/.github/actions/setup_base/action.yml index 26660ce6..e22f514e 100644 --- a/.github/actions/setup_base/action.yml +++ b/.github/actions/setup_base/action.yml @@ -33,7 +33,9 @@ runs: libfontenc \ libglvnd \ libinput \ + libjxl \ libliftoff \ + libwebp \ libxcursor \ libxcvt \ libxfont2 \ @@ -69,6 +71,11 @@ runs: cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` cmake --install build + - name: Get hyprgraphics-git + shell: bash + run: | + git clone https://github.com/hyprwm/hyprgraphics && cd hyprgraphics && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprgraphics && cmake --install build + - name: Get hyprutils-git shell: bash run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2a1fe6..aa0d4b03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,11 +107,13 @@ pkg_check_modules(aquamarine_dep REQUIRED IMPORTED_TARGET aquamarine>=0.4.5) pkg_check_modules(hyprlang_dep REQUIRED IMPORTED_TARGET hyprlang>=0.3.2) pkg_check_modules(hyprcursor_dep REQUIRED IMPORTED_TARGET hyprcursor>=0.1.7) pkg_check_modules(hyprutils_dep REQUIRED IMPORTED_TARGET hyprutils>=0.2.3) +pkg_check_modules(hyprgraphics_dep REQUIRED IMPORTED_TARGET hyprgraphics>=0.1.1) add_compile_definitions(AQUAMARINE_VERSION="${aquamarine_dep_VERSION}") add_compile_definitions(HYPRLANG_VERSION="${hyprlang_dep_VERSION}") add_compile_definitions(HYPRUTILS_VERSION="${hyprutils_dep_VERSION}") add_compile_definitions(HYPRCURSOR_VERSION="${hyprcursor_dep_VERSION}") +add_compile_definitions(HYPRGRAPHICS_VERSION="${hyprgraphics_dep_VERSION}") pkg_check_modules( deps @@ -247,7 +249,7 @@ target_precompile_headers(Hyprland PRIVATE message(STATUS "Setting link libraries") -target_link_libraries(Hyprland rt PkgConfig::aquamarine_dep PkgConfig::hyprlang_dep PkgConfig::hyprutils_dep PkgConfig::hyprcursor_dep PkgConfig::deps) +target_link_libraries(Hyprland rt PkgConfig::aquamarine_dep PkgConfig::hyprlang_dep PkgConfig::hyprutils_dep PkgConfig::hyprcursor_dep PkgConfig::hyprgraphics_dep PkgConfig::deps) if(udis_dep_FOUND) target_link_libraries(Hyprland PkgConfig::udis_dep) else() diff --git a/flake.lock b/flake.lock index 0db2ee60..23bd37a9 100644 --- a/flake.lock +++ b/flake.lock @@ -92,6 +92,32 @@ "type": "github" } }, + "hyprgraphics": { + "inputs": { + "hyprutils": [ + "hyprutils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1733248371, + "narHash": "sha256-FFLJzFTyNhS7tBEEECx0B8Ye/bpmxhFVEKlECgMLc6c=", + "owner": "hyprwm", + "repo": "hyprgraphics", + "rev": "cc95e5babc6065bc3ab4cd195429a9900836ef13", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprgraphics", + "type": "github" + } + }, "hyprland-protocols": { "inputs": { "nixpkgs": [ @@ -246,6 +272,7 @@ "inputs": { "aquamarine": "aquamarine", "hyprcursor": "hyprcursor", + "hyprgraphics": "hyprgraphics", "hyprland-protocols": "hyprland-protocols", "hyprlang": "hyprlang", "hyprutils": "hyprutils", diff --git a/flake.nix b/flake.nix index e3419ef8..f26f1c31 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,13 @@ inputs.hyprlang.follows = "hyprlang"; }; + hyprgraphics = { + url = "github:hyprwm/hyprgraphics"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; + inputs.hyprutils.follows = "hyprutils"; + }; + hyprland-protocols = { url = "github:hyprwm/hyprland-protocols"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/meson.build b/meson.build index 39a5a6d0..c46b199c 100644 --- a/meson.build +++ b/meson.build @@ -33,10 +33,12 @@ endif aquamarine = dependency('aquamarine', version: '>=0.4.5') hyprcursor = dependency('hyprcursor', version: '>=0.1.7') +hyprgraphics = dependency('hyprgraphics', version: '>= 0.1.1') hyprlang = dependency('hyprlang', version: '>= 0.3.2') hyprutils = dependency('hyprutils', version: '>= 0.2.3') add_project_arguments(['-DAQUAMARINE_VERSION="@0@"'.format(aquamarine.version())], language: 'cpp') add_project_arguments(['-DHYPRCURSOR_VERSION="@0@"'.format(hyprcursor.version())], language: 'cpp') +add_project_arguments(['-DHYPRGRAPHICS_VERSION="@0@"'.format(hyprgraphics.version())], language: 'cpp') add_project_arguments(['-DHYPRLANG_VERSION="@0@"'.format(hyprlang.version())], language: 'cpp') add_project_arguments(['-DHYPRUTILS_VERSION="@0@"'.format(hyprutils.version())], language: 'cpp') diff --git a/nix/default.nix b/nix/default.nix index 69174d4d..dbe4879e 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -12,6 +12,7 @@ cairo, git, hyprcursor, + hyprgraphics, hyprland-protocols, hyprlang, hyprutils, @@ -113,6 +114,7 @@ in cairo git hyprcursor + hyprgraphics hyprland-protocols hyprlang hyprutils diff --git a/nix/overlays.nix b/nix/overlays.nix index a7106315..c2103f31 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -22,6 +22,7 @@ in { # Dependencies inputs.aquamarine.overlays.default inputs.hyprcursor.overlays.default + inputs.hyprgraphics.overlays.default inputs.hyprland-protocols.overlays.default inputs.hyprlang.overlays.default inputs.hyprutils.overlays.default diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 53eaa467..3573996d 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1873,11 +1873,11 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) { // shadow if (!pWindow->isX11OverrideRedirect() && !pWindow->m_bX11DoesntWantBorders) { if (pWindow == m_pLastWindow) - pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL); + pWindow->m_cRealShadowColor = CHyprColor(*PSHADOWCOL); else - pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT64_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL); + pWindow->m_cRealShadowColor = CHyprColor(*PSHADOWCOLINACTIVE != INT64_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL); } else { - pWindow->m_cRealShadowColor.setValueAndWarp(CColor(0, 0, 0, 0)); // no shadow + pWindow->m_cRealShadowColor.setValueAndWarp(CHyprColor(0, 0, 0, 0)); // no shadow } pWindow->updateWindowDecos(); @@ -2608,14 +2608,14 @@ void CCompositor::performUserChecks() { g_pHyprNotificationOverlay->addNotification( std::format("Your XDG_CURRENT_DESKTOP environment seems to be managed externally, and the current value is {}.\nThis might cause issues unless it's intentional.", CURRENT_DESKTOP_ENV ? CURRENT_DESKTOP_ENV : "unset"), - CColor{}, 15000, ICON_WARNING); + CHyprColor{}, 15000, ICON_WARNING); } } if (g_pHyprOpenGL->failedAssetsNo > 0) { g_pHyprNotificationOverlay->addNotification(std::format("Hyprland failed to load {} essential asset{}, blame your distro's packager for doing a bad job at packaging!", g_pHyprOpenGL->failedAssetsNo, g_pHyprOpenGL->failedAssetsNo > 1 ? "s" : ""), - CColor{1.0, 0.1, 0.1, 1.0}, 15000, ICON_ERROR); + CHyprColor{1.0, 0.1, 0.1, 1.0}, 15000, ICON_ERROR); } } diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 37c9fc92..212f26fa 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -21,8 +21,9 @@ class ICustomConfigValueData { class CGradientValueData : public ICustomConfigValueData { public: CGradientValueData() {}; - CGradientValueData(CColor col) { + CGradientValueData(CHyprColor col) { m_vColors.push_back(col); + updateColorsOk(); }; virtual ~CGradientValueData() {}; @@ -30,14 +31,29 @@ class CGradientValueData : public ICustomConfigValueData { return CVD_TYPE_GRADIENT; } - void reset(CColor col) { + void reset(CHyprColor col) { m_vColors.clear(); m_vColors.emplace_back(col); m_fAngle = 0; + updateColorsOk(); + } + + void updateColorsOk() { + m_vColorsOkLabA.clear(); + for (auto& c : m_vColors) { + const auto OKLAB = c.asOkLab(); + m_vColorsOkLabA.emplace_back(OKLAB.l); + m_vColorsOkLabA.emplace_back(OKLAB.a); + m_vColorsOkLabA.emplace_back(OKLAB.b); + m_vColorsOkLabA.emplace_back(c.a); + } } /* Vector containing the colors */ - std::vector m_vColors; + std::vector m_vColors; + + /* Vector containing pure colors for shoving into opengl */ + std::vector m_vColorsOkLabA; /* Float corresponding to the angle (rad) */ float m_fAngle = 0; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 07de8c24..820844eb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -70,7 +70,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** const auto COL = configStringToInt(var); if (!COL) throw std::runtime_error(std::format("failed to parse {} as a color", var)); - DATA->m_vColors.push_back(CColor(COL.value())); + DATA->m_vColors.push_back(CHyprColor(COL.value())); } catch (std::exception& e) { Debug::log(WARN, "Error parsing gradient {}", V); parseError = "Error parsing gradient " + V + ": " + e.what(); @@ -85,6 +85,8 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** DATA->m_vColors.push_back(0); // transparent } + DATA->updateColorsOk(); + Hyprlang::CParseResult result; if (!parseError.empty()) result.setError(parseError.c_str()); @@ -676,7 +678,7 @@ CConfigManager::CConfigManager() { Debug::disableTime = reinterpret_cast(m_pConfig->getConfigValuePtr("debug:disable_time")->getDataStaticPtr()); if (ERR.has_value()) - g_pHyprError->queueCreate(ERR.value(), CColor{1.0, 0.1, 0.1, 1.0}); + g_pHyprError->queueCreate(ERR.value(), CHyprColor{1.0, 0.1, 0.1, 1.0}); } std::optional CConfigManager::generateConfig(std::string configPath) { @@ -883,14 +885,14 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { m_szConfigErrors = ""; if (result.error && !std::any_cast(m_pConfig->getConfigValue("debug:suppress_errors"))) - g_pHyprError->queueCreate(result.getError(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + g_pHyprError->queueCreate(result.getError(), CHyprColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); else if (std::any_cast(m_pConfig->getConfigValue("autogenerated")) == 1) g_pHyprError->queueCreate( "Warning: You're using an autogenerated config! (config file: " + getMainConfigPath() + " )\nSUPER+Q -> kitty (if it doesn't launch, make sure it's installed or choose a different terminal in the config)\nSUPER+M -> exit Hyprland", - CColor(1.0, 1.0, 70.0 / 255.0, 1.0)); + CHyprColor(1.0, 1.0, 70.0 / 255.0, 1.0)); else if (*PENABLEEXPLICIT != prevEnabledExplicit) - g_pHyprError->queueCreate("Warning: You changed the render:explicit_sync option, this requires you to restart Hyprland.", CColor(0.9, 0.76, 0.221, 1.0)); + g_pHyprError->queueCreate("Warning: You changed the render:explicit_sync option, this requires you to restart Hyprland.", CHyprColor(0.9, 0.76, 0.221, 1.0)); else g_pHyprError->destroy(); @@ -948,7 +950,8 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { // manual crash if (std::any_cast(m_pConfig->getConfigValue("debug:manual_crash")) && !m_bManualCrashInitiated) { m_bManualCrashInitiated = true; - g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, ICON_INFO); + g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CHyprColor(0), 5000, + ICON_INFO); } else if (m_bManualCrashInitiated && !std::any_cast(m_pConfig->getConfigValue("debug:manual_crash"))) { // cowabunga it is g_pHyprRenderer->initiateManualCrash(); @@ -1015,7 +1018,7 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: if (COMMAND.contains("explicit")) { if (*PENABLEEXPLICIT != prevEnabledExplicit) - g_pHyprError->queueCreate("Warning: You changed the render:explicit_sync option, this requires you to restart Hyprland.", CColor(0.9, 0.76, 0.221, 1.0)); + g_pHyprError->queueCreate("Warning: You changed the render:explicit_sync option, this requires you to restart Hyprland.", CHyprColor(0.9, 0.76, 0.221, 1.0)); else g_pHyprError->destroy(); } @@ -1027,7 +1030,7 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std:: if (std::any_cast(m_pConfig->getConfigValue("debug:manual_crash")) && !m_bManualCrashInitiated) { m_bManualCrashInitiated = true; if (g_pHyprNotificationOverlay) { - g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, + g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CHyprColor(0), 5000, ICON_INFO); } } else if (m_bManualCrashInitiated && !std::any_cast(m_pConfig->getConfigValue("debug:manual_crash"))) { @@ -1671,7 +1674,7 @@ SAnimationPropertyConfig* CConfigManager::getAnimationPropertyConfig(const std:: } void CConfigManager::addParseError(const std::string& err) { - g_pHyprError->queueCreate(err + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + g_pHyprError->queueCreate(err + "\nHyprland may not work correctly.", CHyprColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); } PHLMONITOR CConfigManager::getBoundMonitorForWS(const std::string& wsname) { @@ -1716,7 +1719,7 @@ void CConfigManager::handlePluginLoads() { error << "\n" << path; } - g_pHyprError->queueCreate(error.str(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + g_pHyprError->queueCreate(error.str(), CHyprColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); } if (pluginsChanged) { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 88b74b6e..a3b86e69 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -119,7 +119,7 @@ struct SConfigOptionDescription { }; struct SColorData { - CColor color; + CHyprColor color; }; struct SChoiceData { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 6b62ec8d..74b2a3a1 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -875,9 +875,9 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = std::format("Hyprland {} built from branch {} at commit {} {} ({}).\n" "Date: {}\n" "Tag: {}, commits: {}\n" - "built against:\n aquamarine {}\n hyprlang {}\n hyprutils {}\n hyprcursor {}\n\n\n", + "built against:\n aquamarine {}\n hyprlang {}\n hyprutils {}\n hyprcursor {}\n hyprgraphics {}\n\n\n", HYPRLAND_VERSION, GIT_BRANCH, GIT_COMMIT_HASH, GIT_DIRTY, commitMsg, GIT_COMMIT_DATE, GIT_TAG, GIT_COMMITS, AQUAMARINE_VERSION, - HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION); + HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION, HYPRGRAPHICS_VERSION); #if (!defined(LEGACY_RENDERER) && !defined(ISDEBUG) && !defined(NO_XWAYLAND)) result += "no flags were set\n"; @@ -909,9 +909,10 @@ std::string versionRequest(eHyprCtlOutputFormat format, std::string request) { "buildHyprlang": "{}", "buildHyprutils": "{}", "buildHyprcursor": "{}", + "buildHyprgraphics": "{}", "flags": [)#", GIT_BRANCH, GIT_COMMIT_HASH, HYPRLAND_VERSION, (strcmp(GIT_DIRTY, "dirty") == 0 ? "true" : "false"), escapeJSONStrings(commitMsg), GIT_COMMIT_DATE, GIT_TAG, - GIT_COMMITS, AQUAMARINE_VERSION, HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION); + GIT_COMMITS, AQUAMARINE_VERSION, HYPRLANG_VERSION, HYPRUTILS_VERSION, HYPRCURSOR_VERSION, HYPRGRAPHICS_VERSION); #ifdef LEGACY_RENDERER result += "\"legacyrenderer\","; @@ -1290,7 +1291,7 @@ std::string dispatchSeterror(eHyprCtlOutputFormat format, std::string request) { return "ok"; } - const CColor COLOR = configStringToInt(vars[1]).value_or(0); + const CHyprColor COLOR = configStringToInt(vars[1]).value_or(0); for (size_t i = 2; i < vars.size(); ++i) errorMessage += vars[i] + ' '; @@ -1545,10 +1546,10 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { const auto COLOR_RESULT = configStringToInt(vars[3]); if (!COLOR_RESULT) return "invalid arg 3"; - CColor color = *COLOR_RESULT; + CHyprColor color = *COLOR_RESULT; - size_t msgidx = 4; - float fontsize = 13.f; + size_t msgidx = 4; + float fontsize = 13.f; if (vars[msgidx].length() > 9 && vars[msgidx].compare(0, 9, "fontsize:") == 0) { const auto FONTSIZE = vars[msgidx].substr(9); diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index e46999e6..482db541 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -34,11 +34,11 @@ CHyprNotificationOverlay::~CHyprNotificationOverlay() { cairo_surface_destroy(m_pCairoSurface); } -void CHyprNotificationOverlay::addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon, const float fontSize) { +void CHyprNotificationOverlay::addNotification(const std::string& text, const CHyprColor& color, const float timeMs, const eIcons icon, const float fontSize) { const auto PNOTIF = m_dNotifications.emplace_back(std::make_unique()).get(); PNOTIF->text = icon != eIcons::ICON_NONE ? " " + text /* tiny bit of padding otherwise icon touches text */ : text; - PNOTIF->color = color == CColor(0) ? ICONS_COLORS[icon] : color; + PNOTIF->color = color == CHyprColor(0) ? ICONS_COLORS[icon] : color; PNOTIF->started.reset(); PNOTIF->timeMs = timeMs; PNOTIF->icon = icon; diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp index 0bba8b04..67603e49 100644 --- a/src/debug/HyprNotificationOverlay.hpp +++ b/src/debug/HyprNotificationOverlay.hpp @@ -19,17 +19,17 @@ enum eIconBackend { static const std::array, 3 /* backends */> ICONS_ARRAY = { std::array{"[!]", "[i]", "[Hint]", "[Err]", "[?]", "[ok]", ""}, std::array{"", "", "", "", "", "󰸞", ""}, std::array{"", "", "", "", "", ""}}; -static const std::array ICONS_COLORS = {CColor{255.0 / 255.0, 204 / 255.0, 102 / 255.0, 1.0}, - CColor{128 / 255.0, 255 / 255.0, 255 / 255.0, 1.0}, - CColor{179 / 255.0, 255 / 255.0, 204 / 255.0, 1.0}, - CColor{255 / 255.0, 77 / 255.0, 77 / 255.0, 1.0}, - CColor{255 / 255.0, 204 / 255.0, 153 / 255.0, 1.0}, - CColor{128 / 255.0, 255 / 255.0, 128 / 255.0, 1.0}, - CColor{0, 0, 0, 1.0}}; +static const std::array ICONS_COLORS = {CHyprColor{255.0 / 255.0, 204 / 255.0, 102 / 255.0, 1.0}, + CHyprColor{128 / 255.0, 255 / 255.0, 255 / 255.0, 1.0}, + CHyprColor{179 / 255.0, 255 / 255.0, 204 / 255.0, 1.0}, + CHyprColor{255 / 255.0, 77 / 255.0, 77 / 255.0, 1.0}, + CHyprColor{255 / 255.0, 204 / 255.0, 153 / 255.0, 1.0}, + CHyprColor{128 / 255.0, 255 / 255.0, 128 / 255.0, 1.0}, + CHyprColor{0, 0, 0, 1.0}}; struct SNotification { std::string text = ""; - CColor color; + CHyprColor color; CTimer started; float timeMs = 0; eIcons icon = ICON_NONE; @@ -42,7 +42,7 @@ class CHyprNotificationOverlay { ~CHyprNotificationOverlay(); void draw(PHLMONITOR pMonitor); - void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f); + void addNotification(const std::string& text, const CHyprColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f); void dismissNotifications(const int amount); bool hasAny(); diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 12e81b76..b015d61f 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -674,8 +674,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { // Basic form has only two colors, everything else can be parsed as a gradient if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) { - m_sWindowData.activeBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[0]).value_or(0))), priority); - m_sWindowData.inactiveBorderColor = CWindowOverridableVar(CGradientValueData(CColor(configStringToInt(colorsAndAngles[1]).value_or(0))), priority); + m_sWindowData.activeBorderColor = CWindowOverridableVar(CGradientValueData(CHyprColor(configStringToInt(colorsAndAngles[0]).value_or(0))), priority); + m_sWindowData.inactiveBorderColor = CWindowOverridableVar(CGradientValueData(CHyprColor(configStringToInt(colorsAndAngles[1]).value_or(0))), priority); return; } diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index 5dd59437..672ff6ec 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -356,7 +356,7 @@ class CWindow { CAnimatedVariable m_fActiveInactiveAlpha; // animated shadow color - CAnimatedVariable m_cRealShadowColor; + CAnimatedVariable m_cRealShadowColor; // animated tint CAnimatedVariable m_fDimPercent; diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 6310afb7..7cea72a0 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -34,7 +34,7 @@ struct typeToANIMATEDVARTYPE_t { }; template <> -struct typeToANIMATEDVARTYPE_t { +struct typeToANIMATEDVARTYPE_t { static constexpr ANIMATEDVARTYPE value = AVARTYPE_COLOR; }; @@ -63,7 +63,7 @@ concept OneOf = (... or std::same_as); // This is mainly to get better errors if we put a type that's not supported // Otherwise template errors are ugly template -concept Animable = OneOf; +concept Animable = OneOf; class CBaseAnimatedVariable { public: diff --git a/src/helpers/Color.cpp b/src/helpers/Color.cpp index f9a207bb..fe217c0f 100644 --- a/src/helpers/Color.cpp +++ b/src/helpers/Color.cpp @@ -5,22 +5,52 @@ #define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0) #define BLUE(c) ((double)(((c)) & 0xff) / 255.0) -CColor::CColor() {} +CHyprColor::CHyprColor() {} -CColor::CColor(float r, float g, float b, float a) { - this->r = r; - this->g = g; - this->b = b; - this->a = a; +CHyprColor::CHyprColor(float r_, float g_, float b_, float a_) { + r = r_; + g = g_; + b = b_; + a = a_; + + okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{r, g, b}).asOkLab(); } -CColor::CColor(uint64_t hex) { - this->r = RED(hex); - this->g = GREEN(hex); - this->b = BLUE(hex); - this->a = ALPHA(hex); +CHyprColor::CHyprColor(uint64_t hex) { + r = RED(hex); + g = GREEN(hex); + b = BLUE(hex); + a = ALPHA(hex); + + okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{r, g, b}).asOkLab(); } -uint32_t CColor::getAsHex() const { +CHyprColor::CHyprColor(const Hyprgraphics::CColor& color, float a_) { + const auto SRGB = color.asRgb(); + r = SRGB.r; + g = SRGB.g; + b = SRGB.b; + a = a_; + + okLab = color.asOkLab(); +} + +uint32_t CHyprColor::getAsHex() const { return (uint32_t)(a * 255.f) * 0x1000000 + (uint32_t)(r * 255.f) * 0x10000 + (uint32_t)(g * 255.f) * 0x100 + (uint32_t)(b * 255.f) * 0x1; -} \ No newline at end of file +} + +Hyprgraphics::CColor::SSRGB CHyprColor::asRGB() const { + return {r, g, b}; +} + +Hyprgraphics::CColor::SOkLab CHyprColor::asOkLab() const { + return okLab; +} + +Hyprgraphics::CColor::SHSL CHyprColor::asHSL() const { + return Hyprgraphics::CColor(okLab).asHSL(); +} + +CHyprColor CHyprColor::stripA() const { + return {r, g, b, 1.F}; +} diff --git a/src/helpers/Color.hpp b/src/helpers/Color.hpp index 32ed39ee..cf7f7943 100644 --- a/src/helpers/Color.hpp +++ b/src/helpers/Color.hpp @@ -1,35 +1,47 @@ #pragma once #include +#include +#include "../debug/Log.hpp" +#include "../macros.hpp" -class CColor { +class CHyprColor { public: - CColor(); - CColor(float r, float g, float b, float a); - CColor(uint64_t); - - float r = 0, g = 0, b = 0, a = 1.f; + CHyprColor(); + CHyprColor(float r, float g, float b, float a); + CHyprColor(const Hyprgraphics::CColor& col, float a); + CHyprColor(uint64_t); // AR32 - uint32_t getAsHex() const; + uint32_t getAsHex() const; + Hyprgraphics::CColor::SSRGB asRGB() const; + Hyprgraphics::CColor::SOkLab asOkLab() const; + Hyprgraphics::CColor::SHSL asHSL() const; + CHyprColor stripA() const; - CColor operator-(const CColor& c2) const { - return CColor(r - c2.r, g - c2.g, b - c2.b, a - c2.a); + // + bool operator==(const CHyprColor& c2) const { + return c2.r == r && c2.g == g && c2.b == b && c2.a == a; } - CColor operator+(const CColor& c2) const { - return CColor(r + c2.r, g + c2.g, b + c2.b, a + c2.a); + // stubs for the AnimationMgr + CHyprColor operator-(const CHyprColor& c2) const { + RASSERT(false, "CHyprColor: - is a STUB"); + return {}; } - CColor operator*(const float& v) const { - return CColor(r * v, g * v, b * v, a * v); + CHyprColor operator+(const CHyprColor& c2) const { + RASSERT(false, "CHyprColor: + is a STUB"); + return {}; } - bool operator==(const CColor& c2) const { - return r == c2.r && g == c2.g && b == c2.b && a == c2.a; + CHyprColor operator*(const float& c2) const { + RASSERT(false, "CHyprColor: * is a STUB"); + return {}; } - CColor stripA() const { - return {r, g, b, 1}; - } + double r = 0, g = 0, b = 0, a = 0; + + private: + Hyprgraphics::CColor::SOkLab okLab; // cache for the OkLab representation }; diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 4761346e..74a3030c 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -33,7 +33,7 @@ CHyprError::~CHyprError() { m_fFadeOpacity.unregister(); } -void CHyprError::queueCreate(std::string message, const CColor& color) { +void CHyprError::queueCreate(std::string message, const CHyprColor& color) { m_szQueued = message; m_cQueued = color; } @@ -98,7 +98,7 @@ void CHyprError::createQueued() { cairo_stroke(CAIRO); // draw the text with a common font - const CColor textColor = CColor(0.9, 0.9, 0.9, 1.0); + const CHyprColor textColor = CHyprColor(0.9, 0.9, 0.9, 1.0); cairo_set_source_rgba(CAIRO, textColor.r, textColor.g, textColor.b, textColor.a); static auto fontFamily = CConfigValue("misc:font_family"); @@ -160,7 +160,7 @@ void CHyprError::createQueued() { m_bIsCreated = true; m_szQueued = ""; - m_cQueued = CColor(); + m_cQueued = CHyprColor(); g_pHyprRenderer->damageMonitor(PMONITOR); diff --git a/src/hyprerror/HyprError.hpp b/src/hyprerror/HyprError.hpp index a553614c..042dccd0 100644 --- a/src/hyprerror/HyprError.hpp +++ b/src/hyprerror/HyprError.hpp @@ -11,7 +11,7 @@ class CHyprError { CHyprError(); ~CHyprError(); - void queueCreate(std::string message, const CColor& color); + void queueCreate(std::string message, const CHyprColor& color); void draw(); void destroy(); @@ -21,7 +21,7 @@ class CHyprError { private: void createQueued(); std::string m_szQueued = ""; - CColor m_cQueued; + CHyprColor m_cQueued; bool m_bQueuedDestroy = false; bool m_bIsCreated = false; SP m_pTexture; diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 68dbdda1..7525bf6b 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -8,6 +8,8 @@ #include "eventLoop/EventLoopManager.hpp" #include "../helpers/varlist/VarList.hpp" +#include + int wlTick(SP self, void* data) { if (g_pAnimationManager) g_pAnimationManager->onTicked(); @@ -154,7 +156,7 @@ void CAnimationManager::tick() { // beziers are with a switch unforto // TODO: maybe do something cleaner - auto updateVariable = [&](CAnimatedVariable& av) { + static const auto updateVariable = [&](CAnimatedVariable& av) { // for disabled anims just warp if (av.m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { av.warp(false); @@ -166,13 +168,50 @@ void CAnimationManager::tick() { return; } - const auto DELTA = av.m_Goal - av.m_Begun; const auto BEZIER = m_mBezierCurves.find(av.m_pConfig->pValues->internalBezier); + const auto POINTY = BEZIER != m_mBezierCurves.end() ? BEZIER->second.getYForPoint(SPENT) : DEFAULTBEZIER->second.getYForPoint(SPENT); + + const auto DELTA = av.m_Goal - av.m_Begun; if (BEZIER != m_mBezierCurves.end()) - av.m_Value = av.m_Begun + DELTA * BEZIER->second.getYForPoint(SPENT); + av.m_Value = av.m_Begun + DELTA * POINTY; else - av.m_Value = av.m_Begun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + av.m_Value = av.m_Begun + DELTA * POINTY; + }; + + static const auto updateColorVariable = [&](CAnimatedVariable& av) { + // for disabled anims just warp + if (av.m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { + av.warp(false); + return; + } + + if (SPENT >= 1.f || av.m_Begun == av.m_Goal) { + av.warp(false); + return; + } + + const auto BEZIER = m_mBezierCurves.find(av.m_pConfig->pValues->internalBezier); + const auto POINTY = BEZIER != m_mBezierCurves.end() ? BEZIER->second.getYForPoint(SPENT) : DEFAULTBEZIER->second.getYForPoint(SPENT); + + // convert both to OkLab, then lerp that, and convert back. + // This is not as fast as just lerping rgb, but it's WAY more precise... + // Use the CHyprColor cache for OkLab + + const auto& L1 = av.m_Begun.asOkLab(); + const auto& L2 = av.m_Goal.asOkLab(); + + static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + (two - one) * progress; }; + + const Hyprgraphics::CColor lerped = Hyprgraphics::CColor::SOkLab{ + .l = lerp(L1.l, L2.l, POINTY), + .a = lerp(L1.a, L2.a, POINTY), + .b = lerp(L1.b, L2.b, POINTY), + }; + + av.m_Value = {lerped, lerp(av.m_Begun.a, av.m_Goal.a, POINTY)}; + + return; }; switch (av->m_Type) { @@ -187,8 +226,8 @@ void CAnimationManager::tick() { break; } case AVARTYPE_COLOR: { - auto typedAv = static_cast*>(av); - updateVariable(*typedAv); + auto typedAv = static_cast*>(av); + updateColorVariable(*typedAv); break; } default: UNREACHABLE(); @@ -272,7 +311,7 @@ bool CAnimationManager::deltaSmallToFlip(const Vector2D& a, const Vector2D& b) { return std::abs(a.x - b.x) < 0.5f && std::abs(a.y - b.y) < 0.5f; } -bool CAnimationManager::deltaSmallToFlip(const CColor& a, const CColor& b) { +bool CAnimationManager::deltaSmallToFlip(const CHyprColor& a, const CHyprColor& b) { return std::abs(a.r - b.r) < 0.5f && std::abs(a.g - b.g) < 0.5f && std::abs(a.b - b.b) < 0.5f && std::abs(a.a - b.a) < 0.5f; } @@ -288,7 +327,7 @@ bool CAnimationManager::deltazero(const float& a, const float& b) { return a == b; } -bool CAnimationManager::deltazero(const CColor& a, const CColor& b) { +bool CAnimationManager::deltazero(const CHyprColor& a, const CHyprColor& b) { return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; } diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 601a38b3..3960f261 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -39,10 +39,10 @@ class CAnimationManager { private: bool deltaSmallToFlip(const Vector2D& a, const Vector2D& b); - bool deltaSmallToFlip(const CColor& a, const CColor& b); + bool deltaSmallToFlip(const CHyprColor& a, const CHyprColor& b); bool deltaSmallToFlip(const float& a, const float& b); bool deltazero(const Vector2D& a, const Vector2D& b); - bool deltazero(const CColor& a, const CColor& b); + bool deltazero(const CHyprColor& a, const CHyprColor& b); bool deltazero(const float& a, const float& b); std::unordered_map m_mBezierCurves; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 7f10249a..cfb7453c 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -275,7 +275,7 @@ void CKeybindManager::updateXKBTranslationState() { if (!PKEYMAP) { g_pHyprError->queueCreate("[Runtime Error] Invalid keyboard layout passed. ( rules: " + RULES + ", model: " + MODEL + ", variant: " + VARIANT + ", options: " + OPTIONS + ", layout: " + LAYOUT + " )", - CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + CHyprColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); Debug::log(ERR, "[XKBTranslationState] Keyboard layout {} with variant {} (rules: {}, model: {}, options: {}) couldn't have been loaded.", rules.layout, rules.variant, rules.rules, rules.model, rules.options); diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 0580c9be..c0c190dd 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -505,7 +505,7 @@ SP CPointerManager::renderHWCursorBuffer(SPbind(); g_pHyprOpenGL->beginSimple(state->monitor.lock(), {0, 0, INT16_MAX, INT16_MAX}, RBO); - g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F}); + g_pHyprOpenGL->clear(CHyprColor{0.F, 0.F, 0.F, 0.F}); CBox xbox = {{}, Vector2D{currentCursorImage.size / currentCursorImage.scale * state->monitor->scale}.round()}; Debug::log(TRACE, "[pointer] monitor: {}, size: {}, hw buf: {}, scale: {:.2f}, monscale: {:.2f}, xbox: {}", state->monitor->szName, currentCursorImage.size, cursorSize, diff --git a/src/meson.build b/src/meson.build index 61ca06d5..754cd55a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,6 +10,7 @@ executable( server_protos, aquamarine, hyprcursor, + hyprgraphics, hyprlang, hyprutils, dependency('gbm'), diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index ef3ae06a..1a7f25ab 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -71,7 +71,7 @@ APICALL bool HyprlandAPI::reloadConfig() { return true; } -APICALL bool HyprlandAPI::addNotification(HANDLE handle, const std::string& text, const CColor& color, const float timeMs) { +APICALL bool HyprlandAPI::addNotification(HANDLE handle, const std::string& text, const CHyprColor& color, const float timeMs) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!PLUGIN) @@ -244,7 +244,7 @@ APICALL bool addNotificationV2(HANDLE handle, const std::unordered_map(iterator->second); + const auto COLOR = std::any_cast(iterator->second); // optional eIcons icon = ICON_NONE; diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index 4dcf4ba5..bd257699 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -187,7 +187,7 @@ namespace HyprlandAPI { returns: true on success. False otherwise. */ - APICALL bool addNotification(HANDLE handle, const std::string& text, const CColor& color, const float timeMs); + APICALL bool addNotification(HANDLE handle, const std::string& text, const CHyprColor& color, const float timeMs); /* Creates a trampoline function hook to an internal hl func. @@ -251,7 +251,7 @@ namespace HyprlandAPI { data has to contain: - text: std::string or const char* - time: uint64_t - - color: CColor -> CColor(0) will apply the default color for the notification icon + - color: CHyprColor -> CHyprColor(0) will apply the default color for the notification icon data may contain: - icon: eIcons diff --git a/src/protocols/SinglePixel.cpp b/src/protocols/SinglePixel.cpp index d800539d..41771ce2 100644 --- a/src/protocols/SinglePixel.cpp +++ b/src/protocols/SinglePixel.cpp @@ -2,7 +2,7 @@ #include #include "render/Renderer.hpp" -CSinglePixelBuffer::CSinglePixelBuffer(uint32_t id, wl_client* client, CColor col_) { +CSinglePixelBuffer::CSinglePixelBuffer(uint32_t id, wl_client* client, CHyprColor col_) { LOGM(LOG, "New single-pixel buffer with color 0x{:x}", col_.getAsHex()); color = col_.getAsHex(); @@ -59,7 +59,7 @@ bool CSinglePixelBuffer::good() { return resource->good(); } -CSinglePixelBufferResource::CSinglePixelBufferResource(uint32_t id, wl_client* client, CColor color) { +CSinglePixelBufferResource::CSinglePixelBufferResource(uint32_t id, wl_client* client, CHyprColor color) { buffer = makeShared(id, client, color); if (!buffer->good()) @@ -89,8 +89,8 @@ CSinglePixelBufferManagerResource::CSinglePixelBufferManagerResource(SPsetOnDestroy([this](CWpSinglePixelBufferManagerV1* r) { PROTO::singlePixel->destroyResource(this); }); resource->setCreateU32RgbaBuffer([this](CWpSinglePixelBufferManagerV1* res, uint32_t id, uint32_t r, uint32_t g, uint32_t b, uint32_t a) { - CColor color{r / (float)std::numeric_limits::max(), g / (float)std::numeric_limits::max(), b / (float)std::numeric_limits::max(), - a / (float)std::numeric_limits::max()}; + CHyprColor color{r / (float)std::numeric_limits::max(), g / (float)std::numeric_limits::max(), b / (float)std::numeric_limits::max(), + a / (float)std::numeric_limits::max()}; const auto RESOURCE = PROTO::singlePixel->m_vBuffers.emplace_back(makeShared(id, resource->client(), color)); if (!RESOURCE->good()) { diff --git a/src/protocols/SinglePixel.hpp b/src/protocols/SinglePixel.hpp index ab74825c..b20f582a 100644 --- a/src/protocols/SinglePixel.hpp +++ b/src/protocols/SinglePixel.hpp @@ -9,7 +9,7 @@ class CSinglePixelBuffer : public IHLBuffer { public: - CSinglePixelBuffer(uint32_t id, wl_client* client, CColor col); + CSinglePixelBuffer(uint32_t id, wl_client* client, CHyprColor col); virtual ~CSinglePixelBuffer(); virtual Aquamarine::eBufferCapability caps(); @@ -33,7 +33,7 @@ class CSinglePixelBuffer : public IHLBuffer { class CSinglePixelBufferResource { public: - CSinglePixelBufferResource(uint32_t id, wl_client* client, CColor color); + CSinglePixelBufferResource(uint32_t id, wl_client* client, CHyprColor color); ~CSinglePixelBufferResource(); bool good(); diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index 04c089d7..d00e9dce 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -255,7 +255,7 @@ bool CToplevelExportFrame::copyShm(timespec* now) { if (!g_pHyprRenderer->beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &outFB)) return false; - g_pHyprOpenGL->clear(CColor(0, 0, 0, 1.0)); + g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 1.0)); // render client at 0,0 g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible @@ -308,7 +308,7 @@ bool CToplevelExportFrame::copyDmabuf(timespec* now) { if (!g_pHyprRenderer->beginRender(PMONITOR, fakeDamage, RENDER_MODE_TO_BUFFER, buffer.lock())) return false; - g_pHyprOpenGL->clear(CColor(0, 0, 0, 1.0)); + g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 1.0)); g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible g_pHyprRenderer->renderWindow(pWindow, PMONITOR, now, false, RENDER_PASS_ALL, true, true); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 9c00daee..9b878317 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -566,7 +566,11 @@ void CHyprOpenGLImpl::logShaderError(const GLuint& shader, bool program) { glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog.data()); std::string errorStr(errorLog.begin(), errorLog.end()); - g_pConfigManager->addParseError((program ? "Screen shader parser: Error linking program:" : "Screen shader parser: Error compiling shader: ") + errorStr); + const auto FULLERROR = (program ? "Screen shader parser: Error linking program:" : "Screen shader parser: Error compiling shader: ") + errorStr; + + Debug::log(ERR, "Failed to link shader: {}", FULLERROR); + + g_pConfigManager->addParseError(FULLERROR); } GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string& frag, bool dynamic) { @@ -604,6 +608,8 @@ GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string return 0; } } else { + if (ok != GL_TRUE) + logShaderError(prog, true); RASSERT(ok != GL_FALSE, "createProgram() failed! GL_LINK_STATUS not OK!"); } @@ -627,6 +633,8 @@ GLuint CHyprOpenGLImpl::compileShader(const GLuint& type, std::string src, bool return 0; } } else { + if (ok != GL_TRUE) + logShaderError(shader, false); RASSERT(ok != GL_FALSE, "compileShader() failed! GL_COMPILE_STATUS not OK!"); } @@ -1114,8 +1122,12 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shBORDER1.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shBORDER1.radiusOuter = glGetUniformLocation(prog, "radiusOuter"); m_RenderData.pCurrentMonData->m_shBORDER1.gradient = glGetUniformLocation(prog, "gradient"); + m_RenderData.pCurrentMonData->m_shBORDER1.gradient2 = glGetUniformLocation(prog, "gradient2"); m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength = glGetUniformLocation(prog, "gradientLength"); + m_RenderData.pCurrentMonData->m_shBORDER1.gradient2Length = glGetUniformLocation(prog, "gradient2Length"); m_RenderData.pCurrentMonData->m_shBORDER1.angle = glGetUniformLocation(prog, "angle"); + m_RenderData.pCurrentMonData->m_shBORDER1.angle2 = glGetUniformLocation(prog, "angle2"); + m_RenderData.pCurrentMonData->m_shBORDER1.gradientLerp = glGetUniformLocation(prog, "gradientLerp"); m_RenderData.pCurrentMonData->m_shBORDER1.alpha = glGetUniformLocation(prog, "alpha"); m_RenderData.pCurrentMonData->m_bShadersInitialized = true; @@ -1167,7 +1179,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.posAttrib = glGetAttribLocation(m_sFinalScreenShader.program, "pos"); } -void CHyprOpenGLImpl::clear(const CColor& color) { +void CHyprOpenGLImpl::clear(const CHyprColor& color) { RASSERT(m_RenderData.pMonitor, "Tried to render without begin()!"); TRACY_GPU_ZONE("RenderClear"); @@ -1231,12 +1243,12 @@ void CHyprOpenGLImpl::scissor(const int x, const int y, const int w, const int h scissor(&box, transform); } -void CHyprOpenGLImpl::renderRect(CBox* box, const CColor& col, int round) { +void CHyprOpenGLImpl::renderRect(CBox* box, const CHyprColor& col, int round) { if (!m_RenderData.damage.empty()) renderRectWithDamage(box, col, &m_RenderData.damage, round); } -void CHyprOpenGLImpl::renderRectWithBlur(CBox* box, const CColor& col, int round, float blurA, bool xray) { +void CHyprOpenGLImpl::renderRectWithBlur(CBox* box, const CHyprColor& col, int round, float blurA, bool xray) { if (m_RenderData.damage.empty()) return; @@ -1258,7 +1270,7 @@ void CHyprOpenGLImpl::renderRectWithBlur(CBox* box, const CColor& col, int round glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - renderRect(box, CColor(0, 0, 0, 0), round); + renderRect(box, CHyprColor(0, 0, 0, 0), round); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_EQUAL, 1, 0xFF); @@ -1283,7 +1295,7 @@ void CHyprOpenGLImpl::renderRectWithBlur(CBox* box, const CColor& col, int round renderRectWithDamage(box, col, &m_RenderData.damage, round); } -void CHyprOpenGLImpl::renderRectWithDamage(CBox* box, const CColor& col, CRegion* damage, int round) { +void CHyprOpenGLImpl::renderRectWithDamage(CBox* box, const CHyprColor& col, CRegion* damage, int round) { 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()!"); @@ -1981,7 +1993,7 @@ void CHyprOpenGLImpl::preBlurForCurrentMonitor() { m_RenderData.pMonitor->output->state->state().drmFormat); m_RenderData.pCurrentMonData->blurFB.bind(); - clear(CColor(0, 0, 0, 0)); + clear(CHyprColor(0, 0, 0, 0)); m_bEndFrame = true; // fix transformed renderTextureInternalWithDamage(POUTFB->getTexture(), &wholeMonitor, 1, &fakeDamage, 0, false, true, false); @@ -2100,7 +2112,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(SP tex, CBox* pBox, float glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); if (USENEWOPTIMIZE && !(m_RenderData.discardMode & DISCARD_ALPHA)) - renderRect(pBox, CColor(0, 0, 0, 0), round); + renderRect(pBox, CHyprColor(0, 0, 0, 0), round); else renderTexture(tex, pBox, a, round, true, true); // discard opaque glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); @@ -2184,12 +2196,107 @@ void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, in glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBORDER1.proj, 1, GL_FALSE, glMatrix.getMatrix().data()); #endif - static_assert(sizeof(CColor) == 4 * sizeof(float)); // otherwise the line below this will fail - - glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient, grad.m_vColors.size(), (float*)grad.m_vColors.data()); - glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength, grad.m_vColors.size()); + glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient, grad.m_vColorsOkLabA.size(), (float*)grad.m_vColorsOkLabA.data()); + glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength, grad.m_vColorsOkLabA.size() / 4); glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.angle, (int)(grad.m_fAngle / (PI / 180.0)) % 360 * (PI / 180.0)); glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.alpha, a); + glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradient2Length, 0); + + CBox transformedBox = *box; + transformedBox.transform(wlTransformToHyprutils(invertTransform(m_RenderData.pMonitor->transform)), m_RenderData.pMonitor->vecTransformedSize.x, + m_RenderData.pMonitor->vecTransformedSize.y); + + const auto TOPLEFT = Vector2D(transformedBox.x, transformedBox.y); + const auto FULLSIZE = Vector2D(transformedBox.width, transformedBox.height); + + glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y); + glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y); + glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.fullSizeUntransformed, (float)box->width, (float)box->height); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.radius, round); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.radiusOuter, outerRound == -1 ? round : outerRound); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.thick, scaledBorderSize); + + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib); + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib); + + if (m_RenderData.clipBox.width != 0 && m_RenderData.clipBox.height != 0) { + CRegion damageClip{m_RenderData.clipBox.x, m_RenderData.clipBox.y, m_RenderData.clipBox.width, m_RenderData.clipBox.height}; + damageClip.intersect(m_RenderData.damage); + + if (!damageClip.empty()) { + for (auto const& RECT : damageClip.getRects()) { + scissor(&RECT); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + } + } else { + for (auto const& RECT : m_RenderData.damage.getRects()) { + scissor(&RECT); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + } + + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib); + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.texAttrib); + + blend(BLEND); +} + +void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad1, const CGradientValueData& grad2, float lerp, int round, int borderSize, float a, int outerRound) { + 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()!"); + + TRACY_GPU_ZONE("RenderBorder2"); + + if (m_RenderData.damage.empty() || (m_pCurrentWindow.lock() && m_pCurrentWindow->m_sWindowData.noBorder.valueOrDefault())) + return; + + CBox newBox = *box; + m_RenderData.renderModif.applyToBox(newBox); + + box = &newBox; + + if (borderSize < 1) + return; + + int scaledBorderSize = std::round(borderSize * m_RenderData.pMonitor->scale); + scaledBorderSize = std::round(scaledBorderSize * m_RenderData.renderModif.combinedScale()); + + // adjust box + box->x -= scaledBorderSize; + box->y -= scaledBorderSize; + box->width += 2 * scaledBorderSize; + box->height += 2 * scaledBorderSize; + + round += round == 0 ? 0 : scaledBorderSize; + + Mat3x3 matrix = m_RenderData.monitorProjection.projectBox( + newBox, wlTransformToHyprutils(invertTransform(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform)), newBox.rot); + Mat3x3 glMatrix = m_RenderData.projection.copy().multiply(matrix); + + const auto BLEND = m_bBlend; + blend(true); + + glUseProgram(m_RenderData.pCurrentMonData->m_shBORDER1.program); + +#ifndef GLES2 + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBORDER1.proj, 1, GL_TRUE, glMatrix.getMatrix().data()); +#else + glMatrix.transpose(); + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBORDER1.proj, 1, GL_FALSE, glMatrix.getMatrix().data()); +#endif + + glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient, grad1.m_vColorsOkLabA.size(), (float*)grad1.m_vColorsOkLabA.data()); + glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength, grad1.m_vColorsOkLabA.size() / 4); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.angle, (int)(grad1.m_fAngle / (PI / 180.0)) % 360 * (PI / 180.0)); + glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient2, grad2.m_vColorsOkLabA.size(), (float*)grad2.m_vColorsOkLabA.data()); + glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradient2Length, grad2.m_vColorsOkLabA.size() / 4); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.angle2, (int)(grad2.m_fAngle / (PI / 180.0)) % 360 * (PI / 180.0)); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.alpha, a); + glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.gradientLerp, lerp); CBox transformedBox = *box; transformedBox.transform(wlTransformToHyprutils(invertTransform(m_RenderData.pMonitor->transform)), m_RenderData.pMonitor->vecTransformedSize.x, @@ -2253,7 +2360,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(PHLWINDOW pWindow, CFramebuffer* pFr g_pHyprRenderer->beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, pFramebuffer); - clear(CColor(0, 0, 0, 0)); // JIC + clear(CHyprColor(0, 0, 0, 0)); // JIC timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -2272,7 +2379,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(PHLWINDOW pWindow, CFramebuffer* pFr m_RenderData.currentFB = pFramebuffer; - clear(CColor(0, 0, 0, 0)); // JIC + clear(CHyprColor(0, 0, 0, 0)); // JIC g_pHyprRenderer->renderWindow(pWindow, PMONITOR, &now, false, RENDER_PASS_ALL, true); @@ -2308,7 +2415,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(PHLWINDOW pWindow) { g_pHyprRenderer->m_bRenderingSnapshot = true; - clear(CColor(0, 0, 0, 0)); // JIC + clear(CHyprColor(0, 0, 0, 0)); // JIC timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -2322,7 +2429,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(PHLWINDOW pWindow) { const auto BLURVAL = **PBLUR; **PBLUR = 0; - clear(CColor(0, 0, 0, 0)); // JIC + clear(CHyprColor(0, 0, 0, 0)); // JIC g_pHyprRenderer->renderWindow(pWindow, PMONITOR, &now, !pWindow->m_bX11DoesntWantBorders, RENDER_PASS_ALL); @@ -2355,7 +2462,7 @@ void CHyprOpenGLImpl::makeLayerSnapshot(PHLLS pLayer) { g_pHyprRenderer->m_bRenderingSnapshot = true; - clear(CColor(0, 0, 0, 0)); // JIC + clear(CHyprColor(0, 0, 0, 0)); // JIC timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -2405,7 +2512,7 @@ void CHyprOpenGLImpl::renderSnapshot(PHLWINDOW pWindow) { if (*PDIMAROUND && pWindow->m_sWindowData.dimAround.valueOrDefault()) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * pWindow->m_fAlpha.value())); + g_pHyprOpenGL->renderRect(&monbox, CHyprColor(0, 0, 0, *PDIMAROUND * pWindow->m_fAlpha.value())); g_pHyprRenderer->damageMonitor(PMONITOR); } @@ -2449,7 +2556,7 @@ void CHyprOpenGLImpl::renderSnapshot(PHLLS pLayer) { m_bEndFrame = false; } -void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const CColor& color, float a) { +void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const CHyprColor& color, float a) { RASSERT(m_RenderData.pMonitor, "Tried to render shadow without begin()!"); RASSERT((box->width > 0 && box->height > 0), "Tried to render shadow with width/height < 0!"); RASSERT(m_pCurrentWindow.lock(), "Tried to render shadow without a window!"); @@ -2568,7 +2675,7 @@ void CHyprOpenGLImpl::renderMirrored() { .translate(-monitor->vecTransformedSize / 2.0); // clear stuff outside of mirrored area (e.g. when changing to mirrored) - clear(CColor(0, 0, 0, 0)); + clear(CHyprColor(0, 0, 0, 0)); renderTexture(PFB->getTexture(), &monbox, 1.f, 0, false, false); @@ -2583,7 +2690,7 @@ void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const const auto FONTFAMILY = *PSPLASHFONT != STRVAL_EMPTY ? *PSPLASHFONT : *FALLBACKFONT; const auto FONTSIZE = (int)(size.y / 76); - const auto COLOR = CColor(*PSPLASHCOLOR); + const auto COLOR = CHyprColor(*PSPLASHCOLOR); PangoLayout* layoutText = pango_cairo_create_layout(CAIRO); PangoFontDescription* pangoFD = pango_font_description_new(); @@ -2671,7 +2778,7 @@ SP CHyprOpenGLImpl::loadAsset(const std::string& filename) { return tex; } -SP CHyprOpenGLImpl::renderText(const std::string& text, CColor col, int pt, bool italic) { +SP CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col, int pt, bool italic) { SP tex = makeShared(); static auto FONT = CConfigValue("misc:font_family"); @@ -2804,7 +2911,7 @@ void CHyprOpenGLImpl::initAssets() { g_pCompositor->m_pAqBackend->hasSession() && g_pCompositor->m_pAqBackend->session->vt > 0 ? std::to_string(g_pCompositor->m_pAqBackend->session->vt) : "unknown"), - CColor{0.9F, 0.9F, 0.9F, 0.7F}, 20, true); + CHyprColor{0.9F, 0.9F, 0.9F, 0.7F}, 20, true); // create the default background texture { @@ -2889,7 +2996,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(PHLMONITOR pMonitor) { CRegion fakeDamage{0, 0, INT16_MAX, INT16_MAX}; blend(true); - clear(CColor{0, 0, 0, 1}); + clear(CHyprColor{0, 0, 0, 1}); // first render the background if (m_pBackgroundTexture) { @@ -2981,7 +3088,7 @@ void CHyprOpenGLImpl::restoreMatrix() { void CHyprOpenGLImpl::bindOffMain() { m_RenderData.pCurrentMonData->offMainFB.bind(); - clear(CColor(0, 0, 0, 0)); + clear(CHyprColor(0, 0, 0, 0)); m_RenderData.currentFB = &m_RenderData.pCurrentMonData->offMainFB; } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index c594a7cc..6c0632dd 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -153,15 +153,16 @@ class CHyprOpenGLImpl { void beginSimple(PHLMONITOR, const CRegion& damage, SP rb = nullptr, CFramebuffer* fb = nullptr); void end(); - void renderRect(CBox*, const CColor&, int round = 0); - void renderRectWithBlur(CBox*, const CColor&, int round = 0, float blurA = 1.f, bool xray = false); - void renderRectWithDamage(CBox*, const CColor&, CRegion* damage, int round = 0); + void renderRect(CBox*, const CHyprColor&, int round = 0); + void renderRectWithBlur(CBox*, const CHyprColor&, int round = 0, float blurA = 1.f, bool xray = false); + void renderRectWithDamage(CBox*, const CHyprColor&, CRegion* damage, int round = 0); void renderTexture(SP, CBox*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false); void renderTextureWithDamage(SP, CBox*, CRegion* damage, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false, SP waitTimeline = nullptr, uint64_t waitPoint = 0); void renderTextureWithBlur(SP, CBox*, float a, SP pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f); - void renderRoundedShadow(CBox*, int round, int range, const CColor& color, float a = 1.0); + void renderRoundedShadow(CBox*, int round, int range, const CHyprColor& color, float a = 1.0); void renderBorder(CBox*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); + void renderBorder(CBox*, const CGradientValueData&, const CGradientValueData&, float lerp, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */); void renderTextureMatte(SP tex, CBox* pBox, CFramebuffer& matte); void setMonitorTransformEnabled(bool enabled); @@ -180,7 +181,7 @@ class CHyprOpenGLImpl { void renderSnapshot(PHLLS); bool shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow); - void clear(const CColor&); + void clear(const CHyprColor&); void clearWithTex(); void scissor(const CBox*, bool transform = true); void scissor(const pixman_box32*, bool transform = true); @@ -289,7 +290,7 @@ class CHyprOpenGLImpl { void initEGL(bool gbm); EGLDeviceEXT eglDeviceFromDRMFD(int drmFD); SP loadAsset(const std::string& file); - SP renderText(const std::string& text, CColor col, int pt, bool italic = false); + SP renderText(const std::string& text, CHyprColor col, int pt, bool italic = false); void initAssets(); void initMissingAssetTexture(); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index bba133d9..7e44e64e 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -619,7 +619,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe if (*PDIMAROUND && pWindow->m_sWindowData.dimAround.valueOrDefault() && !m_bRenderingSnapshot && mode != RENDER_PASS_POPUP) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); + g_pHyprOpenGL->renderRect(&monbox, CHyprColor(0, 0, 0, *PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); } renderdata.x += pWindow->m_vFloatingOffset.x; @@ -668,7 +668,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe if (!pWindow->m_sWindowData.noBlur.valueOrDefault() && pWindow->m_pWLSurface->small() && !pWindow->m_pWLSurface->m_bFillIgnoreSmall && renderdata.blur && *PBLUR) { CBox wb = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; wb.scale(pMonitor->scale).round(); - g_pHyprOpenGL->renderRectWithBlur(&wb, CColor(0, 0, 0, 0), renderdata.dontRound ? 0 : renderdata.rounding - 1, renderdata.fadeAlpha, + g_pHyprOpenGL->renderRectWithBlur(&wb, CHyprColor(0, 0, 0, 0), renderdata.dontRound ? 0 : renderdata.rounding - 1, renderdata.fadeAlpha, g_pHyprOpenGL->shouldUseNewBlurOptimizations(nullptr, pWindow)); renderdata.blur = false; } @@ -780,7 +780,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot && !popups) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * pLayer->alpha.value())); + g_pHyprOpenGL->renderRect(&monbox, CHyprColor(0, 0, 0, *PDIMAROUND * pLayer->alpha.value())); } if (pLayer->fadingOut) { @@ -919,7 +919,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA g_pHyprOpenGL->blend(false); if (!canSkipBackBufferClear(pMonitor)) { if (*PRENDERTEX /* inverted cfg flag */) - g_pHyprOpenGL->clear(CColor(*PBACKGROUNDCOLOR)); + g_pHyprOpenGL->clear(CHyprColor(*PBACKGROUNDCOLOR)); else g_pHyprOpenGL->clearWithTex(); // will apply the hypr "wallpaper" } @@ -959,7 +959,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA g_pHyprOpenGL->blend(false); if (!canSkipBackBufferClear(pMonitor)) { if (*PRENDERTEX /* inverted cfg flag */) - g_pHyprOpenGL->clear(CColor(*PBACKGROUNDCOLOR)); + g_pHyprOpenGL->clear(CHyprColor(*PBACKGROUNDCOLOR)); else g_pHyprOpenGL->clearWithTex(); // will apply the hypr "wallpaper" } @@ -995,12 +995,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA if (*PDIMSPECIAL != 0.f) { CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMSPECIAL * (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS))); + g_pHyprOpenGL->renderRect(&monbox, CHyprColor(0, 0, 0, *PDIMSPECIAL * (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS))); } if (*PBLURSPECIAL && *PBLUR) { CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; - g_pHyprOpenGL->renderRectWithBlur(&monbox, CColor(0, 0, 0, 0), 0, (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS)); + g_pHyprOpenGL->renderRectWithBlur(&monbox, CHyprColor(0, 0, 0, 0), 0, (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS)); } break; @@ -1447,7 +1447,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor) { if (*PDAMAGEBLINK && damageBlinkCleanup == 0) { CBox monrect = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; - g_pHyprOpenGL->renderRect(&monrect, CColor(1.0, 0.0, 1.0, 100.0 / 255.0), 0); + g_pHyprOpenGL->renderRect(&monrect, CHyprColor(1.0, 0.0, 1.0, 100.0 / 255.0), 0); damageBlinkCleanup = 1; } else if (*PDAMAGEBLINK) { damageBlinkCleanup++; @@ -2526,7 +2526,7 @@ std::tuple CHyprRenderer::getRenderTimes(PHLMONITOR pMonito static int handleCrashLoop(void* data) { - g_pHyprNotificationOverlay->addNotification("Hyprland will crash in " + std::to_string(10 - (int)(g_pHyprRenderer->m_fCrashingDistort * 2.f)) + "s.", CColor(0), 5000, + g_pHyprNotificationOverlay->addNotification("Hyprland will crash in " + std::to_string(10 - (int)(g_pHyprRenderer->m_fCrashingDistort * 2.f)) + "s.", CHyprColor(0), 5000, ICON_INFO); g_pHyprRenderer->m_fCrashingDistort += 0.5f; @@ -2540,7 +2540,7 @@ static int handleCrashLoop(void* data) { } void CHyprRenderer::initiateManualCrash() { - g_pHyprNotificationOverlay->addNotification("Manual crash initiated. Farewell...", CColor(0), 5000, ICON_INFO); + g_pHyprNotificationOverlay->addNotification("Manual crash initiated. Farewell...", CHyprColor(0), 5000, ICON_INFO); m_pCrashingLoop = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleCrashLoop, nullptr); wl_event_source_timer_update(m_pCrashingLoop, 1000); diff --git a/src/render/Shader.hpp b/src/render/Shader.hpp index d5a312c3..eaf9da96 100644 --- a/src/render/Shader.hpp +++ b/src/render/Shader.hpp @@ -38,9 +38,13 @@ class CShader { GLint applyTint = -1; GLint tint = -1; - GLint gradient = -1; - GLint gradientLength = -1; - GLint angle = -1; + GLint gradient = -1; + GLint gradientLength = -1; + GLint angle = -1; + GLint gradient2 = -1; + GLint gradient2Length = -1; + GLint angle2 = -1; + GLint gradientLerp = -1; float initialTime = 0; GLint time = -1; diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index d62e67c4..b0de4a64 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -60,7 +60,6 @@ void CHyprBorderDecoration::draw(PHLMONITOR pMonitor, float const& a) { auto grad = m_pWindow->m_cRealBorderColor; const bool ANIMATED = m_pWindow->m_fBorderFadeAnimationProgress.isBeingAnimated(); - float a1 = a * (ANIMATED ? m_pWindow->m_fBorderFadeAnimationProgress.value() : 1.f); if (m_pWindow->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) { grad.m_fAngle += m_pWindow->m_fBorderAngleAnimationProgress.value() * M_PI * 2; @@ -70,12 +69,10 @@ void CHyprBorderDecoration::draw(PHLMONITOR pMonitor, float const& a) { int borderSize = m_pWindow->getRealBorderSize(); const auto ROUNDING = m_pWindow->rounding() * pMonitor->scale; - g_pHyprOpenGL->renderBorder(&windowBox, grad, ROUNDING, borderSize, a1); - - if (ANIMATED) { - float a2 = a * (1.f - m_pWindow->m_fBorderFadeAnimationProgress.value()); - g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow->m_cRealBorderColorPrevious, ROUNDING, borderSize, a2); - } + if (ANIMATED) + g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow->m_cRealBorderColorPrevious, grad, m_pWindow->m_fBorderFadeAnimationProgress.value(), ROUNDING, borderSize, a); + else + g_pHyprOpenGL->renderBorder(&windowBox, grad, ROUNDING, borderSize, a); } eDecorationType CHyprBorderDecoration::getDecorationType() { diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 893ad498..39398878 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -93,7 +93,7 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) { if (!validMapped(PWINDOW)) return; - if (PWINDOW->m_cRealShadowColor.value() == CColor(0, 0, 0, 0)) + if (PWINDOW->m_cRealShadowColor.value() == CHyprColor(0, 0, 0, 0)) return; // don't draw invisible shadows if (!PWINDOW->m_sWindowData.decorate.valueOrDefault()) @@ -181,13 +181,13 @@ void CHyprDropShadowDecoration::draw(PHLMONITOR pMonitor, float const& a) { // build the matte // 10-bit formats have dogshit alpha channels, so we have to use the matte to its fullest. // first, clear region of interest with black (fully transparent) - g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0); + g_pHyprOpenGL->renderRect(&fullBox, CHyprColor(0, 0, 0, 1), 0); // render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit) - drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a); + drawShadowInternal(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CHyprColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a); // render black window box ("clip") - g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->scale); + g_pHyprOpenGL->renderRect(&windowBox, CHyprColor(0, 0, 0, 1.0), (ROUNDING + 1 /* This fixes small pixel gaps. */) * pMonitor->scale); alphaSwapFB.bind(); @@ -215,7 +215,7 @@ eDecorationLayer CHyprDropShadowDecoration::getDecorationLayer() { return DECORATION_LAYER_BOTTOM; } -void CHyprDropShadowDecoration::drawShadowInternal(CBox* box, int round, int range, CColor color, float a) { +void CHyprDropShadowDecoration::drawShadowInternal(CBox* box, int round, int range, CHyprColor color, float a) { static auto PSHADOWSHARP = CConfigValue("decoration:shadow:sharp"); g_pHyprOpenGL->blend(true); diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp index 933ee0ef..650f8c92 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.hpp +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -34,7 +34,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration { Vector2D m_vLastWindowPos; Vector2D m_vLastWindowSize; - void drawShadowInternal(CBox* box, int round, int range, CColor color, float a); + void drawShadowInternal(CBox* box, int round, int range, CHyprColor color, float a); CBox m_bLastWindowBox = {0}; CBox m_bLastWindowBoxWithDecos = {0}; diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index b5189be5..937c913d 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -147,7 +147,7 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE; const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE; - CColor color = m_dwGroupMembers[WINDOWINDEX].lock() == g_pCompositor->m_pLastWindow.lock() ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0]; + CHyprColor color = m_dwGroupMembers[WINDOWINDEX].lock() == g_pCompositor->m_pLastWindow.lock() ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0]; color.a *= a; g_pHyprOpenGL->renderRect(&rect, color); @@ -205,19 +205,19 @@ void CHyprGroupBarDecoration::invalidateTextures() { } CTitleTex::CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize, const float monitorScale) { - tex = makeShared(); - szContent = pWindow->m_szTitle; - pWindowOwner = pWindow; - const auto LAYOUTSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); - const auto LAYOUTCAIRO = cairo_create(LAYOUTSURFACE); + tex = makeShared(); + szContent = pWindow->m_szTitle; + pWindowOwner = pWindow; + const auto LAYOUTSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); + const auto LAYOUTCAIRO = cairo_create(LAYOUTSURFACE); - static auto FALLBACKFONT = CConfigValue("misc:font_family"); - static auto PTITLEFONTFAMILY = CConfigValue("group:groupbar:font_family"); - static auto PTITLEFONTSIZE = CConfigValue("group:groupbar:font_size"); - static auto PTEXTCOLOR = CConfigValue("group:groupbar:text_color"); + static auto FALLBACKFONT = CConfigValue("misc:font_family"); + static auto PTITLEFONTFAMILY = CConfigValue("group:groupbar:font_family"); + static auto PTITLEFONTSIZE = CConfigValue("group:groupbar:font_size"); + static auto PTEXTCOLOR = CConfigValue("group:groupbar:text_color"); - const CColor COLOR = CColor(*PTEXTCOLOR); - const auto FONTFAMILY = *PTITLEFONTFAMILY != STRVAL_EMPTY ? *PTITLEFONTFAMILY : *FALLBACKFONT; + const CHyprColor COLOR = CHyprColor(*PTEXTCOLOR); + const auto FONTFAMILY = *PTITLEFONTFAMILY != STRVAL_EMPTY ? *PTITLEFONTFAMILY : *FALLBACKFONT; cairo_surface_destroy(LAYOUTSURFACE); diff --git a/src/render/shaders/Border.hpp b/src/render/shaders/Border.hpp index 1f4a1d97..acd3f3ff 100644 --- a/src/render/shaders/Border.hpp +++ b/src/render/shaders/Border.hpp @@ -17,12 +17,32 @@ uniform float radius; uniform float radiusOuter; uniform float thick; +// Gradients are in OkLabA!!!! {l, a, b, alpha} uniform vec4 gradient[10]; +uniform vec4 gradient2[10]; uniform int gradientLength; +uniform int gradient2Length; uniform float angle; +uniform float angle2; +uniform float gradientLerp; uniform float alpha; -vec4 getColorForCoord(vec2 normalizedCoord) { +float linearToGamma(float x) { + return x >= 0.0031308 ? 1.055 * pow(x, 0.416666666) - 0.055 : 12.92 * x; +} + +vec4 okLabAToSrgb(vec4 lab) { + float l = pow(lab[0] + lab[1] * 0.3963377774 + lab[2] * 0.2158037573, 3.0); + float m = pow(lab[0] + lab[1] * (-0.1055613458) + lab[2] * (-0.0638541728), 3.0); + float s = pow(lab[0] + lab[1] * (-0.0894841775) + lab[2] * (-1.2914855480), 3.0); + + return vec4(linearToGamma(l * 4.0767416621 + m * -3.3077115913 + s * 0.2309699292), + linearToGamma(l * (-1.2684380046) + m * 2.6097574011 + s * (-0.3413193965)), + linearToGamma(l * (-0.0041960863) + m * (-0.7034186147) + s * 1.7076147010), + lab[3]); +} + +vec4 getOkColorForCoordArray1(vec2 normalizedCoord) { if (gradientLength < 2) return gradient[0]; @@ -51,6 +71,46 @@ vec4 getColorForCoord(vec2 normalizedCoord) { return gradient[top] * (progress - float(bottom)) + gradient[bottom] * (float(top) - progress); } +vec4 getOkColorForCoordArray2(vec2 normalizedCoord) { + if (gradient2Length < 2) + return gradient2[0]; + + float finalAng = 0.0; + + if (angle2 > 4.71 /* 270 deg */) { + normalizedCoord[1] = 1.0 - normalizedCoord[1]; + finalAng = 6.28 - angle; + } else if (angle2 > 3.14 /* 180 deg */) { + normalizedCoord[0] = 1.0 - normalizedCoord[0]; + normalizedCoord[1] = 1.0 - normalizedCoord[1]; + finalAng = angle - 3.14; + } else if (angle2 > 1.57 /* 90 deg */) { + normalizedCoord[0] = 1.0 - normalizedCoord[0]; + finalAng = 3.14 - angle2; + } else { + finalAng = angle2; + } + + float sine = sin(finalAng); + + float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradient2Length - 1); + int bottom = int(floor(progress)); + int top = bottom + 1; + + return gradient2[top] * (progress - float(bottom)) + gradient2[bottom] * (float(top) - progress); +} + +vec4 getColorForCoord(vec2 normalizedCoord) { + vec4 result1 = getOkColorForCoordArray1(normalizedCoord); + + if (gradient2Length <= 0) + return okLabAToSrgb(result1); + + vec4 result2 = getOkColorForCoordArray2(normalizedCoord); + + return okLabAToSrgb(mix(result1, result2, gradientLerp)); +} + void main() { highp vec2 pixCoord = vec2(gl_FragCoord); From f6ac755cf76750b8ee53389c54ef653590462c1c Mon Sep 17 00:00:00 2001 From: vaxerski Date: Tue, 3 Dec 2024 21:15:25 +0000 Subject: [PATCH 0078/1566] cleanup: Revert use doLater instead of adding idle event handlers (#8624) This reverts commit 6d7544458d0fafcae410c1978a0cabce2fb4a346. --- src/protocols/Tablet.cpp | 26 ++++++++++++++------------ src/protocols/Tablet.hpp | 7 ++++--- src/protocols/XDGShell.cpp | 18 +++++++++--------- src/protocols/XDGShell.hpp | 8 ++++---- src/xwayland/Server.cpp | 12 ++++++++---- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/protocols/Tablet.cpp b/src/protocols/Tablet.cpp index 7768402b..d7f741b9 100644 --- a/src/protocols/Tablet.cpp +++ b/src/protocols/Tablet.cpp @@ -2,7 +2,6 @@ #include "../devices/Tablet.hpp" #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" -#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include @@ -163,6 +162,11 @@ CTabletToolV2Resource::CTabletToolV2Resource(SP resource_, SP< }); } +CTabletToolV2Resource::~CTabletToolV2Resource() { + if (frameSource) + wl_event_source_remove(frameSource); +} + bool CTabletToolV2Resource::good() { return resource->resource(); } @@ -201,22 +205,20 @@ void CTabletToolV2Resource::sendData() { } void CTabletToolV2Resource::queueFrame() { - if (frameQueued) + if (frameSource) return; - frameQueued = true; - g_pEventLoopManager->doLater([this]() { - if (!frameQueued || tool.expired() || inert) - return; - - sendFrame(); - }); + frameSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, [](void* data) { ((CTabletToolV2Resource*)data)->sendFrame(false); }, this); } -void CTabletToolV2Resource::sendFrame() { - frameQueued = false; +void CTabletToolV2Resource::sendFrame(bool removeSource) { + if (frameSource) { + if (removeSource) + wl_event_source_remove(frameSource); + frameSource = nullptr; + } - if (!current || !resource) + if (!current) return; timespec now; diff --git a/src/protocols/Tablet.hpp b/src/protocols/Tablet.hpp index 8c99bee0..1ebcb1e5 100644 --- a/src/protocols/Tablet.hpp +++ b/src/protocols/Tablet.hpp @@ -112,20 +112,21 @@ class CTabletV2Resource { class CTabletToolV2Resource { public: CTabletToolV2Resource(SP resource_, SP tool_, SP seat_); + ~CTabletToolV2Resource(); bool good(); void sendData(); void queueFrame(); - void sendFrame(); + void sendFrame(bool removeSource = true); bool current = false; WP lastSurf; WP tool; WP seat; + wl_event_source* frameSource = nullptr; - bool frameQueued = false; - bool inert = false; // removed was sent + bool inert = false; // removed was sent private: SP resource; diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index a542c394..688d0006 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -3,7 +3,6 @@ #include #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" -#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include @@ -470,6 +469,8 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPresetRole(); } @@ -483,23 +484,22 @@ SP CXDGSurfaceResource::fromResource(wl_resource* res) { return data ? data->self.lock() : nullptr; } +static void onConfigure(void* data) { + ((CXDGSurfaceResource*)data)->configure(); +} + uint32_t CXDGSurfaceResource::scheduleConfigure() { - if (configureScheduled) + if (configureSource) return scheduledSerial; + configureSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, onConfigure, this); scheduledSerial = wl_display_next_serial(g_pCompositor->m_sWLDisplay); - configureScheduled = true; - g_pEventLoopManager->doLater([this]() { configure(); }); - return scheduledSerial; } void CXDGSurfaceResource::configure() { - if (!resource) - return; - - configureScheduled = false; + configureSource = nullptr; resource->sendConfigure(scheduledSerial); } diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp index 3b7d2d11..ef847f3b 100644 --- a/src/protocols/XDGShell.hpp +++ b/src/protocols/XDGShell.hpp @@ -199,12 +199,12 @@ class CXDGSurfaceResource { void configure(); private: - SP resource; + SP resource; - uint32_t lastConfigureSerial = 0; - uint32_t scheduledSerial = 0; + uint32_t lastConfigureSerial = 0; + uint32_t scheduledSerial = 0; - bool configureScheduled = false; + wl_event_source* configureSource = nullptr; // std::vector> popups; diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index 390ce1f6..f356af18 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -176,6 +176,11 @@ static bool openSockets(std::array& sockets, int display) { return true; } +static void startServer(void* data) { + if (!g_pXWayland->pServer->start()) + Debug::log(ERR, "The XWayland server could not start! XWayland will not work..."); +} + static int xwaylandReady(int fd, uint32_t mask, void* data) { return g_pXWayland->pServer->ready(fd, mask); } @@ -303,10 +308,9 @@ bool CXWaylandServer::create() { setenv("DISPLAY", displayName.c_str(), true); - g_pEventLoopManager->doLater([this]() { - if (!start()) - Debug::log(ERR, "The XWayland server could not start! XWayland will not work..."); - }); + // TODO: lazy mode + + idleSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, ::startServer, nullptr); return true; } From 3c617ce33c64cb43049489598b6391911eed7070 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 3 Dec 2024 22:58:30 +0000 Subject: [PATCH 0079/1566] internal: fixup some missed updateColorsOk() calls --- src/desktop/Window.cpp | 2 ++ src/managers/KeybindManager.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index b015d61f..34682b32 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -692,6 +692,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { inactiveBorderGradient.m_vColors.push_back(configStringToInt(token).value_or(0)); } + activeBorderGradient.updateColorsOk(); + // Includes sanity checks for the number of colors in each gradient if (activeBorderGradient.m_vColors.size() > 10 || inactiveBorderGradient.m_vColors.size() > 10) Debug::log(WARN, "Bordercolor rule \"{}\" has more than 10 colors in one gradient, ignoring", r.szRule); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index cfb7453c..153c3c0d 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2997,6 +2997,8 @@ SDispatchResult CKeybindManager::setProp(std::string args) { return std::invoke_result_t(1); }); + colorData.updateColorsOk(); + if (PROP == "activebordercolor") PWINDOW->m_sWindowData.activeBorderColor = CWindowOverridableVar(colorData, PRIORITY_SET_PROP); else From f9e4998a6d7713b19947b0db2c43ad88c5b71d80 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Wed, 4 Dec 2024 13:12:04 -0500 Subject: [PATCH 0080/1566] snap: check which corner is being grabbed for monitor snapping (#8637) --- src/layout/IHyprLayout.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 8ff55d10..cb1f064b 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -487,19 +487,23 @@ static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRA SRange monX = {MON->vecPosition.x + BORDERSIZE, MON->vecPosition.x + MON->vecSize.x - BORDERSIZE}; SRange monY = {MON->vecPosition.y + BORDERSIZE, MON->vecPosition.y + MON->vecSize.y - BORDERSIZE}; - if (canSnap(sourceX.start, monX.start, GAPSIZE) || canSnap(sourceX.start, (monX.start += MON->vecReservedTopLeft.x + BORDERDIFF), GAPSIZE)) { + if (CORNER & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && + (canSnap(sourceX.start, monX.start, GAPSIZE) || canSnap(sourceX.start, (monX.start += MON->vecReservedTopLeft.x + BORDERDIFF), GAPSIZE))) { SNAP(sourceX.start, sourceX.end, monX.start); snaps |= SNAP_LEFT; } - if (canSnap(sourceX.end, monX.end, GAPSIZE) || canSnap(sourceX.end, (monX.end -= MON->vecReservedBottomRight.x + BORDERDIFF), GAPSIZE)) { + if (CORNER & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && + (canSnap(sourceX.end, monX.end, GAPSIZE) || canSnap(sourceX.end, (monX.end -= MON->vecReservedBottomRight.x + BORDERDIFF), GAPSIZE))) { SNAP(sourceX.end, sourceX.start, monX.end); snaps |= SNAP_RIGHT; } - if (canSnap(sourceY.start, monY.start, GAPSIZE) || canSnap(sourceY.start, (monY.start += MON->vecReservedTopLeft.y + BORDERDIFF), GAPSIZE)) { + if (CORNER & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && + (canSnap(sourceY.start, monY.start, GAPSIZE) || canSnap(sourceY.start, (monY.start += MON->vecReservedTopLeft.y + BORDERDIFF), GAPSIZE))) { SNAP(sourceY.start, sourceY.end, monY.start); snaps |= SNAP_UP; } - if (canSnap(sourceY.end, monY.end, GAPSIZE) || canSnap(sourceY.end, (monY.end -= MON->vecReservedBottomRight.y + BORDERDIFF), GAPSIZE)) { + if (CORNER & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && + (canSnap(sourceY.end, monY.end, GAPSIZE) || canSnap(sourceY.end, (monY.end -= MON->vecReservedBottomRight.y + BORDERDIFF), GAPSIZE))) { SNAP(sourceY.end, sourceY.start, monY.end); snaps |= SNAP_DOWN; } From 22f7d6f1424c296b297df87bf2accdfefac4af33 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 5 Dec 2024 01:59:29 +0000 Subject: [PATCH 0081/1566] core: add a few festive splashes adds two new 'special' splash types for xmas and new years. Activated based on local time. --- src/Compositor.cpp | 14 ++- src/helpers/Splashes.hpp | 184 +++++++++++++++++++++++---------------- 2 files changed, 120 insertions(+), 78 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3573996d..1261d003 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -206,11 +206,21 @@ CCompositor::~CCompositor() { } void CCompositor::setRandomSplash() { + auto tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + auto local = *localtime(&tt); + + const auto* SPLASHES = &NSplashes::SPLASHES; + + if (local.tm_mon + 1 == 12 && local.tm_mday >= 23 && local.tm_mday <= 27) // dec 23-27 + SPLASHES = &NSplashes::SPLASHES_CHRISTMAS; + if ((local.tm_mon + 1 == 12 && local.tm_mday >= 29) || (local.tm_mon + 1 == 1 && local.tm_mday <= 3)) + SPLASHES = &NSplashes::SPLASHES_NEWYEAR; + std::random_device dev; std::mt19937 engine(dev()); - std::uniform_int_distribution<> distribution(0, SPLASHES.size() - 1); + std::uniform_int_distribution<> distribution(0, SPLASHES->size() - 1); - m_szCurrentSplash = SPLASHES[distribution(engine)]; + m_szCurrentSplash = SPLASHES->at(distribution(engine)); } static std::vector> pendingOutputs; diff --git a/src/helpers/Splashes.hpp b/src/helpers/Splashes.hpp index 4a4fd022..2c74abb1 100644 --- a/src/helpers/Splashes.hpp +++ b/src/helpers/Splashes.hpp @@ -3,80 +3,112 @@ #include #include -inline const std::vector SPLASHES = { - // clang-format off - "Woo, animations!", - "It's like Hypr, but better.", - "Release 1.0 when?", - "It's not awesome, it's Hyprland!", - "\"I commit too often, people can't catch up lmao\" - Vaxry", - "This text is random.", - "\"There are reasons to not use rust.\" - Boga", - "Read the wiki.", - "\"Hello everyone this is YOUR daily dose of ‘read the wiki’\" - Vaxry", - "h", - "\"‘why no work’, bro I haven't hacked your pc to get live feeds yet\" - Vaxry", - "Compile, wait for 20 minutes, notice a new commit, compile again.", - "To rice, or not to rice, that is the question.", - "Now available on Fedora!", - "\"Hyprland is so good it starts with a capital letter\" - Hazel", - "\"please make this message a splash\" - eriedaberrie", - "\"the only wayland compositor powered by fried chicken\" - raf", - "\"This will never get into Hyprland\" - Flafy", - "\"Hyprland only gives you up on -git\" - fazzi", - "Segmentation fault (core dumped)", - "\"disabling hyprland logo is a war crime\" - vaxry", - "some basic startup code", - "\"I think I am addicted to hyprland\" - mathisbuilder", - "\"hyprland is the most important package in the arch repos\" - jacekpoz", - "Thanks Brodie!", - "Thanks fufexan!", - "Thanks raf!", - "You can't use --splash to change this message :)", - "Hyprland will overtake Gnome in popularity by [insert year]", - // music reference / quote section - "J'remue le ciel, le jour, la nuit.", - "aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi!", - "Wir sind schon sehr lang zusammen...", - "I see a red door and I want it painted black.", - "Take on me, take me on...", - "You spin me right round baby right round", - "Stayin' alive, stayin' alive", - "Say no way, say no way ya, no way!", - "Ground control to Major Tom...", - "Alors on danse", - "And all that I can see, is just a yellow lemon tree.", - "Got a one-way ticket to the blues", - "Is this the real life, is this just fantasy", - "What's in your head, in your head?", - "We're all living in America, America, America.", - "I'm still standing, better than I ever did", - "Here comes the sun, bringing you love and shining on everyone", - "Two trailer park girls go round the outside", - "With the lights out, it's less dangerous", - "Here we go back, this is the moment, tonight is the night", - "Now you're just somebody that I used to know...", - "Black bird, black moon, black sky", - "Some legends are told, some turn to dust or to gold", - "Your brain gets smart, but your head gets dumb.", - "Save your mercy for someone who needs it more", - "You're gonna hear my voice when I shout it out loud", - "Ding ding pch n daa, bam-ba-ba-re-bam baram bom bom baba-bam-bam-bommm", - "Súbeme la radio que esta es mi canción", - "I'm beggin', beggin' you", - "Never gonna let you down (I am trying!)", - "\"I use Arch, btw\" - John Cena", - "\"Hyper\".replace(\"e\", \"\")", - "\"my win11 install runs hyprland that is true\" - raf", - "\"stop playing league loser\" - hyprBot", - "\"If it ain't broke, don't fix it\" - Lucascito_03", - "\"@vaxry how do i learn c++\" - flicko", - // - "Join the discord server!", - "Thanks ThatOneCalculator!", - "The AUR packages always work, except for the times they don't.", - "Funny animation compositor woo", - // - "2 years!" - // clang-format on +namespace NSplashes { + inline const std::vector SPLASHES = { + // clang-format off + "Woo, animations!", + "It's like Hypr, but better.", + "Release 1.0 when?", + "It's not awesome, it's Hyprland!", + "\"I commit too often, people can't catch up lmao\" - Vaxry", + "This text is random.", + "\"There are reasons to not use rust.\" - Boga", + "Read the wiki.", + "\"Hello everyone this is YOUR daily dose of ‘read the wiki’\" - Vaxry", + "h", + "\"‘why no work’, bro I haven't hacked your pc to get live feeds yet\" - Vaxry", + "Compile, wait for 20 minutes, notice a new commit, compile again.", + "To rice, or not to rice, that is the question.", + "Now available on Fedora!", + "\"Hyprland is so good it starts with a capital letter\" - Hazel", + "\"please make this message a splash\" - eriedaberrie", + "\"the only wayland compositor powered by fried chicken\" - raf", + "\"This will never get into Hyprland\" - Flafy", + "\"Hyprland only gives you up on -git\" - fazzi", + "Segmentation fault (core dumped)", + "\"disabling hyprland logo is a war crime\" - vaxry", + "some basic startup code", + "\"I think I am addicted to hyprland\" - mathisbuilder", + "\"hyprland is the most important package in the arch repos\" - jacekpoz", + "Thanks Brodie!", + "Thanks fufexan!", + "Thanks raf!", + "You can't use --splash to change this message :)", + "Hyprland will overtake Gnome in popularity by [insert year]", + // music reference / quote section + "J'remue le ciel, le jour, la nuit.", + "aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi!", + "Wir sind schon sehr lang zusammen...", + "I see a red door and I want it painted black.", + "Take on me, take me on...", + "You spin me right round baby right round", + "Stayin' alive, stayin' alive", + "Say no way, say no way ya, no way!", + "Ground control to Major Tom...", + "Alors on danse", + "And all that I can see, is just a yellow lemon tree.", + "Got a one-way ticket to the blues", + "Is this the real life, is this just fantasy", + "What's in your head, in your head?", + "We're all living in America, America, America.", + "I'm still standing, better than I ever did", + "Here comes the sun, bringing you love and shining on everyone", + "Two trailer park girls go round the outside", + "With the lights out, it's less dangerous", + "Here we go back, this is the moment, tonight is the night", + "Now you're just somebody that I used to know...", + "Black bird, black moon, black sky", + "Some legends are told, some turn to dust or to gold", + "Your brain gets smart, but your head gets dumb.", + "Save your mercy for someone who needs it more", + "You're gonna hear my voice when I shout it out loud", + "Ding ding pch n daa, bam-ba-ba-re-bam baram bom bom baba-bam-bam-bommm", + "Súbeme la radio que esta es mi canción", + "I'm beggin', beggin' you", + "Never gonna let you down (I am trying!)", + "\"I use Arch, btw\" - John Cena", + "\"Hyper\".replace(\"e\", \"\")", + "\"my win11 install runs hyprland that is true\" - raf", + "\"stop playing league loser\" - hyprBot", + "\"If it ain't broke, don't fix it\" - Lucascito_03", + "\"@vaxry how do i learn c++\" - flicko", + // + "Join the discord server!", + "Thanks ThatOneCalculator!", + "The AUR packages always work, except for the times they don't.", + "Funny animation compositor woo", + // + "2 years!" + // clang-format on + }; + + inline const std::vector SPLASHES_CHRISTMAS = { + // clang-format off + "Merry Christmas!", + "Merry Xmas!", + "Ho ho ho", + "Santa was here", + // clang-format on + }; + + // ONLY valid near new years. + inline static int newYear = []() -> int { + auto tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + auto local = *localtime(&tt); + + if (local.tm_mon < 8 /* decided with a fair die I promise. */) + return local.tm_year + 1900; + return local.tm_year + 1901; + }(); + + inline const std::vector SPLASHES_NEWYEAR = { + // clang-format off + "Happy new Year!", + "[New year] will be the year of the Linux desktop!", + "[New year] will be the year of the Hyprland desktop!", + std::format("{} will be the year of the Linux desktop!", newYear), + std::format("{} will be the year of the Hyprland desktop!", newYear), + std::format("Let's make {} even better than {}!", newYear, newYear - 1), + // clang-format on + }; }; \ No newline at end of file From ceef4fb3a5efe1617790f56e2701846a21c2533d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 5 Dec 2024 03:36:50 +0000 Subject: [PATCH 0082/1566] core: feeling a bit quirky today. --- src/helpers/Splashes.hpp | 49 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/helpers/Splashes.hpp b/src/helpers/Splashes.hpp index 2c74abb1..3ae59956 100644 --- a/src/helpers/Splashes.hpp +++ b/src/helpers/Splashes.hpp @@ -35,6 +35,30 @@ namespace NSplashes { "Thanks raf!", "You can't use --splash to change this message :)", "Hyprland will overtake Gnome in popularity by [insert year]", + "Designed in California - Assembled in China", + "\"something