mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
Create a base version of layot switcher.
This commit is contained in:
parent
816b32ed7b
commit
61adf7ce2d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*~
|
||||
9
util/kbd-layouts/README.org
Normal file
9
util/kbd-layouts/README.org
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Keyboard layout switcher for StumpWM
|
||||
|
||||
** Usage
|
||||
Add
|
||||
#+BEGIN_SRC lisp
|
||||
(load-module "kbd-layouts")
|
||||
#+END_SRC
|
||||
to =.stumpwmrc=
|
||||
|
||||
13
util/kbd-layouts/kbd-layouts.asd
Normal file
13
util/kbd-layouts/kbd-layouts.asd
Normal 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")))
|
||||
|
||||
59
util/kbd-layouts/kbd-layouts.lisp
Normal file
59
util/kbd-layouts/kbd-layouts.lisp
Normal 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)
|
||||
8
util/kbd-layouts/package.lisp
Normal file
8
util/kbd-layouts/package.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
;;;; package.lisp
|
||||
|
||||
(defpackage #:kbd-layouts
|
||||
(:use #:cl #:stumpwm)
|
||||
(:export
|
||||
))
|
||||
|
||||
|
||||
Loading…
Reference in a new issue