-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenshot-maim.lisp
64 lines (54 loc) · 2.46 KB
/
screenshot-maim.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(in-package :screenshot-maim)
(defparameter *path* "/var/tmp/") ; default save path. must be with a leading and trailing slash
(defparameter *format* "png") ; if *ask-filename* is nil. Currently supports `png`, `jpg`, `bmp` and `webp`.
(defparameter *ask-filename* t)
(defparameter *save-to-clipboard* nil)
(defparameter *xclip-selection* "clipboard")
(defparameter *delay* 0.2)
(defparameter *hide-cursor* nil)
(defparameter *quality* 10) ; An integer from 1 to 10 that determines the compression quality.
(defvar *filename-format* "screenshot-~d-~2,'0d-~2,'0d_~2,'0d-~2,'0d-~2,'0d")
(defun maim (args)
(let ((filename (if *ask-filename*
(read-one-line (current-screen) "Filename: " :initial-input *path*)
(maim-gen-filename))))
(when filename
(stumpwm::unmap-message-window (current-screen))
(multiple-value-bind (_ err-text err-code)
(uiop:run-program (format nil "maim ~a --delay=~f --quality=~d ~a ~a"
args
*delay*
*quality*
(if *hide-cursor* "--hidecursor" "")
filename)
:ignore-error-status t
:error-output '(:string :stripped t)
:output nil)
(when (and (eq err-code 0) *save-to-clipboard*)
(uiop:run-program (format nil "xclip -selection ~a -target image/~a ~a"
*xclip-selection*
*format*
filename)
:ignore-error-status t
:error-output '(:string :stripped t)
:output nil))
(if (eq err-code 0)
(message "Screenshotted to ~a" filename)
(message err-text))))))
(defun maim-gen-filename ()
(multiple-value-bind (second minute hour day month year)
(get-decoded-time)
(concat
*path*
(format nil *filename-format* year month day hour minute second)
"."
*format*)))
(defcommand screenshot () ()
"Make screenshot of root window"
(maim ""))
(defcommand screenshot-area () ()
"Make screenshot of selected area of display."
(maim "--select "))
(defcommand screenshot-window () ()
"Make screenshot of focus window"
(maim "-i $(xdotool getactivewindow) "))