Added screenshot contrib

This commit is contained in:
Alex Ermolov 2015-03-01 21:13:01 +03:00
parent becb288110
commit 6566715c80
4 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,5 @@
** Usage
Add this to your =.stumpwmrc=:
#+BEGIN_SRC lisp
(load-module "screenshot")
#+END_SRC

View file

@ -0,0 +1,14 @@
;;;; package.lisp
(defpackage #:screenshot
(:use #:cl :stumpwm :zpng))
(in-package #:screenshot)
(import
'(
zpng::finish-png
zpng::pixel-streamed-png
zpng::start-png
zpng::write-pixel
))

View file

@ -0,0 +1,10 @@
;;;; screenshot.asd
(asdf:defsystem #:screenshot
:serial t
:description "Describe screenshot here"
:author "Michael Filonenko"
:license "GPLv3"
:depends-on (#:zpng)
:components ((:file "package")
(:file "screenshot")))

View file

@ -0,0 +1,50 @@
(in-package #:screenshot)
(export '(screenshot screenshot-window))
(defun %screenshot-window (drawable file &key (height (xlib:drawable-height drawable))
(width (xlib:drawable-width drawable)))
(let* ((png (make-instance 'pixel-streamed-png
:color-type :truecolor-alpha
:width width
:height height)))
(multiple-value-bind (pixarray depth visual)
(xlib:get-raw-image drawable :x 0 :y 0 :width width :height height
:format :Z-PIXMAP)
(declare (ignore depth visual))
(with-open-file (stream file
:direction :output
:if-exists :supersede
:if-does-not-exist :create
:element-type '(unsigned-byte 8))
(start-png png stream)
(case (xlib:display-byte-order (xlib:drawable-display drawable))
(:lsbfirst
(do ((i 0 (+ 4 i)))
((>= i (length pixarray)))
(write-pixel (list (aref pixarray (+ 2 i))
(aref pixarray (+ 1 i))
(aref pixarray i)
#xFF)
png)))
(:msbfirst
(do ((i 0 (+ 4 i)))
((>= i (* height width 4)))
(write-pixel (list (aref pixarray (1+ i))
(aref pixarray (+ 2 i))
(aref pixarray (+ 3 i))
#xFF)
png))))
(finish-png png)))))
(stumpwm:defcommand screenshot
(filename)
((:rest "Filename: "))
"Make screenshot of root window"
(%screenshot-window (stumpwm:screen-root (stumpwm:current-screen)) filename))
(stumpwm:defcommand screenshot-window
(filename)
((:rest "Filename: "))
"Make screenshot of focus window"
(%screenshot-window (stumpwm:window-xwin (stumpwm:current-window)) filename))