Misc cleanup

This commit is contained in:
2022-07-16 17:41:00 -07:00
parent 7d1a0b6155
commit ea62dabfc1
21 changed files with 143 additions and 175 deletions

View File

@ -1,7 +1,7 @@
local backlight = {}
-- The space at the end is important!
local script = configuration_dir .. "modules/backlight/backlight.fish"
local script = conf_dir .. "modules/backlight/backlight.fish"
script = script .. " "
backlight.hooks = {}

View File

@ -1,6 +1,6 @@
local battery = {}
local script = configuration_dir .. "modules/battery/battery.fish"
local script = conf_dir .. "modules/battery/battery.fish"
battery.watch = function(timeout, callback, widget)
awful.widget.watch(script, timeout, callback, widget)

17
modules/i3lock/init.lua Normal file
View File

@ -0,0 +1,17 @@
local script = conf_dir .. "modules/i3lock/lock.fish"
script = script .. " "
return {
keybinds = gears.table.join(
awful.key( {"Mod4"}, "a",
function ()
awful.spawn(script .. beautiful.icons.lockicon, false)
end,
{
description = "Lock screen",
group = "System"
}
)
)
}

13
modules/i3lock/lock.fish Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
icon=$1
tmpbg="/tmp/lockscreen.png"
tmpic="/tmp/lockscreenicon.png"
#(( $# )) && { icon=$1; }
scrot --overwrite "$tmpbg"
convert "$icon" -scale 25% "$tmpic"
convert "$tmpbg" -scale 10% -scale 1000% "$tmpbg"
convert "$tmpbg" "$tmpic" -gravity center -composite -matte "$tmpbg"
i3lock -u -i "$tmpbg"

View File

@ -1,6 +1,6 @@
local launcher = {}
local conf = configuration_dir .. "modules/launcher/launcher.rasi"
local conf = conf_dir .. "modules/launcher/launcher.rasi"
launcher.launcher = function()
awful.spawn("rofi -show drun -theme \"" .. conf .. "\"")

View File

@ -0,0 +1,39 @@
local script = conf_dir .. "modules/screenshot/screenshot.fish"
script = script .. " "
local function capture(source, target)
awful.spawn(script .. "capture " .. source .. " " .. target, false)
end
local function flameshot()
--awful.spawn("flameshot gui -p \"" .. conf.screenshot_dir .. "\"", false)
awful.spawn("flameshot gui", false)
end
return {
keybinds = gears.table.join(
awful.key( {"Control"}, "Print",
function ()
capture("region", "ocr")
end,
{
description = "OCR a region to the clipboard",
group = "Desktop"
}
),
awful.key( {}, "Print",
function ()
flameshot()
end,
{
description = "Take a screenshot",
group = "Desktop"
}
)
)
}

View File

@ -0,0 +1,74 @@
#!/usr/bin/fish
#
# Screenshot wrapper
#
# Take a screenshot of a
# region, window, or screen
# and
# save it to $dest
# copy it to the clipboard
# pipe it through tesseract and xclip the result
function capture
# Screenshot save location
set dest $HOME/Screenshots/
#set tmp_file (mktemp --tmpdir "scrot-tmp-XXX.png")
set tmp_file "/tmp/scrot-tmp.png"
# Capture the desired portion of the screen
switch $argv[1]
case window
scrot --overwrite --silent --focused $tmp_file
case screen
scrot --overwrite --silent $tmp_file
case region
scrot --overwrite --silent --select --freeze --line style=dash,width=2 $tmp_file
case "*"
echo "Unknown source \"$argv[1]\""
echo ""
echo "Usage: capture [source] [target]"
echo " Valid sources: window, screen, region"
echo " Valid targets: save, copy, ocr"
return 0
end
# Output to the desired location
switch $argv[2]
case save
set fname (md5sum $tmp_file | cut -c 1-32)
mv $tmp_file "$dest$fname.png"
case copy
# Don't use the mktmp file here, since we can't clean
# it away immediately. Use the fixed /tmp/scrot-clip insead.
# (Only applicable when a mktemp file is being used)
#rm $tmp_file
#set tmp_file /tmp/scrot-clip.png
xclip -i -selection clipboard -t "image/png" $tmp_file
case ocr
# Recognize text
set ocr (tesseract --dpi 96 -l eng $tmp_file stdout)
# Trim whitespace and copy to clipboard
echo $ocr | sed -e "s/^[ \t]*//" | xclip -i -rmlastnl -selection clipboard
rm $tmp_file
case "*"
echo "Unknown target \"$argv[2]\""
echo ""
echo "Usage: capture [source] [target]"
echo " Valid sources: window, screen, region"
echo " Valid targets: save, copy, ocr"
return 0
end
return 1
end
# Awesomewm refuses to execute this without a sleep.
sleep 0.1
capture $argv