(define-module (oni home config common)
  #:use-module (gnu home services)
  #:use-module (gnu home services desktop)
  #:use-module (gnu home services shells)
  #:use-module (gnu home services ssh)
  #:use-module (guix gexp)
  #:use-module (oni home services xbindkeys)
  #:use-module (oni home services guile)
  #:use-module (oni home services xmodmap)
  #:use-module (oni home services kitty)
  #:use-module ((gnu services)
                #:select (simple-service))
  #:use-module ((gnu home services guix)
                #:select (home-channels-service-type))
  #:use-module ((guix channels)
                #:select (channel
                          make-channel-introduction
                          openpgp-fingerprint))

  #:export (home-redshift-service
	        home-xbindkeys-service
	        home-zsh-service
	        home-guile-service
	        home-xmodmap-service
	        home-openssh-service
	        home-kitty-service
            home-channels-service))

(define home-redshift-service
  (service home-redshift-service-type
           (home-redshift-configuration
            (location-provider 'manual)
            (latitude 49.2127205)
            (longitude -122.9267927))))

(define home-xbindkeys-service 
  (service home-xbindkeys-service-type
           (home-xbindkeys-configuration
            (keybindings
             '(((mod4 q) . "shutdown-rofi")
               ((mod4 k) . "hersbtclient close")
               ((mod4 mod1 k) . "herbstclient remove")
               ((mod4 Return) . "herbstclient spawn kitty")
               ((mod4 t) . "herbstclient spawn hlwm-run-or-raise \"\\(URxct\\|Hyper\\|kitty\\)\" kitty")
               ((mod4 b) . "herbstclient spawn hlwm-run-or-raise \"\\(Conkeror\\|[Ff]irefox\\|Chromium\\|Next\\|qutebrowser\\)\" firefox")
               ((mod4 e) . "herbstclient spawn hlwm-run-or-raise Emacs emacsclient --create-frame")
               ((control mod1 l) . "herbstclient spawn i3lock --color=000000")
               ((mod4 x) . "herbstclient spawn hlwm-switch-tags")
               ((mod4 shift b) . "herbstclient shift left")
               ((mod4 shift n) . "herbstclient shift down")
               ((mod4 shift p) . "herbstclient shift up")
               ((mod4 shift f) . "herbstclient shift right")
               ((mod4 control b) . "herbstclient resize left +0.05")
               ((mod4 control n) . "herbstclient resize down +0.05")
               ((mod4 control p) . "herbstclient resize up +0.05")
               ((mod4 control f) . "herbstclient resize right +0.05")
               ((mod4 shift underscore) . "herbstclient split bottom 0.5")
               ((mod4 shift bar) . "herbstclient split right 0.5")
               ((mod4 period) . "herbstclient use_index +1 --skip-visible")
               ((mod4 comma) . "herbstclient use_index -1 --skip-visible")
               ((mod4 shift control f) . "herbstclient floating toggle")
               ((mod4 f) . "herbstclient cycle_layout 1 vertical max")
               ((mod4 m) . "herbstclient fullscreen toggle")
               ((mod4 p) . "herbstclient pseudotile toggle")
               ((mod4 space) . "herbstclient or , and . compare tags.focus.curframe_wcount = 2 . cycle_layout +1 vertical horizontal max vertical grid , cycle_layout +1")
               ((mod4 BackSpace) . "herbstclient cycle_monitor")
               ((mod4 u) . "herbstclient jumpto urgent")
               ((XF86AudioPlay) . "herbstclient spawn mpc toggle")
               ((XF86AudioNext) . "herbstclient spawn mpc next")
               ((XF86AudioPrev) . "herbstclient spawn mpc prev")
               ((mod4 c)
                ("1" . "herbstclient move_index 0")
                ("2" . "herbstclient move_index 1")
                ("3" . "herbstclient move_index 2")
                ("4" . "herbstclient move_index 3")
                ("5" . "herbstclient move_index 4")
                ("6" . "herbstclient move_index 5")
                ("7" . "herbstclient move_index 6")
                ("8" . "herbstclient move_index 7")
                ("9" . "herbstclient move_index 8")
                ("0" . "herbstclient move_index 9"))
               ((mod4 s)
                ("f" . "flameshot full ~/pictures/screenshots/")
                ("c" . "flameshot gui")))))))

(define home-zsh-service
  (service home-zsh-service-type
           (home-zsh-configuration
            (environment-variables
             '(("HISTFILE" . "$HOME/.zsh/histfile")
               ("HISTSIZE" . "1000")
               ("SAVEHIST" . "1000")
               ("WORDCHARS" . "")))
            (zshrc
             (list
              (mixed-text-file
               "zshrc"
               "fpath=($HOME/.zsh/functions $fpath)\n"
               "autoload -U $HOME/.zsh/functions/*(:t)\n"
               "alias csi=\"rlwrap csi\"\n"
               "alias scsh=\"rlwrap scsh\"\n"
               "alias sbcl=\"rlwrap sbcl\"\n"
               "alias hc=herbstclient\n"
               "alias reco=\"pushd ~/projects/new-dotfiles/ && guix home reconfigure config.scm; popd\"\n"
               "alias abcde=\"guix shell abcde -- abcde\"\n"
               "setopt SHARE_HISTORY\n"
               "setopt HIST_IGNORE_ALL_DUPS\n"
               "setopt HIST_IGNORE_SPACE\n"
               "setopt PROMPT_SUBST\n"
               "zle -N x-copy-region-as-kill\n"
               "zle -N x-kill-region\n"
               "zle -N x-yank\n"
               "bindkey -e '^[w' x-copy-region-as-kill\n"
               "bindkey -e '^W' x-kill-region\n"
               "bindkey -e '^Y' x-yank\n"
               "bindkey -e '^[f' emacs-forward-word\n"
               "bindkey -e '^[F' emacs-forward-word\n"
               "bindkey -e '^[b' emacs-backward-word\n"
               "bindkey -e '^[B' emacs-backward-word\n"
               "autoload -Uz compinit\n"
               "compinit\n"
               "function horizontal-rule() {\n"
               "  local width=$(tput cols)\n"
               "  echo -e \"\\033[0;32m${(pl:$width::━:)}\\033[0m\"\n"
               "}\n"
               "preexec_functions+=(horizontal-rule)\n"
               "precmd_functions+=(horizontal-rule)\n"
               "PROMPT=\"%T \\$(spwd) %B%(?.%F{2}.%F{1}[%?])>%b%f \"")
              (local-file "zsh/spwd.zsh")
              (local-file "zsh/guix-environment.zsh"))))))

(define home-guile-service
  (service home-guile-service-type
           (home-guile-configuration
            (use-readline #t)
            (use-colorized #t))))

(define home-xmodmap-service
  (service home-xmodmap-service-type
           (home-xmodmap-configuration
            (pointer '(3 2 1))
            (extra '("remove Mod5 = ISO_Level3_Shift"
                     "keycode 108 = Alt_L"
                     "add Mod1 = Alt_L"
		     "remove mod4 = Super_R"
		     "keycode 134 = Hyper_R"
		     "add mod3 = Hyper_R")))))

(define home-openssh-service
  (service home-openssh-service-type
           (home-openssh-configuration
            (add-keys-to-agent "yes")
            (hosts (list (openssh-host
                          (name "ryuslash.org")
                          (host-name "ryuslash.org")
                          (user "slash")
                          (port 4511)
                          (extra-content "LocalForward 8090 localhost:8090
LocalForward 2812 localhost:2812
LocalForward 19999 localhost:19999"))
                         (openssh-host
                          (name "rincewind")
                          (host-name "192.168.1.135")
                          (port 4511)))))))

(define home-kitty-service
  (service home-kitty-service-type
           (home-kitty-configuration
            (configuration
             '((font-family . "Fantasque Sans Mono")
               (bold-font . "Fantasque Sans Mono Bold")
               (italic-font . "Fantasque Sans Mono Italic")
               (bold-italic-font . "Fantasque Sans Mono Bold Italic")
               (font-size . 14)
               (symbol-map . "U+f002 Font Awesome 5 Free Solid")
               (cursor-shape . beam)
               (cursor-blink-interval . 0)
               (url-style . single)
               (open-url-with . firefox)
               (copy-on-select . #f)
               (enable-audio-bell . #f)
               (visual-bell-duration . 0)
               (window-padding-width . 11.25)
               (active-tab-font-style . normal)
               (editor . emacsclient)
               (allow-remote-control . #t)
               (enabled-layouts vertical stack tall fat grid horizontal)
               (cursor . "#969696")
               (url-color . "#a88654")
               (active-border-color . "#1f2c3f")
               (inactive-border-color . "#3d3d3d")
               (bell-border-color . "#3f1a1a")
               (active-tab-foreground . "#65a854")
               (active-tab-background . "#1f2c3f")
               (inactive-tab-foreground . "#65a854")
               (inactive-tab-background . "#3d3d3d")
               (foreground . "#bfbfbf")
               (background . "#222424")
               (selection-foreground . "#222424")
               (selection-background . "#7126a3f0f01f")
               (color0 . "#222222")
               (color8 . "#3d3d3d")
               (color1 . "#ca3c828e828e")
               (color9 . "#f01f71267126")
               (color2 . "#90e4ca3c828e")
               (color10 . "#8a8bf01f7126")
               (color3 . "#bbe6ca3c828e")
               (color11 . "#d6baf01f7126")
               (color4 . "#828e9f3aca3c")
               (color12 . "#7126a3f0f01f")
               (color5 . "#bbe6828eca3c")
               (color13 . "#d6ba7126f01f")
               (color6 . "#828eca3cca3c")
               (color14 . "#7126f01ff01f")
               (color7 . "#969696")
               (color15 . "#ededed")
               ;; This doesn't appear to work.
               ; (map . "ctrl+alt+o focus_visible_window")
               (map . "alt+2 new_window")
               (map . "alt+0 close_window")
               ;; Find any "View build log messages" from guix and open the
               ;; build log in Emacs.
               (map . "ctrl+shift+g kitten hints --type=regex --regex=\\\"View build log at '([^']+)'\\.\\\" --program=\\\"emacsclient\\\""))))))

(define home-channels-service
  (simple-service 'my-channel-service
                  home-channels-service-type
                  (list
                   (channel
                    (name 'nonguix)
                    (url "https://gitlab.com/nonguix/nonguix")
                    ;; Enable signature verification:
                    (introduction
                     (make-channel-introduction
                      "897c1a470da759236cc11798f4e0a5f7d4d59fbc"
                      (openpgp-fingerprint
                       "2A39 3FFF 68F4 EF7A 3D29  12AF 6F51 20A0 22FB B2D5"))))
                   (channel
                    (name 'guix-gaming-games)
                    (url "https://gitlab.com/guix-gaming-channels/games.git")
                    (introduction
                     (make-channel-introduction
                      "c23d64f1b8cc086659f8781b27ab6c7314c5cca5"
                      (openpgp-fingerprint
                       "50F3 3E2E 5B0C 3D90 0424  ABE8 9BDC F497 A4BB CC7F"))))
                   (channel
                    (name 'rosenthal)
                    (url "https://codeberg.org/hako/rosenthal.git")
                    (branch "trunk")
                    (introduction
                     (make-channel-introduction
                      "7677db76330121a901604dfbad19077893865f35"
                      (openpgp-fingerprint
                       "13E7 6CD6 E649 C28C 3385  4DF5 5E5A A665 6149 17F7")))))))