Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Change hyprlock style & revive randomwall.js script #1144

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .config/ags/modules/cheatsheet/data_keybinds.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const keybindList = [[
{ "keys": ["rightCtrl"], "action": "Dismiss/close sidebar" },

{ "keys": ["Ctrl", "󰖳", "+", "T"], "action": "Change wallpaper+colorscheme" },
{ "keys": ["Alt", "󰖳", "+", "T"], "action": "Change wallpaper randomly+colorscheme" },

// { "keys": ["󰖳", "+", "B"], "action": "Toggle left sidebar" },
// { "keys": ["󰖳", "+", "N"], "action": "Toggle right sidebar" },
Expand Down
21 changes: 16 additions & 5 deletions .config/ags/modules/sideright/centermodules/wifinetworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const NetResource = (icon, command) => {

const CurrentNetwork = () => {
let authLock = false;
// console.log(Network.wifi);
let timeoutId = null;

const bottomSeparator = Box({
className: 'separator-line',
});
Expand Down Expand Up @@ -138,12 +139,14 @@ const CurrentNetwork = () => {
}),
Entry({
className: 'sidebar-wifinetworks-auth-entry',
visibility: false, // Password dots
visibility: false,
onAccept: (self) => {
authLock = false;
networkAuth.revealChild = false;
execAsync(`nmcli device wifi connect '${connectAttempt}' password '${self.text}'`)
.catch(print);
execAsync(['nmcli', 'connection', 'delete', connectAttempt])
.catch(print)
.then(() => execAsync(['nmcli', 'device', 'wifi', 'connect', connectAttempt, 'password', self.text])
.catch(print));
}
})
]
Expand All @@ -153,6 +156,14 @@ const CurrentNetwork = () => {
authLock = true;
connectAttempt = Network.wifi.ssid;
self.revealChild = true;
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
authLock = false;
self.revealChild = false;
Network.wifi.state = 'activated';
}, 20000); // 20 seconds timeout
}
}),
});
Expand Down Expand Up @@ -247,4 +258,4 @@ export default (props) => {
bottomBar,
]
});
}
}
3 changes: 3 additions & 0 deletions .config/ags/scripts/color_generation/applycolor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,6 @@ apply_gtk &
apply_qt &
apply_fuzzel &
apply_term &

#Executing lockcolor.sh on exit
trap '$HOME/.config/ags/scripts/color_generation/lockcolor.sh && $HOME/.config/ags/scripts/color_generation/cavacolor.sh' EXIT
16 changes: 16 additions & 0 deletions .config/ags/scripts/color_generation/cavacolor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Path
SCSS_FILE="$HOME/.local/state/ags/scss/_material.scss"
CAVA_CONFIG="$HOME/.config/cava/config"

# Pick Color
PRIMARY_COLOR=$(grep -oP '\$primary:\s*#\K[0-9A-Fa-f]+' "$SCSS_FILE")

# Update cava config
if [[ -n "$PRIMARY_COLOR" ]]; then
sed -i "s/^foreground\s*=.*/foreground = '#$PRIMARY_COLOR'/" "$CAVA_CONFIG"
fi

# Refresh cava
pkill -USR1 cava
40 changes: 40 additions & 0 deletions .config/ags/scripts/color_generation/lockcolor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Path to file SCSS and Hyprlock configuration
SCSS_FILE="$HOME/.local/state/ags/scss/_material.scss"
TEMPLATE_CONF="$HOME/.config/ags/scripts/templates/hypr/hyprlock.conf"
HYPRLOCK_CONF="$HOME/.config/hypr/hyprlock.conf"

# Reading HEX from variable $primary and $term9 in _material.scss
PRI_COLOR=$(grep -Po '\$primary:\s*#\K[0-9A-Fa-f]+' "$SCSS_FILE")
SEC_COLOR=$(grep -Po '\$term9:\s*#\K[0-9A-Fa-f]+' "$SCSS_FILE")

# Make sure the color is not empty
if [[ -z "$PRI_COLOR" || -z "$SEC_COLOR" ]]; then
echo "Failed to get color from _material.scss"
exit 1
fi

# Change color format to rgba
RGBA_PRI_COLOR=$(printf "rgba(%d, %d, %d, 1.0)" 0x${PRI_COLOR:0:2} 0x${PRI_COLOR:2:2} 0x${PRI_COLOR:4:2})
RGBA_SEC_COLOR=$(printf "rgba(%d, %d, %d, 1.0)" 0x${SEC_COLOR:0:2} 0x${SEC_COLOR:2:2} 0x${SEC_COLOR:4:2})

# Update color template in hyprlock.conf
if [[ -f "$TEMPLATE_CONF" ]]; then
sed -i "s|\(\$text_color = \).*|\1${RGBA_PRI_COLOR}|" "$TEMPLATE_CONF"
sed -i "s|\(\$entry_border_color = \).*|\1${RGBA_PRI_COLOR}|" "$TEMPLATE_CONF"
sed -i "s|\(\$entry_color = \).*|\1${RGBA_PRI_COLOR}|" "$TEMPLATE_CONF"
sed -i "s|\(\$clock_color = \).*|\1${RGBA_SEC_COLOR}|" "$TEMPLATE_CONF"
echo "Updated: $TEMPLATE_CONF"

# give some delay
sleep 1

# Copy the updated template to hyprlock.conf
cp "$TEMPLATE_CONF" "$HYPRLOCK_CONF"
echo "Copied $TEMPLATE_CONF to $HYPRLOCK_CONF"
else
echo "File not found: $TEMPLATE_CONF"
exit 1
fi

60 changes: 59 additions & 1 deletion .config/ags/scripts/color_generation/randomwall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
#!/usr/bin/env bash

XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
CONFIG_DIR="$XDG_CONFIG_HOME/ags"
$CONFIG_DIR/scripts/color_generation/switchwall.sh "$(fd . $(xdg-user-dir PICTURES)/Wallpapers/ -e .png -e .jpg -e .svg | xargs shuf -n1 -e)"

# Cache DIR
CACHE_DIR="$HOME/.cache/swww"
CACHE_FILE="$CACHE_DIR/wall.$ext"
WALLPAPER_DIR="$HOME/Pictures/Wallpapers"

switch() {
imgpath=$1
read scale screenx screeny screensizey < <(hyprctl monitors -j | jq '.[] | select(.focused) | .scale, .x, .y, .height' | xargs)
cursorposx=$(hyprctl cursorpos -j | jq '.x' 2>/dev/null) || cursorposx=960
cursorposx=$(bc <<< "scale=0; ($cursorposx - $screenx) * $scale / 1")
cursorposy=$(hyprctl cursorpos -j | jq '.y' 2>/dev/null) || cursorposy=540
cursorposy=$(bc <<< "scale=0; ($cursorposy - $screeny) * $scale / 1")
cursorposy_inverted=$((screensizey - cursorposy))

if [ -z "$imgpath" ]; then
echo 'Aborted'
exit 0
fi

rm -f "$CACHE_DIR"/wall.*

# Get the extension of the image
ext="${imgpath##*.}"

# Convert to lowercase
ext=$(echo "$ext" | tr '[:upper:]' '[:lower:]')

# Check if the extension is valid
if [[ -z "$ext" || ! "$ext" =~ ^(jpg|jpeg|png|bmp|webp)$ ]]; then
ext="jpg"
fi

# Set the cache file
CACHE_FILE="$CACHE_DIR/wall.$ext"

# Copy the image to the cache directory
cp "$imgpath" "$CACHE_FILE"

ln -sf "$CACHE_FILE" "$CACHE_DIR/wallpaper"

swww img "$imgpath" --transition-step 100 --transition-fps 144 \
--transition-type outer --transition-angle 30 --transition-duration 1 \
--transition-pos "$cursorposx, $cursorposy_inverted"
}

if [ "$1" == "--noswitch" ]; then
imgpath=$(swww query | awk -F 'image: ' '{print $2}')
elif [[ "$1" ]]; then
switch "$1"
else
# Get a random image
imgpath=$(find "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.bmp" -o -iname "*.webp" \) | shuf -n 1)
switch "$imgpath"
fi

# Generate colors for ags n stuff
"$CONFIG_DIR"/scripts/color_generation/colorgen.sh "${imgpath}" --apply --smart
35 changes: 31 additions & 4 deletions .config/ags/scripts/color_generation/switchwall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
CONFIG_DIR="$XDG_CONFIG_HOME/ags"

# Direktori cache untuk wallpaper
CACHE_DIR="$HOME/.cache/swww"
CACHE_FILE="$CACHE_DIR/wall.$ext"


switch() {
imgpath=$1
read scale screenx screeny screensizey < <(hyprctl monitors -j | jq '.[] | select(.focused) | .scale, .x, .y, .height' | xargs)
Expand All @@ -17,9 +22,31 @@ switch() {
exit 0
fi

# agsv1 run-js "wallpaper.set('')"
# sleep 0.1 && agsv1 run-js "wallpaper.set('${imgpath}')" &
swww img "$imgpath" --transition-step 100 --transition-fps 120 \
mkdir -p "$CACHE_DIR"
rm -f "$CACHE_DIR"/wall.*

# Dapatkan ekstensi asli file (jpg, png, dll.)
ext="${imgpath##*.}"

# Pastikan ekstensi dalam huruf kecil
ext=$(echo "$ext" | tr '[:upper:]' '[:lower:]')

# Jika ekstensi kosong atau tidak valid, gunakan default jpg
if [[ -z "$ext" || ! "$ext" =~ ^(jpg|jpeg|png|bmp|webp)$ ]]; then
ext="jpg"
fi

# Simpan gambar dengan nama sesuai format
CACHE_FILE="$CACHE_DIR/wall.$ext"

# Salin dan timpa file lama
cp "$imgpath" "$CACHE_FILE"

ln -sf "$CACHE_FILE" "$CACHE_DIR/wallpaper"

# ags run-js "wallpaper.set('')"
# sleep 0.1 && ags run-js "wallpaper.set('${imgpath}')" &
swww img "$imgpath" --transition-step 100 --transition-fps 144 \
--transition-type grow --transition-angle 30 --transition-duration 1 \
--transition-pos "$cursorposx, $cursorposy_inverted"
}
Expand All @@ -32,7 +59,7 @@ elif [[ "$1" ]]; then
else
# Select and set image (hyprland)

cd "$(xdg-user-dir PICTURES)/Wallpapers" || cd "$(xdg-user-dir PICTURES)" || return 1
cd "$(xdg-user-dir PICTURES)/Wallpapers" || cd "$(xdg-user-dir PICTURES)" || return 1
switch "$(yad --width 1200 --height 800 --file --add-preview --large-preview --title='Choose wallpaper')"
fi

Expand Down
Loading