mirror of
				https://gitlab.com/ceda_ei/i3lock-delta
				synced 2025-11-04 00:30:05 +01:00 
			
		
		
		
	Added download_daemon which needs to be running in background. Added downloader.php - the part of program that interacts with Unsplash API. Added lock which locks the screen. Added configs.
This commit is contained in:
		
							
								
								
									
										7
									
								
								box_config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								box_config
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
BOX_TOP_LEFT_X=10
 | 
			
		||||
BOX_TOP_LEFT_Y=610
 | 
			
		||||
BOX_BOTTOM_RIGHT_X=410
 | 
			
		||||
BOX_BOTTOM_RIGHT_Y=720
 | 
			
		||||
ROUNDENESS=50
 | 
			
		||||
NAME_X=600
 | 
			
		||||
NAME_Y=10
 | 
			
		||||
							
								
								
									
										20
									
								
								config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								config
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
# TIMECOLOR="00FFFFFF"
 | 
			
		||||
# TIMEFONT="Neuropolitical"
 | 
			
		||||
# TIMESIZE=60
 | 
			
		||||
# TIMESTYLE="%H:%M:%S"
 | 
			
		||||
# DATECOLOR="00FFFFFF"
 | 
			
		||||
# DATEFONT="Space Age"
 | 
			
		||||
# DATESIZE=25
 | 
			
		||||
# DATESTYLE="%A, %d %b"
 | 
			
		||||
## Ring Colors
 | 
			
		||||
# VERIFYING_INSIDE="FFFFFF44"
 | 
			
		||||
# WRONG_INSIDE="FF000044"
 | 
			
		||||
# INSIDE="00000000"
 | 
			
		||||
# LINE="00000000"
 | 
			
		||||
# KEYPRESS="FFFFFFFF"
 | 
			
		||||
# BACKSPACEPRESS="CCCCCCFF"
 | 
			
		||||
# RINGCOLOR="F7045DFF"
 | 
			
		||||
# RINGVERIFYINGCOLOR="F7045DFF"
 | 
			
		||||
# RINGWRONGCOLOR="F7045DFF"
 | 
			
		||||
# RINGTEXTSIZE=14
 | 
			
		||||
# RINGRADIUS=45
 | 
			
		||||
							
								
								
									
										39
									
								
								download_daemon
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								download_daemon
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
# Get the config
 | 
			
		||||
source box_config
 | 
			
		||||
 | 
			
		||||
# Get the resolution
 | 
			
		||||
resolution=`xdpyinfo | grep dimensions | sed 's/dimensions://;;s/ *//g;s/pixels.*//'`
 | 
			
		||||
 | 
			
		||||
# Run the main loop
 | 
			
		||||
while : ; do
 | 
			
		||||
	# Check whether the previous image has been used or not.
 | 
			
		||||
	# If no, wait 300 secs and check again.
 | 
			
		||||
	[[ `< $HOME/.config/lock_screen.sta` -eq 0 ]] && sleep 300 && continue
 | 
			
		||||
	# Download the new image
 | 
			
		||||
	$HOME/i3lock-delta/downloader.php
 | 
			
		||||
	if [[ $? -eq 0 ]]; then
 | 
			
		||||
		name_photographer="`< /tmp/name_photographer`"
 | 
			
		||||
 | 
			
		||||
		# Resize, crop, draw a box for clock, write photographer's name.
 | 
			
		||||
		convert $HOME/.rand_bg -resize "$resolution^" -crop "$resolution" \
 | 
			
		||||
				-draw "fill black fill-opacity 0.4  roundRectangle
 | 
			
		||||
				$BOX_TOP_LEFT_X,$BOX_TOP_LEFT_Y $BOX_BOTTOM_RIGHT_X,$BOX_BOTTOM_RIGHT_Y
 | 
			
		||||
				$ROUNDENESS,$ROUNDENESS text $NAME_X,$NAME_Y 'Photograph by: $name_photographer on Unsplash'" \
 | 
			
		||||
				/tmp/temp_lock.png
 | 
			
		||||
 | 
			
		||||
		# Move to needed place and remove the rest.
 | 
			
		||||
		if [[ -f /tmp/temp_lock-0.png ]] ; then
 | 
			
		||||
			mv /tmp/temp_lock-0.png $HOME/.rand_bg.png
 | 
			
		||||
			rm /tmp/temp_lock-1.png
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		# Remove the original
 | 
			
		||||
		rm $HOME/.rand_bg
 | 
			
		||||
		# Set the image as unused.
 | 
			
		||||
		echo 0 > $HOME/.config/lock_screen.sta
 | 
			
		||||
	else
 | 
			
		||||
		# If download fails, wait 60 secs and restart.
 | 
			
		||||
		sleep 60
 | 
			
		||||
	fi
 | 
			
		||||
done
 | 
			
		||||
							
								
								
									
										38
									
								
								downloader.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										38
									
								
								downloader.php
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
#!/usr/bin/env php
 | 
			
		||||
<?php
 | 
			
		||||
require __DIR__.'/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
# Initialize API
 | 
			
		||||
Crew\Unsplash\HttpClient::init([
 | 
			
		||||
	'applicationId' => file_get_contents(getenv('HOME').'/i3lock-delta/api_key'),
 | 
			
		||||
	'utmSource' => 'i3lock-Delta'
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
# Get custom search queries
 | 
			
		||||
$queries_file_name = getenv('HOME') . '/.config/lock_preferences';
 | 
			
		||||
$queries = file($queries_file_name);
 | 
			
		||||
 | 
			
		||||
# Create the random photo limitations
 | 
			
		||||
$filters = [
 | 
			
		||||
	'featured' => false,
 | 
			
		||||
	'query' => $queries[rand(0,count($queries) - 1)],
 | 
			
		||||
	'orientation' => 'landscape'
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
# Get the random photo
 | 
			
		||||
$img = Crew\Unsplash\Photo::random($filters);
 | 
			
		||||
 | 
			
		||||
# Download the photo
 | 
			
		||||
$url = $img->download();
 | 
			
		||||
$output = file_get_contents($url);
 | 
			
		||||
 | 
			
		||||
# Write image to a file
 | 
			
		||||
$image_filename =getenv('HOME') . '/.rand_bg';
 | 
			
		||||
$image_file = fopen($image_filename, 'w');
 | 
			
		||||
fwrite($image_file, $output);
 | 
			
		||||
fclose($image_file);
 | 
			
		||||
 | 
			
		||||
# Write author's name to a file
 | 
			
		||||
$name_file = fopen('/tmp/name_photographer', 'w');
 | 
			
		||||
fwrite($name_file, $img->{'user'}['name']);
 | 
			
		||||
fclose($name_file);
 | 
			
		||||
							
								
								
									
										44
									
								
								lock
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										44
									
								
								lock
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
TIMECOLOR="00FFFFFF"
 | 
			
		||||
TIMEFONT="Neuropolitical"
 | 
			
		||||
TIMESIZE=60
 | 
			
		||||
TIMESTYLE="%H:%M:%S"
 | 
			
		||||
DATECOLOR="00FFFFFF"
 | 
			
		||||
DATEFONT="Space Age"
 | 
			
		||||
DATESIZE=25
 | 
			
		||||
DATESTYLE="%A, %d %b"
 | 
			
		||||
# Ring Colors
 | 
			
		||||
VERIFYING_INSIDE="FFFFFF44"
 | 
			
		||||
WRONG_INSIDE="FF000044"
 | 
			
		||||
INSIDE="00000000"
 | 
			
		||||
LINE="00000000"
 | 
			
		||||
KEYPRESS="FFFFFFFF"
 | 
			
		||||
BACKSPACEPRESS="CCCCCCFF"
 | 
			
		||||
RINGCOLOR="F7045DFF"
 | 
			
		||||
RINGVERIFYINGCOLOR="F7045DFF"
 | 
			
		||||
RINGWRONGCOLOR="F7045DFF"
 | 
			
		||||
RINGTEXTSIZE=14
 | 
			
		||||
RINGRADIUS=45
 | 
			
		||||
 | 
			
		||||
# Get custom config
 | 
			
		||||
source $HOME/i3lock-delta/config
 | 
			
		||||
 | 
			
		||||
# Pause dunst
 | 
			
		||||
pkill -u ahmad_saalim -USR1 dunst
 | 
			
		||||
# Set the image as used.
 | 
			
		||||
echo 1 > $HOME/.config/lock_screen.sta
 | 
			
		||||
xset dpms force off
 | 
			
		||||
 | 
			
		||||
# Call the lock
 | 
			
		||||
i3lock -i $HOME/.rand_bg.png -knf \
 | 
			
		||||
    --timecolor="$TIMECOLOR" --layout-align 1 --time-align 1 --timefont="$TIMEFONT" \
 | 
			
		||||
    --datecolor="$DATECOLOR" --timepos "30:h-ch" --datesize="$DATESIZE" \
 | 
			
		||||
    --timesize="$TIMESIZE" --datestr="$DATESTYLE" -e --datefont="$DATEFONT" \
 | 
			
		||||
    --date-align 1 --insidevercolor="$VERIFYING_INSIDE" --insidewrongcolor="$WRONG_INSIDE" \
 | 
			
		||||
    --insidecolor="$INSIDE" --linecolor="$LINE" --keyhlcolor="$KEYPRESS" --bshlcolor="$BACKSPACEPRESS" \
 | 
			
		||||
    --ringcolor="$RINGCOLOR" --ringvercolor="$RINGVERIFYINGCOLOR" --ringwrongcolor="$RINGWRONGCOLOR" \
 | 
			
		||||
    --separatorcolor="$KEYPRESS" --indpos="w-r-30:h-r-60" --radius="$RINGRADIUS" --modsize=1 \
 | 
			
		||||
    --textsize="$RINGTEXTSIZE" --indicator --timestr="$TIMESTYLE"
 | 
			
		||||
 | 
			
		||||
# Resume dunst
 | 
			
		||||
pkill -u ahmad_saalim -USR2 dunst
 | 
			
		||||
		Reference in New Issue
	
	Block a user