diff --git a/lisp/globals.lisp b/lisp/globals.lisp index 025ca70..fd0390b 100644 --- a/lisp/globals.lisp +++ b/lisp/globals.lisp @@ -2,18 +2,3 @@ (declaim (type mahogany-state *compositor-state*)) (defglobal *compositor-state* (make-instance 'mahogany-state)) - - -(defun handle-server-stop (sequence seat) - (declare (ignore sequence seat)) - (server-stop *compositor-state*)) - -(defun open-terminal (sequence seat) - (declare (ignore sequence seat)) - (sys:open-terminal)) - -(setf (mahogany-state-keybindings *compositor-state*) - (list (define-kmap - (kbd "C-t") (define-kmap - (kbd "q") #'handle-server-stop - (kbd "c") #'open-terminal)))) diff --git a/lisp/key-bindings.lisp b/lisp/key-bindings.lisp new file mode 100644 index 0000000..a826ce7 --- /dev/null +++ b/lisp/key-bindings.lisp @@ -0,0 +1,34 @@ +(in-package #:mahogany) + +(defun handle-server-stop (sequence seat) + (declare (ignore sequence seat)) + (server-stop *compositor-state*)) + +(defun open-terminal (sequence seat) + (declare (ignore sequence seat)) + (sys:open-terminal)) + +(defun open-kcalc (sequence seat) + (declare (ignore sequence seat)) + (uiop:launch-program (sys:find-program "kcalc"))) + +(defun split-frame-h (sequence seat) + (declare (ignore sequence seat)) + (let ((frame (mahogany-current-frame *compositor-state*))) + (when frame + (tree:split-frame-h frame :direction :left)))) + +(defun split-frame-v (sequence seat) + (declare (ignore sequence seat)) + (let ((frame (mahogany-current-frame *compositor-state*))) + (when frame + (tree:split-frame-v frame :direction :top)))) + +(setf (mahogany-state-keybindings *compositor-state*) + (list (define-kmap + (kbd "C-t") (define-kmap + (kbd "q") #'handle-server-stop + (kbd "c") #'open-terminal + (kbd "s") #'split-frame-v + (kbd "S") #'split-frame-h + (kbd "+") #'open-kcalc)))) diff --git a/mahogany.asd b/mahogany.asd index 6dc99f4..1f460f8 100644 --- a/mahogany.asd +++ b/mahogany.asd @@ -48,6 +48,7 @@ (:file "output" :depends-on ("objects" "bindings" "state")) (:file "view" :depends-on ("globals" "state" "objects" "bindings")) (:file "input" :depends-on ("state" "keyboard")) + (:file "key-bindings" :depends-on ("globals" "state" "keyboard" "tree" "input")) (:file "main" :depends-on ("bindings" "keyboard" "input" "package")))) (asdf:defsystem #:mahogany/executable