mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-05-12 21:30:37 +01:00
Compare commits
66 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7f0c9c6b0 | ||
![]() |
c12cf8e509 | ||
![]() |
0c5fd97d61 | ||
![]() |
fae1c4f6fe | ||
![]() |
e3bd47e177 | ||
![]() |
6c64630df8 | ||
![]() |
0e3e7206bc | ||
![]() |
867a71dd78 | ||
![]() |
82808290d9 | ||
![]() |
eb28a71756 | ||
![]() |
b3f1aa7580 | ||
![]() |
248dfb09f7 | ||
![]() |
656704aeb0 | ||
![]() |
d953296227 | ||
![]() |
71d35aa75f | ||
![]() |
8f73c39f07 | ||
![]() |
a8de918cc4 | ||
![]() |
6daab0517c | ||
![]() |
854235e1c8 | ||
![]() |
dd4c1d5034 | ||
![]() |
0b1f2a97ef | ||
![]() |
ce1eb7b5f9 | ||
![]() |
1ebbc35c55 | ||
![]() |
d9a1625315 | ||
![]() |
9e54d02590 | ||
![]() |
f883e669d1 | ||
![]() |
ee8ee1f9f7 | ||
![]() |
7ab3162d66 | ||
![]() |
9e82fe3547 | ||
![]() |
a13b6f0d1a | ||
![]() |
78ad1d46b5 | ||
![]() |
cb1c504b38 | ||
![]() |
9f37c1c8e9 | ||
![]() |
712ab62a42 | ||
![]() |
e588351d1d | ||
![]() |
2a6ec58366 | ||
![]() |
f6e4c1374e | ||
![]() |
c4b2175822 | ||
![]() |
82b63a6930 | ||
![]() |
a27585b383 | ||
![]() |
ad7600dca9 | ||
![]() |
dc6d72158c | ||
![]() |
ce750456f9 | ||
![]() |
ec82da7108 | ||
![]() |
465148ac21 | ||
![]() |
c976b6a1d1 | ||
![]() |
1bfa79eb83 | ||
![]() |
e77bc92b99 | ||
![]() |
408ce95dd0 | ||
![]() |
07b5e1b4cd | ||
![]() |
742eb98c6a | ||
![]() |
d547d1d4e3 | ||
![]() |
02639c2759 | ||
![]() |
4f964371cc | ||
![]() |
023aff52ad | ||
![]() |
e84267085d | ||
![]() |
a5e346783f | ||
![]() |
73e23e535f | ||
![]() |
de844d39ad | ||
![]() |
00d2cbfee3 | ||
![]() |
8f68fad50a | ||
![]() |
c3d95953c0 | ||
![]() |
e01afaf107 | ||
![]() |
a2f00fb735 | ||
![]() |
836dbfbb13 | ||
![]() |
2c5ae4d661 |
65 changed files with 2897 additions and 1618 deletions
101
.clang-tidy
Normal file
101
.clang-tidy
Normal file
|
@ -0,0 +1,101 @@
|
|||
WarningsAsErrors: '*'
|
||||
HeaderFilterRegex: '.*\.hpp'
|
||||
FormatStyle: 'file'
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-forward-declaration-namespace,
|
||||
-bugprone-forward-declaration-namespace,
|
||||
-bugprone-macro-parentheses,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-branch-clone,
|
||||
-bugprone-assignment-in-if-condition,
|
||||
concurrency-*,
|
||||
-concurrency-mt-unsafe,
|
||||
cppcoreguidelines-*,
|
||||
-cppcoreguidelines-owning-memory,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||
-cppcoreguidelines-avoid-goto,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-cppcoreguidelines-avoid-do-while,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-cppcoreguidelines-special-member-functions,
|
||||
-cppcoreguidelines-explicit-virtual-functions,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-narrowing-conversions,
|
||||
-cppcoreguidelines-pro-type-union-access,
|
||||
-cppcoreguidelines-pro-type-member-init,
|
||||
-cppcoreguidelines-macro-usage,
|
||||
-cppcoreguidelines-macro-to-enum,
|
||||
-cppcoreguidelines-init-variables,
|
||||
-cppcoreguidelines-pro-type-cstyle-cast,
|
||||
-cppcoreguidelines-pro-type-vararg,
|
||||
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||
google-global-names-in-headers,
|
||||
-google-readability-casting,
|
||||
google-runtime-operator,
|
||||
misc-*,
|
||||
-misc-unused-parameters,
|
||||
-misc-no-recursion,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-include-cleaner,
|
||||
-misc-use-anonymous-namespace,
|
||||
-misc-const-correctness,
|
||||
modernize-*,
|
||||
-modernize-return-braced-init-list,
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-use-using,
|
||||
-modernize-use-override,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-macro-to-enum,
|
||||
-modernize-loop-convert,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-pass-by-value,
|
||||
-modernize-use-auto,
|
||||
performance-*,
|
||||
-performance-avoid-endl,
|
||||
-performance-unnecessary-value-param,
|
||||
portability-std-allocator-const,
|
||||
readability-*,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-length,
|
||||
-readability-magic-numbers,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-braces-around-statements,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-else-after-return,
|
||||
-readability-container-data-pointer,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-avoid-nested-conditional-operator,
|
||||
-readability-redundant-member-init,
|
||||
-readability-redundant-string-init,
|
||||
-readability-avoid-const-params-in-decls,
|
||||
-readability-named-parameter,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-qualified-auto,
|
||||
-readability-make-member-function-const,
|
||||
-readability-isolate-declaration,
|
||||
-readability-inconsistent-declaration-parameter-name,
|
||||
-clang-diagnostic-error,
|
||||
|
||||
CheckOptions:
|
||||
performance-for-range-copy.WarnOnAllAutoCopies: true
|
||||
performance-inefficient-string-concatenation.StrictMode: true
|
||||
readability-braces-around-statements.ShortStatementLines: 0
|
||||
readability-identifier-naming.ClassCase: CamelCase
|
||||
readability-identifier-naming.ClassIgnoredRegexp: I.*
|
||||
readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
|
||||
readability-identifier-naming.EnumCase: CamelCase
|
||||
readability-identifier-naming.EnumPrefix: e
|
||||
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.FunctionCase: camelBack
|
||||
readability-identifier-naming.NamespaceCase: CamelCase
|
||||
readability-identifier-naming.NamespacePrefix: N
|
||||
readability-identifier-naming.StructPrefix: S
|
||||
readability-identifier-naming.StructCase: CamelCase
|
1
.github/workflows/nix.yml
vendored
1
.github/workflows/nix.yml
vendored
|
@ -8,7 +8,6 @@ jobs:
|
|||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
|
||||
# not needed (yet)
|
||||
# - uses: cachix/cachix-action@v12
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ compile_commands.json
|
|||
protocols/*.cpp
|
||||
protocols/*.hpp
|
||||
*.kdev4
|
||||
.gdb_history
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.19)
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
|
||||
file(READ "${CMAKE_SOURCE_DIR}/VERSION" VER_RAW)
|
||||
string(STRIP ${VER_RAW} VERSION)
|
||||
|
@ -28,25 +28,39 @@ set(CMAKE_CXX_STANDARD 23)
|
|||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
|
||||
-Wno-missing-field-initializers -Wno-narrowing)
|
||||
|
||||
# get git commit
|
||||
execute_process(
|
||||
OUTPUT_VARIABLE GIT_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND git rev-parse --short HEAD
|
||||
)
|
||||
|
||||
# get git commit of v$VERSION
|
||||
execute_process(
|
||||
OUTPUT_VARIABLE GIT_TAG_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND git rev-parse --short v${VERSION}
|
||||
)
|
||||
|
||||
|
||||
add_compile_definitions(HYPRLOCK_VERSION="${VERSION}")
|
||||
add_compile_definitions(HYPRLOCK_COMMIT="${GIT_SHORT_HASH}")
|
||||
add_compile_definitions(HYPRLOCK_VERSION_COMMIT="${GIT_TAG_SHORT_HASH}")
|
||||
|
||||
if (DEFINED HYPRLOCK_COMMIT)
|
||||
add_compile_definitions(HYPRLOCK_COMMIT="${HYPRLOCK_COMMIT}")
|
||||
else()
|
||||
# get git commit
|
||||
execute_process(
|
||||
OUTPUT_VARIABLE GIT_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND git rev-parse --short HEAD
|
||||
)
|
||||
add_compile_definitions(HYPRLOCK_COMMIT="${GIT_SHORT_HASH}")
|
||||
endif()
|
||||
|
||||
if (DEFINED HYPRLOCK_VERSION_COMMIT)
|
||||
add_compile_definitions(HYPRLOCK_VERSION_COMMIT="${HYPRLOCK_VERSION_COMMIT}")
|
||||
else()
|
||||
# get git commit of v$VERSION
|
||||
execute_process(
|
||||
OUTPUT_VARIABLE GIT_TAG_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND git rev-parse --short v${VERSION}
|
||||
)
|
||||
add_compile_definitions(HYPRLOCK_VERSION_COMMIT="${GIT_TAG_SHORT_HASH}")
|
||||
endif()
|
||||
|
||||
message(STATUS "VERSION COMMIT: ${HYPRLOCK_VERSION_COMMIT}")
|
||||
message(STATUS "COMMIT: ${HYPRLOCK_COMMIT}")
|
||||
|
||||
# position independent build: __FILE__
|
||||
add_compile_options(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=)
|
||||
|
@ -56,34 +70,30 @@ message(STATUS "Checking deps...")
|
|||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(OpenGL REQUIRED COMPONENTS EGL GLES3)
|
||||
find_package(hyprwayland-scanner 0.4.4 REQUIRED)
|
||||
pkg_check_modules(
|
||||
deps
|
||||
REQUIRED
|
||||
IMPORTED_TARGET
|
||||
wayland-client
|
||||
wayland-protocols
|
||||
wayland-protocols>=1.35
|
||||
wayland-egl
|
||||
hyprlang>=0.4.0
|
||||
hyprlang>=0.6.0
|
||||
egl
|
||||
opengl
|
||||
xkbcommon
|
||||
libjpeg
|
||||
libwebp
|
||||
libmagic
|
||||
cairo
|
||||
pangocairo
|
||||
libdrm
|
||||
gbm
|
||||
hyprutils>=0.2.6
|
||||
hyprutils>=0.5.0
|
||||
sdbus-c++>=2.0.0
|
||||
hyprgraphics)
|
||||
|
||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
add_executable(hyprlock ${SRCFILES})
|
||||
target_link_libraries(hyprlock PRIVATE pam rt Threads::Threads PkgConfig::deps
|
||||
OpenGL::EGL OpenGL::GL)
|
||||
OpenGL::EGL OpenGL::GLES3)
|
||||
|
||||
# protocols
|
||||
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
|
||||
|
|
39
README.md
39
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,23 @@ 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
|
||||
- hyprland-protocols
|
||||
- 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.6.0
|
||||
0.8.2
|
||||
|
|
|
@ -1,11 +1,106 @@
|
|||
# sample hyprlock.conf
|
||||
# for more configuration options, refer https://wiki.hyprland.org/Hypr-Ecosystem/hyprlock
|
||||
#
|
||||
# rendered text in all widgets supports pango markup (e.g. <b> or <i> tags)
|
||||
# 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
|
||||
#
|
||||
|
||||
input-field {
|
||||
monitor =
|
||||
fade_on_empty = false
|
||||
$font = Monospace
|
||||
|
||||
general {
|
||||
hide_cursor = false
|
||||
}
|
||||
|
||||
# uncomment to enable fingerprint authentication
|
||||
# auth {
|
||||
# fingerprint {
|
||||
# enabled = true
|
||||
# ready_message = Scan fingerprint to unlock
|
||||
# present_message = Scanning...
|
||||
# retry_delay = 250 # in milliseconds
|
||||
# }
|
||||
# }
|
||||
|
||||
animations {
|
||||
enabled = true
|
||||
bezier = linear, 1, 1, 0, 0
|
||||
animation = fadeIn, 1, 5, linear
|
||||
animation = fadeOut, 1, 5, linear
|
||||
animation = inputFieldDots, 1, 2, linear
|
||||
}
|
||||
|
||||
background {
|
||||
color = rgb(23, 39, 41)
|
||||
monitor =
|
||||
path = screenshot
|
||||
blur_passes = 3
|
||||
}
|
||||
|
||||
input-field {
|
||||
monitor =
|
||||
size = 20%, 5%
|
||||
outline_thickness = 3
|
||||
inner_color = rgba(0, 0, 0, 0.0) # no fill
|
||||
|
||||
outer_color = rgba(33ccffee) rgba(00ff99ee) 45deg
|
||||
check_color = rgba(00ff99ee) rgba(ff6633ee) 120deg
|
||||
fail_color = rgba(ff6633ee) rgba(ff0066ee) 40deg
|
||||
|
||||
font_color = rgb(143, 143, 143)
|
||||
fade_on_empty = false
|
||||
rounding = 15
|
||||
|
||||
font_family = $font
|
||||
placeholder_text = Input password...
|
||||
fail_text = $PAMFAIL
|
||||
|
||||
# uncomment to use a letter instead of a dot to indicate the typed password
|
||||
# dots_text_format = *
|
||||
# dots_size = 0.4
|
||||
dots_spacing = 0.3
|
||||
|
||||
# uncomment to use an input indicator that does not show the password length (similar to swaylock's input indicator)
|
||||
# hide_input = true
|
||||
|
||||
position = 0, -20
|
||||
halign = center
|
||||
valign = center
|
||||
}
|
||||
|
||||
# TIME
|
||||
label {
|
||||
monitor =
|
||||
text = $TIME # ref. https://wiki.hyprland.org/Hypr-Ecosystem/hyprlock/#variable-substitution
|
||||
font_size = 90
|
||||
font_family = $font
|
||||
|
||||
position = -30, 0
|
||||
halign = right
|
||||
valign = top
|
||||
}
|
||||
|
||||
# DATE
|
||||
label {
|
||||
monitor =
|
||||
text = cmd[update:60000] date +"%A, %d %B %Y" # update every 60 seconds
|
||||
font_size = 25
|
||||
font_family = $font
|
||||
|
||||
position = -30, -150
|
||||
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
30
flake.lock
|
@ -13,11 +13,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1734906236,
|
||||
"narHash": "sha256-vH/ysV2ONGQgYZPtcJKwc8jJivzyVxru2aaOxC20ZOE=",
|
||||
"lastModified": 1743953322,
|
||||
"narHash": "sha256-prQ5JKopXtzCMX2eT3dXbaVvGmzjMRE2bXStQDdazpM=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprgraphics",
|
||||
"rev": "6dea3fba08fd704dd624b6d4b261638fb4003c9c",
|
||||
"rev": "9d7f2687c84c729afbc3b13f7937655570f2978d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -39,11 +39,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735393019,
|
||||
"narHash": "sha256-NPpqA8rtmDLsEmZOmz+qR67zsB6Y503Jnv+nSFLKJZ8=",
|
||||
"lastModified": 1744468525,
|
||||
"narHash": "sha256-9HySx+EtsbbKlZDlY+naqqOV679VdxP6x6fP3wxDXJk=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprlang",
|
||||
"rev": "55608efdaa387af7bfdc0eddb404c409958efa43",
|
||||
"rev": "f1000c54d266e6e4e9d646df0774fac5b8a652df",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -62,11 +62,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735316583,
|
||||
"narHash": "sha256-AiiUwHWHfEdpFzXy7l1x3zInCUa1xcRMrbZ1XRSkzwU=",
|
||||
"lastModified": 1743950287,
|
||||
"narHash": "sha256-/6IAEWyb8gC/NKZElxiHChkouiUOrVYNq9YqG0Pzm4Y=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"rev": "8f15d45b120b33712f6db477fe5ffb18034d0ea8",
|
||||
"rev": "f2dc70e448b994cef627a157ee340135bd68fbc6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -85,11 +85,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1735493474,
|
||||
"narHash": "sha256-fktzv4NaqKm94VAkAoVqO/nqQlw+X0/tJJNAeCSfzK4=",
|
||||
"lastModified": 1739870480,
|
||||
"narHash": "sha256-SiDN5BGxa/1hAsqhgJsS03C3t2QrLgBT8u+ENJ0Qzwc=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprwayland-scanner",
|
||||
"rev": "de913476b59ee88685fdc018e77b8f6637a2ae0b",
|
||||
"rev": "206367a08dc5ac4ba7ad31bdca391d098082e64b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -100,11 +100,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1735291276,
|
||||
"narHash": "sha256-NYVcA06+blsLG6wpAbSPTCyLvxD/92Hy4vlY9WxFI1M=",
|
||||
"lastModified": 1744463964,
|
||||
"narHash": "sha256-LWqduOgLHCFxiTNYi3Uj5Lgz0SR+Xhw3kr/3Xd0GPTM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "634fd46801442d760e09493a794c4f15db2d0cbb",
|
||||
"rev": "2631b0b7abcea6e640ce31cd78ea58910d31e650",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
cmake,
|
||||
pkg-config,
|
||||
cairo,
|
||||
file,
|
||||
libdrm,
|
||||
libGL,
|
||||
libjpeg,
|
||||
libwebp,
|
||||
libxkbcommon,
|
||||
mesa,
|
||||
libgbm,
|
||||
hyprgraphics,
|
||||
hyprlang,
|
||||
hyprutils,
|
||||
|
@ -40,13 +37,10 @@ stdenv.mkDerivation {
|
|||
|
||||
buildInputs = [
|
||||
cairo
|
||||
file
|
||||
libdrm
|
||||
libGL
|
||||
libjpeg
|
||||
libwebp
|
||||
libxkbcommon
|
||||
mesa
|
||||
libgbm
|
||||
hyprgraphics
|
||||
hyprlang
|
||||
hyprutils
|
||||
|
@ -60,7 +54,7 @@ stdenv.mkDerivation {
|
|||
|
||||
cmakeFlags = lib.mapAttrsToList lib.cmakeFeature {
|
||||
HYPRLOCK_COMMIT = shortRev;
|
||||
HYPRLOCK_VERSION_COMMIT = shortRev;
|
||||
HYPRLOCK_VERSION_COMMIT = ""; # Intentionally left empty (hyprlock --version will always print the commit)
|
||||
};
|
||||
|
||||
meta = {
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
#include <memory>
|
||||
|
||||
CAuth::CAuth() {
|
||||
static auto* const PENABLEPAM = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("auth:pam:enabled");
|
||||
if (**PENABLEPAM)
|
||||
m_vImpls.push_back(std::make_shared<CPam>());
|
||||
static auto* const PENABLEFINGERPRINT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("auth:fingerprint:enabled");
|
||||
if (**PENABLEFINGERPRINT)
|
||||
m_vImpls.push_back(std::make_shared<CFingerprint>());
|
||||
static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled");
|
||||
if (*ENABLEPAM)
|
||||
m_vImpls.emplace_back(makeShared<CPam>());
|
||||
static const auto ENABLEFINGERPRINT = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:enabled");
|
||||
if (*ENABLEFINGERPRINT)
|
||||
m_vImpls.emplace_back(makeShared<CFingerprint>());
|
||||
|
||||
RASSERT(!m_vImpls.empty(), "At least one authentication method must be enabled!");
|
||||
}
|
||||
|
@ -29,32 +29,16 @@ void CAuth::submitInput(const std::string& input) {
|
|||
for (const auto& i : m_vImpls) {
|
||||
i->handleInput(input);
|
||||
}
|
||||
|
||||
g_pHyprlock->clearPasswordBuffer();
|
||||
}
|
||||
|
||||
bool CAuth::checkWaiting() {
|
||||
for (const auto& i : m_vImpls) {
|
||||
if (i->checkWaiting())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(m_vImpls, [](const auto& i) { return i->checkWaiting(); });
|
||||
}
|
||||
|
||||
std::string CAuth::getInlineFeedback() {
|
||||
std::optional<std::string> firstFeedback = std::nullopt;
|
||||
for (const auto& i : m_vImpls) {
|
||||
const auto FEEDBACK = (m_bDisplayFailText) ? i->getLastFailText() : i->getLastPrompt();
|
||||
if (!FEEDBACK.has_value())
|
||||
continue;
|
||||
|
||||
if (!firstFeedback.has_value())
|
||||
firstFeedback = FEEDBACK;
|
||||
|
||||
if (i->getImplType() == m_eLastActiveImpl)
|
||||
return FEEDBACK.value();
|
||||
}
|
||||
|
||||
return firstFeedback.value_or("Ups, no authentication feedack");
|
||||
const std::string& CAuth::getCurrentFailText() {
|
||||
return m_sCurrentFail.failText;
|
||||
}
|
||||
|
||||
std::optional<std::string> CAuth::getFailText(eAuthImplementations implType) {
|
||||
|
@ -73,7 +57,11 @@ std::optional<std::string> CAuth::getPrompt(eAuthImplementations implType) {
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::shared_ptr<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
|
||||
size_t CAuth::getFailedAttempts() {
|
||||
return m_sCurrentFail.failedAttempts;
|
||||
}
|
||||
|
||||
SP<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
|
||||
for (const auto& i : m_vImpls) {
|
||||
if (i->getImplType() == implType)
|
||||
return i;
|
||||
|
@ -88,29 +76,49 @@ void CAuth::terminate() {
|
|||
}
|
||||
}
|
||||
|
||||
static void passwordFailCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pHyprlock->clearPasswordBuffer();
|
||||
g_pAuth->m_iFailedAttempts++;
|
||||
Debug::log(LOG, "Failed attempts: {}", g_pAuth->m_iFailedAttempts);
|
||||
static void unlockCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pHyprlock->unlock();
|
||||
}
|
||||
|
||||
void CAuth::enqueueUnlock() {
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), unlockCallback, nullptr);
|
||||
}
|
||||
|
||||
static void passwordFailCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pAuth->m_bDisplayFailText = true;
|
||||
|
||||
g_pHyprlock->enqueueForceUpdateTimers();
|
||||
|
||||
g_pHyprlock->renderAllOutputs();
|
||||
}
|
||||
|
||||
static void passwordUnlockCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pHyprlock->unlock();
|
||||
static void displayFailTimeoutCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
if (g_pAuth->m_bDisplayFailText) {
|
||||
g_pAuth->m_bDisplayFailText = false;
|
||||
g_pHyprlock->renderAllOutputs();
|
||||
}
|
||||
}
|
||||
|
||||
void CAuth::enqueueFail() {
|
||||
void CAuth::enqueueFail(const std::string& failText, eAuthImplementations implType) {
|
||||
static const auto FAILTIMEOUT = g_pConfigManager->getValue<Hyprlang::INT>("general:fail_timeout");
|
||||
|
||||
m_sCurrentFail.failText = failText;
|
||||
m_sCurrentFail.failSource = implType;
|
||||
m_sCurrentFail.failedAttempts++;
|
||||
|
||||
Debug::log(LOG, "Failed attempts: {}", m_sCurrentFail.failedAttempts);
|
||||
|
||||
if (m_resetDisplayFailTimer) {
|
||||
m_resetDisplayFailTimer->cancel();
|
||||
m_resetDisplayFailTimer.reset();
|
||||
}
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordFailCallback, nullptr);
|
||||
m_resetDisplayFailTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(*FAILTIMEOUT), displayFailTimeoutCallback, nullptr);
|
||||
}
|
||||
|
||||
void CAuth::enqueueUnlock() {
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordUnlockCallback, nullptr);
|
||||
}
|
||||
|
||||
void CAuth::postActivity(eAuthImplementations implType) {
|
||||
m_eLastActiveImpl = implType;
|
||||
void CAuth::resetDisplayFail() {
|
||||
g_pAuth->m_bDisplayFailText = false;
|
||||
m_resetDisplayFailTimer->cancel();
|
||||
m_resetDisplayFailTimer.reset();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../core/Timer.hpp"
|
||||
|
||||
enum eAuthImplementations {
|
||||
AUTH_IMPL_PAM = 0,
|
||||
AUTH_IMPL_FINGERPRINT = 1,
|
||||
|
@ -28,34 +30,38 @@ class CAuth {
|
|||
public:
|
||||
CAuth();
|
||||
|
||||
void start();
|
||||
void start();
|
||||
|
||||
void submitInput(const std::string& input);
|
||||
bool checkWaiting();
|
||||
void submitInput(const std::string& input);
|
||||
bool checkWaiting();
|
||||
|
||||
// Used by the PasswordInput field. We are constraint to a single line for the authentication feedback there.
|
||||
// Based on m_bDisplayFailText, this will return either the fail text or the prompt.
|
||||
// Based on m_eLastActiveImpl, it will select the implementation.
|
||||
std::string getInlineFeedback();
|
||||
const std::string& getCurrentFailText();
|
||||
|
||||
std::optional<std::string> getFailText(eAuthImplementations implType);
|
||||
std::optional<std::string> getPrompt(eAuthImplementations implType);
|
||||
std::optional<std::string> getFailText(eAuthImplementations implType);
|
||||
std::optional<std::string> getPrompt(eAuthImplementations implType);
|
||||
size_t getFailedAttempts();
|
||||
|
||||
std::shared_ptr<IAuthImplementation> getImpl(eAuthImplementations implType);
|
||||
SP<IAuthImplementation> getImpl(eAuthImplementations implType);
|
||||
|
||||
void terminate();
|
||||
void terminate();
|
||||
|
||||
void enqueueUnlock();
|
||||
void enqueueFail(const std::string& failText, eAuthImplementations implType);
|
||||
|
||||
void resetDisplayFail();
|
||||
|
||||
// Should only be set via the main thread
|
||||
bool m_bDisplayFailText = false;
|
||||
size_t m_iFailedAttempts = 0;
|
||||
|
||||
void enqueueUnlock();
|
||||
void enqueueFail();
|
||||
void postActivity(eAuthImplementations implType);
|
||||
bool m_bDisplayFailText = false;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<IAuthImplementation>> m_vImpls;
|
||||
std::optional<eAuthImplementations> m_eLastActiveImpl = std::nullopt;
|
||||
struct {
|
||||
std::string failText = "";
|
||||
eAuthImplementations failSource = AUTH_IMPL_PAM;
|
||||
size_t failedAttempts = 0;
|
||||
} m_sCurrentFail;
|
||||
|
||||
std::vector<SP<IAuthImplementation>> m_vImpls;
|
||||
std::shared_ptr<CTimer> m_resetDisplayFailTimer;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CAuth> g_pAuth;
|
||||
inline UP<CAuth> g_pAuth;
|
||||
|
|
|
@ -36,10 +36,10 @@ static std::map<std::string, MatchResult> s_mapStringToTestType = {{"verify-no-m
|
|||
{"verify-unknown-error", MATCH_UNKNOWN_ERROR}};
|
||||
|
||||
CFingerprint::CFingerprint() {
|
||||
static auto* const PFINGERPRINTREADY = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:fingerprint:ready_message"));
|
||||
m_sFingerprintReady = *PFINGERPRINTREADY;
|
||||
static auto* const PFINGERPRINTPRESENT = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:fingerprint:present_message"));
|
||||
m_sFingerprintPresent = *PFINGERPRINTPRESENT;
|
||||
static const auto FINGERPRINTREADY = g_pConfigManager->getValue<Hyprlang::STRING>("auth:fingerprint:ready_message");
|
||||
m_sFingerprintReady = *FINGERPRINTREADY;
|
||||
static const auto FINGERPRINTPRESENT = g_pConfigManager->getValue<Hyprlang::STRING>("auth:fingerprint:present_message");
|
||||
m_sFingerprintPresent = *FINGERPRINTPRESENT;
|
||||
}
|
||||
|
||||
CFingerprint::~CFingerprint() {
|
||||
|
@ -47,8 +47,15 @@ CFingerprint::~CFingerprint() {
|
|||
}
|
||||
|
||||
void CFingerprint::init() {
|
||||
m_sDBUSState.connection = sdbus::createSystemBusConnection();
|
||||
m_sDBUSState.login = sdbus::createProxy(*m_sDBUSState.connection, sdbus::ServiceName{"org.freedesktop.login1"}, sdbus::ObjectPath{"/org/freedesktop/login1"});
|
||||
try {
|
||||
m_sDBUSState.connection = sdbus::createSystemBusConnection();
|
||||
m_sDBUSState.login = sdbus::createProxy(*m_sDBUSState.connection, sdbus::ServiceName{"org.freedesktop.login1"}, sdbus::ObjectPath{"/org/freedesktop/login1"});
|
||||
} catch (sdbus::Error& e) {
|
||||
Debug::log(ERR, "fprint: Failed to setup dbus ({})", e.what());
|
||||
m_sDBUSState.connection.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
m_sDBUSState.login->getPropertyAsync("PreparingForSleep").onInterface(LOGIN_MANAGER).uponReplyInvoke([this](std::optional<sdbus::Error> e, sdbus::Variant preparingForSleep) {
|
||||
if (e) {
|
||||
Debug::log(WARN, "fprint: Failed getting value for PreparingForSleep: {}", e->what());
|
||||
|
@ -58,20 +65,13 @@ void CFingerprint::init() {
|
|||
// When entering sleep, the wake signal will trigger startVerify().
|
||||
if (m_sDBUSState.sleeping)
|
||||
return;
|
||||
inhibitSleep();
|
||||
startVerify();
|
||||
});
|
||||
m_sDBUSState.login->uponSignal("PrepareForSleep").onInterface(LOGIN_MANAGER).call([this](bool start) {
|
||||
Debug::log(LOG, "fprint: PrepareForSleep (start: {})", start);
|
||||
if (start) {
|
||||
m_sDBUSState.sleeping = true;
|
||||
stopVerify();
|
||||
m_sDBUSState.inhibitLock.reset();
|
||||
} else {
|
||||
m_sDBUSState.sleeping = false;
|
||||
inhibitSleep();
|
||||
m_sDBUSState.sleeping = start;
|
||||
if (!m_sDBUSState.sleeping && !m_sDBUSState.verifying)
|
||||
startVerify();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -104,18 +104,6 @@ std::shared_ptr<sdbus::IConnection> CFingerprint::getConnection() {
|
|||
return m_sDBUSState.connection;
|
||||
}
|
||||
|
||||
void CFingerprint::inhibitSleep() {
|
||||
m_sDBUSState.login->callMethodAsync("Inhibit")
|
||||
.onInterface(LOGIN_MANAGER)
|
||||
.withArguments("sleep", "hyprlock", "Fingerprint verifcation must be stopped before sleep", "delay")
|
||||
.uponReplyInvoke([this](std::optional<sdbus::Error> e, sdbus::UnixFd fd) {
|
||||
if (e)
|
||||
Debug::log(WARN, "fprint: could not inhibit sleep: {}", e->what());
|
||||
else
|
||||
m_sDBUSState.inhibitLock = fd;
|
||||
});
|
||||
}
|
||||
|
||||
bool CFingerprint::createDeviceProxy() {
|
||||
auto proxy = sdbus::createProxy(*m_sDBUSState.connection, FPRINT, sdbus::ObjectPath{"/net/reactivated/Fprint/Manager"});
|
||||
|
||||
|
@ -143,8 +131,7 @@ bool CFingerprint::createDeviceProxy() {
|
|||
bool isPresent = presentVariant.get<bool>();
|
||||
if (!isPresent)
|
||||
return;
|
||||
m_sPrompt = m_sFingerprintPresent;
|
||||
m_sFailureReason = "";
|
||||
m_sPrompt = m_sFingerprintPresent;
|
||||
g_pHyprlock->enqueueForceUpdateTimers();
|
||||
} catch (std::out_of_range& e) {}
|
||||
});
|
||||
|
@ -153,66 +140,63 @@ bool CFingerprint::createDeviceProxy() {
|
|||
}
|
||||
|
||||
void CFingerprint::handleVerifyStatus(const std::string& result, bool done) {
|
||||
g_pAuth->postActivity(AUTH_IMPL_FINGERPRINT);
|
||||
Debug::log(LOG, "fprint: handling status {}", result);
|
||||
auto matchResult = s_mapStringToTestType[result];
|
||||
bool authenticated = false;
|
||||
bool retry = false;
|
||||
if (m_sDBUSState.sleeping && matchResult != MATCH_DISCONNECTED)
|
||||
if (m_sDBUSState.sleeping) {
|
||||
stopVerify();
|
||||
Debug::log(LOG, "fprint: device suspended");
|
||||
return;
|
||||
}
|
||||
switch (matchResult) {
|
||||
case MATCH_INVALID: Debug::log(WARN, "fprint: unknown status: {}", result); break;
|
||||
case MATCH_NO_MATCH:
|
||||
stopVerify();
|
||||
if (m_sDBUSState.retries >= 3) {
|
||||
m_sPrompt = "";
|
||||
m_sFailureReason = "Fingerprint auth disabled (too many failed attempts)";
|
||||
} else {
|
||||
done = false;
|
||||
startVerify(true);
|
||||
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);
|
||||
m_sFailureReason = "Fingerprint did not match";
|
||||
}
|
||||
break;
|
||||
case MATCH_UNKNOWN_ERROR:
|
||||
stopVerify();
|
||||
m_sPrompt = "";
|
||||
m_sFailureReason = "Fingerprint auth disabled (unknown error)";
|
||||
break;
|
||||
case MATCH_MATCHED:
|
||||
stopVerify();
|
||||
m_sPrompt = "";
|
||||
m_sFailureReason = "";
|
||||
authenticated = true;
|
||||
authenticated = true;
|
||||
g_pAuth->enqueueUnlock();
|
||||
break;
|
||||
case MATCH_RETRY:
|
||||
retry = true;
|
||||
m_sPrompt = "Please retry fingerprint scan";
|
||||
m_sFailureReason = "";
|
||||
retry = true;
|
||||
m_sPrompt = "Please retry fingerprint scan";
|
||||
break;
|
||||
case MATCH_SWIPE_TOO_SHORT:
|
||||
retry = true;
|
||||
m_sPrompt = "Swipe too short - try again";
|
||||
m_sFailureReason = "";
|
||||
retry = true;
|
||||
m_sPrompt = "Swipe too short - try again";
|
||||
break;
|
||||
case MATCH_FINGER_NOT_CENTERED:
|
||||
retry = true;
|
||||
m_sPrompt = "Finger not centered - try again";
|
||||
m_sFailureReason = "";
|
||||
retry = true;
|
||||
m_sPrompt = "Finger not centered - try again";
|
||||
break;
|
||||
case MATCH_REMOVE_AND_RETRY:
|
||||
retry = true;
|
||||
m_sPrompt = "Remove your finger and try again";
|
||||
m_sFailureReason = "";
|
||||
retry = true;
|
||||
m_sPrompt = "Remove your finger and try again";
|
||||
break;
|
||||
case MATCH_DISCONNECTED:
|
||||
m_sPrompt = "";
|
||||
m_sFailureReason = "Fingerprint device disconnected";
|
||||
m_sDBUSState.abort = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!authenticated && !retry)
|
||||
g_pAuth->enqueueFail();
|
||||
g_pAuth->enqueueFail(m_sFailureReason, AUTH_IMPL_FINGERPRINT);
|
||||
else if (retry)
|
||||
g_pHyprlock->enqueueForceUpdateTimers();
|
||||
|
||||
if (done || m_sDBUSState.abort)
|
||||
m_sDBUSState.done = true;
|
||||
|
@ -231,6 +215,7 @@ void CFingerprint::claimDevice() {
|
|||
}
|
||||
|
||||
void CFingerprint::startVerify(bool isRetry) {
|
||||
m_sDBUSState.verifying = true;
|
||||
if (!m_sDBUSState.device) {
|
||||
if (!createDeviceProxy())
|
||||
return;
|
||||
|
@ -242,26 +227,23 @@ void CFingerprint::startVerify(bool isRetry) {
|
|||
m_sDBUSState.device->callMethodAsync("VerifyStart").onInterface(DEVICE).withArguments(finger).uponReplyInvoke([this, isRetry](std::optional<sdbus::Error> e) {
|
||||
if (e) {
|
||||
Debug::log(WARN, "fprint: could not start verifying, {}", e->what());
|
||||
if (isRetry) {
|
||||
m_sPrompt = "";
|
||||
if (isRetry)
|
||||
m_sFailureReason = "Fingerprint auth disabled (failed to restart)";
|
||||
}
|
||||
|
||||
} else {
|
||||
Debug::log(LOG, "fprint: started verifying");
|
||||
if (isRetry) {
|
||||
m_sDBUSState.retries++;
|
||||
m_sPrompt = "Could not match fingerprint. Try again.";
|
||||
m_sFailureReason = "";
|
||||
} else {
|
||||
m_sPrompt = m_sFingerprintReady;
|
||||
m_sFailureReason = "";
|
||||
}
|
||||
m_sPrompt = "Could not match fingerprint. Try again.";
|
||||
} else
|
||||
m_sPrompt = m_sFingerprintReady;
|
||||
}
|
||||
g_pHyprlock->enqueueForceUpdateTimers();
|
||||
});
|
||||
}
|
||||
|
||||
bool CFingerprint::stopVerify() {
|
||||
m_sDBUSState.verifying = false;
|
||||
if (!m_sDBUSState.device)
|
||||
return false;
|
||||
try {
|
||||
|
|
|
@ -29,12 +29,12 @@ class CFingerprint : public IAuthImplementation {
|
|||
std::shared_ptr<sdbus::IConnection> connection;
|
||||
std::unique_ptr<sdbus::IProxy> login;
|
||||
std::unique_ptr<sdbus::IProxy> device;
|
||||
sdbus::UnixFd inhibitLock;
|
||||
|
||||
bool abort = false;
|
||||
bool done = false;
|
||||
int retries = 0;
|
||||
bool sleeping = false;
|
||||
bool abort = false;
|
||||
bool done = false;
|
||||
int retries = 0;
|
||||
bool sleeping = false;
|
||||
bool verifying = false;
|
||||
} m_sDBUSState;
|
||||
|
||||
std::string m_sFingerprintReady;
|
||||
|
@ -45,8 +45,6 @@ class CFingerprint : public IAuthImplementation {
|
|||
|
||||
void handleVerifyStatus(const std::string& result, const bool done);
|
||||
|
||||
void inhibitSleep();
|
||||
|
||||
bool createDeviceProxy();
|
||||
void claimDevice();
|
||||
void startVerify(bool isRetry = false);
|
||||
|
|
|
@ -49,7 +49,7 @@ int conv(int num_msg, const struct pam_message** msg, struct pam_response** resp
|
|||
Debug::log(LOG, "PAM: {}", msg[i]->msg);
|
||||
// Targets this log from pam_faillock: https://github.com/linux-pam/linux-pam/blob/fa3295e079dbbc241906f29bde5fb71bc4172771/modules/pam_faillock/pam_faillock.c#L417
|
||||
if (const auto MSG = std::string(msg[i]->msg); MSG.contains("left to unlock")) {
|
||||
CONVERSATIONSTATE->failText = std::move(MSG);
|
||||
CONVERSATIONSTATE->failText = MSG;
|
||||
CONVERSATIONSTATE->failTextFromPam = true;
|
||||
}
|
||||
break;
|
||||
|
@ -61,11 +61,11 @@ int conv(int num_msg, const struct pam_message** msg, struct pam_response** resp
|
|||
}
|
||||
|
||||
CPam::CPam() {
|
||||
static auto* const PPAMMODULE = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:pam:module"));
|
||||
m_sPamModule = *PPAMMODULE;
|
||||
static const auto PAMMODULE = g_pConfigManager->getValue<Hyprlang::STRING>("auth:pam:module");
|
||||
m_sPamModule = *PAMMODULE;
|
||||
|
||||
if (!std::filesystem::exists(std::filesystem::path("/etc/pam.d/") / m_sPamModule)) {
|
||||
Debug::log(ERR, "Pam module \"/etc/pam.d/{}\" does not exist! Falling back to \"/etc/pam.d/su\"", m_sPamModule);
|
||||
Debug::log(ERR, R"(Pam module "/etc/pam.d/{}" does not exist! Falling back to "/etc/pam.d/su")", m_sPamModule);
|
||||
m_sPamModule = "su";
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ void CPam::init() {
|
|||
return;
|
||||
|
||||
if (!AUTHENTICATED)
|
||||
g_pAuth->enqueueFail();
|
||||
g_pAuth->enqueueFail(m_sConversationState.failText, AUTH_IMPL_PAM);
|
||||
else {
|
||||
g_pAuth->enqueueUnlock();
|
||||
return;
|
||||
|
@ -106,8 +106,8 @@ void CPam::init() {
|
|||
}
|
||||
|
||||
bool CPam::auth() {
|
||||
const pam_conv localConv = {conv, (void*)&m_sConversationState};
|
||||
pam_handle_t* handle = NULL;
|
||||
const pam_conv localConv = {.conv = conv, .appdata_ptr = (void*)&m_sConversationState};
|
||||
pam_handle_t* handle = nullptr;
|
||||
auto uidPassword = getpwuid(getuid());
|
||||
RASSERT(uidPassword && uidPassword->pw_name, "Failed to get username (getpwuid)");
|
||||
|
||||
|
@ -124,7 +124,6 @@ bool CPam::auth() {
|
|||
handle = nullptr;
|
||||
|
||||
m_sConversationState.waitingForPamAuth = false;
|
||||
g_pAuth->postActivity(AUTH_IMPL_PAM);
|
||||
|
||||
if (ret != PAM_SUCCESS) {
|
||||
if (!m_sConversationState.failTextFromPam)
|
||||
|
@ -139,14 +138,7 @@ bool CPam::auth() {
|
|||
return true;
|
||||
}
|
||||
|
||||
// clearing the input must be done from the main thread
|
||||
static void clearInputTimerCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pHyprlock->clearPasswordBuffer();
|
||||
}
|
||||
|
||||
void CPam::waitForInput() {
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), clearInputTimerCallback, nullptr);
|
||||
|
||||
std::unique_lock<std::mutex> lk(m_sConversationState.inputMutex);
|
||||
m_bBlockInput = false;
|
||||
m_sConversationState.waitingForPamAuth = false;
|
||||
|
@ -156,7 +148,6 @@ void CPam::waitForInput() {
|
|||
}
|
||||
|
||||
void CPam::handleInput(const std::string& input) {
|
||||
g_pAuth->postActivity(AUTH_IMPL_PAM);
|
||||
std::unique_lock<std::mutex> lk(m_sConversationState.inputMutex);
|
||||
|
||||
if (!m_sConversationState.inputRequested)
|
||||
|
|
|
@ -27,7 +27,7 @@ class ICustomConfigValueData {
|
|||
|
||||
class CLayoutValueData : public ICustomConfigValueData {
|
||||
public:
|
||||
CLayoutValueData() {};
|
||||
CLayoutValueData() = default;
|
||||
virtual ~CLayoutValueData() {};
|
||||
|
||||
virtual eConfigValueDataTypes getDataType() {
|
||||
|
@ -62,8 +62,9 @@ class CLayoutValueData : public ICustomConfigValueData {
|
|||
class CGradientValueData : public ICustomConfigValueData {
|
||||
public:
|
||||
CGradientValueData() {};
|
||||
CGradientValueData(CColor col) {
|
||||
CGradientValueData(CHyprColor col) {
|
||||
m_vColors.push_back(col);
|
||||
updateColorsOk();
|
||||
};
|
||||
virtual ~CGradientValueData() {};
|
||||
|
||||
|
@ -71,14 +72,29 @@ class CGradientValueData : public ICustomConfigValueData {
|
|||
return CVD_TYPE_GRADIENT;
|
||||
}
|
||||
|
||||
void reset(CColor col) {
|
||||
void reset(CHyprColor col) {
|
||||
m_vColors.clear();
|
||||
m_vColors.emplace_back(col);
|
||||
m_fAngle = 0;
|
||||
updateColorsOk();
|
||||
}
|
||||
|
||||
void updateColorsOk() {
|
||||
m_vColorsOkLabA.clear();
|
||||
for (auto& c : m_vColors) {
|
||||
const auto OKLAB = c.asOkLab();
|
||||
m_vColorsOkLabA.emplace_back(OKLAB.l);
|
||||
m_vColorsOkLabA.emplace_back(OKLAB.a);
|
||||
m_vColorsOkLabA.emplace_back(OKLAB.b);
|
||||
m_vColorsOkLabA.emplace_back(c.a);
|
||||
}
|
||||
}
|
||||
|
||||
/* Vector containing the colors */
|
||||
std::vector<CColor> m_vColors;
|
||||
std::vector<CHyprColor> m_vColors;
|
||||
|
||||
/* Vector containing pure colors for shoving into opengl */
|
||||
std::vector<float> m_vColorsOkLabA;
|
||||
|
||||
/* Float corresponding to the angle (rad) */
|
||||
float m_fAngle = 0;
|
||||
|
@ -86,6 +102,7 @@ class CGradientValueData : public ICustomConfigValueData {
|
|||
/* Whether this gradient stores a fallback value (not exlicitly set) */
|
||||
bool m_bIsFallback = false;
|
||||
|
||||
//
|
||||
bool operator==(const CGradientValueData& other) const {
|
||||
if (other.m_vColors.size() != m_vColors.size() || m_fAngle != other.m_fAngle)
|
||||
return false;
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
#include "ConfigManager.hpp"
|
||||
#include "ConfigDataValues.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../config/ConfigDataValues.hpp"
|
||||
#include "../core/AnimationManager.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <hyprutils/path/Path.hpp>
|
||||
#include <filesystem>
|
||||
#include <glob.h>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
using namespace Hyprutils::String;
|
||||
using namespace Hyprutils::Animation;
|
||||
|
||||
ICustomConfigValueData::~ICustomConfigValueData() {
|
||||
; // empty
|
||||
}
|
||||
|
@ -25,6 +30,30 @@ static Hyprlang::CParseResult handleSource(const char* c, const char* v) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleBezier(const char* c, const char* v) {
|
||||
const std::string VALUE = v;
|
||||
const std::string COMMAND = c;
|
||||
|
||||
const auto RESULT = g_pConfigManager->handleBezier(COMMAND, VALUE);
|
||||
|
||||
Hyprlang::CParseResult result;
|
||||
if (RESULT.has_value())
|
||||
result.setError(RESULT.value().c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult handleAnimation(const char* c, const char* v) {
|
||||
const std::string VALUE = v;
|
||||
const std::string COMMAND = c;
|
||||
|
||||
const auto RESULT = g_pConfigManager->handleAnimation(COMMAND, VALUE);
|
||||
|
||||
Hyprlang::CParseResult result;
|
||||
if (RESULT.has_value())
|
||||
result.setError(RESULT.value().c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult configHandleLayoutOption(const char* v, void** data) {
|
||||
const std::string VALUE = v;
|
||||
|
||||
|
@ -71,22 +100,33 @@ static void configHandleLayoutOptionDestroy(void** data) {
|
|||
}
|
||||
|
||||
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
||||
std::string V = VALUE;
|
||||
const std::string V = VALUE;
|
||||
|
||||
if (!*data)
|
||||
*data = new CGradientValueData();
|
||||
|
||||
const auto DATA = reinterpret_cast<CGradientValueData*>(*data);
|
||||
|
||||
CVarList varlist(V, 0, ' ');
|
||||
DATA->m_vColors.clear();
|
||||
DATA->m_bIsFallback = false;
|
||||
|
||||
std::string parseError = "";
|
||||
std::string rolling = V;
|
||||
|
||||
for (auto const& var : varlist) {
|
||||
if (var.find("deg") != std::string::npos) {
|
||||
// last arg
|
||||
while (!rolling.empty()) {
|
||||
const auto SPACEPOS = rolling.find(' ');
|
||||
const bool LAST = SPACEPOS == std::string::npos;
|
||||
std::string var = rolling.substr(0, SPACEPOS);
|
||||
if (var.find("rgb") != std::string::npos) { // rgb(a)
|
||||
const auto CLOSEPARENPOS = rolling.find(')');
|
||||
if (CLOSEPARENPOS == std::string::npos || CLOSEPARENPOS + 1 >= rolling.length()) {
|
||||
var = trim(rolling);
|
||||
rolling.clear();
|
||||
} else {
|
||||
var = rolling.substr(0, CLOSEPARENPOS + 1);
|
||||
rolling = trim(rolling.substr(CLOSEPARENPOS + 2));
|
||||
}
|
||||
} else if (var.find("deg") != std::string::npos) { // last arg
|
||||
try {
|
||||
DATA->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (M_PI / 180.0); // radians
|
||||
} catch (...) {
|
||||
|
@ -95,7 +135,8 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**
|
|||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} else // hex
|
||||
rolling = trim(rolling.substr(LAST ? rolling.length() : SPACEPOS + 1));
|
||||
|
||||
if (DATA->m_vColors.size() >= 10) {
|
||||
Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V);
|
||||
|
@ -107,7 +148,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**
|
|||
continue;
|
||||
|
||||
try {
|
||||
DATA->m_vColors.push_back(CColor(configStringToInt(var)));
|
||||
DATA->m_vColors.emplace_back(configStringToInt(var));
|
||||
} catch (std::exception& e) {
|
||||
Debug::log(WARN, "Error parsing gradient {}", V);
|
||||
parseError = "Error parsing gradient " + V + ": " + e.what();
|
||||
|
@ -116,16 +157,18 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**
|
|||
|
||||
if (V.empty()) {
|
||||
DATA->m_bIsFallback = true;
|
||||
DATA->m_vColors.push_back(0); // transparent
|
||||
DATA->m_vColors.emplace_back(0); // transparent
|
||||
}
|
||||
|
||||
if (DATA->m_vColors.size() == 0) {
|
||||
Debug::log(WARN, "Error parsing gradient {}", V);
|
||||
parseError = "Error parsing gradient " + V + ": No colors?";
|
||||
|
||||
DATA->m_vColors.push_back(0); // transparent
|
||||
DATA->m_vColors.emplace_back(0); // transparent
|
||||
}
|
||||
|
||||
DATA->updateColorsOk();
|
||||
|
||||
Hyprlang::CParseResult result;
|
||||
if (!parseError.empty())
|
||||
result.setError(parseError.c_str());
|
||||
|
@ -166,21 +209,26 @@ 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});
|
||||
m_config.addConfigValue("general:disable_loading_bar", Hyprlang::INT{0});
|
||||
|
||||
#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:no_fade_in", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:no_fade_out", 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});
|
||||
m_config.addConfigValue("general:screencopy_mode", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:fail_timeout", Hyprlang::INT{2000});
|
||||
|
||||
m_config.addConfigValue("auth:pam:enabled", Hyprlang::INT{1});
|
||||
m_config.addConfigValue("auth:pam:module", Hyprlang::STRING{"hyprlock"});
|
||||
m_config.addConfigValue("auth:fingerprint:enabled", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("auth:fingerprint:ready_message", Hyprlang::STRING{"(Scan fingerprint to unlock)"});
|
||||
m_config.addConfigValue("auth:fingerprint:present_message", Hyprlang::STRING{"Scanning fingerprint"});
|
||||
m_config.addConfigValue("auth:fingerprint:retry_delay", Hyprlang::INT{250});
|
||||
|
||||
m_config.addConfigValue("animations:enabled", Hyprlang::INT{1});
|
||||
|
||||
m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""});
|
||||
|
@ -212,6 +260,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{""});
|
||||
|
@ -228,6 +277,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{""});
|
||||
|
@ -239,7 +289,6 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("input-field", "dots_center", Hyprlang::INT{1});
|
||||
m_config.addSpecialConfigValue("input-field", "dots_spacing", Hyprlang::FLOAT{0.2});
|
||||
m_config.addSpecialConfigValue("input-field", "dots_rounding", Hyprlang::INT{-1});
|
||||
m_config.addSpecialConfigValue("input-field", "dots_fade_time", Hyprlang::INT{200});
|
||||
m_config.addSpecialConfigValue("input-field", "dots_text_format", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1});
|
||||
m_config.addSpecialConfigValue("input-field", "fade_timeout", Hyprlang::INT{2000});
|
||||
|
@ -250,12 +299,11 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("input-field", "position", LAYOUTCONFIG("0,0"));
|
||||
m_config.addSpecialConfigValue("input-field", "placeholder_text", Hyprlang::STRING{"<i>Input Password</i>"});
|
||||
m_config.addSpecialConfigValue("input-field", "hide_input", Hyprlang::INT{0});
|
||||
m_config.addSpecialConfigValue("input-field", "hide_input_base_color", Hyprlang::INT{0xEE00FF99});
|
||||
m_config.addSpecialConfigValue("input-field", "rounding", Hyprlang::INT{-1});
|
||||
m_config.addSpecialConfigValue("input-field", "check_color", GRADIENTCONFIG("0xFF22CC88"));
|
||||
m_config.addSpecialConfigValue("input-field", "fail_color", GRADIENTCONFIG("0xFFCC2222"));
|
||||
m_config.addSpecialConfigValue("input-field", "fail_text", Hyprlang::STRING{"<i>$FAIL</i>"});
|
||||
m_config.addSpecialConfigValue("input-field", "fail_timeout", Hyprlang::INT{2000});
|
||||
m_config.addSpecialConfigValue("input-field", "fail_transition", Hyprlang::INT{300});
|
||||
m_config.addSpecialConfigValue("input-field", "capslock_color", GRADIENTCONFIG(""));
|
||||
m_config.addSpecialConfigValue("input-field", "numlock_color", GRADIENTCONFIG(""));
|
||||
m_config.addSpecialConfigValue("input-field", "bothlock_color", GRADIENTCONFIG(""));
|
||||
|
@ -271,14 +319,40 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("label", "font_size", Hyprlang::INT{16});
|
||||
m_config.addSpecialConfigValue("label", "text", Hyprlang::STRING{"Sample Text"});
|
||||
m_config.addSpecialConfigValue("label", "font_family", Hyprlang::STRING{"Sans"});
|
||||
m_config.addSpecialConfigValue("label", "halign", Hyprlang::STRING{"none"});
|
||||
m_config.addSpecialConfigValue("label", "valign", Hyprlang::STRING{"none"});
|
||||
m_config.addSpecialConfigValue("label", "halign", Hyprlang::STRING{"center"});
|
||||
m_config.addSpecialConfigValue("label", "valign", Hyprlang::STRING{"center"});
|
||||
m_config.addSpecialConfigValue("label", "rotate", Hyprlang::FLOAT{0});
|
||||
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", {false});
|
||||
m_config.registerHandler(&::handleSource, "source", {.allowFlags = false});
|
||||
m_config.registerHandler(&::handleBezier, "bezier", {.allowFlags = false});
|
||||
m_config.registerHandler(&::handleAnimation, "animation", {.allowFlags = false});
|
||||
|
||||
//
|
||||
// Init Animations
|
||||
//
|
||||
m_AnimationTree.createNode("global");
|
||||
|
||||
// toplevel
|
||||
m_AnimationTree.createNode("fade", "global");
|
||||
m_AnimationTree.createNode("inputField", "global");
|
||||
|
||||
// inputField
|
||||
m_AnimationTree.createNode("inputFieldColors", "inputField");
|
||||
m_AnimationTree.createNode("inputFieldFade", "inputField");
|
||||
m_AnimationTree.createNode("inputFieldWidth", "inputField");
|
||||
m_AnimationTree.createNode("inputFieldDots", "inputField");
|
||||
|
||||
// fade
|
||||
m_AnimationTree.createNode("fadeIn", "fade");
|
||||
m_AnimationTree.createNode("fadeOut", "fade");
|
||||
|
||||
// set config for root node
|
||||
m_AnimationTree.setConfigForNode("global", 1, 8.f, "default");
|
||||
m_AnimationTree.setConfigForNode("inputFieldColors", 1, 8.f, "linear");
|
||||
|
||||
m_config.commence();
|
||||
|
||||
|
@ -288,13 +362,7 @@ void CConfigManager::init() {
|
|||
Debug::log(ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError());
|
||||
|
||||
#undef SHADOWABLE
|
||||
}
|
||||
|
||||
std::mutex configMtx;
|
||||
|
||||
void* const* CConfigManager::getValuePtr(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lg(configMtx);
|
||||
return m_config.getConfigValuePtr(name.c_str())->getDataStaticPtr();
|
||||
#undef CLICKABLE
|
||||
}
|
||||
|
||||
std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
||||
|
@ -306,14 +374,17 @@ 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());
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
"background",
|
||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
|
||||
{
|
||||
.type = "background",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"path", m_config.getSpecialConfigValue("background", "path", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("background", "color", k.c_str())},
|
||||
{"blur_size", m_config.getSpecialConfigValue("background", "blur_size", k.c_str())},
|
||||
|
@ -337,9 +408,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
"shape",
|
||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
|
||||
{
|
||||
.type = "shape",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("shape", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("shape", "rounding", k.c_str())},
|
||||
{"border_size", m_config.getSpecialConfigValue("shape", "border_size", k.c_str())},
|
||||
|
@ -352,6 +423,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
|
||||
|
@ -362,9 +434,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
"image",
|
||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
|
||||
{
|
||||
.type = "image",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"path", m_config.getSpecialConfigValue("image", "path", k.c_str())},
|
||||
{"size", m_config.getSpecialConfigValue("image", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("image", "rounding", k.c_str())},
|
||||
|
@ -378,6 +450,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
|
||||
|
@ -387,9 +460,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
"input-field",
|
||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
|
||||
{
|
||||
.type = "input-field",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("input-field", "size", k.c_str())},
|
||||
{"inner_color", m_config.getSpecialConfigValue("input-field", "inner_color", k.c_str())},
|
||||
{"outer_color", m_config.getSpecialConfigValue("input-field", "outer_color", k.c_str())},
|
||||
|
@ -398,7 +471,6 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"dots_spacing", m_config.getSpecialConfigValue("input-field", "dots_spacing", k.c_str())},
|
||||
{"dots_center", m_config.getSpecialConfigValue("input-field", "dots_center", k.c_str())},
|
||||
{"dots_rounding", m_config.getSpecialConfigValue("input-field", "dots_rounding", k.c_str())},
|
||||
{"dots_fade_time", m_config.getSpecialConfigValue("input-field", "dots_fade_time", k.c_str())},
|
||||
{"dots_text_format", m_config.getSpecialConfigValue("input-field", "dots_text_format", k.c_str())},
|
||||
{"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())},
|
||||
{"fade_timeout", m_config.getSpecialConfigValue("input-field", "fade_timeout", k.c_str())},
|
||||
|
@ -409,12 +481,11 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
|
||||
{"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())},
|
||||
{"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())},
|
||||
{"hide_input_base_color", m_config.getSpecialConfigValue("input-field", "hide_input_base_color", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
|
||||
{"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())},
|
||||
{"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())},
|
||||
{"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
|
||||
{"fail_timeout", m_config.getSpecialConfigValue("input-field", "fail_timeout", k.c_str())},
|
||||
{"fail_transition", m_config.getSpecialConfigValue("input-field", "fail_transition", k.c_str())},
|
||||
{"capslock_color", m_config.getSpecialConfigValue("input-field", "capslock_color", k.c_str())},
|
||||
{"numlock_color", m_config.getSpecialConfigValue("input-field", "numlock_color", k.c_str())},
|
||||
{"bothlock_color", m_config.getSpecialConfigValue("input-field", "bothlock_color", k.c_str())},
|
||||
|
@ -431,9 +502,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
"label",
|
||||
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
|
||||
{
|
||||
.type = "label",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"position", m_config.getSpecialConfigValue("label", "position", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("label", "color", k.c_str())},
|
||||
{"font_size", m_config.getSpecialConfigValue("label", "font_size", k.c_str())},
|
||||
|
@ -445,6 +516,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
|
||||
|
@ -498,3 +570,80 @@ std::optional<std::string> CConfigManager::handleSource(const std::string& comma
|
|||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleBezier(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
std::string bezierName = ARGS[0];
|
||||
|
||||
if (ARGS[1] == "")
|
||||
return "too few arguments";
|
||||
float p1x = std::stof(ARGS[1]);
|
||||
|
||||
if (ARGS[2] == "")
|
||||
return "too few arguments";
|
||||
float p1y = std::stof(ARGS[2]);
|
||||
|
||||
if (ARGS[3] == "")
|
||||
return "too few arguments";
|
||||
float p2x = std::stof(ARGS[3]);
|
||||
|
||||
if (ARGS[4] == "")
|
||||
return "too few arguments";
|
||||
float p2y = std::stof(ARGS[4]);
|
||||
|
||||
if (ARGS[5] != "")
|
||||
return "too many arguments";
|
||||
|
||||
g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
const auto ANIMNAME = ARGS[0];
|
||||
|
||||
if (!m_AnimationTree.nodeExists(ANIMNAME))
|
||||
return "no such animation";
|
||||
|
||||
// This helper casts strings like "1", "true", "off", "yes"... to int.
|
||||
int64_t enabledInt = configStringToInt(ARGS[1]);
|
||||
|
||||
// Checking that the int is 1 or 0 because the helper can return integers out of range.
|
||||
if (enabledInt > 1 || enabledInt < 0)
|
||||
return "invalid animation on/off state";
|
||||
|
||||
if (!enabledInt) {
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, 0, 1, "default");
|
||||
return {};
|
||||
}
|
||||
|
||||
int64_t speed = -1;
|
||||
|
||||
// speed
|
||||
if (isNumber(ARGS[2], true)) {
|
||||
speed = std::stof(ARGS[2]);
|
||||
|
||||
if (speed <= 0) {
|
||||
speed = 1.f;
|
||||
return "invalid speed";
|
||||
}
|
||||
} else {
|
||||
speed = 10.f;
|
||||
return "invalid speed";
|
||||
}
|
||||
|
||||
std::string bezierName = ARGS[3];
|
||||
// ARGS[4] (style) currently usused by hyprlock
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, enabledInt, speed, bezierName, "");
|
||||
|
||||
if (!g_pAnimationManager->bezierExists(bezierName)) {
|
||||
const auto PANIMNODE = m_AnimationTree.getConfig(ANIMNAME);
|
||||
PANIMNODE->internalBezier = "default";
|
||||
return "no such bezier";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/animation/AnimationConfig.hpp>
|
||||
|
||||
#include <hyprlang.hpp>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CConfigManager {
|
||||
public:
|
||||
CConfigManager(std::string configPath);
|
||||
void init();
|
||||
void* const* getValuePtr(const std::string& name);
|
||||
void init();
|
||||
|
||||
template <typename T>
|
||||
Hyprlang::CSimpleConfigValue<T> getValue(const std::string& name) {
|
||||
return Hyprlang::CSimpleConfigValue<T>(&m_config, name.c_str());
|
||||
}
|
||||
|
||||
struct SWidgetConfig {
|
||||
std::string type;
|
||||
|
@ -19,13 +26,18 @@ class CConfigManager {
|
|||
std::unordered_map<std::string, std::any> values;
|
||||
};
|
||||
|
||||
std::vector<SWidgetConfig> getWidgetConfigs();
|
||||
std::optional<std::string> handleSource(const std::string&, const std::string&);
|
||||
std::vector<SWidgetConfig> getWidgetConfigs();
|
||||
|
||||
std::string configCurrentPath;
|
||||
std::optional<std::string> handleSource(const std::string&, const std::string&);
|
||||
std::optional<std::string> handleBezier(const std::string&, const std::string&);
|
||||
std::optional<std::string> handleAnimation(const std::string&, const std::string&);
|
||||
|
||||
std::string configCurrentPath;
|
||||
|
||||
Hyprutils::Animation::CAnimationConfigTree m_AnimationTree;
|
||||
|
||||
private:
|
||||
Hyprlang::CConfig m_config;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CConfigManager> g_pConfigManager;
|
||||
inline UP<CConfigManager> g_pConfigManager;
|
||||
|
|
127
src/core/AnimationManager.cpp
Normal file
127
src/core/AnimationManager.cpp
Normal file
|
@ -0,0 +1,127 @@
|
|||
#include "AnimationManager.hpp"
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
#include "../config/ConfigDataValues.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
|
||||
CHyprlockAnimationManager::CHyprlockAnimationManager() {
|
||||
addBezierWithName("linear", {0, 0}, {1, 1});
|
||||
}
|
||||
|
||||
template <Animable VarType>
|
||||
void updateVariable(CAnimatedVariable<VarType>& av, const float POINTY, bool warp = false) {
|
||||
if (warp || !av.enabled() || av.value() == av.goal()) {
|
||||
av.warp(true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto DELTA = av.goal() - av.begun();
|
||||
av.value() = av.begun() + DELTA * POINTY;
|
||||
}
|
||||
|
||||
void updateColorVariable(CAnimatedVariable<CHyprColor>& av, const float POINTY, bool warp = false) {
|
||||
if (warp || !av.enabled() || av.value() == av.goal()) {
|
||||
av.warp(true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// convert both to OkLab, then lerp that, and convert back.
|
||||
// This is not as fast as just lerping rgb, but it's WAY more precise...
|
||||
// Use the CHyprColor cache for OkLab
|
||||
|
||||
const auto& L1 = av.begun().asOkLab();
|
||||
const auto& L2 = av.goal().asOkLab();
|
||||
|
||||
static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + ((two - one) * progress); };
|
||||
|
||||
const Hyprgraphics::CColor lerped = Hyprgraphics::CColor::SOkLab{
|
||||
.l = lerp(L1.l, L2.l, POINTY),
|
||||
.a = lerp(L1.a, L2.a, POINTY),
|
||||
.b = lerp(L1.b, L2.b, POINTY),
|
||||
};
|
||||
|
||||
av.value() = {lerped, lerp(av.begun().a, av.goal().a, POINTY)};
|
||||
}
|
||||
|
||||
void updateGradientVariable(CAnimatedVariable<CGradientValueData>& av, const float POINTY, bool warp = false) {
|
||||
if (warp || av.value() == av.goal()) {
|
||||
av.warp(true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
av.value().m_vColors.resize(av.goal().m_vColors.size(), av.goal().m_vColors.back());
|
||||
|
||||
for (size_t i = 0; i < av.value().m_vColors.size(); ++i) {
|
||||
const CHyprColor& sourceCol = (i < av.begun().m_vColors.size()) ? av.begun().m_vColors[i] : av.begun().m_vColors.back();
|
||||
const CHyprColor& targetCol = (i < av.goal().m_vColors.size()) ? av.goal().m_vColors[i] : av.goal().m_vColors.back();
|
||||
|
||||
const auto& L1 = sourceCol.asOkLab();
|
||||
const auto& L2 = targetCol.asOkLab();
|
||||
|
||||
static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + ((two - one) * progress); };
|
||||
|
||||
const Hyprgraphics::CColor lerped = Hyprgraphics::CColor::SOkLab{
|
||||
.l = lerp(L1.l, L2.l, POINTY),
|
||||
.a = lerp(L1.a, L2.a, POINTY),
|
||||
.b = lerp(L1.b, L2.b, POINTY),
|
||||
};
|
||||
|
||||
av.value().m_vColors[i] = {lerped, lerp(sourceCol.a, targetCol.a, POINTY)};
|
||||
}
|
||||
|
||||
if (av.begun().m_fAngle != av.goal().m_fAngle) {
|
||||
const float DELTA = av.goal().m_fAngle - av.begun().m_fAngle;
|
||||
av.value().m_fAngle = av.begun().m_fAngle + DELTA * POINTY;
|
||||
}
|
||||
|
||||
av.value().updateColorsOk();
|
||||
}
|
||||
|
||||
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();
|
||||
if (!PAV || !PAV->ok())
|
||||
continue;
|
||||
|
||||
const auto SPENT = PAV->getPercent();
|
||||
const auto PBEZIER = getBezier(PAV->getBezierName());
|
||||
const auto POINTY = PBEZIER->getYForPoint(SPENT);
|
||||
const bool WARP = !*ANIMATIONSENABLED || SPENT >= 1.f;
|
||||
|
||||
switch (PAV->m_Type) {
|
||||
case AVARTYPE_FLOAT: {
|
||||
auto pTypedAV = dynamic_cast<CAnimatedVariable<float>*>(PAV.get());
|
||||
RASSERT(pTypedAV, "Failed to upcast animated float");
|
||||
updateVariable(*pTypedAV, POINTY, WARP);
|
||||
} break;
|
||||
case AVARTYPE_VECTOR: {
|
||||
auto pTypedAV = dynamic_cast<CAnimatedVariable<Vector2D>*>(PAV.get());
|
||||
RASSERT(pTypedAV, "Failed to upcast animated Vector2D");
|
||||
updateVariable(*pTypedAV, POINTY, WARP);
|
||||
} break;
|
||||
case AVARTYPE_COLOR: {
|
||||
auto pTypedAV = dynamic_cast<CAnimatedVariable<CHyprColor>*>(PAV.get());
|
||||
RASSERT(pTypedAV, "Failed to upcast animated CHyprColor");
|
||||
updateColorVariable(*pTypedAV, POINTY, WARP);
|
||||
} break;
|
||||
case AVARTYPE_GRADIENT: {
|
||||
auto pTypedAV = dynamic_cast<CAnimatedVariable<CGradientValueData>*>(PAV.get());
|
||||
RASSERT(pTypedAV, "Failed to upcast animated CGradientValueData");
|
||||
updateGradientVariable(*pTypedAV, POINTY, WARP);
|
||||
} break;
|
||||
default: continue;
|
||||
}
|
||||
|
||||
PAV->onUpdate();
|
||||
}
|
||||
|
||||
tickDone();
|
||||
}
|
||||
|
||||
void CHyprlockAnimationManager::scheduleTick() {
|
||||
m_bTickScheduled = true;
|
||||
}
|
||||
|
||||
void CHyprlockAnimationManager::onTicked() {
|
||||
m_bTickScheduled = false;
|
||||
}
|
33
src/core/AnimationManager.hpp
Normal file
33
src/core/AnimationManager.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/animation/AnimationManager.hpp>
|
||||
#include <hyprutils/animation/AnimatedVariable.hpp>
|
||||
|
||||
#include "../helpers/AnimatedVariable.hpp"
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CHyprlockAnimationManager : public Hyprutils::Animation::CAnimationManager {
|
||||
public:
|
||||
CHyprlockAnimationManager();
|
||||
|
||||
void tick();
|
||||
virtual void scheduleTick();
|
||||
virtual void onTicked();
|
||||
|
||||
using SAnimationPropertyConfig = Hyprutils::Animation::SAnimationPropertyConfig;
|
||||
|
||||
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->create(EAVTYPE, static_cast<Hyprutils::Animation::CAnimationManager*>(this), PAV, v);
|
||||
PAV->setConfig(pConfig);
|
||||
|
||||
pav = std::move(PAV);
|
||||
}
|
||||
|
||||
bool m_bTickScheduled = false;
|
||||
};
|
||||
|
||||
inline UP<CHyprlockAnimationManager> g_pAnimationManager;
|
|
@ -9,12 +9,15 @@ 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()));
|
||||
|
||||
dev->sendSetShape(lastCursorSerial, shape);
|
||||
}
|
||||
|
||||
void CCursorShape::hideCursor() {
|
||||
g_pSeatManager->m_pPointer->sendSetCursor(lastCursorSerial, nullptr, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,21 +31,21 @@ CEGL::CEGL(wl_display* display) {
|
|||
throw std::runtime_error("EGL_EXT_platform_wayland not supported");
|
||||
|
||||
eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
if (eglGetPlatformDisplayEXT == NULL)
|
||||
if (eglGetPlatformDisplayEXT == nullptr)
|
||||
throw std::runtime_error("Failed to get eglGetPlatformDisplayEXT");
|
||||
|
||||
eglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
|
||||
if (eglCreatePlatformWindowSurfaceEXT == NULL)
|
||||
if (eglCreatePlatformWindowSurfaceEXT == nullptr)
|
||||
throw std::runtime_error("Failed to get eglCreatePlatformWindowSurfaceEXT");
|
||||
|
||||
eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, display, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
if (eglInitialize(eglDisplay, NULL, NULL) == EGL_FALSE) {
|
||||
if (eglInitialize(eglDisplay, nullptr, nullptr) == EGL_FALSE) {
|
||||
Debug::log(CRIT, "Failed to initialize EGL");
|
||||
goto error;
|
||||
}
|
||||
|
@ -83,4 +83,4 @@ CEGL::~CEGL() {
|
|||
|
||||
void CEGL::makeCurrent(EGLSurface surf) {
|
||||
eglMakeCurrent(eglDisplay, surf, surf, eglContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "../defines.hpp"
|
||||
|
||||
class CEGL {
|
||||
public:
|
||||
CEGL(wl_display*);
|
||||
|
@ -19,4 +19,4 @@ class CEGL {
|
|||
void makeCurrent(EGLSurface surf);
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CEGL> g_pEGL;
|
||||
inline UP<CEGL> g_pEGL;
|
||||
|
|
|
@ -1,27 +1,24 @@
|
|||
#include "LockSurface.hpp"
|
||||
#include "hyprlock.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "Egl.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../core/AnimationManager.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
#include "src/config/ConfigManager.hpp"
|
||||
|
||||
CSessionLockSurface::~CSessionLockSurface() {
|
||||
if (eglWindow)
|
||||
wl_egl_window_destroy(eglWindow);
|
||||
}
|
||||
|
||||
CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
|
||||
CSessionLockSurface::CSessionLockSurface(const SP<COutput>& pOutput) : m_outputRef(pOutput), m_outputID(pOutput->m_ID) {
|
||||
surface = makeShared<CCWlSurface>(g_pHyprlock->getCompositor()->sendCreateSurface());
|
||||
RASSERT(surface, "Couldn't create wl_surface");
|
||||
|
||||
if (!surface) {
|
||||
Debug::log(CRIT, "Couldn't create wl_surface");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const auto PFRACTIONALSCALING = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:fractional_scaling");
|
||||
const auto ENABLE_FSV1 = **PFRACTIONALSCALING == 1 || /* auto enable */ (**PFRACTIONALSCALING == 2);
|
||||
const auto PFRACTIONALMGR = g_pHyprlock->getFractionalMgr();
|
||||
const auto PVIEWPORTER = g_pHyprlock->getViewporter();
|
||||
static const auto FRACTIONALSCALING = g_pConfigManager->getValue<Hyprlang::INT>("general:fractional_scaling");
|
||||
const auto ENABLE_FSV1 = *FRACTIONALSCALING == 1 || /* auto enable */ (*FRACTIONALSCALING == 2);
|
||||
const auto PFRACTIONALMGR = g_pHyprlock->getFractionalMgr();
|
||||
const auto PVIEWPORTER = g_pHyprlock->getViewporter();
|
||||
|
||||
if (ENABLE_FSV1 && PFRACTIONALMGR && PVIEWPORTER) {
|
||||
fractional = makeShared<CCWpFractionalScaleV1>(PFRACTIONALMGR->sendGetFractionalScale(surface->resource()));
|
||||
|
@ -44,12 +41,8 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
|
|||
if (!PVIEWPORTER)
|
||||
Debug::log(LOG, "No viewporter support! Oops, won't be able to scale!");
|
||||
|
||||
lockSurface = makeShared<CCExtSessionLockSurfaceV1>(g_pHyprlock->getSessionLock()->sendGetLockSurface(surface->resource(), output->output->resource()));
|
||||
|
||||
if (!lockSurface) {
|
||||
Debug::log(CRIT, "Couldn't create ext_session_lock_surface_v1");
|
||||
exit(1);
|
||||
}
|
||||
lockSurface = makeShared<CCExtSessionLockSurfaceV1>(g_pHyprlock->getSessionLock()->sendGetLockSurface(surface->resource(), pOutput->m_wlOutput->resource()));
|
||||
RASSERT(lockSurface, "Couldn't create ext_session_lock_surface_v1");
|
||||
|
||||
lockSurface->setConfigure([this](CCExtSessionLockSurfaceV1* r, uint32_t serial, uint32_t width, uint32_t height) { configure({(double)width, (double)height}, serial); });
|
||||
}
|
||||
|
@ -61,6 +54,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
const bool SAMESIZE = logicalSize == size_;
|
||||
const bool SAMESCALE = appliedScale == fractionalScale;
|
||||
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
|
||||
serial = serial_;
|
||||
logicalSize = size_;
|
||||
appliedScale = fractionalScale;
|
||||
|
@ -70,8 +65,8 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
viewport->sendSetDestination(logicalSize.x, logicalSize.y);
|
||||
surface->sendSetBufferScale(1);
|
||||
} else {
|
||||
size = size_ * output->scale;
|
||||
surface->sendSetBufferScale(output->scale);
|
||||
size = size_ * POUTPUT->scale;
|
||||
surface->sendSetBufferScale(POUTPUT->scale);
|
||||
}
|
||||
|
||||
if (!SAMESERIAL)
|
||||
|
@ -83,27 +78,18 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
|
|||
|
||||
if (!eglWindow) {
|
||||
eglWindow = wl_egl_window_create((wl_surface*)surface->resource(), size.x, size.y);
|
||||
if (!eglWindow) {
|
||||
Debug::log(CRIT, "Couldn't create eglWindow");
|
||||
exit(1);
|
||||
}
|
||||
RASSERT(eglWindow, "Couldn't create eglWindow");
|
||||
} else
|
||||
wl_egl_window_resize(eglWindow, size.x, size.y, 0, 0);
|
||||
|
||||
if (!eglSurface) {
|
||||
eglSurface = g_pEGL->eglCreatePlatformWindowSurfaceEXT(g_pEGL->eglDisplay, g_pEGL->eglConfig, eglWindow, nullptr);
|
||||
if (!eglSurface) {
|
||||
Debug::log(CRIT, "Couldn't create eglSurface: {}", (int)eglGetError());
|
||||
// Clean up resources to prevent leaks
|
||||
wl_egl_window_destroy(eglWindow);
|
||||
eglWindow = nullptr;
|
||||
exit(1); // Consider graceful exit or fallback
|
||||
}
|
||||
RASSERT(eglSurface, "Couldn't create eglSurface");
|
||||
}
|
||||
|
||||
if (readyForFrame && !(SAMESIZE && SAMESCALE)) {
|
||||
g_pRenderer->removeWidgetsFor(this);
|
||||
Debug::log(LOG, "Reloading widgets");
|
||||
Debug::log(LOG, "output {} changed, reloading widgets!", POUTPUT->stringPort);
|
||||
g_pRenderer->reconfigureWidgetsFor(POUTPUT->m_ID);
|
||||
}
|
||||
|
||||
readyForFrame = true;
|
||||
|
@ -116,25 +102,33 @@ void CSessionLockSurface::onScaleUpdate() {
|
|||
}
|
||||
|
||||
void CSessionLockSurface::render() {
|
||||
Debug::log(TRACE, "render lock");
|
||||
|
||||
if (frameCallback || !readyForFrame) {
|
||||
needsFrame = true;
|
||||
return;
|
||||
}
|
||||
|
||||
g_pAnimationManager->tick();
|
||||
const auto FEEDBACK = g_pRenderer->renderLock(*this);
|
||||
frameCallback = makeShared<CCWlCallback>(surface->sendFrame());
|
||||
frameCallback->setDone([this](CCWlCallback* r, uint32_t data) {
|
||||
frameCallback->setDone([this](CCWlCallback* r, uint32_t frameTime) {
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
if (Debug::verbose) {
|
||||
const auto POUTPUT = m_outputRef.lock();
|
||||
Debug::log(TRACE, "[{}] frame {}, Current fps: {:.2f}", POUTPUT->stringPort, m_frames, 1000.f / (frameTime - m_lastFrameTime));
|
||||
}
|
||||
|
||||
m_lastFrameTime = frameTime;
|
||||
|
||||
m_frames++;
|
||||
|
||||
onCallback();
|
||||
});
|
||||
|
||||
eglSwapBuffers(g_pEGL->eglDisplay, eglSurface);
|
||||
|
||||
needsFrame = FEEDBACK.needsFrame;
|
||||
needsFrame = FEEDBACK.needsFrame || g_pAnimationManager->shouldTickForNext();
|
||||
}
|
||||
|
||||
void CSessionLockSurface::onCallback() {
|
||||
|
@ -144,4 +138,8 @@ void CSessionLockSurface::onCallback() {
|
|||
needsFrame = false;
|
||||
render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SP<CCWlSurface> CSessionLockSurface::getWlSurface() {
|
||||
return surface;
|
||||
}
|
||||
|
|
|
@ -14,21 +14,24 @@ class CRenderer;
|
|||
|
||||
class CSessionLockSurface {
|
||||
public:
|
||||
CSessionLockSurface(COutput* output);
|
||||
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:
|
||||
COutput* output = nullptr;
|
||||
WP<COutput> m_outputRef;
|
||||
OUTPUTID m_outputID = OUTPUT_INVALID;
|
||||
|
||||
SP<CCWlSurface> surface = nullptr;
|
||||
SP<CCExtSessionLockSurfaceV1> lockSurface = nullptr;
|
||||
uint32_t serial = 0;
|
||||
|
@ -42,8 +45,12 @@ class CSessionLockSurface {
|
|||
|
||||
bool needsFrame = false;
|
||||
|
||||
uint32_t m_lastFrameTime = 0;
|
||||
uint32_t m_frames = 0;
|
||||
|
||||
// wayland callbacks
|
||||
SP<CCWlCallback> frameCallback = nullptr;
|
||||
|
||||
friend class CRenderer;
|
||||
};
|
||||
friend class COutput;
|
||||
};
|
||||
|
|
|
@ -1,32 +1,35 @@
|
|||
#include "Output.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "hyprlock.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
|
||||
COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(output_) {
|
||||
output->setDescription([this](CCWlOutput* r, const char* description) {
|
||||
void COutput::create(WP<COutput> pSelf, SP<CCWlOutput> pWlOutput, uint32_t _name) {
|
||||
m_ID = _name;
|
||||
m_wlOutput = pWlOutput;
|
||||
m_self = pSelf;
|
||||
|
||||
m_wlOutput->setDescription([this](CCWlOutput* r, const char* description) {
|
||||
stringDesc = description ? std::string{description} : "";
|
||||
Debug::log(LOG, "output {} description {}", name, stringDesc);
|
||||
Debug::log(LOG, "output {} description {}", m_ID, stringDesc);
|
||||
});
|
||||
|
||||
output->setName([this](CCWlOutput* r, const char* name) {
|
||||
m_wlOutput->setName([this](CCWlOutput* r, const char* name) {
|
||||
stringName = std::string{name} + stringName;
|
||||
stringPort = std::string{name};
|
||||
Debug::log(LOG, "output {} name {}", name, name);
|
||||
});
|
||||
|
||||
output->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; });
|
||||
m_wlOutput->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; });
|
||||
|
||||
output->setDone([this](CCWlOutput* r) {
|
||||
Debug::log(LOG, "output {} done", name);
|
||||
if (g_pHyprlock->m_bLocked && !sessionLockSurface) {
|
||||
// if we are already locked, create a surface dynamically
|
||||
Debug::log(LOG, "Creating a surface dynamically for output as we are already locked");
|
||||
sessionLockSurface = std::make_unique<CSessionLockSurface>(this);
|
||||
m_wlOutput->setDone([this](CCWlOutput* r) {
|
||||
done = true;
|
||||
Debug::log(LOG, "output {} done", m_ID);
|
||||
if (g_pHyprlock->m_lockAquired && !m_sessionLockSurface) {
|
||||
Debug::log(LOG, "output {} creating a new lock surface", m_ID);
|
||||
createSessionLockSurface();
|
||||
}
|
||||
});
|
||||
|
||||
output->setMode([this](CCWlOutput* r, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||
m_wlOutput->setMode([this](CCWlOutput* r, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||
// handle portrait mode and flipped cases
|
||||
if (transform % 2 == 1)
|
||||
size = {height, width};
|
||||
|
@ -34,10 +37,33 @@ COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(o
|
|||
size = {width, height};
|
||||
});
|
||||
|
||||
output->setGeometry(
|
||||
[this](CCWlOutput* r, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform) {
|
||||
transform = (wl_output_transform)transform;
|
||||
m_wlOutput->setGeometry(
|
||||
[this](CCWlOutput* r, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform_) {
|
||||
transform = (wl_output_transform)transform_;
|
||||
|
||||
Debug::log(LOG, "output {} make {} model {}", name, make ? make : "", model ? model : "");
|
||||
Debug::log(LOG, "output {} make {} model {}", m_ID, make ? make : "", model ? model : "");
|
||||
});
|
||||
}
|
||||
|
||||
void COutput::createSessionLockSurface() {
|
||||
if (!m_self.valid()) {
|
||||
Debug::log(ERR, "output {} dead??", m_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_sessionLockSurface) {
|
||||
Debug::log(ERR, "output {} already has a session lock surface", m_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (size == Vector2D{0, 0}) {
|
||||
Debug::log(WARN, "output {} refusing to create a lock surface with size 0x0", m_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
m_sessionLockSurface = makeUnique<CSessionLockSurface>(m_self.lock());
|
||||
}
|
||||
|
||||
Vector2D COutput::getViewport() const {
|
||||
return (m_sessionLockSurface) ? m_sessionLockSurface->size : size;
|
||||
}
|
||||
|
|
|
@ -2,26 +2,32 @@
|
|||
|
||||
#include "../defines.hpp"
|
||||
#include "wayland.hpp"
|
||||
#include "../helpers/Math.hpp"
|
||||
#include "LockSurface.hpp"
|
||||
#include <memory>
|
||||
|
||||
class COutput {
|
||||
public:
|
||||
COutput(SP<CCWlOutput> output, uint32_t name);
|
||||
COutput() = default;
|
||||
~COutput() = default;
|
||||
|
||||
uint32_t name = 0;
|
||||
bool focused = false;
|
||||
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
Vector2D size;
|
||||
int scale = 1;
|
||||
std::string stringName = "";
|
||||
std::string stringPort = "";
|
||||
std::string stringDesc = "";
|
||||
void create(WP<COutput> pSelf, SP<CCWlOutput> pWlOutput, uint32_t name);
|
||||
|
||||
std::unique_ptr<CSessionLockSurface> sessionLockSurface;
|
||||
OUTPUTID m_ID = 0;
|
||||
bool focused = false;
|
||||
bool done = false;
|
||||
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
Vector2D size;
|
||||
int scale = 1;
|
||||
std::string stringName = "";
|
||||
std::string stringPort = "";
|
||||
std::string stringDesc = "";
|
||||
|
||||
SP<CCWlOutput> output = nullptr;
|
||||
UP<CSessionLockSurface> m_sessionLockSurface;
|
||||
|
||||
private:
|
||||
SP<CCWlOutput> m_wlOutput = nullptr;
|
||||
|
||||
WP<COutput> m_self;
|
||||
|
||||
void createSessionLockSurface();
|
||||
|
||||
Vector2D getViewport() const;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../config/ConfigManager.hpp"
|
||||
#include <chrono>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
CSeatManager::~CSeatManager() {
|
||||
if (m_pXKBState)
|
||||
|
@ -25,7 +26,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;
|
||||
|
||||
|
@ -39,16 +46,34 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
if (!m_pCursorShape)
|
||||
return;
|
||||
|
||||
static auto* const PHIDE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:hide_cursor");
|
||||
|
||||
m_pCursorShape->lastCursorSerial = serial;
|
||||
|
||||
if (**PHIDE)
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -130,7 +155,7 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
|
|||
}
|
||||
|
||||
void CSeatManager::registerCursorShape(SP<CCWpCursorShapeManagerV1> shape) {
|
||||
m_pCursorShape = std::make_unique<CCursorShape>(shape);
|
||||
m_pCursorShape = makeUnique<CCursorShape>(shape);
|
||||
}
|
||||
|
||||
bool CSeatManager::registered() {
|
||||
|
|
|
@ -5,29 +5,28 @@
|
|||
#include "wayland.hpp"
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
#include <memory>
|
||||
|
||||
class CSeatManager {
|
||||
public:
|
||||
CSeatManager() = default;
|
||||
~CSeatManager();
|
||||
|
||||
void registerSeat(SP<CCWlSeat> seat);
|
||||
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
|
||||
bool registered();
|
||||
void registerSeat(SP<CCWlSeat> seat);
|
||||
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
|
||||
bool registered();
|
||||
|
||||
SP<CCWlKeyboard> m_pKeeb;
|
||||
SP<CCWlPointer> m_pPointer;
|
||||
SP<CCWlKeyboard> m_pKeeb;
|
||||
SP<CCWlPointer> m_pPointer;
|
||||
|
||||
std::unique_ptr<CCursorShape> m_pCursorShape;
|
||||
UP<CCursorShape> m_pCursorShape;
|
||||
|
||||
xkb_context* m_pXKBContext = nullptr;
|
||||
xkb_keymap* m_pXKBKeymap = nullptr;
|
||||
xkb_state* m_pXKBState = nullptr;
|
||||
xkb_compose_state* m_pXKBComposeState = nullptr;
|
||||
xkb_context* m_pXKBContext = nullptr;
|
||||
xkb_keymap* m_pXKBKeymap = nullptr;
|
||||
xkb_state* m_pXKBState = nullptr;
|
||||
xkb_compose_state* m_pXKBComposeState = nullptr;
|
||||
|
||||
private:
|
||||
SP<CCWlSeat> m_pSeat;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CSeatManager> g_pSeatManager = std::make_unique<CSeatManager>();
|
||||
inline UP<CSeatManager> g_pSeatManager = makeUnique<CSeatManager>();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#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) : cb(cb_), data(data_) {
|
||||
expires = std::chrono::system_clock::now() + timeout;
|
||||
allowForceUpdate = force;
|
||||
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_, bool force) :
|
||||
cb(cb_), data(data_), allowForceUpdate(force) {
|
||||
expires = std::chrono::system_clock::now() + timeout;
|
||||
}
|
||||
|
||||
bool CTimer::passed() {
|
||||
|
|
|
@ -1,47 +1,56 @@
|
|||
#include "hyprlock.hpp"
|
||||
#include "AnimationManager.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
#include "../auth/Auth.hpp"
|
||||
#include "../auth/Fingerprint.hpp"
|
||||
#include "Egl.hpp"
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <csignal>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <xf86drm.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include <hyprutils/os/Process.hpp>
|
||||
#include <malloc.h>
|
||||
|
||||
using namespace Hyprutils::OS;
|
||||
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender, const bool noFadeIn) {
|
||||
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
|
||||
if (!m_sWaylandState.display) {
|
||||
Debug::log(CRIT, "Couldn't connect to a wayland compositor");
|
||||
exit(1);
|
||||
}
|
||||
static void setMallocThreshold() {
|
||||
#ifdef M_TRIM_THRESHOLD
|
||||
// The default is 128 pages,
|
||||
// which is very large and can lead to a lot of memory used for no reason
|
||||
// because trimming hasn't happened
|
||||
static const int PAGESIZE = sysconf(_SC_PAGESIZE);
|
||||
mallopt(M_TRIM_THRESHOLD, 6 * PAGESIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
g_pEGL = std::make_unique<CEGL>(m_sWaylandState.display);
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender) {
|
||||
setMallocThreshold();
|
||||
|
||||
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
|
||||
RASSERT(m_sWaylandState.display, "Couldn't connect to a wayland compositor");
|
||||
|
||||
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
|
||||
|
||||
if (!immediate) {
|
||||
const auto PGRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
|
||||
m_tGraceEnds = **PGRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**PGRACE) : std::chrono::system_clock::from_time_t(0);
|
||||
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
|
||||
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
|
||||
|
||||
const auto PIMMEDIATERENDER = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:immediate_render");
|
||||
m_bImmediateRender = immediateRender || **PIMMEDIATERENDER;
|
||||
|
||||
const auto* const PNOFADEIN = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_in");
|
||||
m_bNoFadeIn = noFadeIn || **PNOFADEIN;
|
||||
static const auto IMMEDIATERENDER = g_pConfigManager->getValue<Hyprlang::INT>("general:immediate_render");
|
||||
m_bImmediateRender = immediateRender || *IMMEDIATERENDER;
|
||||
|
||||
const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP");
|
||||
const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""};
|
||||
|
@ -64,7 +73,7 @@ static void registerSignalAction(int sig, void (*handler)(int), int sa_flags = 0
|
|||
static void handleUnlockSignal(int sig) {
|
||||
if (sig == SIGUSR1) {
|
||||
Debug::log(LOG, "Unlocking with a SIGUSR1");
|
||||
g_pHyprlock->releaseSessionLock();
|
||||
g_pAuth->enqueueUnlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,20 +92,6 @@ static void handlePollTerminate(int sig) {
|
|||
;
|
||||
}
|
||||
|
||||
static void handleCriticalSignal(int sig) {
|
||||
g_pHyprlock->attemptRestoreOnDeath();
|
||||
|
||||
// remove our handlers
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sigaction(SIGABRT, &sa, nullptr);
|
||||
sigaction(SIGSEGV, &sa, nullptr);
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
static char* gbm_find_render_node(drmDevice* device) {
|
||||
drmDevice* devices[64];
|
||||
char* render_node = nullptr;
|
||||
|
@ -158,7 +153,7 @@ void CHyprlock::addDmabufListener() {
|
|||
uint64_t modifier;
|
||||
};
|
||||
// An entry in the table has to be 16 bytes long
|
||||
assert(sizeof(fm_entry) == 16);
|
||||
static_assert(sizeof(fm_entry) == 16);
|
||||
|
||||
uint32_t n_modifiers = dma.formatTableSize / sizeof(fm_entry);
|
||||
fm_entry* fm_entry = (struct fm_entry*)dma.formatTable;
|
||||
|
@ -232,10 +227,7 @@ void CHyprlock::addDmabufListener() {
|
|||
memcpy(&device, device_arr->data, sizeof(device));
|
||||
|
||||
drmDevice* drmDev;
|
||||
if (drmGetDeviceFromDevId(device, /* flags */ 0, &drmDev) != 0) {
|
||||
Debug::log(WARN, "[dmabuf] unable to open main device?");
|
||||
exit(1);
|
||||
}
|
||||
RASSERT(drmGetDeviceFromDevId(device, /* flags */ 0, &drmDev) == 0, "unable to open main device?");
|
||||
|
||||
dma.gbmDevice = createGBMDevice(drmDev);
|
||||
drmFreeDevice(&drmDev);
|
||||
|
@ -268,14 +260,15 @@ void CHyprlock::run() {
|
|||
return;
|
||||
}
|
||||
|
||||
g_pSeatManager->registerSeat(makeShared<CCWlSeat>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_seat_interface, 9)));
|
||||
g_pSeatManager->registerSeat(makeShared<CCWlSeat>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_seat_interface, 8)));
|
||||
} else if (IFACE == ext_session_lock_manager_v1_interface.name)
|
||||
m_sWaylandState.sessionLock =
|
||||
makeShared<CCExtSessionLockManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &ext_session_lock_manager_v1_interface, 1));
|
||||
else if (IFACE == wl_output_interface.name)
|
||||
m_vOutputs.emplace_back(
|
||||
std::make_unique<COutput>(makeShared<CCWlOutput>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_output_interface, 4)), name));
|
||||
else if (IFACE == wp_cursor_shape_manager_v1_interface.name)
|
||||
else if (IFACE == wl_output_interface.name) {
|
||||
const auto POUTPUT = makeShared<COutput>();
|
||||
POUTPUT->create(POUTPUT, makeShared<CCWlOutput>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_output_interface, 4)), name);
|
||||
m_vOutputs.emplace_back(POUTPUT);
|
||||
} else if (IFACE == wp_cursor_shape_manager_v1_interface.name)
|
||||
g_pSeatManager->registerCursorShape(
|
||||
makeShared<CCWpCursorShapeManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wp_cursor_shape_manager_v1_interface, 1)));
|
||||
else if (IFACE == wl_compositor_interface.name)
|
||||
|
@ -288,6 +281,8 @@ void CHyprlock::run() {
|
|||
else if (IFACE == zwlr_screencopy_manager_v1_interface.name)
|
||||
m_sWaylandState.screencopy =
|
||||
makeShared<CCZwlrScreencopyManagerV1>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &zwlr_screencopy_manager_v1_interface, 3));
|
||||
else if (IFACE == wl_shm_interface.name)
|
||||
m_sWaylandState.shm = makeShared<CCWlShm>((wl_proxy*)wl_registry_bind((wl_registry*)r->resource(), name, &wl_shm_interface, 1));
|
||||
else
|
||||
return;
|
||||
|
||||
|
@ -295,9 +290,9 @@ void CHyprlock::run() {
|
|||
});
|
||||
m_sWaylandState.registry->setGlobalRemove([this](CCWlRegistry* r, uint32_t name) {
|
||||
Debug::log(LOG, " | removed iface {}", name);
|
||||
auto outputIt = std::find_if(m_vOutputs.begin(), m_vOutputs.end(), [name](const auto& other) { return other->name == name; });
|
||||
auto outputIt = std::ranges::find_if(m_vOutputs, [id = name](const auto& other) { return other->m_ID == id; });
|
||||
if (outputIt != m_vOutputs.end()) {
|
||||
g_pRenderer->removeWidgetsFor(outputIt->get()->sessionLockSurface.get());
|
||||
g_pRenderer->removeWidgetsFor((*outputIt)->m_ID);
|
||||
m_vOutputs.erase(outputIt);
|
||||
}
|
||||
});
|
||||
|
@ -312,13 +307,10 @@ void CHyprlock::run() {
|
|||
// gather info about monitors
|
||||
wl_display_roundtrip(m_sWaylandState.display);
|
||||
|
||||
g_pRenderer = std::make_unique<CRenderer>();
|
||||
g_pAuth = std::make_unique<CAuth>();
|
||||
g_pRenderer = makeUnique<CRenderer>();
|
||||
g_pAuth = makeUnique<CAuth>();
|
||||
g_pAuth->start();
|
||||
|
||||
static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out");
|
||||
const bool NOFADEOUT = **PNOFADEOUT;
|
||||
|
||||
Debug::log(LOG, "Running on {}", m_sCurrentDesktop);
|
||||
|
||||
// Hyprland violates the protocol a bit to allow for this.
|
||||
|
@ -335,10 +327,8 @@ void CHyprlock::run() {
|
|||
}
|
||||
}
|
||||
|
||||
acquireSessionLock();
|
||||
|
||||
// Recieved finished
|
||||
if (m_bTerminate) {
|
||||
// Failed to lock the session
|
||||
if (!acquireSessionLock()) {
|
||||
m_sLoopState.timerEvent = true;
|
||||
m_sLoopState.timerCV.notify_all();
|
||||
g_pRenderer->asyncResourceGatherer->notify();
|
||||
|
@ -353,10 +343,6 @@ void CHyprlock::run() {
|
|||
registerSignalAction(SIGUSR1, handleUnlockSignal, SA_RESTART);
|
||||
registerSignalAction(SIGUSR2, handleForceUpdateSignal);
|
||||
registerSignalAction(SIGRTMIN, handlePollTerminate);
|
||||
registerSignalAction(SIGSEGV, handleCriticalSignal);
|
||||
registerSignalAction(SIGABRT, handleCriticalSignal);
|
||||
|
||||
createSessionLockSurfaces();
|
||||
|
||||
pollfd pollfds[2];
|
||||
pollfds[0] = {
|
||||
|
@ -373,32 +359,33 @@ void CHyprlock::run() {
|
|||
|
||||
std::thread pollThr([this, &pollfds, fdcount]() {
|
||||
while (!m_bTerminate) {
|
||||
int ret = poll(pollfds, fdcount, 5000 /* 5 seconds, reasonable. Just in case we need to terminate and the signal fails */);
|
||||
bool preparedToRead = wl_display_prepare_read(m_sWaylandState.display) == 0;
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
int events = 0;
|
||||
if (preparedToRead) {
|
||||
events = poll(pollfds, fdcount, 5000);
|
||||
|
||||
if (events < 0) {
|
||||
RASSERT(errno == EINTR, "[core] Polling fds failed with {}", errno);
|
||||
wl_display_cancel_read(m_sWaylandState.display);
|
||||
continue;
|
||||
|
||||
Debug::log(CRIT, "[core] Polling fds failed with {}", errno);
|
||||
attemptRestoreOnDeath();
|
||||
m_bTerminate = true;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fdcount; ++i) {
|
||||
if (pollfds[i].revents & POLLHUP) {
|
||||
Debug::log(CRIT, "[core] Disconnected from pollfd id {}", i);
|
||||
attemptRestoreOnDeath();
|
||||
m_bTerminate = true;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fdcount; ++i) {
|
||||
RASSERT(!(pollfds[i].revents & POLLHUP), "[core] Disconnected from pollfd id {}", i);
|
||||
}
|
||||
|
||||
wl_display_read_events(m_sWaylandState.display);
|
||||
m_sLoopState.wlDispatched = false;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
if (events > 0 || !preparedToRead) {
|
||||
Debug::log(TRACE, "[core] got poll event");
|
||||
std::lock_guard<std::mutex> lg2(m_sLoopState.eventLoopMutex);
|
||||
std::unique_lock lk(m_sLoopState.eventLoopMutex);
|
||||
m_sLoopState.event = true;
|
||||
m_sLoopState.loopCV.notify_all();
|
||||
|
||||
m_sLoopState.wlDispatchCV.wait_for(lk, std::chrono::milliseconds(100), [this] { return m_sLoopState.wlDispatched; });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -411,8 +398,7 @@ void CHyprlock::run() {
|
|||
float least = 10000;
|
||||
for (auto& t : m_vTimers) {
|
||||
const auto TIME = std::clamp(t->leftMs(), 1.f, INFINITY);
|
||||
if (TIME < least)
|
||||
least = TIME;
|
||||
least = std::min(TIME, least);
|
||||
}
|
||||
|
||||
m_sLoopState.timersMutex.unlock();
|
||||
|
@ -430,17 +416,13 @@ void CHyprlock::run() {
|
|||
});
|
||||
|
||||
m_sLoopState.event = true; // let it process once
|
||||
g_pRenderer->startFadeIn();
|
||||
|
||||
while (!m_bTerminate) {
|
||||
std::unique_lock lk(m_sLoopState.eventRequestMutex);
|
||||
if (m_sLoopState.event == false)
|
||||
if (!m_sLoopState.event)
|
||||
m_sLoopState.loopCV.wait_for(lk, std::chrono::milliseconds(5000), [this] { return m_sLoopState.event; });
|
||||
|
||||
if (!NOFADEOUT && m_bFadeStarted && std::chrono::system_clock::now() > m_tFadeEnds) {
|
||||
releaseSessionLock();
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_bTerminate)
|
||||
break;
|
||||
|
||||
|
@ -448,30 +430,18 @@ void CHyprlock::run() {
|
|||
|
||||
m_sLoopState.event = false;
|
||||
|
||||
wl_display_dispatch_pending(m_sWaylandState.display);
|
||||
wl_display_flush(m_sWaylandState.display);
|
||||
|
||||
m_sLoopState.wlDispatched = true;
|
||||
m_sLoopState.wlDispatchCV.notify_all();
|
||||
|
||||
if (pollfds[1].revents & POLLIN /* dbus */) {
|
||||
while (dbusConn && dbusConn->processPendingEvent()) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (pollfds[0].revents & POLLIN /* wl */) {
|
||||
Debug::log(TRACE, "got wl event");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// finalize wayland dispatching. Dispatch pending on the queue
|
||||
int ret = 0;
|
||||
do {
|
||||
ret = wl_display_dispatch_pending(m_sWaylandState.display);
|
||||
wl_display_flush(m_sWaylandState.display);
|
||||
} while (ret > 0 && !m_bTerminate);
|
||||
|
||||
// do timers
|
||||
m_sLoopState.timersMutex.lock();
|
||||
auto timerscpy = m_vTimers;
|
||||
|
@ -494,11 +464,6 @@ void CHyprlock::run() {
|
|||
m_sLoopState.timersMutex.unlock();
|
||||
|
||||
passed.clear();
|
||||
|
||||
if (!NOFADEOUT && m_bFadeStarted && std::chrono::system_clock::now() > m_tFadeEnds) {
|
||||
releaseSessionLock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const auto DPY = m_sWaylandState.display;
|
||||
|
@ -529,21 +494,21 @@ void CHyprlock::run() {
|
|||
}
|
||||
|
||||
void CHyprlock::unlock() {
|
||||
static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out");
|
||||
|
||||
if (**PNOFADEOUT || m_sCurrentDesktop != "Hyprland") {
|
||||
releaseSessionLock();
|
||||
if (!m_bLocked) {
|
||||
Debug::log(WARN, "Unlock called, but not locked yet. This can happen when dpms is off during the grace period.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500);
|
||||
m_bFadeStarted = true;
|
||||
const bool IMMEDIATE = m_sCurrentDesktop != "Hyprland";
|
||||
|
||||
g_pRenderer->startFadeOut(true, IMMEDIATE);
|
||||
m_bUnlockedCalled = true;
|
||||
|
||||
renderAllOutputs();
|
||||
}
|
||||
|
||||
bool CHyprlock::isUnlocked() {
|
||||
return m_bFadeStarted || m_bTerminate;
|
||||
return m_bUnlockedCalled || m_bTerminate;
|
||||
}
|
||||
|
||||
void CHyprlock::clearPasswordBuffer() {
|
||||
|
@ -556,25 +521,25 @@ void CHyprlock::clearPasswordBuffer() {
|
|||
}
|
||||
|
||||
void CHyprlock::renderOutput(const std::string& stringPort) {
|
||||
const auto MON = std::find_if(m_vOutputs.begin(), m_vOutputs.end(), [stringPort](const auto& other) { return other->stringPort == stringPort; });
|
||||
const auto MON = std::ranges::find_if(m_vOutputs, [stringPort](const auto& other) { return other->stringPort == stringPort; });
|
||||
|
||||
if (MON == m_vOutputs.end() || !MON->get())
|
||||
if (MON == m_vOutputs.end() || !*MON)
|
||||
return;
|
||||
|
||||
const auto PMONITOR = MON->get();
|
||||
const auto& PMONITOR = *MON;
|
||||
|
||||
if (!PMONITOR->sessionLockSurface)
|
||||
if (!PMONITOR->m_sessionLockSurface)
|
||||
return;
|
||||
|
||||
PMONITOR->sessionLockSurface->render();
|
||||
PMONITOR->m_sessionLockSurface->render();
|
||||
}
|
||||
|
||||
void CHyprlock::renderAllOutputs() {
|
||||
for (auto& o : m_vOutputs) {
|
||||
if (!o->sessionLockSurface)
|
||||
if (!o->m_sessionLockSurface)
|
||||
continue;
|
||||
|
||||
o->sessionLockSurface->render();
|
||||
o->m_sessionLockSurface->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -607,7 +572,7 @@ void CHyprlock::repeatKey(xkb_keysym_t sym) {
|
|||
}
|
||||
|
||||
void CHyprlock::onKey(uint32_t key, bool down) {
|
||||
if (m_bFadeStarted || m_bTerminate)
|
||||
if (isUnlocked())
|
||||
return;
|
||||
|
||||
if (down && std::chrono::system_clock::now() < m_tGraceEnds) {
|
||||
|
@ -615,10 +580,10 @@ void CHyprlock::onKey(uint32_t key, bool down) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (down && std::find(m_vPressedKeys.begin(), m_vPressedKeys.end(), key) != m_vPressedKeys.end()) {
|
||||
if (down && std::ranges::find(m_vPressedKeys, key) != m_vPressedKeys.end()) {
|
||||
Debug::log(ERR, "Invalid key down event (key already pressed?)");
|
||||
return;
|
||||
} else if (!down && std::find(m_vPressedKeys.begin(), m_vPressedKeys.end(), key) == m_vPressedKeys.end()) {
|
||||
} else if (!down && std::ranges::find(m_vPressedKeys, key) == m_vPressedKeys.end()) {
|
||||
Debug::log(ERR, "Invalid key down event (stray release event?)");
|
||||
return;
|
||||
}
|
||||
|
@ -638,6 +603,9 @@ void CHyprlock::onKey(uint32_t key, bool down) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (g_pAuth->m_bDisplayFailText)
|
||||
g_pAuth->resetDisplayFail();
|
||||
|
||||
if (down) {
|
||||
m_bCapsLock = xkb_state_mod_name_is_active(g_pSeatManager->m_pXKBState, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED);
|
||||
m_bNumLock = xkb_state_mod_name_is_active(g_pSeatManager->m_pXKBState, XKB_MOD_NAME_NUM, XKB_STATE_MODS_LOCKED);
|
||||
|
@ -672,9 +640,9 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
|||
} else if (SYM == XKB_KEY_Return || SYM == XKB_KEY_KP_Enter) {
|
||||
Debug::log(LOG, "Authenticating");
|
||||
|
||||
static auto* const PIGNOREEMPTY = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:ignore_empty_input");
|
||||
static const auto IGNOREEMPTY = g_pConfigManager->getValue<Hyprlang::INT>("general:ignore_empty_input");
|
||||
|
||||
if (m_sPasswordState.passBuffer.empty() && **PIGNOREEMPTY) {
|
||||
if (m_sPasswordState.passBuffer.empty() && *IGNOREEMPTY) {
|
||||
Debug::log(LOG, "Ignoring empty input");
|
||||
return;
|
||||
}
|
||||
|
@ -701,9 +669,68 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
|||
}
|
||||
}
|
||||
|
||||
void CHyprlock::acquireSessionLock() {
|
||||
void CHyprlock::onClick(uint32_t button, bool down, const Vector2D& pos) {
|
||||
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());
|
||||
if (!m_sLockState.lock) {
|
||||
Debug::log(ERR, "Failed to create a lock object!");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_sLockState.lock->setLocked([this](CCExtSessionLockV1* r) { onLockLocked(); });
|
||||
|
||||
|
@ -711,10 +738,27 @@ void CHyprlock::acquireSessionLock() {
|
|||
|
||||
// roundtrip in case the compositor sends `finished` right away
|
||||
wl_display_roundtrip(m_sWaylandState.display);
|
||||
|
||||
// recieved finished right away (probably already locked)
|
||||
if (m_bTerminate)
|
||||
return false;
|
||||
|
||||
m_lockAquired = true;
|
||||
|
||||
// create a session lock surface for exiting outputs
|
||||
for (auto& o : m_vOutputs) {
|
||||
if (!o->done)
|
||||
continue;
|
||||
|
||||
o->createSessionLockSurface();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CHyprlock::releaseSessionLock() {
|
||||
Debug::log(LOG, "Unlocking session");
|
||||
|
||||
if (m_bTerminate) {
|
||||
Debug::log(ERR, "Unlock already happend?");
|
||||
return;
|
||||
|
@ -742,12 +786,6 @@ void CHyprlock::releaseSessionLock() {
|
|||
wl_display_roundtrip(m_sWaylandState.display);
|
||||
}
|
||||
|
||||
void CHyprlock::createSessionLockSurfaces() {
|
||||
for (auto& o : m_vOutputs) {
|
||||
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get());
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprlock::onLockLocked() {
|
||||
Debug::log(LOG, "onLockLocked called");
|
||||
|
||||
|
@ -834,69 +872,10 @@ 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;
|
||||
}
|
||||
|
||||
void CHyprlock::attemptRestoreOnDeath() {
|
||||
if (m_bTerminate || m_sCurrentDesktop != "Hyprland")
|
||||
return;
|
||||
|
||||
const auto XDG_RUNTIME_DIR = getenv("XDG_RUNTIME_DIR");
|
||||
const auto HIS = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||
|
||||
if (!XDG_RUNTIME_DIR || !HIS)
|
||||
return;
|
||||
|
||||
// dirty hack
|
||||
uint64_t timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(0)).count();
|
||||
|
||||
const auto LASTRESTARTPATH = std::string{XDG_RUNTIME_DIR} + "/.hyprlockrestart";
|
||||
|
||||
if (std::filesystem::exists(LASTRESTARTPATH)) {
|
||||
std::ifstream ifs(LASTRESTARTPATH);
|
||||
std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
uint64_t timeEncoded = 0;
|
||||
try {
|
||||
timeEncoded = std::stoull(content);
|
||||
} catch (std::exception& e) {
|
||||
// oops?
|
||||
ifs.close();
|
||||
std::filesystem::remove(LASTRESTARTPATH);
|
||||
return;
|
||||
}
|
||||
ifs.close();
|
||||
|
||||
if (timeNowMs - timeEncoded < 4000 /* 4s, seems reasonable */) {
|
||||
Debug::log(LOG, "Not restoring on death; less than 4s since last death");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::ofstream ofs(LASTRESTARTPATH, std::ios::trunc);
|
||||
ofs << timeNowMs;
|
||||
ofs.close();
|
||||
|
||||
if (m_bLocked && m_sLockState.lock) {
|
||||
m_sLockState.lock.reset();
|
||||
|
||||
// Destroy sessionLockSurfaces
|
||||
m_vOutputs.clear();
|
||||
}
|
||||
|
||||
spawnSync("hyprctl keyword misc:allow_session_lock_restore true");
|
||||
spawnSync("hyprctl dispatch exec \"hyprlock --immediate --immediate-render\"");
|
||||
SP<CCWlShm> CHyprlock::getShm() {
|
||||
return m_sWaylandState.shm;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ struct SDMABUFModifier {
|
|||
|
||||
class CHyprlock {
|
||||
public:
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender, const bool noFadeIn);
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender);
|
||||
~CHyprlock();
|
||||
|
||||
void run();
|
||||
|
@ -37,9 +37,6 @@ class CHyprlock {
|
|||
void unlock();
|
||||
bool isUnlocked();
|
||||
|
||||
void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
|
||||
void onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -48,16 +45,12 @@ class CHyprlock {
|
|||
void onLockLocked();
|
||||
void onLockFinished();
|
||||
|
||||
void acquireSessionLock();
|
||||
bool acquireSessionLock();
|
||||
void releaseSessionLock();
|
||||
|
||||
void createSessionLockSurfaces();
|
||||
|
||||
void attemptRestoreOnDeath();
|
||||
|
||||
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);
|
||||
|
@ -79,6 +72,7 @@ class CHyprlock {
|
|||
SP<CCWpFractionalScaleManagerV1> getFractionalMgr();
|
||||
SP<CCWpViewporter> getViewporter();
|
||||
SP<CCZwlrScreencopyManagerV1> getScreencopy();
|
||||
SP<CCWlShm> getShm();
|
||||
|
||||
int32_t m_iKeebRepeatRate = 25;
|
||||
int32_t m_iKeebRepeatDelay = 600;
|
||||
|
@ -87,27 +81,27 @@ class CHyprlock {
|
|||
|
||||
bool m_bTerminate = false;
|
||||
|
||||
bool m_bLocked = false;
|
||||
bool m_lockAquired = false;
|
||||
bool m_bLocked = false;
|
||||
|
||||
bool m_bCapsLock = false;
|
||||
bool m_bNumLock = false;
|
||||
bool m_bCtrl = false;
|
||||
bool m_bFadeStarted = false;
|
||||
bool m_bCapsLock = false;
|
||||
bool m_bNumLock = false;
|
||||
bool m_bCtrl = false;
|
||||
|
||||
bool m_bImmediateRender = false;
|
||||
|
||||
bool m_bNoFadeIn = false;
|
||||
|
||||
std::string m_sCurrentDesktop = "";
|
||||
|
||||
//
|
||||
std::chrono::system_clock::time_point m_tGraceEnds;
|
||||
std::chrono::system_clock::time_point m_tFadeEnds;
|
||||
Vector2D m_vLastEnterCoords = {};
|
||||
WP<COutput> m_focusedOutput;
|
||||
|
||||
Vector2D m_vMouseLocation = {};
|
||||
|
||||
std::shared_ptr<CTimer> m_pKeyRepeatTimer = nullptr;
|
||||
|
||||
std::vector<std::unique_ptr<COutput>> m_vOutputs;
|
||||
std::vector<SP<COutput>> m_vOutputs;
|
||||
std::vector<std::shared_ptr<CTimer>> getTimers();
|
||||
|
||||
struct {
|
||||
|
@ -134,6 +128,7 @@ class CHyprlock {
|
|||
SP<CCWpFractionalScaleManagerV1> fractional = nullptr;
|
||||
SP<CCWpViewporter> viewporter = nullptr;
|
||||
SP<CCZwlrScreencopyManagerV1> screencopy = nullptr;
|
||||
SP<CCWlShm> shm = nullptr;
|
||||
} m_sWaylandState;
|
||||
|
||||
void addDmabufListener();
|
||||
|
@ -155,14 +150,19 @@ class CHyprlock {
|
|||
std::condition_variable loopCV;
|
||||
bool event = false;
|
||||
|
||||
std::condition_variable wlDispatchCV;
|
||||
bool wlDispatched = false;
|
||||
|
||||
std::condition_variable timerCV;
|
||||
std::mutex timerRequestMutex;
|
||||
bool timerEvent = false;
|
||||
} m_sLoopState;
|
||||
|
||||
bool m_bUnlockedCalled = false;
|
||||
|
||||
std::vector<std::shared_ptr<CTimer>> m_vTimers;
|
||||
|
||||
std::vector<uint32_t> m_vPressedKeys;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CHyprlock> g_pHyprlock;
|
||||
inline UP<CHyprlock> g_pHyprlock;
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/memory/WeakPtr.hpp>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <hyprgraphics/color/Color.hpp>
|
||||
|
||||
using namespace Hyprutils::Memory;
|
||||
using namespace Hyprgraphics;
|
||||
#define SP CSharedPointer
|
||||
#define WP CWeakPointer
|
||||
#define WP CWeakPointer
|
||||
#define UP CUniquePointer
|
||||
|
||||
typedef int64_t OUTPUTID;
|
||||
constexpr OUTPUTID OUTPUT_INVALID = -1;
|
||||
|
|
67
src/helpers/AnimatedVariable.hpp
Normal file
67
src/helpers/AnimatedVariable.hpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/animation/AnimatedVariable.hpp>
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "Math.hpp"
|
||||
#include "../defines.hpp"
|
||||
#include "../config/ConfigDataValues.hpp"
|
||||
|
||||
enum eAnimatedVarType {
|
||||
AVARTYPE_INVALID = -1,
|
||||
AVARTYPE_FLOAT,
|
||||
AVARTYPE_VECTOR,
|
||||
AVARTYPE_COLOR,
|
||||
AVARTYPE_GRADIENT
|
||||
};
|
||||
|
||||
// Utility to bind a type with its corresponding eAnimatedVarType
|
||||
template <class T>
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct STypeToAnimatedVarType_t {
|
||||
static constexpr eAnimatedVarType value = AVARTYPE_INVALID;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct STypeToAnimatedVarType_t<float> {
|
||||
static constexpr eAnimatedVarType value = AVARTYPE_FLOAT;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct STypeToAnimatedVarType_t<Vector2D> {
|
||||
static constexpr eAnimatedVarType value = AVARTYPE_VECTOR;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct STypeToAnimatedVarType_t<CHyprColor> {
|
||||
static constexpr eAnimatedVarType value = AVARTYPE_COLOR;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct STypeToAnimatedVarType_t<CGradientValueData> {
|
||||
static constexpr eAnimatedVarType value = AVARTYPE_GRADIENT;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr eAnimatedVarType typeToeAnimatedVarType = STypeToAnimatedVarType_t<T>::value;
|
||||
|
||||
// Utility to define a concept as a list of possible type
|
||||
template <class T, class... U>
|
||||
concept OneOf = (... or std::same_as<T, U>);
|
||||
|
||||
// Concept to describe which type can be placed into CAnimatedVariable
|
||||
// This is mainly to get better errors if we put a type that's not supported
|
||||
// Otherwise template errors are ugly
|
||||
template <class T>
|
||||
concept Animable = OneOf<T, Vector2D, float, CHyprColor, CGradientValueData>;
|
||||
|
||||
struct SAnimationContext {};
|
||||
|
||||
template <Animable VarType>
|
||||
using CAnimatedVariable = Hyprutils::Animation::CGenericAnimatedVariable<VarType, SAnimationContext>;
|
||||
|
||||
template <Animable VarType>
|
||||
using PHLANIMVAR = SP<CAnimatedVariable<VarType>>;
|
||||
|
||||
template <Animable VarType>
|
||||
using PHLANIMVARREF = WP<CAnimatedVariable<VarType>>;
|
|
@ -5,22 +5,43 @@
|
|||
#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0)
|
||||
#define BLUE(c) ((double)(((c)) & 0xff) / 255.0)
|
||||
|
||||
CColor::CColor() {}
|
||||
|
||||
CColor::CColor(float r, float g, float b, float a) {
|
||||
this->r = r;
|
||||
this->g = g;
|
||||
this->b = b;
|
||||
this->a = a;
|
||||
CHyprColor::CHyprColor() {
|
||||
;
|
||||
}
|
||||
|
||||
CColor::CColor(uint64_t hex) {
|
||||
this->r = RED(hex);
|
||||
this->g = GREEN(hex);
|
||||
this->b = BLUE(hex);
|
||||
this->a = ALPHA(hex);
|
||||
CHyprColor::CHyprColor(float r_, float g_, float b_, float a_) : r(r_), g(g_), b(b_), a(a_) {
|
||||
okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{.r = r, .g = g, .b = b}).asOkLab();
|
||||
}
|
||||
|
||||
uint32_t CColor::getAsHex() const {
|
||||
return (uint32_t)(a * 255.f) * 0x1000000 + (uint32_t)(r * 255.f) * 0x10000 + (uint32_t)(g * 255.f) * 0x100 + (uint32_t)(b * 255.f) * 0x1;
|
||||
}
|
||||
CHyprColor::CHyprColor(uint64_t hex) : r(RED(hex)), g(GREEN(hex)), b(BLUE(hex)), a(ALPHA(hex)) {
|
||||
okLab = Hyprgraphics::CColor(Hyprgraphics::CColor::SSRGB{.r = r, .g = g, .b = b}).asOkLab();
|
||||
}
|
||||
|
||||
CHyprColor::CHyprColor(const Hyprgraphics::CColor& color, float a_) : a(a_) {
|
||||
const auto SRGB = color.asRgb();
|
||||
r = SRGB.r;
|
||||
g = SRGB.g;
|
||||
b = SRGB.b;
|
||||
|
||||
okLab = color.asOkLab();
|
||||
}
|
||||
|
||||
uint32_t CHyprColor::getAsHex() const {
|
||||
return ((uint32_t)(a * 255.f) * 0x1000000) + ((uint32_t)(r * 255.f) * 0x10000) + ((uint32_t)(g * 255.f) * 0x100) + ((uint32_t)(b * 255.f) * 0x1);
|
||||
}
|
||||
|
||||
Hyprgraphics::CColor::SSRGB CHyprColor::asRGB() const {
|
||||
return {.r = r, .g = g, .b = b};
|
||||
}
|
||||
|
||||
Hyprgraphics::CColor::SOkLab CHyprColor::asOkLab() const {
|
||||
return okLab;
|
||||
}
|
||||
|
||||
Hyprgraphics::CColor::SHSL CHyprColor::asHSL() const {
|
||||
return Hyprgraphics::CColor(okLab).asHSL();
|
||||
}
|
||||
|
||||
CHyprColor CHyprColor::stripA() const {
|
||||
return {r, g, b, 1.F};
|
||||
}
|
||||
|
|
|
@ -1,35 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "../helpers/Log.hpp"
|
||||
#include <hyprgraphics/color/Color.hpp>
|
||||
|
||||
class CColor {
|
||||
class CHyprColor {
|
||||
public:
|
||||
CColor();
|
||||
CColor(float r, float g, float b, float a);
|
||||
CColor(uint64_t);
|
||||
|
||||
float r = 0, g = 0, b = 0, a = 1.f;
|
||||
CHyprColor();
|
||||
CHyprColor(float r, float g, float b, float a);
|
||||
CHyprColor(const Hyprgraphics::CColor& col, float a);
|
||||
CHyprColor(uint64_t);
|
||||
|
||||
// AR32
|
||||
uint32_t getAsHex() const;
|
||||
uint32_t getAsHex() const;
|
||||
Hyprgraphics::CColor::SSRGB asRGB() const;
|
||||
Hyprgraphics::CColor::SOkLab asOkLab() const;
|
||||
Hyprgraphics::CColor::SHSL asHSL() const;
|
||||
CHyprColor stripA() const;
|
||||
|
||||
CColor operator-(const CColor& c2) const {
|
||||
return CColor(r - c2.r, g - c2.g, b - c2.b, a - c2.a);
|
||||
//
|
||||
bool operator==(const CHyprColor& c2) const {
|
||||
return c2.r == r && c2.g == g && c2.b == b && c2.a == a;
|
||||
}
|
||||
|
||||
CColor operator+(const CColor& c2) const {
|
||||
return CColor(r + c2.r, g + c2.g, b + c2.b, a + c2.a);
|
||||
// stubs for the AnimationMgr
|
||||
CHyprColor operator-(const CHyprColor& c2) const {
|
||||
RASSERT(false, "CHyprColor: - is a STUB");
|
||||
return {};
|
||||
}
|
||||
|
||||
CColor operator*(const float& v) const {
|
||||
return CColor(r * v, g * v, b * v, a * v);
|
||||
CHyprColor operator+(const CHyprColor& c2) const {
|
||||
RASSERT(false, "CHyprColor: + is a STUB");
|
||||
return {};
|
||||
}
|
||||
|
||||
bool operator==(const CColor& c2) const {
|
||||
return r == c2.r && g == c2.g && b == c2.b && a == c2.a;
|
||||
CHyprColor operator*(const float& c2) const {
|
||||
RASSERT(false, "CHyprColor: * is a STUB");
|
||||
return {};
|
||||
}
|
||||
|
||||
CColor stripA() const {
|
||||
return {r, g, b, 1};
|
||||
}
|
||||
double r = 0, g = 0, b = 0, a = 0;
|
||||
|
||||
private:
|
||||
Hyprgraphics::CColor::SOkLab okLab; // cache for the OkLab representation
|
||||
};
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <fcntl.h>
|
||||
#include "MiscFunctions.hpp"
|
||||
#include "../helpers/Log.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);
|
||||
|
@ -13,10 +17,11 @@ std::string absolutePath(const std::string& rawpath, const std::string& currentD
|
|||
// Handling where rawpath starts with '~'
|
||||
if (!rawpath.empty() && rawpath[0] == '~') {
|
||||
static const char* const ENVHOME = getenv("HOME");
|
||||
return std::filesystem::path(ENVHOME) / path.relative_path().string().substr(2);
|
||||
path = std::filesystem::path(ENVHOME) / path.relative_path().string().substr(2);
|
||||
}
|
||||
|
||||
// Handling e.g. ./, ../
|
||||
else if (path.is_relative()) {
|
||||
if (path.is_relative()) {
|
||||
return std::filesystem::weakly_canonical(std::filesystem::path(currentDir) / path);
|
||||
} else {
|
||||
return std::filesystem::weakly_canonical(path);
|
||||
|
@ -54,11 +59,11 @@ int64_t configStringToInt(const std::string& VALUE) {
|
|||
a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f);
|
||||
} catch (std::exception& e) { throw std::invalid_argument("failed parsing " + VALUEWITHOUTFUNC); }
|
||||
|
||||
return a * (Hyprlang::INT)0x1000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b;
|
||||
return (a * (Hyprlang::INT)0x1000000) + (r * (Hyprlang::INT)0x10000) + (g * (Hyprlang::INT)0x100) + b;
|
||||
} else if (VALUEWITHOUTFUNC.length() == 8) {
|
||||
const auto RGBA = parseHex(VALUEWITHOUTFUNC);
|
||||
// now we need to RGBA -> ARGB. The config holds ARGB only.
|
||||
return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF);
|
||||
return (RGBA >> 8) + (0x1000000 * (RGBA & 0xFF));
|
||||
}
|
||||
|
||||
throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values");
|
||||
|
@ -76,7 +81,7 @@ int64_t configStringToInt(const std::string& VALUE) {
|
|||
rolling = rolling.substr(rolling.find(',') + 1);
|
||||
auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||
|
||||
return (Hyprlang::INT)0xFF000000 + r * (Hyprlang::INT)0x10000 + g * (Hyprlang::INT)0x100 + b;
|
||||
return (Hyprlang::INT)0xFF000000 + (r * (Hyprlang::INT)0x10000) + (g * (Hyprlang::INT)0x100) + b;
|
||||
} else if (VALUEWITHOUTFUNC.length() == 6) {
|
||||
return parseHex(VALUEWITHOUTFUNC) + 0xFF000000;
|
||||
}
|
||||
|
@ -97,4 +102,59 @@ int64_t configStringToInt(const std::string& VALUE) {
|
|||
} catch (std::exception& e) { throw std::invalid_argument(std::string{"stoll threw: "} + e.what()); }
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int createPoolFile(size_t size, std::string& name) {
|
||||
const auto XDGRUNTIMEDIR = getenv("XDG_RUNTIME_DIR");
|
||||
if (!XDGRUNTIMEDIR) {
|
||||
Debug::log(CRIT, "XDG_RUNTIME_DIR not set!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = std::string(XDGRUNTIMEDIR) + "/.hyprlock_sc_XXXXXX";
|
||||
|
||||
const auto FD = mkstemp((char*)name.c_str());
|
||||
if (FD < 0) {
|
||||
Debug::log(CRIT, "createPoolFile: fd < 0");
|
||||
return -1;
|
||||
}
|
||||
// set cloexec
|
||||
long flags = fcntl(FD, F_GETFD);
|
||||
if (flags == -1) {
|
||||
close(FD);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fcntl(FD, F_SETFD, flags | FD_CLOEXEC) == -1) {
|
||||
close(FD);
|
||||
Debug::log(CRIT, "createPoolFile: fcntl < 0");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ftruncate(FD, size) < 0) {
|
||||
close(FD);
|
||||
Debug::log(CRIT, "createPoolFile: ftruncate < 0");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -6,3 +6,6 @@
|
|||
|
||||
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);
|
||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -2,6 +2,7 @@
|
|||
#include "config/ConfigManager.hpp"
|
||||
#include "core/hyprlock.hpp"
|
||||
#include "helpers/Log.hpp"
|
||||
#include "core/AnimationManager.hpp"
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
|
@ -28,6 +29,14 @@ std::optional<std::string> parseArg(const std::vector<std::string>& args, const
|
|||
}
|
||||
}
|
||||
|
||||
static void printVersion() {
|
||||
constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT;
|
||||
if (ISTAGGEDRELEASE)
|
||||
std::println("Hyprlock version v{}", HYPRLOCK_VERSION);
|
||||
else
|
||||
std::println("Hyprlock version v{} (commit {})", HYPRLOCK_VERSION, HYPRLOCK_COMMIT);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv, char** envp) {
|
||||
std::string configPath;
|
||||
std::string wlDisplay;
|
||||
|
@ -46,12 +55,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
|
||||
if (arg == "--version" || arg == "-V") {
|
||||
constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT;
|
||||
if (ISTAGGEDRELEASE)
|
||||
std::println("Hyprlock version v{}", HYPRLOCK_VERSION);
|
||||
else
|
||||
std::println("Hyprlock version v{} (commit {})", HYPRLOCK_VERSION, HYPRLOCK_COMMIT);
|
||||
|
||||
printVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -89,8 +93,11 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
}
|
||||
|
||||
printVersion();
|
||||
g_pAnimationManager = makeUnique<CHyprlockAnimationManager>();
|
||||
|
||||
try {
|
||||
g_pConfigManager = std::make_unique<CConfigManager>(configPath);
|
||||
g_pConfigManager = makeUnique<CConfigManager>(configPath);
|
||||
g_pConfigManager->init();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "ConfigManager threw: {}", ex.what());
|
||||
|
@ -100,8 +107,11 @@ int main(int argc, char** argv, char** envp) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (noFadeIn || immediate)
|
||||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = std::make_unique<CHyprlock>(wlDisplay, immediate, immediateRender, noFadeIn);
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "../config/ConfigManager.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include <cairo/cairo.h>
|
||||
#include <magic.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
@ -15,13 +14,13 @@ using namespace Hyprgraphics;
|
|||
|
||||
CAsyncResourceGatherer::CAsyncResourceGatherer() {
|
||||
if (g_pHyprlock->getScreencopy())
|
||||
enqueueDMAFrames();
|
||||
enqueueScreencopyFrames();
|
||||
|
||||
initialGatherThread = std::thread([this]() { this->gather(); });
|
||||
asyncLoopThread = std::thread([this]() { this->asyncAssetSpinLock(); });
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::enqueueDMAFrames() {
|
||||
void CAsyncResourceGatherer::enqueueScreencopyFrames() {
|
||||
// some things can't be done async :(
|
||||
// gather background textures when needed
|
||||
|
||||
|
@ -48,15 +47,12 @@ void CAsyncResourceGatherer::enqueueDMAFrames() {
|
|||
}
|
||||
|
||||
for (auto& mon : mons) {
|
||||
const auto MON = std::find_if(g_pHyprlock->m_vOutputs.begin(), g_pHyprlock->m_vOutputs.end(),
|
||||
[mon](const auto& other) { return other->stringPort == mon || other->stringDesc.starts_with(mon); });
|
||||
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;
|
||||
|
||||
const auto PMONITOR = MON->get();
|
||||
|
||||
dmas.emplace_back(std::make_unique<CDMAFrame>(PMONITOR));
|
||||
scframes.emplace_back(makeUnique<CScreencopyFrame>(*MON));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,9 +69,9 @@ SPreloadedAsset* CAsyncResourceGatherer::getAssetByID(const std::string& id) {
|
|||
}
|
||||
};
|
||||
|
||||
for (auto& dma : dmas) {
|
||||
if (id == dma->resourceID)
|
||||
return dma->asset.ready ? &dma->asset : nullptr;
|
||||
for (auto& frame : scframes) {
|
||||
if (id == frame->m_resourceID)
|
||||
return frame->m_asset.ready ? &frame->m_asset : nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -130,7 +126,7 @@ void CAsyncResourceGatherer::gather() {
|
|||
}
|
||||
}
|
||||
|
||||
while (!g_pHyprlock->m_bTerminate && std::any_of(dmas.begin(), dmas.end(), [](const auto& d) { return !d->asset.ready; })) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -215,15 +211,15 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
|||
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 CColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CColor>(rq.props.at("color")) : CColor(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;
|
||||
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 auto* const TRIM = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:text_trim");
|
||||
std::string text = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
|
||||
static const auto TRIM = g_pConfigManager->getValue<Hyprlang::INT>("general:text_trim");
|
||||
std::string text = ISCMD ? spawnSync(rq.asset) : rq.asset;
|
||||
|
||||
if (**TRIM) {
|
||||
if (*TRIM) {
|
||||
text.erase(0, text.find_first_not_of(" \n\r\t"));
|
||||
text.erase(text.find_last_not_of(" \n\r\t") + 1);
|
||||
}
|
||||
|
@ -304,22 +300,11 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
|||
preloadTargets.push_back(target);
|
||||
}
|
||||
|
||||
struct STimerCallbackData {
|
||||
void (*cb)(void*) = nullptr;
|
||||
void* data = nullptr;
|
||||
};
|
||||
|
||||
static void timerCallback(std::shared_ptr<CTimer> self, void* data_) {
|
||||
auto data = (STimerCallbackData*)data_;
|
||||
data->cb(data->data);
|
||||
delete data;
|
||||
}
|
||||
|
||||
void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
||||
while (!g_pHyprlock->m_bTerminate) {
|
||||
|
||||
std::unique_lock lk(asyncLoopState.requestsMutex);
|
||||
if (asyncLoopState.pending == false) // avoid a lock if a thread managed to request something already since we .unlock()ed
|
||||
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;
|
||||
|
@ -349,7 +334,7 @@ void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
|||
|
||||
// plant timer for callback
|
||||
if (r.callback)
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), timerCallback, new STimerCallbackData{r.callback, r.callbackData});
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [cb = r.callback](auto, auto) { cb(); }, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "DMAFrame.hpp"
|
||||
#include "Screencopy.hpp"
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
@ -37,8 +37,7 @@ class CAsyncResourceGatherer {
|
|||
// 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.
|
||||
void (*callback)(void*) = nullptr;
|
||||
void* callbackData = nullptr;
|
||||
std::function<void()> callback = nullptr;
|
||||
};
|
||||
|
||||
void requestAsyncAssetPreload(const SPreloadRequest& request);
|
||||
|
@ -75,7 +74,7 @@ class CAsyncResourceGatherer {
|
|||
Vector2D size;
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<CDMAFrame>> dmas;
|
||||
std::vector<UP<CScreencopyFrame>> scframes;
|
||||
|
||||
std::vector<SPreloadTarget> preloadTargets;
|
||||
std::mutex preloadTargetsMutex;
|
||||
|
@ -83,5 +82,5 @@ class CAsyncResourceGatherer {
|
|||
std::unordered_map<std::string, SPreloadedAsset> assets;
|
||||
|
||||
void gather();
|
||||
void enqueueDMAFrames();
|
||||
void enqueueScreencopyFrames();
|
||||
};
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
#include "DMAFrame.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../core/hyprlock.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include <EGL/eglext.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
#include <GLES3/gl32.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullptr;
|
||||
static PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr;
|
||||
|
||||
//
|
||||
std::string CDMAFrame::getResourceId(COutput* output) {
|
||||
return std::format("dma:{}-{}x{}", output->stringPort, output->size.x, output->size.y);
|
||||
}
|
||||
|
||||
CDMAFrame::CDMAFrame(COutput* output_) {
|
||||
resourceID = getResourceId(output_);
|
||||
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
Debug::log(ERR, "No glEGLImageTargetTexture2DOES??");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!eglQueryDmaBufModifiersEXT)
|
||||
eglQueryDmaBufModifiersEXT = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC)eglGetProcAddress("eglQueryDmaBufModifiersEXT");
|
||||
|
||||
// firstly, plant a listener for the frame
|
||||
frameCb = makeShared<CCZwlrScreencopyFrameV1>(g_pHyprlock->getScreencopy()->sendCaptureOutput(false, output_->output->resource()));
|
||||
|
||||
frameCb->setBufferDone([this](CCZwlrScreencopyFrameV1* r) {
|
||||
Debug::log(TRACE, "[sc] wlrOnBufferDone for {}", (void*)this);
|
||||
|
||||
if (!onBufferDone()) {
|
||||
Debug::log(ERR, "onBufferDone failed");
|
||||
return;
|
||||
}
|
||||
|
||||
frameCb->sendCopy(wlBuffer->resource());
|
||||
|
||||
Debug::log(TRACE, "[sc] wlr frame copied");
|
||||
});
|
||||
|
||||
frameCb->setLinuxDmabuf([this](CCZwlrScreencopyFrameV1* r, uint32_t format, uint32_t width, uint32_t height) {
|
||||
Debug::log(TRACE, "[sc] wlrOnDmabuf for {}", (void*)this);
|
||||
|
||||
w = width;
|
||||
h = height;
|
||||
fmt = format;
|
||||
|
||||
Debug::log(TRACE, "[sc] DMABUF format reported: {:x}", format);
|
||||
});
|
||||
|
||||
frameCb->setReady([this](CCZwlrScreencopyFrameV1* r, uint32_t, uint32_t, uint32_t) {
|
||||
Debug::log(TRACE, "[sc] wlrOnReady for {}", (void*)this);
|
||||
|
||||
if (!onBufferReady()) {
|
||||
Debug::log(ERR, "onBufferReady failed");
|
||||
return;
|
||||
}
|
||||
|
||||
frameCb.reset();
|
||||
});
|
||||
|
||||
frameCb->setBuffer([this](CCZwlrScreencopyFrameV1* r, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
||||
Debug::log(TRACE, "[sc] wlrOnBuffer for {}", (void*)this);
|
||||
|
||||
frameSize = stride * height;
|
||||
frameStride = stride;
|
||||
});
|
||||
}
|
||||
|
||||
CDMAFrame::~CDMAFrame() {
|
||||
if (g_pEGL)
|
||||
eglDestroyImage(g_pEGL->eglDisplay, image);
|
||||
|
||||
// leaks bo and stuff but lives throughout so for now who cares
|
||||
}
|
||||
|
||||
bool CDMAFrame::onBufferDone() {
|
||||
uint32_t flags = GBM_BO_USE_RENDERING;
|
||||
|
||||
if (!eglQueryDmaBufModifiersEXT) {
|
||||
Debug::log(WARN, "Querying modifiers without eglQueryDmaBufModifiersEXT support");
|
||||
bo = gbm_bo_create(g_pHyprlock->dma.gbmDevice, w, h, fmt, flags);
|
||||
} else {
|
||||
std::vector<uint64_t> mods;
|
||||
mods.resize(64);
|
||||
std::vector<EGLBoolean> externalOnly;
|
||||
externalOnly.resize(64);
|
||||
int num = 0;
|
||||
if (!eglQueryDmaBufModifiersEXT(g_pEGL->eglDisplay, fmt, 64, mods.data(), externalOnly.data(), &num) || num == 0) {
|
||||
Debug::log(WARN, "eglQueryDmaBufModifiersEXT failed, falling back to regular bo");
|
||||
bo = gbm_bo_create(g_pHyprlock->dma.gbmDevice, w, h, fmt, flags);
|
||||
} else {
|
||||
Debug::log(LOG, "eglQueryDmaBufModifiersEXT found {} mods", num);
|
||||
std::vector<uint64_t> goodMods;
|
||||
for (int i = 0; i < num; ++i) {
|
||||
if (externalOnly[i]) {
|
||||
Debug::log(TRACE, "Modifier {:x} failed test", mods[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
Debug::log(TRACE, "Modifier {:x} passed test", mods[i]);
|
||||
goodMods.push_back(mods[i]);
|
||||
}
|
||||
|
||||
uint64_t zero = 0;
|
||||
bool hasLinear = std::find(goodMods.begin(), goodMods.end(), 0) != goodMods.end();
|
||||
|
||||
bo = gbm_bo_create_with_modifiers2(g_pHyprlock->dma.gbmDevice, w, h, fmt, hasLinear ? &zero : goodMods.data(), hasLinear ? 1 : goodMods.size(), flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bo) {
|
||||
Debug::log(ERR, "Couldn't create a drm buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
planes = gbm_bo_get_plane_count(bo);
|
||||
|
||||
uint64_t mod = gbm_bo_get_modifier(bo);
|
||||
Debug::log(LOG, "bo chose modifier {:x}", mod);
|
||||
|
||||
auto params = makeShared<CCZwpLinuxBufferParamsV1>(g_pHyprlock->dma.linuxDmabuf->sendCreateParams());
|
||||
if (!params) {
|
||||
Debug::log(ERR, "zwp_linux_dmabuf_v1_create_params failed");
|
||||
gbm_bo_destroy(bo);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t plane = 0; plane < (size_t)planes; plane++) {
|
||||
size[plane] = 0;
|
||||
stride[plane] = gbm_bo_get_stride_for_plane(bo, plane);
|
||||
offset[plane] = gbm_bo_get_offset(bo, plane);
|
||||
fd[plane] = gbm_bo_get_fd_for_plane(bo, plane);
|
||||
|
||||
if (fd[plane] < 0) {
|
||||
Debug::log(ERR, "gbm_bo_get_fd_for_plane failed");
|
||||
params.reset();
|
||||
gbm_bo_destroy(bo);
|
||||
for (size_t plane_tmp = 0; plane_tmp < plane; plane_tmp++) {
|
||||
close(fd[plane_tmp]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
params->sendAdd(fd[plane], plane, offset[plane], stride[plane], mod >> 32, mod & 0xffffffff);
|
||||
}
|
||||
|
||||
wlBuffer = makeShared<CCWlBuffer>(params->sendCreateImmed(w, h, fmt, (zwpLinuxBufferParamsV1Flags)0));
|
||||
params.reset();
|
||||
|
||||
if (!wlBuffer) {
|
||||
Debug::log(ERR, "[pw] zwp_linux_buffer_params_v1_create_immed failed");
|
||||
gbm_bo_destroy(bo);
|
||||
for (size_t plane = 0; plane < (size_t)planes; plane++)
|
||||
close(fd[plane]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDMAFrame::onBufferReady() {
|
||||
static const int general_attribs = 3;
|
||||
static const int plane_attribs = 5;
|
||||
static const int entries_per_attrib = 2;
|
||||
EGLAttrib attribs[(general_attribs + plane_attribs * 4) * entries_per_attrib + 1];
|
||||
int attr = 0;
|
||||
Vector2D size{w, h};
|
||||
|
||||
attribs[attr++] = EGL_WIDTH;
|
||||
attribs[attr++] = size.x;
|
||||
attribs[attr++] = EGL_HEIGHT;
|
||||
attribs[attr++] = size.y;
|
||||
attribs[attr++] = EGL_LINUX_DRM_FOURCC_EXT;
|
||||
attribs[attr++] = fmt;
|
||||
attribs[attr++] = EGL_DMA_BUF_PLANE0_FD_EXT;
|
||||
attribs[attr++] = fd[0];
|
||||
attribs[attr++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
|
||||
attribs[attr++] = offset[0];
|
||||
attribs[attr++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
|
||||
attribs[attr++] = stride[0];
|
||||
attribs[attr] = EGL_NONE;
|
||||
|
||||
image = eglCreateImage(g_pEGL->eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs);
|
||||
|
||||
if (image == EGL_NO_IMAGE) {
|
||||
Debug::log(ERR, "failed creating an egl image");
|
||||
return false;
|
||||
}
|
||||
|
||||
asset.texture.allocate();
|
||||
asset.texture.m_vSize = size;
|
||||
glBindTexture(GL_TEXTURE_2D, asset.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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
Debug::log(LOG, "Got dma frame with size {}", size);
|
||||
|
||||
asset.ready = true;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../core/Output.hpp"
|
||||
#include <gbm.h>
|
||||
#include "Shared.hpp"
|
||||
#include "linux-dmabuf-v1.hpp"
|
||||
#include "wlr-screencopy-unstable-v1.hpp"
|
||||
|
||||
class CDMAFrame;
|
||||
|
||||
class CDMAFrame {
|
||||
public:
|
||||
static std::string getResourceId(COutput* output);
|
||||
|
||||
CDMAFrame(COutput* mon);
|
||||
~CDMAFrame();
|
||||
|
||||
bool onBufferDone();
|
||||
bool onBufferReady();
|
||||
|
||||
SP<CCWlBuffer> wlBuffer = nullptr;
|
||||
|
||||
std::string resourceID;
|
||||
|
||||
SPreloadedAsset asset;
|
||||
|
||||
private:
|
||||
gbm_bo* bo = nullptr;
|
||||
|
||||
int planes = 0;
|
||||
|
||||
int fd[4];
|
||||
uint32_t size[4], stride[4], offset[4];
|
||||
|
||||
SP<CCZwlrScreencopyFrameV1> frameCb = nullptr;
|
||||
int w = 0, h = 0;
|
||||
uint32_t fmt = 0;
|
||||
size_t frameSize = 0;
|
||||
size_t frameStride = 0;
|
||||
|
||||
EGLImage image = nullptr;
|
||||
};
|
|
@ -117,6 +117,6 @@ CFramebuffer::~CFramebuffer() {
|
|||
release();
|
||||
}
|
||||
|
||||
bool CFramebuffer::isAllocated() {
|
||||
bool CFramebuffer::isAllocated() const {
|
||||
return m_iFb != (GLuint)-1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class CFramebuffer {
|
|||
void bind() const;
|
||||
void release();
|
||||
void reset();
|
||||
bool isAllocated();
|
||||
bool isAllocated() const;
|
||||
|
||||
Vector2D m_vSize;
|
||||
|
||||
|
@ -21,4 +21,4 @@ class CFramebuffer {
|
|||
GLuint m_iFb = -1;
|
||||
|
||||
CTexture* m_pStencilTex = nullptr;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#include "Renderer.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include "Shaders.hpp"
|
||||
#include "Screencopy.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../helpers/Color.hpp"
|
||||
#include "../core/AnimationManager.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include "../core/Output.hpp"
|
||||
#include "../core/hyprlock.hpp"
|
||||
#include "../renderer/DMAFrame.hpp"
|
||||
#include "../helpers/Color.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include <GLES3/gl32.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#include <algorithm>
|
||||
#include "Shaders.hpp"
|
||||
#include "src/helpers/Log.hpp"
|
||||
#include "widgets/PasswordInputField.hpp"
|
||||
#include "widgets/Background.hpp"
|
||||
#include "widgets/Label.hpp"
|
||||
|
@ -28,7 +30,7 @@ GLuint compileShader(const GLuint& type, std::string src) {
|
|||
|
||||
auto shaderSource = src.c_str();
|
||||
|
||||
glShaderSource(shader, 1, (const GLchar**)&shaderSource, nullptr);
|
||||
glShaderSource(shader, 1, &shaderSource, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint ok;
|
||||
|
@ -42,11 +44,11 @@ GLuint compileShader(const GLuint& type, std::string src) {
|
|||
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.c_str());
|
||||
RASSERT(vertCompiled, "Compiling shader failed. VERTEX NULL! Shader source:\n\n{}", vert);
|
||||
|
||||
auto fragCompiled = compileShader(GL_FRAGMENT_SHADER, frag);
|
||||
|
||||
RASSERT(fragCompiled, "Compiling shader failed. FRAGMENT NULL! Shader source:\n\n{}", frag.c_str());
|
||||
RASSERT(fragCompiled, "Compiling shader failed. FRAGMENT NULL! Shader source:\n\n{}", frag);
|
||||
|
||||
auto prog = glCreateProgram();
|
||||
glAttachShader(prog, vertCompiled);
|
||||
|
@ -76,7 +78,7 @@ CRenderer::CRenderer() {
|
|||
g_pEGL->makeCurrent(nullptr);
|
||||
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageCallback(glMessageCallbackA, 0);
|
||||
glDebugMessageCallback(glMessageCallbackA, nullptr);
|
||||
|
||||
GLuint prog = createProgram(QUADVERTSRC, QUADFRAGSRC);
|
||||
rectShader.program = prog;
|
||||
|
@ -186,19 +188,19 @@ CRenderer::CRenderer() {
|
|||
borderShader.gradient = glGetUniformLocation(prog, "gradient");
|
||||
borderShader.gradientLength = glGetUniformLocation(prog, "gradientLength");
|
||||
borderShader.angle = glGetUniformLocation(prog, "angle");
|
||||
borderShader.gradient2 = glGetUniformLocation(prog, "gradient2");
|
||||
borderShader.gradient2Length = glGetUniformLocation(prog, "gradient2Length");
|
||||
borderShader.angle2 = glGetUniformLocation(prog, "angle2");
|
||||
borderShader.gradientLerp = glGetUniformLocation(prog, "gradientLerp");
|
||||
borderShader.alpha = glGetUniformLocation(prog, "alpha");
|
||||
|
||||
asyncResourceGatherer = std::make_unique<CAsyncResourceGatherer>();
|
||||
}
|
||||
asyncResourceGatherer = makeUnique<CAsyncResourceGatherer>();
|
||||
|
||||
static int frames = 0;
|
||||
static bool firstFullFrame = false;
|
||||
g_pAnimationManager->createAnimation(0.f, opacity, g_pConfigManager->m_AnimationTree.getConfig("fadeIn"));
|
||||
}
|
||||
|
||||
//
|
||||
CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf) {
|
||||
static auto* const PDISABLEBAR = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:disable_loading_bar");
|
||||
static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out");
|
||||
|
||||
projection = Mat3x3::outputProjection(surf.size, HYPRUTILS_TRANSFORM_NORMAL);
|
||||
|
||||
g_pEGL->makeCurrent(surf.eglSurface);
|
||||
|
@ -215,52 +217,24 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf
|
|||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
SRenderFeedback feedback;
|
||||
float bga = 0.0;
|
||||
const bool WAITFORASSETS = !g_pHyprlock->m_bImmediateRender && !asyncResourceGatherer->gathered;
|
||||
|
||||
if (WAITFORASSETS) {
|
||||
|
||||
// render status
|
||||
if (!**PDISABLEBAR) {
|
||||
CBox progress = {0, 0, asyncResourceGatherer->progress * surf.size.x, 2};
|
||||
renderRect(progress, CColor{0.2f, 0.1f, 0.1f, 1.f}, 0);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!firstFullFrame) {
|
||||
firstFullFrameTime = std::chrono::system_clock::now();
|
||||
firstFullFrame = true;
|
||||
}
|
||||
|
||||
bga = std::clamp(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - firstFullFrameTime).count() / 500000.0, 0.0, 1.0);
|
||||
|
||||
if (g_pHyprlock->m_bNoFadeIn)
|
||||
bga = 1.0;
|
||||
|
||||
if (g_pHyprlock->m_bFadeStarted && !**PNOFADEOUT) {
|
||||
bga =
|
||||
std::clamp(std::chrono::duration_cast<std::chrono::microseconds>(g_pHyprlock->m_tFadeEnds - std::chrono::system_clock::now()).count() / 500000.0 - 0.02, 0.0, 1.0);
|
||||
// - 0.02 so that the fade ends a little earlier than the final second
|
||||
}
|
||||
if (!WAITFORASSETS) {
|
||||
// render widgets
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(&surf);
|
||||
for (auto& w : *WIDGETS) {
|
||||
feedback.needsFrame = w->draw({bga}) || feedback.needsFrame;
|
||||
const auto WIDGETS = getOrCreateWidgetsFor(surf);
|
||||
for (auto& w : WIDGETS) {
|
||||
feedback.needsFrame = w->draw({opacity->value()}) || feedback.needsFrame;
|
||||
}
|
||||
}
|
||||
|
||||
frames++;
|
||||
|
||||
Debug::log(TRACE, "frame {}", frames);
|
||||
|
||||
feedback.needsFrame = feedback.needsFrame || !asyncResourceGatherer->gathered || bga < 1.0;
|
||||
feedback.needsFrame = feedback.needsFrame || !asyncResourceGatherer->gathered;
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
return feedback;
|
||||
}
|
||||
|
||||
void CRenderer::renderRect(const CBox& box, const CColor& col, int rounding) {
|
||||
void CRenderer::renderRect(const CBox& box, const CHyprColor& col, int rounding) {
|
||||
const auto ROUNDEDBOX = box.copy().round();
|
||||
Mat3x3 matrix = projMatrix.projectBox(ROUNDEDBOX, HYPRUTILS_TRANSFORM_NORMAL, box.rot);
|
||||
Mat3x3 glMatrix = projection.copy().multiply(matrix);
|
||||
|
@ -298,12 +272,11 @@ void CRenderer::renderBorder(const CBox& box, const CGradientValueData& gradient
|
|||
|
||||
glUniformMatrix3fv(borderShader.proj, 1, GL_TRUE, glMatrix.getMatrix().data());
|
||||
|
||||
static_assert(sizeof(CColor) == 4 * sizeof(float)); // otherwise the line below this will fail
|
||||
|
||||
glUniform4fv(borderShader.gradient, gradient.m_vColors.size(), (float*)gradient.m_vColors.data());
|
||||
glUniform1i(borderShader.gradientLength, gradient.m_vColors.size());
|
||||
glUniform4fv(borderShader.gradient, gradient.m_vColorsOkLabA.size() / 4, (float*)gradient.m_vColorsOkLabA.data());
|
||||
glUniform1i(borderShader.gradientLength, gradient.m_vColorsOkLabA.size() / 4);
|
||||
glUniform1f(borderShader.angle, (int)(gradient.m_fAngle / (M_PI / 180.0)) % 360 * (M_PI / 180.0));
|
||||
glUniform1f(borderShader.alpha, alpha);
|
||||
glUniform1i(borderShader.gradient2Length, 0);
|
||||
|
||||
const auto TOPLEFT = Vector2D(ROUNDEDBOX.x, ROUNDEDBOX.y);
|
||||
const auto FULLSIZE = Vector2D(ROUNDEDBOX.width, ROUNDEDBOX.height);
|
||||
|
@ -414,62 +387,49 @@ void CRenderer::renderTextureMix(const CBox& box, const CTexture& tex, const CTe
|
|||
glBindTexture(tex.m_iTarget, 0);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface* surf) {
|
||||
if (!widgets.contains(surf)) {
|
||||
template <class Widget>
|
||||
static void createWidget(std::vector<SP<IWidget>>& widgets) {
|
||||
const auto W = makeShared<Widget>();
|
||||
W->registerSelf(W);
|
||||
widgets.emplace_back(W);
|
||||
}
|
||||
|
||||
std::vector<SP<IWidget>>& CRenderer::getOrCreateWidgetsFor(const CSessionLockSurface& surf) {
|
||||
RASSERT(surf.m_outputID != OUTPUT_INVALID, "Invalid output ID!");
|
||||
|
||||
if (!widgets.contains(surf.m_outputID)) {
|
||||
auto CWIDGETS = g_pConfigManager->getWidgetConfigs();
|
||||
|
||||
std::sort(CWIDGETS.begin(), CWIDGETS.end(), [](CConfigManager::SWidgetConfig& a, CConfigManager::SWidgetConfig& b) {
|
||||
std::ranges::sort(CWIDGETS, [](CConfigManager::SWidgetConfig& a, CConfigManager::SWidgetConfig& b) {
|
||||
return std::any_cast<Hyprlang::INT>(a.values.at("zindex")) < std::any_cast<Hyprlang::INT>(b.values.at("zindex"));
|
||||
});
|
||||
|
||||
const auto POUTPUT = surf.m_outputRef.lock();
|
||||
for (auto& c : CWIDGETS) {
|
||||
if (!c.monitor.empty() && c.monitor != surf->output->stringPort && !surf->output->stringDesc.starts_with(c.monitor) &&
|
||||
!surf->output->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
|
||||
if (c.type == "background") {
|
||||
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
std::string resourceID = "";
|
||||
if (PATH == "screenshot") {
|
||||
resourceID = CDMAFrame::getResourceId(surf->output);
|
||||
// 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 (asyncResourceGatherer->gathered) {
|
||||
if (!asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = ""; // Fallback to solid color (background:color)
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
} else if (!PATH.empty())
|
||||
resourceID = "background:" + PATH;
|
||||
|
||||
widgets[surf].emplace_back(std::make_unique<CBackground>(surf->size, surf->output, resourceID, c.values, PATH == "screenshot"));
|
||||
createWidget<CBackground>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "input-field") {
|
||||
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values, surf->output->stringPort));
|
||||
createWidget<CPasswordInputField>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "label") {
|
||||
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values, surf->output->stringPort));
|
||||
createWidget<CLabel>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "shape") {
|
||||
widgets[surf].emplace_back(std::make_unique<CShape>(surf->size, c.values));
|
||||
createWidget<CShape>(widgets[surf.m_outputID]);
|
||||
} else if (c.type == "image") {
|
||||
const std::string PATH = std::any_cast<Hyprlang::STRING>(c.values.at("path"));
|
||||
|
||||
std::string resourceID = "";
|
||||
if (!PATH.empty())
|
||||
resourceID = "image:" + PATH;
|
||||
|
||||
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values));
|
||||
createWidget<CImage>(widgets[surf.m_outputID]);
|
||||
} else {
|
||||
Debug::log(ERR, "Unknown widget type: {}", c.type);
|
||||
continue;
|
||||
}
|
||||
|
||||
widgets[surf.m_outputID].back()->configure(c.values, POUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
return &widgets[surf];
|
||||
return widgets[surf.m_outputID];
|
||||
}
|
||||
|
||||
void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) {
|
||||
|
@ -635,6 +595,30 @@ void CRenderer::popFb() {
|
|||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, boundFBs.empty() ? 0 : boundFBs.back());
|
||||
}
|
||||
|
||||
void CRenderer::removeWidgetsFor(const CSessionLockSurface* surf) {
|
||||
widgets.erase(surf);
|
||||
}
|
||||
void CRenderer::removeWidgetsFor(OUTPUTID id) {
|
||||
widgets.erase(id);
|
||||
}
|
||||
|
||||
void CRenderer::reconfigureWidgetsFor(OUTPUTID id) {
|
||||
// TODO: reconfigure widgets by just calling their configure method again.
|
||||
// Requires a way to get a widgets config properties.
|
||||
// I think the best way would be to store the anonymos key of the widget config.
|
||||
removeWidgetsFor(id);
|
||||
}
|
||||
|
||||
void CRenderer::startFadeIn() {
|
||||
Debug::log(LOG, "Starting fade in");
|
||||
*opacity = 1.f;
|
||||
|
||||
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;
|
||||
|
||||
if (unlock)
|
||||
opacity->setCallbackOnEnd([](auto) { g_pHyprlock->releaseSessionLock(); }, true);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include "Shader.hpp"
|
||||
#include "../defines.hpp"
|
||||
#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<const CSessionLockSurface*, std::vector<std::unique_ptr<IWidget>>> widgetMap_t;
|
||||
typedef std::unordered_map<OUTPUTID, std::vector<SP<IWidget>>> widgetMap_t;
|
||||
|
||||
class CRenderer {
|
||||
public:
|
||||
|
@ -22,46 +23,51 @@ class CRenderer {
|
|||
};
|
||||
|
||||
struct SBlurParams {
|
||||
int size = 0, passes = 0;
|
||||
float noise = 0, contrast = 0, brightness = 0, vibrancy = 0, vibrancy_darkness = 0;
|
||||
std::optional<CColor> colorize;
|
||||
float boostA = 1.0;
|
||||
int size = 0, passes = 0;
|
||||
float noise = 0, contrast = 0, brightness = 0, vibrancy = 0, vibrancy_darkness = 0;
|
||||
std::optional<CHyprColor> colorize;
|
||||
float boostA = 1.0;
|
||||
};
|
||||
|
||||
SRenderFeedback renderLock(const CSessionLockSurface& surface);
|
||||
SRenderFeedback renderLock(const CSessionLockSurface& surf);
|
||||
|
||||
void renderRect(const CBox& box, const CColor& col, int rounding = 0);
|
||||
void renderRect(const CBox& box, const CHyprColor& col, int rounding = 0);
|
||||
void renderBorder(const CBox& box, const CGradientValueData& gradient, int thickness, int rounding = 0, float alpha = 1.0);
|
||||
void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
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);
|
||||
|
||||
std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
UP<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
|
||||
void pushFb(GLint fb);
|
||||
void popFb();
|
||||
void pushFb(GLint fb);
|
||||
void popFb();
|
||||
|
||||
void removeWidgetsFor(const CSessionLockSurface* surf);
|
||||
void removeWidgetsFor(OUTPUTID id);
|
||||
void reconfigureWidgetsFor(OUTPUTID id);
|
||||
|
||||
void startFadeIn();
|
||||
void startFadeOut(bool unlock = false, bool immediate = true);
|
||||
std::vector<SP<IWidget>>& getOrCreateWidgetsFor(const CSessionLockSurface& surf);
|
||||
|
||||
private:
|
||||
widgetMap_t widgets;
|
||||
widgetMap_t widgets;
|
||||
|
||||
std::vector<std::unique_ptr<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;
|
||||
|
||||
std::vector<GLint> boundFBs;
|
||||
std::vector<GLint> boundFBs;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CRenderer> g_pRenderer;
|
||||
inline UP<CRenderer> g_pRenderer;
|
||||
|
|
475
src/renderer/Screencopy.cpp
Normal file
475
src/renderer/Screencopy.cpp
Normal file
|
@ -0,0 +1,475 @@
|
|||
#include "Screencopy.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
#include "../core/hyprlock.hpp"
|
||||
#include "../core/Egl.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "wlr-screencopy-unstable-v1.hpp"
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <gbm.h>
|
||||
#include <hyprutils/memory/UniquePtr.hpp>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <libdrm/drm_fourcc.h>
|
||||
#include <GLES3/gl32.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullptr;
|
||||
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();
|
||||
|
||||
static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode");
|
||||
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);
|
||||
|
||||
if (!m_frame || !m_frame->onBufferDone() || !m_frame->m_wlBuffer) {
|
||||
Debug::log(ERR, "[sc] Failed to create a wayland buffer for the screencopy frame");
|
||||
return;
|
||||
}
|
||||
|
||||
m_sc->sendCopy(m_frame->m_wlBuffer->resource());
|
||||
|
||||
Debug::log(TRACE, "[sc] wlr frame copied");
|
||||
});
|
||||
|
||||
m_sc->setFailed([this](CCZwlrScreencopyFrameV1* r) {
|
||||
Debug::log(ERR, "[sc] wlrOnFailed for {}", (void*)r);
|
||||
|
||||
m_frame.reset();
|
||||
});
|
||||
|
||||
m_sc->setReady([this](CCZwlrScreencopyFrameV1* r, uint32_t, uint32_t, uint32_t) {
|
||||
Debug::log(TRACE, "[sc] wlrOnReady for {}", (void*)this);
|
||||
|
||||
if (!m_frame || !m_frame->onBufferReady(m_asset)) {
|
||||
Debug::log(ERR, "[sc] Failed to bind the screencopy buffer to a texture");
|
||||
return;
|
||||
}
|
||||
|
||||
m_sc.reset();
|
||||
});
|
||||
}
|
||||
|
||||
CSCDMAFrame::CSCDMAFrame(SP<CCZwlrScreencopyFrameV1> sc) : m_sc(sc) {
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
||||
if (!glEGLImageTargetTexture2DOES) {
|
||||
Debug::log(ERR, "No glEGLImageTargetTexture2DOES??");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!eglQueryDmaBufModifiersEXT)
|
||||
eglQueryDmaBufModifiersEXT = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC)eglGetProcAddress("eglQueryDmaBufModifiersEXT");
|
||||
|
||||
m_sc->setLinuxDmabuf([this](CCZwlrScreencopyFrameV1* r, uint32_t format, uint32_t width, uint32_t height) {
|
||||
Debug::log(TRACE, "[sc] wlrOnDmabuf for {}", (void*)this);
|
||||
|
||||
m_w = width;
|
||||
m_h = height;
|
||||
m_fmt = format;
|
||||
|
||||
Debug::log(TRACE, "[sc] DMABUF format reported: {:x}", format);
|
||||
});
|
||||
|
||||
m_sc->setBuffer([](CCZwlrScreencopyFrameV1* r, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
||||
; // unused by dma
|
||||
});
|
||||
}
|
||||
|
||||
CSCDMAFrame::~CSCDMAFrame() {
|
||||
if (g_pEGL)
|
||||
eglDestroyImage(g_pEGL->eglDisplay, m_image);
|
||||
|
||||
// leaks bo and stuff but lives throughout so for now who cares
|
||||
}
|
||||
|
||||
bool CSCDMAFrame::onBufferDone() {
|
||||
uint32_t flags = GBM_BO_USE_RENDERING;
|
||||
|
||||
if (!eglQueryDmaBufModifiersEXT) {
|
||||
Debug::log(WARN, "Querying modifiers without eglQueryDmaBufModifiersEXT support");
|
||||
m_bo = gbm_bo_create(g_pHyprlock->dma.gbmDevice, m_w, m_h, m_fmt, flags);
|
||||
} else {
|
||||
std::array<uint64_t, 64> mods;
|
||||
std::array<EGLBoolean, 64> externalOnly;
|
||||
int num = 0;
|
||||
if (!eglQueryDmaBufModifiersEXT(g_pEGL->eglDisplay, m_fmt, 64, mods.data(), externalOnly.data(), &num) || num == 0) {
|
||||
Debug::log(WARN, "eglQueryDmaBufModifiersEXT failed, falling back to regular bo");
|
||||
m_bo = gbm_bo_create(g_pHyprlock->dma.gbmDevice, m_w, m_h, m_fmt, flags);
|
||||
} else {
|
||||
Debug::log(LOG, "eglQueryDmaBufModifiersEXT found {} mods", num);
|
||||
std::vector<uint64_t> goodMods;
|
||||
for (int i = 0; i < num; ++i) {
|
||||
if (externalOnly[i]) {
|
||||
Debug::log(TRACE, "Modifier {:x} failed test", mods[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
Debug::log(TRACE, "Modifier {:x} passed test", mods[i]);
|
||||
goodMods.emplace_back(mods[i]);
|
||||
}
|
||||
|
||||
m_bo = gbm_bo_create_with_modifiers2(g_pHyprlock->dma.gbmDevice, m_w, m_h, m_fmt, goodMods.data(), goodMods.size(), flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_bo) {
|
||||
Debug::log(ERR, "[bo] Couldn't create a drm buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_planes = gbm_bo_get_plane_count(m_bo);
|
||||
Debug::log(LOG, "[bo] has {} plane(s)", m_planes);
|
||||
|
||||
m_mod = gbm_bo_get_modifier(m_bo);
|
||||
Debug::log(LOG, "[bo] chose modifier {:x}", m_mod);
|
||||
|
||||
auto params = makeShared<CCZwpLinuxBufferParamsV1>(g_pHyprlock->dma.linuxDmabuf->sendCreateParams());
|
||||
if (!params) {
|
||||
Debug::log(ERR, "zwp_linux_dmabuf_v1_create_params failed");
|
||||
gbm_bo_destroy(m_bo);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t plane = 0; plane < (size_t)m_planes; plane++) {
|
||||
m_stride[plane] = gbm_bo_get_stride_for_plane(m_bo, plane);
|
||||
m_offset[plane] = gbm_bo_get_offset(m_bo, plane);
|
||||
m_fd[plane] = gbm_bo_get_fd_for_plane(m_bo, plane);
|
||||
|
||||
if (m_fd[plane] < 0) {
|
||||
Debug::log(ERR, "gbm_m_bo_get_fd_for_plane failed");
|
||||
params.reset();
|
||||
gbm_bo_destroy(m_bo);
|
||||
for (size_t plane_tmp = 0; plane_tmp < plane; plane_tmp++) {
|
||||
close(m_fd[plane_tmp]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
params->sendAdd(m_fd[plane], plane, m_offset[plane], m_stride[plane], m_mod >> 32, m_mod & 0xffffffff);
|
||||
}
|
||||
|
||||
m_wlBuffer = makeShared<CCWlBuffer>(params->sendCreateImmed(m_w, m_h, m_fmt, (zwpLinuxBufferParamsV1Flags)0));
|
||||
params.reset();
|
||||
|
||||
if (!m_wlBuffer) {
|
||||
Debug::log(ERR, "[pw] zwp_linux_buffer_params_v1_create_immed failed");
|
||||
gbm_bo_destroy(m_bo);
|
||||
for (size_t plane = 0; plane < (size_t)m_planes; plane++)
|
||||
close(m_fd[plane]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSCDMAFrame::onBufferReady(SPreloadedAsset& asset) {
|
||||
static constexpr struct {
|
||||
EGLAttrib fd;
|
||||
EGLAttrib offset;
|
||||
EGLAttrib pitch;
|
||||
EGLAttrib modlo;
|
||||
EGLAttrib modhi;
|
||||
} attrNames[4] = {{.fd = EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE1_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE2_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE3_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}};
|
||||
|
||||
std::vector<EGLAttrib> attribs = {
|
||||
EGL_WIDTH, m_w, EGL_HEIGHT, m_h, EGL_LINUX_DRM_FOURCC_EXT, m_fmt,
|
||||
};
|
||||
for (int i = 0; i < m_planes; i++) {
|
||||
attribs.emplace_back(attrNames[i].fd);
|
||||
attribs.emplace_back(m_fd[i]);
|
||||
attribs.emplace_back(attrNames[i].offset);
|
||||
attribs.emplace_back(m_offset[i]);
|
||||
attribs.emplace_back(attrNames[i].pitch);
|
||||
attribs.emplace_back(m_stride[i]);
|
||||
if (m_mod != DRM_FORMAT_MOD_INVALID) {
|
||||
attribs.emplace_back(attrNames[i].modlo);
|
||||
attribs.emplace_back(m_mod & 0xFFFFFFFF);
|
||||
attribs.emplace_back(attrNames[i].modhi);
|
||||
attribs.emplace_back(m_mod >> 32);
|
||||
}
|
||||
}
|
||||
attribs.emplace_back(EGL_NONE);
|
||||
|
||||
m_image = eglCreateImage(g_pEGL->eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, attribs.data());
|
||||
|
||||
if (m_image == EGL_NO_IMAGE) {
|
||||
Debug::log(ERR, "Failed creating an egl image");
|
||||
return false;
|
||||
}
|
||||
|
||||
asset.texture.allocate();
|
||||
asset.texture.m_vSize = {m_w, m_h};
|
||||
glBindTexture(GL_TEXTURE_2D, asset.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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CSCSHMFrame::CSCSHMFrame(SP<CCZwlrScreencopyFrameV1> sc) : m_sc(sc) {
|
||||
Debug::log(TRACE, "[sc] [shm] Creating a SHM frame");
|
||||
|
||||
m_sc->setBuffer([this](CCZwlrScreencopyFrameV1* r, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
||||
Debug::log(TRACE, "[sc] [shm] wlrOnBuffer for {}", (void*)this);
|
||||
|
||||
const auto SIZE = stride * height;
|
||||
m_shmFmt = format;
|
||||
m_w = width;
|
||||
m_h = height;
|
||||
m_stride = stride;
|
||||
|
||||
// Create a shm pool with format and size
|
||||
std::string shmPoolFile;
|
||||
const auto FD = createPoolFile(SIZE, shmPoolFile);
|
||||
|
||||
if (FD < 0) {
|
||||
Debug::log(ERR, "[sc] [shm] failed to create a pool file");
|
||||
return;
|
||||
}
|
||||
|
||||
m_shmData = mmap(nullptr, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, FD, 0);
|
||||
if (m_shmData == MAP_FAILED) {
|
||||
Debug::log(ERR, "[sc] [shm] failed to (errno {})", strerror(errno));
|
||||
close(FD);
|
||||
m_ok = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getShm()) {
|
||||
Debug::log(ERR, "[sc] [shm] Failed to get WLShm global");
|
||||
close(FD);
|
||||
m_ok = false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto pShmPool = makeShared<CCWlShmPool>(g_pHyprlock->getShm()->sendCreatePool(FD, SIZE));
|
||||
m_wlBuffer = makeShared<CCWlBuffer>(pShmPool->sendCreateBuffer(0, width, height, stride, m_shmFmt));
|
||||
|
||||
pShmPool.reset();
|
||||
|
||||
close(FD);
|
||||
});
|
||||
|
||||
m_sc->setLinuxDmabuf([](CCZwlrScreencopyFrameV1* r, uint32_t, uint32_t, uint32_t) {
|
||||
; // unused by scshm
|
||||
});
|
||||
}
|
||||
|
||||
CSCSHMFrame::~CSCSHMFrame() {
|
||||
if (m_convBuffer)
|
||||
free(m_convBuffer);
|
||||
if (m_shmData)
|
||||
munmap(m_shmData, m_stride * m_h);
|
||||
}
|
||||
|
||||
void CSCSHMFrame::convertBuffer() {
|
||||
const auto BYTESPERPX = m_stride / m_w;
|
||||
if (BYTESPERPX == 4) {
|
||||
switch (m_shmFmt) {
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
case WL_SHM_FORMAT_XRGB8888: {
|
||||
Debug::log(LOG, "[sc] [shm] Converting ARGB to RGBA");
|
||||
uint8_t* data = (uint8_t*)m_shmData;
|
||||
|
||||
for (uint32_t y = 0; y < m_h; ++y) {
|
||||
for (uint32_t x = 0; x < m_w; ++x) {
|
||||
struct pixel {
|
||||
// little-endian ARGB
|
||||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* px = (struct pixel*)(data + (y * m_w * 4) + (x * 4));
|
||||
|
||||
// RGBA
|
||||
*px = {.blue = px->red, .green = px->green, .red = px->blue, .alpha = px->alpha};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case WL_SHM_FORMAT_ABGR8888:
|
||||
case WL_SHM_FORMAT_XBGR8888: {
|
||||
Debug::log(LOG, "[sc] [shm] Converting ABGR to RGBA");
|
||||
uint8_t* data = (uint8_t*)m_shmData;
|
||||
|
||||
for (uint32_t y = 0; y < m_h; ++y) {
|
||||
for (uint32_t x = 0; x < m_w; ++x) {
|
||||
struct pixel {
|
||||
// little-endian ARGB
|
||||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* px = (struct pixel*)(data + (y * m_w * 4) + (x * 4));
|
||||
|
||||
// BGRA
|
||||
*px = {.blue = px->blue, .green = px->green, .red = px->red, .alpha = px->alpha};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case WL_SHM_FORMAT_ABGR2101010:
|
||||
case WL_SHM_FORMAT_ARGB2101010:
|
||||
case WL_SHM_FORMAT_XRGB2101010:
|
||||
case WL_SHM_FORMAT_XBGR2101010: {
|
||||
Debug::log(LOG, "[sc] [shm] Converting 10-bit channels to 8-bit");
|
||||
uint8_t* data = (uint8_t*)m_shmData;
|
||||
|
||||
const bool FLIP = m_shmFmt != WL_SHM_FORMAT_XBGR2101010;
|
||||
|
||||
for (uint32_t y = 0; y < m_h; ++y) {
|
||||
for (uint32_t x = 0; x < m_w; ++x) {
|
||||
uint32_t* px = (uint32_t*)(data + (y * m_w * 4) + (x * 4));
|
||||
|
||||
// conv to 8 bit
|
||||
uint8_t R = (uint8_t)std::round((255.0 * (((*px) & 0b00000000000000000000001111111111) >> 0) / 1023.0));
|
||||
uint8_t G = (uint8_t)std::round((255.0 * (((*px) & 0b00000000000011111111110000000000) >> 10) / 1023.0));
|
||||
uint8_t B = (uint8_t)std::round((255.0 * (((*px) & 0b00111111111100000000000000000000) >> 20) / 1023.0));
|
||||
uint8_t A = (uint8_t)std::round((255.0 * (((*px) & 0b11000000000000000000000000000000) >> 30) / 3.0));
|
||||
|
||||
// write 8-bit values
|
||||
*px = ((FLIP ? B : R) << 0) + (G << 8) + ((FLIP ? R : B) << 16) + (A << 24);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
Debug::log(WARN, "[sc] [shm] Unsupported format {}", m_shmFmt);
|
||||
}
|
||||
}
|
||||
} else if (BYTESPERPX == 3) {
|
||||
Debug::log(LOG, "[sc] [shm] Converting 24 bit to 32 bit");
|
||||
m_convBuffer = malloc(m_w * m_h * 4);
|
||||
const int NEWSTRIDE = m_w * 4;
|
||||
RASSERT(m_convBuffer, "malloc failed");
|
||||
|
||||
switch (m_shmFmt) {
|
||||
case WL_SHM_FORMAT_BGR888: {
|
||||
Debug::log(LOG, "[sc] [shm] Converting BGR to RGBA");
|
||||
for (uint32_t y = 0; y < m_h; ++y) {
|
||||
for (uint32_t x = 0; x < m_w; ++x) {
|
||||
struct pixel3 {
|
||||
// little-endian RGB
|
||||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
}* srcPx = (struct pixel3*)((char*)m_shmData + (y * m_stride) + (x * 3));
|
||||
struct pixel4 {
|
||||
// little-endian ARGB
|
||||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* dstPx = (struct pixel4*)((char*)m_convBuffer + (y * NEWSTRIDE) + (x * 4));
|
||||
*dstPx = {.blue = srcPx->blue, .green = srcPx->green, .red = srcPx->red, .alpha = 0xFF};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case WL_SHM_FORMAT_RGB888: {
|
||||
Debug::log(LOG, "[sc] [shm] Converting RGB to RGBA");
|
||||
for (uint32_t y = 0; y < m_h; ++y) {
|
||||
for (uint32_t x = 0; x < m_w; ++x) {
|
||||
struct pixel3 {
|
||||
// big-endian RGB
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
}* srcPx = (struct pixel3*)((char*)m_shmData + (y * m_stride) + (x * 3));
|
||||
struct pixel4 {
|
||||
// big-endian ARGB
|
||||
unsigned char alpha;
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
}* dstPx = (struct pixel4*)((char*)m_convBuffer + (y * NEWSTRIDE) + (x * 4));
|
||||
*dstPx = {.alpha = srcPx->red, .red = srcPx->green, .green = srcPx->blue, .blue = 0xFF};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
Debug::log(ERR, "[sc] [shm] Unsupported format for 24bit buffer {}", m_shmFmt);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Debug::log(ERR, "[sc] [shm] Unsupported bytes per pixel {}", BYTESPERPX);
|
||||
}
|
||||
}
|
||||
|
||||
bool CSCSHMFrame::onBufferReady(SPreloadedAsset& asset) {
|
||||
convertBuffer();
|
||||
|
||||
asset.texture.allocate();
|
||||
asset.texture.m_vSize.x = m_w;
|
||||
asset.texture.m_vSize.y = m_h;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, asset.texture.m_iTexID);
|
||||
|
||||
void* buffer = m_convBuffer ? m_convBuffer : m_shmData;
|
||||
|
||||
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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
94
src/renderer/Screencopy.hpp
Normal file
94
src/renderer/Screencopy.hpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../core/Output.hpp"
|
||||
#include <cstdint>
|
||||
#include <gbm.h>
|
||||
#include <memory>
|
||||
#include "Shared.hpp"
|
||||
#include "linux-dmabuf-v1.hpp"
|
||||
#include "wlr-screencopy-unstable-v1.hpp"
|
||||
|
||||
class ISCFrame {
|
||||
public:
|
||||
ISCFrame() = default;
|
||||
virtual ~ISCFrame() = default;
|
||||
|
||||
virtual bool onBufferDone() = 0;
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset) = 0;
|
||||
|
||||
SP<CCWlBuffer> m_wlBuffer = nullptr;
|
||||
};
|
||||
|
||||
class CScreencopyFrame {
|
||||
public:
|
||||
static std::string getResourceId(SP<COutput> pOutput);
|
||||
|
||||
CScreencopyFrame(SP<COutput> pOutput);
|
||||
~CScreencopyFrame() = default;
|
||||
|
||||
void captureOutput();
|
||||
|
||||
SP<CCZwlrScreencopyFrameV1> m_sc = nullptr;
|
||||
|
||||
std::string m_resourceID;
|
||||
SPreloadedAsset m_asset;
|
||||
|
||||
private:
|
||||
WP<COutput> m_outputRef;
|
||||
UP<ISCFrame> m_frame = nullptr;
|
||||
|
||||
bool m_dmaFailed = false;
|
||||
};
|
||||
|
||||
// Uses a gpu buffer created via gbm_bo
|
||||
class CSCDMAFrame : public ISCFrame {
|
||||
public:
|
||||
CSCDMAFrame(SP<CCZwlrScreencopyFrameV1> sc);
|
||||
virtual ~CSCDMAFrame();
|
||||
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset);
|
||||
virtual bool onBufferDone();
|
||||
|
||||
private:
|
||||
gbm_bo* m_bo = nullptr;
|
||||
|
||||
int m_planes = 0;
|
||||
uint64_t m_mod = 0;
|
||||
|
||||
int m_fd[4];
|
||||
uint32_t m_stride[4], m_offset[4];
|
||||
|
||||
int m_w = 0, m_h = 0;
|
||||
uint32_t m_fmt = 0;
|
||||
|
||||
SP<CCZwlrScreencopyFrameV1> m_sc = nullptr;
|
||||
|
||||
EGLImage m_image = nullptr;
|
||||
};
|
||||
|
||||
// Uses a shm buffer - is slow and needs ugly format conversion
|
||||
// Used as a fallback just in case.
|
||||
class CSCSHMFrame : public ISCFrame {
|
||||
public:
|
||||
CSCSHMFrame(SP<CCZwlrScreencopyFrameV1> sc);
|
||||
virtual ~CSCSHMFrame();
|
||||
|
||||
virtual bool onBufferDone() {
|
||||
return m_ok;
|
||||
}
|
||||
virtual bool onBufferReady(SPreloadedAsset& asset);
|
||||
void convertBuffer();
|
||||
|
||||
private:
|
||||
bool m_ok = true;
|
||||
|
||||
uint32_t m_w = 0, m_h = 0;
|
||||
uint32_t m_stride = 0;
|
||||
|
||||
SP<CCZwlrScreencopyFrameV1> m_sc = nullptr;
|
||||
|
||||
uint32_t m_shmFmt = 0;
|
||||
void* m_shmData = nullptr;
|
||||
void* m_convBuffer = nullptr;
|
||||
};
|
|
@ -41,9 +41,13 @@ class CShader {
|
|||
GLint applyTint = -1;
|
||||
GLint tint = -1;
|
||||
|
||||
GLint gradient = -1;
|
||||
GLint gradientLength = -1;
|
||||
GLint angle = -1;
|
||||
GLint gradient = -1;
|
||||
GLint gradientLength = -1;
|
||||
GLint gradient2 = -1;
|
||||
GLint gradient2Length = -1;
|
||||
GLint gradientLerp = -1;
|
||||
GLint angle = -1;
|
||||
GLint angle2 = -1;
|
||||
|
||||
GLint time = -1;
|
||||
GLint distort = -1;
|
||||
|
|
|
@ -427,12 +427,32 @@ uniform float radius;
|
|||
uniform float radiusOuter;
|
||||
uniform float thick;
|
||||
|
||||
// Gradients are in OkLabA!!!! {l, a, b, alpha}
|
||||
uniform vec4 gradient[10];
|
||||
uniform vec4 gradient2[10];
|
||||
uniform int gradientLength;
|
||||
uniform int gradient2Length;
|
||||
uniform float angle;
|
||||
uniform float angle2;
|
||||
uniform float gradientLerp;
|
||||
uniform float alpha;
|
||||
|
||||
vec4 getColorForCoord(vec2 normalizedCoord) {
|
||||
float linearToGamma(float x) {
|
||||
return x >= 0.0031308 ? 1.055 * pow(x, 0.416666666) - 0.055 : 12.92 * x;
|
||||
}
|
||||
|
||||
vec4 okLabAToSrgb(vec4 lab) {
|
||||
float l = pow(lab[0] + lab[1] * 0.3963377774 + lab[2] * 0.2158037573, 3.0);
|
||||
float m = pow(lab[0] + lab[1] * (-0.1055613458) + lab[2] * (-0.0638541728), 3.0);
|
||||
float s = pow(lab[0] + lab[1] * (-0.0894841775) + lab[2] * (-1.2914855480), 3.0);
|
||||
|
||||
return vec4(linearToGamma(l * 4.0767416621 + m * -3.3077115913 + s * 0.2309699292),
|
||||
linearToGamma(l * (-1.2684380046) + m * 2.6097574011 + s * (-0.3413193965)),
|
||||
linearToGamma(l * (-0.0041960863) + m * (-0.7034186147) + s * 1.7076147010),
|
||||
lab[3]);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray1(vec2 normalizedCoord) {
|
||||
if (gradientLength < 2)
|
||||
return gradient[0];
|
||||
|
||||
|
@ -461,6 +481,46 @@ vec4 getColorForCoord(vec2 normalizedCoord) {
|
|||
return gradient[top] * (progress - float(bottom)) + gradient[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray2(vec2 normalizedCoord) {
|
||||
if (gradient2Length < 2)
|
||||
return gradient2[0];
|
||||
|
||||
float finalAng = 0.0;
|
||||
|
||||
if (angle2 > 4.71 /* 270 deg */) {
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = 6.28 - angle;
|
||||
} else if (angle2 > 3.14 /* 180 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = angle - 3.14;
|
||||
} else if (angle2 > 1.57 /* 90 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
finalAng = 3.14 - angle2;
|
||||
} else {
|
||||
finalAng = angle2;
|
||||
}
|
||||
|
||||
float sine = sin(finalAng);
|
||||
|
||||
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradient2Length - 1);
|
||||
int bottom = int(floor(progress));
|
||||
int top = bottom + 1;
|
||||
|
||||
return gradient2[top] * (progress - float(bottom)) + gradient2[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getColorForCoord(vec2 normalizedCoord) {
|
||||
vec4 result1 = getOkColorForCoordArray1(normalizedCoord);
|
||||
|
||||
if (gradient2Length <= 0)
|
||||
return okLabAToSrgb(result1);
|
||||
|
||||
vec4 result2 = getOkColorForCoordArray2(normalizedCoord);
|
||||
|
||||
return okLabAToSrgb(mix(result1, result2, gradientLerp));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
highp vec2 pixCoord = vec2(gl_FragCoord);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Texture.hpp"
|
||||
|
||||
CTexture::CTexture() {
|
||||
// naffin'
|
||||
; // naffin'
|
||||
}
|
||||
|
||||
CTexture::~CTexture() {
|
||||
|
@ -20,4 +20,4 @@ void CTexture::allocate() {
|
|||
if (!m_bAllocated)
|
||||
glGenTextures(1, &m_iTexID);
|
||||
m_bAllocated = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,23 +10,15 @@
|
|||
#include <GLES3/gl32.h>
|
||||
|
||||
CBackground::~CBackground() {
|
||||
|
||||
if (reloadTimer) {
|
||||
reloadTimer->cancel();
|
||||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
fade.reset();
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std::string& resourceID_, const std::unordered_map<std::string, std::any>& props, bool ss) :
|
||||
viewport(viewport_), resourceID(resourceID_), output(output_), isScreenshot(ss) {
|
||||
void CBackground::registerSelf(const SP<CBackground>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CBackground::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
try {
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
|
@ -48,6 +40,29 @@ CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std:
|
|||
RASSERT(false, "Missing propperty for CBackground: {}", e.what()); //
|
||||
}
|
||||
|
||||
isScreenshot = path == "screenshot";
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = isScreenshot ? wlTransformToHyprutils(invertTransform(pOutput->transform)) : HYPRUTILS_TRANSFORM_NORMAL;
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
} else if (!path.empty())
|
||||
resourceID = "background:" + path;
|
||||
|
||||
if (!isScreenshot && reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
|
@ -57,36 +72,47 @@ CBackground::CBackground(const Vector2D& viewport_, COutput* output_, const std:
|
|||
}
|
||||
}
|
||||
|
||||
void CBackground::renderRect(CColor color) {
|
||||
void CBackground::reset() {
|
||||
if (reloadTimer) {
|
||||
reloadTimer->cancel();
|
||||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
fade.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CBackground::renderRect(CHyprColor color) {
|
||||
CBox monbox = {0, 0, viewport.x, viewport.y};
|
||||
g_pRenderer->renderRect(monbox, color, 0);
|
||||
}
|
||||
|
||||
static void onReloadTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
static void onReloadTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG) {
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onCrossFadeTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
static void onCrossFadeTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PBG = (CBackground*)data;
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty()) {
|
||||
CColor col = color;
|
||||
CHyprColor col = color;
|
||||
col.a *= data.opacity;
|
||||
renderRect(col);
|
||||
return data.opacity < 1.0;
|
||||
|
@ -96,7 +122,7 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
|
||||
if (!asset) {
|
||||
CColor col = color;
|
||||
CHyprColor col = color;
|
||||
col.a *= data.opacity;
|
||||
renderRect(col);
|
||||
return true;
|
||||
|
@ -115,7 +141,7 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
|
||||
// make it brah
|
||||
Vector2D size = asset->texture.m_vSize;
|
||||
if (output->transform % 2 == 1 && isScreenshot) {
|
||||
if (transform % 2 == 1 && isScreenshot) {
|
||||
size.x = asset->texture.m_vSize.y;
|
||||
size.y = asset->texture.m_vSize.x;
|
||||
}
|
||||
|
@ -142,15 +168,19 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
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,
|
||||
HYPRUTILS_TRANSFORM_NORMAL);
|
||||
transform);
|
||||
else
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0,
|
||||
isScreenshot ?
|
||||
wlTransformToHyprutils(invertTransform(output->transform)) :
|
||||
HYPRUTILS_TRANSFORM_NORMAL); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs
|
||||
g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0, transform);
|
||||
|
||||
if (blurPasses > 0)
|
||||
g_pRenderer->blurFB(blurredFB, CRenderer::SBlurParams{blurSize, blurPasses, noise, contrast, brightness, vibrancy, vibrancy_darkness});
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -178,9 +208,9 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
void CBackground::plantReloadTimer() {
|
||||
|
||||
if (reloadTime == 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onReloadTimer, this, true);
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
else if (reloadTime > 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), onReloadTimer, this, false);
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
}
|
||||
|
||||
void CBackground::onCrossFadeTimerUpdate() {
|
||||
|
@ -189,10 +219,10 @@ void CBackground::onCrossFadeTimerUpdate() {
|
|||
|
||||
if (fade) {
|
||||
fade->crossFadeTimer.reset();
|
||||
fade.reset(nullptr);
|
||||
fade.reset();
|
||||
}
|
||||
|
||||
if (!(blurPasses > 0 || isScreenshot))
|
||||
if (blurPasses <= 0 && !isScreenshot)
|
||||
blurredFB.release();
|
||||
|
||||
asset = pendingAsset;
|
||||
|
@ -201,7 +231,7 @@ void CBackground::onCrossFadeTimerUpdate() {
|
|||
pendingAsset = nullptr;
|
||||
firstRender = true;
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
||||
void CBackground::onReloadTimerUpdate() {
|
||||
|
@ -210,7 +240,7 @@ void CBackground::onReloadTimerUpdate() {
|
|||
// Path parsing and early returns
|
||||
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
path = spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
@ -244,8 +274,7 @@ void CBackground::onReloadTimerUpdate() {
|
|||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
@ -261,7 +290,7 @@ void CBackground::startCrossFadeOrUpdateRender() {
|
|||
if (crossFadeTime > 0) {
|
||||
// Start a fade
|
||||
if (!fade)
|
||||
fade = std::make_unique<SFade>(std::chrono::system_clock::now(), 0, nullptr);
|
||||
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) {
|
||||
|
@ -269,17 +298,18 @@ void CBackground::startCrossFadeOrUpdateRender() {
|
|||
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)), onCrossFadeTimer, this);
|
||||
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), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
}
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../../core/Timer.hpp"
|
||||
#include "../Framebuffer.hpp"
|
||||
#include "../AsyncResourceGatherer.hpp"
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
@ -23,11 +24,17 @@ struct SFade {
|
|||
|
||||
class CBackground : public IWidget {
|
||||
public:
|
||||
CBackground(const Vector2D& viewport, COutput* output_, const std::string& resourceID, const std::unordered_map<std::string, std::any>& props, bool ss_);
|
||||
CBackground() = default;
|
||||
~CBackground();
|
||||
|
||||
void registerSelf(const SP<CBackground>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
void renderRect(CColor color);
|
||||
|
||||
void reset(); // Unload assets, remove timers, etc.
|
||||
|
||||
void renderRect(CHyprColor color);
|
||||
|
||||
void onReloadTimerUpdate();
|
||||
void onCrossFadeTimerUpdate();
|
||||
|
@ -35,6 +42,8 @@ class CBackground : public IWidget {
|
|||
void startCrossFadeOrUpdateRender();
|
||||
|
||||
private:
|
||||
WP<CBackground> m_self;
|
||||
|
||||
// if needed
|
||||
CFramebuffer blurredFB;
|
||||
|
||||
|
@ -48,23 +57,25 @@ class CBackground : public IWidget {
|
|||
Vector2D viewport;
|
||||
std::string path = "";
|
||||
|
||||
std::string outputPort;
|
||||
Hyprutils::Math::eTransform transform;
|
||||
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID;
|
||||
|
||||
float crossFadeTime = -1.0;
|
||||
|
||||
CColor color;
|
||||
CHyprColor color;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
COutput* output = nullptr;
|
||||
bool isScreenshot = false;
|
||||
SPreloadedAsset* pendingAsset = nullptr;
|
||||
bool firstRender = true;
|
||||
|
||||
std::unique_ptr<SFade> fade;
|
||||
UP<SFade> fade;
|
||||
|
||||
int reloadTime = -1;
|
||||
std::string reloadCommand;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
std::shared_ptr<CTimer> reloadTimer;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../auth/Auth.hpp"
|
||||
#include "../../auth/Fingerprint.hpp"
|
||||
#include <chrono>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
@ -17,14 +16,16 @@ using namespace Hyprutils::String;
|
|||
namespace std {
|
||||
namespace chrono {
|
||||
using date::current_zone;
|
||||
using date::locate_zone;
|
||||
using date::time_zone;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Vector2D rotateVector(const Vector2D& vec, const double& ang) {
|
||||
static Vector2D rotateVector(const Vector2D& vec, const double& ang) {
|
||||
const double COS = std::abs(std::cos(ang));
|
||||
const double SIN = std::abs(std::sin(ang));
|
||||
return Vector2D(vec.x * COS + vec.y * SIN, vec.x * SIN + vec.y * COS);
|
||||
return Vector2D((vec.x * COS) + (vec.y * SIN), (vec.x * SIN) + (vec.y * COS));
|
||||
}
|
||||
|
||||
Vector2D IWidget::posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign, const double& ang) {
|
||||
|
@ -77,7 +78,7 @@ int IWidget::roundingForBorderBox(const CBox& borderBox, int roundingConfig, int
|
|||
|
||||
static void replaceAllAttempts(std::string& str) {
|
||||
|
||||
const size_t ATTEMPTS = g_pAuth->m_iFailedAttempts;
|
||||
const size_t ATTEMPTS = g_pAuth->getFailedAttempts();
|
||||
const std::string STR = std::to_string(ATTEMPTS);
|
||||
size_t pos = 0;
|
||||
|
||||
|
@ -99,64 +100,74 @@ static void replaceAllAttempts(std::string& str) {
|
|||
}
|
||||
|
||||
static void replaceAllLayout(std::string& str) {
|
||||
std::string layoutName = "error";
|
||||
const auto LAYOUTIDX = g_pHyprlock->m_uiActiveLayout;
|
||||
|
||||
const auto LAYOUTIDX = g_pHyprlock->m_uiActiveLayout;
|
||||
const auto LAYOUTNAME = xkb_keymap_layout_get_name(g_pSeatManager->m_pXKBKeymap, LAYOUTIDX);
|
||||
const std::string STR = LAYOUTNAME ? LAYOUTNAME : "error";
|
||||
size_t pos = 0;
|
||||
if (g_pSeatManager->m_pXKBKeymap) {
|
||||
const auto PNAME = xkb_keymap_layout_get_name(g_pSeatManager->m_pXKBKeymap, LAYOUTIDX);
|
||||
if (PNAME)
|
||||
layoutName = PNAME;
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
while ((pos = str.find("$LAYOUT", pos)) != std::string::npos) {
|
||||
if (str.substr(pos, 8).ends_with('[') && str.substr(pos).contains(']')) {
|
||||
const std::string REPL = str.substr(pos + 8, str.find_first_of(']', pos) - 8 - pos);
|
||||
const CVarList LANGS(REPL);
|
||||
const std::string LANG = LANGS[LAYOUTIDX].empty() ? STR : LANGS[LAYOUTIDX] == "!" ? "" : LANGS[LAYOUTIDX];
|
||||
if (LAYOUTIDX >= LANGS.size()) {
|
||||
Debug::log(ERR, "Layout index {} out of bounds. Max is {}.", LAYOUTIDX, LANGS.size() - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string LANG = LANGS[LAYOUTIDX].empty() ? layoutName : LANGS[LAYOUTIDX] == "!" ? "" : LANGS[LAYOUTIDX];
|
||||
str.replace(pos, 9 + REPL.length(), LANG);
|
||||
pos += LANG.length();
|
||||
} else {
|
||||
str.replace(pos, 7, STR);
|
||||
pos += STR.length();
|
||||
str.replace(pos, 7, layoutName);
|
||||
pos += layoutName.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool logMissingTzOnce = true;
|
||||
static std::string getTime() {
|
||||
const auto PCURRENTTZ = std::chrono::current_zone();
|
||||
const auto TPNOW = std::chrono::system_clock::now();
|
||||
static bool logMissingTzOnce = true;
|
||||
static std::chrono::hh_mm_ss<std::chrono::system_clock::duration> getTime() {
|
||||
const std::chrono::time_zone* pCurrentTz = nullptr;
|
||||
try {
|
||||
auto name = std::getenv("TZ");
|
||||
if (name)
|
||||
pCurrentTz = std::chrono::locate_zone(name);
|
||||
} catch (std::runtime_error&) { Debug::log(WARN, "Invalid TZ value. Falling back to current timezone!"); }
|
||||
|
||||
if (!pCurrentTz)
|
||||
pCurrentTz = std::chrono::current_zone();
|
||||
|
||||
const auto TPNOW = std::chrono::system_clock::now();
|
||||
|
||||
//
|
||||
std::chrono::hh_mm_ss<std::chrono::system_clock::duration> hhmmss;
|
||||
if (!PCURRENTTZ) {
|
||||
if (!pCurrentTz) {
|
||||
if (logMissingTzOnce) {
|
||||
Debug::log(WARN, "Current timezone unknown for $TIME. Falling back to UTC!");
|
||||
Debug::log(WARN, "Current timezone unknown. Falling back to UTC!");
|
||||
logMissingTzOnce = false;
|
||||
}
|
||||
hhmmss = std::chrono::hh_mm_ss{TPNOW - std::chrono::floor<std::chrono::days>(TPNOW)};
|
||||
} else
|
||||
hhmmss = std::chrono::hh_mm_ss{PCURRENTTZ->to_local(TPNOW) - std::chrono::floor<std::chrono::days>(PCURRENTTZ->to_local(TPNOW))};
|
||||
hhmmss = std::chrono::hh_mm_ss{pCurrentTz->to_local(TPNOW) - std::chrono::floor<std::chrono::days>(pCurrentTz->to_local(TPNOW))};
|
||||
|
||||
const auto HRS = hhmmss.hours().count();
|
||||
const auto MINS = hhmmss.minutes().count();
|
||||
return hhmmss;
|
||||
}
|
||||
|
||||
static std::string getTime24h() {
|
||||
const auto HHMMSS = getTime();
|
||||
const auto HRS = HHMMSS.hours().count();
|
||||
const auto MINS = HHMMSS.minutes().count();
|
||||
return (HRS < 10 ? "0" : "") + std::to_string(HRS) + ":" + (MINS < 10 ? "0" : "") + std::to_string(MINS);
|
||||
}
|
||||
|
||||
static std::string getTime12h() {
|
||||
const auto PCURRENTTZ = std::chrono::current_zone();
|
||||
const auto TPNOW = std::chrono::system_clock::now();
|
||||
|
||||
//
|
||||
std::chrono::hh_mm_ss<std::chrono::system_clock::duration> hhmmss;
|
||||
if (!PCURRENTTZ) {
|
||||
if (logMissingTzOnce) {
|
||||
Debug::log(WARN, "Current timezone unknown for $TIME12. Falling back to UTC!");
|
||||
logMissingTzOnce = false;
|
||||
}
|
||||
hhmmss = std::chrono::hh_mm_ss{TPNOW - std::chrono::floor<std::chrono::days>(TPNOW)};
|
||||
} else
|
||||
hhmmss = std::chrono::hh_mm_ss{PCURRENTTZ->to_local(TPNOW) - std::chrono::floor<std::chrono::days>(PCURRENTTZ->to_local(TPNOW))};
|
||||
|
||||
const auto HRS = hhmmss.hours().count();
|
||||
const auto MINS = hhmmss.minutes().count();
|
||||
const auto HHMMSS = getTime();
|
||||
const auto HRS = HHMMSS.hours().count();
|
||||
const auto MINS = HHMMSS.minutes().count();
|
||||
return (HRS == 12 || HRS == 0 ? "12" : (HRS % 12 < 10 ? "0" : "") + std::to_string(HRS % 12)) + ":" + (MINS < 10 ? "0" : "") + std::to_string(MINS) +
|
||||
(HRS < 12 ? " AM" : " PM");
|
||||
}
|
||||
|
@ -184,22 +195,10 @@ IWidget::SFormatResult IWidget::formatString(std::string in) {
|
|||
}
|
||||
|
||||
if (in.contains("$TIME")) {
|
||||
replaceInString(in, "$TIME", getTime());
|
||||
replaceInString(in, "$TIME", getTime24h());
|
||||
result.updateEveryMs = result.updateEveryMs != 0 && result.updateEveryMs < 1000 ? result.updateEveryMs : 1000;
|
||||
}
|
||||
|
||||
if (in.contains("$FAIL")) {
|
||||
const auto FAIL = g_pAuth->getFailText(AUTH_IMPL_PAM);
|
||||
replaceInString(in, "$FAIL", FAIL.value_or(""));
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$PROMPT")) {
|
||||
const auto PROMPT = g_pAuth->getPrompt(AUTH_IMPL_PAM);
|
||||
replaceInString(in, "$PROMPT", PROMPT.value_or(""));
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$ATTEMPTS")) {
|
||||
replaceAllAttempts(in);
|
||||
result.allowForceUpdate = true;
|
||||
|
@ -210,9 +209,27 @@ IWidget::SFormatResult IWidget::formatString(std::string in) {
|
|||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$FPRINTMESSAGE")) {
|
||||
const auto FPRINTMESSAGE = g_pAuth->getFailText(AUTH_IMPL_FINGERPRINT);
|
||||
replaceInString(in, "$FPRINTMESSAGE", FPRINTMESSAGE.value_or(""));
|
||||
if (in.contains("$FAIL")) {
|
||||
const auto FAIL = g_pAuth->getCurrentFailText();
|
||||
replaceInString(in, "$FAIL", FAIL);
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$PAMFAIL")) {
|
||||
const auto FAIL = g_pAuth->getFailText(AUTH_IMPL_PAM);
|
||||
replaceInString(in, "$PAMFAIL", FAIL.value_or(""));
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$PAMPROMPT")) {
|
||||
const auto PROMPT = g_pAuth->getPrompt(AUTH_IMPL_PAM);
|
||||
replaceInString(in, "$PAMPROMPT", PROMPT.value_or(""));
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
if (in.contains("$FPRINTFAIL")) {
|
||||
const auto FPRINTFAIL = g_pAuth->getFailText(AUTH_IMPL_FINGERPRINT);
|
||||
replaceInString(in, "$FPRINTFAIL", FPRINTFAIL.value_or(""));
|
||||
result.allowForceUpdate = true;
|
||||
}
|
||||
|
||||
|
@ -249,3 +266,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,22 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/Math.hpp"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <any>
|
||||
|
||||
class COutput;
|
||||
|
||||
class IWidget {
|
||||
public:
|
||||
struct SRenderData {
|
||||
float opacity = 1;
|
||||
};
|
||||
|
||||
virtual ~IWidget() = default;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
float updateEveryMs = 0; // 0 means don't (static)
|
||||
|
@ -26,4 +40,10 @@ class IWidget {
|
|||
};
|
||||
|
||||
static SFormatResult formatString(std::string in);
|
||||
|
||||
void setHover(bool hover);
|
||||
bool isHovered() const;
|
||||
|
||||
private:
|
||||
bool hovered = false;
|
||||
};
|
||||
|
|
|
@ -6,35 +6,33 @@
|
|||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprlang.hpp>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
|
||||
CImage::~CImage() {
|
||||
if (imageTimer) {
|
||||
imageTimer->cancel();
|
||||
imageTimer.reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void CImage::registerSelf(const SP<CImage>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE) {
|
||||
PIMAGE->onTimerUpdate();
|
||||
PIMAGE->plantTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
const auto PIMAGE = (CImage*)data;
|
||||
|
||||
PIMAGE->onTimerUpdate();
|
||||
PIMAGE->plantTimer();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PIMAGE = (CImage*)data;
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE)
|
||||
PIMAGE->renderUpdate();
|
||||
}
|
||||
|
||||
void CImage::onTimerUpdate() {
|
||||
const std::string OLDPATH = path;
|
||||
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
path = spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
@ -65,9 +63,7 @@ void CImage::onTimerUpdate() {
|
|||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
@ -75,34 +71,41 @@ void CImage::onTimerUpdate() {
|
|||
void CImage::plantTimer() {
|
||||
|
||||
if (reloadTime == 0) {
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onTimer(REF); }, nullptr, true);
|
||||
} else if (reloadTime > 0)
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), onTimer, this, false);
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onTimer(REF); }, nullptr, false);
|
||||
}
|
||||
|
||||
CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& resourceID_, const std::unordered_map<std::string, std::any>& props) :
|
||||
viewport(viewport_), resourceID(resourceID_), output(output_), shadow(this, props, viewport_) {
|
||||
void CImage::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
stringPort = pOutput->stringPort;
|
||||
|
||||
shadow.configure(m_self.lock(), 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()); //
|
||||
}
|
||||
|
||||
angle = angle * M_PI / 180.0;
|
||||
resourceID = "image:" + path;
|
||||
angle = angle * M_PI / 180.0;
|
||||
|
||||
if (reloadTime > -1) {
|
||||
try {
|
||||
|
@ -113,6 +116,25 @@ CImage::CImage(const Vector2D& viewport_, COutput* output_, const std::string& r
|
|||
}
|
||||
}
|
||||
|
||||
void CImage::reset() {
|
||||
if (imageTimer) {
|
||||
imageTimer->cancel();
|
||||
imageTimer.reset();
|
||||
}
|
||||
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
imageFB.release();
|
||||
|
||||
if (asset && reloadTime > -1) // Don't unload asset if it's a static image
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID = "";
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
bool CImage::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty())
|
||||
|
@ -176,10 +198,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;
|
||||
|
@ -204,9 +226,32 @@ void CImage::renderUpdate() {
|
|||
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);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -17,16 +17,26 @@ class COutput;
|
|||
|
||||
class CImage : public IWidget {
|
||||
public:
|
||||
CImage(const Vector2D& viewport, COutput* output_, const std::string& resourceID, const std::unordered_map<std::string, std::any>& props);
|
||||
CImage() = default;
|
||||
~CImage();
|
||||
|
||||
void registerSelf(const SP<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 CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CImage> m_self;
|
||||
|
||||
CFramebuffer imageFB;
|
||||
|
||||
int size;
|
||||
|
@ -35,6 +45,7 @@ class CImage : public IWidget {
|
|||
double angle;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
|
||||
std::string halign, valign, path;
|
||||
|
||||
|
@ -42,14 +53,17 @@ class CImage : public IWidget {
|
|||
|
||||
int reloadTime;
|
||||
std::string reloadCommand;
|
||||
std::string onclickCommand;
|
||||
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
std::shared_ptr<CTimer> imageTimer;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
|
||||
Vector2D viewport;
|
||||
std::string stringPort;
|
||||
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if reloading image
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
COutput* output = nullptr;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
CShadowable shadow;
|
||||
};
|
||||
|
|
|
@ -3,36 +3,31 @@
|
|||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include "../../helpers/MiscFunctions.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
CLabel::~CLabel() {
|
||||
if (labelTimer) {
|
||||
labelTimer->cancel();
|
||||
labelTimer.reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void CLabel::registerSelf(const SP<CLabel>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
static void onTimer(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL) {
|
||||
// update label
|
||||
PLABEL->onTimerUpdate();
|
||||
// plant new timer
|
||||
PLABEL->plantTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
if (data == nullptr)
|
||||
return;
|
||||
const auto PLABEL = (CLabel*)data;
|
||||
|
||||
// update label
|
||||
PLABEL->onTimerUpdate();
|
||||
|
||||
// plant new timer
|
||||
PLABEL->plantTimer();
|
||||
}
|
||||
|
||||
static void onAssetCallback(void* data) {
|
||||
const auto PLABEL = (CLabel*)data;
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallbackTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||
onAssetCallback(data);
|
||||
static void onAssetCallback(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL)
|
||||
PLABEL->renderUpdate();
|
||||
}
|
||||
|
||||
std::string CLabel::getUniqueResourceId() {
|
||||
|
@ -57,32 +52,39 @@ void CLabel::onTimerUpdate() {
|
|||
pendingResourceID = request.id;
|
||||
request.asset = label.formatted;
|
||||
|
||||
request.callback = onAssetCallback;
|
||||
request.callbackData = this;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
void CLabel::plantTimer() {
|
||||
|
||||
if (label.updateEveryMs != 0)
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), onTimer, this, label.allowForceUpdate);
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), [REF = m_self](auto, auto) { onTimer(REF); }, this, label.allowForceUpdate);
|
||||
else if (label.updateEveryMs == 0 && label.allowForceUpdate)
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onTimer(REF); }, this, true);
|
||||
}
|
||||
|
||||
CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
|
||||
outputStringPort(output), shadow(this, props, viewport_) {
|
||||
void CLabel::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
configPos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
|
||||
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"));
|
||||
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"));
|
||||
CColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
CHyprColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
int fontSize = std::any_cast<Hyprlang::INT>(props.at("font_size"));
|
||||
|
||||
label = formatString(labelPreFormat);
|
||||
|
@ -105,14 +107,30 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string,
|
|||
RASSERT(false, "Missing property for CLabel: {}", e.what()); //
|
||||
}
|
||||
|
||||
configPos = pos;
|
||||
viewport = viewport_;
|
||||
pos = configPos; // Label size not known yet
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
|
||||
plantTimer();
|
||||
}
|
||||
|
||||
void CLabel::reset() {
|
||||
if (labelTimer) {
|
||||
labelTimer->cancel();
|
||||
labelTimer.reset();
|
||||
}
|
||||
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
if (asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
|
||||
asset = nullptr;
|
||||
pendingResourceID.clear();
|
||||
resourceID.clear();
|
||||
}
|
||||
|
||||
bool CLabel::draw(const SRenderData& data) {
|
||||
if (!asset) {
|
||||
asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID);
|
||||
|
@ -150,9 +168,29 @@ void CLabel::renderUpdate() {
|
|||
} else {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
||||
CBox CLabel::getBoundingBoxWl() const {
|
||||
if (!asset)
|
||||
return CBox{};
|
||||
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - asset->texture.m_vSize.y},
|
||||
asset->texture.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);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,26 @@ class CSessionLockSurface;
|
|||
|
||||
class CLabel : public IWidget {
|
||||
public:
|
||||
CLabel(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
||||
CLabel() = default;
|
||||
~CLabel();
|
||||
|
||||
void registerSelf(const SP<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 CBox getBoundingBoxWl() const;
|
||||
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
|
||||
virtual void onHover(const Vector2D& pos);
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CLabel> m_self;
|
||||
|
||||
std::string getUniqueResourceId();
|
||||
|
||||
std::string labelPreFormat;
|
||||
|
@ -36,6 +46,7 @@ class CLabel : public IWidget {
|
|||
std::string resourceID;
|
||||
std::string pendingResourceID; // if dynamic label
|
||||
std::string halign, valign;
|
||||
std::string onclickCommand;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
|
||||
std::string outputStringPort;
|
||||
|
|
|
@ -3,18 +3,37 @@
|
|||
#include "../../core/hyprlock.hpp"
|
||||
#include "../../auth/Auth.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "../../config/ConfigManager.hpp"
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include "../../core/AnimationManager.hpp"
|
||||
#include "../../helpers/Color.hpp"
|
||||
#include <cmath>
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <algorithm>
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
|
||||
viewport(viewport_), outputStringPort(output), shadow(this, props, viewport_) {
|
||||
CPasswordInputField::~CPasswordInputField() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void CPasswordInputField::registerSelf(const SP<CPasswordInputField>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
void CPasswordInputField::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
outputStringPort = pOutput->stringPort;
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport_);
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport_);
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
configSize = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
outThick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
||||
|
@ -22,7 +41,6 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
dots.spacing = std::any_cast<Hyprlang::FLOAT>(props.at("dots_spacing"));
|
||||
dots.center = std::any_cast<Hyprlang::INT>(props.at("dots_center"));
|
||||
dots.rounding = std::any_cast<Hyprlang::INT>(props.at("dots_rounding"));
|
||||
dots.fadeMs = std::any_cast<Hyprlang::INT>(props.at("dots_fade_time"));
|
||||
dots.textFormat = std::any_cast<Hyprlang::STRING>(props.at("dots_text_format"));
|
||||
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
||||
fadeTimeoutMs = std::any_cast<Hyprlang::INT>(props.at("fade_timeout"));
|
||||
|
@ -30,9 +48,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
configPlaceholderText = std::any_cast<Hyprlang::STRING>(props.at("placeholder_text"));
|
||||
configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text"));
|
||||
configFailTimeoutMs = std::any_cast<Hyprlang::INT>(props.at("fail_timeout"));
|
||||
fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||
colorConfig.transitionMs = std::any_cast<Hyprlang::INT>(props.at("fail_transition"));
|
||||
colorConfig.outer = CGradientValueData::fromAnyPv(props.at("outer_color"));
|
||||
colorConfig.inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
|
||||
colorConfig.font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
|
||||
|
@ -43,25 +59,31 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
colorConfig.num = CGradientValueData::fromAnyPv(props.at("numlock_color"));
|
||||
colorConfig.invertNum = std::any_cast<Hyprlang::INT>(props.at("invert_numlock"));
|
||||
colorConfig.swapFont = std::any_cast<Hyprlang::INT>(props.at("swap_font_color"));
|
||||
colorConfig.hiddenBase = std::any_cast<Hyprlang::INT>(props.at("hide_input_base_color"));
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CPasswordInputField: {}", e.what()); //
|
||||
} catch (const std::out_of_range& e) {
|
||||
RASSERT(false, "Missing property for CPasswordInputField: {}", e.what()); //
|
||||
}
|
||||
|
||||
configPos = pos;
|
||||
configSize = size;
|
||||
configPos = pos;
|
||||
colorState.font = colorConfig.font;
|
||||
|
||||
pos = posFromHVAlign(viewport, size, pos, halign, valign);
|
||||
dots.size = std::clamp(dots.size, 0.2f, 0.8f);
|
||||
dots.spacing = std::clamp(dots.spacing, -1.f, 1.f);
|
||||
colorConfig.transitionMs = std::clamp(colorConfig.transitionMs, 0, 1000);
|
||||
colorConfig.caps = colorConfig.caps->m_bIsFallback ? colorConfig.fail : colorConfig.caps;
|
||||
pos = posFromHVAlign(viewport, configSize, pos, halign, valign);
|
||||
dots.size = std::clamp(dots.size, 0.2f, 0.8f);
|
||||
dots.spacing = std::clamp(dots.spacing, -1.f, 1.f);
|
||||
|
||||
colorState.inner = colorConfig.inner;
|
||||
colorState.outer = *colorConfig.outer;
|
||||
colorState.font = colorConfig.font;
|
||||
colorState.outerSource = colorConfig.outer;
|
||||
colorConfig.caps = colorConfig.caps->m_bIsFallback ? colorConfig.fail : colorConfig.caps;
|
||||
|
||||
g_pAnimationManager->createAnimation(0.f, fade.a, g_pConfigManager->m_AnimationTree.getConfig("inputFieldFade"));
|
||||
g_pAnimationManager->createAnimation(0.f, dots.currentAmount, g_pConfigManager->m_AnimationTree.getConfig("inputFieldDots"));
|
||||
g_pAnimationManager->createAnimation(configSize, size, g_pConfigManager->m_AnimationTree.getConfig("inputFieldWidth"));
|
||||
g_pAnimationManager->createAnimation(colorConfig.inner, colorState.inner, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
g_pAnimationManager->createAnimation(*colorConfig.outer, colorState.outer, g_pConfigManager->m_AnimationTree.getConfig("inputFieldColors"));
|
||||
|
||||
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
|
||||
pos = posFromHVAlign(viewport, size->goal(), configPos, halign, valign);
|
||||
|
||||
if (!dots.textFormat.empty()) {
|
||||
dots.textResourceID = std::format("input:{}-{}", (uintptr_t)this, dots.textFormat);
|
||||
|
@ -70,8 +92,8 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
request.asset = dots.textFormat;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
||||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = colorState.font;
|
||||
request.props["font_size"] = (int)(std::nearbyint(size.y * dots.size * 0.5f) * 2.f);
|
||||
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);
|
||||
}
|
||||
|
@ -80,10 +102,26 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
|
|||
updatePlaceholder();
|
||||
}
|
||||
|
||||
static void fadeOutCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
CPasswordInputField* p = (CPasswordInputField*)data;
|
||||
void CPasswordInputField::reset() {
|
||||
if (fade.fadeOutTimer.get()) {
|
||||
fade.fadeOutTimer->cancel();
|
||||
fade.fadeOutTimer.reset();
|
||||
}
|
||||
|
||||
p->onFadeOutTimer();
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
if (placeholder.asset)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.asset);
|
||||
|
||||
placeholder.asset = nullptr;
|
||||
placeholder.resourceID.clear();
|
||||
placeholder.currentText.clear();
|
||||
}
|
||||
|
||||
static void fadeOutCallback(WP<CPasswordInputField> ref) {
|
||||
if (const auto PP = ref.lock(); PP)
|
||||
PP->onFadeOutTimer();
|
||||
}
|
||||
|
||||
void CPasswordInputField::onFadeOutTimer() {
|
||||
|
@ -95,7 +133,7 @@ void CPasswordInputField::onFadeOutTimer() {
|
|||
|
||||
void CPasswordInputField::updateFade() {
|
||||
if (!fadeOnEmpty) {
|
||||
fade.a = 1.0;
|
||||
fade.a->setValueAndWarp(1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -109,73 +147,34 @@ void CPasswordInputField::updateFade() {
|
|||
fade.fadeOutTimer.reset();
|
||||
}
|
||||
|
||||
if (!INPUTUSED && fade.a != 0.0 && (!fade.animated || fade.appearing)) {
|
||||
if (!INPUTUSED && fade.a->goal() != 0.0) {
|
||||
if (fade.allowFadeOut || fadeTimeoutMs == 0) {
|
||||
fade.a = 1.0;
|
||||
fade.animated = true;
|
||||
fade.appearing = false;
|
||||
fade.start = std::chrono::system_clock::now();
|
||||
*fade.a = 0.0;
|
||||
fade.allowFadeOut = false;
|
||||
} else if (!fade.fadeOutTimer.get())
|
||||
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), fadeOutCallback, this);
|
||||
}
|
||||
fade.fadeOutTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(fadeTimeoutMs), [REF = m_self](auto, auto) { fadeOutCallback(REF); }, nullptr);
|
||||
|
||||
if (INPUTUSED && fade.a != 1.0 && (!fade.animated || !fade.appearing)) {
|
||||
fade.a = 0.0;
|
||||
fade.animated = true;
|
||||
fade.appearing = true;
|
||||
fade.start = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
if (fade.animated) {
|
||||
if (fade.appearing)
|
||||
fade.a = std::clamp(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0);
|
||||
else
|
||||
fade.a = std::clamp(1.0 - std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0);
|
||||
|
||||
if ((fade.appearing && fade.a == 1.0) || (!fade.appearing && fade.a == 0.0))
|
||||
fade.animated = false;
|
||||
} else if (INPUTUSED && fade.a->goal() != 1.0)
|
||||
*fade.a = 1.0;
|
||||
|
||||
if (fade.a->isBeingAnimated())
|
||||
redrawShadow = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateDots() {
|
||||
if (passwordLength == dots.currentAmount)
|
||||
if (dots.currentAmount->goal() == passwordLength)
|
||||
return;
|
||||
|
||||
// Fully fading the dots to 0 currently does not look good
|
||||
if (passwordLength == 0 && dots.currentAmount > 2) {
|
||||
dots.currentAmount = 0;
|
||||
if (checkWaiting)
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::abs(passwordLength - dots.currentAmount) > 1) {
|
||||
dots.currentAmount = std::clamp(dots.currentAmount, passwordLength - 1.f, passwordLength + 1.f);
|
||||
dots.lastFrame = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dots.lastFrame).count(), 0, 20000);
|
||||
|
||||
const float TOADD = dots.fadeMs > 0 ? ((double)DELTA / 1000000.0) * (1000.0 / (double)dots.fadeMs) : 1;
|
||||
|
||||
if (passwordLength > dots.currentAmount) {
|
||||
dots.currentAmount += TOADD;
|
||||
if (dots.currentAmount > passwordLength)
|
||||
dots.currentAmount = passwordLength;
|
||||
} else if (passwordLength < dots.currentAmount) {
|
||||
dots.currentAmount -= TOADD;
|
||||
if (dots.currentAmount < passwordLength)
|
||||
dots.currentAmount = passwordLength;
|
||||
}
|
||||
|
||||
dots.lastFrame = std::chrono::system_clock::now();
|
||||
if (passwordLength == 0)
|
||||
dots.currentAmount->setValueAndWarp(passwordLength);
|
||||
else
|
||||
*dots.currentAmount = passwordLength;
|
||||
}
|
||||
|
||||
bool CPasswordInputField::draw(const SRenderData& data) {
|
||||
CBox inputFieldBox = {pos, size};
|
||||
CBox outerBox = {pos - Vector2D{outThick, outThick}, size + Vector2D{outThick * 2, outThick * 2}};
|
||||
|
||||
if (firstRender || redrawShadow) {
|
||||
firstRender = false;
|
||||
redrawShadow = false;
|
||||
|
@ -195,26 +194,29 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
updateWidth();
|
||||
updateHiddenInputState();
|
||||
|
||||
SRenderData shadowData = data;
|
||||
shadowData.opacity *= fade.a;
|
||||
CBox inputFieldBox = {pos, size->value()};
|
||||
CBox outerBox = {pos - Vector2D{outThick, outThick}, size->value() + Vector2D{outThick * 2, outThick * 2}};
|
||||
|
||||
if (!dynamicWidth.animated || size.x > dynamicWidth.source)
|
||||
SRenderData shadowData = data;
|
||||
shadowData.opacity *= fade.a->value();
|
||||
|
||||
if (!size->isBeingAnimated())
|
||||
shadow.draw(shadowData);
|
||||
|
||||
CGradientValueData outerGrad = colorState.outer;
|
||||
for (auto& c : outerGrad.m_vColors)
|
||||
c.a *= fade.a * data.opacity;
|
||||
//CGradientValueData outerGrad = colorState.outer->value();
|
||||
//for (auto& c : outerGrad.m_vColors)
|
||||
// c.a *= fade.a->value() * data.opacity;
|
||||
|
||||
CColor innerCol = colorState.inner;
|
||||
innerCol.a *= fade.a * data.opacity;
|
||||
CColor fontCol = colorState.font;
|
||||
fontCol.a *= fade.a * data.opacity;
|
||||
CHyprColor innerCol = colorState.inner->value();
|
||||
innerCol.a *= fade.a->value() * data.opacity;
|
||||
CHyprColor fontCol = colorState.font;
|
||||
fontCol.a *= fade.a->value() * data.opacity;
|
||||
|
||||
if (outThick > 0) {
|
||||
const int BORDERROUND = roundingForBorderBox(outerBox, rounding, outThick);
|
||||
g_pRenderer->renderBorder(outerBox, outerGrad, outThick, BORDERROUND, fade.a * data.opacity);
|
||||
const auto OUTERROUND = roundingForBorderBox(outerBox, rounding, outThick);
|
||||
g_pRenderer->renderBorder(outerBox, colorState.outer->value(), outThick, OUTERROUND, fade.a->value() * data.opacity);
|
||||
|
||||
if (passwordLength != 0 && hiddenInputState.enabled && !fade.animated && data.opacity == 1.0) {
|
||||
if (passwordLength != 0 && !checkWaiting && hiddenInputState.enabled) {
|
||||
CBox outerBoxScaled = outerBox;
|
||||
Vector2D p = outerBox.pos();
|
||||
outerBoxScaled.translate(-p).scale(0.5).translate(p);
|
||||
|
@ -224,7 +226,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
outerBoxScaled.x += outerBoxScaled.w;
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(outerBoxScaled.x, outerBoxScaled.y, outerBoxScaled.w, outerBoxScaled.h);
|
||||
g_pRenderer->renderBorder(outerBox, hiddenInputState.lastColor, outThick, BORDERROUND, fade.a * data.opacity);
|
||||
g_pRenderer->renderBorder(outerBox, hiddenInputState.lastColor, outThick, OUTERROUND, fade.a->value() * data.opacity);
|
||||
glScissor(0, 0, viewport.x, viewport.y);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
@ -233,7 +235,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
const int ROUND = roundingForBox(inputFieldBox, rounding);
|
||||
g_pRenderer->renderRect(inputFieldBox, innerCol, ROUND);
|
||||
|
||||
if (!hiddenInputState.enabled && !g_pHyprlock->m_bFadeStarted) {
|
||||
if (!hiddenInputState.enabled) {
|
||||
const int RECTPASSSIZE = std::nearbyint(inputFieldBox.h * dots.size * 0.5f) * 2.f;
|
||||
Vector2D passSize{RECTPASSSIZE, RECTPASSSIZE};
|
||||
int passSpacing = std::floor(passSize.x * dots.spacing);
|
||||
|
@ -250,53 +252,56 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
}
|
||||
}
|
||||
|
||||
const int DOT_PAD = (inputFieldBox.h - passSize.y) / 2;
|
||||
const int DOT_AREA_WIDTH = inputFieldBox.w - DOT_PAD * 2; // avail width for dots
|
||||
const int MAX_DOTS = std::round(DOT_AREA_WIDTH * 1.0 / (passSize.x + passSpacing)); // max amount of dots that can fit in the area
|
||||
const int DOT_FLOORED = std::floor(dots.currentAmount);
|
||||
const float DOT_ALPHA = fontCol.a;
|
||||
const auto CURRDOTS = dots.currentAmount->value();
|
||||
const double DOTPAD = (inputFieldBox.h - passSize.y) / 2.0;
|
||||
const double DOTAREAWIDTH = inputFieldBox.w - (DOTPAD * 2);
|
||||
const int MAXDOTS = std::round(DOTAREAWIDTH * 1.0 / (passSize.x + passSpacing));
|
||||
const int DOTFLOORED = std::floor(CURRDOTS);
|
||||
const auto DOTALPHA = fontCol.a;
|
||||
|
||||
// Calculate the total width required for all dots including spaces between them
|
||||
const int TOTAL_DOTS_WIDTH = (passSize.x + passSpacing) * dots.currentAmount - passSpacing;
|
||||
const double CURRWIDTH = ((passSize.x + passSpacing) * CURRDOTS) - passSpacing;
|
||||
|
||||
// Calculate starting x-position to ensure dots stay centered within the input field
|
||||
int xstart = dots.center ? (DOT_AREA_WIDTH - TOTAL_DOTS_WIDTH) / 2 + DOT_PAD : DOT_PAD;
|
||||
double xstart = dots.center ? ((DOTAREAWIDTH - CURRWIDTH) / 2.0) + DOTPAD : DOTPAD;
|
||||
|
||||
if (dots.currentAmount > MAX_DOTS)
|
||||
xstart = (inputFieldBox.w + MAX_DOTS * (passSize.x + passSpacing) - passSpacing - 2 * TOTAL_DOTS_WIDTH) / 2;
|
||||
if (CURRDOTS > MAXDOTS)
|
||||
xstart = (inputFieldBox.w + MAXDOTS * (passSize.x + passSpacing) - passSpacing - 2 * CURRWIDTH) / 2.0;
|
||||
|
||||
if (dots.rounding == -1)
|
||||
dots.rounding = passSize.x / 2.0;
|
||||
else if (dots.rounding == -2)
|
||||
dots.rounding = rounding == -1 ? passSize.x / 2.0 : rounding * dots.size;
|
||||
|
||||
for (int i = 0; i < dots.currentAmount; ++i) {
|
||||
if (i < DOT_FLOORED - MAX_DOTS)
|
||||
for (int i = 0; i < CURRDOTS; ++i) {
|
||||
if (i < DOTFLOORED - MAXDOTS)
|
||||
continue;
|
||||
|
||||
if (dots.currentAmount != DOT_FLOORED) {
|
||||
if (i == DOT_FLOORED)
|
||||
fontCol.a *= (dots.currentAmount - DOT_FLOORED) * data.opacity;
|
||||
else if (i == DOT_FLOORED - MAX_DOTS)
|
||||
fontCol.a *= (1 - dots.currentAmount + DOT_FLOORED) * data.opacity;
|
||||
if (CURRDOTS != DOTFLOORED) {
|
||||
if (i == DOTFLOORED)
|
||||
fontCol.a *= (CURRDOTS - DOTFLOORED) * data.opacity;
|
||||
else if (i == DOTFLOORED - MAXDOTS)
|
||||
fontCol.a *= (1 - CURRDOTS + DOTFLOORED) * data.opacity;
|
||||
}
|
||||
|
||||
Vector2D dotPosition =
|
||||
inputFieldBox.pos() + Vector2D{xstart + (int)inputFieldBox.w % 2 / 2.f + i * (passSize.x + passSpacing), inputFieldBox.h / 2.f - passSize.y / 2.f};
|
||||
CBox box{dotPosition, passSize};
|
||||
Vector2D dotPosition = inputFieldBox.pos() + Vector2D{xstart + (i * (passSize.x + passSpacing)), (inputFieldBox.h / 2.0) - (passSize.y / 2.0)};
|
||||
CBox box{dotPosition, passSize};
|
||||
if (!dots.textFormat.empty()) {
|
||||
if (!dots.textAsset)
|
||||
if (!dots.textAsset) {
|
||||
forceReload = true;
|
||||
fontCol.a = DOTALPHA;
|
||||
break;
|
||||
}
|
||||
|
||||
g_pRenderer->renderTexture(box, dots.textAsset->texture, fontCol.a, dots.rounding);
|
||||
} else {
|
||||
} else
|
||||
g_pRenderer->renderRect(box, fontCol, dots.rounding);
|
||||
}
|
||||
fontCol.a = DOT_ALPHA;
|
||||
|
||||
fontCol.a = DOTALPHA;
|
||||
}
|
||||
}
|
||||
|
||||
if (passwordLength == 0 && !placeholder.resourceID.empty()) {
|
||||
if (passwordLength == 0 && !checkWaiting && !placeholder.resourceID.empty()) {
|
||||
SPreloadedAsset* currAsset = nullptr;
|
||||
|
||||
if (!placeholder.asset)
|
||||
|
@ -304,21 +309,21 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
|
||||
currAsset = placeholder.asset;
|
||||
|
||||
if (currAsset && currAsset->texture.m_vSize.x + size.y <= size.x) {
|
||||
Vector2D pos = outerBox.pos() + outerBox.size() / 2.f;
|
||||
pos = pos - currAsset->texture.m_vSize / 2.f;
|
||||
CBox textbox{pos, currAsset->texture.m_vSize};
|
||||
g_pRenderer->renderTexture(textbox, currAsset->texture, data.opacity * fade.a, 0);
|
||||
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};
|
||||
|
||||
// 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);
|
||||
glScissor(0, 0, viewport.x, viewport.y);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
} else
|
||||
forceReload = true;
|
||||
}
|
||||
|
||||
return dots.currentAmount != passwordLength || fade.animated || colorState.animated || redrawShadow || data.opacity < 1.0 || dynamicWidth.animated || forceReload;
|
||||
}
|
||||
|
||||
static void failTimeoutCallback(std::shared_ptr<CTimer> self, void* data) {
|
||||
g_pAuth->m_bDisplayFailText = false;
|
||||
g_pHyprlock->renderAllOutputs();
|
||||
return redrawShadow || forceReload;
|
||||
}
|
||||
|
||||
void CPasswordInputField::updatePlaceholder() {
|
||||
|
@ -333,32 +338,34 @@ void CPasswordInputField::updatePlaceholder() {
|
|||
return;
|
||||
}
|
||||
|
||||
const auto AUTHFEEDBACK = g_pAuth->getInlineFeedback();
|
||||
const auto ALLOWCOLORSWAP = outThick == 0 && colorConfig.swapFont;
|
||||
|
||||
if (!ALLOWCOLORSWAP && placeholder.lastAuthFeedback == AUTHFEEDBACK && g_pAuth->m_iFailedAttempts == placeholder.failedAttempts)
|
||||
// already requested a placeholder for the current fail
|
||||
if (displayFail && placeholder.failedAttempts == g_pAuth->getFailedAttempts())
|
||||
return;
|
||||
|
||||
placeholder.failedAttempts = g_pAuth->m_iFailedAttempts;
|
||||
placeholder.lastAuthFeedback = AUTHFEEDBACK;
|
||||
placeholder.failedAttempts = g_pAuth->getFailedAttempts();
|
||||
|
||||
placeholder.asset = nullptr;
|
||||
std::string newText = (displayFail) ? formatString(configFailText).formatted : formatString(configPlaceholderText).formatted;
|
||||
|
||||
if (displayFail) {
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(configFailTimeoutMs), failTimeoutCallback, nullptr);
|
||||
const auto FORMATTEDFAIL = formatString(configFailText).formatted;
|
||||
placeholder.currentText = FORMATTEDFAIL;
|
||||
} else {
|
||||
const auto FORMATTEDPLACEHOLDER = formatString(configPlaceholderText).formatted;
|
||||
placeholder.currentText = FORMATTEDPLACEHOLDER;
|
||||
}
|
||||
// if the text is unchanged we don't need to do anything, unless we are swapping font color
|
||||
const auto ALLOWCOLORSWAP = outThick == 0 && colorConfig.swapFont;
|
||||
if (!ALLOWCOLORSWAP && newText == placeholder.currentText)
|
||||
return;
|
||||
|
||||
placeholder.resourceID =
|
||||
const auto NEWRESOURCEID =
|
||||
std::format("placeholder:{}{}{}{}{}{}", placeholder.currentText, (uintptr_t)this, colorState.font.r, colorState.font.g, colorState.font.b, colorState.font.a);
|
||||
|
||||
if (std::find(placeholder.registeredResourceIDs.begin(), placeholder.registeredResourceIDs.end(), placeholder.resourceID) != placeholder.registeredResourceIDs.end())
|
||||
if (placeholder.resourceID == NEWRESOURCEID)
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "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
|
||||
|
@ -368,42 +375,34 @@ void CPasswordInputField::updatePlaceholder() {
|
|||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
|
||||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = colorState.font;
|
||||
request.props["font_size"] = (int)size.y / 4;
|
||||
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);
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateWidth() {
|
||||
const auto NOW = std::chrono::system_clock::now();
|
||||
double targetSizeX = configSize.x;
|
||||
double targetSizeX = configSize.x;
|
||||
|
||||
if (placeholder.asset)
|
||||
targetSizeX = placeholder.asset->texture.m_vSize.x + size.y;
|
||||
if (passwordLength == 0 && placeholder.asset)
|
||||
targetSizeX = placeholder.asset->texture.m_vSize.x + size->goal().y;
|
||||
|
||||
if (targetSizeX < configSize.x)
|
||||
targetSizeX = configSize.x;
|
||||
targetSizeX = std::max(targetSizeX, configSize.x);
|
||||
|
||||
if (size.x != targetSizeX) {
|
||||
if (!dynamicWidth.animated) {
|
||||
dynamicWidth.source = size.x;
|
||||
dynamicWidth.start = NOW;
|
||||
dynamicWidth.animated = true;
|
||||
}
|
||||
|
||||
const auto TIMEDELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(NOW - dynamicWidth.start).count(), 1000, 100000);
|
||||
const auto INCR = std::clamp(std::abs(targetSizeX - dynamicWidth.source) * TIMEDELTA / 1000000.0, 1.0, 1000.0);
|
||||
if (size.x > targetSizeX)
|
||||
size.x -= INCR;
|
||||
else
|
||||
size.x += INCR;
|
||||
|
||||
if ((dynamicWidth.source < targetSizeX && size.x > targetSizeX) || (dynamicWidth.source > targetSizeX && size.x < targetSizeX)) {
|
||||
size.x = targetSizeX;
|
||||
redrawShadow = true;
|
||||
dynamicWidth.animated = false;
|
||||
}
|
||||
if (size->goal().x != targetSizeX) {
|
||||
*size = Vector2D{targetSizeX, configSize.y};
|
||||
size->setCallbackOnEnd([this](auto) {
|
||||
redrawShadow = true;
|
||||
pos = posFromHVAlign(viewport, size->value(), configPos, halign, valign);
|
||||
});
|
||||
}
|
||||
|
||||
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
|
||||
if (size->isBeingAnimated()) {
|
||||
redrawShadow = true;
|
||||
pos = posFromHVAlign(viewport, size->value(), configPos, halign, valign);
|
||||
}
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateHiddenInputState() {
|
||||
|
@ -413,78 +412,29 @@ void CPasswordInputField::updateHiddenInputState() {
|
|||
// randomize new thang
|
||||
hiddenInputState.lastPasswordLength = passwordLength;
|
||||
|
||||
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
float r1 = (rand() % 100) / 255.0;
|
||||
float r2 = (rand() % 100) / 255.0;
|
||||
int r3 = rand() % 3;
|
||||
int r4 = rand() % 2;
|
||||
int r5 = rand() % 2;
|
||||
const auto BASEOK = colorConfig.hiddenBase.asOkLab();
|
||||
|
||||
((float*)&hiddenInputState.lastColor.r)[r3] = r1 + 155 / 255.0;
|
||||
((float*)&hiddenInputState.lastColor.r)[(r3 + r4) % 3] = r2 + 155 / 255.0;
|
||||
// convert to polar coordinates
|
||||
const auto OKICHCHROMA = std::sqrt(std::pow(BASEOK.a, 2) + std::pow(BASEOK.b, 2));
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (i != r3 && i != ((r3 + r4) % 3)) {
|
||||
((float*)&hiddenInputState.lastColor.r)[i] = 1.0 - ((float*)&hiddenInputState.lastColor.r)[r5 ? r3 : ((r3 + r4) % 3)];
|
||||
}
|
||||
}
|
||||
// now randomly rotate the hue
|
||||
const double OKICHHUE = (rand() % 10000000 / 10000000.0) * M_PI * 4;
|
||||
|
||||
hiddenInputState.lastColor.a = 1.0;
|
||||
// convert back to OkLab
|
||||
const Hyprgraphics::CColor newColor = Hyprgraphics::CColor::SOkLab{
|
||||
.l = BASEOK.l,
|
||||
.a = OKICHCHROMA * std::cos(OKICHHUE),
|
||||
.b = OKICHCHROMA * std::sin(OKICHHUE),
|
||||
};
|
||||
|
||||
hiddenInputState.lastColor = {newColor, 1.0};
|
||||
hiddenInputState.lastQuadrant = (hiddenInputState.lastQuadrant + rand() % 3 + 1) % 4;
|
||||
}
|
||||
|
||||
static void changeChannel(const float& source, const float& target, float& subject, const double& multi, bool& animated) {
|
||||
|
||||
const float DELTA = target - source;
|
||||
|
||||
if (subject != target) {
|
||||
subject += DELTA * multi;
|
||||
animated = true;
|
||||
|
||||
if ((source < target && subject > target) || (source > target && subject < target))
|
||||
subject = target;
|
||||
}
|
||||
}
|
||||
|
||||
static void changeColor(const CColor& source, const CColor& target, CColor& subject, const double& multi, bool& animated) {
|
||||
|
||||
changeChannel(source.r, target.r, subject.r, multi, animated);
|
||||
changeChannel(source.g, target.g, subject.g, multi, animated);
|
||||
changeChannel(source.b, target.b, subject.b, multi, animated);
|
||||
changeChannel(source.a, target.a, subject.a, multi, animated);
|
||||
}
|
||||
|
||||
static void changeGrad(CGradientValueData* psource, CGradientValueData* ptarget, CGradientValueData& subject, const double& multi, bool& animated) {
|
||||
if (!psource || !ptarget)
|
||||
return;
|
||||
|
||||
subject.m_vColors.resize(ptarget->m_vColors.size(), subject.m_vColors.back());
|
||||
|
||||
for (size_t i = 0; i < subject.m_vColors.size(); ++i) {
|
||||
const CColor& sourceCol = (i < psource->m_vColors.size()) ? psource->m_vColors[i] : psource->m_vColors.back();
|
||||
const CColor& targetCol = (i < ptarget->m_vColors.size()) ? ptarget->m_vColors[i] : ptarget->m_vColors.back();
|
||||
changeColor(sourceCol, targetCol, subject.m_vColors[i], multi, animated);
|
||||
}
|
||||
|
||||
if (psource->m_fAngle != ptarget->m_fAngle) {
|
||||
const float DELTA = ptarget->m_fAngle - psource->m_fAngle;
|
||||
subject.m_fAngle += DELTA * multi;
|
||||
animated = true;
|
||||
|
||||
if ((psource->m_fAngle < ptarget->m_fAngle && subject.m_fAngle > ptarget->m_fAngle) || (psource->m_fAngle > ptarget->m_fAngle && subject.m_fAngle < ptarget->m_fAngle))
|
||||
subject.m_fAngle = ptarget->m_fAngle;
|
||||
}
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateColors() {
|
||||
const bool BORDERLESS = outThick == 0;
|
||||
const bool NUMLOCK = (colorConfig.invertNum) ? !g_pHyprlock->m_bNumLock : g_pHyprlock->m_bNumLock;
|
||||
const auto MULTI = colorConfig.transitionMs == 0 ?
|
||||
1.0 :
|
||||
std::clamp(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - colorState.lastFrame).count() / (double)colorConfig.transitionMs,
|
||||
0.0016, 0.5);
|
||||
const bool BORDERLESS = outThick == 0;
|
||||
const bool NUMLOCK = (colorConfig.invertNum) ? !g_pHyprlock->m_bNumLock : g_pHyprlock->m_bNumLock;
|
||||
|
||||
//
|
||||
CGradientValueData* targetGrad = nullptr;
|
||||
|
||||
if (g_pHyprlock->m_bCapsLock && NUMLOCK && !colorConfig.both->m_bIsFallback)
|
||||
|
@ -496,41 +446,41 @@ void CPasswordInputField::updateColors() {
|
|||
|
||||
if (checkWaiting)
|
||||
targetGrad = colorConfig.check;
|
||||
else if (displayFail)
|
||||
else if (displayFail && passwordLength == 0)
|
||||
targetGrad = colorConfig.fail;
|
||||
|
||||
CGradientValueData* outerTarget = colorConfig.outer;
|
||||
CColor innerTarget = colorConfig.inner;
|
||||
CColor fontTarget = (displayFail) ? colorConfig.fail->m_vColors.front() : colorConfig.font;
|
||||
CHyprColor innerTarget = colorConfig.inner;
|
||||
CHyprColor fontTarget = (displayFail) ? colorConfig.fail->m_vColors.front() : colorConfig.font;
|
||||
|
||||
if (checkWaiting || displayFail || g_pHyprlock->m_bCapsLock || NUMLOCK) {
|
||||
if (targetGrad) {
|
||||
if (BORDERLESS && colorConfig.swapFont) {
|
||||
fontTarget = colorConfig.fail->m_vColors.front();
|
||||
fontTarget = targetGrad->m_vColors.front();
|
||||
} else if (BORDERLESS && !colorConfig.swapFont) {
|
||||
innerTarget = colorConfig.fail->m_vColors.front();
|
||||
// When changing the inner color the font cannot be fail_color
|
||||
innerTarget = targetGrad->m_vColors.front();
|
||||
// When changing the inner color, the font cannot be fail_color
|
||||
fontTarget = colorConfig.font;
|
||||
} else {
|
||||
} else if (targetGrad) {
|
||||
outerTarget = targetGrad;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetGrad != colorState.currentTarget) {
|
||||
colorState.outerSource = &colorState.outer;
|
||||
colorState.innerSource = colorState.inner;
|
||||
if (!BORDERLESS && *outerTarget != colorState.outer->goal())
|
||||
*colorState.outer = *outerTarget;
|
||||
|
||||
colorState.currentTarget = targetGrad;
|
||||
}
|
||||
if (innerTarget != colorState.inner->goal())
|
||||
*colorState.inner = innerTarget;
|
||||
|
||||
colorState.animated = false;
|
||||
|
||||
if (!BORDERLESS)
|
||||
changeGrad(colorState.outerSource, outerTarget, colorState.outer, MULTI, colorState.animated);
|
||||
changeColor(colorState.innerSource, innerTarget, colorState.inner, MULTI, colorState.animated);
|
||||
|
||||
// Font color is only chaned, when `swap_font_color` is set to true and no border is present.
|
||||
// It is not animated, because that does not look good and we would need to rerender the text for each frame.
|
||||
colorState.font = fontTarget;
|
||||
|
||||
colorState.lastFrame = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
#include "../../helpers/Math.hpp"
|
||||
#include "../../core/Timer.hpp"
|
||||
#include "Shadowable.hpp"
|
||||
#include "src/config/ConfigDataValues.hpp"
|
||||
#include <chrono>
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include "../../helpers/AnimatedVariable.hpp"
|
||||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include <vector>
|
||||
#include <any>
|
||||
#include <unordered_map>
|
||||
|
@ -15,64 +16,64 @@ struct SPreloadedAsset;
|
|||
|
||||
class CPasswordInputField : public IWidget {
|
||||
public:
|
||||
CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
|
||||
CPasswordInputField() = default;
|
||||
virtual ~CPasswordInputField();
|
||||
|
||||
void registerSelf(const SP<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 onHover(const Vector2D& pos);
|
||||
virtual CBox getBoundingBoxWl() const;
|
||||
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
||||
private:
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
WP<CPasswordInputField> m_self;
|
||||
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
|
||||
size_t passwordLength = 0;
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
|
||||
Vector2D size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
size_t passwordLength = 0;
|
||||
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
|
||||
int outThick, rounding;
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
|
||||
int outThick, rounding;
|
||||
|
||||
struct {
|
||||
std::chrono::system_clock::time_point start;
|
||||
bool animated = false;
|
||||
double source = 0;
|
||||
} dynamicWidth;
|
||||
|
||||
struct {
|
||||
float currentAmount = 0;
|
||||
int fadeMs = 0;
|
||||
std::chrono::system_clock::time_point lastFrame;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
std::string textFormat = "";
|
||||
SPreloadedAsset* textAsset = nullptr;
|
||||
std::string textResourceID;
|
||||
PHLANIMVAR<float> currentAmount;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
std::string textFormat = "";
|
||||
std::string textResourceID;
|
||||
SPreloadedAsset* textAsset = nullptr;
|
||||
} dots;
|
||||
|
||||
struct {
|
||||
std::chrono::system_clock::time_point start;
|
||||
float a = 0;
|
||||
bool appearing = true;
|
||||
bool animated = false;
|
||||
std::shared_ptr<CTimer> fadeOutTimer = nullptr;
|
||||
bool allowFadeOut = false;
|
||||
PHLANIMVAR<float> a;
|
||||
bool appearing = true;
|
||||
std::shared_ptr<CTimer> fadeOutTimer = nullptr;
|
||||
bool allowFadeOut = false;
|
||||
} fade;
|
||||
|
||||
struct {
|
||||
|
@ -81,50 +82,40 @@ class CPasswordInputField : public IWidget {
|
|||
|
||||
std::string currentText = "";
|
||||
size_t failedAttempts = 0;
|
||||
bool canGetNewText = true;
|
||||
|
||||
std::string lastAuthFeedback;
|
||||
|
||||
std::vector<std::string> registeredResourceIDs;
|
||||
|
||||
} placeholder;
|
||||
|
||||
struct {
|
||||
CColor lastColor;
|
||||
int lastQuadrant = 0;
|
||||
int lastPasswordLength = 0;
|
||||
bool enabled = false;
|
||||
CHyprColor lastColor;
|
||||
int lastQuadrant = 0;
|
||||
int lastPasswordLength = 0;
|
||||
bool enabled = false;
|
||||
} hiddenInputState;
|
||||
|
||||
struct {
|
||||
CGradientValueData* outer = nullptr;
|
||||
CColor inner;
|
||||
CColor font;
|
||||
CHyprColor inner;
|
||||
CHyprColor font;
|
||||
CGradientValueData* fail = nullptr;
|
||||
CGradientValueData* check = nullptr;
|
||||
CGradientValueData* caps = nullptr;
|
||||
CGradientValueData* num = nullptr;
|
||||
CGradientValueData* both = nullptr;
|
||||
|
||||
CHyprColor hiddenBase;
|
||||
|
||||
int transitionMs = 0;
|
||||
bool invertNum = false;
|
||||
bool swapFont = false;
|
||||
} colorConfig;
|
||||
|
||||
struct {
|
||||
CGradientValueData outer;
|
||||
CColor inner;
|
||||
CColor font;
|
||||
|
||||
CGradientValueData* outerSource = nullptr;
|
||||
CColor innerSource;
|
||||
|
||||
CGradientValueData* currentTarget = nullptr;
|
||||
|
||||
bool animated = false;
|
||||
|
||||
//
|
||||
std::chrono::system_clock::time_point lastFrame;
|
||||
PHLANIMVAR<CGradientValueData> outer;
|
||||
PHLANIMVAR<CHyprColor> inner;
|
||||
// Font color is only chaned, when `swap_font_color` is set to true and no border is present.
|
||||
// It is not animated, because that does not look good and we would need to rerender the text for each frame.
|
||||
CHyprColor font;
|
||||
} colorState;
|
||||
|
||||
bool fadeOnEmpty;
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
#include "../Renderer.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
|
||||
CShadowable::CShadowable(IWidget* widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) : widget(widget_), viewport(viewport_) {
|
||||
void CShadowable::configure(WP<IWidget> widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_) {
|
||||
m_widget = widget_;
|
||||
viewport = viewport_;
|
||||
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("shadow_size"));
|
||||
passes = std::any_cast<Hyprlang::INT>(props.at("shadow_passes"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("shadow_color"));
|
||||
|
@ -10,6 +13,10 @@ CShadowable::CShadowable(IWidget* widget_, const std::unordered_map<std::string,
|
|||
}
|
||||
|
||||
void CShadowable::markShadowDirty() {
|
||||
const auto WIDGET = m_widget.lock();
|
||||
|
||||
if (!m_widget)
|
||||
return;
|
||||
|
||||
if (passes == 0)
|
||||
return;
|
||||
|
@ -22,7 +29,7 @@ void CShadowable::markShadowDirty() {
|
|||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
ignoreDraw = true;
|
||||
widget->draw(IWidget::SRenderData{.opacity = 1.0});
|
||||
WIDGET->draw(IWidget::SRenderData{.opacity = 1.0});
|
||||
ignoreDraw = false;
|
||||
|
||||
g_pRenderer->blurFB(shadowFB, CRenderer::SBlurParams{.size = size, .passes = passes, .colorize = color, .boostA = boostA});
|
||||
|
@ -31,7 +38,7 @@ void CShadowable::markShadowDirty() {
|
|||
}
|
||||
|
||||
bool CShadowable::draw(const IWidget::SRenderData& data) {
|
||||
if (passes == 0)
|
||||
if (!m_widget || passes == 0)
|
||||
return true;
|
||||
|
||||
if (!shadowFB.isAllocated() || ignoreDraw)
|
||||
|
@ -40,4 +47,4 @@ bool CShadowable::draw(const IWidget::SRenderData& data) {
|
|||
CBox box = {0, 0, viewport.x, viewport.y};
|
||||
g_pRenderer->renderTexture(box, shadowFB.m_cTex, data.opacity, 0, HYPRUTILS_TRANSFORM_NORMAL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,22 +11,24 @@
|
|||
|
||||
class CShadowable {
|
||||
public:
|
||||
CShadowable(IWidget* widget_, const std::unordered_map<std::string, std::any>& props, const Vector2D& viewport_ /* TODO: make this not the entire viewport */);
|
||||
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 */);
|
||||
|
||||
// instantly re-renders the shadow using the widget's draw() method
|
||||
void markShadowDirty();
|
||||
virtual bool draw(const IWidget::SRenderData& data);
|
||||
|
||||
private:
|
||||
IWidget* widget = nullptr;
|
||||
int size = 10;
|
||||
int passes = 4;
|
||||
float boostA = 1.0;
|
||||
CColor color{0, 0, 0, 1.0};
|
||||
Vector2D viewport;
|
||||
WP<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;
|
||||
|
||||
CFramebuffer shadowFB;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,30 +1,40 @@
|
|||
#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>
|
||||
|
||||
CShape::CShape(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props) : shadow(this, props, viewport_) {
|
||||
void CShape::registerSelf(const SP<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);
|
||||
|
||||
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) {
|
||||
RASSERT(false, "Missing property for CShape: {}", e.what()); //
|
||||
}
|
||||
|
||||
viewport = viewport_;
|
||||
angle = angle * M_PI / 180.0;
|
||||
angle = angle * M_PI / 180.0;
|
||||
|
||||
const Vector2D VBORDER = {border, border};
|
||||
const Vector2D REALSIZE = size + VBORDER * 2.0;
|
||||
|
@ -72,7 +82,7 @@ bool CShape::draw(const SRenderData& data) {
|
|||
const int BORDERROUND = roundingForBorderBox(borderBox, rounding, border);
|
||||
Debug::log(LOG, "round: {}, borderround: {}", ROUND, BORDERROUND);
|
||||
|
||||
shapeFB.alloc(borderBox.width + borderBox.x * 2.0, borderBox.height + borderBox.y * 2.0, true);
|
||||
shapeFB.alloc(borderBox.width + (borderBox.x * 2.0), borderBox.height + (borderBox.y * 2.0), true);
|
||||
g_pRenderer->pushFb(shapeFB.m_iFb);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -94,3 +104,19 @@ bool CShape::draw(const SRenderData& data) {
|
|||
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -11,17 +11,26 @@
|
|||
|
||||
class CShape : public IWidget {
|
||||
public:
|
||||
CShape(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props);
|
||||
CShape() = default;
|
||||
virtual ~CShape() = default;
|
||||
|
||||
void registerSelf(const SP<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 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;
|
||||
|
||||
CFramebuffer shapeFB;
|
||||
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CColor color;
|
||||
CHyprColor color;
|
||||
CGradientValueData borderGrad;
|
||||
Vector2D size;
|
||||
Vector2D pos;
|
||||
|
@ -32,6 +41,7 @@ class CShape : public IWidget {
|
|||
std::string halign, valign;
|
||||
|
||||
bool firstRender = true;
|
||||
std::string onclickCommand;
|
||||
|
||||
Vector2D viewport;
|
||||
CShadowable shadow;
|
||||
|
|
Loading…
Reference in a new issue