You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.4 KiB
122 lines
2.4 KiB
#!pwsh -noprofile |
|
# -*- mode: powershell -*- |
|
|
|
<# Screen locker for Wayland (and maybe Xorg). Rewritten in pwsh because math is |
|
pain. |
|
|
|
Dependencies: |
|
- neofetch |
|
- powershell |
|
- grim or gnome-screenshot or scrot |
|
- imagemagick |
|
|
|
#> |
|
|
|
# init variables. These can be changed for ease of use. |
|
$image = "/tmp/scrot.png" |
|
$paintlevel = 1 |
|
$swirl = 75 |
|
$thickness = 130 |
|
$message1 = 'SCREEN LOCKED ' |
|
$message2 = $message1 + $message1 |
|
$message3 = $message1 + $message2 |
|
$message = '"' + $message2 + '"' |
|
$font = "Impact" |
|
|
|
function screenshot { |
|
param ($image) |
|
switch -regex (neofetch wm) { |
|
(".*Mutter") { gnome-screenshot -f $image } |
|
(".*[Hh]yprland.*|sway") { grim $image } |
|
default { scrot $image } |
|
} |
|
} |
|
|
|
# take initial screenshot. Yes this must be done before all other logic. |
|
screenshot $image |
|
|
|
# Grab resolution from that image. |
|
$null, [int]$resx, |
|
$null, [int]$resy = ((file /tmp/scrot.png) -split ',')[1] -split ' ' |
|
|
|
function get_angle { |
|
param ( |
|
[int] $legx, |
|
[int] $legy) |
|
$angle = [math]::Atan2($legy, $legx) * 180 / [math]::PI |
|
while ($angle -lt 0) { |
|
$angle += 360 |
|
} |
|
$angle |
|
} |
|
|
|
function draw_swirl { |
|
magick $image ` |
|
-paint $paintlevel ` |
|
-swirl $swirl ` |
|
$image |
|
} |
|
|
|
function write_message { |
|
param( |
|
$origx, |
|
$origy, |
|
$angle, |
|
$color) |
|
$annotation = ( |
|
'"' + |
|
$angle + |
|
'x' + |
|
$angle + |
|
'+' + |
|
$origx + |
|
'+' + |
|
"$origy " + $message + '"' |
|
) |
|
echo $message |
|
echo $annotation |
|
magick $image ` |
|
-stroke black -strokewidth 1 -gravity Center ` |
|
-font "$font" -pointsize $thickness ` |
|
-kerning 30 ` |
|
-interword-spacing 60 ` |
|
-undercolor "$color" ` |
|
-annotate "$annotation" ` |
|
$image |
|
} |
|
function l_draw_tape { |
|
param( |
|
$minx, |
|
$miny, |
|
$maxx, |
|
$maxy, |
|
$color) |
|
# l_draw_line $minx $miny $maxx $maxy $color # removed b/c undercolor |
|
$absx = $maxx - $minx |
|
$absy = $maxy - $miny |
|
$angle = + (get_angle $absx $absy) |
|
if ($absx -lt 0) { $bigx = $maxx } else { $bigx = $minx } |
|
if ($absy -lt 0) { $bigy = $maxy } else { $bigy = $miny } |
|
write_message $bigx $bigy $angle $color |
|
# write_message $minx $miny $maxx $maxy $angle $color |
|
} |
|
|
|
function x_draw_tape { |
|
# the simplest shape and only current supported. Makes a big X. |
|
l_draw_tape 0 0 $resx $resy "#a0a000" |
|
l_draw_tape 0 $resy $resx 0 "#b0b000" |
|
} |
|
|
|
function m_draw_tape { |
|
# draw a big M out of caution tape. Broken. |
|
$halfx = $resx / 2 |
|
$halfy = $resy / 2 |
|
# l_draw_tape 0 $resy $resx 0 "#d2d200" |
|
l_draw_tape 0 0 $halfx $resy "#abab00" |
|
} |
|
|
|
draw_swirl |
|
x_draw_tape |
|
# m_draw_tape |
|
|
|
swaylock -i $image -e -F --font "MesloLGS NF"
|
|
|