-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Cicle wallpaper and theme #2
Open
Davi-S
wants to merge
4
commits into
HyDE-Project:master
Choose a base branch
from
Davi-S:cicle-wallpaper-and-theme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Paths to scripts and directories | ||
WALL_SCRIPT="$HOME/.local/share/bin/swwwallpaper.sh" | ||
THEME_SCRIPT="$HOME/.local/share/bin/themeswitch.sh" | ||
#SDDM_SCRIPT="$HOME/bin/setsddmwallpaper" | ||
SDDM_SCRIPT="$HOME/.local/share/bin/setsddmwallpaper.sh" | ||
LOG_FILE="$HOME/.local/share/cyclewallpaperandtheme.log" | ||
WALL_CYCLE_FILE="$HOME/.local/share/cyclewallpapercount" | ||
THEME_CYCLE_FILE="$HOME/.local/share/cyclethemecount" | ||
THEME_CHANGE_FLAG_FILE="$HOME/.local/share/cyclethemeflag" | ||
THEMES_DIR="$HOME/.config/hyde/themes" | ||
HYDE_CONFIG="$HOME/.config/hyde/hyde.conf" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too hardcoded, I will expose a global variables later and will use it so global stuff can be source/imported. Also don't put logs in .local/share. |
||
|
||
# Log messages to file | ||
log() { | ||
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE" | ||
} | ||
|
||
# Safely read a counter file or initialize it | ||
read_or_initialize_counter() { | ||
local file="$1" | ||
[ ! -f "$file" ] && echo 0 > "$file" | ||
cat "$file" | ||
} | ||
|
||
# Increment and save a counter | ||
increment_counter() { | ||
local count="$1" | ||
local max="$2" | ||
local file="$3" | ||
echo $(( (count + 1) % max )) > "$file" | ||
} | ||
|
||
# Cycle to the next theme | ||
cycle_theme() { | ||
# Get theme list | ||
themes=() | ||
while IFS= read -r theme; do | ||
themes+=("$theme") | ||
done < <(find "$THEMES_DIR" -mindepth 1 -maxdepth 1 -type d | sort) | ||
themes=("${themes[@]##*/}") # Strip path to get only names | ||
|
||
# Read and increment theme counter | ||
theme_count=$(read_or_initialize_counter "$THEME_CYCLE_FILE") | ||
next_theme="${themes[$theme_count]}" | ||
increment_counter "$theme_count" "${#themes[@]}" "$THEME_CYCLE_FILE" | ||
|
||
# Apply theme and wait for stability | ||
"$THEME_SCRIPT" -s "$next_theme" >> "$LOG_FILE" 2>&1 | ||
log "Theme changed to: $next_theme" | ||
sleep 3 | ||
} | ||
|
||
# Cycle to the next wallpaper | ||
cycle_wallpaper() { | ||
# Determine current theme and wallpaper directory | ||
current_theme=$(grep '^hydeTheme=' "$HYDE_CONFIG" | sed -E 's/^hydeTheme="([^"]+)"/\1/') | ||
if [ -z "$current_theme" ]; then | ||
log "ERROR: Unable to determine current theme from $HYDE_CONFIG." | ||
exit 1 | ||
fi | ||
|
||
wallpaper_dir="$THEMES_DIR/$current_theme/wallpapers" | ||
if [ ! -d "$wallpaper_dir" ]; then | ||
log "ERROR: Wallpaper directory for theme '$current_theme' does not exist: $wallpaper_dir" | ||
exit 1 | ||
fi | ||
|
||
# Get wallpaper list | ||
wallpapers=("$wallpaper_dir"/*) | ||
total_wallpapers=${#wallpapers[@]} | ||
if [ "$total_wallpapers" -eq 0 ]; then | ||
log "ERROR: No wallpapers found in $wallpaper_dir" | ||
exit 1 | ||
fi | ||
|
||
# Read and increment wallpaper counter | ||
wall_count=$(read_or_initialize_counter "$WALL_CYCLE_FILE") | ||
next_wallpaper="${wallpapers[$wall_count]}" | ||
increment_counter "$wall_count" "$total_wallpapers" "$WALL_CYCLE_FILE" | ||
|
||
# Set wallpaper | ||
"$WALL_SCRIPT" -s "$next_wallpaper" >> "$LOG_FILE" 2>&1 | ||
"$SDDM_SCRIPT" "$next_wallpaper" >> "$LOG_FILE" 2>&1 | ||
log "Wallpaper changed to: $next_wallpaper" | ||
|
||
# If all wallpapers are cycled, flag theme change | ||
if [ "$wall_count" -eq $((total_wallpapers - 1)) ]; then | ||
touch "$THEME_CHANGE_FLAG_FILE" | ||
echo 0 > "$WALL_CYCLE_FILE" | ||
log "Theme change flagged for next run." | ||
fi | ||
} | ||
|
||
# Main execution | ||
if [ -f "$THEME_CHANGE_FLAG_FILE" ]; then | ||
cycle_theme | ||
rm -f "$THEME_CHANGE_FLAG_FILE" | ||
fi | ||
|
||
cycle_wallpaper | ||
log "Cycle operation completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Configuration | ||
SDDM_THEME_CONFIG="/usr/share/sddm/themes/Corners/theme.conf" | ||
BACKGROUND_DIR="/usr/share/sddm/themes/Corners/backgrounds" | ||
WALLPAPER_NAME="customwallpaper" | ||
|
||
# Log messages | ||
log() { | ||
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" | ||
} | ||
|
||
# Validate input | ||
if [ -z "$1" ]; then | ||
log "ERROR: No wallpaper path provided." | ||
exit 1 | ||
fi | ||
|
||
WALLPAPER_PATH="$1" | ||
if [ ! -f "$WALLPAPER_PATH" ]; then | ||
log "ERROR: Wallpaper file does not exist: $WALLPAPER_PATH" | ||
exit 1 | ||
fi | ||
|
||
# Update SDDM wallpaper | ||
cp -f "$WALLPAPER_PATH" "$BACKGROUND_DIR/$WALLPAPER_NAME" | ||
sed -i "s|^Background=.*|Background=\"backgrounds/$WALLPAPER_NAME\"|" "$SDDM_THEME_CONFIG" | ||
|
||
log "SDDM wallpaper updated to: $BACKGROUND_DIR/$WALLPAPER_NAME" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use bash in your shebang if the script is not POSIX (sh) at all, so the linters won't scream.