From 373e5f71c31cfc700954359427d84c41587b4994 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 23 Jul 2022 16:48:02 -0700 Subject: [PATCH 1/7] Changed file manager --- config-template.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-template.lua b/config-template.lua index 8025532..8069d16 100755 --- a/config-template.lua +++ b/config-template.lua @@ -79,7 +79,7 @@ config.core = { bar_shortcuts = { { - "pcmanfm", + "thunar", "folder" }, { From 40b43f940cb0ce9300b1aba38601355981161abd Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 1 Aug 2022 15:00:16 -0700 Subject: [PATCH 2/7] Improved screenshot script --- README.md | 2 +- modules/screenshot/init.lua | 36 +++++++++++---- modules/screenshot/screenshot.fish | 48 +++++++++++++++++++ modules/screenshot/screenshot.sh | 74 ------------------------------ 4 files changed, 75 insertions(+), 85 deletions(-) create mode 100755 modules/screenshot/screenshot.fish delete mode 100755 modules/screenshot/screenshot.sh diff --git a/README.md b/README.md index 9e631f9..9d43955 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ To use, copy config.lua.template into config.lua and edit it to your liking. - rofi - fish - upower, xbacklight - - flameshot, scrot, xclip, tesseract + - flameshot, xclip, tesseract - pamixer - sox - ibus diff --git a/modules/screenshot/init.lua b/modules/screenshot/init.lua index f3998ce..e764c11 100644 --- a/modules/screenshot/init.lua +++ b/modules/screenshot/init.lua @@ -2,14 +2,8 @@ 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", false) +local function screenshot_action(mode) + awful.spawn(script .. mode, false) end @@ -17,12 +11,34 @@ return { keybinds = gears.table.join( awful.key( {}, "Print", function () - flameshot() + screenshot_action("normal") end, { description = "Take a screenshot", - group = "Desktop" + group = "Screenshot" + } + ), + + awful.key( {"Control"}, "Print", + function () + screenshot_action("ocr") + end, + + { + description = "OCR Capture", + group = "Screenshot" + } + ), + + awful.key( {"Shift"}, "Print", + function () + screenshot_action("pin") + end, + + { + description = "Pin a screenshot", + group = "Screenshot" } ) ) diff --git a/modules/screenshot/screenshot.fish b/modules/screenshot/screenshot.fish new file mode 100755 index 0000000..5575595 --- /dev/null +++ b/modules/screenshot/screenshot.fish @@ -0,0 +1,48 @@ +#!/usr/bin/fish +# +# Screenshot wrapper +# +# Usage: ./screenshot.fish [action] +# Actions: +# Normal: regular flameshot +# Pin: flameshot fast pin +# OCR: flameshot -> tesseract -> xclip, no save. + + +function capture + # Screenshot save location + set dest $HOME/Screenshots/ + + #set tmp_file (mktemp --tmpdir "scrot-tmp-XXX.png") + set tmp_file "/tmp/screenshot-tmp.png" + + switch $argv[1] + case normal + flameshot gui + + case pin + flameshot gui --accept-on-select --pin + + case ocr + flameshot gui --accept-on-select --path $tmp_file + + # 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 action \"$argv[1]\"" + echo "" + echo "Usage: screenshot.fish [action]" + echo " Valid actions: normal, pin, ocr" + return 0 + end + + return 1 +end + +capture $argv diff --git a/modules/screenshot/screenshot.sh b/modules/screenshot/screenshot.sh deleted file mode 100755 index e283e2e..0000000 --- a/modules/screenshot/screenshot.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/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 From 5dca4a76b4f1d517cee544e939c33b84e540cae7 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 2 Aug 2022 16:43:28 -0700 Subject: [PATCH 3/7] Added russian OCR screenshot --- modules/screenshot/init.lua | 17 ++++++++++++++--- modules/screenshot/screenshot.fish | 12 +++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/screenshot/init.lua b/modules/screenshot/init.lua index e764c11..f8f0fab 100644 --- a/modules/screenshot/init.lua +++ b/modules/screenshot/init.lua @@ -20,17 +20,28 @@ return { } ), - awful.key( {"Control"}, "Print", + awful.key( {"Control", "Shift"}, "Print", function () - screenshot_action("ocr") + screenshot_action("ocr-rus") end, { - description = "OCR Capture", + description = "OCR Capture (Russian)", group = "Screenshot" } ), + awful.key( {"Control"}, "Print", + function () + screenshot_action("ocr-eng") + end, + + { + description = "OCR Capture (English)", + group = "Screenshot" + } + ), + awful.key( {"Shift"}, "Print", function () screenshot_action("pin") diff --git a/modules/screenshot/screenshot.fish b/modules/screenshot/screenshot.fish index 5575595..97df369 100755 --- a/modules/screenshot/screenshot.fish +++ b/modules/screenshot/screenshot.fish @@ -23,7 +23,7 @@ function capture case pin flameshot gui --accept-on-select --pin - case ocr + case ocr-eng flameshot gui --accept-on-select --path $tmp_file # Recognize text @@ -33,6 +33,16 @@ function capture echo $ocr | sed -e "s/^[ \t]*//" | xclip -i -rmlastnl -selection clipboard rm $tmp_file + case ocr-rus + flameshot gui --accept-on-select --path $tmp_file + + # Recognize text + set ocr (tesseract --dpi 96 -l rus $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 action \"$argv[1]\"" From e8312903dbcf7ba2478e97a268b8b00a21ec34ba Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 2 Aug 2022 19:36:59 -0700 Subject: [PATCH 4/7] Added print screenshot command --- modules/screenshot/init.lua | 12 ++++++++++++ modules/screenshot/screenshot.fish | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/screenshot/init.lua b/modules/screenshot/init.lua index f8f0fab..9ecc2a4 100644 --- a/modules/screenshot/init.lua +++ b/modules/screenshot/init.lua @@ -52,5 +52,17 @@ return { group = "Screenshot" } ) + ), + + awful.key( {"Shift", "Control", "Mod1"}, "Print", + function () + -- Make sure your default printer is set in CUPS! + screenshot_action("lpr") + end, + + { + description = "Print a screenshot", + group = "Screenshot" + } ) } diff --git a/modules/screenshot/screenshot.fish b/modules/screenshot/screenshot.fish index 97df369..10e018f 100755 --- a/modules/screenshot/screenshot.fish +++ b/modules/screenshot/screenshot.fish @@ -43,6 +43,14 @@ function capture echo $ocr | sed -e "s/^[ \t]*//" | xclip -i -rmlastnl -selection clipboard rm $tmp_file + case lpr + # Default printer must be set for the lpr command to work. + + # TODO: don't lpr if screenshot is cancelled. + flameshot gui --accept-on-select --path $tmp_file + convert $tmp_file $tmp_file.pdf + lpr -T "Autoprint Screenshot" $tmp_file.pdf + rm $tmp_file case "*" echo "Unknown action \"$argv[1]\"" From c9aef48da2f0e25c099d94312160a0ae66c84169 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Aug 2022 07:41:41 -0700 Subject: [PATCH 5/7] Added lpr screenshot action --- modules/screenshot/init.lua | 48 ++++++++++++++---------------- modules/screenshot/screenshot.fish | 2 +- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/modules/screenshot/init.lua b/modules/screenshot/init.lua index 9ecc2a4..3f631de 100644 --- a/modules/screenshot/init.lua +++ b/modules/screenshot/init.lua @@ -1,9 +1,8 @@ - -local script = conf_dir .. "modules/screenshot/screenshot.fish" -script = script .. " " - local function screenshot_action(mode) - awful.spawn(script .. mode, false) + awful.spawn( + conf_dir .. "modules/screenshot/screenshot.fish " .. mode, + false + ) end @@ -32,15 +31,15 @@ return { ), awful.key( {"Control"}, "Print", - function () - screenshot_action("ocr-eng") - end, + function () + screenshot_action("ocr-eng") + end, - { - description = "OCR Capture (English)", - group = "Screenshot" - } - ), + { + description = "OCR Capture (English)", + group = "Screenshot" + } + ), awful.key( {"Shift"}, "Print", function () @@ -51,18 +50,17 @@ return { description = "Pin a screenshot", group = "Screenshot" } + ), + + awful.key( {"Mod1"}, "Print", + function () + -- Make sure your default printer is set in CUPS! + screenshot_action("lpr") + end, + { + description = "Print a screenshot", + group = "Screenshot" + } ) - ), - - awful.key( {"Shift", "Control", "Mod1"}, "Print", - function () - -- Make sure your default printer is set in CUPS! - screenshot_action("lpr") - end, - - { - description = "Print a screenshot", - group = "Screenshot" - } ) } diff --git a/modules/screenshot/screenshot.fish b/modules/screenshot/screenshot.fish index 10e018f..a627309 100755 --- a/modules/screenshot/screenshot.fish +++ b/modules/screenshot/screenshot.fish @@ -45,7 +45,7 @@ function capture case lpr # Default printer must be set for the lpr command to work. - + # TODO: don't lpr if screenshot is cancelled. flameshot gui --accept-on-select --path $tmp_file convert $tmp_file $tmp_file.pdf From 17725f880761ed0a86353005401ce2c48eb54d15 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Aug 2022 18:04:09 -0700 Subject: [PATCH 6/7] Added ibus hook for host interface --- modules/ibus/init.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/ibus/init.lua b/modules/ibus/init.lua index b237f65..e5b51c9 100644 --- a/modules/ibus/init.lua +++ b/modules/ibus/init.lua @@ -1,9 +1,27 @@ local util = require("modules.ibus.util") +local popup = require("modules.ibus.popup") +local widget = require("modules.ibus.widget") return { widget = require("modules.ibus.widget").widget, keybinds = require("modules.ibus.keybinds"), + set = function(lang) + -- Switch to a language. Used by host interface. + + local lang_id + for k, v in pairs(config.ibus.language_list) do + if (v["indicator_code"] == lang) then + lang_id = k + end + end + + util.set(lang_id, function() + popup.update() + widget.update() + end) + end, + init = function() util.set(1) end From f6a8f5004bc95372cbdc36a2f1d7666f28849c10 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Aug 2022 18:05:24 -0700 Subject: [PATCH 7/7] Remove pdf in screenshot script --- modules/screenshot/screenshot.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/screenshot/screenshot.fish b/modules/screenshot/screenshot.fish index a627309..f6abe56 100755 --- a/modules/screenshot/screenshot.fish +++ b/modules/screenshot/screenshot.fish @@ -50,7 +50,9 @@ function capture flameshot gui --accept-on-select --path $tmp_file convert $tmp_file $tmp_file.pdf lpr -T "Autoprint Screenshot" $tmp_file.pdf + rm $tmp_file + rm $tmp_file.pdf case "*" echo "Unknown action \"$argv[1]\""