FollieHiyuki-dotfiles/home/.config/doom/exwm.el

384 lines
14 KiB
EmacsLisp
Raw Normal View History

2021-02-15 17:35:54 -05:00
;;; exwm.el -*- lexical-binding: t; -*-
(defun follie/run-in-background (command)
(let ((command-parts (split-string command "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
(defun follie/set-wallpaper ()
2021-03-03 02:45:15 -05:00
"Change the current wallpaper with feh"
2021-02-15 18:26:02 -05:00
(interactive)
2021-02-15 17:35:54 -05:00
(start-process-shell-command
"feh" nil "feh --no-fehbg --bg-fill --randomize ~/Pictures/Wallpapers/*"))
(defun follie/exwm-init-hook ()
;; Make workspace 1 the default at startup
;;(exwm-workspace-switch-create 1)
2021-02-28 00:38:04 -05:00
;; Start pinentry
(pinentry-start)
2021-02-15 17:35:54 -05:00
;; Additional status info on modeline
(setq display-time-day-and-date t)
(display-time-mode 1)
(if (not (equal "Battery status not available" (battery)))
(display-battery-mode 1))
;; Startup apps
(follie/run-in-background "pipewire")
(follie/run-in-background "dunst")
(follie/run-in-background "mpDris2")
(start-process-shell-command "xsetroot" nil "xsetroot -cursor_name left_ptr"))
2021-02-19 20:13:59 -05:00
(follie/run-in-background "greenclip daemon")
2021-02-15 17:35:54 -05:00
(defun follie/configure-window-by-class ()
(interactive)
(pcase exwm-class-name
("Komikku" (exwm-floating-toggle-floating)
2021-02-16 12:04:27 -05:00
(exwm-layout-hide-mode-line))))
2021-02-15 17:35:54 -05:00
(defun follie/update-displays ()
(lambda ()
2021-02-17 00:40:50 -05:00
(start-process-shell-command
"xrandr" nil "xrandr --output eDP-1 --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-1 --mode 1920x1080 --pos 1920x0 --rotate normal"))
2021-02-15 18:26:02 -05:00
(follie/set-wallpaper)
2021-02-17 00:40:50 -05:00
(message "Updated displays: %s"
(string-trim (shell-command-to-string "xrandr | grep \" connected\" | awk '{print $1}' | sed '$!N;s/\\n/ /'"))))
2021-02-15 17:35:54 -05:00
2021-02-17 17:19:52 -05:00
(defun follie/exwm-rename-buffer ()
(interactive)
(exwm-workspace-rename-buffer
(concat exwm-class-name ":"
(if (<= (length exwm-title) 30) exwm-title
(concat (substring exwm-title 0 29))))))
2021-02-15 17:35:54 -05:00
(use-package! exwm
:config
;; Number of workspaces
2021-02-16 12:04:27 -05:00
(setq exwm-workspace-number 6)
2021-02-15 17:35:54 -05:00
;; Extra stuff at startup
(add-hook 'exwm-init-hook #'follie/exwm-init-hook)
;; Update buffer name
2021-02-17 17:19:52 -05:00
(add-hook 'exwm-update-class-hook #'follie/exwm-rename-buffer)
(add-hook 'exwm-update-title-hook #'follie/exwm-rename-buffer)
2021-02-15 17:35:54 -05:00
2021-02-17 00:40:50 -05:00
;; Force tiling by default
2021-02-18 18:42:26 -05:00
;;(setq exwm-manage-force-tiling t)
2021-02-15 17:35:54 -05:00
;; Window rules
(add-hook 'exwm-manage-finish-hook #'follie/configure-window-by-class)
;; Automatically move EXWM buffer to current workspace
2021-02-17 00:40:50 -05:00
(setq exwm-layout-show-all-buffers t)
2021-02-15 17:35:54 -05:00
;; Display all buffers in every workspace buffer list
(setq exwm-workspace-show-all-buffers t)
;; Multi monitor
(require 'exwm-randr)
(setq exwm-randr-workspace-monitor-plist '(1 "HDMI-1"))
(add-hook 'exwm-randr-screen-change-hook #'follie/update-displays)
(exwm-randr-enable)
;; System tray on minibuffer
(require 'exwm-systemtray)
2021-02-16 12:04:27 -05:00
(setq exwm-systemtray-height 20)
2021-02-15 17:35:54 -05:00
(exwm-systemtray-enable)
;; Automatically send cursor to the selected display
(setq exwm-workspace-warp-cursor t)
;; Focus follows cursor
(setq mouse-autoselect-window t
focus-follows-mouse t)
;; Keys that always pass through to Emacs in line-mode
(setq exwm-input-prefix-keys
'(?\C-x
2021-02-17 00:40:50 -05:00
?\C-u
?\C-g ;; keyboard-quit
?\C-h
?\M-x
?\M-`
?\M-&
?\M-:
?\C-\M-j)) ;; Buffer list
2021-02-15 17:35:54 -05:00
;; Ctrl+q to enable next key to be sent directly
(define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key)
;; Global key bindings
(setq exwm-input-global-keys
`(
;; Reset to line-mode (C-c C-k switches to char-mode via exwm-input-release-keyboard)
([?\s-r] . exwm-reset)
;; Move between windows
2021-02-15 17:35:54 -05:00
([s-left] . windmove-left)
([s-right] . windmove-right)
([s-up] . windmove-up)
([s-down] . windmove-down)
2021-02-18 18:42:26 -05:00
([?\s-h] . windmove-left)
([?\s-l] . windmove-right)
([?\s-k] . windmove-up)
([?\s-j] . windmove-down)
2021-02-15 17:35:54 -05:00
;; Swap window position
([s-S-left] . windmove-swap-states-left)
([s-S-right] . windmove-swap-states-right)
([s-S-up] . windmove-swap-states-up)
([s-S-down] . windmove-swap-states-down)
([?\s-H] . windmove-swap-states-left)
([?\s-L] . windmove-swap-states-right)
([?\s-K] . windmove-swap-states-up)
([?\s-J] . windmove-swap-states-down)
2021-02-15 17:35:54 -05:00
;; Launch applications via shell command
([?\s-&] . (lambda (command)
(interactive (list (read-shell-command "$ ")))
(start-process-shell-command command nil command)))
;; Switch workspace
([?\s-w] . exwm-workspace-switch)
([?\s-`] . (lambda () (interactive) (exwm-workspace-switch-create 0)))
;; 's-N': Switch to certain workspace with Super (Win) plus a number key (0 - 9)
,@(mapcar (lambda (i)
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,i))))
(number-sequence 0 9))))
;; Additional bindings for convenience
(exwm-input-set-key (kbd "s-s") '+eshell/toggle)
(exwm-input-set-key (kbd "s-v") '+vterm/here)
2021-02-15 17:35:54 -05:00
(exwm-input-set-key (kbd "s-SPC") 'counsel-linux-app)
2021-02-18 18:42:26 -05:00
(exwm-input-set-key (kbd "s-t") 'exwm-floating-toggle-floating)
(exwm-input-set-key (kbd "s-f") 'exwm-layout-toggle-fullscreen)
2021-02-15 17:35:54 -05:00
;; Enable EXWM
(exwm-enable)
;; Work around ido frame
2021-02-17 00:40:50 -05:00
(require 'exwm-config)
(exwm-config-ido)
(ido-mode nil))
2021-02-18 18:42:26 -05:00
;; Edit everything in X windows with Emacs
2021-02-17 00:40:50 -05:00
(use-package! exwm-edit
:after exwm
:config
(exwm-input-set-key (kbd "s-e") #'exwm-edit--compose))
2021-02-17 12:42:02 -05:00
;; xbps but with Emacs
;;(use-package! system-packages
2021-03-03 02:45:15 -05:00
;; :after exwm
2021-02-17 12:42:02 -05:00
;; :config
;; (setq system-packages-use-sudo t))
2021-02-17 00:40:50 -05:00
2021-02-22 21:30:23 -05:00
;; Elfeed
(setq rmh-elfeed-org-files (list (expand-file-name "elfeed.org" doom-private-dir)))
;;(add-hook! 'elfeed-search-mode-hook 'elfeed-update)
2021-03-03 02:45:15 -05:00
;; playerctl status on modeline
;; (use-package! doom-modeline-now-playing
;; :after doom-modeline
;; :defer t
;; :config
;; (doom-modeline-now-playing-timer)
;; ;; Enable almost everywhere
;; (doom-modeline-def-modeline 'main
;; '(bar workspace-name window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info now-playing)
;; '(objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
;; (doom-modeline-def-modeline 'special
;; '(bar window-number modals matches buffer-info buffer-position word-count parrot selection-info now-playing)
;; '(objed-state misc-info battery irc-buffers debug minor-modes input-method indent-info buffer-encoding major-mode process))
;; (doom-modeline-def-modeline 'project
;; '(bar window-number buffer-default-directory now-playing)
;; '(misc-info battery irc mu4e gnus github debug minor-modes input-method major-mode process))
;; (doom-modeline-def-modeline 'vcs
;; '(bar window-number modals matches buffer-info buffer-position parrot selection-info now-playing)
;; '(misc-info battery irc mu4e gnus github debug minor-modes buffer-encoding major-mode process))
;; (doom-modeline-def-modeline 'info
;; '(bar window-number buffer-info info-nodes buffer-position parrot selection-info now-playing)
;; '(misc-info buffer-encoding major-mode))
;; (doom-modeline-def-modeline 'media
;; '(bar window-number buffer-size buffer-info now-playing)
;; '(misc-info media-info major-mode process vcs))
;; (doom-modeline-def-modeline 'message
;; '(bar window-number modals matches buffer-info-simple buffer-position word-count parrot selection-info now-playing)
;; '(objed-state misc-info battery debug minor-modes input-method indent-info buffer-encoding major-mode))
;; (doom-modeline-def-modeline 'pdf
;; '(bar window-number matches buffer-info pdf-pages now-playing)
;; '(misc-info major-mode process vcs))
;; (doom-modeline-def-modeline 'org-src
;; '(bar window-number modals matches buffer-info-simple buffer-position word-count parrot selection-info now-playing)
;; '(objed-state misc-info debug lsp minor-modes input-method indent-info buffer-encoding major-mode process checker))
;; (doom-modeline-def-modeline 'timemachine
;; '(bar window-number matches git-timemachine buffer-position word-count parrot selection-info now-playing)
;; '(misc-info minor-modes indent-info buffer-encoding major-mode)))
;; Mapping for built-in mpc-mode
(map! :leader :desc "music" "e" nil
2021-03-03 02:45:15 -05:00
:leader "e RET" #'mpc-play-at-point
:leader "e v" #'mpc-select-toggle
:leader "e >" #'mpc-next
:leader "e <" #'mpc-prev
:leader "e f" #'mpc-seek-current
:leader "e p" #'mpc-pause
:leader "e q" #'mpc-quit
:leader "e s" #'mpc-toggle-play
:leader "e c" #'mpc-toggle-consume
:leader "e 1" #'mpc-toggle-single
:leader "e r" #'mpc-toggle-repeat
:leader "e z" #'mpc-toggle-shuffle
:leader "e l" #'mpc-playlist)
2021-02-17 00:40:50 -05:00
;; EMMS
;; (use-package! emms
;; :after exwm
2021-03-03 02:45:15 -05:00
;; :defer t
2021-02-17 00:40:50 -05:00
;; :init
;; (setq emms-seek-seconds 10)
;; :config
;; (require 'emms-setup)
;; (emms-all)
;; (emms-default-players)
;; ;; Play music with emms directly
;; (setq emms-source-file-default-directory "~/Music/"
;; emms-info-asynchronously 1
;; emms-playlist-buffer-name "*EMMS-Music*"
;; emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find
;; emms-browser-covers 'emms-browser-cache-thumbnail-async)
;; ;; Use mpd backend
2021-02-17 00:40:50 -05:00
;; ;;(require 'emms-player-mpd)
;; ;;(setq emms-player-mpd-server-name "localhost"
;; ;; emms-player-mpd-server-port "6600"
;; ;; emms-player-mpd-music-directory "~/Music")
;; ;;(add-to-list 'emms-player-list 'emms-player-mpd)
;; (add-to-list 'emms-info-functions
;; ;;'emms-info-mpd
;; 'emms-info-exiftool)
2021-03-03 02:45:15 -05:00
;; (map! :leader "e a" #'emms-playlist-mode-go
;; :leader "e b" #'emms-browse-by-album
;; :leader "e x" #'emms-pause
;; :leader "e g" #'emms-stop
;; :leader "e j" #'emms-previous
;; :leader "e k" #'emms-next))
2021-02-17 00:40:50 -05:00
;; Truncate emms module on mode line
;;(use-package! emms-mode-line-cycle
;; :after emms
;; :config
;; (emms-playing-time 1)
;; (emms-mode-line 1)
;; (emms-mode-line-cycle 1))
2021-02-22 21:30:23 -05:00
;;(use-package! ivy-emms
;; :after emms
;; :config
;; (setq ivy-emms-default-action #'ivy-emms-play-next)
;; (setq ivy-emms-default-multi-action #'ivy-emms-play-next-multi))
;; Duck the web with ivy
(use-package! counsel-web
:after counsel
:config
(setq counsel-web-engine 'duckduckgo)
(setq counsel-web-search-action #'browse-url)
(setq counsel-web-search-alternate-action #'browse-url-firefox)
(setq counsel-web-search-dynamic-update nil)
(exwm-input-set-key (kbd "s-d") #'counsel-web-search))
2021-02-17 00:40:50 -05:00
2021-03-03 02:45:15 -05:00
;; Elpher
(defun elpher--init-hook ()
(setq visual-fill-column-center-text t)
(font-lock-mode -1)
(visual-fill-column-mode 1))
(use-package! elpher
:defer t
:config
(setq elpher-use-tls t
elpher-auto-disengage-TLS t
elpher-connection-timeout 10
elpher-gemini-max-fill-width 80
elpher-gemini-TLS-cert-checks nil)
(add-hook 'elpher-mode-hook 'elpher--init-hook))
2021-02-17 00:40:50 -05:00
;; Function keys
(use-package! desktop-environment
:after exwm
2021-02-18 18:42:26 -05:00
:diminish desktop-environment-mode
:config
;; Give me back Super+l
(progn
(setf
(alist-get (elt (kbd "s-l") 0) desktop-environment-mode-map nil t)
nil)
(desktop-environment-mode))
(exwm-input-set-key (kbd "s-x") #'desktop-environment-lock-screen)
2021-02-17 00:40:50 -05:00
:custom
;; Brightness
(desktop-environment-brightness-get-command "brightnessctl")
(desktop-environment-brightness-get-regexp "\\([0-9]+%\\)")
(desktop-environment-brightness-set-command "brightnessctl set %s")
(desktop-environment-brightness-small-increment "2%+")
(desktop-environment-brightness-small-decrement "2%-")
(desktop-environment-brightness-normal-increment "5%+")
(desktop-environment-brightness-normal-decrement "5%-")
;; Volume
(desktop-environment-volume-get-command "pulsemixer --get-volume")
(desktop-environment-volume-get-regexp "\\([0-9]+ \\)")
(desktop-environment-volume-toggle-command "pulsemixer --toggle-mute")
(desktop-environment-volume-toggle-microphone-command nil)
(desktop-environment-volume-set-command "pulsemixer --change-volume %s")
(desktop-environment-volume-small-increment "+2")
(desktop-environment-volume-small-decrement "-2")
(desktop-environment-volume-normal-increment "+5")
(desktop-environment-volume-normal-decrement "-5")
;; Screenshot
(desktop-environment-screenshot-directory "~/Screenshots")
(desktop-environment-screenshot-command "scrot -m -q 100 '%Y-%m-%d-%T_$wx$h.png'")
(desktop-environment-screenshot-partial-command
"scrot -s -f -l style=solid,width=2,color=\"red\" -q 100 '%Y-%m-%d-%T_$wx$h.png'")
;; Screenlock
(desktop-environment-screenlock-command "~/.local/bin/X11/i3lock.sh"))
2021-02-15 17:35:54 -05:00
;; Control dunst
(defun close-desktop-notifications ()
"Close all current notifications"
2021-02-15 17:35:54 -05:00
(interactive)
(start-process-shell-command "dunstctl" nil "dunstctl close-all"))
2021-02-22 21:30:23 -05:00
(defun toggle-desktop-notifications ()
"Toggle desktop notification on/off"
2021-02-15 17:35:54 -05:00
(interactive)
(start-process-shell-command "dunstctl" nil "dunstctl set-paused toggle"))
2021-02-18 18:42:26 -05:00
;; Clipboard management
(defun greenclip--select-item (str)
"Copy selected item to clipboard"
(setq str (replace-regexp-in-string "\u00a0" "\n" str))
2021-03-03 02:45:15 -05:00
;; (kill-new str) ;; Add the item to Emacs kill ring as well
(condition-case nil
(cond
((fboundp 'ns-set-pasteboard)
(ns-set-pasteboard str))
((fboundp 'gui-set-selection)
(gui-set-selection 'CLIPBOARD str))
(t
(error "No clipboard support")))
(error
(with-temp-buffer
(insert str)
(if (file-executable-p "xsel")
(call-process-region (point-min) (point-max) "xsel" nil nil nil "--clipboard" "--input")
(call-process-region (point-min) (point-max) "xclip" nil nil nil "-selection clipboard" "--input"))))))
2021-02-22 21:30:23 -05:00
(defun ivy-greenclip ()
"Select an item from X clipboard history"
2021-02-22 21:30:23 -05:00
(interactive)
(let* ((history (split-string (shell-command-to-string "greenclip print") "[\r\n]+")))
(ivy-read "Clipboard item: "
2021-02-22 21:30:23 -05:00
history
:action (lambda (str)
(greenclip--select-item str)))))
(defun greenclip-clear-history ()
2021-03-03 02:45:15 -05:00
"Clear X clipboard history"
2021-02-18 18:42:26 -05:00
(interactive)
(start-process-shell-command "greenclip" nil "pkill greenclip && greenclip clear")
(follie/run-in-background "greenclip daemon"))