engstrand-config / dwl-guile

Dynamic tiling Wayland compositor configurable in Guile Scheme, based on dwl and libguile - now with a REPL!
Other
97 stars 5 forks source link

Add Emacs-like configuration #26

Closed Frewacom closed 1 year ago

Frewacom commented 1 year ago

Update config parser to use an Emacs-like configuration (see also https://github.com/engstrand-config/home-service-dwl-guile/issues/9).

This allows for a much more user-friendly configuration experience, as well as making it feasible to use dwl-guile without the Guix home-service. Settings can also easily be modified during runtime using dwl-guile -e "<exp>".

The config should look something like this:

;; General variables
(setq border-px 10
      root-color "#ffffff"
      focus-color "#000000")

;; Bindings can be set as a symbol or procedure (lambda)
(define (my-callback)
  (dwl:reload-config))

;; Run long running jobs in a new thread to prevent blocking of
;; dwl-guile main thread.
(define (my-non-blocking-callback)
  (dwl:async-eval
   (begin ...)))

(add-key "S-[127]" 'my-callback)
(add-key "S-<enter>" 'dwl:toggle-gaps)
(add-key "S-<space>" (lambda () (dwl:reload-config)))
(add-key "S-s-a" 'my-non-blocking-callback)

;; Mouse bindings with same add-key macro
(add-key "S-<mouse-left>" 'dwl:move)

;; Rules, layouts, etc, accept a key as first argument which allows you to
;; easily override certain behaviour if needed.
(add-rule 'emacs '((id "emacs") (alpha 1.0) (swallow? #t)))
(add-monitor-rule 'hdmi '((name "HDMI-1") (x 0) (y 0)))
(add-monitor-rule 'dp '((name "DP-1") (x 0) (y 1080)))

(add-layout 'tile "[]=" 'dwl:tile)
(add-layout 'monocle "|M|" 'dwl:monocle)
(add-layout 'fib "@" 'my-patch:fibonacci)

(add-xkb-config '((rules "...") (options "...")))
johanengstrand commented 1 year ago

Setting multiple keys/rules could look something like below. Not sure about the exact function names though.

;; General variables
(setq border-px 10
      root-color "#ffffff"
      focus-color "#000000")

;; Bindings can be set as a symbol or procedure (lambda)
(define (my-callback)
  (dwl:reload-config))

;; Run long running jobs in a new thread to prevent blocking of
;; dwl-guile main thread.
(define (my-non-blocking-callback)
  (dwl:async-eval
   (begin ...)))

;; Bind keys on keyboard ('keys)
(bind 'keys "S-[127]" 'my-callback
            "S-<enter>" 'dwl:toggle-gaps
            "S-<space>" (lambda () (dwl:reload-config))
            "S-s-a" 'my-non-blocking-callback)

;; Bind mouse buttons ('buttons)
(bind 'buttons "S-<mouse-left>" 'dwl:move)

;; Rules, layouts, etc, accept a key as first argument which allows you to
;; easily override certain behaviour if needed.
(set-rules 'emacs '((id "emacs") 
                    (alpha 1.0) 
                    (swallow? #t))
           'mpv '((id "mpv")
                  (alpha 1.0)
                  (swallow? #t)))

(set-monitors 'left '((name "HDMI-1") (x 0) (y 0))
              'right '((name "DP-1") (x 0) (y 1080)))

(set-layouts 'tile "[]=" 'dwl:tile
             'monocle "|M|" 'dwl:monocle
             'fib "[@]" 'my-patch:fibonacci)

(add-xkb-config '((rules "...") (options "...")))
Frewacom commented 1 year ago

Added in v2.0.0.