This commit is contained in:
nixo 2020-05-12 20:43:10 +02:00
parent 625f5aed51
commit 00770d5723
1 changed files with 19 additions and 18 deletions

View File

@ -3,8 +3,7 @@
#:use-module (gri3 hooks) #:use-module (gri3 hooks)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:export #:export (define-mode-map add-key-binding kbd key-press-hook clear-bindings))
(define-mode-map add-key-binding kbd key-press-hook clear-bindings))
(define *bindings* '()) (define *bindings* '())
(define *mode-map* '()) (define *mode-map* '())
@ -31,33 +30,35 @@
#t) #t)
#f)))) #f))))
(define (notify-exceptions exc)
(system (format #f "notify-send exception ~A" exc)))
(define (key-press-hook param)
(with-exception-handler notify-exceptions key-press-hook-real #:unwind? #t))
(define (clear-bindings) (set! *bindings* '())) (define (clear-bindings) (set! *bindings* '()))
(define (add-key-binding key func) (define (add-key-binding key func)
(match-let (((mode (press mod keysym)) key)) (match-let (((mode (press mod keysym)) key))
;; (format #t "Binding key ~A\n" keysym) ;; (format #t "Binding key ~A\n" keysym)
;; get notified for key with all mods ;; get notified for key with all mods
(for-each (for-each (lambda (mod) (bind-key keysym mod)) (list #x8 #x10 #x26 #x40))
(lambda (mod)
(bind-key keysym mod))
(list #x8 #x10 #x26 #x40))
;; Store the key+func couple in the list of hooks ;; Store the key+func couple in the list of hooks
(set! *bindings* (set! *bindings* (assoc-set! *bindings* `("default" (,press ,mod ,keysym)) func))))
(assoc-set! *bindings* `("default" (,press ,mod ,keysym)) func))))
(define (special->keysym name) (define (special->keysym name)
(or (assoc-ref '( ;; ("NUL") (or (assoc-ref
;; ("REM") '( ;; ("NUL")
("RET" . "Return") ;; ("REM")
("TAB" . "Tab") ("RET" . "Return")
("LFD" . "Linefeed") ("TAB" . "Tab")
("ESC" . "Escape") ("LFD" . "Linefeed")
("SPC" . "space") ("ESC" . "Escape")
("DEL" . "Delete")) ("SPC" . "space")
name) ("DEL" . "Delete"))
name)
name)) name))
(define (define-mode-map map mode) (define (define-mode-map map mode)
(set! *mode-map* (append *mode-map* `((,map . ,mode))))) (set! *mode-map* (append *mode-map* `((,map . ,mode)))))