Files
riverguile/README.md
Leon Henrik Plickat a5b129d637 Update README
2024-01-15 10:16:02 +01:00

58 lines
2.3 KiB
Markdown

# riverguile
Scripting layer for the [river](https://github.com/riverwm/river) Wayland
server using [Guile Scheme](https://www.gnu.org/software/guile/). Send commands
to river and install handlers for various events, including layout demands.
The ultimate aim of giverguile is to allow comfortable scripting in the context
of desktop operations, including window management.
> "So, the UNIX philosophy is nice and all, but I wish I could script my desktop
> in a way that's a bit more integrated and less hacky."
Do you agree with that statement? Do you like Lisp / Scheme? Do you believe
policy over mechanism is the only sane way to design a scripting API? Then
riverguile might be what you want!
Riverguile follows river development closely, exposing new functionality as
scheme procedures and advocating for even more scripting features. Right now,
riverguile is implemented as an interpreter for river init scripts.
```scheme
#!/bin/env riverguile
!#
(use-modules (riverguile))
;; Lock the screen after five minutes and darken the screen.
(install-handler 'idle:300 (lambda (event)
(cond ((eq? event 'idle) (system "swaylock &")
(system "backlight.sh set-to 40"))
((eq? event 'resume) (system "backlight.sh set-to 100")))))
(define split 0.55)
(define (layout:rows n x y w h)
(letrec ((height (/ h n))
(rows (lambda (n)
(if (eq? n 0)
'()
(let ((Y (- (+ y h) (* n height))))
(append (list (list x Y w height))
(rows (- n 1))))))))
(rows n)))
(define (layout:split n x y w h)
(if (eq? n 1)
(list (list x y w h))
(letrec* ((left (* split w))
(right (- w left)))
(append (list (list x y left h))
(layout:rows (- n 1) (+ x left) y right h)))))
;; Replicate rivertile.
(R default-layout riverguile)
(install-handler 'layout-demand (lambda (view-count width height tags output)
(layout:split view-count 0 0 width height)))
```