From ac398060f984b34ab958ff3dfed87ca068d2b952 Mon Sep 17 00:00:00 2001 From: Ceda EI <19731116+Ceda-EI@users.noreply.github.com> Date: Thu, 28 Dec 2017 20:27:35 +0530 Subject: [PATCH] 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. --- box_config | 7 +++++++ config | 20 ++++++++++++++++++++ download_daemon | 39 +++++++++++++++++++++++++++++++++++++++ downloader.php | 38 ++++++++++++++++++++++++++++++++++++++ lock | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 box_config create mode 100644 config create mode 100755 download_daemon create mode 100755 downloader.php create mode 100755 lock diff --git a/box_config b/box_config new file mode 100644 index 0000000..bfa5803 --- /dev/null +++ b/box_config @@ -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 diff --git a/config b/config new file mode 100644 index 0000000..b4dce60 --- /dev/null +++ b/config @@ -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 diff --git a/download_daemon b/download_daemon new file mode 100755 index 0000000..046d566 --- /dev/null +++ b/download_daemon @@ -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 diff --git a/downloader.php b/downloader.php new file mode 100755 index 0000000..a8b5f9f --- /dev/null +++ b/downloader.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php + 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); diff --git a/lock b/lock new file mode 100755 index 0000000..42e0003 --- /dev/null +++ b/lock @@ -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