Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawned xclip and scrot threads using async #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
awesomewm-screenshot
=======
====================

A screenshot widget for Awesome WM.
It's compatible with Awesome 4
It's compatible with Awesome 4 (4.3)

Requirements
------------

* scrot
* xclip


Get it
------

Expand Down Expand Up @@ -40,9 +39,13 @@ local screenshot = require("screenshot")
{description = "Take a screenshot of delay", group = "screenshot"}),
```

the default storage of the ~/Pictures/
the default storage of the ~/Pictures/Screenshots/

## This Fork

I added the async functionality in the spawn commands since the orginal way wasn't working for me.

License
------
-------

this software is distributed in MIT License
54 changes: 39 additions & 15 deletions screenshot.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,65 @@
local awful = require("awful")
local naughty = require("naughty")

timers = { 5,10 }
screenshot = os.getenv("HOME") .. "/Pictures/scrot/$(date +%F_%T).png"
Timers = { 5, 10 }

function getPath()
Date = os.date("%Y-%m-%d_%H:%M:%S") --Change File Format Here
Screenshot = os.getenv("HOME") .. "/Pictures/Screenshots/" .. Date --Change Directory Here
return Screenshot
end

function scrot_full()
scrot("scrot " .. screenshot .. " -e 'xclip -selection c -t image/png < $f', scrot_callback", scrot_callback, "Take a screenshot of entire screen")
path=getPath()
awful.spawn.easy_async_with_shell("scrot " .. Screenshot,
function()
awful.spawn.easy_async_with_shell("xclip -selection clipboard -t image/png -i " .. path,
scrot_callback("Take a screenshot entire screen"))
end)
end

function scrot_selection()
scrot("sleep 0.5 && scrot -s " .. screenshot .. " -e 'xclip -selection c -t image/png < $f'", scrot_callback, "Take a screenshot of selection")
path=getPath()
awful.spawn.easy_async_with_shell("scrot -s " .. path,
function()
awful.spawn.easy_async_with_shell("xclip -selection clipboard -t image/png -i " .. path,
scrot_callback("Take a screenshot of selection"))
end)
end

function scrot_window()
scrot("scrot -u " .. screenshot .. " -e 'xclip -selection c -t image/png < $f'", scrot_callback, "Take a screenshot of focused window")
path=getPath()
awful.spawn.easy_async_with_shell("scrot -u " .. path,
function()
awful.spawn.easy_async_with_shell("xclip -selection clipboard -t image/png -i " .. path,
scrot_callback("Take a screenshot of focused window"))
end)
end

function scrot_delay()
items={}
for key, value in ipairs(timers) do
items[#items+1]={tostring(value) , "scrot -d ".. value.." " .. screenshot .. " -e 'xclip -selection c -t image/png < $f'","Take a screenshot of delay" }
path=getPath()
items = {}
for key, value in ipairs(Timers) do
items[#items + 1] = { tostring(value),
"scrot -d " .. value .. " " .. path .. " -e 'xclip -selection c -t image/png < $f'",
"Take a screenshot of delay" }
end
awful.menu.new(
{
items = items
}
):show({keygrabber= true})
{
items = items
}
):show({ keygrabber = true })
scrot_callback()
end

function scrot(cmd , callback, args)
function scrot(cmd, callback, args)
awful.util.spawn_with_shell(cmd)
callback(args)
end

function scrot_callback(text)
naughty.notify({
text = text,
timeout = 0.5
timeout = 1
})
end
end