2020-05-22 01:55:37 +02:00
|
|
|
#!/bin/python3
|
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
import time
|
2017-12-20 00:24:46 +01:00
|
|
|
import os
|
2017-12-21 02:30:19 +01:00
|
|
|
|
2017-12-20 00:24:46 +01:00
|
|
|
from PIL import Image
|
2017-12-21 00:25:55 +01:00
|
|
|
|
2019-07-25 09:51:54 +02:00
|
|
|
DEBUG = False
|
2017-12-20 00:24:46 +01:00
|
|
|
|
|
|
|
def screenshot():
|
2018-01-31 04:23:36 +01:00
|
|
|
ss_time = time.time()
|
2019-03-30 04:56:38 +01:00
|
|
|
os.system('maim -f png /tmp/i3lock.png')
|
2018-01-31 04:23:36 +01:00
|
|
|
print('Screenshot: {}'.format(time.time() - ss_time))
|
2017-12-20 00:24:46 +01:00
|
|
|
|
2018-09-12 22:42:41 +02:00
|
|
|
|
2017-12-20 00:24:46 +01:00
|
|
|
def pixelate():
|
2018-01-31 04:23:36 +01:00
|
|
|
pxl_time = time.time()
|
2017-12-21 07:49:37 +01:00
|
|
|
pixelSize = 12
|
2017-12-21 00:25:55 +01:00
|
|
|
|
2017-12-21 02:30:19 +01:00
|
|
|
image = Image.open('/tmp/i3lock.png')
|
|
|
|
|
2018-01-31 04:23:36 +01:00
|
|
|
image_x, image_y = image.size
|
2017-12-21 02:30:19 +01:00
|
|
|
|
2018-01-31 04:23:36 +01:00
|
|
|
image = image.resize((int(image_x / pixelSize), int(image_y / pixelSize)), Image.NEAREST)
|
|
|
|
image_x, image_y = image.size
|
2018-09-12 22:42:41 +02:00
|
|
|
|
2017-12-21 02:30:19 +01:00
|
|
|
image = image.resize((image_x * pixelSize, image_y * pixelSize),
|
2018-09-12 22:42:41 +02:00
|
|
|
Image.NEAREST)
|
2017-12-21 00:25:55 +01:00
|
|
|
|
2017-12-21 02:30:19 +01:00
|
|
|
image.save('/tmp/i3lock.png')
|
2019-08-14 22:05:24 +02:00
|
|
|
os.chmod('/tmp/i3lock.png', 0o666)
|
2018-01-31 04:23:36 +01:00
|
|
|
print('pixelate: {}'.format(time.time() - pxl_time))
|
2017-12-21 00:25:55 +01:00
|
|
|
|
2017-12-20 00:24:46 +01:00
|
|
|
|
2017-12-21 00:25:55 +01:00
|
|
|
def getResolution():
|
2017-12-21 02:30:19 +01:00
|
|
|
image = Image.open('/tmp/i3lock.png')
|
2017-12-21 00:25:55 +01:00
|
|
|
return image.size
|
|
|
|
|
|
|
|
|
|
|
|
def lock_config():
|
|
|
|
'Generation of a customized lock command'
|
2018-01-31 04:23:36 +01:00
|
|
|
lock_time = time.time()
|
2017-12-21 00:25:55 +01:00
|
|
|
# constants
|
|
|
|
lock_core = 'i3lock'
|
|
|
|
default_fontsize = 32
|
|
|
|
# resolution
|
|
|
|
res = getResolution()
|
|
|
|
# res_x = int(res[0])
|
|
|
|
res_y = int(res[1])
|
|
|
|
|
|
|
|
# alignments
|
2017-12-21 02:30:19 +01:00
|
|
|
left_margin = int(res[0] / 25)
|
|
|
|
|
2017-12-21 00:25:55 +01:00
|
|
|
# clock pos
|
|
|
|
clock_x = left_margin
|
2018-05-20 19:38:00 +02:00
|
|
|
clock_y = int(res_y * (90 / 100))
|
2017-12-21 00:25:55 +01:00
|
|
|
|
|
|
|
date_x = left_margin
|
|
|
|
date_y = clock_y + default_fontsize
|
|
|
|
|
|
|
|
# clock config
|
|
|
|
lock_clock_args = '-k'
|
|
|
|
lock_clock_align = '--time-align 1 --date-align 1 --layout-align 1'
|
|
|
|
clock = "{} {}".format(lock_clock_args, lock_clock_align)
|
|
|
|
# time
|
|
|
|
lock_time_pos = '--timepos="{}:{}"'.format(clock_x, clock_y)
|
2017-12-21 02:30:19 +01:00
|
|
|
lock_time_size = '--timesize={}'.format(default_fontsize * 2)
|
2018-01-31 04:23:36 +01:00
|
|
|
l_time = "{} {}".format(lock_time_pos, lock_time_size)
|
2017-12-21 00:25:55 +01:00
|
|
|
# date
|
|
|
|
lock_date_pos = '--datepos="{}:{}"'.format(date_x, date_y)
|
|
|
|
lock_date_size = '--datesize={}'.format(default_fontsize)
|
|
|
|
date = "{} {}".format(lock_date_pos, lock_date_size)
|
2018-08-29 21:22:24 +02:00
|
|
|
# date color
|
|
|
|
datecolor = '--datecolor=777777ff'
|
|
|
|
timecolor = '--timecolor=777777ff'
|
|
|
|
color = '{} {}'.format(datecolor, timecolor)
|
2017-12-21 00:25:55 +01:00
|
|
|
# done
|
2018-08-29 21:22:24 +02:00
|
|
|
datetime = "{} {} {}".format(l_time, date, color)
|
2017-12-20 00:24:46 +01:00
|
|
|
|
2017-12-21 00:25:55 +01:00
|
|
|
# Indicator config
|
|
|
|
# Indicator inner
|
|
|
|
# Color of the circle while resting/typing | Color: transparenet
|
|
|
|
lock_rest_color = '--insidecolor 00000000 '
|
|
|
|
# Color of the circle while "VERIFYING..." | Color: transparent
|
|
|
|
lock_ver_color = '--insidevercolor 00000000 '
|
|
|
|
# Color of the circle if wrong | Color: transparent
|
|
|
|
lock_wrong_color = '--insidewrongcolor 00000000 '
|
2017-12-21 02:30:19 +01:00
|
|
|
indicator_inner = "{} {} {}".format(lock_rest_color, lock_wrong_color,
|
2018-09-12 22:42:41 +02:00
|
|
|
lock_ver_color)
|
2017-12-21 00:25:55 +01:00
|
|
|
|
|
|
|
# indicator_outer_ring
|
|
|
|
# Default Color of the ring | Color: torquoise
|
|
|
|
lock_ring = '--ringcolor 00CED1FF'
|
|
|
|
# Color of ring when wrong pw | Color: red
|
|
|
|
lock_ring_w = '--ringwrongcolor D10000FF'
|
|
|
|
# Color of ring when verifying | color dark-torquoise
|
|
|
|
lock_ring_v = '--ringvercolor 25B6B8FF'
|
|
|
|
# Color on Keypresses | Color: green
|
|
|
|
lock_press = '--keyhlcolor 00D103FF'
|
|
|
|
# Color on Deletion | Color: orange
|
|
|
|
lock_del = '--bshlcolor D13400FF'
|
|
|
|
# Color of seperator | Color: dark-blue
|
2017-12-21 02:30:19 +01:00
|
|
|
lock_sep_color = '--separatorcolor 0000D1FF'
|
2018-03-26 00:25:13 +02:00
|
|
|
# Right Text
|
2018-04-05 09:46:48 +02:00
|
|
|
lock_right_text = '--veriftext="..."'
|
2018-03-26 00:25:13 +02:00
|
|
|
# Wrong Text
|
|
|
|
lock_wrong_text = '--wrongtext="Noope"'
|
2018-04-05 09:46:48 +02:00
|
|
|
# Text Size
|
2018-05-20 19:38:00 +02:00
|
|
|
# lock_text_size = '--textsize=20'
|
2018-03-26 00:25:13 +02:00
|
|
|
# Ring Position
|
2018-05-20 19:38:00 +02:00
|
|
|
lock_texts = '{} {}'.format(lock_right_text, lock_wrong_text)
|
|
|
|
lock_pos = '--indpos={}:{}'.format(int(clock_x)+370, int(clock_y))
|
2018-03-26 00:25:13 +02:00
|
|
|
# Ring size
|
|
|
|
ring_size = 40
|
|
|
|
lock_radius = '--radius {}'.format(ring_size)
|
|
|
|
lock_stats = '{} {}'.format(lock_pos, lock_radius)
|
2018-04-05 09:46:48 +02:00
|
|
|
indicator_outer_ring = "{} {} {} {} {} {} {} {}".format(lock_ring,
|
2018-09-12 22:42:41 +02:00
|
|
|
lock_ring_w,
|
|
|
|
lock_ring_v,
|
|
|
|
lock_press,
|
|
|
|
lock_del,
|
|
|
|
lock_sep_color,
|
|
|
|
lock_stats,
|
|
|
|
lock_texts)
|
2017-12-21 00:25:55 +01:00
|
|
|
# done
|
|
|
|
indicator = "{} {}".format(indicator_inner, indicator_outer_ring)
|
2017-12-21 02:30:19 +01:00
|
|
|
|
2017-12-21 00:25:55 +01:00
|
|
|
# background
|
2017-12-21 02:30:19 +01:00
|
|
|
lock_pic = '-i /tmp/i3lock.png'
|
|
|
|
|
2018-03-26 00:25:13 +02:00
|
|
|
print('lock: {}'.format(time.time() - lock_time))
|
2017-12-21 02:30:19 +01:00
|
|
|
return "{} {} {} {} {}".format(lock_core, clock, datetime, indicator,
|
2018-09-12 22:42:41 +02:00
|
|
|
lock_pic)
|
2017-12-21 00:25:55 +01:00
|
|
|
|
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
def lock():
|
|
|
|
'Locks the System'
|
|
|
|
command = lock_config()
|
|
|
|
|
|
|
|
os.system(command)
|
|
|
|
|
2018-09-12 22:42:41 +02:00
|
|
|
def proc_exists(proc_name):
|
|
|
|
proc_check = time.time()
|
|
|
|
this_proc = "i3lock.py"
|
|
|
|
proc_path = '/proc'
|
|
|
|
proc = next(os.walk('{}/'.format(proc_path)))[1]
|
|
|
|
counter = 0
|
|
|
|
for process in proc:
|
|
|
|
counter+=1
|
|
|
|
cmdline_path = '{}/{}/cmdline'.format(proc_path,process)
|
|
|
|
try:
|
|
|
|
with open(cmdline_path, 'r') as cmd:
|
|
|
|
proc_content = cmd.readline()
|
|
|
|
proc_content = '{}: {}'.format(counter, proc_content)
|
|
|
|
if proc_content:
|
|
|
|
if proc_name in proc_content:
|
|
|
|
if 'xss-lock' not in proc_content:
|
|
|
|
if this_proc not in proc_content:
|
|
|
|
print('Process Exists: {}'.format(time.time() - proc_check))
|
|
|
|
return True
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
print('Process Exists: {}'.format(time.time() - proc_check))
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_running():
|
|
|
|
return proc_exists("i3lock")
|
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
|
|
|
|
def log(start_time):
|
2017-12-21 00:25:55 +01:00
|
|
|
write_mode = ''
|
|
|
|
home = os.path.expanduser('~')
|
|
|
|
log_file_path = "{}/{}".format(home, ".scripts/lock.log")
|
|
|
|
|
|
|
|
if (os.path.isfile(log_file_path)):
|
|
|
|
write_mode = 'a'
|
|
|
|
else:
|
|
|
|
write_mode = 'w'
|
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
program_duration = time.time() - start_time
|
2017-12-21 00:25:55 +01:00
|
|
|
with open(log_file_path, write_mode) as f:
|
2018-01-19 06:50:57 +01:00
|
|
|
f.write("[{}] {} seconds runtime.\n".format(time.asctime(), program_duration))
|
2017-12-21 00:25:55 +01:00
|
|
|
f.close()
|
2017-12-20 00:24:46 +01:00
|
|
|
|
2018-09-12 22:42:41 +02:00
|
|
|
|
2017-12-21 00:25:55 +01:00
|
|
|
if __name__ == '__main__':
|
2018-09-12 22:42:41 +02:00
|
|
|
if not is_running():
|
|
|
|
start_time = time.time()
|
|
|
|
screenshot()
|
|
|
|
pixelate()
|
|
|
|
lock()
|
|
|
|
log(start_time)
|