Create a base version of layot switcher.

This commit is contained in:
Wojciech Gac 2015-08-07 16:03:39 +02:00
parent 816b32ed7b
commit 61adf7ce2d
5 changed files with 90 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*~

View file

@ -0,0 +1,9 @@
Keyboard layout switcher for StumpWM
** Usage
Add
#+BEGIN_SRC lisp
(load-module "kbd-layouts")
#+END_SRC
to =.stumpwmrc=

View file

@ -0,0 +1,13 @@
;;;; kbd-layouts.asd
(asdf:compute-source-registry)
(declaim (optimize (speed 0) (debug 3) (safety 3)))
(asdf:defsystem #:kbd-layouts
:serial t
:description "Describe kbd-layouts here"
:author "Wojciech Gac"
:license "GPLv3"
:depends-on (#:stumpwm)
:components ((:file "package")
(:file "kbd-layouts")))

View file

@ -0,0 +1,59 @@
;;;; kbd-layouts.lisp
(in-package #:kbd-layouts)
;;;;;;;;;;;;;;;
;; Variables ;;
;;;;;;;;;;;;;;;
(defvar *available-keyboard-layouts* nil)
;; Output from 'setxkbmap -print' is authoritative
(defvar *current-keyboard-layout* nil)
;; Available options:
;; :normal -> CapsLock
;; :ctrl -> Ctrl
(defvar *caps-lock-behavior* nil)
;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions ;;
;;;;;;;;;;;;;;;;;;;;;;
(defun keyboard-layout-list (&rest layouts)
"Return a circular list of keyboard layouts (as given to
setxkbmap). The first layout in the list will be the default."
(rplacd (last layouts) layouts)
(setf *available-keyboard-layouts* layouts)
;; Immediately select first layout from the list
(switch-keyboard-layout))
(defun current-keyboard-layout (ml)
"Return current keyboard layout"
(declare (ignore ml))
(let ((cmd "setxkbmap -print | awk -F'+' '/xkb_symbols/ {print $2}'"))
(string-trim '(#\Newline) (run-shell-command cmd t))))
;; Make the current keyboard layout accessible from the modeline via %L.
(add-screen-mode-line-formatter #\L #'current-keyboard-layout)
;;;;;;;;;;;;;;
;; Commands ;;
;;;;;;;;;;;;;;
(defcommand switch-keyboard-layout () ()
(let* ((layout (pop *available-keyboard-layouts*))
(cmd (format nil "setxkbmap ~a" layout)))
;;;;;;;;;;;;;;
;; Defaults ;;
;;;;;;;;;;;;;;
(keyboard-layout-list "us")
(setf *caps-lock-behavior* :normal)
(define-key *top-map* (kbd "S-space") "switch-keyboard-layout")
;; Run it once to set the default layout
;; (switch-keyboard-layout)

View file

@ -0,0 +1,8 @@
;;;; package.lisp
(defpackage #:kbd-layouts
(:use #:cl #:stumpwm)
(:export
))