feat(background): show clock for video wallpapers. (#1719)

This commit is contained in:
end-4
2025-07-30 07:30:15 +02:00
committed by GitHub
3 changed files with 98 additions and 87 deletions
@@ -37,12 +37,12 @@ Scope {
property int firstWorkspaceId: relevantWindows[0]?.workspace.id || 1 property int firstWorkspaceId: relevantWindows[0]?.workspace.id || 1
property int lastWorkspaceId: relevantWindows[relevantWindows.length - 1]?.workspace.id || 10 property int lastWorkspaceId: relevantWindows[relevantWindows.length - 1]?.workspace.id || 10
// Wallpaper // Wallpaper
property string wallpaperPath: Config.options.background.wallpaperPath
property bool wallpaperIsVideo: Config.options.background.wallpaperPath.endsWith(".mp4") property bool wallpaperIsVideo: Config.options.background.wallpaperPath.endsWith(".mp4")
|| Config.options.background.wallpaperPath.endsWith(".webm") || Config.options.background.wallpaperPath.endsWith(".webm")
|| Config.options.background.wallpaperPath.endsWith(".mkv") || Config.options.background.wallpaperPath.endsWith(".mkv")
|| Config.options.background.wallpaperPath.endsWith(".avi") || Config.options.background.wallpaperPath.endsWith(".avi")
|| Config.options.background.wallpaperPath.endsWith(".mov") || Config.options.background.wallpaperPath.endsWith(".mov")
property string wallpaperPath: wallpaperIsVideo ? Config.options.background.thumbnailPath : Config.options.background.wallpaperPath
property real preferredWallpaperScale: Config.options.background.parallax.workspaceZoom property real preferredWallpaperScale: Config.options.background.parallax.workspaceZoom
property real effectiveWallpaperScale: 1 // Some reasonable init value, to be updated property real effectiveWallpaperScale: 1 // Some reasonable init value, to be updated
property int wallpaperWidth: modelData.width // Some reasonable init value, to be updated property int wallpaperWidth: modelData.width // Some reasonable init value, to be updated
@@ -148,7 +148,7 @@ Scope {
// Wallpaper // Wallpaper
Image { Image {
id: wallpaperImage id: wallpaper
visible: !bgRoot.wallpaperIsVideo visible: !bgRoot.wallpaperIsVideo
property real value // 0 to 1, for offset property real value // 0 to 1, for offset
value: { value: {
@@ -176,13 +176,14 @@ Scope {
width: bgRoot.screen.width * bgRoot.effectiveWallpaperScale width: bgRoot.screen.width * bgRoot.effectiveWallpaperScale
height: bgRoot.screen.height * bgRoot.effectiveWallpaperScale height: bgRoot.screen.height * bgRoot.effectiveWallpaperScale
} }
}
// The clock // The clock
Item { Item {
id: clock id: clock
anchors { anchors {
left: parent.left left: wallpaper.left
top: parent.top top: wallpaper.top
leftMargin: ((root.fixedClockPosition ? root.fixedClockX : bgRoot.clockX * bgRoot.effectiveWallpaperScale) - implicitWidth / 2) - (wallpaperImage.effectiveValue * bgRoot.movableXSpace) leftMargin: ((root.fixedClockPosition ? root.fixedClockX : bgRoot.clockX * bgRoot.effectiveWallpaperScale) - implicitWidth / 2) - (wallpaperImage.effectiveValue * bgRoot.movableXSpace)
topMargin: ((root.fixedClockPosition ? root.fixedClockY : bgRoot.clockY * bgRoot.effectiveWallpaperScale) - implicitHeight / 2) topMargin: ((root.fixedClockPosition ? root.fixedClockY : bgRoot.clockY * bgRoot.effectiveWallpaperScale) - implicitHeight / 2)
Behavior on leftMargin { Behavior on leftMargin {
@@ -198,7 +199,7 @@ Scope {
ColumnLayout { ColumnLayout {
id: clockColumn id: clockColumn
anchors.centerIn: parent anchors.centerIn: wallpaper
spacing: 0 spacing: 0
StyledText { StyledText {
@@ -264,7 +265,6 @@ Scope {
} }
} }
}
// Password prompt // Password prompt
StyledText { StyledText {
@@ -115,6 +115,7 @@ Singleton {
property real clockX: -500 property real clockX: -500
property real clockY: -500 property real clockY: -500
property string wallpaperPath: "" property string wallpaperPath: ""
property string thumbnailPath: ""
property JsonObject parallax: JsonObject { property JsonObject parallax: JsonObject {
property bool enableWorkspace: true property bool enableWorkspace: true
property real workspaceZoom: 1.07 // Relative to your screen, not wallpaper size property real workspaceZoom: 1.07 // Relative to your screen, not wallpaper size
@@ -110,15 +110,15 @@ check_and_prompt_upscale() {
fi fi
} }
THUMBNAIL_DIR="/tmp/mpvpaper_thumbnails"
CUSTOM_DIR="$XDG_CONFIG_HOME/hypr/custom" CUSTOM_DIR="$XDG_CONFIG_HOME/hypr/custom"
RESTORE_SCRIPT_DIR="$CUSTOM_DIR/scripts" RESTORE_SCRIPT_DIR="$CUSTOM_DIR/scripts"
RESTORE_SCRIPT="$RESTORE_SCRIPT_DIR/__restore_video_wallpaper.sh" RESTORE_SCRIPT="$RESTORE_SCRIPT_DIR/__restore_video_wallpaper.sh"
THUMBNAIL_DIR="$RESTORE_SCRIPT_DIR/mpvpaper_thumbnails"
VIDEO_OPTS="no-audio loop hwdec=auto scale=bilinear interpolation=no video-sync=display-resample panscan=1.0 video-scale-x=1.0 video-scale-y=1.0 video-align-x=0.5 video-align-y=0.5 load-scripts=no" VIDEO_OPTS="no-audio loop hwdec=auto scale=bilinear interpolation=no video-sync=display-resample panscan=1.0 video-scale-x=1.0 video-scale-y=1.0 video-align-x=0.5 video-align-y=0.5 load-scripts=no"
is_video() { is_video() {
local extension="${1##*.}" local extension="${1##*.}"
[[ "$extension" == "mp4" || "$extension" == "mkv" || "$extension" == "webm" ]] && return 0 || return 1 [[ "$extension" == "mp4" || "$extension" == "webm" || "$extension" == "mkv" || "$extension" == "avi" || "$extension" == "mov" ]] && return 0 || return 1
} }
kill_existing_mpvpaper() { kill_existing_mpvpaper() {
@@ -158,6 +158,13 @@ set_wallpaper_path() {
fi fi
} }
set_thumbnail_path() {
local path="$1"
if [ -f "$SHELL_CONFIG_FILE" ]; then
jq --arg path "$path" '.background.thumbnailPath = $path' "$SHELL_CONFIG_FILE" > "$SHELL_CONFIG_FILE.tmp" && mv "$SHELL_CONFIG_FILE.tmp" "$SHELL_CONFIG_FILE"
fi
}
switch() { switch() {
imgpath="$1" imgpath="$1"
mode_flag="$2" mode_flag="$2"
@@ -226,6 +233,9 @@ switch() {
thumbnail="$THUMBNAIL_DIR/$(basename "$imgpath").jpg" thumbnail="$THUMBNAIL_DIR/$(basename "$imgpath").jpg"
ffmpeg -y -i "$imgpath" -vframes 1 "$thumbnail" 2>/dev/null ffmpeg -y -i "$imgpath" -vframes 1 "$thumbnail" 2>/dev/null
# Set thumbnail path
set_thumbnail_path "$thumbnail"
if [ -f "$thumbnail" ]; then if [ -f "$thumbnail" ]; then
matugen_args=(image "$thumbnail") matugen_args=(image "$thumbnail")
generate_colors_material_args=(--path "$thumbnail") generate_colors_material_args=(--path "$thumbnail")