Skip to content

Commit

Permalink
Add keybindings to split the current frame
Browse files Browse the repository at this point in the history
+ Add a binding to open kcalc so we can better observe how the frame
  splitting behavior is working.
+ Move the keybinding definitions into their own file so they are
  easier to find.
  • Loading branch information
sdilts committed Oct 28, 2024
1 parent 682d996 commit dab291c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
15 changes: 0 additions & 15 deletions lisp/globals.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
34 changes: 34 additions & 0 deletions lisp/key-bindings.lisp
Original file line number Diff line number Diff line change
@@ -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))))
1 change: 1 addition & 0 deletions mahogany.asd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dab291c

Please sign in to comment.