keys.lisp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. ;;; keys.lisp --- Key bindings (Dvorak layout)
  2. ;; Copyright © 2013–2019 Alex Kost <alezost@gmail.com>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (in-package :stumpwm)
  17. (set-prefix-key (kbd "s-t"))
  18. ;;; Functional/additional keys (placed on the same keys)
  19. (defvar al/f-keys-alist
  20. '(("F1" . "Help")
  21. ("F2" . "SunUndo")
  22. ("F3" . "SunAgain")
  23. ("F4" . "XF86New")
  24. ("F5" . "XF86Open")
  25. ("F6" . "XF86Close")
  26. ("F7" . "XF86Reply")
  27. ("F8" . "XF86Forward")
  28. ("F9" . "XF86Send")
  29. ("F10" . "XF86Spell")
  30. ("F11" . "XF86Save")
  31. ("F12" . "SunPrint_Screen"))
  32. "Alist of functional and additional keys bound to the same commands.")
  33. (defun al/define-key (map key command)
  34. "Similar to `define-key', except KEY should be a string.
  35. If KEY is a functional key from `al/f-keys-alist', bind COMMAND to the
  36. additional key."
  37. (define-key map (kbd key) command)
  38. (let ((add-key (cdr (assoc key al/f-keys-alist :test 'equal))))
  39. (when add-key
  40. (define-key map (kbd add-key) command))))
  41. ;; Bind "H-<key>" to sending <key> to the current window
  42. ;; (<key> is a key from `al/f-keys-alist').
  43. (dolist (key-assoc al/f-keys-alist)
  44. (let ((fun-key (car key-assoc))
  45. (add-key (cdr key-assoc)))
  46. (flet ((dk (bound-key sent-key)
  47. (define-key *top-map*
  48. (kbd (concat "H-" bound-key))
  49. (concat "al/send-key " sent-key))))
  50. (dk fun-key fun-key)
  51. (dk add-key fun-key))))
  52. ;;; Managing windows, frames & groups
  53. (al/define-key *root-map* "F" "fselect")
  54. (al/define-key *root-map* "=" "balance-frames")
  55. (al/define-key *root-map* "s-c" "delete-window")
  56. (al/define-key *root-map* "C" "kill-window")
  57. (al/define-key *root-map* "o" "al/fother")
  58. (al/define-key *root-map* "M-o" "fnext")
  59. (al/define-key *top-map* "s-r" "al/toggle-root")
  60. (al/define-key *top-map* "s-w" "windowlist")
  61. (al/define-key *top-map* "M-s-w" "vgroups")
  62. (al/define-key *top-map* "M-s-g" "grouplist")
  63. (al/define-key *top-map* "H-o" "al/other H-o")
  64. (al/define-key *top-map* "H-M-o" "al/next H-M-o")
  65. (al/define-key *top-map* "s-H-o" "al/toggle-ignore-emacs")
  66. (al/define-key *top-map* "s-n" "gother")
  67. (al/define-key *top-map* "M-s-n" "al/gmove-to-other-group")
  68. (al/define-key *tile-group-root-map* "s-f" "fullscreen")
  69. (al/define-key *tile-group-top-map* "s-z" "hsplit")
  70. (al/define-key *tile-group-top-map* "M-s-z" "vsplit")
  71. (al/define-key *tile-group-top-map* "s-x" "only")
  72. ;;; Focusing windows
  73. (al/define-key *tile-group-top-map* "s-b" "pull-hidden-other")
  74. (al/define-key *tile-group-top-map* "M-s-b" "pull-hidden-next")
  75. (al/define-key *tile-group-top-map* "s-TAB" "pull-hidden-next")
  76. (al/define-key *tile-group-top-map* "s-ISO_Left_Tab" "pull-hidden-previous")
  77. (al/define-key *float-group-top-map* "s-b" "al/float-window-other")
  78. (al/define-key *float-group-top-map* "M-s-b" "al/float-window-next")
  79. (al/define-key *float-group-top-map* "s-TAB" "al/float-window-next")
  80. (al/define-key *float-group-top-map* "s-ISO_Left_Tab" "al/float-window-previous")
  81. ;;; Moving/resizing windows
  82. ;; Use numpad keys for manipulating windows:
  83. ;; [C-]M-<key> for resizing
  84. ;; [C-]s-<key> for moving
  85. ;; C-<key> for moving to the screen edges
  86. (al/define-key *float-group-top-map*
  87. "s-KP_Begin" "al/float-window-gravity center")
  88. (defun al/define-numpad-key-xy (map modifier cmd val)
  89. (flet ((dk (key x y)
  90. (define-key map (kbd (concat modifier key))
  91. (format nil "~a ~D ~D" cmd x y))))
  92. (dk "KP_Home" (- val) (- val))
  93. (dk "KP_Up" 0 (- val))
  94. (dk "KP_Page_Up" val (- val))
  95. (dk "KP_Right" val 0)
  96. (dk "KP_Page_Down" val val)
  97. (dk "KP_Down" 0 val)
  98. (dk "KP_End" (- val) val)
  99. (dk "KP_Left" (- val) 0)))
  100. (al/define-numpad-key-xy *float-group-top-map* "s-" "al/move-float-window" 10)
  101. (al/define-numpad-key-xy *float-group-top-map* "C-s-" "al/move-float-window" 1)
  102. (al/define-numpad-key-xy *float-group-top-map* "M-" "al/resize-float-window" 10)
  103. (al/define-numpad-key-xy *float-group-top-map* "C-M-" "al/resize-float-window" 1)
  104. (defun al/define-numpad-key-gravity (map modifier cmd)
  105. (flet ((dk (key gravity)
  106. (define-key map (kbd (concat modifier key))
  107. (format nil "~a ~a" cmd gravity))))
  108. (dk "KP_Begin" "center")
  109. (dk "KP_Home" "top-left")
  110. (dk "KP_Up" "top")
  111. (dk "KP_Page_Up" "top-right")
  112. (dk "KP_Right" "right")
  113. (dk "KP_Page_Down" "bottom-right")
  114. (dk "KP_Down" "bottom")
  115. (dk "KP_End" "bottom-left")
  116. (dk "KP_Left" "left")))
  117. (al/define-numpad-key-gravity *tile-group-top-map* "C-" "gravity")
  118. (al/define-numpad-key-gravity *float-group-top-map* "C-" "al/float-window-gravity")
  119. ;;; Resizing frames
  120. (al/define-key *top-map* "M-s-XF86AudioRaiseVolume" "resize 0 10")
  121. (al/define-key *top-map* "M-s-XF86AudioLowerVolume" "resize 0 -10")
  122. (al/define-key *top-map* "C-M-s-XF86AudioRaiseVolume" "resize 0 1")
  123. (al/define-key *top-map* "C-M-s-XF86AudioLowerVolume" "resize 0 -1")
  124. (al/define-key *top-map* "s-XF86AudioRaiseVolume" "resize 10 0")
  125. (al/define-key *top-map* "s-XF86AudioLowerVolume" "resize -10 0")
  126. (al/define-key *top-map* "C-s-XF86AudioRaiseVolume" "resize 1 0")
  127. (al/define-key *top-map* "C-s-XF86AudioLowerVolume" "resize -1 0")
  128. ;;; Controlling WiFi
  129. (al/define-key *top-map* "XF86WLAN" "exec rfkill unblock wlan")
  130. (al/define-key *top-map* "s-XF86WLAN" "exec rfkill block wlan")
  131. ;; Pressing XF86RFKill blocks/unblocks wlan automatically (on the kernel
  132. ;; level), but this key is still available for binding.
  133. (al/define-key *top-map* "XF86RFKill" "echo The state of ^[^B^5*wlan^] has been changed")
  134. ;;; Controlling brightness
  135. (al/define-key *top-map* "XF86MonBrightnessUp" "exec osd-backlight -inc 3")
  136. (al/define-key *top-map* "XF86MonBrightnessDown" "exec osd-backlight -dec 3")
  137. (al/define-key *top-map* "M-XF86MonBrightnessUp" "exec osd-backlight -inc 10")
  138. (al/define-key *top-map* "M-XF86MonBrightnessDown" "exec osd-backlight -dec 10")
  139. ;;; Controlling sound
  140. (al/define-key *top-map* "XF86AudioMute" "al/sound-set-current-scontrol toggle")
  141. (al/define-key *top-map* "M-XF86AudioMute" "al/sound-next-scontrol")
  142. (al/define-key *top-map* "C-XF86AudioMute" "exec tvtime-command TOGGLE_MUTE")
  143. (al/define-key *top-map* "XF86AudioRaiseVolume" "al/sound-set-current-scontrol 3%+")
  144. (al/define-key *top-map* "XF86AudioLowerVolume" "al/sound-set-current-scontrol 3%-")
  145. (al/define-key *top-map* "C-XF86AudioRaiseVolume" "al/sound-set-current-scontrol 1%+")
  146. (al/define-key *top-map* "C-XF86AudioLowerVolume" "al/sound-set-current-scontrol 1%-")
  147. (al/define-key *top-map* "M-XF86AudioRaiseVolume" "al/sound-set-current-scontrol 10%+")
  148. (al/define-key *top-map* "M-XF86AudioLowerVolume" "al/sound-set-current-scontrol 10%-")
  149. (al/define-key *top-map* "C-M-XF86AudioRaiseVolume" "al/sound-set-current-scontrol 60%")
  150. (al/define-key *top-map* "C-M-XF86AudioLowerVolume" "al/sound-set-current-scontrol 20%")
  151. ;;; Controlling EMMS
  152. (al/define-key *top-map* "C-XF86AudioPlay" "al/emms-eval (emms-play-file \"~/docs/audio/grass.wav\")")
  153. (al/define-key *top-map* "XF86AudioPlay" "al/emms-eval (emms-pause)")
  154. (al/define-key *top-map* "XF86AudioStop" "al/emms-eval (emms-pause)")
  155. (al/define-key *top-map* "H-XF86AudioStop" "al/emms-eval (emms-stop)")
  156. (al/define-key *top-map* "s-XF86AudioStop" "al/emms-eval (emms-stop)")
  157. (al/define-key *top-map* "H-XF86AudioPrev" "al/emms-eval (emms-previous)")
  158. (al/define-key *top-map* "s-XF86AudioPrev" "al/emms-eval (emms-previous)")
  159. (al/define-key *top-map* "H-XF86AudioNext" "al/emms-eval (emms-next)")
  160. (al/define-key *top-map* "s-XF86AudioNext" "al/emms-eval (emms-next)")
  161. (al/define-key *top-map* "H-XF86AudioPlay" "al/emms-eval (al/emms-first)")
  162. (al/define-key *top-map* "s-XF86AudioPlay" "al/emms-eval (al/emms-first)")
  163. (al/define-key *top-map* "XF86AudioPrev" "al/emms-eval (al/emms-seek-backward 10)")
  164. (al/define-key *top-map* "XF86AudioNext" "al/emms-eval (al/emms-seek-forward 10)")
  165. (al/define-key *top-map* "C-XF86AudioPrev" "al/emms-eval (al/emms-seek-backward 3)")
  166. (al/define-key *top-map* "C-XF86AudioNext" "al/emms-eval (al/emms-seek-forward 3)")
  167. (al/define-key *top-map* "M-XF86AudioPrev" "al/emms-eval (al/emms-seek-backward 60)")
  168. (al/define-key *top-map* "M-XF86AudioNext" "al/emms-eval (al/emms-seek-forward 60)")
  169. (al/define-key *top-map* "C-M-XF86AudioPrev" "al/emms-eval (al/emms-seek-backward 180)")
  170. (al/define-key *top-map* "C-M-XF86AudioNext" "al/emms-eval (al/emms-seek-forward 180)")
  171. (al/define-key *top-map* "XF86AudioMedia" "al/emms-eval (emms-smart-browse)")
  172. (al/define-key *top-map* "XF86Music" "al/emms-eval (al/emms-notify)")
  173. ;;; Miscellaneous bindings
  174. (defvar *al/emacs-map* (make-sparse-keymap)
  175. "Keymap for finding files (and doing other things) in emacs.")
  176. (al/define-key *top-map* "s-f" '*al/emacs-map*)
  177. (al/define-key *al/emacs-map* "1" "al/frames1")
  178. (al/define-key *al/emacs-map* "b" "al/emacs-eval-show (find-file \"~/notes/bookmarks.org\")")
  179. (al/define-key *al/emacs-map* "n" "al/emacs-eval-show (org-capture 1 \"n\")")
  180. (al/define-key *al/emacs-map* "t" "al/emacs-eval-show (find-file \"~/notes/tasks.org\")")
  181. (al/define-key *al/emacs-map* "i" "al/emacs-eval-show (find-file \"~/notes/info.org\")")
  182. (al/define-key *al/emacs-map* "m" "al/emms-eval (al/emms-notify)")
  183. (al/define-key *top-map* "s-g" "abort")
  184. (al/define-key *top-map* "s-h" '*help-map*)
  185. (al/define-key *top-map* "s-u" "time")
  186. (al/define-key *top-map* "s-i" "info")
  187. (al/define-key *top-map* "s-l" "lastmsg")
  188. (al/define-key *top-map* "s-d" "al/send-key-to-emacs XF86Spell")
  189. (al/define-key *top-map* "XF86Documents" "al/emacs-eval-show (find-file \"~/notes/bookmarks.org\")")
  190. (al/define-key *top-map* "C-XF86Documents" "al/emacs-eval-show (org-capture 1 \"n\")")
  191. (al/define-key *top-map* "M-XF86Documents" "al/emacs-eval-show (find-file \"~/notes/tasks.org\")")
  192. (al/define-key *top-map* "S-XF86Documents" "al/emacs-eval-show (find-file \"~/notes/info.org\")")
  193. (al/define-key *top-map* "XF86Calculator" "al/emacs-eval-show (calc)")
  194. (al/define-key *top-map* "C-XF86Calculator" "al/emacs-eval-show (calendar)")
  195. (al/define-key *top-map* "H-ESC" "exec hide-osds")
  196. (al/define-key *top-map* "s-7" "al/set-layout 0 s-7")
  197. (al/define-key *top-map* "s-8" "al/set-layout 1 s-8")
  198. (al/define-key *top-map* "s-9" "al/set-layout 2 s-9")
  199. (al/define-key *top-map* "s-Kanji" "al/toggle-caps-lock")
  200. (al/define-key *top-map* "H-y" "al/yank-primary")
  201. (al/define-key *top-map* "F12" "exec capture desktop")
  202. (al/define-key *top-map* "M-F12" "exec capture image")
  203. (al/define-key *top-map* "M-SunPrint_Screen" "exec capture image")
  204. (al/define-key *top-map* "C-S-F12" "exec capture video")
  205. (al/define-key *top-map* "C-S-SunPrint_Screen" "exec capture video")
  206. (al/define-key *top-map* "s-F12" "exec toggle-osd-clock")
  207. (al/define-key *top-map* "s-SunPrint_Screen" "exec toggle-osd-clock")
  208. (al/define-key *top-map* "XF86TouchpadToggle" "exec toggle-touchpad")
  209. (al/define-key *top-map* "XF86Sleep" "exec monitor blank")
  210. (al/define-key *top-map* "C-XF86Sleep" "exec monitor suspend")
  211. (al/define-key *top-map* "M-XF86Sleep" "exec monitor off")
  212. (al/define-key *top-map* "C-M-H-XF86Sleep" "exec shutdown now")
  213. ;; Using "exec suspend" is not possible, because "suspend" is a shell
  214. ;; builtin command, and "sh -c" (which is called by "exec") does not
  215. ;; load my "~/.bashrc" where it is disabled.
  216. (al/define-key *top-map* "S-s-XF86Sleep" "exec `which suspend`")
  217. ;; root map
  218. (al/define-key *root-map* "V" "version")
  219. (al/define-key *root-map* "c" "colon")
  220. (al/define-key *root-map* "v" "eval")
  221. (al/define-key *root-map* "i" "list-window-properties")
  222. (al/define-key *root-map* "s-b" "al/banish-pointer")
  223. (al/define-key *root-map* "s-u" "al/toggle-unclutter")
  224. ;; menu map
  225. (al/define-key *menu-map* "s-c" 'menu-up)
  226. (al/define-key *menu-map* "s-t" 'menu-down)
  227. (al/define-key *menu-map* "C-." 'menu-up)
  228. (al/define-key *menu-map* "C-e" 'menu-down)
  229. (al/define-key *menu-map* "M-." 'menu-scroll-up)
  230. (al/define-key *menu-map* "M-e" 'menu-scroll-down)
  231. (al/define-key *menu-map* "s-m" 'menu-finish)
  232. (al/define-key *menu-map* "s-g" 'menu-abort)
  233. ;; input map
  234. (al/define-key *input-map* "C-p" 'input-delete-backward-char)
  235. (al/define-key *input-map* "M-p" 'input-backward-kill-word)
  236. (al/define-key *input-map* "C-," 'input-delete-forward-char)
  237. (al/define-key *input-map* "M-," 'input-forward-kill-word)
  238. (al/define-key *input-map* "C-u" 'input-forward-char)
  239. (al/define-key *input-map* "M-u" 'input-forward-word)
  240. (al/define-key *input-map* "C-o" 'input-backward-char)
  241. (al/define-key *input-map* "M-o" 'input-backward-word)
  242. (al/define-key *input-map* "C-a" 'input-move-beginning-of-line)
  243. (al/define-key *input-map* "C-i" 'input-move-end-of-line)
  244. (al/define-key *input-map* "M-<" 'input-kill-line)
  245. (al/define-key *input-map* "M-P" 'input-kill-to-beginning)
  246. (al/define-key *input-map* "M-." 'input-history-back)
  247. (al/define-key *input-map* "M-e" 'input-history-forward)
  248. (al/define-key *input-map* "C-m" 'input-submit)
  249. ;;; Web jumps
  250. (defvar *al/web-map* (make-sparse-keymap)
  251. "Keymap for quick browsing.")
  252. (defvar *al/web-wiki-map* (make-sparse-keymap)
  253. "Keymap for quick browsing wikipedia.")
  254. (al/define-key *top-map* "F5" '*al/web-map*)
  255. (al/define-key *al/web-map* "F5" "al/browser --new-tab about:blank")
  256. (al/define-key *al/web-map* "g" "al/browse-show https://github.com/notifications")
  257. (al/define-key *al/web-map* "y" "al/browse-show https://www.youtube.com/feed/subscriptions")
  258. (al/define-key *al/web-map* "z" "al/browse-show zeus")
  259. (al/define-key *al/web-map* "t" "al/browse-show http://tv.yandex.ru/4/?period=all-day")
  260. (al/define-key *al/web-map* "M" "al/browse-show https://maps.google.com/maps?hl=ru")
  261. (al/define-key *al/web-map* "W" "al/browse-show http://www.gismeteo.ru/city/hourly/5039/")
  262. (al/define-key *al/web-map* "w" '*al/web-wiki-map*)
  263. ;; tv and radio jumps
  264. (defvar *al/tv-radio-map* (make-sparse-keymap)
  265. "Keymap for quick access to tv and radio resources.")
  266. (al/define-key *top-map* "F6" '*al/tv-radio-map*)
  267. (al/define-key *al/tv-radio-map* "F6" "exec toggle-tvtime")
  268. (al/define-key *al/tv-radio-map* "v" "al/emms-eval (emms-play-url \"mms://live.rfn.ru/vesti_fm\")")
  269. (al/define-key *al/tv-radio-map* "o" "al/browse-show http://www.onlinetv.ru/")
  270. (al/define-key *al/tv-radio-map* "e" "al/send-key-to-emacs C-M-s-e")
  271. ;;; Executing progs
  272. (defvar *al/exec-map* (make-sparse-keymap)
  273. "Keymap for executing shell commands or switching to running applications.")
  274. (al/define-key *top-map* "s-m" '*al/exec-map*)
  275. (al/define-key *al/exec-map* "s-m" "exec")
  276. (al/define-key *al/exec-map* "e" "al/emacs")
  277. (al/define-key *al/exec-map* "E" "exec emacs --no-site-file --debug-init")
  278. (al/define-key *al/exec-map* "t" "al/xterm")
  279. (al/define-key *al/exec-map* "T" "exec xterm")
  280. (al/define-key *al/exec-map* "b" "al/browser")
  281. (al/define-key *al/exec-map* "M" "al/emacs-eval (mana-start)")
  282. ;;; Mode line
  283. (defvar *al/mode-line-map* (make-sparse-keymap)
  284. "Keymap for controlling the mode line.")
  285. (al/define-key *top-map* "M-s-m" '*al/mode-line-map*)
  286. (al/define-key *al/mode-line-map* "M-s-m" "mode-line")
  287. (al/define-key *al/mode-line-map* "t" "mode-line")
  288. (al/define-key *al/mode-line-map* "." "al/mode-line-top")
  289. (al/define-key *al/mode-line-map* "e" "al/mode-line-bottom")
  290. ;;; Mana
  291. (defvar *al/mana-map* (make-sparse-keymap)
  292. "Keymap for sending keys to Mana.")
  293. (al/define-key *top-map* "s-j" '*al/mana-map*)
  294. (al/define-key *al/mana-map* "s-j" "mana-state")
  295. (al/define-key *al/mana-map* "a" "mana-attack")
  296. (al/define-key *al/mana-map* "A" "mana-quick-attack")
  297. (al/define-key *al/mana-map* "H" "mana-bat-quest-full")
  298. (al/define-key *al/mana-map* "h" "mana-bat-quest-cont")
  299. (al/define-key *al/mana-map* "l" "al/emacs-eval-show (find-file \"~/.local/share/mana/logs/server.themanaworld.org/\")")
  300. (al/define-key *al/mana-map* "m" "al/emacs-eval-show (find-file \"~/notes/tmw/monsters.org\")")
  301. (al/define-key *al/mana-map* "q" "al/emacs-eval-show (find-file \"~/notes/tmw/quests.org\")")
  302. (al/define-key *al/mana-map* "s" "al/emacs-eval-show (find-file \"~/notes/tmw/spells.org\")")
  303. (al/define-key *al/mana-map* "S" "al/emacs-eval-show (find-file \"~/src/tmw/tmwa-server-data/world/map/npc\")")
  304. (al/define-key *al/mana-map* "b" "mana-break")
  305. (al/define-key *al/mana-map* "k" "mana-kill")
  306. ;;; keys.lisp ends here