feat(update): huge changes

This commit is contained in:
sankalp committed 2025-04-25 06:33:51 +05:45
1 parent 53c077106f
commit 6b9b419aa9
98 files changed
+9636 -5575

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
#!/bin/bash
# Print usage information
print_usage() {
cat <<"EOF"
Usage: screen-tools.sh [mode] [option]
Modes:
screenshot [option] Take a screenshot
Options:
p Print all screens
s Snip current screen
sf Snip current screen (frozen)
m Print focused monitor
[mockup] Optional: Add mockup effect to screenshot
record Start/Stop screen recording
ocr Perform OCR on selected area
EOF
}
# OCR functionality
do_ocr() {
sleep 0.25
ocr_text=$(grimblast --freeze save area - | tesseract -l eng - - 2>/dev/null)
# Check if OCR was successful
if [[ -n "$ocr_text" ]]; then
echo -n "$ocr_text" | wl-copy
notify-send -a "Modus" "OCR Success" "Text Copied to Clipboard"
else
notify-send -a "Modus" "OCR Failed" "No text recognized or operation failed"
fi
}
# Screen recording functionality
do_screenrecord() {
if [ -z "$XDG_VIDEOS_DIR" ]; then
XDG_VIDEOS_DIR="$HOME/Videos"
fi
local save_dir="${XDG_VIDEOS_DIR:-$HOME/Videos}/Recordings"
mkdir -p "$save_dir"
if pgrep -f "gpu-screen-recorder" >/dev/null; then
pkill -SIGINT -f "gpu-screen-recorder"
sleep 1
local last_video=$(ls -t "$save_dir"/*.mp4 2>/dev/null | head -n 1)
local action=$(notify-send -a "Modus" "⬜ Recording stopped" \
-A "view=View" -A "open=Open folder")
if [ "$action" = "view" ] && [ -n "$last_video" ]; then
xdg-open "$last_video"
elif [ "$action" = "open" ]; then
xdg-open "$save_dir"
fi
exit 0
fi
local output_file="$save_dir/$(date +%Y-%m-%d-%H-%M-%S).mp4"
notify-send -a "Modus" "🔴 Recording started"
gpu-screen-recorder -w screen -q ultra -a default_output -ac opus -cr full -f 60 -o "$output_file"
}
# Screenshot functionality
do_screenshot() {
sleep 0.25
if [ -z "$XDG_PICTURES_DIR" ]; then
XDG_PICTURES_DIR="$HOME/Pictures"
fi
local save_dir="${3:-$XDG_PICTURES_DIR/Screenshots}"
local save_file=$(date +'%y%m%d_%Hh%Mm%Ss_screenshot.png')
local full_path="$save_dir/$save_file"
mkdir -p "$save_dir"
local mockup_mode="$2"
case $1 in
p) grimblast copysave screen "$full_path" ;;
s) grimblast copysave area "$full_path" ;;
sf) grimblast --freeze copysave area "$full_path" ;;
m) grimblast copysave output "$full_path" ;;
*)
echo "Invalid screenshot mode"
print_usage
exit 1
;;
esac
if [ -f "$full_path" ]; then
if [ "$mockup_mode" = "mockup" ]; then
local temp_file="${full_path%.png}_temp.png"
cropped_file="${full_path%.png}_cropped.png"
local mockup_file="${full_path%.png}_mockup.png"
# First crop the top pixel using a different approach
# Use +0+1 to start at y-coordinate 1 (skipping the first pixel row)
magick "$full_path" -crop +0+1 +repage "$cropped_file"
magick "$cropped_file" \
\( +clone -alpha extract -draw 'fill black polygon 0,0 0,20 20,0 fill white circle 20,20 20,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite "$temp_file"
magick "$temp_file" \
\( +clone -background black -shadow 60x20+0+10 -alpha set -channel A -evaluate multiply 1 +channel \) \
+swap -background none -layers merge +repage "$mockup_file"
rm "$temp_file" "$cropped_file"
mv "$mockup_file" "$full_path"
if command -v wl-copy >/dev/null 2>&1; then
wl-copy <"$full_path"
elif command -v xclip >/dev/null 2>&1; then
xclip -selection clipboard -t image/png <"$full_path"
fi
fi
local action=$(notify-send -a "Modus" -i "$full_path" "Screenshot saved" "in $full_path" \
-A "view=View" -A "edit=Edit" -A "open=Open Folder")
case "$action" in
view) xdg-open "$full_path" ;;
edit) swappy -f "$full_path" ;;
open) xdg-open "$save_dir" ;;
esac
else
notify-send -a "Modus" "Screenshot Aborted"
fi
}
# Handle command line arguments
if [ $# -eq 0 ]; then
print_usage
exit 1
fi
case "$1" in
screenshot)
if [ $# -lt 2 ]; then
echo "Error: Screenshot mode requires an option"
print_usage
exit 1
fi
do_screenshot "$2" "$3"
;;
record)
do_screenrecord
;;
ocr)
do_ocr
;;
*)
echo "Error: Invalid mode '$1'"
print_usage
exit 1
;;
esac
-63
View File
@@ -1,63 +0,0 @@
#!/bin/bash
# Function to get the relative path based on the current script's location
get_relative_path() {
local path=$1
local level=$2
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for ((i = 1; i <= level; i++)); do
script_dir="$(dirname "$script_dir")"
done
echo "$script_dir/$path"
}
# Assign relative paths to variables
GENERATOR=$(get_relative_path "../material-colors/generate.py")
SETTINGS_FILE=$(get_relative_path "../assets/settings.json")
# Function to read a value from the JSON file
get_json_value() {
local key=$1
jq -r --arg key "$key" '.[$key]' $SETTINGS_FILE
}
# Function to update a value in the JSON file
update_json_value() {
local key=$1
local value=$2
jq --arg key "$key" --arg value "$value" \
'.[$key] = $value' $SETTINGS_FILE >"$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" $SETTINGS_FILE
}
toggle() {
local color_scheme=$(get_json_value "color-scheme")
local generation_scheme=$(get_json_value "generation-scheme")
if [ "$color_scheme" == "dark" ]; then
python -O $GENERATOR -R --color-scheme light --scheme $generation_scheme
update_json_value "color-scheme" "light"
elif [ "$color_scheme" == "light" ]; then
python -O $GENERATOR -R --color-scheme dark --scheme $generation_scheme
update_json_value "color-scheme" "dark"
else
echo "Unknown color scheme: $color_scheme"
fi
}
set() {
local new_scheme=$1
local generation_scheme=$(get_json_value "generation-scheme")
python -O $GENERATOR -R --color-scheme $new_scheme --scheme $generation_scheme
update_json_value "color-scheme" $new_scheme
}
# Process arguments
if [[ "$1" == "--toggle" ]]; then
toggle
elif [[ "$1" == "--set" ]]; then
set $2
else
echo "Usage: $0 --toggle | --set <color-scheme>"
fi
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env sh
# Check if animations are disabled (game mode is active)
check_gamemode() {
HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}')
if [ "$HYPRGAMEMODE" = 0 ]; then
echo "t"
return 0
else
echo "f"
return 1
fi
}
# Toggle game mode state
toggle_gamemode() {
HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}')
if [ "$HYPRGAMEMODE" = 1 ]; then
hyprctl --batch "\
keyword animations:enabled 0;\
keyword decoration:shadow:enabled 0;\
keyword decoration:blur:enabled 0;\
keyword general:gaps_in 0;\
keyword general:gaps_out 0;\
keyword general:border_size 1;\
keyword decoration:rounding 0"
exit
fi
hyprctl reload
}
# Main script logic
case "$1" in
check)
check_gamemode
;;
*)
toggle_gamemode
;;
esac
+75
View File
@@ -0,0 +1,75 @@
#!/bin/bash
pick_rgb() {
# Execute hyprpicker with RGB format and save the output to a variable
hyprpicker -a -n -f rgb && sleep 0.1
# Create a temporal 64x64 PNG file with the color in /tmp using convert
magick -size 64x64 xc:"rgb($(wl-paste))" /tmp/color.png
# Send a notification using the file as an icon
notify-send "RGB color picked" "rgb($(wl-paste))" -i /tmp/color.png -a "Hyprpicker"
# Remove the temporal file
rm /tmp/color.png
# Exit
exit 0
}
pick_hex() {
# Execute hyprpicker and save the output to a variable
hyprpicker -a -n -f hex && sleep 0.1
# Create a temporal 64x64 PNG file with the color in /tmp using convert
magick -size 64x64 xc:"$(wl-paste)" /tmp/color.png
# Send a notification using the file as an icon
notify-send "HEX color picked" "$(wl-paste)" -i /tmp/color.png -a "Hyprpicker"
# Remove the temporal file
rm /tmp/color.png
# Exit
exit 0
}
pick_hsv() {
# Copy the color to the clipboard
echo -n "$(hyprpicker -n -f hsv)" | wl-copy -n
# Create a temporal 64x64 PNG file with the color in /tmp using convert
magick -size 64x64 xc:"hsv($(wl-paste))" /tmp/color.png
# Send a notification using the file as an icon
notify-send "HSV color picked" "hsv($(wl-paste))" -i /tmp/color.png -a "Hyprpicker"
# Remove the temporal file
rm /tmp/color.png
# Exit
exit 0
}
case "$1" in
-rgb)
pick_rgb
;;
-hsv)
pick_hsv
;;
-hex)
pick_hex
;;
*)
echo "Usage: $0 [-rgb|-hex|-hsv]"
exit 1
;;
esac
+84 -66
View File
@@ -1,160 +1,178 @@
#!/bin/bash
# Word of caution: changing this can break update module, be vigilant
# Word of caution: Changing this may break the update module, be careful!
# Function to check updates for Arch-based distros
check_arch_updates() {
official_updates=0
aur_updates=0
flatpak_updates=0
tooltip="" # Initialize tooltip variable
tooltip=""
# Get the number of official updates using 'checkupdates'
# Get the number of official updates
official_updates=$(checkupdates 2>/dev/null | wc -l)
# Determine the AUR helper
if command -v paru &>/dev/null; then
aur_helper="paru"
else
aur_helper="yay"
fi
# Get the number of AUR updates using 'yay'
# Get the number of AUR updates
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
# Check for Flatpak updates
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
fi
# Calculate total updates
total_updates=$((official_updates + aur_updates + flatpak_updates))
# Build the tooltip for official updates
tooltip="󰣇 Official $official_updates\n󰮯 AUR $aur_updates"
# Build the tooltip
tooltip="󰣇 Official: $official_updates\n󰮯 AUR: $aur_updates\n Flatpak: $flatpak_updates"
# Check if flatpak is installed
if command -v flatpak &>/dev/null; then
# Get the number of Flatpak updates if flatpak is installed
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
# Append Flatpak updates to the tooltip
tooltip="$tooltip\n Flatpak $flatpak_updates"
# Recalculate total updates
total_updates=$((official_updates + aur_updates + flatpak_updates))
fi
# Output the result as a JSON object
# Output JSON
echo "{\"total\":\"$total_updates\", \"tooltip\":\"$tooltip\"}"
}
# Function to check updates for Ubuntu-based distros
check_ubuntu_updates() {
official_updates=0
flatpak_updates=0
tooltip=""
# Check if flatpak is installed and get Flatpak updates if it is
# Get the number of official updates
official_updates=$(apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst)
# Check for Flatpak updates
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
# Always show Flatpak updates in the tooltip, even if there are none
tooltip="󰕈 Official $official_updates\n Flatpak $flatpak_updates"
else
# If flatpak is not installed, only show official updates
tooltip="󰕈 Official $official_updates"
fi
# Get the number of official updates using 'apt-get'
official_updates=$(apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst)
# Calculate total updates
total_updates=$((official_updates + flatpak_updates))
# Output the result as a JSON object
# Build the tooltip
tooltip="󰕈 Official: $official_updates\n Flatpak: $flatpak_updates"
# Output JSON
echo "{\"total\":\"$total_updates\", \"tooltip\":\"$tooltip\"}"
}
# Function to check updates for Fedora-based distros
check_fedora_updates() {
official_updates=0
flatpak_updates=0
tooltip=""
# Get the number of official updates using 'dnf'
official_updates=$(dnf check-update -q | grep -v '^Loaded plugins' | grep -v '^No match for' | wc -l)
# Get the number of official updates
official_updates=$(dnf list updates -q | tail -n +2 | wc -l)
# Check for Flatpak updates
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
fi
# Calculate total updates
total_updates=$((official_updates + flatpak_updates))
# Check if flatpak is installed and get Flatpak updates if it is
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
# Always show Flatpak updates in the tooltip, even if there are none
tooltip="󰣛 Official $official_updates\n Flatpak $flatpak_updates"
else
# If flatpak is not installed, only show official updates
tooltip="󰣛 Official $official_updates"
fi
# Build the tooltip
tooltip="󰣛 Official: $official_updates\n Flatpak: $flatpak_updates"
# Output the result as a JSON object
# Output JSON
echo "{\"total\":\"$total_updates\", \"tooltip\":\"$tooltip\"}"
}
# Function to check updates for openSUSE-based distros
check_opensuse_updates() {
official_updates=0
flatpak_updates=0
tooltip=""
# Check if flatpak is installed and get Flatpak updates if it is
# Get the number of official updates (skip header lines)
official_updates=$(zypper lu | tail -n +3 | wc -l)
# Check for Flatpak updates
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
fi
# Get the number of official updates using 'dnf'
official_updates=$(zypper lu | wc -l)
# Calculate total updates
total_updates=$((official_updates + flatpak_updates))
# Check if flatpak is installed and get Flatpak updates if it is
if command -v flatpak &>/dev/null; then
flatpak_updates=$(flatpak remote-ls --updates | wc -l)
# Always show Flatpak updates in the tooltip, even if there are none
tooltip=" Official $official_updates\n Flatpak $flatpak_updates"
else
# If flatpak is not installed, only show official updates
tooltip=" Official $official_updates"
fi
# Build the tooltip
tooltip=" Official: $official_updates\n Flatpak: $flatpak_updates"
# Output the result as a JSON object
# Output JSON
echo "{\"total\":\"$total_updates\", \"tooltip\":\"$tooltip\"}"
}
# Function to update Arch-based distros
update_arch() {
command="
fastfetch
yay -Syu
read -n 1 -p 'Press any key to continue...'
"
kitty --title systemupdate sh -c "${command}"
kitty --title "System Update" sh -c "
fastfetch
yay -Syu
read -n 1 -p 'Press any key to continue...'
"
}
# Function to update Ubuntu-based distros
update_ubuntu() {
kitty --title "System Update" sh -c "
neofetch
sudo apt update && sudo apt upgrade -y
read -n 1 -p 'Press any key to continue...'
"
}
# Function to update Fedora-based distros
update_fedora() {
kitty --title "System Update" sh -c "
neofetch
sudo dnf upgrade -y
read -n 1 -p 'Press any key to continue...'
"
}
# Function to update openSUSE-based distros
update_opensuse() {
kitty --title "System Update" sh -c "
neofetch
sudo zypper up -y
read -n 1 -p 'Press any key to continue...'
"
}
# Main case handling for different distributions
case "$1" in
-arch)
if [ -z "$2" ]; then # If second argument is null (not provided)
if [ -z "$2" ]; then
check_arch_updates
else
update_arch
fi
;;
-ubuntu)
if [ -z "$2" ]; then # If second argument is null (not provided)
if [ -z "$2" ]; then
check_ubuntu_updates
else
update_ubuntu
fi
;;
-fedora)
if [ -z "$2" ]; then # If second argument is null (not provided)
if [ -z "$2" ]; then
check_fedora_updates
else
update_fedora
fi
;;
-suse)
if [ -z "$2" ]; then # If second argument is null (not provided)
if [ -z "$2" ]; then
check_opensuse_updates
else
update_arch
update_opensuse
fi
;;
*)
-271
View File
@@ -1,271 +0,0 @@
import os
import sys
import importlib.util
import argparse
import fcntl
import subprocess
import asyncio
import random as _random
import colorsys
import json
import inspect
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 = get_relative_path("../assets/settings.json")
def acquire_lock():
global lock_file
lock_file = open(lock_file_path, "w")
try:
fcntl.flock(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
lock_file.write(str(os.getpid()))
lock_file.flush()
except IOError:
print("Another instance of the script is already running.")
sys.exit(1)
def release_lock():
fcntl.flock(lock_file, fcntl.LOCK_UN)
lock_file.close()
os.remove(lock_file_path)
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(
int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)
)
numeric_hex_color = int(hex_color_str.lstrip("#"), 16)
return numeric_hex_color
def load_settings():
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"
)
args = parser.parse_args()
random = args.random
prev = args.prev
image = args.image
notify = args.notify
status = args.status
HOME = os.path.expanduser("~")
module_path = get_relative_path("../material-colors")
sys.path.append(module_path)
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
cache_file = f"{HOME}/.cache/current_wallpaper"
square = f"{HOME}/.cache/square_wallpaper.png"
png = f"{HOME}/.cache/current_wallpaper.png"
def current_state(state_str: str):
with open(status, "w") as f:
f.write(state_str)
def send_notify(label: str, desc: str):
if not notify:
return
subprocess.run(["notify-send", label, desc])
def state(name: str | None, label: str | None, desc: str | None):
if name is not None:
current_state(name)
if label is not None:
send_notify(label, desc or "")
def join(*args):
return os.path.join(*args)
async def main():
state("init", None, None)
settings = load_settings()
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/example-1.jpg"
# new_wallpaper = get_relative_path("../assets/wallpapers/1.png")
if random:
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:
try:
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:
f.write(new_wallpaper)
with_image = f"with image {new_wallpaper}"
# -----------------------------------------------------
# Set the new wallpaper
# -----------------------------------------------------
transition_type = swww_animation
state("changing", "Changing wallpaper...", with_image)
print(":: Changing wallpaper...")
if wallpaper_engine == "swww":
print(":: Using swww")
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,
]
)
else:
print(":: Wallpaper Engine disabled")
# -----------------------------------------------------
# Generate colors
# -----------------------------------------------------
state("colors", "Generating colors...", with_image)
print(":: Generate colors")
_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,
)
# Generate square and png versions
await asyncio.gather(square_image(new_wallpaper), png_image(new_wallpaper))
state("finish", "Wallpaper procedure complete!", with_image)
async def png_image(wallpaper: str):
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
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
print(f":: Error while processing image: {stderr.decode()}")
else:
print(":: JPG successfully converted to PNG!")
async def square_image(wallpaper):
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
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
print(f":: Error while processing image: {stderr.decode()}")
else:
print(":: Square image created!")
if __name__ == "__main__":
acquire_lock()
try:
asyncio.run(main())
finally:
release_lock()