Skip to content

Commit

Permalink
Retry root keymap setup if initial keysym load fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mwitmer committed Jul 8, 2019
1 parent cd86ecf commit 268ec01
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions module/guile-wm/module/root-keymap.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#:use-module (guile-wm command)
#:use-module (guile-wm draw)
#:use-module (guile-wm shared)
#:use-module (ice-9 format)
#:use-module (srfi srfi-11)
#:export (root-keymap keymap-cursor with-root-keymap-disabled))

Expand All @@ -32,12 +33,17 @@
(define-once root-key-val 'C-t)
(define (root-key-ref) root-key-val)
(define (root-key-set! k)
(define keysyms (make-keysym-table))
(let-values (((old-codes old-mods) (symbol->key keysyms root-key-val))
((new-codes new-mods) (symbol->key keysyms k)))
(if old-codes (ungrab-key (car old-codes) target-win old-mods))
(grab-key #t target-win new-mods (car new-codes) 'async 'async)
(set! root-key-val k)))
(let lp ((attempts 0))
(define keysyms (make-keysym-table))
(let-values (((old-codes old-mods) (symbol->key keysyms root-key-val))
((new-codes new-mods) (symbol->key keysyms k)))
(if old-codes (ungrab-key (car old-codes) target-win old-mods))
(if (not new-codes)
(if (< attempts 4)
(lp (+ attempts 1))
(error "Key not defined" k))
(begin (grab-key #t target-win new-mods (car new-codes) 'async 'async)
(set! root-key-val k))))))

(define-public root-key (make-procedure-with-setter root-key-ref root-key-set!))

Expand Down

0 comments on commit 268ec01

Please sign in to comment.