@@ -11,6 +11,8 @@ scrDir=${scrDir:-$HOME/.local/lib/hyde}
1111confDir=" ${confDir:- $XDG_CONFIG_HOME } "
1212cacheDir=" ${HYDE_CACHE_HOME:- " ${XDG_CACHE_HOME} /hyde" } "
1313WALLPAPER=" ${cacheDir} /wall.set"
14+ HYPRLOCK_SCOPE_NAME=" hyde-${XDG_SESSION_DESKTOP:- unknown} -lockscreen.scope"
15+
1416
1517USAGE () {
1618 cat << EOF
@@ -74,12 +76,12 @@ fn_mpris() {
7476 if [ -f " $HOME /.face.icon" ]; then
7577 if ! cmp -s " $HOME /.face.icon" " ${THUMB} .png" ; then
7678 cp -f " $HOME /.face.icon" " ${THUMB} .png"
77- pkill -USR2 hyprlock > /dev/null 2>&1 # updates the mpris thumbnail
79+ reload_hyprlock
7880 fi
7981 else
8082 if ! cmp -s " $XDG_DATA_HOME /icons/Wallbash-Icon/hyde.png" " ${THUMB} .png" ; then
8183 cp " $XDG_DATA_HOME /icons/Wallbash-Icon/hyde.png" " ${THUMB} .png"
82- pkill -USR2 hyprlock > /dev/null 2>&1 # updates the mpris thumbnail
84+ reload_hyprlock
8385 fi
8486 fi
8587 exit 1
@@ -116,7 +118,7 @@ mpris_thumb() { # Generate thumbnail for mpris
116118 echo " ${artUrl} " > " ${THUMB} " .lnk
117119 curl -Lso " ${THUMB} " .art " $artUrl "
118120 magick " ${THUMB} .art" -quality 50 " ${THUMB} .png"
119- pkill -USR2 hyprlock > /dev/null 2>&1 # updates the mpris thumbnail
121+ reload_hyprlock
120122}
121123
122124fn_cava () {
@@ -133,6 +135,17 @@ fn_art() {
133135 echo " ${cacheDir} /landing/mpris.art"
134136}
135137
138+ find_filepath () {
139+ local filename=" ${*:- $1 } "
140+ local search_dirs=(
141+ " ${XDG_CONFIG_HOME:- $HOME / .config} /hypr/hyprlock"
142+ " ${XDG_CONFIG_HOME:- $HOME / .config} /hyde/hyprlock"
143+ " ${HYPRLOCK_CONF_DIR} "
144+ )
145+ print_log -sec " hyprlock" -stat " Searching for layout" " $filename "
146+ find " ${search_dirs[@]} " -type f -name " ${filename} *" 2> /dev/null | head -n 1
147+ }
148+
136149# hyprlock selector
137150fn_select () {
138151 # Set rofi scaling
@@ -164,7 +177,7 @@ fn_select() {
164177 fi
165178
166179 layout_items=" Theme Preference
167- $layout_items "
180+ ${ layout_items} "
168181
169182 selected_layout=$( awk -F/ ' {print $NF}' <<< " $layout_items" |
170183 rofi -dmenu -i -select " ${HYPRLOCK_LAYOUT} " \
@@ -173,29 +186,128 @@ $layout_items"
173186 -theme-str " ${font_override} " \
174187 -theme-str " ${r_override} " \
175188 -theme-str " $( get_rofi_pos) " \
176- -theme " ${ROFI_HYPRLOCK_STYLE:- clipboard} " )
189+ -on-selection-changed " hyde-shell hyprlock.sh --test-preview \" {entry}\" " \
190+ -theme " ${ROFI_HYPRLOCK_STYLE:- clipboard} " )
191+
177192 if [ -z " $selected_layout " ]; then
178193 echo " No selection made"
179194 exit 0
180195 fi
181- set_conf " HYPRLOCK_LAYOUT" " ${selected_layout} "
196+
197+ set_conf " HYPRLOCK_LAYOUT" " ${selected_layout} "
182198 if [ " $selected_layout " == " Theme Preference" ]; then
183199 selected_layout=" theme"
184200 fi
185- generate_conf " ${layout_dir} /${selected_layout} .conf"
186- " ${scrDir} /font.sh" resolve " ${layout_dir} /${selected_layout} .conf"
201+ local hyprlock_conf_path
202+ hyprlock_conf_path=$( find_filepath " ${selected_layout} " )
203+ generate_conf " $hyprlock_conf_path "
204+ " ${scrDir} /font.sh" resolve " $hyprlock_conf_path "
187205 fn_profile
188206
189207 # Notify the user
190208 notify-send -i " system-lock-screen" " Hyprlock layout:" " ${selected_layout} "
191209
210+ }
211+
212+ check_and_sanitize_process () {
213+ local unit_name=" ${1:- ${HYPRLOCK_SCOPE_NAME} } "
214+ if systemctl --user is-active " ${unit_name} " > /dev/null 2>&1 ; then
215+ systemctl --user stop " ${unit_name} " > /dev/null 2>&1
216+ fi
217+ }
218+
219+ reload_hyprlock () {
220+ local unit_name=" ${2:- ${HYPRLOCK_SCOPE_NAME} } "
221+
222+ if systemctl --user is-active " ${unit_name} " > /dev/null 2>&1 ; then
223+ systemctl --user kill -s USR2 " ${HYPRLOCK_SCOPE_NAME} " > /dev/null 2>&1
224+ else
225+ pkill -USR2 hyprlock > /dev/null 2>&1
226+ fi
227+
228+ }
229+
230+ append_label_to_file () {
231+ local file=" ${1} "
232+
233+ cat << EOF >>"${file} "
234+ label {
235+ text = PREVIEW! Press a key or swipe to exit.
236+ color = rgba(\$ wallbash_txt122)
237+ font_size = 50
238+ position = 0, 0
239+ halign = center
240+ valign = top
241+ zindex = 6
242+ }
243+
244+ label {
245+ text = PREVIEW! Press a key or swipe to exit.
246+ color = rgba(\$ wallbash_txt122)
247+ font_size = 50
248+ position = 0, 0
249+ halign = center
250+ valign = bottom
251+ zindex = 6
252+ }
253+
254+ label {
255+ text = PREVIEW! Press a key or swipe to exit.
256+ color = rgba(\$ wallbash_txt122)
257+ font_size = 50
258+ position = 0, 0
259+ halign = center
260+ valign = center
261+ zindex = 6
262+ }
263+
264+ EOF
265+
266+ }
267+
268+
269+ layout_test () {
270+ print_log -sec " hyprlock" -stat " Test" " Please swipe,press a key or click to exit."
271+ local hyprlock_conf_name=" ${*:- ${1} } "
272+ if [[ " ${hyprlock_conf_name} " == " Theme Preference" ]]; then
273+ hyprlock_conf_name=" theme"
274+ fi
275+ check_and_sanitize_process
276+ hyprlock_conf_path=$( find_filepath " ${hyprlock_conf_name} " )
277+ if [ -z " ${hyprlock_conf_path} " ]; then
278+ print_log -sec " hyprlock" -stat " Error" " Layout ${hyprlock_conf_name} not found."
279+ exit 1
280+ fi
281+ sleep 2
282+ local temp_path=" ${XDG_RUNTIME_DIR} /hyde/hyprlock-test.conf"
283+ generate_conf " ${hyprlock_conf_path} " " ${temp_path} "
284+ append_label_to_file " ${temp_path} "
285+ app2unit.sh -S both -u " ${HYPRLOCK_SCOPE_NAME} " -t scope -- hyprlock --no-fade-in --immediate-render --grace 99999999 -c " ${temp_path} "
286+ rm -f " ${temp_path} "
287+ }
288+
289+ rofi_test_preview () {
290+ # ? this function provides an anti spam mechanism for the rofi preview
291+ local hyprlock_conf_name=" ${*:- ${1} } "
292+ if [[ " ${hyprlock_conf_name} " == " Theme Preference" ]]; then
293+ hyprlock_conf_name=" theme"
294+ fi
295+ local unit_name=" hyde-${XDG_SESSION_DESKTOP:- unknown} -lockscreen-preview.scope"
296+ check_and_sanitize_process " ${unit_name} "
297+ send_notifs " Hyprlock layout: ${hyprlock_conf_name} " " Please swipe, press a key or click to exit." \
298+ -i " system-lock-screen" -t 3000 \
299+ -r 9
300+ app2unit.sh -S both -u " ${unit_name} " -t scope -- hyprlock.sh --test " ${hyprlock_conf_name} "
301+
302+
192303}
193304
194305generate_conf () {
195306 local path=" ${1:- $confDir / hypr/ hyprlock/ theme.conf} "
307+ local target_file=" ${2:- $confDir / hypr/ hyprlock.conf} "
196308 local hyde_hyprlock_conf=${SHARE_DIR:- $XDG_DATA_HOME } /hyde/hyprlock.conf
197309
198- cat << CONF >"$confDir /hypr/hyprlock.conf "
310+ cat << CONF >"${target_file} "
199311#! █░█ █▄█ █▀█ █▀█ █░░ █▀█ █▀▀ █▄▀
200312#! █▀█ ░█░ █▀▀ █▀▄ █▄▄ █▄█ █▄▄ █░█
201313
@@ -316,12 +428,13 @@ if [ -z "${*}" ]; then
316428 print_log -sec " hyprlock" -stat " setting" " $HYDE_CACHE_HOME /wallpapers/hyprlock.png"
317429 " ${scrDir} /wallpaper.sh" -s " $( readlink " ${HYDE_THEME_DIR} /wall.set" ) " --backend hyprlock
318430 fi
319- pidof hyprlock || hyprlock
431+ check_and_sanitize_process
432+ app2unit.sh -u " ${HYPRLOCK_SCOPE_NAME} " -t scope -- hyprlock
320433 exit 0
321434fi
322435
323436# Define long options
324- LONGOPTS=" select,background,profile,mpris:,cava,art,help"
437+ LONGOPTS=" select,background,profile,mpris:,cava,art,help,test:,test-preview: "
325438
326439# Parse options
327440PARSED=$(
@@ -335,6 +448,14 @@ eval set -- "$PARSED"
335448
336449while true ; do
337450 case " $1 " in
451+ --test)
452+ layout_test " ${2} "
453+ exit 0
454+ ;;
455+ --test-preview)
456+ rofi_test_preview " ${2} "
457+ exit 0
458+ ;;
338459 select | -S | --select)
339460 fn_select
340461 exit 0
0 commit comments