mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-12-20 00:40:03 +01:00
Compare commits
42 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d099f87d36 | ||
|
|
e2da7c6b1f | ||
|
|
98b86752fe | ||
|
|
36ec73f166 | ||
|
|
bdc44ab5d6 | ||
|
|
de2cc5bd54 | ||
|
|
c8a6768dca | ||
|
|
3cb799b184 | ||
| c48279d1e0 | |||
|
|
7f769fa993 | ||
|
|
1380ca04ae | ||
|
|
61b36c64a8 | ||
|
|
a7f2634a9e | ||
|
|
450ae1e5f0 | ||
|
|
04cfdc4e5b | ||
|
|
cedbb24472 | ||
|
|
8d0e56998e | ||
|
|
a356bf055b | ||
|
|
347e05a40e | ||
| bdf0ef8282 | |||
|
|
71691634e4 | ||
|
|
1e5e62d6e3 | ||
|
|
d993bdc105 | ||
|
|
8ebcee2969 | ||
|
|
1553dd78fc | ||
| 31297a871b | |||
|
|
17fefce86e | ||
|
|
46498da4a0 | ||
|
|
fee04f6406 | ||
|
|
d84b44e695 | ||
|
|
7999f448d7 | ||
|
|
a9638986c3 | ||
| e67036e8cc | |||
|
|
f9d8dfab7a | ||
|
|
1303bb4b7e | ||
|
|
8455fc8ca6 | ||
|
|
da1d076d84 | ||
|
|
f7f0c9c6b0 | ||
|
|
c12cf8e509 | ||
|
|
0c5fd97d61 | ||
|
|
fae1c4f6fe | ||
|
|
e3bd47e177 |
58 changed files with 1665 additions and 1287 deletions
30
.github/workflows/nix.yml
vendored
30
.github/workflows/nix.yml
vendored
|
|
@ -7,7 +7,35 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- name: Install Nix
|
||||
uses: nixbuild/nix-quick-install-action@v31
|
||||
with:
|
||||
nix_conf: |
|
||||
keep-env-derivations = true
|
||||
keep-outputs = true
|
||||
|
||||
- name: Restore and save Nix store
|
||||
uses: nix-community/cache-nix-action@v6
|
||||
with:
|
||||
# restore and save a cache using this key
|
||||
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
|
||||
# if there's no cache hit, restore a cache by this prefix
|
||||
restore-prefixes-first-match: nix-${{ runner.os }}-
|
||||
# collect garbage until the Nix store size (in bytes) is at most this number
|
||||
# before trying to save a new cache
|
||||
# 1G = 1073741824
|
||||
gc-max-store-size-linux: 1G
|
||||
# do purge caches
|
||||
purge: true
|
||||
# purge all versions of the cache
|
||||
purge-prefixes: nix-${{ runner.os }}-
|
||||
# created more than this number of seconds ago
|
||||
purge-created: 0
|
||||
# or, last accessed more than this number of seconds ago
|
||||
# relative to the start of the `Post Restore and save Nix store` phase
|
||||
purge-last-accessed: 0
|
||||
# except any version with the key that is the same as the `primary-key`
|
||||
purge-primary-key: never
|
||||
|
||||
# not needed (yet)
|
||||
# - uses: cachix/cachix-action@v12
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ add_compile_definitions(HYPRLOCK_VERSION="${VERSION}")
|
|||
if (DEFINED HYPRLOCK_COMMIT)
|
||||
add_compile_definitions(HYPRLOCK_COMMIT="${HYPRLOCK_COMMIT}")
|
||||
else()
|
||||
# get git commit
|
||||
# get git commit
|
||||
execute_process(
|
||||
OUTPUT_VARIABLE GIT_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
|
|
@ -82,20 +82,30 @@ pkg_check_modules(
|
|||
hyprlang>=0.6.0
|
||||
egl
|
||||
xkbcommon
|
||||
libjpeg
|
||||
libwebp
|
||||
libmagic
|
||||
cairo
|
||||
pangocairo
|
||||
libdrm
|
||||
gbm
|
||||
hyprutils>=0.5.0
|
||||
hyprutils>=0.11.0
|
||||
sdbus-c++>=2.0.0
|
||||
hyprgraphics)
|
||||
hyprgraphics>=0.1.6)
|
||||
find_library(PAM_FOUND NAMES pam libpam)
|
||||
if(PAM_FOUND)
|
||||
set(PAM_LIB ${PAM_FOUND})
|
||||
else()
|
||||
pkg_check_modules(PAM IMPORTED_TARGET pam libpam)
|
||||
if(PAM_FOUND)
|
||||
set(PAM_LIB PkgConfig::PAM)
|
||||
else()
|
||||
message(FATAL_ERROR "The required library libpam was not found.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Found pam at ${PAM_LIB}")
|
||||
|
||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
add_executable(hyprlock ${SRCFILES})
|
||||
target_link_libraries(hyprlock PRIVATE pam rt Threads::Threads PkgConfig::deps
|
||||
target_link_libraries(hyprlock PRIVATE ${PAM_LIB} rt Threads::Threads PkgConfig::deps
|
||||
OpenGL::EGL OpenGL::GLES3)
|
||||
|
||||
# protocols
|
||||
|
|
|
|||
38
README.md
38
README.md
|
|
@ -2,10 +2,14 @@
|
|||
Hyprland's simple, yet multi-threaded and GPU-accelerated screen locking utility.
|
||||
|
||||
## Features
|
||||
- uses the secure ext-session-lock protocol
|
||||
- full support for fractional-scale
|
||||
- fully GPU accelerated
|
||||
- multi-threaded resource acquisition for no hitches
|
||||
- Uses the ext-session-lock protocol
|
||||
- Support for fractional-scale
|
||||
- Fully GPU accelerated
|
||||
- Multi-threaded resource acquisition
|
||||
- Blurred screenshot as the background
|
||||
- Native fingerprint support (using libfprint's dbus interface)
|
||||
- Some of Hyprland's eyecandy: gradient borders, blur, animations, shadows, etc.
|
||||
- and more...
|
||||
|
||||
## How it looks
|
||||
|
||||
|
|
@ -25,26 +29,22 @@ yay -S hyprlock-git # compiles from latest source
|
|||
|
||||
### Deps
|
||||
You need the following dependencies
|
||||
- wayland-client
|
||||
- wayland-protocols
|
||||
- mesa
|
||||
- hyprwayland-scanner
|
||||
|
||||
And the development libraries for the following
|
||||
- cairo
|
||||
- libdrm
|
||||
- pango
|
||||
- xkbcommon
|
||||
- pam
|
||||
- hyprgraphics
|
||||
- hyprlang
|
||||
- hyprutils
|
||||
- hyprgraphics
|
||||
- libmagic (file-devel on Fedora)
|
||||
- hyprwayland-scanner
|
||||
- mesa (required is libgbm, libdrm and the opengl runtime)
|
||||
- pam
|
||||
- pango
|
||||
- sdbus-cpp (>= 2.0.0)
|
||||
- wayland-client
|
||||
- wayland-protocols
|
||||
- xkbcommon
|
||||
|
||||
Development libraries are usually suffixed with `-devel` or `-dev` in most distro repos.
|
||||
|
||||
You also need to install `mesa-libgbm-devel` on some distros like RPM based ones where its not
|
||||
bundled with the mesa package.
|
||||
Sometimes distro packages are missing required development files.
|
||||
Such distros usually offer development versions of library package - commonly suffixed with `-devel` or `-dev`.
|
||||
|
||||
### Building
|
||||
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
0.8.2
|
||||
0.9.2
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@
|
|||
# ref. https://wiki.hyprland.org/Hypr-Ecosystem/hyprlock/#general-remarks
|
||||
#
|
||||
# shortcuts to clear password buffer: ESC, Ctrl+U, Ctrl+Backspace
|
||||
#
|
||||
# you can get started by copying this config to ~/.config/hypr/hyprlock.conf
|
||||
#
|
||||
|
||||
$font = Monospace
|
||||
|
||||
general {
|
||||
hide_cursor = true
|
||||
hide_cursor = false
|
||||
}
|
||||
|
||||
# uncomment to enable fingerprint authentication
|
||||
|
|
@ -90,3 +93,14 @@ label {
|
|||
halign = right
|
||||
valign = top
|
||||
}
|
||||
|
||||
label {
|
||||
monitor =
|
||||
text = $LAYOUT[en,ru]
|
||||
font_size = 24
|
||||
onclick = hyprctl switchxkblayout all next
|
||||
|
||||
position = 250, -20
|
||||
halign = center
|
||||
valign = center
|
||||
}
|
||||
|
|
|
|||
30
flake.lock
generated
30
flake.lock
generated
|
|
@ -13,11 +13,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1743953322,
|
||||
"narHash": "sha256-prQ5JKopXtzCMX2eT3dXbaVvGmzjMRE2bXStQDdazpM=",
|
||||
"lastModified": 1763733840,
|
||||
"narHash": "sha256-JnET78yl5RvpGuDQy3rCycOCkiKoLr5DN1fPhRNNMco=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprgraphics",
|
||||
"rev": "9d7f2687c84c729afbc3b13f7937655570f2978d",
|
||||
"rev": "8f1bec691b2d198c60cccabca7a94add2df4ed1a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -39,11 +39,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1744468525,
|
||||
"narHash": "sha256-9HySx+EtsbbKlZDlY+naqqOV679VdxP6x6fP3wxDXJk=",
|
||||
"lastModified": 1764612430,
|
||||
"narHash": "sha256-54ltTSbI6W+qYGMchAgCR6QnC1kOdKXN6X6pJhOWxFg=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprlang",
|
||||
"rev": "f1000c54d266e6e4e9d646df0774fac5b8a652df",
|
||||
"rev": "0d00dc118981531aa731150b6ea551ef037acddd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -62,11 +62,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1743950287,
|
||||
"narHash": "sha256-/6IAEWyb8gC/NKZElxiHChkouiUOrVYNq9YqG0Pzm4Y=",
|
||||
"lastModified": 1764962281,
|
||||
"narHash": "sha256-rGbEMhTTyTzw4iyz45lch5kXseqnqcEpmrHdy+zHsfo=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"rev": "f2dc70e448b994cef627a157ee340135bd68fbc6",
|
||||
"rev": "fe686486ac867a1a24f99c753bb40ffed338e4b0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -85,11 +85,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1739870480,
|
||||
"narHash": "sha256-SiDN5BGxa/1hAsqhgJsS03C3t2QrLgBT8u+ENJ0Qzwc=",
|
||||
"lastModified": 1763640274,
|
||||
"narHash": "sha256-Uan1Nl9i4TF/kyFoHnTq1bd/rsWh4GAK/9/jDqLbY5A=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprwayland-scanner",
|
||||
"rev": "206367a08dc5ac4ba7ad31bdca391d098082e64b",
|
||||
"rev": "f6cf414ca0e16a4d30198fd670ec86df3c89f671",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -100,11 +100,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1744463964,
|
||||
"narHash": "sha256-LWqduOgLHCFxiTNYi3Uj5Lgz0SR+Xhw3kr/3Xd0GPTM=",
|
||||
"lastModified": 1765186076,
|
||||
"narHash": "sha256-hM20uyap1a0M9d344I692r+ik4gTMyj60cQWO+hAYP8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2631b0b7abcea6e640ce31cd78ea58910d31e650",
|
||||
"rev": "addf7cf5f383a3101ecfba091b98d0a1263dc9b8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
cmake,
|
||||
pkg-config,
|
||||
cairo,
|
||||
file,
|
||||
libdrm,
|
||||
libGL,
|
||||
libjpeg,
|
||||
libwebp,
|
||||
libxkbcommon,
|
||||
libgbm,
|
||||
hyprgraphics,
|
||||
|
|
@ -40,11 +37,8 @@ stdenv.mkDerivation {
|
|||
|
||||
buildInputs = [
|
||||
cairo
|
||||
file
|
||||
libdrm
|
||||
libGL
|
||||
libjpeg
|
||||
libwebp
|
||||
libxkbcommon
|
||||
libgbm
|
||||
hyprgraphics
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ in {
|
|||
inputs.self.overlays.sdbuscpp
|
||||
(final: prev: {
|
||||
hyprlock = prev.callPackage ./default.nix {
|
||||
stdenv = prev.gcc14Stdenv;
|
||||
stdenv = prev.gcc15Stdenv;
|
||||
version = version + "+date=" + (mkDate (inputs.self.lastModifiedDate or "19700101")) + "_" + (inputs.self.shortRev or "dirty");
|
||||
inherit (final) hyprlang;
|
||||
shortRev = self.sourceInfo.shortRev or "dirty";
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ void CAuth::terminate() {
|
|||
}
|
||||
}
|
||||
|
||||
static void unlockCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
static void unlockCallback(ASP<CTimer> self, void* data) {
|
||||
g_pHyprlock->unlock();
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ void CAuth::enqueueUnlock() {
|
|||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), unlockCallback, nullptr);
|
||||
}
|
||||
|
||||
static void passwordFailCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
static void passwordFailCallback(ASP<CTimer> self, void* data) {
|
||||
g_pAuth->m_bDisplayFailText = true;
|
||||
|
||||
g_pHyprlock->enqueueForceUpdateTimers();
|
||||
|
|
@ -92,7 +92,7 @@ static void passwordFailCallback(std::shared_ptr<CTimer> self, void* data) {
|
|||
g_pHyprlock->renderAllOutputs();
|
||||
}
|
||||
|
||||
static void displayFailTimeoutCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
static void displayFailTimeoutCallback(ASP<CTimer> self, void* data) {
|
||||
if (g_pAuth->m_bDisplayFailText) {
|
||||
g_pAuth->m_bDisplayFailText = false;
|
||||
g_pHyprlock->renderAllOutputs();
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class CAuth {
|
|||
} m_sCurrentFail;
|
||||
|
||||
std::vector<SP<IAuthImplementation>> m_vImpls;
|
||||
std::shared_ptr<CTimer> m_resetDisplayFailTimer;
|
||||
ASP<CTimer> m_resetDisplayFailTimer;
|
||||
};
|
||||
|
||||
inline UP<CAuth> g_pAuth;
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ void CFingerprint::handleVerifyStatus(const std::string& result, bool done) {
|
|||
} else {
|
||||
done = false;
|
||||
static const auto RETRYDELAY = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:retry_delay");
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(*RETRYDELAY), [](std::shared_ptr<CTimer> self, void* data) { ((CFingerprint*)data)->startVerify(true); }, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(*RETRYDELAY), [](ASP<CTimer> self, void* data) { ((CFingerprint*)data)->startVerify(true); }, this);
|
||||
m_sFailureReason = "Fingerprint did not match";
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -209,9 +209,11 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue(name, "shadow_passes", Hyprlang::INT{0}); \
|
||||
m_config.addSpecialConfigValue(name, "shadow_color", Hyprlang::INT{0xFF000000}); \
|
||||
m_config.addSpecialConfigValue(name, "shadow_boost", Hyprlang::FLOAT{1.2});
|
||||
|
||||
#define CLICKABLE(name) m_config.addSpecialConfigValue(name, "onclick", Hyprlang::STRING{""});
|
||||
|
||||
m_config.addConfigValue("general:text_trim", Hyprlang::INT{1});
|
||||
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:ignore_empty_input", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:immediate_render", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:fractional_scaling", Hyprlang::INT{2});
|
||||
|
|
@ -257,6 +259,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("shape", "xray", Hyprlang::INT{0});
|
||||
m_config.addSpecialConfigValue("shape", "zindex", Hyprlang::INT{0});
|
||||
SHADOWABLE("shape");
|
||||
CLICKABLE("shape");
|
||||
|
||||
m_config.addSpecialCategory("image", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("image", "monitor", Hyprlang::STRING{""});
|
||||
|
|
@ -273,6 +276,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("image", "reload_cmd", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("image", "zindex", Hyprlang::INT{0});
|
||||
SHADOWABLE("image");
|
||||
CLICKABLE("image");
|
||||
|
||||
m_config.addSpecialCategory("input-field", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("input-field", "monitor", Hyprlang::STRING{""});
|
||||
|
|
@ -320,6 +324,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("label", "text_align", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("label", "zindex", Hyprlang::INT{0});
|
||||
SHADOWABLE("label");
|
||||
CLICKABLE("label");
|
||||
|
||||
m_config.registerHandler(&::handleSource, "source", {.allowFlags = false});
|
||||
m_config.registerHandler(&::handleBezier, "bezier", {.allowFlags = false});
|
||||
|
|
@ -356,6 +361,7 @@ void CConfigManager::init() {
|
|||
Debug::log(ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError());
|
||||
|
||||
#undef SHADOWABLE
|
||||
#undef CLICKABLE
|
||||
}
|
||||
|
||||
std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
||||
|
|
@ -367,6 +373,8 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
"shadow_boost", m_config.getSpecialConfigValue(name, "shadow_boost", k.c_str()) \
|
||||
}
|
||||
|
||||
#define CLICKABLE(name) {"onclick", m_config.getSpecialConfigValue(name, "onclick", k.c_str())}
|
||||
|
||||
//
|
||||
auto keys = m_config.listKeysForSpecialCategory("background");
|
||||
result.reserve(keys.size());
|
||||
|
|
@ -414,6 +422,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"xray", m_config.getSpecialConfigValue("shape", "xray", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("shape", "zindex", k.c_str())},
|
||||
SHADOWABLE("shape"),
|
||||
CLICKABLE("shape"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
@ -440,6 +449,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"reload_cmd", m_config.getSpecialConfigValue("image", "reload_cmd", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("image", "zindex", k.c_str())},
|
||||
SHADOWABLE("image"),
|
||||
CLICKABLE("image"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
@ -505,6 +515,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"text_align", m_config.getSpecialConfigValue("label", "text_align", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("label", "zindex", k.c_str())},
|
||||
SHADOWABLE("label"),
|
||||
CLICKABLE("label"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ void updateGradientVariable(CAnimatedVariable<CGradientValueData>& av, const flo
|
|||
|
||||
void CHyprlockAnimationManager::tick() {
|
||||
static const auto ANIMATIONSENABLED = g_pConfigManager->getValue<Hyprlang::INT>("animations:enabled");
|
||||
for (size_t i = 0; i < m_vActiveAnimatedVariables.size(); i++) {
|
||||
const auto PAV = m_vActiveAnimatedVariables[i].lock();
|
||||
for (const auto& PAV : m_vActiveAnimatedVariables) {
|
||||
if (!PAV || !PAV->ok())
|
||||
continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,12 +19,10 @@ class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager
|
|||
template <Animable VarType>
|
||||
void createAnimation(const VarType& v, PHLANIMVAR<VarType>& pav, SP<SAnimationPropertyConfig> pConfig) {
|
||||
constexpr const eAnimatedVarType EAVTYPE = typeToeAnimatedVarType<VarType>;
|
||||
const auto PAV = makeShared<CAnimatedVariable<VarType>>();
|
||||
pav = makeUnique<CAnimatedVariable<VarType>>();
|
||||
|
||||
PAV->create(EAVTYPE, static_cast<Hyprutils::Animation::CAnimationManager*>(this), PAV, v);
|
||||
PAV->setConfig(pConfig);
|
||||
|
||||
pav = std::move(PAV);
|
||||
pav->create2(EAVTYPE, static_cast<Hyprutils::Animation::CAnimationManager*>(this), pav, v);
|
||||
pav->setConfig(pConfig);
|
||||
}
|
||||
|
||||
bool m_bTickScheduled = false;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,16 @@ CCursorShape::CCursorShape(SP<CCWpCursorShapeManagerV1> mgr) : mgr(mgr) {
|
|||
}
|
||||
|
||||
void CCursorShape::setShape(const wpCursorShapeDeviceV1Shape shape) {
|
||||
if (!dev)
|
||||
if (!g_pSeatManager->m_pPointer)
|
||||
return;
|
||||
|
||||
if (!dev)
|
||||
dev = makeShared<CCWpCursorShapeDeviceV1>(mgr->sendGetPointer(g_pSeatManager->m_pPointer->resource()));
|
||||
|
||||
shapeChanged = true;
|
||||
dev->sendSetShape(lastCursorSerial, shape);
|
||||
}
|
||||
|
||||
void CCursorShape::hideCursor() {
|
||||
g_pSeatManager->m_pPointer->sendSetCursor(lastCursorSerial, nullptr, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ class CCursorShape {
|
|||
void hideCursor();
|
||||
|
||||
uint32_t lastCursorSerial = 0;
|
||||
bool shapeChanged = false;
|
||||
|
||||
private:
|
||||
SP<CCWpCursorShapeManagerV1> mgr = nullptr;
|
||||
SP<CCWpCursorShapeDeviceV1> dev = nullptr;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,8 +38,9 @@ CEGL::CEGL(wl_display* display) {
|
|||
if (eglCreatePlatformWindowSurfaceEXT == nullptr)
|
||||
throw std::runtime_error("Failed to get eglCreatePlatformWindowSurfaceEXT");
|
||||
|
||||
eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, display, nullptr);
|
||||
EGLint matched = 0;
|
||||
const char* vendorString = nullptr;
|
||||
eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, display, nullptr);
|
||||
EGLint matched = 0;
|
||||
if (eglDisplay == EGL_NO_DISPLAY) {
|
||||
Debug::log(CRIT, "Failed to create EGL display");
|
||||
goto error;
|
||||
|
|
@ -65,6 +66,9 @@ CEGL::CEGL(wl_display* display) {
|
|||
goto error;
|
||||
}
|
||||
|
||||
vendorString = eglQueryString(eglDisplay, EGL_VENDOR);
|
||||
m_isNvidia = (vendorString) ? std::string{vendorString}.contains("NVIDIA") : false;
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ class CEGL {
|
|||
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC eglCreatePlatformWindowSurfaceEXT;
|
||||
|
||||
void makeCurrent(EGLSurface surf);
|
||||
|
||||
bool m_isNvidia = false;
|
||||
};
|
||||
|
||||
inline UP<CEGL> g_pEGL;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
#include "../renderer/Renderer.hpp"
|
||||
|
||||
CSessionLockSurface::~CSessionLockSurface() {
|
||||
if (frameCallback)
|
||||
frameCallback.reset();
|
||||
|
||||
if (eglSurface)
|
||||
eglDestroySurface(g_pEGL->eglDisplay, eglSurface);
|
||||
|
||||
if (eglWindow)
|
||||
wl_egl_window_destroy(eglWindow);
|
||||
}
|
||||
|
|
@ -139,3 +145,7 @@ void CSessionLockSurface::onCallback() {
|
|||
render();
|
||||
}
|
||||
}
|
||||
|
||||
SP<CCWlSurface> CSessionLockSurface::getWlSurface() {
|
||||
return surface;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@ class CSessionLockSurface {
|
|||
CSessionLockSurface(const SP<COutput>& pOutput);
|
||||
~CSessionLockSurface();
|
||||
|
||||
void configure(const Vector2D& size, uint32_t serial);
|
||||
void configure(const Vector2D& size, uint32_t serial);
|
||||
|
||||
bool readyForFrame = false;
|
||||
bool readyForFrame = false;
|
||||
|
||||
float fractionalScale = 1.0;
|
||||
float fractionalScale = 1.0;
|
||||
|
||||
void render();
|
||||
void onCallback();
|
||||
void onScaleUpdate();
|
||||
void render();
|
||||
void onCallback();
|
||||
void onScaleUpdate();
|
||||
SP<CCWlSurface> getWlSurface();
|
||||
|
||||
private:
|
||||
WP<COutput> m_outputRef;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@
|
|||
#include <chrono>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
CSeatManager::~CSeatManager() {
|
||||
if (m_pCursorShape && m_pCursorShape->shapeChanged)
|
||||
m_pCursorShape->setShape(wpCursorShapeDeviceV1Shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
|
||||
|
||||
if (m_pXKBState)
|
||||
xkb_state_unref(m_pXKBState);
|
||||
if (m_pXKBKeymap)
|
||||
|
|
@ -26,7 +30,13 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
if (caps & WL_SEAT_CAPABILITY_POINTER) {
|
||||
m_pPointer = makeShared<CCWlPointer>(r->sendGetPointer());
|
||||
|
||||
static const auto HIDECURSOR = g_pConfigManager->getValue<Hyprlang::INT>("general:hide_cursor");
|
||||
m_pPointer->setMotion([](CCWlPointer* r, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||
g_pHyprlock->m_vMouseLocation = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)};
|
||||
|
||||
if (!*HIDECURSOR)
|
||||
g_pHyprlock->onHover(g_pHyprlock->m_vMouseLocation);
|
||||
|
||||
if (std::chrono::system_clock::now() > g_pHyprlock->m_tGraceEnds)
|
||||
return;
|
||||
|
||||
|
|
@ -40,19 +50,43 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
if (!m_pCursorShape)
|
||||
return;
|
||||
|
||||
static const auto HIDE = g_pConfigManager->getValue<Hyprlang::INT>("general:hide_cursor");
|
||||
|
||||
m_pCursorShape->lastCursorSerial = serial;
|
||||
|
||||
if (*HIDE)
|
||||
if (*HIDECURSOR)
|
||||
m_pCursorShape->hideCursor();
|
||||
else
|
||||
m_pCursorShape->setShape(wpCursorShapeDeviceV1Shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
|
||||
|
||||
g_pHyprlock->m_vLastEnterCoords = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)};
|
||||
|
||||
if (*HIDECURSOR)
|
||||
return;
|
||||
|
||||
for (const auto& POUTPUT : g_pHyprlock->m_vOutputs) {
|
||||
if (!POUTPUT->m_sessionLockSurface)
|
||||
continue;
|
||||
|
||||
const auto& PWLSURFACE = POUTPUT->m_sessionLockSurface->getWlSurface();
|
||||
if (PWLSURFACE->resource() == surf)
|
||||
g_pHyprlock->m_focusedOutput = POUTPUT;
|
||||
}
|
||||
});
|
||||
|
||||
m_pPointer->setLeave([](CCWlPointer* r, uint32_t serial, wl_proxy* surf) { g_pHyprlock->m_focusedOutput.reset(); });
|
||||
|
||||
m_pPointer->setButton([](CCWlPointer* r, uint32_t serial, uint32_t time, uint32_t button, wl_pointer_button_state state) {
|
||||
if (*HIDECURSOR)
|
||||
return;
|
||||
g_pHyprlock->onClick(button, state == WL_POINTER_BUTTON_STATE_PRESSED, g_pHyprlock->m_vMouseLocation);
|
||||
});
|
||||
}
|
||||
|
||||
if (caps & WL_SEAT_CAPABILITY_TOUCH) {
|
||||
m_pTouch = makeShared<CCWlTouch>(r->sendGetTouch());
|
||||
m_pTouch->setDown([](CCWlTouch* r, uint32_t serial, uint32_t time, wl_proxy* surface, int32_t id, wl_fixed_t x, wl_fixed_t y) {
|
||||
g_pHyprlock->onClick(BTN_LEFT, true, {wl_fixed_to_double(x), wl_fixed_to_double(y)});
|
||||
});
|
||||
m_pTouch->setUp([](CCWlTouch* r, uint32_t serial, uint32_t time, int32_t id) { g_pHyprlock->onClick(BTN_LEFT, false, {0, 0}); });
|
||||
};
|
||||
if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
|
||||
m_pKeeb = makeShared<CCWlKeyboard>(r->sendGetKeyboard());
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class CSeatManager {
|
|||
|
||||
SP<CCWlKeyboard> m_pKeeb;
|
||||
SP<CCWlPointer> m_pPointer;
|
||||
SP<CCWlTouch> m_pTouch;
|
||||
|
||||
UP<CCursorShape> m_pCursorShape;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "Timer.hpp"
|
||||
|
||||
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_, bool force) :
|
||||
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data_, bool force) :
|
||||
cb(cb_), data(data_), allowForceUpdate(force) {
|
||||
expires = std::chrono::system_clock::now() + timeout;
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ bool CTimer::cancelled() {
|
|||
return wasCancelled;
|
||||
}
|
||||
|
||||
void CTimer::call(std::shared_ptr<CTimer> self) {
|
||||
void CTimer::call(ASP<CTimer> self) {
|
||||
cb(self, data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CTimer {
|
||||
public:
|
||||
CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_, bool force);
|
||||
CTimer(std::chrono::system_clock::duration timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data_, bool force);
|
||||
|
||||
void cancel();
|
||||
bool passed();
|
||||
|
|
@ -14,12 +15,12 @@ class CTimer {
|
|||
float leftMs();
|
||||
|
||||
bool cancelled();
|
||||
void call(std::shared_ptr<CTimer> self);
|
||||
void call(ASP<CTimer> self);
|
||||
|
||||
private:
|
||||
std::function<void(std::shared_ptr<CTimer> self, void* data)> cb;
|
||||
void* data = nullptr;
|
||||
std::chrono::system_clock::time_point expires;
|
||||
bool wasCancelled = false;
|
||||
bool allowForceUpdate = false;
|
||||
std::function<void(ASP<CTimer> self, void* data)> cb;
|
||||
void* data = nullptr;
|
||||
std::chrono::system_clock::time_point expires;
|
||||
bool wasCancelled = false;
|
||||
bool allowForceUpdate = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
#include "hyprlock.hpp"
|
||||
#include "AnimationManager.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
#include "../renderer/AsyncResourceManager.hpp"
|
||||
#include "../auth/Auth.hpp"
|
||||
#include "../auth/Fingerprint.hpp"
|
||||
#include "Egl.hpp"
|
||||
#include "./Egl.hpp"
|
||||
#include "./Seat.hpp"
|
||||
#include <chrono>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/poll.h>
|
||||
|
|
@ -16,8 +18,6 @@
|
|||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <xf86drm.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include <hyprutils/os/Process.hpp>
|
||||
|
|
@ -35,7 +35,7 @@ static void setMallocThreshold() {
|
|||
#endif
|
||||
}
|
||||
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender) {
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediateRender, const int graceSeconds) {
|
||||
setMallocThreshold();
|
||||
|
||||
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
|
||||
|
|
@ -43,10 +43,9 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b
|
|||
|
||||
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
|
||||
|
||||
if (!immediate) {
|
||||
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace");
|
||||
m_tGraceEnds = *GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(*GRACE) : std::chrono::system_clock::from_time_t(0);
|
||||
} else
|
||||
if (graceSeconds > 0)
|
||||
m_tGraceEnds = std::chrono::system_clock::now() + std::chrono::seconds(graceSeconds);
|
||||
else
|
||||
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
|
||||
|
||||
static const auto IMMEDIATERENDER = g_pConfigManager->getValue<Hyprlang::INT>("general:immediate_render");
|
||||
|
|
@ -238,6 +237,18 @@ void CHyprlock::addDmabufListener() {
|
|||
});
|
||||
}
|
||||
|
||||
void CHyprlock::removeDmabufListener() {
|
||||
if (dma.linuxDmabufFeedback) {
|
||||
dma.linuxDmabufFeedback->sendDestroy();
|
||||
dma.linuxDmabufFeedback.reset();
|
||||
}
|
||||
|
||||
if (dma.linuxDmabuf) {
|
||||
dma.linuxDmabuf->sendDestroy();
|
||||
dma.linuxDmabuf.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprlock::run() {
|
||||
m_sWaylandState.registry = makeShared<CCWlRegistry>((wl_proxy*)wl_display_get_registry(m_sWaylandState.display));
|
||||
m_sWaylandState.registry->setGlobal([this](CCWlRegistry* r, uint32_t name, const char* interface, uint32_t version) {
|
||||
|
|
@ -307,32 +318,26 @@ void CHyprlock::run() {
|
|||
// gather info about monitors
|
||||
wl_display_roundtrip(m_sWaylandState.display);
|
||||
|
||||
g_pRenderer = makeUnique<CRenderer>();
|
||||
g_pAuth = makeUnique<CAuth>();
|
||||
g_pRenderer = makeUnique<CRenderer>();
|
||||
g_asyncResourceManager = makeUnique<CAsyncResourceManager>();
|
||||
g_pAuth = makeUnique<CAuth>();
|
||||
g_pAuth->start();
|
||||
|
||||
Debug::log(LOG, "Running on {}", m_sCurrentDesktop);
|
||||
|
||||
// Hyprland violates the protocol a bit to allow for this.
|
||||
if (m_sCurrentDesktop != "Hyprland") {
|
||||
while (!g_pRenderer->asyncResourceGatherer->gathered) {
|
||||
wl_display_flush(m_sWaylandState.display);
|
||||
if (wl_display_prepare_read(m_sWaylandState.display) == 0) {
|
||||
wl_display_read_events(m_sWaylandState.display);
|
||||
wl_display_dispatch_pending(m_sWaylandState.display);
|
||||
} else {
|
||||
wl_display_dispatch(m_sWaylandState.display);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
g_asyncResourceManager->enqueueStaticAssets();
|
||||
g_asyncResourceManager->enqueueScreencopyFrames();
|
||||
|
||||
if (!g_pHyprlock->m_bImmediateRender)
|
||||
// Gather background resources and screencopy frames before locking the screen.
|
||||
// We need to do this because as soon as we lock the screen, workspaces frames can no longer be captured. It either won't work at all, or we will capture hyprlock itself.
|
||||
// Bypass with --immediate-render (can cause the background first rendering a solid color and missing or inaccurate screencopy frames)
|
||||
g_asyncResourceManager->gatherInitialResources(m_sWaylandState.display);
|
||||
|
||||
// Failed to lock the session
|
||||
if (!acquireSessionLock()) {
|
||||
m_sLoopState.timerEvent = true;
|
||||
m_sLoopState.timerCV.notify_all();
|
||||
g_pRenderer->asyncResourceGatherer->notify();
|
||||
g_pRenderer->asyncResourceGatherer->await();
|
||||
g_pAuth->terminate();
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -442,43 +447,21 @@ void CHyprlock::run() {
|
|||
}
|
||||
}
|
||||
|
||||
// do timers
|
||||
m_sLoopState.timersMutex.lock();
|
||||
auto timerscpy = m_vTimers;
|
||||
m_sLoopState.timersMutex.unlock();
|
||||
|
||||
std::vector<std::shared_ptr<CTimer>> passed;
|
||||
|
||||
for (auto& t : timerscpy) {
|
||||
if (t->passed() && !t->cancelled()) {
|
||||
t->call(t);
|
||||
passed.push_back(t);
|
||||
}
|
||||
|
||||
if (t->cancelled())
|
||||
passed.push_back(t);
|
||||
}
|
||||
|
||||
m_sLoopState.timersMutex.lock();
|
||||
std::erase_if(m_vTimers, [passed](const auto& timer) { return std::find(passed.begin(), passed.end(), timer) != passed.end(); });
|
||||
m_sLoopState.timersMutex.unlock();
|
||||
|
||||
passed.clear();
|
||||
processTimers();
|
||||
}
|
||||
|
||||
const auto DPY = m_sWaylandState.display;
|
||||
|
||||
m_sLoopState.timerEvent = true;
|
||||
m_sLoopState.timerCV.notify_all();
|
||||
g_pRenderer->asyncResourceGatherer->notify();
|
||||
g_pRenderer->asyncResourceGatherer->await();
|
||||
m_sWaylandState = {};
|
||||
dma = {};
|
||||
|
||||
m_vOutputs.clear();
|
||||
g_pEGL.reset();
|
||||
g_pRenderer.reset();
|
||||
g_pSeatManager.reset();
|
||||
g_asyncResourceManager.reset();
|
||||
g_pRenderer.reset();
|
||||
g_pEGL.reset();
|
||||
|
||||
wl_display_disconnect(DPY);
|
||||
|
||||
|
|
@ -499,16 +482,13 @@ void CHyprlock::unlock() {
|
|||
return;
|
||||
}
|
||||
|
||||
const bool IMMEDIATE = m_sCurrentDesktop != "Hyprland";
|
||||
|
||||
g_pRenderer->startFadeOut(true, IMMEDIATE);
|
||||
m_bUnlockedCalled = true;
|
||||
g_pRenderer->startFadeOut(true);
|
||||
|
||||
renderAllOutputs();
|
||||
}
|
||||
|
||||
bool CHyprlock::isUnlocked() {
|
||||
return m_bUnlockedCalled || m_bTerminate;
|
||||
return !m_bLocked;
|
||||
}
|
||||
|
||||
void CHyprlock::clearPasswordBuffer() {
|
||||
|
|
@ -555,7 +535,7 @@ void CHyprlock::startKeyRepeat(xkb_keysym_t sym) {
|
|||
if (m_iKeebRepeatDelay <= 0)
|
||||
return;
|
||||
|
||||
m_pKeyRepeatTimer = addTimer(std::chrono::milliseconds(m_iKeebRepeatDelay), [sym](std::shared_ptr<CTimer> self, void* data) { g_pHyprlock->repeatKey(sym); }, nullptr);
|
||||
m_pKeyRepeatTimer = addTimer(std::chrono::milliseconds(m_iKeebRepeatDelay), [sym](ASP<CTimer> self, void* data) { g_pHyprlock->repeatKey(sym); }, nullptr);
|
||||
}
|
||||
|
||||
void CHyprlock::repeatKey(xkb_keysym_t sym) {
|
||||
|
|
@ -566,7 +546,7 @@ void CHyprlock::repeatKey(xkb_keysym_t sym) {
|
|||
|
||||
// This condition is for backspace and delete keys, but should also be ok for other keysyms since our buffer won't be empty anyways
|
||||
if (bool CONTINUE = m_sPasswordState.passBuffer.length() > 0; CONTINUE)
|
||||
m_pKeyRepeatTimer = addTimer(std::chrono::milliseconds(m_iKeebRepeatRate), [sym](std::shared_ptr<CTimer> self, void* data) { g_pHyprlock->repeatKey(sym); }, nullptr);
|
||||
m_pKeyRepeatTimer = addTimer(std::chrono::milliseconds(m_iKeebRepeatRate), [sym](ASP<CTimer> self, void* data) { g_pHyprlock->repeatKey(sym); }, nullptr);
|
||||
|
||||
renderAllOutputs();
|
||||
}
|
||||
|
|
@ -633,7 +613,7 @@ void CHyprlock::onKey(uint32_t key, bool down) {
|
|||
void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
||||
const auto SYM = sym;
|
||||
|
||||
if (SYM == XKB_KEY_Escape || (m_bCtrl && (SYM == XKB_KEY_u || SYM == XKB_KEY_BackSpace))) {
|
||||
if (SYM == XKB_KEY_Escape || (m_bCtrl && (SYM == XKB_KEY_u || SYM == XKB_KEY_BackSpace || SYM == XKB_KEY_a))) {
|
||||
Debug::log(LOG, "Clearing password buffer");
|
||||
|
||||
m_sPasswordState.passBuffer = "";
|
||||
|
|
@ -669,6 +649,64 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
|||
}
|
||||
}
|
||||
|
||||
void CHyprlock::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
if (!down)
|
||||
return;
|
||||
|
||||
if (!m_focusedOutput.lock())
|
||||
return;
|
||||
|
||||
// TODO: add the UNLIKELY marco from Hyprland
|
||||
if (!m_focusedOutput->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
const auto SCALEDPOS = pos * m_focusedOutput->m_sessionLockSurface->fractionalScale;
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*m_focusedOutput->m_sessionLockSurface);
|
||||
for (const auto& widget : widgets) {
|
||||
if (widget->containsPoint(SCALEDPOS))
|
||||
widget->onClick(button, down, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprlock::onHover(const Vector2D& pos) {
|
||||
if (!m_focusedOutput.lock())
|
||||
return;
|
||||
|
||||
if (!m_focusedOutput->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
bool outputNeedsRedraw = false;
|
||||
bool cursorChanged = false;
|
||||
|
||||
const auto SCALEDPOS = pos * m_focusedOutput->m_sessionLockSurface->fractionalScale;
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*m_focusedOutput->m_sessionLockSurface);
|
||||
for (const auto& widget : widgets) {
|
||||
const bool CONTAINSPOINT = widget->containsPoint(SCALEDPOS);
|
||||
const bool HOVERED = widget->isHovered();
|
||||
|
||||
if (CONTAINSPOINT) {
|
||||
if (!HOVERED) {
|
||||
widget->setHover(true);
|
||||
widget->onHover(pos);
|
||||
outputNeedsRedraw = true;
|
||||
}
|
||||
|
||||
if (!cursorChanged)
|
||||
cursorChanged = true;
|
||||
|
||||
} else if (HOVERED) {
|
||||
widget->setHover(false);
|
||||
outputNeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cursorChanged)
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
|
||||
|
||||
if (outputNeedsRedraw)
|
||||
m_focusedOutput->m_sessionLockSurface->render();
|
||||
}
|
||||
|
||||
bool CHyprlock::acquireSessionLock() {
|
||||
Debug::log(LOG, "Locking session");
|
||||
m_sLockState.lock = makeShared<CCExtSessionLockV1>(m_sWaylandState.sessionLock->sendLock());
|
||||
|
|
@ -790,23 +828,47 @@ size_t CHyprlock::getPasswordBufferDisplayLen() {
|
|||
return std::count_if(m_sPasswordState.passBuffer.begin(), m_sPasswordState.passBuffer.end(), [](char c) { return (c & 0xc0) != 0x80; });
|
||||
}
|
||||
|
||||
std::shared_ptr<CTimer> CHyprlock::addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data,
|
||||
bool force) {
|
||||
ASP<CTimer> CHyprlock::addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data, bool force) {
|
||||
std::lock_guard<std::mutex> lg(m_sLoopState.timersMutex);
|
||||
const auto T = m_vTimers.emplace_back(std::make_shared<CTimer>(timeout, cb_, data, force));
|
||||
const auto T = m_vTimers.emplace_back(makeAtomicShared<CTimer>(timeout, cb_, data, force));
|
||||
m_sLoopState.timerEvent = true;
|
||||
m_sLoopState.timerCV.notify_all();
|
||||
return T;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<CTimer>> CHyprlock::getTimers() {
|
||||
void CHyprlock::processTimers() {
|
||||
// do timers
|
||||
m_sLoopState.timersMutex.lock();
|
||||
auto timerscpy = m_vTimers;
|
||||
m_sLoopState.timersMutex.unlock();
|
||||
|
||||
std::vector<ASP<CTimer>> passed;
|
||||
|
||||
for (auto& t : timerscpy) {
|
||||
if (t->passed() && !t->cancelled()) {
|
||||
t->call(t);
|
||||
passed.push_back(t);
|
||||
}
|
||||
|
||||
if (t->cancelled())
|
||||
passed.push_back(t);
|
||||
}
|
||||
|
||||
m_sLoopState.timersMutex.lock();
|
||||
std::erase_if(m_vTimers, [passed](const auto& timer) { return std::find(passed.begin(), passed.end(), timer) != passed.end(); });
|
||||
m_sLoopState.timersMutex.unlock();
|
||||
|
||||
passed.clear();
|
||||
}
|
||||
|
||||
std::vector<ASP<CTimer>> CHyprlock::getTimers() {
|
||||
return m_vTimers;
|
||||
}
|
||||
|
||||
void CHyprlock::enqueueForceUpdateTimers() {
|
||||
addTimer(
|
||||
std::chrono::milliseconds(1),
|
||||
[](std::shared_ptr<CTimer> self, void* data) {
|
||||
[](ASP<CTimer> self, void* data) {
|
||||
for (auto& t : g_pHyprlock->getTimers()) {
|
||||
if (t->canForceUpdate()) {
|
||||
t->call(t);
|
||||
|
|
@ -817,19 +879,6 @@ void CHyprlock::enqueueForceUpdateTimers() {
|
|||
nullptr, false);
|
||||
}
|
||||
|
||||
std::string CHyprlock::spawnSync(const std::string& cmd) {
|
||||
CProcess proc("/bin/sh", {"-c", cmd});
|
||||
if (!proc.runSync()) {
|
||||
Debug::log(ERR, "Failed to run \"{}\"", cmd);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!proc.stdErr().empty())
|
||||
Debug::log(ERR, "Shell command \"{}\" STDERR:\n{}", cmd, proc.stdErr());
|
||||
|
||||
return proc.stdOut();
|
||||
}
|
||||
|
||||
SP<CCZwlrScreencopyManagerV1> CHyprlock::getScreencopy() {
|
||||
return m_sWaylandState.screencopy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@
|
|||
#include "linux-dmabuf-v1.hpp"
|
||||
#include "viewporter.hpp"
|
||||
#include "Output.hpp"
|
||||
#include "Seat.hpp"
|
||||
#include "CursorShape.hpp"
|
||||
#include "Timer.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <condition_variable>
|
||||
#include <optional>
|
||||
|
|
@ -29,41 +26,41 @@ struct SDMABUFModifier {
|
|||
|
||||
class CHyprlock {
|
||||
public:
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender);
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediateRender, const int gracePeriod);
|
||||
~CHyprlock();
|
||||
|
||||
void run();
|
||||
void run();
|
||||
|
||||
void unlock();
|
||||
bool isUnlocked();
|
||||
void unlock();
|
||||
bool isUnlocked();
|
||||
|
||||
std::shared_ptr<CTimer> addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data,
|
||||
bool force = false);
|
||||
ASP<CTimer> addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data, bool force = false);
|
||||
void processTimers();
|
||||
|
||||
void enqueueForceUpdateTimers();
|
||||
void enqueueForceUpdateTimers();
|
||||
|
||||
void onLockLocked();
|
||||
void onLockFinished();
|
||||
void onLockLocked();
|
||||
void onLockFinished();
|
||||
|
||||
bool acquireSessionLock();
|
||||
void releaseSessionLock();
|
||||
bool acquireSessionLock();
|
||||
void releaseSessionLock();
|
||||
|
||||
std::string spawnSync(const std::string& cmd);
|
||||
void onKey(uint32_t key, bool down);
|
||||
void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
void onHover(const Vector2D& pos);
|
||||
void startKeyRepeat(xkb_keysym_t sym);
|
||||
void repeatKey(xkb_keysym_t sym);
|
||||
void handleKeySym(xkb_keysym_t sym, bool compose);
|
||||
void onPasswordCheckTimer();
|
||||
void clearPasswordBuffer();
|
||||
bool passwordCheckWaiting();
|
||||
std::optional<std::string> passwordLastFailReason();
|
||||
|
||||
void onKey(uint32_t key, bool down);
|
||||
void startKeyRepeat(xkb_keysym_t sym);
|
||||
void repeatKey(xkb_keysym_t sym);
|
||||
void handleKeySym(xkb_keysym_t sym, bool compose);
|
||||
void onPasswordCheckTimer();
|
||||
void clearPasswordBuffer();
|
||||
bool passwordCheckWaiting();
|
||||
std::optional<std::string> passwordLastFailReason();
|
||||
void renderOutput(const std::string& stringPort);
|
||||
void renderAllOutputs();
|
||||
|
||||
void renderOutput(const std::string& stringPort);
|
||||
void renderAllOutputs();
|
||||
|
||||
size_t getPasswordBufferLen();
|
||||
size_t getPasswordBufferDisplayLen();
|
||||
size_t getPasswordBufferLen();
|
||||
size_t getPasswordBufferDisplayLen();
|
||||
|
||||
SP<CCExtSessionLockManagerV1> getSessionLockMgr();
|
||||
SP<CCExtSessionLockV1> getSessionLock();
|
||||
|
|
@ -95,11 +92,14 @@ class CHyprlock {
|
|||
//
|
||||
std::chrono::system_clock::time_point m_tGraceEnds;
|
||||
Vector2D m_vLastEnterCoords = {};
|
||||
WP<COutput> m_focusedOutput;
|
||||
|
||||
std::shared_ptr<CTimer> m_pKeyRepeatTimer = nullptr;
|
||||
Vector2D m_vMouseLocation = {};
|
||||
|
||||
ASP<CTimer> m_pKeyRepeatTimer = nullptr;
|
||||
|
||||
std::vector<SP<COutput>> m_vOutputs;
|
||||
std::vector<std::shared_ptr<CTimer>> getTimers();
|
||||
std::vector<ASP<CTimer>> getTimers();
|
||||
|
||||
struct {
|
||||
SP<CCZwpLinuxDmabufV1> linuxDmabuf = nullptr;
|
||||
|
|
@ -116,6 +116,9 @@ class CHyprlock {
|
|||
} dma;
|
||||
gbm_device* createGBMDevice(drmDevice* dev);
|
||||
|
||||
void addDmabufListener();
|
||||
void removeDmabufListener();
|
||||
|
||||
private:
|
||||
struct {
|
||||
wl_display* display = nullptr;
|
||||
|
|
@ -128,8 +131,6 @@ class CHyprlock {
|
|||
SP<CCWlShm> shm = nullptr;
|
||||
} m_sWaylandState;
|
||||
|
||||
void addDmabufListener();
|
||||
|
||||
struct {
|
||||
SP<CCExtSessionLockV1> lock = nullptr;
|
||||
} m_sLockState;
|
||||
|
|
@ -155,11 +156,9 @@ class CHyprlock {
|
|||
bool timerEvent = false;
|
||||
} m_sLoopState;
|
||||
|
||||
bool m_bUnlockedCalled = false;
|
||||
std::vector<ASP<CTimer>> m_vTimers;
|
||||
|
||||
std::vector<std::shared_ptr<CTimer>> m_vTimers;
|
||||
|
||||
std::vector<uint32_t> m_vPressedKeys;
|
||||
std::vector<uint32_t> m_vPressedKeys;
|
||||
};
|
||||
|
||||
inline UP<CHyprlock> g_pHyprlock;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,20 @@
|
|||
|
||||
#include <hyprutils/memory/WeakPtr.hpp>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <hyprutils/memory/Atomic.hpp>
|
||||
#include <hyprgraphics/color/Color.hpp>
|
||||
|
||||
using namespace Hyprutils::Memory;
|
||||
using namespace Hyprgraphics;
|
||||
|
||||
using ResourceID = size_t;
|
||||
|
||||
#define SP CSharedPointer
|
||||
#define WP CWeakPointer
|
||||
#define UP CUniquePointer
|
||||
|
||||
#define ASP CAtomicSharedPointer
|
||||
#define AWP CAtomicWeakPointer
|
||||
|
||||
typedef int64_t OUTPUTID;
|
||||
constexpr OUTPUTID OUTPUT_INVALID = -1;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ template <Animable VarType>
|
|||
using CAnimatedVariable = Hyprutils::Animation::CGenericAnimatedVariable<VarType, SAnimationContext>;
|
||||
|
||||
template <Animable VarType>
|
||||
using PHLANIMVAR = SP<CAnimatedVariable<VarType>>;
|
||||
using PHLANIMVAR = UP<CAnimatedVariable<VarType>>;
|
||||
|
||||
template <Animable VarType>
|
||||
using PHLANIMVARREF = WP<CAnimatedVariable<VarType>>;
|
||||
|
|
|
|||
|
|
@ -51,4 +51,4 @@ namespace Debug {
|
|||
std::println("[{}] {}", logLevelString(level), std::vformat(fmt, std::make_format_args(args...)));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@
|
|||
#include "MiscFunctions.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <hyprutils/os/Process.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace Hyprutils::String;
|
||||
using namespace Hyprutils::OS;
|
||||
|
||||
std::string absolutePath(const std::string& rawpath, const std::string& currentDir) {
|
||||
std::filesystem::path path(rawpath);
|
||||
|
|
@ -137,3 +139,22 @@ int createPoolFile(size_t size, std::string& name) {
|
|||
|
||||
return FD;
|
||||
}
|
||||
|
||||
std::string spawnSync(const std::string& cmd) {
|
||||
CProcess proc("/bin/sh", {"-c", cmd});
|
||||
if (!proc.runSync()) {
|
||||
Debug::log(ERR, "Failed to run \"{}\"", cmd);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!proc.stdErr().empty())
|
||||
Debug::log(ERR, "Shell command \"{}\" STDERR:\n{}", cmd, proc.stdErr());
|
||||
|
||||
return proc.stdOut();
|
||||
}
|
||||
|
||||
void spawnAsync(const std::string& cmd) {
|
||||
CProcess proc("/bin/sh", {"-c", cmd});
|
||||
if (!proc.runAsync())
|
||||
Debug::log(ERR, "Failed to start \"{}\"", cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,5 @@
|
|||
std::string absolutePath(const std::string&, const std::string&);
|
||||
int64_t configStringToInt(const std::string& VALUE);
|
||||
int createPoolFile(size_t size, std::string& name);
|
||||
std::string spawnSync(const std::string& cmd);
|
||||
void spawnAsync(const std::string& cmd);
|
||||
|
|
|
|||
27
src/main.cpp
27
src/main.cpp
|
|
@ -13,7 +13,7 @@ void help() {
|
|||
" -q, --quiet - Disable logging\n"
|
||||
" -c FILE, --config FILE - Specify config file to use\n"
|
||||
" --display NAME - Specify the Wayland display to connect to\n"
|
||||
" --immediate - Lock immediately, ignoring any configured grace period\n"
|
||||
" --grace SECONDS - Set grace period in seconds before requiring authentication\n"
|
||||
" --immediate-render - Do not wait for resources before drawing the background\n"
|
||||
" --no-fade-in - Disable the fade-in animation when the lock screen appears\n"
|
||||
" -V, --version - Show version information\n"
|
||||
|
|
@ -40,9 +40,9 @@ static void printVersion() {
|
|||
int main(int argc, char** argv, char** envp) {
|
||||
std::string configPath;
|
||||
std::string wlDisplay;
|
||||
bool immediate = false;
|
||||
bool immediateRender = false;
|
||||
bool noFadeIn = false;
|
||||
int graceSeconds = 0;
|
||||
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
|
||||
|
|
@ -77,8 +77,25 @@ int main(int argc, char** argv, char** envp) {
|
|||
else
|
||||
return 1;
|
||||
|
||||
} else if (arg == "--immediate")
|
||||
immediate = true;
|
||||
} else if (arg == "--grace" && i + 1 < (std::size_t)argc) {
|
||||
if (auto value = parseArg(args, arg, i); value) {
|
||||
try {
|
||||
graceSeconds = std::stoi(*value);
|
||||
if (graceSeconds < 0) {
|
||||
std::println(stderr, "Error: Grace period must be non-negative.");
|
||||
return 1;
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
std::println(stderr, "Error: Invalid grace period value: {}", *value);
|
||||
return 1;
|
||||
}
|
||||
} else
|
||||
return 1;
|
||||
|
||||
} else if (arg == "--immediate") {
|
||||
graceSeconds = 0;
|
||||
Debug::log(WARN, R"("--immediate" is deprecated. Use the "--grace" option instead.)");
|
||||
}
|
||||
|
||||
else if (arg == "--immediate-render")
|
||||
immediateRender = true;
|
||||
|
|
@ -111,7 +128,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediateRender, graceSeconds);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
|
|
|
|||
|
|
@ -1,368 +0,0 @@
|
|||
#include "AsyncResourceGatherer.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include <cairo/cairo.h>
|
||||
#include <magic.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include "../core/hyprlock.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "src/helpers/Color.hpp"
|
||||
#include "src/helpers/Log.hpp"
|
||||
#include <hyprgraphics/image/Image.hpp>
|
||||
using namespace Hyprgraphics;
|
||||
|
||||
CAsyncResourceGatherer::CAsyncResourceGatherer() {
|
||||
if (g_pHyprlock->getScreencopy())
|
||||
enqueueScreencopyFrames();
|
||||
|
||||
initialGatherThread = std::thread([this]() { this->gather(); });
|
||||
asyncLoopThread = std::thread([this]() { this->asyncAssetSpinLock(); });
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::enqueueScreencopyFrames() {
|
||||
// some things can't be done async :(
|
||||
// gather background textures when needed
|
||||
|
||||
const auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
|
||||
|
||||
std::vector<std::string> mons;
|
||||
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (c.type != "background")
|
||||
continue;
|
||||
|
||||
if (std::string{std::any_cast<Hyprlang::STRING>(c.values.at("path"))} != "screenshot")
|
||||
continue;
|
||||
|
||||
// mamma mia
|
||||
if (c.monitor.empty()) {
|
||||
mons.clear();
|
||||
for (auto& m : g_pHyprlock->m_vOutputs) {
|
||||
mons.push_back(m->stringPort);
|
||||
}
|
||||
break;
|
||||
} else
|
||||
mons.push_back(c.monitor);
|
||||
}
|
||||
|
||||
for (auto& mon : mons) {
|
||||
const auto MON = std::ranges::find_if(g_pHyprlock->m_vOutputs, [mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
|
||||
|
||||
if (MON == g_pHyprlock->m_vOutputs.end())
|
||||
continue;
|
||||
|
||||
scframes.emplace_back(makeUnique<CScreencopyFrame>(*MON));
|
||||
}
|
||||
}
|
||||
|
||||
SPreloadedAsset* CAsyncResourceGatherer::getAssetByID(const std::string& id) {
|
||||
for (auto& a : assets) {
|
||||
if (a.first == id)
|
||||
return &a.second;
|
||||
}
|
||||
|
||||
if (apply()) {
|
||||
for (auto& a : assets) {
|
||||
if (a.first == id)
|
||||
return &a.second;
|
||||
}
|
||||
};
|
||||
|
||||
for (auto& frame : scframes) {
|
||||
if (id == frame->m_resourceID)
|
||||
return frame->m_asset.ready ? &frame->m_asset : nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SP<CCairoSurface> getCairoSurfaceFromImageFile(const std::filesystem::path& path) {
|
||||
|
||||
auto image = CImage(path);
|
||||
if (!image.success()) {
|
||||
Debug::log(ERR, "Image {} could not be loaded: {}", path.string(), image.getError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return image.cairoSurface();
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::gather() {
|
||||
const auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
|
||||
|
||||
g_pEGL->makeCurrent(nullptr);
|
||||
|
||||
// gather resources to preload
|
||||
// clang-format off
|
||||
int preloads = std::count_if(CWIDGETS.begin(), CWIDGETS.end(), [](const auto& w) {
|
||||
return w.type == "background" || w.type == "image";
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
progress = 0;
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (c.type == "background" || c.type == "image") {
|
||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 180100
|
||||
progress = progress + 1.0 / (preloads + 1.0);
|
||||
#else
|
||||
progress += 1.0 / (preloads + 1.0);
|
||||
#endif
|
||||
|
||||
std::string path = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
if (path.empty() || path == "screenshot")
|
||||
continue;
|
||||
|
||||
std::string id = (c.type == "background" ? std::string{"background:"} : std::string{"image:"}) + path;
|
||||
|
||||
// render the image directly, since we are in a seperate thread
|
||||
CAsyncResourceGatherer::SPreloadRequest rq;
|
||||
rq.type = CAsyncResourceGatherer::TARGET_IMAGE;
|
||||
rq.asset = path;
|
||||
rq.id = id;
|
||||
|
||||
renderImage(rq);
|
||||
}
|
||||
}
|
||||
|
||||
while (!g_pHyprlock->m_bTerminate && std::ranges::any_of(scframes, [](const auto& d) { return !d->m_asset.ready; })) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
gathered = true;
|
||||
}
|
||||
|
||||
bool CAsyncResourceGatherer::apply() {
|
||||
preloadTargetsMutex.lock();
|
||||
|
||||
if (preloadTargets.empty()) {
|
||||
preloadTargetsMutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
auto currentPreloadTargets = preloadTargets;
|
||||
preloadTargets.clear();
|
||||
preloadTargetsMutex.unlock();
|
||||
|
||||
for (auto& t : currentPreloadTargets) {
|
||||
if (t.type == TARGET_IMAGE) {
|
||||
const auto ASSET = &assets[t.id];
|
||||
|
||||
const cairo_status_t SURFACESTATUS = (cairo_status_t)t.cairosurface->status();
|
||||
const auto CAIROFORMAT = cairo_image_surface_get_format(t.cairosurface->cairo());
|
||||
const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB32F : GL_RGBA;
|
||||
const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA;
|
||||
const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE;
|
||||
|
||||
if (SURFACESTATUS != CAIRO_STATUS_SUCCESS) {
|
||||
Debug::log(ERR, "Resource {} invalid ({})", t.id, cairo_status_to_string(SURFACESTATUS));
|
||||
ASSET->texture.m_iType = TEXTURE_INVALID;
|
||||
}
|
||||
|
||||
ASSET->texture.m_vSize = t.size;
|
||||
ASSET->texture.allocate();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, ASSET->texture.m_iTexID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
if (CAIROFORMAT != CAIRO_FORMAT_RGB96F) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, glIFormat, ASSET->texture.m_vSize.x, ASSET->texture.m_vSize.y, 0, glFormat, glType, t.data);
|
||||
|
||||
cairo_destroy((cairo_t*)t.cairo);
|
||||
t.cairosurface.reset();
|
||||
} else
|
||||
Debug::log(ERR, "Unsupported type in ::apply(): {}", (int)t.type);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::renderImage(const SPreloadRequest& rq) {
|
||||
SPreloadTarget target;
|
||||
target.type = TARGET_IMAGE;
|
||||
target.id = rq.id;
|
||||
|
||||
std::filesystem::path ABSOLUTEPATH(absolutePath(rq.asset, ""));
|
||||
const auto CAIROISURFACE = getCairoSurfaceFromImageFile(ABSOLUTEPATH);
|
||||
|
||||
if (!CAIROISURFACE) {
|
||||
Debug::log(ERR, "renderImage: No cairo surface!");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto CAIRO = cairo_create(CAIROISURFACE->cairo());
|
||||
cairo_scale(CAIRO, 1, 1);
|
||||
|
||||
target.cairo = CAIRO;
|
||||
target.cairosurface = CAIROISURFACE;
|
||||
target.data = CAIROISURFACE->data();
|
||||
target.size = CAIROISURFACE->size();
|
||||
|
||||
std::lock_guard lg{preloadTargetsMutex};
|
||||
preloadTargets.push_back(target);
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
||||
SPreloadTarget target;
|
||||
target.type = TARGET_IMAGE; /* text is just an image lol */
|
||||
target.id = rq.id;
|
||||
|
||||
const int FONTSIZE = rq.props.contains("font_size") ? std::any_cast<int>(rq.props.at("font_size")) : 16;
|
||||
const CHyprColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CHyprColor>(rq.props.at("color")) : CHyprColor(1.0, 1.0, 1.0, 1.0);
|
||||
const std::string FONTFAMILY = rq.props.contains("font_family") ? std::any_cast<std::string>(rq.props.at("font_family")) : "Sans";
|
||||
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
|
||||
|
||||
static const auto TRIM = g_pConfigManager->getValue<Hyprlang::INT>("general:text_trim");
|
||||
std::string text = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
|
||||
|
||||
if (*TRIM) {
|
||||
text.erase(0, text.find_first_not_of(" \n\r\t"));
|
||||
text.erase(text.find_last_not_of(" \n\r\t") + 1);
|
||||
}
|
||||
|
||||
auto CAIROSURFACE = makeShared<CCairoSurface>(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1920, 1080 /* dummy value */));
|
||||
auto CAIRO = cairo_create(CAIROSURFACE->cairo());
|
||||
|
||||
// draw title using Pango
|
||||
PangoLayout* layout = pango_cairo_create_layout(CAIRO);
|
||||
|
||||
PangoFontDescription* fontDesc = pango_font_description_from_string(FONTFAMILY.c_str());
|
||||
pango_font_description_set_size(fontDesc, FONTSIZE * PANGO_SCALE);
|
||||
pango_layout_set_font_description(layout, fontDesc);
|
||||
pango_font_description_free(fontDesc);
|
||||
|
||||
if (rq.props.contains("text_align")) {
|
||||
const std::string TEXTALIGN = std::any_cast<std::string>(rq.props.at("text_align"));
|
||||
PangoAlignment align = PANGO_ALIGN_LEFT;
|
||||
if (TEXTALIGN == "center")
|
||||
align = PANGO_ALIGN_CENTER;
|
||||
else if (TEXTALIGN == "right")
|
||||
align = PANGO_ALIGN_RIGHT;
|
||||
|
||||
pango_layout_set_alignment(layout, align);
|
||||
}
|
||||
|
||||
PangoAttrList* attrList = nullptr;
|
||||
GError* gError = nullptr;
|
||||
char* buf = nullptr;
|
||||
if (pango_parse_markup(text.c_str(), -1, 0, &attrList, &buf, nullptr, &gError))
|
||||
pango_layout_set_text(layout, buf, -1);
|
||||
else {
|
||||
Debug::log(ERR, "Pango markup parsing for {} failed: {}", text, gError->message);
|
||||
g_error_free(gError);
|
||||
pango_layout_set_text(layout, text.c_str(), -1);
|
||||
}
|
||||
|
||||
if (!attrList)
|
||||
attrList = pango_attr_list_new();
|
||||
|
||||
if (buf)
|
||||
free(buf);
|
||||
|
||||
pango_attr_list_insert(attrList, pango_attr_scale_new(1));
|
||||
pango_layout_set_attributes(layout, attrList);
|
||||
pango_attr_list_unref(attrList);
|
||||
|
||||
int layoutWidth, layoutHeight;
|
||||
pango_layout_get_size(layout, &layoutWidth, &layoutHeight);
|
||||
|
||||
// TODO: avoid this?
|
||||
cairo_destroy(CAIRO);
|
||||
CAIROSURFACE = makeShared<CCairoSurface>(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, layoutWidth / PANGO_SCALE, layoutHeight / PANGO_SCALE));
|
||||
CAIRO = cairo_create(CAIROSURFACE->cairo());
|
||||
|
||||
// clear the pixmap
|
||||
cairo_save(CAIRO);
|
||||
cairo_set_operator(CAIRO, CAIRO_OPERATOR_CLEAR);
|
||||
cairo_paint(CAIRO);
|
||||
cairo_restore(CAIRO);
|
||||
|
||||
// render the thing
|
||||
cairo_set_source_rgba(CAIRO, FONTCOLOR.r, FONTCOLOR.g, FONTCOLOR.b, FONTCOLOR.a);
|
||||
|
||||
cairo_move_to(CAIRO, 0, 0);
|
||||
pango_cairo_show_layout(CAIRO, layout);
|
||||
|
||||
g_object_unref(layout);
|
||||
|
||||
cairo_surface_flush(CAIROSURFACE->cairo());
|
||||
|
||||
target.cairo = CAIRO;
|
||||
target.cairosurface = CAIROSURFACE;
|
||||
target.data = CAIROSURFACE->data();
|
||||
target.size = {layoutWidth / (double)PANGO_SCALE, layoutHeight / (double)PANGO_SCALE};
|
||||
|
||||
std::lock_guard lg{preloadTargetsMutex};
|
||||
preloadTargets.push_back(target);
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
||||
while (!g_pHyprlock->m_bTerminate) {
|
||||
|
||||
std::unique_lock lk(asyncLoopState.requestsMutex);
|
||||
if (!asyncLoopState.pending) // avoid a lock if a thread managed to request something already since we .unlock()ed
|
||||
asyncLoopState.requestsCV.wait_for(lk, std::chrono::seconds(5), [this] { return asyncLoopState.pending; }); // wait for events
|
||||
|
||||
asyncLoopState.pending = false;
|
||||
|
||||
if (asyncLoopState.requests.empty()) {
|
||||
lk.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
auto requests = asyncLoopState.requests;
|
||||
asyncLoopState.requests.clear();
|
||||
|
||||
lk.unlock();
|
||||
|
||||
// process requests
|
||||
for (auto& r : requests) {
|
||||
Debug::log(TRACE, "Processing requested resourceID {}", r.id);
|
||||
|
||||
if (r.type == TARGET_TEXT) {
|
||||
renderText(r);
|
||||
} else if (r.type == TARGET_IMAGE) {
|
||||
renderImage(r);
|
||||
} else {
|
||||
Debug::log(ERR, "Unsupported async preload type {}??", (int)r.type);
|
||||
continue;
|
||||
}
|
||||
|
||||
// plant timer for callback
|
||||
if (r.callback)
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [cb = r.callback](auto, auto) { cb(); }, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::requestAsyncAssetPreload(const SPreloadRequest& request) {
|
||||
Debug::log(TRACE, "Requesting label resource {}", request.id);
|
||||
|
||||
std::lock_guard<std::mutex> lg(asyncLoopState.requestsMutex);
|
||||
asyncLoopState.requests.push_back(request);
|
||||
asyncLoopState.pending = true;
|
||||
asyncLoopState.requestsCV.notify_all();
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::unloadAsset(SPreloadedAsset* asset) {
|
||||
std::erase_if(assets, [asset](const auto& a) { return &a.second == asset; });
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::notify() {
|
||||
std::lock_guard<std::mutex> lg(asyncLoopState.requestsMutex);
|
||||
asyncLoopState.requests.clear();
|
||||
asyncLoopState.pending = true;
|
||||
asyncLoopState.requestsCV.notify_all();
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::await() {
|
||||
if (initialGatherThread.joinable())
|
||||
initialGatherThread.join();
|
||||
if (asyncLoopThread.joinable())
|
||||
asyncLoopThread.join();
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Screencopy.hpp"
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <condition_variable>
|
||||
#include <any>
|
||||
#include "Shared.hpp"
|
||||
#include <hyprgraphics/cairo/CairoSurface.hpp>
|
||||
|
||||
class CAsyncResourceGatherer {
|
||||
public:
|
||||
CAsyncResourceGatherer();
|
||||
std::atomic<bool> gathered = false;
|
||||
|
||||
std::atomic<float> progress = 0;
|
||||
|
||||
/* only call from ogl thread */
|
||||
SPreloadedAsset* getAssetByID(const std::string& id);
|
||||
|
||||
bool apply();
|
||||
|
||||
enum eTargetType {
|
||||
TARGET_IMAGE = 0,
|
||||
TARGET_TEXT
|
||||
};
|
||||
|
||||
struct SPreloadRequest {
|
||||
eTargetType type;
|
||||
std::string asset;
|
||||
std::string id;
|
||||
|
||||
std::unordered_map<std::string, std::any> props;
|
||||
|
||||
// optional. Callbacks will be dispatched from the main thread,
|
||||
// so wayland/gl calls are OK.
|
||||
// will fire once the resource is fully loaded and ready.
|
||||
std::function<void()> callback = nullptr;
|
||||
};
|
||||
|
||||
void requestAsyncAssetPreload(const SPreloadRequest& request);
|
||||
void unloadAsset(SPreloadedAsset* asset);
|
||||
void notify();
|
||||
void await();
|
||||
|
||||
private:
|
||||
std::thread asyncLoopThread;
|
||||
std::thread initialGatherThread;
|
||||
|
||||
void asyncAssetSpinLock();
|
||||
void renderText(const SPreloadRequest& rq);
|
||||
void renderImage(const SPreloadRequest& rq);
|
||||
|
||||
struct {
|
||||
std::condition_variable requestsCV;
|
||||
std::mutex requestsMutex;
|
||||
|
||||
std::vector<SPreloadRequest> requests;
|
||||
bool pending = false;
|
||||
|
||||
bool busy = false;
|
||||
} asyncLoopState;
|
||||
|
||||
struct SPreloadTarget {
|
||||
eTargetType type = TARGET_IMAGE;
|
||||
std::string id = "";
|
||||
|
||||
void* data = nullptr;
|
||||
void* cairo = nullptr;
|
||||
SP<Hyprgraphics::CCairoSurface> cairosurface;
|
||||
|
||||
Vector2D size;
|
||||
};
|
||||
|
||||
std::vector<UP<CScreencopyFrame>> scframes;
|
||||
|
||||
std::vector<SPreloadTarget> preloadTargets;
|
||||
std::mutex preloadTargetsMutex;
|
||||
|
||||
std::unordered_map<std::string, SPreloadedAsset> assets;
|
||||
|
||||
void gather();
|
||||
void enqueueScreencopyFrames();
|
||||
};
|
||||
351
src/renderer/AsyncResourceManager.cpp
Normal file
351
src/renderer/AsyncResourceManager.cpp
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
#include "AsyncResourceManager.hpp"
|
||||
|
||||
#include "./resources/TextCmdResource.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "../core/hyprlock.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
using namespace Hyprgraphics;
|
||||
using namespace Hyprutils::OS;
|
||||
|
||||
static inline ResourceID scopeResourceID(uint8_t scope, size_t in) {
|
||||
return (in & ~0x0f) | scope;
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::resourceIDForTextRequest(const CTextResource::STextResourceData& s) {
|
||||
// TODO: Currently ignores the font string and resulting distribution is probably not perfect.
|
||||
const auto H1 = std::hash<std::string>{}(s.text);
|
||||
const auto H2 = std::hash<double>{}(s.color.asRgb().r);
|
||||
const auto H3 = std::hash<double>{}(s.color.asRgb().g) + s.fontSize;
|
||||
const auto H4 = std::hash<double>{}(s.color.asRgb().b) + s.align;
|
||||
|
||||
return scopeResourceID(1, H1 ^ (H2 << 1) ^ (H3 << 2) ^ (H4 << 3));
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::resourceIDForTextCmdRequest(const CTextResource::STextResourceData& s, size_t revision) {
|
||||
return scopeResourceID(2, resourceIDForTextRequest(s) ^ (revision << 32));
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::resourceIDForImageRequest(const std::string& path, size_t revision) {
|
||||
return scopeResourceID(3, std::hash<std::string>{}(path) ^ (revision << 32));
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::resourceIDForScreencopy(const std::string& port) {
|
||||
return scopeResourceID(4, std::hash<std::string>{}(port));
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::requestText(const CTextResource::STextResourceData& params, const AWP<IWidget>& widget) {
|
||||
const auto RESOURCEID = resourceIDForTextRequest(params);
|
||||
if (request(RESOURCEID, widget)) {
|
||||
Debug::log(TRACE, "Reusing text resource \"{}\" (resourceID: {})", params.text, RESOURCEID, (uintptr_t)widget.get());
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
auto resource = makeAtomicShared<CTextResource>(CTextResource::STextResourceData{params});
|
||||
CAtomicSharedPointer<IAsyncResource> resourceGeneric{resource};
|
||||
|
||||
Debug::log(TRACE, "Requesting text resource \"{}\" (resourceID: {})", params.text, RESOURCEID, (uintptr_t)widget.get());
|
||||
enqueue(RESOURCEID, resourceGeneric, widget);
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::requestTextCmd(const CTextResource::STextResourceData& params, size_t revision, const AWP<IWidget>& widget) {
|
||||
const auto RESOURCEID = resourceIDForTextCmdRequest(params, revision);
|
||||
if (request(RESOURCEID, widget)) {
|
||||
Debug::log(TRACE, "Reusing text cmd resource \"{}\" revision {} (resourceID: {})", params.text, revision, RESOURCEID, (uintptr_t)widget.get());
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
auto resource = makeAtomicShared<CTextCmdResource>(CTextResource::STextResourceData{params});
|
||||
CAtomicSharedPointer<IAsyncResource> resourceGeneric{resource};
|
||||
|
||||
Debug::log(TRACE, "Requesting text cmd resource \"{}\" revision {} (resourceID: {})", params.text, revision, RESOURCEID, (uintptr_t)widget.get());
|
||||
enqueue(RESOURCEID, resourceGeneric, widget);
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
ResourceID CAsyncResourceManager::requestImage(const std::string& path, size_t revision, const AWP<IWidget>& widget) {
|
||||
const auto RESOURCEID = resourceIDForImageRequest(path, revision);
|
||||
if (request(RESOURCEID, widget)) {
|
||||
Debug::log(TRACE, "Reusing image resource {} revision {} (resourceID: {})", path, revision, RESOURCEID, (uintptr_t)widget.get());
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
auto resource = makeAtomicShared<CImageResource>(absolutePath(path, ""));
|
||||
CAtomicSharedPointer<IAsyncResource> resourceGeneric{resource};
|
||||
|
||||
Debug::log(TRACE, "Requesting image resource {} revision {} (resourceID: {})", path, revision, RESOURCEID, (uintptr_t)widget.get());
|
||||
enqueue(RESOURCEID, resourceGeneric, widget);
|
||||
return RESOURCEID;
|
||||
}
|
||||
|
||||
ASP<CTexture> CAsyncResourceManager::getAssetByID(size_t id) {
|
||||
if (!m_assets.contains(id))
|
||||
return nullptr;
|
||||
|
||||
return m_assets[id].texture;
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::enqueueStaticAssets() {
|
||||
const auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
|
||||
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (c.type == "background" || c.type == "image") {
|
||||
std::string path = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
if (path.empty() || path == "screenshot")
|
||||
continue;
|
||||
|
||||
requestImage(path, 0, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::enqueueScreencopyFrames() {
|
||||
if (g_pHyprlock->m_vOutputs.empty())
|
||||
return;
|
||||
|
||||
static const auto ANIMATIONSENABLED = g_pConfigManager->getValue<Hyprlang::INT>("animations:enabled");
|
||||
|
||||
const auto FADEINCFG = g_pConfigManager->m_AnimationTree.getConfig("fadeIn");
|
||||
const auto FADEOUTCFG = g_pConfigManager->m_AnimationTree.getConfig("fadeOut");
|
||||
|
||||
const bool FADENEEDSSC = *ANIMATIONSENABLED &&
|
||||
((FADEINCFG->pValues && FADEINCFG->pValues->internalEnabled) || // fadeIn or fadeOut enabled
|
||||
(FADEOUTCFG->pValues && FADEOUTCFG->pValues->internalEnabled));
|
||||
|
||||
const auto BGSCREENSHOT = std::ranges::any_of(g_pConfigManager->getWidgetConfigs(), [](const auto& w) { //
|
||||
return w.type == "background" && std::string{std::any_cast<Hyprlang::STRING>(w.values.at("path"))} == "screenshot";
|
||||
});
|
||||
|
||||
if (!BGSCREENSHOT && !FADENEEDSSC) {
|
||||
Debug::log(LOG, "Skipping screencopy");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& MON : g_pHyprlock->m_vOutputs) {
|
||||
m_scFrames.emplace_back(makeUnique<CScreencopyFrame>());
|
||||
auto* frame = m_scFrames.back().get();
|
||||
frame->capture(MON);
|
||||
m_assets.emplace(frame->m_resourceID, SPreloadedTexture{.texture = nullptr, .refs = 1});
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::screencopyToTexture(const CScreencopyFrame& scFrame) {
|
||||
if (!scFrame.m_ready || !m_assets.contains(scFrame.m_resourceID)) {
|
||||
Debug::log(ERR, "Bogus call to CAsyncResourceManager::screencopyToTexture. This is a bug!");
|
||||
return;
|
||||
}
|
||||
|
||||
m_assets[scFrame.m_resourceID].texture = scFrame.m_asset;
|
||||
|
||||
Debug::log(TRACE, "Done sc frame {}", scFrame.m_resourceID);
|
||||
|
||||
std::erase_if(m_scFrames, [&scFrame](const auto& f) { return f.get() == &scFrame; });
|
||||
|
||||
if (m_scFrames.empty()) {
|
||||
Debug::log(LOG, "Gathered all screencopy frames - removing dmabuf listeners");
|
||||
g_pHyprlock->removeDmabufListener();
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::gatherInitialResources(wl_display* display) {
|
||||
const auto MAXDELAYMS = 2000; // 2 Seconds
|
||||
const auto STARTGATHERTP = std::chrono::system_clock::now();
|
||||
|
||||
m_gatheredEventfd = CFileDescriptor{eventfd(0, EFD_CLOEXEC)};
|
||||
|
||||
int fdcount = 1;
|
||||
pollfd pollfds[2];
|
||||
pollfds[0] = {
|
||||
.fd = wl_display_get_fd(display),
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
if (m_gatheredEventfd.isValid()) {
|
||||
pollfds[1] = {
|
||||
.fd = m_gatheredEventfd.get(),
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
fdcount++;
|
||||
}
|
||||
|
||||
bool gathered = false;
|
||||
while (!gathered) {
|
||||
wl_display_flush(display);
|
||||
if (wl_display_prepare_read(display) == 0) {
|
||||
if (poll(pollfds, fdcount, /* 100ms timeout */ 100) < 0) {
|
||||
RASSERT(errno == EINTR, "[core] Polling fds failed with {}", errno);
|
||||
wl_display_cancel_read(display);
|
||||
continue;
|
||||
}
|
||||
wl_display_read_events(display);
|
||||
wl_display_dispatch_pending(display);
|
||||
} else {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
wl_display_dispatch(display);
|
||||
}
|
||||
|
||||
g_pHyprlock->processTimers();
|
||||
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - STARTGATHERTP).count() > MAXDELAYMS) {
|
||||
Debug::log(WARN, "Gathering resources timed out after {} milliseconds. Backgrounds may be delayed and render `background:color` at first.", MAXDELAYMS);
|
||||
break;
|
||||
}
|
||||
|
||||
gathered = m_resources.empty() && m_scFrames.empty();
|
||||
}
|
||||
|
||||
Debug::log(LOG, "Resources gathered after {} milliseconds", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - STARTGATHERTP).count());
|
||||
}
|
||||
|
||||
bool CAsyncResourceManager::checkIdPresent(ResourceID id) {
|
||||
return m_assets.contains(id);
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::unload(ASP<CTexture> texture) {
|
||||
auto preload = std::ranges::find_if(m_assets, [texture](const auto& a) { return a.second.texture == texture; });
|
||||
if (preload == m_assets.end())
|
||||
return;
|
||||
|
||||
preload->second.refs--;
|
||||
|
||||
if (preload->second.refs == 0) {
|
||||
Debug::log(TRACE, "Releasing resourceID: {}!", preload->first);
|
||||
m_assets.erase(preload->first);
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::unloadById(ResourceID id) {
|
||||
if (!m_assets.contains(id))
|
||||
return;
|
||||
|
||||
m_assets[id].refs--;
|
||||
|
||||
if (m_assets[id].refs == 0) {
|
||||
Debug::log(TRACE, "Releasing resourceID: {}!", id);
|
||||
m_assets.erase(id);
|
||||
}
|
||||
}
|
||||
|
||||
bool CAsyncResourceManager::request(ResourceID id, const AWP<IWidget>& widget) {
|
||||
if (!m_assets.contains(id)) {
|
||||
// New asset!!
|
||||
m_assets.emplace(id, SPreloadedTexture{.texture = nullptr, .refs = 1});
|
||||
return false;
|
||||
}
|
||||
|
||||
m_assets[id].refs++;
|
||||
|
||||
if (m_assets[id].texture) {
|
||||
// Asset already present. Dispatch the asset callback function.
|
||||
const auto& TEXTURE = m_assets[id].texture;
|
||||
if (widget)
|
||||
widget->onAssetUpdate(id, TEXTURE);
|
||||
|
||||
// TODO: add a centalized mechanism to render in one place in the event loop to avoid duplicate render calls
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [](auto, auto) { g_pHyprlock->renderAllOutputs(); }, nullptr);
|
||||
} else if (widget) {
|
||||
// Asset currently in-flight. Add the widget reference to in order for the callback to get dispatched later.
|
||||
m_resourcesMutex.lock();
|
||||
if (!m_resources.contains(id)) {
|
||||
Debug::log(ERR, "In-flight resourceID: {} not found! This is a bug.", id);
|
||||
m_resourcesMutex.unlock();
|
||||
return true;
|
||||
}
|
||||
m_resources[id].second.emplace_back(widget);
|
||||
m_resourcesMutex.unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::enqueue(ResourceID resourceID, const ASP<IAsyncResource>& resource, const AWP<IWidget>& widget) {
|
||||
m_gatherer.enqueue(resource);
|
||||
|
||||
m_resourcesMutex.lock();
|
||||
if (m_resources.contains(resourceID))
|
||||
Debug::log(ERR, "Resource already enqueued! This is a bug.");
|
||||
|
||||
m_resources[resourceID] = {resource, {widget}};
|
||||
m_resourcesMutex.unlock();
|
||||
|
||||
resource->m_events.finished.listenStatic([resourceID]() {
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [](auto, void* resourceID) { g_asyncResourceManager->onResourceFinished((size_t)resourceID); }, (void*)resourceID);
|
||||
});
|
||||
}
|
||||
|
||||
void CAsyncResourceManager::onResourceFinished(ResourceID id) {
|
||||
m_resourcesMutex.lock();
|
||||
if (!m_resources.contains(id)) {
|
||||
m_resourcesMutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto RESOURCE = m_resources[id].first;
|
||||
const auto WIDGETS = m_resources[id].second;
|
||||
m_resources.erase(id);
|
||||
m_resourcesMutex.unlock();
|
||||
|
||||
if (!m_assets.contains(id) || m_assets[id].refs == 0) // Not referenced? Drop it
|
||||
return;
|
||||
|
||||
if (!RESOURCE || !RESOURCE->m_asset.cairoSurface)
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "Resource to texture id:{}", id);
|
||||
|
||||
const auto texture = makeAtomicShared<CTexture>();
|
||||
|
||||
const cairo_status_t SURFACESTATUS = (cairo_status_t)RESOURCE->m_asset.cairoSurface->status();
|
||||
const auto CAIROFORMAT = cairo_image_surface_get_format(RESOURCE->m_asset.cairoSurface->cairo());
|
||||
const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB32F : GL_RGBA;
|
||||
const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA;
|
||||
const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE;
|
||||
|
||||
if (SURFACESTATUS != CAIRO_STATUS_SUCCESS) {
|
||||
Debug::log(ERR, "resourceID: {} invalid ({})", id, cairo_status_to_string(SURFACESTATUS));
|
||||
texture->m_iType = TEXTURE_INVALID;
|
||||
}
|
||||
|
||||
texture->m_vSize = RESOURCE->m_asset.pixelSize;
|
||||
texture->allocate();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->m_iTexID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
if (CAIROFORMAT != CAIRO_FORMAT_RGB96F) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, glIFormat, texture->m_vSize.x, texture->m_vSize.y, 0, glFormat, glType, RESOURCE->m_asset.cairoSurface->data());
|
||||
|
||||
m_assets[id].texture = texture;
|
||||
|
||||
for (const auto& widget : WIDGETS) {
|
||||
if (widget)
|
||||
widget->onAssetUpdate(id, texture);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderAllOutputs();
|
||||
|
||||
if (!m_gathered && !g_pHyprlock->m_bImmediateRender) {
|
||||
m_resourcesMutex.lock();
|
||||
if (m_resources.empty()) {
|
||||
m_gathered = true;
|
||||
if (m_gatheredEventfd.isValid())
|
||||
eventfd_write(m_gatheredEventfd.get(), 1);
|
||||
|
||||
m_gatheredEventfd.reset();
|
||||
}
|
||||
m_resourcesMutex.unlock();
|
||||
}
|
||||
}
|
||||
91
src/renderer/AsyncResourceManager.hpp
Normal file
91
src/renderer/AsyncResourceManager.hpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "./Texture.hpp"
|
||||
#include "./Screencopy.hpp"
|
||||
#include "./widgets/IWidget.hpp"
|
||||
|
||||
#include <hyprgraphics/resource/AsyncResourceGatherer.hpp>
|
||||
#include <hyprgraphics/resource/resources/AsyncResource.hpp>
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
#include <hyprgraphics/resource/resources/ImageResource.hpp>
|
||||
#include <hyprutils/os/FileDescriptor.hpp>
|
||||
|
||||
class CAsyncResourceManager {
|
||||
|
||||
public:
|
||||
// Notes on resource lifetimes:
|
||||
// Resources id's are the result of hashing the requested resource parameters.
|
||||
// When a new request is made, adding a new entry to the m_assets map is done immediatly.
|
||||
// Subsequent calls through this section with the same resource id will increment the texture's references.
|
||||
// The manager will release the resource when refs reaches 0, while the resource itelf may outlife it's reference in the manager.
|
||||
// Why not use ASP/AWP for this?
|
||||
// The problem is that we want to to increment the reference as soon as requesting the resource id.
|
||||
// Not only when actually retrieving the asset with `getAssetById`.
|
||||
//
|
||||
// Improvement idea: Make a wrapper object that is returned when requesting and contains the resource id. Then we can unload with RAII.
|
||||
|
||||
// Those are hash functions that return the id for a requested resource.
|
||||
static ResourceID resourceIDForTextRequest(const CTextResource::STextResourceData& s);
|
||||
// Consumer needs to increment the revision parameter to get a new command evaluation.
|
||||
static ResourceID resourceIDForTextCmdRequest(const CTextResource::STextResourceData& s, size_t revision);
|
||||
// Image paths may be file system links, thus this function supports a revision parameter that gets factored into the resource id.
|
||||
static ResourceID resourceIDForImageRequest(const std::string& path, size_t revision);
|
||||
static ResourceID resourceIDForScreencopy(const std::string& port);
|
||||
|
||||
struct SPreloadedTexture {
|
||||
ASP<CTexture> texture;
|
||||
size_t refs = 0;
|
||||
};
|
||||
|
||||
CAsyncResourceManager() = default;
|
||||
~CAsyncResourceManager() = default;
|
||||
|
||||
ResourceID requestText(const CTextResource::STextResourceData& params, const AWP<IWidget>& widget);
|
||||
// Same as requestText but substitute the text with what launching sh -c request.text returns.
|
||||
ResourceID requestTextCmd(const CTextResource::STextResourceData& params, size_t revision, const AWP<IWidget>& widget);
|
||||
ResourceID requestImage(const std::string& path, size_t revision, const AWP<IWidget>& widget);
|
||||
|
||||
ASP<CTexture> getAssetByID(ResourceID id);
|
||||
|
||||
void unload(ASP<CTexture> resource);
|
||||
void unloadById(ResourceID id);
|
||||
|
||||
void enqueueStaticAssets();
|
||||
void enqueueScreencopyFrames();
|
||||
void screencopyToTexture(const CScreencopyFrame& scFrame);
|
||||
void gatherInitialResources(wl_display* display);
|
||||
|
||||
bool checkIdPresent(ResourceID id);
|
||||
|
||||
private:
|
||||
// Returns whether or not the id was already requested.
|
||||
// Makes sure the widgets onAssetCallback function gets called.
|
||||
bool request(ResourceID id, const AWP<IWidget>& widget);
|
||||
// Adds a new resource to m_resources and passes it to m_gatherer.
|
||||
void enqueue(ResourceID resourceID, const ASP<IAsyncResource>& resource, const AWP<IWidget>& widget);
|
||||
// Callback for finished resources.
|
||||
// Copies the resources cairo surface to a GL_TEXTURE_2D and sets it in the asset map.
|
||||
// Removes the entry in m_resources.
|
||||
// Call onAssetUpdate for all stored widget references.
|
||||
void onResourceFinished(ResourceID id);
|
||||
|
||||
// For polling when using gatherInitialResources.
|
||||
bool m_gathered = false;
|
||||
Hyprutils::OS::CFileDescriptor m_gatheredEventfd;
|
||||
|
||||
bool m_exit = false;
|
||||
|
||||
int m_loadedAssets = 0;
|
||||
|
||||
// not shared between threads
|
||||
std::unordered_map<ResourceID, SPreloadedTexture> m_assets;
|
||||
std::vector<UP<CScreencopyFrame>> m_scFrames;
|
||||
// shared between threads
|
||||
std::mutex m_resourcesMutex;
|
||||
std::unordered_map<ResourceID, std::pair<ASP<Hyprgraphics::IAsyncResource>, std::vector<AWP<IWidget>>>> m_resources;
|
||||
|
||||
Hyprgraphics::CAsyncResourceGatherer m_gatherer;
|
||||
};
|
||||
|
||||
inline UP<CAsyncResourceManager> g_asyncResourceManager;
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#include "Framebuffer.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include <hyprutils/os/FileDescriptor.hpp>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
#include <utility>
|
||||
|
||||
static uint32_t drmFormatToGL(uint32_t drm) {
|
||||
switch (drm) {
|
||||
|
|
@ -97,7 +99,7 @@ void CFramebuffer::bind() const {
|
|||
glViewport(0, 0, m_vSize.x, m_vSize.y);
|
||||
}
|
||||
|
||||
void CFramebuffer::release() {
|
||||
void CFramebuffer::destroyBuffer() {
|
||||
if (m_iFb != (uint32_t)-1 && m_iFb)
|
||||
glDeleteFramebuffers(1, &m_iFb);
|
||||
|
||||
|
|
@ -114,9 +116,9 @@ void CFramebuffer::release() {
|
|||
}
|
||||
|
||||
CFramebuffer::~CFramebuffer() {
|
||||
release();
|
||||
destroyBuffer();
|
||||
}
|
||||
|
||||
bool CFramebuffer::isAllocated() {
|
||||
bool CFramebuffer::isAllocated() const {
|
||||
return m_iFb != (GLuint)-1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,17 +8,19 @@ class CFramebuffer {
|
|||
public:
|
||||
~CFramebuffer();
|
||||
|
||||
bool alloc(int w, int h, bool highres = false);
|
||||
void addStencil();
|
||||
void bind() const;
|
||||
void release();
|
||||
void reset();
|
||||
bool isAllocated();
|
||||
bool alloc(int w, int h, bool highres = false);
|
||||
void addStencil();
|
||||
void bind() const;
|
||||
void destroyBuffer();
|
||||
bool isAllocated() const;
|
||||
|
||||
Vector2D m_vSize;
|
||||
Vector2D m_vSize;
|
||||
|
||||
CTexture m_cTex;
|
||||
GLuint m_iFb = -1;
|
||||
CTexture m_cTex;
|
||||
GLuint m_iFb = -1;
|
||||
|
||||
CTexture* m_pStencilTex = nullptr;
|
||||
};
|
||||
CTexture* m_pStencilTex = nullptr;
|
||||
|
||||
CFramebuffer& operator=(CFramebuffer&&) = delete;
|
||||
CFramebuffer& operator=(const CFramebuffer&) = delete;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ inline const float fullVerts[] = {
|
|||
0, 1, // bottom left
|
||||
};
|
||||
|
||||
GLuint compileShader(const GLuint& type, std::string src) {
|
||||
static GLuint compileShader(const GLuint& type, std::string src) {
|
||||
auto shader = glCreateShader(type);
|
||||
|
||||
auto shaderSource = src.c_str();
|
||||
|
|
@ -41,7 +41,7 @@ GLuint compileShader(const GLuint& type, std::string src) {
|
|||
return shader;
|
||||
}
|
||||
|
||||
GLuint createProgram(const std::string& vert, const std::string& frag) {
|
||||
static GLuint createProgram(const std::string& vert, const std::string& frag) {
|
||||
auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert);
|
||||
|
||||
RASSERT(vertCompiled, "Compiling shader failed. VERTEX NULL! Shader source:\n\n{}", vert);
|
||||
|
|
@ -194,8 +194,6 @@ CRenderer::CRenderer() {
|
|||
borderShader.gradientLerp = glGetUniformLocation(prog, "gradientLerp");
|
||||
borderShader.alpha = glGetUniformLocation(prog, "alpha");
|
||||
|
||||
asyncResourceGatherer = makeUnique<CAsyncResourceGatherer>();
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, opacity, g_pConfigManager->m_AnimationTree.getConfig("fadeIn"));
|
||||
}
|
||||
|
||||
|
|
@ -217,18 +215,12 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf
|
|||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
SRenderFeedback feedback;
|
||||
const bool WAITFORASSETS = !g_pHyprlock->m_bImmediateRender && !asyncResourceGatherer->gathered;
|
||||
|
||||
if (!WAITFORASSETS) {
|
||||
// render widgets
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(surf);
|
||||
for (auto& w : WIDGETS) {
|
||||
feedback.needsFrame = w->draw({opacity->value()}) || feedback.needsFrame;
|
||||
}
|
||||
// render widgets
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(surf);
|
||||
for (auto& w : WIDGETS) {
|
||||
feedback.needsFrame = w->draw({opacity->value()}) || feedback.needsFrame;
|
||||
}
|
||||
|
||||
feedback.needsFrame = feedback.needsFrame || !asyncResourceGatherer->gathered;
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
return feedback;
|
||||
|
|
@ -388,13 +380,13 @@ void CRenderer::renderTextureMix(const CBox& box, const CTexture& tex, const CTe
|
|||
}
|
||||
|
||||
template <class Widget>
|
||||
static void createWidget(std::vector<SP<IWidget>>& widgets) {
|
||||
const auto W = makeShared<Widget>();
|
||||
static void createWidget(std::vector<ASP<IWidget>>& widgets) {
|
||||
const auto W = makeAtomicShared<Widget>();
|
||||
W->registerSelf(W);
|
||||
widgets.emplace_back(W);
|
||||
}
|
||||
|
||||
std::vector<SP<IWidget>>& CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface& surf) {
|
||||
std::vector<ASP<IWidget>>& CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface& surf) {
|
||||
RASSERT(surf.m_outputID != OUTPUT_INVALID, "Invalid output ID!");
|
||||
|
||||
if (!widgets.contains(surf.m_outputID)) {
|
||||
|
|
@ -406,7 +398,7 @@ std::vector<SP<IWidget>>& CRenderer::getOrCreateWidgetsFor(const CSessionLockSur
|
|||
|
||||
const auto POUTPUT = surf.m_outputRef.lock();
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (!c.monitor.empty() && c.monitor != POUTPUT->stringPort && !POUTPUT->stringDesc.starts_with(c.monitor) && !POUTPUT->stringDesc.starts_with("desc:" + c.monitor))
|
||||
if (!c.monitor.empty() && c.monitor != POUTPUT->stringPort && !POUTPUT->stringDesc.starts_with(c.monitor) && !("desc:" + POUTPUT->stringDesc).starts_with(c.monitor))
|
||||
continue;
|
||||
|
||||
// by type
|
||||
|
|
@ -613,12 +605,13 @@ void CRenderer::startFadeIn() {
|
|||
opacity->setCallbackOnEnd([this](auto) { opacity->setConfig(g_pConfigManager->m_AnimationTree.getConfig("fadeOut")); }, true);
|
||||
}
|
||||
|
||||
void CRenderer::startFadeOut(bool unlock, bool immediate) {
|
||||
if (immediate)
|
||||
opacity->setValueAndWarp(0.f);
|
||||
else
|
||||
*opacity = 0.f;
|
||||
void CRenderer::startFadeOut(bool unlock) {
|
||||
*opacity = 0.f;
|
||||
|
||||
if (unlock)
|
||||
opacity->setCallbackOnEnd([](auto) { g_pHyprlock->releaseSessionLock(); }, true);
|
||||
}
|
||||
|
||||
void CRenderer::warpOpacity(float newOpacity) {
|
||||
opacity->setValueAndWarp(newOpacity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,11 @@
|
|||
#include "../core/LockSurface.hpp"
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
#include "../helpers/Color.hpp"
|
||||
#include "AsyncResourceGatherer.hpp"
|
||||
#include "../config/ConfigDataValues.hpp"
|
||||
#include "widgets/IWidget.hpp"
|
||||
#include "Framebuffer.hpp"
|
||||
|
||||
typedef std::unordered_map<OUTPUTID, std::vector<SP<IWidget>>> widgetMap_t;
|
||||
typedef std::unordered_map<OUTPUTID, std::vector<ASP<IWidget>>> widgetMap_t;
|
||||
|
||||
class CRenderer {
|
||||
public:
|
||||
|
|
@ -37,7 +36,6 @@ class CRenderer {
|
|||
void renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a = 1.0, float mixFactor = 0.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
void blurFB(const CFramebuffer& outfb, SBlurParams params);
|
||||
|
||||
UP<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
|
||||
void pushFb(GLint fb);
|
||||
|
|
@ -47,28 +45,28 @@ class CRenderer {
|
|||
void reconfigureWidgetsFor(OUTPUTID id);
|
||||
|
||||
void startFadeIn();
|
||||
void startFadeOut(bool unlock = false, bool immediate = true);
|
||||
void startFadeOut(bool unlock = false);
|
||||
void warpOpacity(float warpOpacity);
|
||||
std::vector<ASP<IWidget>>& getOrCreateWidgetsFor(const CSessionLockSurface& surf);
|
||||
|
||||
private:
|
||||
widgetMap_t widgets;
|
||||
widgetMap_t widgets;
|
||||
|
||||
std::vector<SP<IWidget>>& getOrCreateWidgetsFor(const CSessionLockSurface& surf);
|
||||
CShader rectShader;
|
||||
CShader texShader;
|
||||
CShader texMixShader;
|
||||
CShader blurShader1;
|
||||
CShader blurShader2;
|
||||
CShader blurPrepareShader;
|
||||
CShader blurFinishShader;
|
||||
CShader borderShader;
|
||||
|
||||
CShader rectShader;
|
||||
CShader texShader;
|
||||
CShader texMixShader;
|
||||
CShader blurShader1;
|
||||
CShader blurShader2;
|
||||
CShader blurPrepareShader;
|
||||
CShader blurFinishShader;
|
||||
CShader borderShader;
|
||||
Mat3x3 projMatrix = Mat3x3::identity();
|
||||
Mat3x3 projection;
|
||||
|
||||
Mat3x3 projMatrix = Mat3x3::identity();
|
||||
Mat3x3 projection;
|
||||
PHLANIMVAR<float> opacity;
|
||||
|
||||
PHLANIMVAR<float> opacity;
|
||||
|
||||
std::vector<GLint> boundFBs;
|
||||
std::vector<GLint> boundFBs;
|
||||
};
|
||||
|
||||
inline UP<CRenderer> g_pRenderer;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "Screencopy.hpp"
|
||||
#include "./AsyncResourceManager.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "../core/hyprlock.hpp"
|
||||
|
|
@ -23,27 +24,20 @@ static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullpt
|
|||
static PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr;
|
||||
|
||||
//
|
||||
std::string CScreencopyFrame::getResourceId(SP<COutput> pOutput) {
|
||||
return std::format("screencopy:{}-{}x{}", pOutput->stringPort, pOutput->size.x, pOutput->size.y);
|
||||
}
|
||||
|
||||
CScreencopyFrame::CScreencopyFrame(SP<COutput> pOutput) : m_outputRef(pOutput) {
|
||||
captureOutput();
|
||||
void CScreencopyFrame::capture(SP<COutput> pOutput) {
|
||||
RASSERT(pOutput, "Screencopy, but no valid output");
|
||||
|
||||
static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode");
|
||||
|
||||
m_asset = makeAtomicShared<CTexture>();
|
||||
m_resourceID = CAsyncResourceManager::resourceIDForScreencopy(pOutput->stringPort);
|
||||
|
||||
m_sc = makeShared<CCZwlrScreencopyFrameV1>(g_pHyprlock->getScreencopy()->sendCaptureOutput(false, pOutput->m_wlOutput->resource()));
|
||||
|
||||
if (*SCMODE == 1)
|
||||
m_frame = makeUnique<CSCSHMFrame>(m_sc);
|
||||
else
|
||||
m_frame = makeUnique<CSCDMAFrame>(m_sc);
|
||||
}
|
||||
|
||||
void CScreencopyFrame::captureOutput() {
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
RASSERT(POUTPUT, "Screencopy, but no valid output");
|
||||
|
||||
m_resourceID = getResourceId(POUTPUT);
|
||||
|
||||
m_sc = makeShared<CCZwlrScreencopyFrameV1>(g_pHyprlock->getScreencopy()->sendCaptureOutput(false, POUTPUT->m_wlOutput->resource()));
|
||||
|
||||
m_sc->setBufferDone([this](CCZwlrScreencopyFrameV1* r) {
|
||||
Debug::log(TRACE, "[sc] wlrOnBufferDone for {}", (void*)this);
|
||||
|
|
@ -73,6 +67,8 @@ void CScreencopyFrame::captureOutput() {
|
|||
}
|
||||
|
||||
m_sc.reset();
|
||||
m_ready = true;
|
||||
g_asyncResourceManager->screencopyToTexture(*this);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -80,11 +76,21 @@ CSCDMAFrame::CSCDMAFrame(SP<CCZwlrScreencopyFrameV1> sc) : m_sc(sc) {
|
|||
if (!glEGLImageTargetTexture2DOES) {
|
||||
glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
Debug::log(ERR, "No glEGLImageTargetTexture2DOES??");
|
||||
Debug::log(ERR, "[sc] No glEGLImageTargetTexture2DOES??");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->dma.linuxDmabuf) {
|
||||
Debug::log(ERR, "[sc] No DMABUF support?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->dma.gbmDevice) {
|
||||
Debug::log(ERR, "[sc] No gbmDevice for DMABUF was created?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eglQueryDmaBufModifiersEXT)
|
||||
eglQueryDmaBufModifiersEXT = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC)eglGetProcAddress("eglQueryDmaBufModifiersEXT");
|
||||
|
||||
|
|
@ -191,7 +197,7 @@ bool CSCDMAFrame::onBufferDone() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CSCDMAFrame::onBufferReady(SPreloadedAsset& asset) {
|
||||
bool CSCDMAFrame::onBufferReady(ASP<CTexture> texture) {
|
||||
static constexpr struct {
|
||||
EGLAttrib fd;
|
||||
EGLAttrib offset;
|
||||
|
|
@ -245,9 +251,9 @@ bool CSCDMAFrame::onBufferReady(SPreloadedAsset& asset) {
|
|||
return false;
|
||||
}
|
||||
|
||||
asset.texture.allocate();
|
||||
asset.texture.m_vSize = {m_w, m_h};
|
||||
glBindTexture(GL_TEXTURE_2D, asset.texture.m_iTexID);
|
||||
texture->allocate();
|
||||
texture->m_vSize = {m_w, m_h};
|
||||
glBindTexture(GL_TEXTURE_2D, texture->m_iTexID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
|
@ -255,9 +261,7 @@ bool CSCDMAFrame::onBufferReady(SPreloadedAsset& asset) {
|
|||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_image);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
Debug::log(LOG, "Got dma frame with size {}", asset.texture.m_vSize);
|
||||
|
||||
asset.ready = true;
|
||||
Debug::log(LOG, "Got dma frame with size {}", texture->m_vSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -449,14 +453,14 @@ void CSCSHMFrame::convertBuffer() {
|
|||
}
|
||||
}
|
||||
|
||||
bool CSCSHMFrame::onBufferReady(SPreloadedAsset& asset) {
|
||||
bool CSCSHMFrame::onBufferReady(ASP<CTexture> texture) {
|
||||
convertBuffer();
|
||||
|
||||
asset.texture.allocate();
|
||||
asset.texture.m_vSize.x = m_w;
|
||||
asset.texture.m_vSize.y = m_h;
|
||||
texture->allocate();
|
||||
texture->m_vSize.x = m_w;
|
||||
texture->m_vSize.y = m_h;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, asset.texture.m_iTexID);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->m_iTexID);
|
||||
|
||||
void* buffer = m_convBuffer ? m_convBuffer : m_shmData;
|
||||
|
||||
|
|
@ -467,9 +471,7 @@ bool CSCSHMFrame::onBufferReady(SPreloadedAsset& asset) {
|
|||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_w, m_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
Debug::log(LOG, "[sc] [shm] Got screenshot with size {}", asset.texture.m_vSize);
|
||||
|
||||
asset.ready = true;
|
||||
Debug::log(LOG, "[sc] [shm] Got screenshot with size {}", texture->m_vSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
#include "../defines.hpp"
|
||||
#include "../core/Output.hpp"
|
||||
#include "../renderer/Texture.hpp"
|
||||
#include <cstdint>
|
||||
#include <gbm.h>
|
||||
#include <memory>
|
||||
#include "Shared.hpp"
|
||||
#include "linux-dmabuf-v1.hpp"
|
||||
#include "wlr-screencopy-unstable-v1.hpp"
|
||||
|
||||
|
|
@ -14,28 +13,27 @@ class ISCFrame {
|
|||
ISCFrame() = default;
|
||||
virtual ~ISCFrame() = default;
|
||||
|
||||
virtual bool onBufferDone() = 0;
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset) = 0;
|
||||
virtual bool onBufferDone() = 0;
|
||||
virtual bool onBufferReady(ASP<CTexture> asset) = 0;
|
||||
|
||||
SP<CCWlBuffer> m_wlBuffer = nullptr;
|
||||
};
|
||||
|
||||
class CScreencopyFrame {
|
||||
public:
|
||||
static std::string getResourceId(SP<COutput> pOutput);
|
||||
|
||||
CScreencopyFrame(SP<COutput> pOutput);
|
||||
CScreencopyFrame() = default;
|
||||
~CScreencopyFrame() = default;
|
||||
|
||||
void captureOutput();
|
||||
void capture(SP<COutput> pOutput);
|
||||
|
||||
SP<CCZwlrScreencopyFrameV1> m_sc = nullptr;
|
||||
|
||||
std::string m_resourceID;
|
||||
SPreloadedAsset m_asset;
|
||||
size_t m_resourceID;
|
||||
ASP<CTexture> m_asset;
|
||||
|
||||
bool m_ready = false;
|
||||
|
||||
private:
|
||||
WP<COutput> m_outputRef;
|
||||
UP<ISCFrame> m_frame = nullptr;
|
||||
|
||||
bool m_dmaFailed = false;
|
||||
|
|
@ -47,7 +45,7 @@ class CSCDMAFrame : public ISCFrame {
|
|||
CSCDMAFrame(SP<CCZwlrScreencopyFrameV1> sc);
|
||||
virtual ~CSCDMAFrame();
|
||||
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset);
|
||||
virtual bool onBufferReady(ASP<CTexture> asset);
|
||||
virtual bool onBufferDone();
|
||||
|
||||
private:
|
||||
|
|
@ -77,7 +75,7 @@ class CSCSHMFrame : public ISCFrame {
|
|||
virtual bool onBufferDone() {
|
||||
return m_ok;
|
||||
}
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset);
|
||||
virtual bool onBufferReady(ASP<CTexture> texture);
|
||||
void convertBuffer();
|
||||
|
||||
private:
|
||||
|
|
|
|||
31
src/renderer/resources/TextCmdResource.cpp
Normal file
31
src/renderer/resources/TextCmdResource.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include "TextCmdResource.hpp"
|
||||
|
||||
#include "../../config/ConfigManager.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
|
||||
using namespace Hyprgraphics;
|
||||
|
||||
CTextCmdResource::CTextCmdResource(CTextResource::STextResourceData&& data) : m_data(std::move(data)) {
|
||||
;
|
||||
}
|
||||
|
||||
void CTextCmdResource::render() {
|
||||
static const auto TRIM = g_pConfigManager->getValue<Hyprlang::INT>("general:text_trim");
|
||||
|
||||
CTextResource::STextResourceData textData = m_data;
|
||||
|
||||
textData.text = spawnSync(m_data.text);
|
||||
|
||||
if (*TRIM) {
|
||||
textData.text.erase(0, textData.text.find_first_not_of(" \n\r\t"));
|
||||
textData.text.erase(textData.text.find_last_not_of(" \n\r\t") + 1);
|
||||
}
|
||||
|
||||
Hyprgraphics::CTextResource textResource(std::move(textData));
|
||||
|
||||
textResource.render();
|
||||
|
||||
std::swap(m_asset, textResource.m_asset);
|
||||
}
|
||||
15
src/renderer/resources/TextCmdResource.hpp
Normal file
15
src/renderer/resources/TextCmdResource.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprgraphics/resource/resources/AsyncResource.hpp>
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
|
||||
class CTextCmdResource : public Hyprgraphics::IAsyncResource {
|
||||
public:
|
||||
CTextCmdResource(Hyprgraphics::CTextResource::STextResourceData&& data);
|
||||
virtual ~CTextCmdResource() = default;
|
||||
|
||||
virtual void render();
|
||||
|
||||
private:
|
||||
Hyprgraphics::CTextResource::STextResourceData m_data;
|
||||
};
|
||||
|
|
@ -1,19 +1,28 @@
|
|||
#include "Background.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../AsyncResourceManager.hpp"
|
||||
#include "../Framebuffer.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include "../../core/AnimationManager.hpp"
|
||||
#include "../../config/ConfigManager.hpp"
|
||||
#include <chrono>
|
||||
#include <hyprlang.hpp>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <GLES3/gl32.h>
|
||||
|
||||
CBackground::CBackground() {
|
||||
blurredFB = makeUnique<CFramebuffer>();
|
||||
pendingBlurredFB = makeUnique<CFramebuffer>();
|
||||
transformedScFB = makeUnique<CFramebuffer>();
|
||||
}
|
||||
|
||||
CBackground::~CBackground() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void CBackground::registerSelf(const SP<CBackground>& self) {
|
||||
void CBackground::registerSelf(const ASP<CBackground>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +41,6 @@ void CBackground::configure(const std::unordered_map<std::string, std::any>& pro
|
|||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(props.at("reload_cmd"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
crossFadeTime = std::any_cast<Hyprlang::FLOAT>(props.at("crossfade_time"));
|
||||
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CBackground: {}", e.what()); //
|
||||
|
|
@ -42,33 +50,35 @@ void CBackground::configure(const std::unordered_map<std::string, std::any>& pro
|
|||
|
||||
isScreenshot = path == "screenshot";
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = isScreenshot ? wlTransformToHyprutils(invertTransform(pOutput->transform)) : HYPRUTILS_TRANSFORM_NORMAL;
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = wlTransformToHyprutils(invertTransform(pOutput->transform));
|
||||
scResourceID = CAsyncResourceManager::resourceIDForScreencopy(pOutput->stringPort);
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, crossFadeProgress, g_pConfigManager->m_AnimationTree.getConfig("fadeIn"));
|
||||
|
||||
if (!g_asyncResourceManager->checkIdPresent(scResourceID)) {
|
||||
Debug::log(LOG, "Missing screenshot for output {}", outputPort);
|
||||
scResourceID = 0;
|
||||
}
|
||||
|
||||
if (isScreenshot) {
|
||||
resourceID = CScreencopyFrame::getResourceId(pOutput);
|
||||
// When the initial gather of the asyncResourceGatherer is completed (ready), all DMAFrames are available.
|
||||
// Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
|
||||
if (g_pRenderer->asyncResourceGatherer->gathered) {
|
||||
if (!g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = ""; // Fallback to solid color (background:color)
|
||||
}
|
||||
resourceID = scResourceID; // Fallback to solid background:color when scResourceID==0
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
resourceID = 0;
|
||||
}
|
||||
|
||||
} else if (!path.empty())
|
||||
resourceID = "background:" + path;
|
||||
resourceID = g_asyncResourceManager->requestImage(path, m_imageRevision, nullptr);
|
||||
|
||||
if (!isScreenshot && reloadTime > -1) {
|
||||
if (!reloadCommand.empty() && reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
if (!isScreenshot)
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
} catch (std::exception& e) { Debug::log(ERR, "{}", e.what()); }
|
||||
|
||||
plantReloadTimer(); // No reloads for screenshots.
|
||||
plantReloadTimer(); // No reloads if reloadCommand is empty
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -78,13 +88,59 @@ void CBackground::reset() {
|
|||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
fade.reset();
|
||||
}
|
||||
blurredFB->destroyBuffer();
|
||||
pendingBlurredFB->destroyBuffer();
|
||||
}
|
||||
|
||||
void CBackground::updatePrimaryAsset() {
|
||||
if (asset || resourceID == 0)
|
||||
return;
|
||||
|
||||
asset = g_asyncResourceManager->getAssetByID(resourceID);
|
||||
if (!asset)
|
||||
return;
|
||||
|
||||
const bool NEEDFB = (isScreenshot || blurPasses > 0 || asset->m_vSize != viewport || transform != HYPRUTILS_TRANSFORM_NORMAL) && (!blurredFB->isAllocated() || firstRender);
|
||||
if (NEEDFB)
|
||||
renderToFB(*asset, *blurredFB, blurPasses, isScreenshot);
|
||||
}
|
||||
|
||||
void CBackground::updatePendingAsset() {
|
||||
// For crossfading a new asset
|
||||
if (!pendingAsset || blurPasses == 0 || pendingBlurredFB->isAllocated())
|
||||
return;
|
||||
|
||||
renderToFB(*pendingAsset, *pendingBlurredFB, blurPasses);
|
||||
}
|
||||
|
||||
void CBackground::updateScAsset() {
|
||||
if (scAsset || scResourceID == 0)
|
||||
return;
|
||||
|
||||
// path=screenshot -> scAsset = asset
|
||||
scAsset = (asset && isScreenshot) ? asset : g_asyncResourceManager->getAssetByID(scResourceID);
|
||||
if (!scAsset)
|
||||
return;
|
||||
|
||||
const bool NEEDSCTRANSFORM = transform != HYPRUTILS_TRANSFORM_NORMAL;
|
||||
if (NEEDSCTRANSFORM)
|
||||
renderToFB(*scAsset, *transformedScFB, 0, true);
|
||||
}
|
||||
|
||||
const CTexture& CBackground::getPrimaryAssetTex() const {
|
||||
// This case is only for background:path=screenshot with blurPasses=0
|
||||
if (isScreenshot && blurPasses == 0 && transformedScFB->isAllocated())
|
||||
return transformedScFB->m_cTex;
|
||||
|
||||
return (blurredFB->isAllocated()) ? blurredFB->m_cTex : *asset;
|
||||
}
|
||||
|
||||
const CTexture& CBackground::getPendingAssetTex() const {
|
||||
return (pendingBlurredFB->isAllocated()) ? pendingBlurredFB->m_cTex : *pendingAsset;
|
||||
}
|
||||
|
||||
const CTexture& CBackground::getScAssetTex() const {
|
||||
return (transformedScFB->isAllocated()) ? transformedScFB->m_cTex : *scAsset;
|
||||
}
|
||||
|
||||
void CBackground::renderRect(CHyprColor color) {
|
||||
|
|
@ -92,105 +148,18 @@ void CBackground::renderRect(CHyprColor color) {
|
|||
g_pRenderer->renderRect(monbox, color, 0);
|
||||
}
|
||||
|
||||
static void onReloadTimer(WP<CBackground> ref) {
|
||||
static void onReloadTimer(AWP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG) {
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onCrossFadeTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
}
|
||||
static CBox getScaledBoxForTextureSize(const Vector2D& size, const Vector2D& viewport) {
|
||||
CBox texbox = {{}, size};
|
||||
|
||||
static void onAssetCallback(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty()) {
|
||||
CHyprColor col = color;
|
||||
col.a *= data.opacity;
|
||||
renderRect(col);
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
|
||||
if (!asset)
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
|
||||
if (!asset) {
|
||||
CHyprColor col = color;
|
||||
col.a *= data.opacity;
|
||||
renderRect(col);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (asset->texture.m_iType == TEXTURE_INVALID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
resourceID = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fade || ((blurPasses > 0 || isScreenshot) && (!blurredFB.isAllocated() || firstRender))) {
|
||||
|
||||
if (firstRender)
|
||||
firstRender = false;
|
||||
|
||||
// make it brah
|
||||
Vector2D size = asset->texture.m_vSize;
|
||||
if (transform % 2 == 1 && isScreenshot) {
|
||||
size.x = asset->texture.m_vSize.y;
|
||||
size.y = asset->texture.m_vSize.x;
|
||||
}
|
||||
|
||||
CBox texbox = {{}, size};
|
||||
|
||||
float scaleX = viewport.x / size.x;
|
||||
float scaleY = viewport.y / size.y;
|
||||
|
||||
texbox.w *= std::max(scaleX, scaleY);
|
||||
texbox.h *= std::max(scaleX, scaleY);
|
||||
|
||||
if (scaleX > scaleY)
|
||||
texbox.y = -(texbox.h - viewport.y) / 2.f;
|
||||
else
|
||||
texbox.x = -(texbox.w - viewport.x) / 2.f;
|
||||
texbox.round();
|
||||
|
||||
if (!blurredFB.isAllocated())
|
||||
blurredFB.alloc(viewport.x, viewport.y); // TODO 10 bit
|
||||
|
||||
blurredFB.bind();
|
||||
|
||||
if (fade)
|
||||
g_pRenderer->renderTextureMix(texbox, asset->texture, pendingAsset->texture, 1.0,
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - fade->start).count() / (1000 * crossFadeTime), 0,
|
||||
transform);
|
||||
else
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0, transform);
|
||||
|
||||
if (blurPasses > 0)
|
||||
g_pRenderer->blurFB(blurredFB,
|
||||
CRenderer::SBlurParams{.size = blurSize,
|
||||
.passes = blurPasses,
|
||||
.noise = noise,
|
||||
.contrast = contrast,
|
||||
.brightness = brightness,
|
||||
.vibrancy = vibrancy,
|
||||
.vibrancy_darkness = vibrancy_darkness});
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
CTexture* tex = blurredFB.isAllocated() ? &blurredFB.m_cTex : &asset->texture;
|
||||
|
||||
CBox texbox = {{}, tex->m_vSize};
|
||||
|
||||
Vector2D size = tex->m_vSize;
|
||||
float scaleX = viewport.x / tex->m_vSize.x;
|
||||
float scaleY = viewport.y / tex->m_vSize.y;
|
||||
float scaleX = viewport.x / size.x;
|
||||
float scaleY = viewport.y / size.y;
|
||||
|
||||
texbox.w *= std::max(scaleX, scaleY);
|
||||
texbox.h *= std::max(scaleX, scaleY);
|
||||
|
|
@ -200,9 +169,114 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
else
|
||||
texbox.x = -(texbox.w - viewport.x) / 2.f;
|
||||
texbox.round();
|
||||
g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180);
|
||||
|
||||
return fade || data.opacity < 1.0; // actively render during fading
|
||||
return texbox;
|
||||
}
|
||||
|
||||
void CBackground::renderToFB(const CTexture& tex, CFramebuffer& fb, int passes, bool applyTransform) {
|
||||
if (firstRender)
|
||||
firstRender = false;
|
||||
|
||||
// make it brah
|
||||
Vector2D size = tex.m_vSize;
|
||||
if (applyTransform && transform % 2 == 1) {
|
||||
size.x = tex.m_vSize.y;
|
||||
size.y = tex.m_vSize.x;
|
||||
}
|
||||
|
||||
const auto TEXBOX = getScaledBoxForTextureSize(size, viewport);
|
||||
|
||||
if (!fb.isAllocated())
|
||||
fb.alloc(viewport.x, viewport.y); // TODO 10 bit
|
||||
|
||||
fb.bind();
|
||||
|
||||
g_pRenderer->renderTexture(TEXBOX, tex, 1.0, 0, applyTransform ? transform : HYPRUTILS_TRANSFORM_NORMAL);
|
||||
|
||||
if (blurPasses > 0)
|
||||
g_pRenderer->blurFB(fb,
|
||||
CRenderer::SBlurParams{
|
||||
.size = blurSize,
|
||||
.passes = passes,
|
||||
.noise = noise,
|
||||
.contrast = contrast,
|
||||
.brightness = brightness,
|
||||
.vibrancy = vibrancy,
|
||||
.vibrancy_darkness = vibrancy_darkness,
|
||||
});
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
updatePrimaryAsset();
|
||||
updatePendingAsset();
|
||||
updateScAsset();
|
||||
|
||||
if (asset && asset->m_iType == TEXTURE_INVALID) {
|
||||
g_asyncResourceManager->unload(asset);
|
||||
resourceID = 0;
|
||||
renderRect(color);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!asset || resourceID == 0) {
|
||||
// fade in/out with a solid color
|
||||
if (data.opacity < 1.0 && scAsset) {
|
||||
const auto& SCTEX = getScAssetTex();
|
||||
const auto SCTEXBOX = getScaledBoxForTextureSize(SCTEX.m_vSize, viewport);
|
||||
g_pRenderer->renderTexture(SCTEXBOX, SCTEX, 1, 0, HYPRUTILS_TRANSFORM_FLIPPED_180);
|
||||
CHyprColor col = color;
|
||||
col.a *= data.opacity;
|
||||
renderRect(col);
|
||||
return true;
|
||||
}
|
||||
|
||||
renderRect(color);
|
||||
return !asset && resourceID > 0; // resource not ready
|
||||
}
|
||||
|
||||
const auto& TEX = getPrimaryAssetTex();
|
||||
const auto TEXBOX = getScaledBoxForTextureSize(TEX.m_vSize, viewport);
|
||||
if (data.opacity < 1.0 && scAsset) {
|
||||
const auto& SCTEX = getScAssetTex();
|
||||
g_pRenderer->renderTextureMix(TEXBOX, SCTEX, TEX, 1.0, data.opacity, 0);
|
||||
} else if (crossFadeProgress->isBeingAnimated()) {
|
||||
const auto& PENDINGTEX = getPendingAssetTex();
|
||||
g_pRenderer->renderTextureMix(TEXBOX, TEX, PENDINGTEX, 1.0, crossFadeProgress->value(), 0);
|
||||
} else
|
||||
g_pRenderer->renderTexture(TEXBOX, TEX, 1, 0);
|
||||
|
||||
return crossFadeProgress->isBeingAnimated() || data.opacity < 1.0;
|
||||
}
|
||||
|
||||
void CBackground::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
|
||||
pendingResource = false;
|
||||
|
||||
if (!newAsset)
|
||||
Debug::log(ERR, "Background asset update failed, resourceID: {} not available on update!", id);
|
||||
else if (newAsset->m_iType == TEXTURE_INVALID) {
|
||||
g_asyncResourceManager->unload(newAsset);
|
||||
Debug::log(ERR, "New background asset has an invalid texture!");
|
||||
} else {
|
||||
pendingAsset = newAsset;
|
||||
crossFadeProgress->setValueAndWarp(0);
|
||||
*crossFadeProgress = 1.0;
|
||||
|
||||
crossFadeProgress->setCallbackOnEnd(
|
||||
[REF = m_self, id](auto) {
|
||||
if (const auto PSELF = REF.lock()) {
|
||||
if (PSELF->asset)
|
||||
g_asyncResourceManager->unload(PSELF->asset);
|
||||
PSELF->asset = PSELF->pendingAsset;
|
||||
PSELF->pendingAsset = nullptr;
|
||||
PSELF->resourceID = id;
|
||||
|
||||
PSELF->blurredFB->destroyBuffer();
|
||||
PSELF->blurredFB = std::move(PSELF->pendingBlurredFB);
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
void CBackground::plantReloadTimer() {
|
||||
|
|
@ -213,34 +287,13 @@ void CBackground::plantReloadTimer() {
|
|||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
}
|
||||
|
||||
void CBackground::onCrossFadeTimerUpdate() {
|
||||
|
||||
// Animation done: Unload previous asset, deinitialize the fade and pass the asset
|
||||
|
||||
if (fade) {
|
||||
fade->crossFadeTimer.reset();
|
||||
fade.reset();
|
||||
}
|
||||
|
||||
if (blurPasses <= 0 && !isScreenshot)
|
||||
blurredFB.release();
|
||||
|
||||
asset = pendingAsset;
|
||||
resourceID = pendingResourceID;
|
||||
pendingResourceID = "";
|
||||
pendingAsset = nullptr;
|
||||
firstRender = true;
|
||||
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
||||
void CBackground::onReloadTimerUpdate() {
|
||||
const std::string OLDPATH = path;
|
||||
|
||||
// Path parsing and early returns
|
||||
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
path = spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
|
@ -258,58 +311,22 @@ void CBackground::onReloadTimerUpdate() {
|
|||
return;
|
||||
|
||||
modificationTime = MTIME;
|
||||
if (OLDPATH == path)
|
||||
m_imageRevision++;
|
||||
else
|
||||
m_imageRevision = 0;
|
||||
} catch (std::exception& e) {
|
||||
path = OLDPATH;
|
||||
Debug::log(ERR, "{}", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pendingResourceID.empty())
|
||||
if (pendingResource)
|
||||
return;
|
||||
|
||||
pendingResource = true;
|
||||
|
||||
// Issue the next request
|
||||
|
||||
request.id = std::string{"background:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
void CBackground::startCrossFadeOrUpdateRender() {
|
||||
auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID);
|
||||
if (newAsset) {
|
||||
if (newAsset->texture.m_iType == TEXTURE_INVALID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(newAsset);
|
||||
Debug::log(ERR, "New asset had an invalid texture!");
|
||||
} else if (resourceID != pendingResourceID) {
|
||||
pendingAsset = newAsset;
|
||||
if (crossFadeTime > 0) {
|
||||
// Start a fade
|
||||
if (!fade)
|
||||
fade = makeUnique<SFade>(std::chrono::system_clock::now(), 0, nullptr);
|
||||
else {
|
||||
// Maybe we where already fading so reset it just in case, but should'nt be happening.
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
}
|
||||
fade->start = std::chrono::system_clock::now();
|
||||
fade->a = 0;
|
||||
fade->crossFadeTimer =
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds((int)(1000.0 * crossFadeTime)), [REF = m_self](auto, auto) { onCrossFadeTimer(REF); }, nullptr);
|
||||
} else {
|
||||
onCrossFadeTimerUpdate();
|
||||
}
|
||||
}
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
AWP<IWidget> widget(m_self);
|
||||
g_asyncResourceManager->requestImage(path, m_imageRevision, widget);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,81 +1,85 @@
|
|||
#pragma once
|
||||
|
||||
#include "IWidget.hpp"
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/AnimatedVariable.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../core/Timer.hpp"
|
||||
#include "../Framebuffer.hpp"
|
||||
#include "../AsyncResourceGatherer.hpp"
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
struct SPreloadedAsset;
|
||||
class COutput;
|
||||
|
||||
struct SFade {
|
||||
std::chrono::system_clock::time_point start;
|
||||
float a = 0;
|
||||
std::shared_ptr<CTimer> crossFadeTimer = nullptr;
|
||||
};
|
||||
|
||||
class CBackground : public IWidget {
|
||||
public:
|
||||
CBackground() = default;
|
||||
CBackground();
|
||||
~CBackground();
|
||||
|
||||
void registerSelf(const SP<CBackground>& self);
|
||||
void registerSelf(const ASP<CBackground>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset);
|
||||
|
||||
void reset(); // Unload assets, remove timers, etc.
|
||||
void reset(); // Unload assets, remove timers, etc.
|
||||
|
||||
void renderRect(CHyprColor color);
|
||||
void updatePrimaryAsset();
|
||||
void updatePendingAsset();
|
||||
void updateScAsset();
|
||||
|
||||
void onReloadTimerUpdate();
|
||||
void onCrossFadeTimerUpdate();
|
||||
void plantReloadTimer();
|
||||
void startCrossFadeOrUpdateRender();
|
||||
const CTexture& getPrimaryAssetTex() const;
|
||||
const CTexture& getPendingAssetTex() const;
|
||||
const CTexture& getScAssetTex() const;
|
||||
|
||||
void renderRect(CHyprColor color);
|
||||
void renderToFB(const CTexture& text, CFramebuffer& fb, int passes, bool applyTransform = false);
|
||||
|
||||
void onReloadTimerUpdate();
|
||||
void plantReloadTimer();
|
||||
void startCrossFade();
|
||||
|
||||
private:
|
||||
WP<CBackground> m_self;
|
||||
AWP<CBackground> m_self;
|
||||
|
||||
// if needed
|
||||
CFramebuffer blurredFB;
|
||||
UP<CFramebuffer> blurredFB;
|
||||
UP<CFramebuffer> pendingBlurredFB;
|
||||
UP<CFramebuffer> transformedScFB;
|
||||
|
||||
int blurSize = 10;
|
||||
int blurPasses = 3;
|
||||
float noise = 0.0117;
|
||||
float contrast = 0.8916;
|
||||
float brightness = 0.8172;
|
||||
float vibrancy = 0.1696;
|
||||
float vibrancy_darkness = 0.0;
|
||||
Vector2D viewport;
|
||||
std::string path = "";
|
||||
int blurSize = 10;
|
||||
int blurPasses = 3;
|
||||
float noise = 0.0117;
|
||||
float contrast = 0.8916;
|
||||
float brightness = 0.8172;
|
||||
float vibrancy = 0.1696;
|
||||
float vibrancy_darkness = 0.0;
|
||||
Vector2D viewport;
|
||||
std::string path = "";
|
||||
|
||||
std::string outputPort;
|
||||
Hyprutils::Math::eTransform transform;
|
||||
std::string outputPort;
|
||||
Hyprutils::Math::eTransform transform;
|
||||
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID;
|
||||
ResourceID resourceID = 0;
|
||||
ResourceID scResourceID = 0;
|
||||
bool pendingResource = false;
|
||||
|
||||
float crossFadeTime = -1.0;
|
||||
PHLANIMVAR<float> crossFadeProgress;
|
||||
|
||||
CHyprColor color;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
bool isScreenshot = false;
|
||||
SPreloadedAsset* pendingAsset = nullptr;
|
||||
bool firstRender = true;
|
||||
CHyprColor color;
|
||||
ASP<CTexture> asset = nullptr;
|
||||
ASP<CTexture> scAsset = nullptr;
|
||||
ASP<CTexture> pendingAsset = nullptr;
|
||||
bool isScreenshot = false;
|
||||
bool firstRender = true;
|
||||
|
||||
UP<SFade> fade;
|
||||
|
||||
int reloadTime = -1;
|
||||
std::string reloadCommand;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
std::shared_ptr<CTimer> reloadTimer;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
int reloadTime = -1;
|
||||
std::string reloadCommand;
|
||||
ASP<CTimer> reloadTimer;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
size_t m_imageRevision = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../auth/Auth.hpp"
|
||||
#include <chrono>
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
|
|
@ -10,7 +11,7 @@
|
|||
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
#pragma comment(lib, "date-tz")
|
||||
#include <date/tz.h>
|
||||
namespace std {
|
||||
|
|
@ -76,6 +77,16 @@ int IWidget::roundingForBorderBox(const CBox& borderBox, int roundingConfig, int
|
|||
return std::clamp(roundingConfig + thickness, 0, MINHALFBORDER);
|
||||
}
|
||||
|
||||
Hyprgraphics::CTextResource::eTextAlignmentMode IWidget::parseTextAlignment(const std::string& alignment) {
|
||||
Hyprgraphics::CTextResource::eTextAlignmentMode align = Hyprgraphics::CTextResource::TEXT_ALIGN_LEFT;
|
||||
if (alignment == "center")
|
||||
align = Hyprgraphics::CTextResource::TEXT_ALIGN_CENTER;
|
||||
else if (alignment == "right")
|
||||
align = Hyprgraphics::CTextResource::TEXT_ALIGN_RIGHT;
|
||||
|
||||
return align;
|
||||
}
|
||||
|
||||
static void replaceAllAttempts(std::string& str) {
|
||||
|
||||
const size_t ATTEMPTS = g_pAuth->getFailedAttempts();
|
||||
|
|
@ -116,7 +127,7 @@ static void replaceAllLayout(std::string& str) {
|
|||
const CVarList LANGS(REPL);
|
||||
if (LAYOUTIDX >= LANGS.size()) {
|
||||
Debug::log(ERR, "Layout index {} out of bounds. Max is {}.", LAYOUTIDX, LANGS.size() - 1);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string LANG = LANGS[LAYOUTIDX].empty() ? layoutName : LANGS[LAYOUTIDX] == "!" ? "" : LANGS[LAYOUTIDX];
|
||||
|
|
@ -175,8 +186,8 @@ static std::string getTime12h() {
|
|||
IWidget::SFormatResult IWidget::formatString(std::string in) {
|
||||
|
||||
auto uidPassword = getpwuid(getuid());
|
||||
char* username = uidPassword->pw_name;
|
||||
char* user_gecos = uidPassword->pw_gecos;
|
||||
char* username = uidPassword ? uidPassword->pw_name : nullptr;
|
||||
char* user_gecos = uidPassword ? uidPassword->pw_gecos : nullptr;
|
||||
|
||||
if (!username)
|
||||
Debug::log(ERR, "Error in formatString, username null. Errno: ", errno);
|
||||
|
|
@ -266,3 +277,15 @@ IWidget::SFormatResult IWidget::formatString(std::string in) {
|
|||
result.formatted = in;
|
||||
return result;
|
||||
}
|
||||
|
||||
void IWidget::setHover(bool hover) {
|
||||
hovered = hover;
|
||||
}
|
||||
|
||||
bool IWidget::isHovered() const {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
bool IWidget::containsPoint(const Vector2D& pos) const {
|
||||
return getBoundingBoxWl().containsPoint(pos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../core/Seat.hpp"
|
||||
#include "../Texture.hpp"
|
||||
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
|
@ -16,13 +20,23 @@ class IWidget {
|
|||
|
||||
virtual ~IWidget() = default;
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) = 0;
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) = 0;
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
// Never render within onAssetUpdate!
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) = 0;
|
||||
|
||||
static Vector2D posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign,
|
||||
const double& ang = 0);
|
||||
static int roundingForBox(const CBox& box, int roundingConfig);
|
||||
static int roundingForBorderBox(const CBox& borderBox, int roundingConfig, int thickness);
|
||||
static Hyprgraphics::CTextResource::eTextAlignmentMode parseTextAlignment(const std::string& alignment);
|
||||
|
||||
virtual CBox getBoundingBoxWl() const {
|
||||
return CBox();
|
||||
};
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos) {}
|
||||
virtual void onHover(const Vector2D& pos) {}
|
||||
bool containsPoint(const Vector2D& pos) const;
|
||||
|
||||
struct SFormatResult {
|
||||
std::string formatted;
|
||||
|
|
@ -33,4 +47,10 @@ class IWidget {
|
|||
};
|
||||
|
||||
static SFormatResult formatString(std::string in);
|
||||
|
||||
void setHover(bool hover);
|
||||
bool isHovered() const;
|
||||
|
||||
private:
|
||||
bool hovered = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,37 +1,39 @@
|
|||
#include "Image.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../AsyncResourceManager.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
|
||||
CImage::~CImage() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void CImage::registerSelf(const SP<CImage>& self) {
|
||||
void CImage::registerSelf(const ASP<CImage>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CImage> ref) {
|
||||
static void onTimer(AWP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE) {
|
||||
PIMAGE->onTimerUpdate();
|
||||
PIMAGE->plantTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onAssetCallback(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE)
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
void CImage::onTimerUpdate() {
|
||||
if (m_pendingResource) {
|
||||
Debug::log(WARN, "Trying to update image, but a resource is still pending! Skipping update.");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string OLDPATH = path;
|
||||
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
path = spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
|
@ -49,22 +51,20 @@ void CImage::onTimerUpdate() {
|
|||
return;
|
||||
|
||||
modificationTime = MTIME;
|
||||
if (OLDPATH == path)
|
||||
m_imageRevision++;
|
||||
else
|
||||
m_imageRevision = 0;
|
||||
} catch (std::exception& e) {
|
||||
path = OLDPATH;
|
||||
Debug::log(ERR, "{}", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pendingResourceID.empty())
|
||||
return;
|
||||
m_pendingResource = true;
|
||||
|
||||
request.id = std::string{"image:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
AWP<IWidget> widget(m_self);
|
||||
g_asyncResourceManager->requestImage(path, m_imageRevision, widget);
|
||||
}
|
||||
|
||||
void CImage::plantTimer() {
|
||||
|
|
@ -81,28 +81,29 @@ void CImage::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
viewport = pOutput->getViewport();
|
||||
stringPort = pOutput->stringPort;
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
shadow.configure(m_self, props, viewport);
|
||||
|
||||
try {
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
configPos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(props.at("reload_cmd"));
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(props.at("reload_cmd"));
|
||||
onclickCommand = std::any_cast<Hyprlang::STRING>(props.at("onclick"));
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CImage: {}", e.what()); //
|
||||
} catch (const std::out_of_range& e) {
|
||||
RASSERT(false, "Missing propperty for CImage: {}", e.what()); //
|
||||
}
|
||||
|
||||
resourceID = "image:" + path;
|
||||
resourceID = g_asyncResourceManager->requestImage(path, m_imageRevision, nullptr);
|
||||
angle = angle * M_PI / 180.0;
|
||||
|
||||
if (reloadTime > -1) {
|
||||
|
|
@ -123,30 +124,30 @@ void CImage::reset() {
|
|||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
imageFB.release();
|
||||
imageFB.destroyBuffer();
|
||||
|
||||
if (asset && reloadTime > -1) // Don't unload asset if it's a static image
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
g_asyncResourceManager->unload(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID = "";
|
||||
resourceID = "";
|
||||
m_pendingResource = false;
|
||||
resourceID = 0;
|
||||
}
|
||||
|
||||
bool CImage::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty())
|
||||
if (resourceID == 0)
|
||||
return false;
|
||||
|
||||
if (!asset)
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
asset = g_asyncResourceManager->getAssetByID(resourceID);
|
||||
|
||||
if (!asset)
|
||||
return true;
|
||||
|
||||
if (asset->texture.m_iType == TEXTURE_INVALID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
resourceID = "";
|
||||
if (asset->m_iType == TEXTURE_INVALID) {
|
||||
g_asyncResourceManager->unload(asset);
|
||||
resourceID = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +155,7 @@ bool CImage::draw(const SRenderData& data) {
|
|||
|
||||
const Vector2D IMAGEPOS = {border, border};
|
||||
const Vector2D BORDERPOS = {0.0, 0.0};
|
||||
const Vector2D TEXSIZE = asset->texture.m_vSize;
|
||||
const Vector2D TEXSIZE = asset->m_vSize;
|
||||
const float SCALEX = size / TEXSIZE.x;
|
||||
const float SCALEY = size / TEXSIZE.y;
|
||||
|
||||
|
|
@ -182,7 +183,7 @@ bool CImage::draw(const SRenderData& data) {
|
|||
g_pRenderer->renderBorder(borderBox, color, border, BORDERROUND, 1.0);
|
||||
|
||||
texbox.round();
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, ROUND, HYPRUTILS_TRANSFORM_NORMAL);
|
||||
g_pRenderer->renderTexture(texbox, *asset, 1.0, ROUND, HYPRUTILS_TRANSFORM_NORMAL);
|
||||
g_pRenderer->popFb();
|
||||
}
|
||||
|
||||
|
|
@ -196,10 +197,10 @@ bool CImage::draw(const SRenderData& data) {
|
|||
|
||||
shadow.draw(data);
|
||||
|
||||
const auto TEXPOS = posFromHVAlign(viewport, tex->m_vSize, pos, halign, valign, angle);
|
||||
pos = posFromHVAlign(viewport, tex->m_vSize, configPos, halign, valign, angle);
|
||||
|
||||
texbox.x = TEXPOS.x;
|
||||
texbox.y = TEXPOS.y;
|
||||
texbox.x = pos.x;
|
||||
texbox.y = pos.y;
|
||||
|
||||
texbox.round();
|
||||
texbox.rot = angle;
|
||||
|
|
@ -208,28 +209,40 @@ bool CImage::draw(const SRenderData& data) {
|
|||
return data.opacity < 1.0;
|
||||
}
|
||||
|
||||
void CImage::renderUpdate() {
|
||||
auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID);
|
||||
if (newAsset) {
|
||||
if (newAsset->texture.m_iType == TEXTURE_INVALID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(newAsset);
|
||||
} else if (resourceID != pendingResourceID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
imageFB.release();
|
||||
void CImage::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
|
||||
m_pendingResource = false;
|
||||
|
||||
asset = newAsset;
|
||||
resourceID = pendingResourceID;
|
||||
firstRender = true;
|
||||
}
|
||||
pendingResourceID = "";
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
pendingResourceID = "";
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
if (!newAsset)
|
||||
Debug::log(ERR, "asset update failed, resourceID: {} not available on update!", id);
|
||||
else if (newAsset->m_iType == TEXTURE_INVALID) {
|
||||
g_asyncResourceManager->unload(newAsset);
|
||||
Debug::log(ERR, "New image asset has an invalid texture!");
|
||||
} else {
|
||||
g_asyncResourceManager->unload(asset);
|
||||
imageFB.destroyBuffer();
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
asset = newAsset;
|
||||
resourceID = id;
|
||||
firstRender = true;
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(stringPort);
|
||||
}
|
||||
|
||||
CBox CImage::getBoundingBoxWl() const {
|
||||
if (!imageFB.isAllocated())
|
||||
return CBox{};
|
||||
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - imageFB.m_cTex.m_vSize.y},
|
||||
imageFB.m_cTex.m_vSize,
|
||||
};
|
||||
}
|
||||
|
||||
void CImage::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
if (down && !onclickCommand.empty())
|
||||
spawnAsync(onclickCommand);
|
||||
}
|
||||
|
||||
void CImage::onHover(const Vector2D& pos) {
|
||||
if (!onclickCommand.empty())
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "IWidget.hpp"
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "../../core/Timer.hpp"
|
||||
#include "../AsyncResourceGatherer.hpp"
|
||||
#include "Shadowable.hpp"
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
|
@ -20,10 +20,15 @@ class CImage : public IWidget {
|
|||
CImage() = default;
|
||||
~CImage();
|
||||
|
||||
void registerSelf(const SP<CImage>& self);
|
||||
void registerSelf(const ASP<CImage>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset);
|
||||
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
void reset();
|
||||
|
||||
|
|
@ -32,32 +37,37 @@ class CImage : public IWidget {
|
|||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CImage> m_self;
|
||||
AWP<CImage> m_self;
|
||||
|
||||
CFramebuffer imageFB;
|
||||
CFramebuffer imageFB;
|
||||
|
||||
int size;
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
int size = 0;
|
||||
int rounding = 0;
|
||||
double border = 0;
|
||||
double angle = 0;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
|
||||
std::string halign, valign, path;
|
||||
std::string halign, valign, path;
|
||||
|
||||
bool firstRender = true;
|
||||
bool firstRender = true;
|
||||
|
||||
int reloadTime;
|
||||
std::string reloadCommand;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
std::shared_ptr<CTimer> imageTimer;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
int reloadTime;
|
||||
std::string reloadCommand;
|
||||
std::string onclickCommand;
|
||||
|
||||
Vector2D viewport;
|
||||
std::string stringPort;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
size_t m_imageRevision = 0;
|
||||
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if reloading image
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
CShadowable shadow;
|
||||
ASP<CTimer> imageTimer;
|
||||
|
||||
Vector2D viewport;
|
||||
std::string stringPort;
|
||||
|
||||
ResourceID resourceID = 0;
|
||||
bool m_pendingResource = false;
|
||||
|
||||
ASP<CTexture> asset = nullptr;
|
||||
CShadowable shadow;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
#include "Label.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../AsyncResourceManager.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "src/defines.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
|
|
@ -11,11 +14,11 @@ CLabel::~CLabel() {
|
|||
reset();
|
||||
}
|
||||
|
||||
void CLabel::registerSelf(const SP<CLabel>& self) {
|
||||
void CLabel::registerSelf(const ASP<CLabel>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CLabel> ref) {
|
||||
static void onTimer(AWP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL) {
|
||||
// update label
|
||||
PLABEL->onTimerUpdate();
|
||||
|
|
@ -24,16 +27,12 @@ static void onTimer(WP<CLabel> ref) {
|
|||
}
|
||||
}
|
||||
|
||||
static void onAssetCallback(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL)
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
std::string CLabel::getUniqueResourceId() {
|
||||
return std::string{"label:"} + std::to_string((uintptr_t)this) + ",time:" + std::to_string(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
}
|
||||
|
||||
void CLabel::onTimerUpdate() {
|
||||
if (m_pendingResource) {
|
||||
Debug::log(WARN, "Trying to update label, but a resource is still pending! Skipping update.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string oldFormatted = label.formatted;
|
||||
|
||||
label = formatString(labelPreFormat);
|
||||
|
|
@ -41,19 +40,17 @@ void CLabel::onTimerUpdate() {
|
|||
if (label.formatted == oldFormatted && !label.alwaysUpdate)
|
||||
return;
|
||||
|
||||
if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Trying to update label, but resource {} is still pending! Skipping update.", pendingResourceID);
|
||||
return;
|
||||
}
|
||||
|
||||
// request new
|
||||
request.id = getUniqueResourceId();
|
||||
pendingResourceID = request.id;
|
||||
request.asset = label.formatted;
|
||||
request.text = label.formatted;
|
||||
m_pendingResource = true;
|
||||
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
AWP<IWidget> widget(m_self);
|
||||
if (label.cmd) {
|
||||
// Don't increment by one to avoid clashes with multiple widget using the same label command.
|
||||
m_dynamicRevision += label.updateEveryMs;
|
||||
g_asyncResourceManager->requestTextCmd(request, m_dynamicRevision, widget.lock());
|
||||
} else
|
||||
g_asyncResourceManager->requestText(request, widget.lock());
|
||||
}
|
||||
|
||||
void CLabel::plantTimer() {
|
||||
|
|
@ -70,7 +67,7 @@ void CLabel::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
shadow.configure(m_self, props, viewport);
|
||||
|
||||
try {
|
||||
configPos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
|
|
@ -79,6 +76,7 @@ void CLabel::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
angle = angle * M_PI / 180.0;
|
||||
onclickCommand = std::any_cast<Hyprlang::STRING>(props.at("onclick"));
|
||||
|
||||
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
||||
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||
|
|
@ -87,17 +85,13 @@ void CLabel::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
|
||||
label = formatString(labelPreFormat);
|
||||
|
||||
request.id = getUniqueResourceId();
|
||||
resourceID = request.id;
|
||||
request.asset = label.formatted;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
||||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = labelColor;
|
||||
request.props["font_size"] = fontSize;
|
||||
request.props["cmd"] = label.cmd;
|
||||
request.text = label.formatted;
|
||||
request.font = fontFamily;
|
||||
request.fontSize = fontSize;
|
||||
request.color = labelColor.asRGB();
|
||||
|
||||
if (!textAlign.empty())
|
||||
request.props["text_align"] = textAlign;
|
||||
request.align = parseTextAlignment(textAlign);
|
||||
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CLabel: {}", e.what()); //
|
||||
|
|
@ -107,7 +101,10 @@ void CLabel::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
|
||||
pos = configPos; // Label size not known yet
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
if (label.cmd) {
|
||||
resourceID = g_asyncResourceManager->requestTextCmd(request, m_dynamicRevision, nullptr);
|
||||
} else
|
||||
resourceID = g_asyncResourceManager->requestText(request, nullptr);
|
||||
|
||||
plantTimer();
|
||||
}
|
||||
|
|
@ -122,16 +119,16 @@ void CLabel::reset() {
|
|||
return;
|
||||
|
||||
if (asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
g_asyncResourceManager->unload(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID.clear();
|
||||
resourceID.clear();
|
||||
asset = nullptr;
|
||||
m_pendingResource = false;
|
||||
resourceID = 0;
|
||||
}
|
||||
|
||||
bool CLabel::draw(const SRenderData& data) {
|
||||
if (!asset) {
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
asset = g_asyncResourceManager->getAssetByID(resourceID);
|
||||
|
||||
if (!asset)
|
||||
return true;
|
||||
|
|
@ -145,30 +142,49 @@ bool CLabel::draw(const SRenderData& data) {
|
|||
shadow.draw(data);
|
||||
|
||||
// calc pos
|
||||
pos = posFromHVAlign(viewport, asset->texture.m_vSize, configPos, halign, valign, angle);
|
||||
pos = posFromHVAlign(viewport, asset->m_vSize, configPos, halign, valign, angle);
|
||||
|
||||
CBox box = {pos.x, pos.y, asset->texture.m_vSize.x, asset->texture.m_vSize.y};
|
||||
CBox box = {pos.x, pos.y, asset->m_vSize.x, asset->m_vSize.y};
|
||||
box.rot = angle;
|
||||
g_pRenderer->renderTexture(box, asset->texture, data.opacity);
|
||||
g_pRenderer->renderTexture(box, *asset, data.opacity);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CLabel::renderUpdate() {
|
||||
auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID);
|
||||
if (newAsset) {
|
||||
// new asset is ready :D
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
asset = newAsset;
|
||||
resourceID = pendingResourceID;
|
||||
pendingResourceID = "";
|
||||
updateShadow = true;
|
||||
void CLabel::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
|
||||
Debug::log(TRACE, "Label update for resourceID {}", id);
|
||||
m_pendingResource = false;
|
||||
|
||||
if (!newAsset)
|
||||
Debug::log(ERR, "asset update failed, resourceID: {} not available on update!", id);
|
||||
else if (newAsset->m_iType == TEXTURE_INVALID) {
|
||||
g_asyncResourceManager->unload(newAsset);
|
||||
Debug::log(ERR, "New image asset has an invalid texture!");
|
||||
} else {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
return;
|
||||
// new asset is ready :D
|
||||
g_asyncResourceManager->unload(asset);
|
||||
asset = newAsset;
|
||||
resourceID = id;
|
||||
updateShadow = true;
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
||||
CBox CLabel::getBoundingBoxWl() const {
|
||||
if (!asset)
|
||||
return CBox{};
|
||||
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - asset->m_vSize.y},
|
||||
asset->m_vSize,
|
||||
};
|
||||
}
|
||||
|
||||
void CLabel::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
if (down && !onclickCommand.empty())
|
||||
spawnAsync(onclickCommand);
|
||||
}
|
||||
|
||||
void CLabel::onHover(const Vector2D& pos) {
|
||||
if (!onclickCommand.empty())
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../defines.hpp"
|
||||
#include "IWidget.hpp"
|
||||
#include "Shadowable.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../core/Timer.hpp"
|
||||
#include "../AsyncResourceGatherer.hpp"
|
||||
#include <hyprgraphics/resource/resources/AsyncResource.hpp>
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
|
@ -17,10 +18,15 @@ class CLabel : public IWidget {
|
|||
CLabel() = default;
|
||||
~CLabel();
|
||||
|
||||
void registerSelf(const SP<CLabel>& self);
|
||||
void registerSelf(const ASP<CLabel>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset);
|
||||
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
void reset();
|
||||
|
||||
|
|
@ -29,28 +35,32 @@ class CLabel : public IWidget {
|
|||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CLabel> m_self;
|
||||
AWP<CLabel> m_self;
|
||||
|
||||
std::string getUniqueResourceId();
|
||||
std::string labelPreFormat;
|
||||
IWidget::SFormatResult label;
|
||||
|
||||
std::string labelPreFormat;
|
||||
IWidget::SFormatResult label;
|
||||
std::string halign, valign;
|
||||
std::string onclickCommand;
|
||||
|
||||
Vector2D viewport;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
double angle;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if dynamic label
|
||||
std::string halign, valign;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
Vector2D viewport;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
double angle;
|
||||
|
||||
std::string outputStringPort;
|
||||
ResourceID resourceID = 0;
|
||||
bool m_pendingResource = false;
|
||||
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
size_t m_dynamicRevision = 0;
|
||||
|
||||
std::shared_ptr<CTimer> labelTimer = nullptr;
|
||||
ASP<CTexture> asset = nullptr;
|
||||
|
||||
CShadowable shadow;
|
||||
bool updateShadow = true;
|
||||
std::string outputStringPort;
|
||||
|
||||
Hyprgraphics::CTextResource::STextResourceData request;
|
||||
|
||||
ASP<CTimer> labelTimer = nullptr;
|
||||
|
||||
CShadowable shadow;
|
||||
bool updateShadow = true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "PasswordInputField.hpp"
|
||||
#include "../AsyncResourceManager.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../auth/Auth.hpp"
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
#include "../../core/AnimationManager.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprgraphics/resource/resources/TextResource.hpp>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <algorithm>
|
||||
|
|
@ -19,7 +21,7 @@ CPasswordInputField::~CPasswordInputField() {
|
|||
reset();
|
||||
}
|
||||
|
||||
void CPasswordInputField::registerSelf(const SP<CPasswordInputField>& self) {
|
||||
void CPasswordInputField::registerSelf(const ASP<CPasswordInputField>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ void CPasswordInputField::configure(const std::unordered_map<std::string, std::a
|
|||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
shadow.configure(m_self, props, viewport);
|
||||
|
||||
try {
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
|
|
@ -86,16 +88,12 @@ void CPasswordInputField::configure(const std::unordered_map<std::string, std::a
|
|||
pos = posFromHVAlign(viewport, size->goal(), configPos, halign, valign);
|
||||
|
||||
if (!dots.textFormat.empty()) {
|
||||
dots.textResourceID = std::format("input:{}-{}", (uintptr_t)this, dots.textFormat);
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
request.id = dots.textResourceID;
|
||||
request.asset = dots.textFormat;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
||||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = colorConfig.font;
|
||||
request.props["font_size"] = (int)(std::nearbyint(configSize.y * dots.size * 0.5f) * 2.f);
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
Hyprgraphics::CTextResource::STextResourceData request;
|
||||
request.text = dots.textFormat;
|
||||
request.font = fontFamily;
|
||||
request.color = colorConfig.font.asRGB();
|
||||
request.fontSize = (int)(std::nearbyint(configSize.y * dots.size * 0.5f) * 2.f);
|
||||
dots.textResourceID = g_asyncResourceManager->requestText(request, nullptr);
|
||||
}
|
||||
|
||||
// request the inital placeholder asset
|
||||
|
|
@ -103,7 +101,7 @@ void CPasswordInputField::configure(const std::unordered_map<std::string, std::a
|
|||
}
|
||||
|
||||
void CPasswordInputField::reset() {
|
||||
if (fade.fadeOutTimer.get()) {
|
||||
if (fade.fadeOutTimer) {
|
||||
fade.fadeOutTimer->cancel();
|
||||
fade.fadeOutTimer.reset();
|
||||
}
|
||||
|
|
@ -112,14 +110,14 @@ void CPasswordInputField::reset() {
|
|||
return;
|
||||
|
||||
if (placeholder.asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.asset);
|
||||
g_asyncResourceManager->unload(placeholder.asset);
|
||||
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID.clear();
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID = 0;
|
||||
placeholder.currentText.clear();
|
||||
}
|
||||
|
||||
static void fadeOutCallback(WP<CPasswordInputField> ref) {
|
||||
static void fadeOutCallback(AWP<CPasswordInputField> ref) {
|
||||
if (const auto PP = ref.lock(); PP)
|
||||
PP->onFadeOutTimer();
|
||||
}
|
||||
|
|
@ -151,7 +149,7 @@ void CPasswordInputField::updateFade() {
|
|||
if (fade.allowFadeOut || fadeTimeoutMs == 0) {
|
||||
*fade.a = 0.0;
|
||||
fade.allowFadeOut = false;
|
||||
} else if (!fade.fadeOutTimer.get())
|
||||
} else if (!fade.fadeOutTimer)
|
||||
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), [REF = m_self](auto, auto) { fadeOutCallback(REF); }, nullptr);
|
||||
|
||||
} else if (INPUTUSED && fade.a->goal() != 1.0)
|
||||
|
|
@ -242,12 +240,12 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
|
||||
if (!dots.textFormat.empty()) {
|
||||
if (!dots.textAsset)
|
||||
dots.textAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(dots.textResourceID);
|
||||
dots.textAsset = g_asyncResourceManager->getAssetByID(dots.textResourceID);
|
||||
|
||||
if (!dots.textAsset)
|
||||
forceReload = true;
|
||||
else {
|
||||
passSize = dots.textAsset->texture.m_vSize;
|
||||
passSize = dots.textAsset->m_vSize;
|
||||
passSpacing = std::floor(passSize.x * dots.spacing);
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +291,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
break;
|
||||
}
|
||||
|
||||
g_pRenderer->renderTexture(box, dots.textAsset->texture, fontCol.a, dots.rounding);
|
||||
g_pRenderer->renderTexture(box, *dots.textAsset, fontCol.a, dots.rounding);
|
||||
} else
|
||||
g_pRenderer->renderRect(box, fontCol, dots.rounding);
|
||||
|
||||
|
|
@ -301,22 +299,22 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
}
|
||||
}
|
||||
|
||||
if (passwordLength == 0 && !checkWaiting && !placeholder.resourceID.empty()) {
|
||||
SPreloadedAsset* currAsset = nullptr;
|
||||
if (passwordLength == 0 && !checkWaiting && placeholder.resourceID > 0) {
|
||||
ASP<CTexture> currAsset = nullptr;
|
||||
|
||||
if (!placeholder.asset)
|
||||
placeholder.asset = g_pRenderer->asyncResourceGatherer->getAssetByID(placeholder.resourceID);
|
||||
placeholder.asset = g_asyncResourceManager->getAssetByID(placeholder.resourceID);
|
||||
|
||||
currAsset = placeholder.asset;
|
||||
|
||||
if (currAsset) {
|
||||
const Vector2D ASSETPOS = inputFieldBox.pos() + inputFieldBox.size() / 2.0 - currAsset->texture.m_vSize / 2.0;
|
||||
const CBox ASSETBOX{ASSETPOS, currAsset->texture.m_vSize};
|
||||
const Vector2D ASSETPOS = inputFieldBox.pos() + inputFieldBox.size() / 2.0 - currAsset->m_vSize / 2.0;
|
||||
const CBox ASSETBOX{ASSETPOS, currAsset->m_vSize};
|
||||
|
||||
// Cut the texture to the width of the input field
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(inputFieldBox.x, inputFieldBox.y, inputFieldBox.w, inputFieldBox.h);
|
||||
g_pRenderer->renderTexture(ASSETBOX, currAsset->texture, data.opacity * fade.a->value(), 0);
|
||||
g_pRenderer->renderTexture(ASSETBOX, *currAsset, data.opacity * fade.a->value(), 0);
|
||||
glScissor(0, 0, viewport.x, viewport.y);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else
|
||||
|
|
@ -329,10 +327,9 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
void CPasswordInputField::updatePlaceholder() {
|
||||
if (passwordLength != 0) {
|
||||
if (placeholder.asset && /* keep prompt asset cause it is likely to be used again */ displayFail) {
|
||||
std::erase(placeholder.registeredResourceIDs, placeholder.resourceID);
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.asset);
|
||||
g_asyncResourceManager->unload(placeholder.asset);
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID = "";
|
||||
placeholder.resourceID = 0;
|
||||
redrawShadow = true;
|
||||
}
|
||||
return;
|
||||
|
|
@ -351,43 +348,30 @@ void CPasswordInputField::updatePlaceholder() {
|
|||
if (!ALLOWCOLORSWAP && newText == placeholder.currentText)
|
||||
return;
|
||||
|
||||
const auto NEWRESOURCEID =
|
||||
std::format("placeholder:{}{}{}{}{}{}", placeholder.currentText, (uintptr_t)this, colorState.font.r, colorState.font.g, colorState.font.b, colorState.font.a);
|
||||
|
||||
if (placeholder.resourceID == NEWRESOURCEID)
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "Updating placeholder text: {}", newText);
|
||||
Debug::log(LOG, "Updating placeholder text: {}", newText);
|
||||
placeholder.currentText = newText;
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID = NEWRESOURCEID;
|
||||
|
||||
if (std::ranges::find(placeholder.registeredResourceIDs, placeholder.resourceID) != placeholder.registeredResourceIDs.end())
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "Requesting new placeholder asset: {}", placeholder.resourceID);
|
||||
placeholder.registeredResourceIDs.push_back(placeholder.resourceID);
|
||||
|
||||
// query
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
request.id = placeholder.resourceID;
|
||||
request.asset = placeholder.currentText;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
||||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = colorState.font;
|
||||
request.props["font_size"] = (int)size->value().y / 4;
|
||||
request.callback = [REF = m_self] {
|
||||
if (const auto SELF = REF.lock(); SELF)
|
||||
g_pHyprlock->renderOutput(SELF->outputStringPort);
|
||||
};
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
Hyprgraphics::CTextResource::STextResourceData request;
|
||||
request.text = placeholder.currentText;
|
||||
request.font = fontFamily;
|
||||
request.color = colorState.font.asRGB();
|
||||
request.fontSize = (int)size->value().y / 4;
|
||||
|
||||
AWP<IWidget> widget(m_self);
|
||||
placeholder.resourceID = g_asyncResourceManager->requestText(request, widget);
|
||||
}
|
||||
|
||||
void CPasswordInputField::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
|
||||
;
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateWidth() {
|
||||
double targetSizeX = configSize.x;
|
||||
|
||||
if (passwordLength == 0 && placeholder.asset)
|
||||
targetSizeX = placeholder.asset->texture.m_vSize.x + size->goal().y;
|
||||
targetSizeX = placeholder.asset->m_vSize.x + size->goal().y;
|
||||
|
||||
targetSizeX = std::max(targetSizeX, configSize.x);
|
||||
|
||||
|
|
@ -473,3 +457,14 @@ void CPasswordInputField::updateColors() {
|
|||
|
||||
colorState.font = fontTarget;
|
||||
}
|
||||
|
||||
CBox CPasswordInputField::getBoundingBoxWl() const {
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - size->value().y},
|
||||
size->value(),
|
||||
};
|
||||
}
|
||||
|
||||
void CPasswordInputField::onHover(const Vector2D& pos) {
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "IWidget.hpp"
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include "../../core/Timer.hpp"
|
||||
|
|
@ -19,69 +20,71 @@ class CPasswordInputField : public IWidget {
|
|||
CPasswordInputField() = default;
|
||||
virtual ~CPasswordInputField();
|
||||
|
||||
void registerSelf(const SP<CPasswordInputField>& self);
|
||||
void registerSelf(const ASP<CPasswordInputField>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset);
|
||||
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
||||
private:
|
||||
WP<CPasswordInputField> m_self;
|
||||
AWP<CPasswordInputField> m_self;
|
||||
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
|
||||
size_t passwordLength = 0;
|
||||
size_t passwordLength = 0;
|
||||
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
|
||||
int outThick, rounding;
|
||||
int outThick, rounding;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<float> currentAmount;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
std::string textFormat = "";
|
||||
std::string textResourceID;
|
||||
SPreloadedAsset* textAsset = nullptr;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
size_t textResourceID = 0;
|
||||
std::string textFormat = "";
|
||||
ASP<CTexture> textAsset = nullptr;
|
||||
} dots;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<float> a;
|
||||
bool appearing = true;
|
||||
std::shared_ptr<CTimer> fadeOutTimer = nullptr;
|
||||
bool allowFadeOut = false;
|
||||
PHLANIMVAR<float> a;
|
||||
bool appearing = true;
|
||||
ASP<CTimer> fadeOutTimer = nullptr;
|
||||
bool allowFadeOut = false;
|
||||
} fade;
|
||||
|
||||
struct {
|
||||
std::string resourceID = "";
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
size_t resourceID = 0;
|
||||
ASP<CTexture> asset = nullptr;
|
||||
|
||||
std::string currentText = "";
|
||||
size_t failedAttempts = 0;
|
||||
|
||||
std::vector<std::string> registeredResourceIDs;
|
||||
std::string currentText = "";
|
||||
size_t failedAttempts = 0;
|
||||
} placeholder;
|
||||
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include "../Renderer.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
void CShadowable::configure(WP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) {
|
||||
void CShadowable::configure(AWP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) {
|
||||
m_widget = widget_;
|
||||
viewport = viewport_;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,19 +13,19 @@ class CShadowable {
|
|||
public:
|
||||
virtual ~CShadowable() = default;
|
||||
CShadowable() = default;
|
||||
void configure(WP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_ /* TODO: make this not the entire viewport */);
|
||||
void configure(AWP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_ /* TODO: make this not the entire viewport */);
|
||||
|
||||
// instantly re-renders the shadow using the widget's draw() method
|
||||
void markShadowDirty();
|
||||
virtual bool draw(const IWidget::SRenderData& data);
|
||||
|
||||
private:
|
||||
WP<IWidget> m_widget;
|
||||
int size = 10;
|
||||
int passes = 4;
|
||||
float boostA = 1.0;
|
||||
CHyprColor color{0, 0, 0, 1.0};
|
||||
Vector2D viewport;
|
||||
AWP<IWidget> m_widget;
|
||||
int size = 10;
|
||||
int passes = 4;
|
||||
float boostA = 1.0;
|
||||
CHyprColor color{0, 0, 0, 1.0};
|
||||
Vector2D viewport;
|
||||
|
||||
// to avoid recursive shadows
|
||||
bool ignoreDraw = false;
|
||||
|
|
|
|||
|
|
@ -1,29 +1,33 @@
|
|||
#include "Shape.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
#include <sys/types.h>
|
||||
|
||||
void CShape::registerSelf(const SP<CShape>& self) {
|
||||
void CShape::registerSelf(const ASP<CShape>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CShape::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
shadow.configure(m_self, props, viewport);
|
||||
|
||||
try {
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
borderGrad = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
xray = std::any_cast<Hyprlang::INT>(props.at("xray"));
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
borderGrad = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
xray = std::any_cast<Hyprlang::INT>(props.at("xray"));
|
||||
onclickCommand = std::any_cast<Hyprlang::STRING>(props.at("onclick"));
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CShape: {}", e.what()); //
|
||||
} catch (const std::out_of_range& e) {
|
||||
|
|
@ -100,3 +104,24 @@ bool CShape::draw(const SRenderData& data) {
|
|||
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
|
||||
void CShape::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
|
||||
;
|
||||
}
|
||||
|
||||
CBox CShape::getBoundingBoxWl() const {
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - size.y},
|
||||
size,
|
||||
};
|
||||
}
|
||||
|
||||
void CShape::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
if (down && !onclickCommand.empty())
|
||||
spawnAsync(onclickCommand);
|
||||
}
|
||||
|
||||
void CShape::onHover(const Vector2D& pos) {
|
||||
if (!onclickCommand.empty())
|
||||
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,18 @@ class CShape : public IWidget {
|
|||
CShape() = default;
|
||||
virtual ~CShape() = default;
|
||||
|
||||
void registerSelf(const SP<CShape>& self);
|
||||
void registerSelf(const ASP<CShape>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void onAssetUpdate(ResourceID id, ASP<CTexture> newAsset);
|
||||
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
private:
|
||||
WP<CShape> m_self;
|
||||
AWP<CShape> m_self;
|
||||
|
||||
CFramebuffer shapeFB;
|
||||
|
||||
|
|
@ -38,6 +43,7 @@ class CShape : public IWidget {
|
|||
std::string halign, valign;
|
||||
|
||||
bool firstRender = true;
|
||||
std::string onclickCommand;
|
||||
|
||||
Vector2D viewport;
|
||||
CShadowable shadow;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue