mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
Added screenshot contrib
This commit is contained in:
parent
becb288110
commit
6566715c80
5
util/screenshot/README.org
Normal file
5
util/screenshot/README.org
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
** Usage
|
||||
Add this to your =.stumpwmrc=:
|
||||
#+BEGIN_SRC lisp
|
||||
(load-module "screenshot")
|
||||
#+END_SRC
|
||||
14
util/screenshot/package.lisp
Normal file
14
util/screenshot/package.lisp
Normal 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
|
||||
))
|
||||
10
util/screenshot/screenshot.asd
Normal file
10
util/screenshot/screenshot.asd
Normal 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")))
|
||||
50
util/screenshot/screenshot.lisp
Normal file
50
util/screenshot/screenshot.lisp
Normal 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))
|
||||
Loading…
Reference in a new issue