This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--- Screenshots and related configuration settings
|
|
|
|
--
|
|
|
|
-- @author Brian Sobulefsky <brian.sobulefsky@protonmail.com>
|
|
|
|
-- @copyright 2021 Brian Sobulefsky
|
|
|
|
-- @inputmodule awful.screenshot
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
-- Grab environment we need
|
2022-09-05 10:10:40 +02:00
|
|
|
local capi = {
|
|
|
|
root = root,
|
|
|
|
screen = screen,
|
|
|
|
client = client,
|
|
|
|
mousegrabber = mousegrabber
|
|
|
|
}
|
|
|
|
|
|
|
|
local gears = require("gears")
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
local beautiful = require("beautiful")
|
2022-09-05 10:10:40 +02:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
local abutton = require("awful.button")
|
|
|
|
local akey = require("awful.key")
|
|
|
|
local glib = require("lgi").GLib
|
|
|
|
local datetime = glib.DateTime
|
|
|
|
local timezone = glib.TimeZone
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-02-03 08:47:44 +01:00
|
|
|
-- The module to be returned
|
2022-09-05 10:10:40 +02:00
|
|
|
local module = { mt = {}, _screenshot_methods = {} }
|
|
|
|
local screenshot_validation = {}
|
|
|
|
|
|
|
|
local datetime_obj = datetime.new_now
|
|
|
|
|
|
|
|
-- When $SOURCE_DATE_EPOCH and $SOURCE_DIRECTORY are both set, then this code is
|
|
|
|
-- most likely being run by the test runner. Ensure reproducible dates.
|
|
|
|
local source_date_epoch = tonumber(os.getenv("SOURCE_DATE_EPOCH"))
|
|
|
|
if source_date_epoch and os.getenv("SOURCE_DIRECTORY") then
|
|
|
|
datetime_obj = function()
|
|
|
|
return datetime.new_from_unix_utc(source_date_epoch)
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
2022-09-05 10:10:40 +02:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Generate a date string with the same format as the `textclock` and also with
|
|
|
|
-- support Debian reproducible builds.
|
|
|
|
local function get_date(format)
|
|
|
|
return datetime_obj(timezone.new_local()):format(format)
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Convert to a real image surface so it can be added to an imagebox.
|
|
|
|
local function to_surface(raw_surface, width, height)
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.RGB24, width, height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
cr:set_source_surface(gears.surface(raw_surface))
|
|
|
|
cr:paint()
|
|
|
|
|
|
|
|
return img
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- The screenshot interactive frame color.
|
|
|
|
-- @beautiful beautiful.screenshot_frame_color
|
|
|
|
-- @tparam[opt="#ff0000"] color screenshot_frame_color
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- The screenshot interactive frame shape.
|
|
|
|
-- @beautiful beautiful.screenshot_frame_shape
|
|
|
|
-- @tparam[opt=gears.shape.rectangle] shape screenshot_frame_shape
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function screenshot_validation.directory(directory)
|
2022-02-03 08:47:44 +01:00
|
|
|
-- Fully qualify a "~/" path or a relative path to $HOME. One might argue
|
|
|
|
-- that the relative path should fully qualify to $PWD, but for a window
|
|
|
|
-- manager this should be the same thing to the extent that anything else
|
|
|
|
-- is arguably unexpected behavior.
|
|
|
|
if string.find(directory, "^~/") then
|
2022-09-05 10:10:40 +02:00
|
|
|
directory = string.gsub(directory, "^~/",
|
2022-08-24 09:17:41 +02:00
|
|
|
string.gsub(os.getenv("HOME"), "/*$", "/", 1))
|
2022-02-03 08:47:44 +01:00
|
|
|
elseif string.find(directory, "^[^/]") then
|
2022-09-05 10:10:40 +02:00
|
|
|
directory = string.gsub(os.getenv("HOME"), "/*$", "/", 1) .. directory
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
-- Assure that we return exactly one trailing slash
|
2022-08-24 09:17:41 +02:00
|
|
|
directory = string.gsub(directory, '/*$', '/', 1)
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Add a trailing "/" if none is present.
|
|
|
|
if directory:sub(-1) ~= "/" then
|
|
|
|
directory = directory .. "/"
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- If the directory eixsts, but cannot be used, print and error.
|
|
|
|
if gears.filesystem.is_dir(directory) and not gears.filesystem.dir_writable(directory) then
|
|
|
|
gears.debug.print_error("`"..directory.. "` is not writable.")
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return directory
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-02-03 08:47:44 +01:00
|
|
|
-- Internal function to sanitize a prefix string
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
--
|
2022-02-03 08:47:44 +01:00
|
|
|
-- Currently only strips all path separators ('/'). Allows for empty prefix.
|
2022-09-05 10:10:40 +02:00
|
|
|
function screenshot_validation.prefix(prefix)
|
|
|
|
if prefix:match("[/.]") then
|
|
|
|
gears.debug.print_error("`"..prefix..
|
|
|
|
"` is not a valid prefix because it contains `/` or `.`")
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return prefix
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Internal routine to verify that a file_path is valid.
|
|
|
|
function screenshot_validation.file_path(file_path)
|
|
|
|
if gears.filesystem.file_readable(file_path) then
|
|
|
|
gears.debug.print_error("`"..file_path.."` already exist.")
|
2022-07-17 18:39:02 +02:00
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return file_path
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Warn about invalid geometries.
|
|
|
|
function screenshot_validation.geometry(geo)
|
|
|
|
for _, part in ipairs {"x", "y", "width", "height" } do
|
|
|
|
if not geo[part] then
|
|
|
|
gears.debug.print_error("The screenshot geometry must be a table with "..
|
|
|
|
"`x`, `y`, `width` and `height`"
|
|
|
|
)
|
|
|
|
break
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return geo
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function screenshot_validation.screen(scr)
|
|
|
|
return capi.screen[scr]
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local function make_file_name(self, method)
|
|
|
|
local date_time = get_date(self.date_format)
|
|
|
|
method = method and method.."_" or ""
|
|
|
|
return self.prefix .. "_" .. method .. date_time .. ".png"
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local function make_file_path(self, method)
|
|
|
|
return self.directory .. (self._private.file_name or make_file_name(self, method))
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Internal function to do the actual work of taking a cropped screenshot
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
--
|
|
|
|
-- This function does not do any data checking. Public functions should do
|
|
|
|
-- all data checking. This function was made to combine the interactive sipper
|
|
|
|
-- run by the mousegrabber and the programmatically defined snip function,
|
|
|
|
-- though there may be other uses.
|
2022-09-05 10:10:40 +02:00
|
|
|
local function crop_shot(source, geo)
|
|
|
|
local target = source:create_similar(cairo.Content.COLOR, geo.width, geo.height)
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local cr = cairo.Context(target)
|
|
|
|
cr:set_source_surface(source, -geo.x, -geo.y)
|
|
|
|
cr:rectangle(0, 0, geo.width, geo.height)
|
|
|
|
cr:fill()
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return target
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Internal function used by the interactive mode mousegrabber to update the
|
|
|
|
-- frame outline of the current state of the cropped screenshot
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
--
|
|
|
|
-- This function is largely a copy of awful.mouse.snap.show_placeholder(geo),
|
|
|
|
-- so it is probably a good idea to create a utility routine to handle both use
|
|
|
|
-- cases. It did not seem appropriate to make that change as a part of the pull
|
|
|
|
-- request that was creating the screenshot API, as it would clutter and
|
|
|
|
-- confuse the change.
|
2022-09-05 10:10:40 +02:00
|
|
|
local function show_frame(self, surface, geo)
|
|
|
|
local col = self._private.frame_color
|
|
|
|
or beautiful.screenshot_frame_color
|
|
|
|
or "#ff0000"
|
|
|
|
|
|
|
|
local shape = self.frame_shape
|
|
|
|
or beautiful.screenshot_frame_shape
|
|
|
|
or gears.shape.rectangle
|
|
|
|
|
|
|
|
local w, h = root.size()
|
|
|
|
|
|
|
|
self._private.selection_widget = wibox.widget {
|
|
|
|
border_width = 3,
|
|
|
|
border_color = col,
|
|
|
|
shape = shape,
|
|
|
|
color = "transparent",
|
|
|
|
visible = false,
|
|
|
|
widget = wibox.widget.separator
|
|
|
|
}
|
|
|
|
self._private.selection_widget.point = {x=0, y=0}
|
|
|
|
self._private.selection_widget.fit = function() return 0,0 end
|
|
|
|
|
|
|
|
self._private.canvas_widget = wibox.widget {
|
|
|
|
widget = wibox.layout.manual
|
|
|
|
}
|
|
|
|
|
|
|
|
self._private.imagebox = wibox.widget {
|
|
|
|
image = surface,
|
|
|
|
widget = wibox.widget.imagebox
|
|
|
|
}
|
|
|
|
|
|
|
|
self._private.imagebox.point = geo
|
|
|
|
self._private.canvas_widget:add(self._private.imagebox)
|
|
|
|
self._private.canvas_widget:add(self._private.selection_widget)
|
|
|
|
|
|
|
|
self._private.frame = wibox {
|
|
|
|
ontop = true,
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
width = w,
|
|
|
|
height = h,
|
|
|
|
widget = self._private.canvas_widget,
|
|
|
|
visible = true,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Emitted when the interactive succeed.
|
|
|
|
-- @signal snipping::success
|
|
|
|
-- @tparam awful.screenshot self
|
|
|
|
|
|
|
|
--- Emitted when the interactive is cancelled.
|
|
|
|
-- @signal snipping::cancelled
|
|
|
|
-- @tparam awful.screenshot self
|
|
|
|
-- @tparam string reason Either `"mouse_button"`, `"key"`, or `"too_small"`.
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Internal function that generates the callback to be passed to the
|
|
|
|
-- mousegrabber that implements the interactive mode.
|
|
|
|
--
|
|
|
|
-- The interactive tool is basically a mousegrabber, which takes a single function
|
|
|
|
-- of one argument, representing the mouse state data.
|
|
|
|
local function start_snipping(self, surface, geometry, method)
|
|
|
|
self._private.mg_first_pnt = {}
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local accept_buttons, reject_buttons = {}, {}
|
2021-11-13 21:27:05 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--TODO support modifiers.
|
|
|
|
for _, btn in ipairs(self.accept_buttons) do
|
|
|
|
accept_buttons[btn.button] = true
|
|
|
|
end
|
|
|
|
for _, btn in ipairs(self.reject_buttons) do
|
|
|
|
reject_buttons[btn.button] = true
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local pressed = false
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
show_frame(self, surface, geometry)
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local function ret_mg_callback(mouse_data, accept, reject)
|
|
|
|
local frame = self._private.frame
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
for btn, status in pairs(mouse_data.buttons) do
|
|
|
|
accept = accept or (status and accept_buttons[btn])
|
|
|
|
reject = reject or (status and reject_buttons[btn])
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
if reject then
|
|
|
|
frame.visible = false
|
|
|
|
self._private.frame, self._private.mg_first_pnt = nil, nil
|
|
|
|
self:emit_signal("snipping::cancelled", "mouse_button")
|
|
|
|
|
|
|
|
return false
|
|
|
|
elseif pressed then
|
|
|
|
local min_x = math.min(self._private.mg_first_pnt[1], mouse_data.x)
|
|
|
|
local max_x = math.max(self._private.mg_first_pnt[1], mouse_data.x)
|
|
|
|
local min_y = math.min(self._private.mg_first_pnt[2], mouse_data.y)
|
|
|
|
local max_y = math.max(self._private.mg_first_pnt[2], mouse_data.y)
|
|
|
|
|
|
|
|
local new_geo = {
|
|
|
|
x = min_x,
|
|
|
|
y = min_y,
|
|
|
|
width = max_x - min_x,
|
|
|
|
height = max_y - min_y,
|
|
|
|
}
|
|
|
|
|
|
|
|
if not accept then
|
|
|
|
-- Released
|
|
|
|
|
|
|
|
self._private.frame, self._private.mg_first_pnt = nil, nil
|
|
|
|
|
|
|
|
-- This may fail gracefully anyway but require a minimum 3x3 of pixels
|
|
|
|
if min_x >= max_x-1 or min_y >= max_y-1 then
|
|
|
|
self:emit_signal("snipping::cancelled", "too_small")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
self._private.selection_widget.visible = false
|
|
|
|
|
|
|
|
self._private.surfaces[method] = {
|
|
|
|
surface = crop_shot(surface, new_geo),
|
|
|
|
geometry = new_geo
|
|
|
|
}
|
|
|
|
|
|
|
|
self:emit_signal("snipping::success")
|
|
|
|
self:save()
|
|
|
|
|
|
|
|
frame.visible = false
|
|
|
|
self._private.frame, self._private.mg_first_pnt = nil, nil
|
|
|
|
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
-- Update position
|
|
|
|
self._private.selection_widget.point.x = min_x
|
|
|
|
self._private.selection_widget.point.y = min_y
|
|
|
|
self._private.selection_widget.fit = function()
|
|
|
|
return new_geo.width, new_geo.height
|
|
|
|
end
|
|
|
|
self._private.selection_widget:emit_signal("widget::layout_changed")
|
|
|
|
self._private.canvas_widget:emit_signal("widget::redraw_needed")
|
|
|
|
end
|
|
|
|
elseif accept then
|
|
|
|
pressed = true
|
|
|
|
self._private.selection_widget.visible = true
|
|
|
|
self._private.selection_widget.point.x = mouse_data.x
|
|
|
|
self._private.selection_widget.point.y = mouse_data.y
|
|
|
|
self._private.mg_first_pnt[1] = mouse_data.x
|
|
|
|
self._private.mg_first_pnt[2] = mouse_data.y
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return true
|
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
capi.mousegrabber.run(ret_mg_callback, self.cursor)
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-02-03 08:47:44 +01:00
|
|
|
-- Internal function exected when a root window screenshot is taken.
|
2022-09-05 10:10:40 +02:00
|
|
|
function module._screenshot_methods.root()
|
|
|
|
local w, h = root.size()
|
|
|
|
return to_surface(capi.root.content(), w, h), {x = 0, y = 0, width = w, height = h}
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Internal function executed when a physical screen screenshot is taken.
|
2022-09-05 10:10:40 +02:00
|
|
|
function module._screenshot_methods.screen(self)
|
|
|
|
local geo = self.screen.geometry
|
|
|
|
return to_surface(self.screen.content, geo.width, geo.height), geo
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Internal function executed when a client window screenshot is taken.
|
2022-09-05 10:10:40 +02:00
|
|
|
function module._screenshot_methods.client(self)
|
|
|
|
local c = self.client
|
|
|
|
local bw = c.border_width
|
|
|
|
local _, top_size = c:titlebar_top()
|
|
|
|
local _, right_size = c:titlebar_right()
|
|
|
|
local _, bottom_size = c:titlebar_bottom()
|
|
|
|
local _, left_size = c:titlebar_left()
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local c_geo = c:geometry()
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local actual_geo = {
|
|
|
|
x = c_geo.x + left_size + bw,
|
|
|
|
y = c_geo.y + top_size + bw,
|
|
|
|
width = c_geo.width - right_size - left_size,
|
|
|
|
height = c_geo.height - bottom_size - top_size,
|
|
|
|
}
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return to_surface(c.content, actual_geo.width, actual_geo.height), actual_geo
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-02-03 08:47:44 +01:00
|
|
|
-- Internal function executed when a snip screenshow (a defined geometry) is
|
|
|
|
-- taken.
|
2022-09-05 10:10:40 +02:00
|
|
|
function module._screenshot_methods.geometry(self)
|
|
|
|
local root_w, root_h = root.size()
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local root_intrsct = gears.geometry.rectangle.get_intersection(self.geometry, {
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
width = root_w,
|
|
|
|
height = root_h
|
|
|
|
})
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return crop_shot(module._screenshot_methods.root(self), root_intrsct), root_intrsct
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Various accessors for the screenshot object returned by any public
|
|
|
|
-- module method.
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot directory property.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
|
|
|
-- @property directory
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam[opt=os.getenv("HOME")] string directory
|
|
|
|
-- @propemits true false
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot prefix property.
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
--
|
2022-02-03 08:47:44 +01:00
|
|
|
-- @property prefix
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam[opt="Screenshot-"] string prefix
|
|
|
|
-- @propemits true false
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Get screenshot file path.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @property file_path
|
|
|
|
-- @tparam[opt=self.directory..self.prefix..os.date()..".png"] string file_path
|
|
|
|
-- @propemits true false
|
|
|
|
-- @see file_name
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Get screenshot file name.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @property file_name
|
|
|
|
-- @tparam[opt=self.prefix..os.date()..".png"] string file_name
|
|
|
|
-- @propemits true false
|
|
|
|
-- @see file_path
|
|
|
|
|
|
|
|
--- The date format used in the default suffix.
|
|
|
|
-- @property date_format
|
|
|
|
-- @tparam[opt="%Y%m%d%H%M%S"] string date_format
|
|
|
|
-- @see wibox.widget.textclock
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- The cursor used in interactive mode.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @property cursor
|
|
|
|
-- @tparam[opt="crosshair"] string cursor
|
|
|
|
-- @propemits true false
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Use the mouse to select an area (snipping tool).
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @property interactive
|
|
|
|
-- @tparam[opt=false] boolean interactive
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot screen.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
|
|
|
-- @property screen
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam[opt=nil] screen|nil screen
|
|
|
|
-- @see mouse.screen
|
|
|
|
-- @see awful.screen.focused
|
|
|
|
-- @see screen.primary
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot client.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
|
|
|
-- @property client
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam[opt=nil] client|nil client
|
|
|
|
-- @see mouse.client
|
|
|
|
-- @see client.focus
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot geometry.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
|
|
|
-- @property geometry
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam table geometry
|
|
|
|
-- @tparam table geometry.x
|
|
|
|
-- @tparam table geometry.y
|
|
|
|
-- @tparam table geometry.width
|
|
|
|
-- @tparam table geometry.height
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Get screenshot surface.
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- If none, or only one of: `screen`, `client` or `geometry` is provided, then
|
|
|
|
-- this screenshot object will have a single target image. While specifying
|
|
|
|
-- multiple target isn't recommended, you can use the `surfaces` properties
|
|
|
|
-- to access them.
|
|
|
|
--
|
|
|
|
-- Note that this is empty until either `save` or `refresh` is called.
|
|
|
|
--
|
2022-02-03 08:47:44 +01:00
|
|
|
-- @property surface
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam nil|image surface
|
|
|
|
-- @propertydefault `nil` if the screenshot hasn't been taken yet, a `gears.surface`
|
|
|
|
-- compatible image otherwise.
|
|
|
|
-- @readonly
|
|
|
|
-- @see surfaces
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Get screenshot surfaces.
|
|
|
|
--
|
|
|
|
-- When multiple methods are enabled for the same screenshot, then it will
|
|
|
|
-- have multiple images. This property exposes each image individually.
|
|
|
|
--
|
|
|
|
-- Note that this is empty until either `save` or `refresh` is called. Also
|
|
|
|
-- note that you should make multiple `awful.screenshot` objects rather than
|
|
|
|
-- put multiple targets in the same object.
|
|
|
|
--
|
|
|
|
-- @property surfaces
|
|
|
|
-- @tparam[opt={}] table surfaces
|
|
|
|
-- @tparam[opt=nil] image surfaces.root The screenshot of all screens. This is
|
|
|
|
-- the default if none of `client`, screen` or `geometry` have been set.
|
|
|
|
-- @tparam[opt=nil] image surfaces.client The surface for the `client` property.
|
|
|
|
-- @tparam[opt=nil] image surfaces.screen The surface for the `screen` property.
|
|
|
|
-- @tparam[opt=nil] image surfaces.geometry The surface for the `geometry` property.
|
|
|
|
-- @readonly
|
|
|
|
-- @see surface
|
|
|
|
|
|
|
|
--- The interactive frame color.
|
|
|
|
-- @property frame_color
|
|
|
|
-- @tparam color|nil frame_color
|
|
|
|
-- @propbeautiful
|
|
|
|
-- @propemits true false
|
|
|
|
|
|
|
|
--- The interactive frame shape.
|
|
|
|
-- @property frame_shape
|
|
|
|
-- @tparam shape|nil frame_shape
|
|
|
|
-- @propbeautiful
|
|
|
|
-- @propemits true false
|
|
|
|
|
|
|
|
--- Define which mouse button exit the interactive snipping mode.
|
|
|
|
--
|
|
|
|
-- @property reject_buttons
|
|
|
|
-- @tparam[opt={awful.button({}, 3)}}] table reject_buttons
|
|
|
|
-- @tablerowtype A list of `awful.button` objects.
|
|
|
|
-- @propemits true false
|
|
|
|
-- @see accept_buttons
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Mouse buttons used to save the screenshot when using the interactive snipping mode.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @property accept_buttons
|
|
|
|
-- @tparam[opt={awful.button({}, 1)}}] table accept_buttons
|
|
|
|
-- @tablerowtype A list of `awful.button` objects.
|
|
|
|
-- @propemits true false
|
|
|
|
-- @see reject_buttons
|
|
|
|
|
|
|
|
local defaults = {
|
|
|
|
prefix = "Screenshot-",
|
|
|
|
directory = screenshot_validation.directory(os.getenv("HOME")),
|
|
|
|
cursor = "crosshair",
|
|
|
|
date_format = "%Y%m%d%H%M%S",
|
|
|
|
interactive = false,
|
|
|
|
reject_buttons = {abutton({}, 3)},
|
|
|
|
accept_buttons = {abutton({}, 1)},
|
|
|
|
reject_keys = {akey({}, "Escape")},
|
|
|
|
accept_keys = {akey({}, "Return")},
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Create the standard properties.
|
|
|
|
for _, prop in ipairs { "frame_color", "geometry", "screen", "client", "date_format",
|
|
|
|
"prefix", "directory", "file_path", "file_name", "cursor",
|
|
|
|
"interactive", "reject_buttons", "accept_buttons",
|
|
|
|
"reject_keys", "accept_keys", "frame_shape" } do
|
|
|
|
module["set_"..prop] = function(self, value)
|
|
|
|
self._private[prop] = screenshot_validation[prop]
|
|
|
|
and screenshot_validation[prop](value) or value
|
|
|
|
self:emit_signal("property::"..prop, value)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
module["get_"..prop] = function(self)
|
|
|
|
return self._private[prop] or defaults[prop]
|
|
|
|
end
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:get_file_path()
|
|
|
|
return self._private.file_path or make_file_path(self)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:get_file_name()
|
|
|
|
return self._private.file_name or make_file_name(self)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:get_surface()
|
|
|
|
return self.surfaces[1]
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:get_surfaces()
|
|
|
|
local ret = {}
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
for method, surface in pairs(self._private.surfaces or {}) do
|
|
|
|
ret[method] = surface.surface
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return ret
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:get_surfaces()
|
|
|
|
local ret = {}
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
for _, surface in pairs(self._private.surfaces or {}) do
|
|
|
|
table.insert(ret, surface.surface)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return ret
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Take new screenshot(s) now.
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- @method refresh
|
|
|
|
-- @treturn table A table with the method name as key and the images as value.
|
|
|
|
-- @see save
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
function module:refresh()
|
|
|
|
local methods = {}
|
|
|
|
self._private.surfaces = {}
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
for method in pairs(module._screenshot_methods) do
|
|
|
|
if self._private[method] then
|
|
|
|
table.insert(methods, method)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
-- Fallback to a screenshot of everything.
|
|
|
|
methods = #methods > 0 and methods or {"root"}
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
for _, method in ipairs(methods) do
|
|
|
|
local surface, geo = module._screenshot_methods[method](self)
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
if self.interactive then
|
|
|
|
start_snipping(self, surface, geo, method)
|
|
|
|
else
|
|
|
|
self._private.surfaces[method] = {surface = surface, geometry = geo}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return self.surfaces
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Emitted when a the screenshot is saved.
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-09-05 10:10:40 +02:00
|
|
|
-- This can be due to `:save()` being called, the `interactive` mode finishing
|
|
|
|
-- or `auto_save_delay` timing out.
|
|
|
|
--
|
|
|
|
-- @signal file::saved
|
|
|
|
-- @tparam awful.screenshot self The screenshot.
|
|
|
|
-- @tparam string file_path The path.
|
|
|
|
-- @tparam[opt] string|nil method The method associated with the file_path. This
|
|
|
|
-- can be `root`, `geometry`, `client` or `screen`.
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
--- Save screenshot.
|
|
|
|
--
|
|
|
|
-- @method save
|
|
|
|
-- @tparam[opt=self.file_path] string file_path Optionally override the file path.
|
|
|
|
-- @noreturn
|
|
|
|
-- @emits saved
|
|
|
|
-- @see refresh
|
|
|
|
function module:save(file_path)
|
|
|
|
if not self._private.surfaces then self:refresh() end
|
|
|
|
|
|
|
|
for method, surface in pairs(self._private.surfaces) do
|
|
|
|
file_path = file_path
|
|
|
|
or self._private.file_path
|
|
|
|
or make_file_path(self, #self._private.surfaces > 1 and method or nil)
|
|
|
|
|
|
|
|
surface.surface:write_to_png(file_path)
|
|
|
|
self:emit_signal("file::saved", file_path, method)
|
|
|
|
end
|
2022-02-03 08:47:44 +01:00
|
|
|
end
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-07-17 18:39:02 +02:00
|
|
|
--- Screenshot constructor - it is possible to call this directly, but it is.
|
2022-02-04 06:20:50 +01:00
|
|
|
-- recommended to use the helper constructors, such as awful.screenshot.root
|
2022-02-03 08:47:44 +01:00
|
|
|
--
|
2022-07-17 18:39:02 +02:00
|
|
|
-- @constructorfct awful.screenshot
|
2022-09-05 10:10:40 +02:00
|
|
|
-- @tparam[opt={}] table args
|
|
|
|
-- @tparam[opt] string args.directory Get screenshot directory property.
|
|
|
|
-- @tparam[opt] string args.prefix Get screenshot prefix property.
|
|
|
|
-- @tparam[opt] string args.file_path Get screenshot file path.
|
|
|
|
-- @tparam[opt] string args.file_name Get screenshot file name.
|
|
|
|
-- @tparam[opt] screen args.screen Get screenshot screen.
|
|
|
|
-- @tparam[opt] string args.date_format The date format used in the default suffix.
|
|
|
|
-- @tparam[opt] string args.cursor The cursor used in interactive mode.
|
|
|
|
-- @tparam[opt] boolean args.interactive Rather than take a screenshot of an
|
|
|
|
-- object, use the mouse to select an area.
|
|
|
|
-- @tparam[opt] client args.client Get screenshot client.
|
|
|
|
-- @tparam[opt] table args.geometry Get screenshot geometry.
|
|
|
|
-- @tparam[opt] color args.frame_color The frame color.
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
local function new(_, args)
|
|
|
|
args = (type(args) == "table" and args) or {}
|
|
|
|
local self = gears.object({
|
|
|
|
enable_auto_signals = true,
|
|
|
|
enable_properties = true
|
|
|
|
})
|
2022-02-03 08:47:44 +01:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
self._private = {}
|
|
|
|
gears.table.crush(self, module, true)
|
|
|
|
gears.table.crush(self, args)
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
|
2022-09-05 10:10:40 +02:00
|
|
|
return self
|
This commit begins the development of a more appropriate user facing
screenshot API. It extends a prior commit which extended the lower level
content API, which had been a property of the client object but is now
available as a property of the screen object and a method of the root
object.
This commit creates a new screenshot module for the awful module. The
public functions include root(), screen(), client(), snipper(), and
snip(). These take root window, screen, and client window screenshots,
launch an interactive snip tool for cropped screenshots, and take a
cropped screenshot of a geometry passed by argument, respectively. The
init() function is also available for configuration. Using this library
is more appropriate for the average rc.lua.
Since the API is new, this commit does not include any changes to
rc.lua. The developers can modify rc.lua when there is sufficient
confidence in API stability and robustness.
lib/awful/init.lua is modified so that the awful module includes the new
lib/awful/screenshot.lua submodule.
Signed off: Brian Sobulefsky <brian.sobulefsky@protonmail.com>
2021-10-12 05:54:47 +02:00
|
|
|
end
|
|
|
|
|
2022-02-03 08:47:44 +01:00
|
|
|
return setmetatable(module, {__call = new})
|
2022-09-05 10:10:40 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|