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.
134 lines
2.9 KiB
134 lines
2.9 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" |
|
$tempdir = "~/.local/share/waylock" |
|
|
|
function screenshot { |
|
param ($image) |
|
switch -regex (neofetch de) { # or wm maybe idk |
|
(".*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, |
|
$length) |
|
$annotation = ( |
|
# '"' + |
|
# '-annotate ' + |
|
[string]$angle + |
|
'x' + |
|
$angle + |
|
'+' + |
|
$origx + |
|
'+' + |
|
$origy + ' ' + $message # + '"' |
|
) |
|
sh -c ("magick " + $image + |
|
" -stroke black -strokewidth 1 -font '" + |
|
$font + |
|
"' -pointsize " + |
|
$thickness + " -kerning 30 -interword-spacing 60 " + |
|
" -undercolor '" + $color + "' -annotate " + $annotation + " " + |
|
$image) |
|
} |
|
function length { |
|
param($x1,$y1,$x2,$y2) |
|
$absx = $x2 - $x1 |
|
$absy = $y2 - $y1 |
|
$xx = [math]::pow($absx,2) |
|
$yy = [math]::pow($absy,2) |
|
[math]::Sqrt(($xx + $yy))} |
|
|
|
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 0 0 $resy |
|
write_message 0 0 90 "#d2d200" |
|
l_draw_tape 0 0 $halfx $halfy "#abab00" |
|
l_draw_tape $resx 0 $halfx $halfy "#d2d200" |
|
write_message ($resx - $thickness) 0 90 "#abab00" |
|
} |
|
|
|
draw_swirl |
|
x_draw_tape |
|
# m_draw_tape |
|
|
|
# swaylock -i $image -e -F --font "MesloLGS NF" --scaling=stretch
|
|
|