updates: README.md

This commit is contained in:
sankalp committed 2025-02-17 22:28:56 +05:45
1 parent 0cefd1f31e
commit 88310be397
86 files changed
+183 -23196

No files matched your search

-100
View File
@@ -1,100 +0,0 @@
#!/bin/bash
notif="$HOME/dotfiles/hypr/assets/bell.png"
######################################
# #
# Toggle Animation #
# #
######################################
toggle_animation() {
cache_file="/tmp/toggle_animation"
if [ -f $cache_file ]; then
hyprctl keyword animations:enabled true
ags -r 'enableAnimations(true)'
rm $cache_file
else
hyprctl keyword animations:enabled false
ags -r 'enableAnimations(false)'
touch $cache_file
fi
}
################################################
# #
# Change Layout Master to Dwindle #
# #
################################################
change_layout() {
LAYOUT=$(hyprctl -j getoption general:layout | jq -r '.str')
case $LAYOUT in
"master")
hyprctl keyword general:layout dwindle
hyprctl keyword unbind SUPER,J
hyprctl keyword unbind SUPER,K
hyprctl keyword bind SUPER,J,cyclenext
hyprctl keyword bind SUPER,K,cyclenext,prev
hyprctl keyword bind SUPER,O,togglesplit
notify-send -u low -i "$notif" "Dwindle Layout"
;;
"dwindle")
hyprctl keyword general:layout master
hyprctl keyword unbind SUPER,J
hyprctl keyword unbind SUPER,K
hyprctl keyword unbind SUPER,O
hyprctl keyword bind SUPER,J,layoutmsg,cyclenext
hyprctl keyword bind SUPER,K,layoutmsg,cycleprev
notify-send -u low -i "$notif" "Master Layout"
;;
*) ;;
esac
}
######################################
# #
# GameMode #
# #
######################################)
gamemode() {
status=$(hyprctl getoption animations:enabled -j | jq ".int")
if [[ $status -eq 1 ]]; then
notify-send -e -u low -i "$notif" "All animations off"
hyprctl keyword animations:enabled 0
swww kill
else
notify-send -e -u normal -i "$notif" "All animations normal"
hyprctl keyword animations:enabled 1
swww query || swww init && $random_wall
fi
}
######################################
# #
# Keyboard Layout Switcher #
# #
######################################
kb_changer() {
layout_f="$HOME/.cache/kb_layout"
settings_file="$HOME/dotfiles/hypr/UserConfigs/UserSettings.conf"
current_layout=$(cat "$layout_f")
[ -f "$settings_file" ] && IFS=',' read -ra layout_mapping <<< "$(grep 'kb_layout=' "$settings_file" | cut -d '=' -f 2)"
for i in "${!layout_mapping[@]}"; do
[ "$current_layout" == "${layout_mapping[i]}" ] && new_layout="${layout_mapping[((i + 1) % ${#layout_mapping[@]})]}" && break
done
hyprctl switchxkblayout "at-translated-set-2-keyboard" "$new_layout" && echo "$new_layout" > "$layout_f"
hyprctl devices -j | jq -r '.keyboards[].name' | while read -r name; do
hyprctl switchxkblayout "$name" next || { notify-send -u low -t 2000 'Keyboard layout' 'Error: Layout change failed'; exit 1; }
done
notify-send -u low "Kb_layout" "Changed"
}
-18
View File
@@ -1,18 +0,0 @@
#!/bin/bash
# Path to your JSON file
JSON_FILE="$HOME/dotfiles/.settings/apps.json"
# Read the application type from the argument
APP_TYPE=$1
# Extract the corresponding application value from the JSON file using jq
APP=$(jq -r ".$APP_TYPE" "$JSON_FILE")
# Check if the application is defined in the JSON file
if [ "$APP" != "null" ]; then
# Open the specified application
$APP
else
echo "No application defined for $APP_TYPE in $JSON_FILE"
fi
-106
View File
@@ -1,106 +0,0 @@
#!/bin/bash
# This script is used for the lockscreen battery indicator.
for bat in /sys/class/power_supply/BAT*; do
if [ -e "$bat/uevent" ]; then
BAT_PATH="$bat"
break
fi
done
if [ -z "$BAT_PATH" ]; then
echo "No battery found."
exit 1
fi
# Read battery status and capacity from the uevent file
POWER_SUPPLY_STATUS=$(grep "^POWER_SUPPLY_STATUS=" "$BAT_PATH/uevent" | cut -d'=' -f2)
POWER_SUPPLY_CAPACITY=$(grep "^POWER_SUPPLY_CAPACITY=" "$BAT_PATH/uevent" | cut -d'=' -f2)
# Check if the values are actually found
if [ -z "$POWER_SUPPLY_STATUS" ] || [ -z "$POWER_SUPPLY_CAPACITY" ]; then
echo "Error: Could not read battery status or capacity."
exit 1
fi
declare -A battery_icons_charging=(
[100]="battery_charging_full"
[90]="battery_charging_90"
[80]="battery_charging_80"
[70]="battery_charging_80"
[60]="battery_charging_60"
[50]="battery_charging_50"
[40]="battery_charging_30"
[30]="battery_charging_30"
[20]="battery_charging_20"
[10]="battery_charging_20"
[0]="battery_charging_20"
)
declare -A battery_icons=(
[100]="battery_full"
[90]="battery_6_bar"
[80]="battery_5_bar"
[70]="battery_5_bar"
[60]="battery_4_bar"
[50]="battery_3_bar"
[40]="battery_2_bar"
[30]="battery_2_bar"
[20]="battery_1_bar"
[10]="battery_1_bar"
[0]="battery_alert"
)
get_closest_battery_icon() {
local level="$1"
local charging="$2"
local -n icons_array
if [ "$charging" = "true" ]; then
icons_array=battery_icons_charging
else
icons_array=battery_icons
fi
local levels=($(for key in "${!icons_array[@]}"; do echo "$key"; done | sort -nr))
for threshold in "${levels[@]}"; do
if [ "$level" -ge "$threshold" ]; then
echo "${icons_array[$threshold]}"
return
fi
done
echo "${icons_array[${levels[-1]}]}"
}
icon() {
local capacity="$POWER_SUPPLY_CAPACITY"
local charging="false"
if [ "$POWER_SUPPLY_STATUS" = "Charging" ]; then
charging="true"
fi
get_closest_battery_icon "$capacity" "$charging"
}
info() {
cat "$BAT_PATH/uevent"
}
status() {
echo "$POWER_SUPPLY_CAPACITY%"
}
case $1 in
info) info ;;
icon) icon ;;
status) status ;;
*)
echo "Usage: $0 {info|icon|status}"
exit 1
;;
esac
@@ -1,24 +0,0 @@
#!/bin/bash
# Path to your settings JSON file
settings_file="$HOME/dotfiles/.settings/settings.json"
# Read wallpaper engine from the JSON file
wallpaper_engine=$(jq -r '.["wallpaper-engine"]' "$settings_file")
if [ "$wallpaper_engine" == "swww" ]; then
# swww
echo ":: Using swww"
swww-daemon
swww-daemon --format xrgb
sleep 0.5
python -O ~/dotfiles/hypr/scripts/wallpaper.py -P
elif [ "$wallpaper_engine" == "hyprpaper" ]; then
# hyprpaper
echo ":: Using hyprpaper"
sleep 0.5
python -O ~/dotfiles/hypr/scripts/wallpaper.py -P
else
echo ":: Wallpaper Engine disabled"
python -O ~/dotfiles/hypr/scripts/wallpaper.py -P
fi
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
layout_f="$HOME/.cache/kb_layout"
settings_file="$HOME/dotfiles/hypr/UserConfigs/UserSettings.conf"
current_layout=$(cat "$layout_f")
[ -f "$settings_file" ] && IFS=',' read -ra layout_mapping <<<"$(grep 'kb_layout=' "$settings_file" | cut -d '=' -f 2)"
for i in "${!layout_mapping[@]}"; do
[ "$current_layout" == "${layout_mapping[i]}" ] && new_layout="${layout_mapping[((i + 1) % ${#layout_mapping[@]})]}" && break
done
hyprctl switchxkblayout "at-translated-set-2-keyboard" "$new_layout" && echo "$new_layout" >"$layout_f"
hyprctl devices -j | jq -r '.keyboards[].name' | while read -r name; do
hyprctl switchxkblayout "$name" next || {
notify-send -u low -t 2000 'Keyboard layout' 'Error: Layout change failed'
exit 1
}
done
notify-send -u low "Kb_layout" "Changed"
+5
View File
@@ -0,0 +1,5 @@
{
"color-scheme": "dark",
"custom-color": "none",
"generation-scheme": "tonalSpot"
}
+104 -84
View File
@@ -8,14 +8,27 @@ import asyncio
import random as _random
import colorsys
import json
import inspect
lock_file_path = '/tmp/wallpaper.lock'
settings_file_path = os.path.expanduser('~/dotfiles/.settings/settings.json')
def get_relative_path(path: str, level: int = 1) -> str:
prev_globals = inspect.stack()[level][0].f_globals
file_var = (
os.path.dirname(os.path.abspath(prev_globals["__file__"]))
if "__file__" in prev_globals
else os.getcwd()
)
return os.path.join(file_var, path)
lock_file_path = "/tmp/wallpaper.lock"
# settings_file_path = os.path.expanduser("~/dotfiles/.settings/settings.json")
settings_file_path = get_relative_path("./settings.json")
def acquire_lock():
global lock_file
lock_file = open(lock_file_path, 'w')
lock_file = open(lock_file_path, "w")
try:
fcntl.flock(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
lock_file.write(str(os.getpid()))
@@ -34,25 +47,45 @@ def release_lock():
def hue_to_numeric_hex(hue):
hue = hue / 360.0
rgb = colorsys.hls_to_rgb(hue, 0.5, 1.0)
hex_color_str = '#{:02x}{:02x}{:02x}'.format(
hex_color_str = "#{:02x}{:02x}{:02x}".format(
int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
)
numeric_hex_color = int(hex_color_str.lstrip('#'), 16)
numeric_hex_color = int(hex_color_str.lstrip("#"), 16)
return numeric_hex_color
def load_settings():
with open(settings_file_path, 'r') as file:
default_settings = {
"color-scheme": "dark",
"custom-color": "none",
"generation-scheme": "tonalSpot",
}
if not os.path.exists(settings_file_path):
os.makedirs(os.path.dirname(settings_file_path), exist_ok=True)
with open(settings_file_path, "w") as file:
json.dump(default_settings, file, indent=4)
with open(settings_file_path, "r") as file:
return json.load(file)
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-I', '--image', type=str, help="Image")
group.add_argument('-P', '--prev', help="Use last used wallpaper for color generation", action='store_true')
group.add_argument('-R', '--random', help="Random image from folder", action='store_true')
parser.add_argument('-n', '--notify', help="Send notifications", action='store_true')
parser.add_argument('--status', type=str, help="Status file", default="/tmp/wallpaper.status")
group.add_argument("-I", "--image", type=str, help="Image")
group.add_argument(
"-P",
"--prev",
help="Use last used wallpaper for color generation",
action="store_true",
)
group.add_argument(
"-R", "--random", help="Random image from folder", action="store_true"
)
parser.add_argument("-n", "--notify", help="Send notifications", action="store_true")
parser.add_argument(
"--status", type=str, help="Status file", default="/tmp/wallpaper.status"
)
args = parser.parse_args()
@@ -64,15 +97,15 @@ status = args.status
HOME = os.path.expanduser("~")
module_path = f'{HOME}/dotfiles/material-colors'
module_path = f"{HOME}/dotfiles/material-colors"
sys.path.append(module_path)
module_name = 'generate'
file_path = f'{module_path}/{module_name}.py'
module_name = "generate"
file_path = f"{module_path}/{module_name}.py"
spec = importlib.util.spec_from_file_location(module_name, file_path)
GENERATOR = importlib.util.module_from_spec(spec) # type: ignore
spec.loader.exec_module(GENERATOR) # type: ignore
spec.loader.exec_module(GENERATOR) # type: ignore
cache_file = f"{HOME}/.cache/current_wallpaper"
square = f"{HOME}/.cache/square_wallpaper.png"
@@ -80,7 +113,7 @@ png = f"{HOME}/.cache/current_wallpaper.png"
def current_state(state_str: str):
with open(status, 'w') as f:
with open(status, "w") as f:
f.write(state_str)
@@ -102,22 +135,30 @@ def join(*args):
async def main():
global color_scheme, custom_color, generation_scheme, swww_animation, wallpaper_engine, hyprpaper_tpl
# global \
# color_scheme, \
# custom_color, \
# generation_scheme, \
# swww_animation, \
# wallpaper_engine
state("init", None, None)
settings = load_settings()
color_scheme = settings['color-scheme']
custom_color = settings['custom-color']
generation_scheme = settings['generation-scheme']
swww_animation = settings['swww-anim']
wallpaper_engine = settings['wallpaper-engine']
hyprpaper_tpl = settings['hyprpaper-tpl']
color_scheme = settings["color-scheme"]
custom_color = settings["custom-color"]
generation_scheme = settings["generation-scheme"]
swww_animation = "wipe"
wallpaper_engine = "swww"
new_wallpaper = f"{HOME}/Pictures/wallpapers/1.png"
if random:
files = [f for f in os.listdir(f"{HOME}/Pictures/wallpapers/") if f.endswith(('.png', '.jpg', '.jpeg'))]
files = [
f
for f in os.listdir(f"{HOME}/Pictures/wallpapers/")
if f.endswith((".png", ".jpg", ".jpeg"))
]
if files:
new_wallpaper = join(f"{HOME}/Pictures/wallpapers", _random.choice(files))
elif prev:
@@ -125,13 +166,13 @@ async def main():
with open(cache_file) as f:
new_wallpaper = f.read().strip()
except FileNotFoundError:
...
pass
elif image is not None:
new_wallpaper = os.path.abspath(image)
print(f":: Wallpaper {new_wallpaper}")
with open(cache_file, 'w') as f:
with open(cache_file, "w") as f:
f.write(new_wallpaper)
with_image = f"with image {new_wallpaper}"
@@ -148,31 +189,25 @@ async def main():
if wallpaper_engine == "swww":
print(":: Using swww")
cursor_pos = subprocess.getoutput('hyprctl cursorpos').replace(", ", ",")
cursor_pos = subprocess.getoutput("hyprctl cursorpos").replace(", ", ",")
subprocess.run([
'swww', 'img', new_wallpaper,
'--transition-bezier', '.43,1.19,1,.4',
'--transition-fps', '60',
'--transition-type', transition_type,
'--transition-duration', '0.7',
'--transition-pos', cursor_pos
])
elif wallpaper_engine == "hyprpaper":
print(":: Using hyprpaper")
subprocess.run(['killall', 'hyprpaper'])
output = hyprpaper_tpl.replace('WALLPAPER', new_wallpaper)
hyprpaper_conf_file = os.path.expanduser('~/dotfiles/hypr/hyprpaper.conf')
with open(hyprpaper_conf_file, 'w') as file:
file.write(output)
subprocess.run([
"hyprctl", "dispatch", "exec", "hyprpaper"
])
subprocess.run(
[
"swww",
"img",
new_wallpaper,
"--transition-bezier",
".43,1.19,1,.4",
"--transition-fps",
"60",
"--transition-type",
transition_type,
"--transition-duration",
"0.7",
"--transition-pos",
cursor_pos,
]
)
else:
print(":: Wallpaper Engine disabled")
@@ -182,47 +217,35 @@ async def main():
# -----------------------------------------------------
state("colors", "Generating colors...", with_image)
print(":: Generate colors")
_starts_with = (lambda x: str(x).startswith("-"))
_starts_with = lambda x: str(x).startswith("-")
GENERATOR.main(
color_scheme, new_wallpaper,
(hue_to_numeric_hex(int(custom_color.lstrip("-")))
if _starts_with(custom_color) else (
int(custom_color.lstrip('#'), 16)
if custom_color != "none"
else None
)),
scheme_name=generation_scheme
color_scheme,
new_wallpaper,
(
hue_to_numeric_hex(int(custom_color.lstrip("-")))
if _starts_with(custom_color)
else (int(custom_color.lstrip("#"), 16) if custom_color != "none" else None)
),
scheme_name=generation_scheme,
)
# -----------------------------------------------------
# Square image
# -----------------------------------------------------
square_task = asyncio.create_task(square_image(new_wallpaper))
# Generate square and png versions
await asyncio.gather(square_image(new_wallpaper), png_image(new_wallpaper))
# -----------------------------------------------------
# Png image
# -----------------------------------------------------
png_task = asyncio.create_task(png_image(new_wallpaper))
state("tasks", None, None)
await asyncio.gather(square_task, png_task)
state("finish", "Wallpaper procedure complete!", with_image)
async def png_image(wallpaper: str):
_from = (".jpg", "jpeg")
if not wallpaper.endswith(_from):
cmd = f"cp -f {wallpaper} {png}"
else:
with_image = f"with image {wallpaper}"
state(None, "Converting jpg to png...", with_image)
if wallpaper.lower().endswith((".jpg", ".jpeg")):
state(None, "Converting jpg to png...", f"with image {wallpaper}")
print(":: Converting jpg to png...")
cmd = f"magick {wallpaper}[0] {png}"
else:
cmd = f"cp -f {wallpaper} {png}"
process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
@@ -233,14 +256,11 @@ async def png_image(wallpaper: str):
async def square_image(wallpaper):
with_image = f"with image {wallpaper}"
state(None, "Creating square version...", with_image)
state(None, "Creating square version...", f"with image {wallpaper}")
print(":: Creating square version")
cmd = f"magick {wallpaper}[0] -gravity Center -extent 1:1 {square}"
process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()