nav.lisp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. (in-package :stumpwm)
  2. (require :globalwindows)
  3. (setf *new-frame-action* :empty)
  4. (setf *window-format* "%m%n%s %c %50t")
  5. (setf *maximum-completions* 25)
  6. ;;;
  7. ;;; Mouse
  8. ;;;
  9. ;; Don't set it to “sloppy”,
  10. ;; because it could switch window after switch desktop
  11. (setf *mouse-focus-policy* :click)
  12. (defcommand mouse-click () ()
  13. (setf *mouse-focus-policy* :click))
  14. (defcommand mouse-sloppy () ()
  15. (setf *mouse-focus-policy* :sloppy))
  16. (defcommand xmenu () ()
  17. (run-shell-command "xmenu.sh"))
  18. ;;;
  19. ;;; Desktop
  20. ;;;
  21. (defcommand desktop-restore (desktop rules) ((:string "Restore desktop: ")
  22. (:string "Restore rules: "))
  23. (let ((desktop (format nil "~a/.stumpwm.d/desktop/~a.lisp" (getenv "HOME") desktop))
  24. (rules (format nil "~a/.stumpwm.d/rules/~a.lisp" (getenv "HOME") rules)))
  25. (message (format nil "Restore desktop from ~s file." desktop))
  26. (message (format nil "Restore rules from ~s file." rules))
  27. (restore-from-file desktop)
  28. (clear-window-placement-rules)
  29. (restore-window-placement-rules rules)
  30. (place-existing-windows)))
  31. (defcommand dump-group-to-file (file) (:rest "Dump To File: ")
  32. "Dumps the frames of the current group of the current screen to the named file."
  33. (dump-to-file (dump-group (current-group)) file))
  34. ;;;
  35. ;;; Frames
  36. ;;;
  37. (defun grid-split-3x3 ()
  38. (flet ((split ()
  39. (progn
  40. (hsplit)
  41. (vsplit)
  42. (fnext)
  43. (fnext)
  44. (vsplit)
  45. (fnext)
  46. (fnext))))
  47. (progn
  48. (hsplit)
  49. (vsplit)
  50. (split)
  51. (split)
  52. (vsplit)
  53. (split)
  54. (split))))
  55. (defcommand scroll-other-window () ()
  56. (stumpwm:run-commands "fother" "window-send-string " "fother"))
  57. (defcommand warp-mouse-active-frame () ()
  58. "Move mouse cursor to the top right of current frame."
  59. (let* ((current-frame (tile-group-current-frame (current-group)))
  60. (pointer-x (- (+ (frame-x current-frame)
  61. (frame-width current-frame))
  62. 100))
  63. (pointer-y (+ 100 (frame-y current-frame))))
  64. (warp-pointer (current-screen) pointer-x pointer-y)))
  65. (defcommand wi-sync-all-frame-windows () ()
  66. (sync-all-frame-windows (current-group)))
  67. (defcommand other-in-frame-or-fother () ()
  68. (let* ((group (current-group))
  69. (frame (tile-group-current-frame group)))
  70. (if (> (length (frame-sort-windows group frame)) 1)
  71. (other-in-frame)
  72. (fother))))
  73. ;;;
  74. ;;; Windows
  75. ;;;
  76. (defcommand window-resize-by-half-horizontal () ()
  77. ""
  78. (resize (- (round (/ (parse-integer (format-expand *window-formatters* "%w" (current-window))) 2.0))) 0))
  79. (defcommand window-resize-by-half-vertical () ()
  80. ""
  81. (resize 0 (- (round (/ (parse-integer (format-expand *window-formatters* "%h" (current-window))) 2)))))
  82. (defun current-window-width ()
  83. (format-expand *window-formatters* "%w" (current-window)))
  84. (defun current-window-height ()
  85. (format-expand *window-formatters* "%h" (current-window)))
  86. (defcommand global-windowlist-custom () ()
  87. (let ((window (current-window)))
  88. (cond
  89. ((and window (string= (window-class window) "Emacs"))
  90. (emacsclient-eval "(helm-buffers-list)"))
  91. (t (globalwindows:global-windowlist)))))
  92. (defcommand next-in-frame-custom () ()
  93. (let ((window (current-window)))
  94. (cond
  95. ((string= (window-class window) "Emacs")
  96. (emacsclient-eval "(next-buffer)"))
  97. ((string= (window-class window) "mpv")
  98. (window-send-string ">"))
  99. ((some (lambda (str)
  100. (string= str (window-class window)))
  101. '("firefox-default" "Chromium-browser" "Xfce4-terminal"))
  102. (send-fake-key window (kbd "C-Page_Down")))
  103. ((and (string= (window-class window) "XTerm")
  104. (string= (window-name window) "tmux"))
  105. (send-fake-key window (kbd "C-b"))
  106. (send-fake-key window (kbd "n")))
  107. (t (next-in-frame)))))
  108. (defcommand prev-in-frame-custom () ()
  109. (let ((window (current-window)))
  110. (cond
  111. ((string= (window-class window) "Emacs")
  112. (emacsclient-eval "(previous-buffer)"))
  113. ((string= (window-class window) "mpv")
  114. (window-send-string "<"))
  115. ((some (lambda (str)
  116. (string= str (window-class window)))
  117. '("firefox-default" "Chromium-browser" "Xfce4-terminal"))
  118. (send-fake-key window (kbd "C-Page_Up")))
  119. ((and (string= (window-class window) "XTerm")
  120. (string= (window-name window) "tmux"))
  121. (send-fake-key window (kbd "C-b"))
  122. (send-fake-key window (kbd "p")))
  123. (t (prev-in-frame)))))
  124. (defcommand keybinding-s-k () ()
  125. (let ((window (current-window)))
  126. (cond
  127. ((uiop/utility:string-prefix-p "repl-nix" (window-title window))
  128. (kill-window window))
  129. ((string= (window-class window) "Emacs")
  130. (emacsclient-eval "(kill-buffer (window-buffer (frame-selected-window)))"))
  131. ((string= (window-class window) "firefox-default")
  132. (send-fake-key window (kbd "M-w")))
  133. ((and (string= (window-class window) "XTerm")
  134. (string= (window-name window) "tmux"))
  135. (sb-thread:make-thread
  136. (lambda ()
  137. (send-fake-key window (kbd "C-b"))
  138. (send-fake-key window (kbd "x"))
  139. (sleep 0.01)
  140. (send-fake-key window (kbd "y")))))
  141. (t (delete-window window)))))
  142. (defcommand keybinding-s-o () ()
  143. (let ((window (current-window)))
  144. (cond
  145. ((string= (window-class window) "Emacs")
  146. (send-fake-key window (kbd "M-x"))
  147. (window-send-string "ffap"))
  148. (t (emacs-anywhere)))))
  149. (defcommand keybinding-s-r () ()
  150. (let ((window (current-window)))
  151. (cond
  152. ((string= (window-class window) "Xfce4-terminal")
  153. (send-fake-key window (kbd "C-F")))
  154. ((and (string= (window-class window) "XTerm")
  155. (string= (window-name window) "tmux"))
  156. (send-fake-key window (kbd "C-b"))
  157. (send-fake-key window (kbd "[")))
  158. (t (repl-guile)))))
  159. (defcommand keybinding-s-= () ()
  160. (let ((window (current-window)))
  161. (cond
  162. ((string= (window-class window) "Emacs")
  163. (send-fake-key window (kbd "C-x"))
  164. (send-fake-key window (kbd "C-=")))
  165. ((string= (window-class window) "firefox-default")
  166. (send-fake-key window (kbd "M-=")))
  167. ((some (lambda (str)
  168. (string= str (window-class window)))
  169. '("Chromium-browser" "Xfce4-terminal"))
  170. (send-fake-key window (kbd "C-+")))
  171. ((string= (window-class window) "XTerm")
  172. (send-fake-key window (kbd "S-KP_Add")))
  173. ((string= (window-class window) "Alacritty")
  174. (send-fake-key window (kbd "C-="))))))
  175. (defcommand keybinding-s-- () ()
  176. (let ((window (current-window)))
  177. (cond
  178. ((string= (window-class window) "Emacs")
  179. (send-fake-key window (kbd "C-x"))
  180. (send-fake-key window (kbd "C--")))
  181. ((string= (window-class window) "firefox-default")
  182. (send-fake-key window (kbd "M--")))
  183. ((some (lambda (str)
  184. (string= str (window-class window)))
  185. '("Chromium-browser" "Xfce4-terminal"))
  186. (send-fake-key window (kbd "C--")))
  187. ((string= (window-class window) "XTerm")
  188. (send-fake-key window (kbd "S-KP_Subtract")))
  189. ((string= (window-class window) "Alacritty")
  190. (send-fake-key window (kbd "C--"))))))
  191. (defcommand keybinding-s-x () ()
  192. (let ((clipboard (get-x-selection)))
  193. (cond ((string-contains "AC_" clipboard)
  194. (sb-thread:make-thread
  195. (lambda ()
  196. (run-shell-command (format nil "notify-send ~s"
  197. (string-trim '(#\Newline)
  198. (run-shell-command (format nil "hms web unix ~a" clipboard)
  199. t)))))))
  200. ((= (length clipboard) 24)
  201. (mjru-mongo-development-id-object)))))
  202. ;;;
  203. ;;; Small frame
  204. ;;;
  205. (defvar *small-frame-width* 954)
  206. (defun small-framep ()
  207. (let ((group (current-group)))
  208. (if (string= (class-name (class-of group)) "FLOAT-GROUP")
  209. nil
  210. (<= (frame-width (tile-group-current-frame group)) *small-frame-width*))))
  211. (defcommand current-frame-smallp () ()
  212. (if (small-framep)
  213. (progn (message "small") 1)
  214. (progn (message "big") 0)))
  215. ;;;
  216. ;;; Clipboard
  217. ;;;
  218. (defcommand window-send-clipboard () ()
  219. (window-send-string (get-x-selection)))
  220. ;;;
  221. ;;; Help
  222. ;;;
  223. (defcommand display-0-keys () ()
  224. (term-shell-command
  225. (join (list "less"
  226. (concat (getenv "HOME") "/.local/share/chezmoi/dot_stumpwm.d/display-0.lisp")))))
  227. (defcommand delete-window! (&optional (window (current-window))) ()
  228. (delete-window window)
  229. (when (not (current-window))
  230. (run-commands "fnext")))
  231. (defcommand delete-window-or-remove-split () ()
  232. (if (current-window)
  233. (run-commands "delete-window")
  234. (run-commands "remove")))
  235. ;;;
  236. ;;; Menu
  237. ;;;
  238. (defcommand bemenu-run () ()
  239. (run-shell-command
  240. "bemenu-run --fb '#000000' --ab '#000000' --tb '#000000' --nb '#000000' --tf '#ffffff' --hf '#ffffff' --hb '#2e8b57' --border 1 --bdr '#333333' --line-height 25 --hp 10 --fn 'DejaVu Sans Mono 10' --list 20 --center --no-spacing"))