;; -*- lisp -*-
;;
;; Author:  Henrik Lissner <henrik@lissner.net>
;; URL:     https://github.com/hlissner/doom-emacs
;;
;;;
(in-package :stumpwm)
;; (swank:create-server
;;  :dont-close t
;;  :port swank::default-server-port)

;;;
(defvar *config-dir* "~/.config/dotfiles/config/stumpwm")

(defcommand reload-dotfiles () ()
  (load (concat *config-dir* "/config"))
  (message "Config reloaded"))
(define-key *top-map* (kbd "s-r") "reload-dotfiles")

;; (load (concat *config-dir* "/core/core.lisp"))


(defun show-key-seq (key seq val)
  (message (print-key-seq (reverse seq))))
(add-hook *key-press-hook* 'show-key-seq)


;;; Config
(setf *mouse-focus-policy* :click)
(set-font "-CTDB-Fira Sans-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1")


;;; Keybinds
(set-prefix-key (kbd "C-z"))
(define-key *top-map* (kbd "C-RET") "exec urxvt")

(let ((map *top-map*))
  ;; (gnew "a")
  ;; (gnew "b")
  ;; (gnew "c")
  (dotimes (i 9)
    (define-key map (kbd (format nil "s-~D" i))
      (format nil "gselect ~D" i))
    (define-key map (kbd (format nil "s-S-~D" i))
      (format nil "gmove ~D" i))))

;; Window management
(define-key *top-map* (kbd "s-f") "float-this")
(define-key *top-map* (kbd "s-F") "unfloat-this")

(define-key *top-map* (kbd "s-h") "move-focus left")
(define-key *top-map* (kbd "s-j") "move-focus down")
(define-key *top-map* (kbd "s-k") "move-focus up")
(define-key *top-map* (kbd "s-l") "move-focus right")

(define-key *top-map* (kbd "s-H") "move-window left")
(define-key *top-map* (kbd "s-J") "move-window down")
(define-key *top-map* (kbd "s-K") "move-window up")
(define-key *top-map* (kbd "s-L") "move-window right")

(define-key *top-map* (kbd "s-RET") "exec xst")
(define-key *top-map* (kbd "s-SPC") "exec rofi/appmenu")

(define-key *top-map* (kbd "s-TAB")   "next-in-frame")
(define-key *top-map* (kbd "s-ISO_Left_Tab") "prev-in-frame")

(define-key *top-map* (kbd "s-`")   "exec scratch")


(defvar *window-manipulation-map* (make-sparse-keymap))

(defcommand kill-or-delete-window () ()
            (and (delete-window)
                 (remove-split)))

(define-key *top-map* (kbd "s-q") "delete-window")
(define-key *top-map* (kbd "s-Q") "kill-or-delete-window")
(define-key *top-map* (kbd "s-w") *window-manipulation-map*)
(let ((map *window-manipulation-map*))
  (define-key map (kbd "s-c") "remove-split")
  (define-key map (kbd "s-s") "hsplit")
  (define-key map (kbd "s-v") "vsplit"))


;;; Modeline
(setf *bar-med-color* "^B^3")
(setf *bar-hi-color* "^B^3")
(setf *bar-crit-color* "^B^1")

(setf *colors*
      '("#101216"  ; fg
        "#f9a03f"  ; orange
        "#8BD49C"  ; green
        "#8abeb7"  ; cyan
        "#5EC4FF"  ; blue
        "#cc6666"  ; red
        "#E27E8D"  ; magenta
        "#f0c674"  ; yellow
        ))

(update-color-map (current-screen))

(setf *group-format* " %t ")
(setf *window-format* "%m%s%20t ")
(setf *mode-line-timeout* 1)

(setf *time-modeline-string* "^B^3 %e %b %H:%M ^n")

(set-focus-color (elt *colors* 6))
(set-unfocus-color (elt *colors* 0))

(setf *screen-mode-line-format*
      (list "^B^3%g ^n^b %W ^>  "
            "  %B  %d"
            ))

(setf *mode-line-border-width* 0)
(setf *mode-line-pad-x* 0)
(setf *mode-line-pad-y* 0)
(setf *mode-line-background-color* (elt *colors* 0))
(setf *mode-line-foreground-color* (elt *colors* 1))

(unless (head-mode-line (current-head))
  (toggle-mode-line (current-screen) (current-head)))
