Files
.emacs.d/lisp/init-exwm.el

164 lines
5.0 KiB
EmacsLisp

;;; init-exwm.el --- exwm config -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(when *is-linux*
(use-package exwm
:defer t
:config
(setq pop-up-windows nil)
(setq exwm-workspace-number 1)
(exwm-input-set-key (kbd "s-&")
(lambda (command)
(interactive (list (read-shell-command "$ ")))
(let ((display-buffer-alist
'((".*" . (display-buffer-no-window . nil)))))
(async-shell-command command))))
(defun my--exwm-switch-to-workspace (delta)
(let ((target
(mod (+ exwm-workspace-current-index delta)
(length exwm-workspace--list))))
(exwm-workspace-switch target)))
(defun my-exwm-next-workspace ()
"Switch to next exwm workspace."
(interactive)
(my--exwm-switch-to-workspace 1)
(if (= 1 (length exwm-workspace--list))
(message "No next workspace")))
(defun my-exwm-previous-workspace ()
"Switch to previous exwm workspace."
(interactive)
(my--exwm-switch-to-workspace -1)
(if (= 1 (length exwm-workspace--list))
(message "No previous workspace")))
(global-set-key (kbd "s-]") 'my-exwm-next-workspace)
(global-set-key (kbd "s-[") 'my-exwm-previous-workspace)
(add-to-list 'global-mode-string
'(:eval (propertize (format " WS:%d " exwm-workspace-current-index)
'face 'mode-line-emphasis))
t)
(setq exwm-input-prefix-keys
'(?\C-x
?\C-u
?\C-c
?\C-h
?\M-x
?\M-o
?\M-[
?\M-]
?\s-[
?\s-]
?\s-
XF86AudioLowerVolume
XF86AudioRaiseVolume
XF86AudioMute
))
(define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key)
(setq exwm-input-global-keys
`(([?\s-r] . exwm-reset)
([?\s-b] . windmove-left)
([?\s-f] . windmove-right)
([?\s-p] . windmove-up)
([?\s-n] . windmove-down)
([?\s-S] . desktop-environment-screenshot)
([?\s-s] . desktop-environment-screenshot-part)
([?\s-w] . exwm-workspace-switch)
([?\s-o] . other-window)
([?\s-m] . exwm-layout-toggle-mode-line)
([?\s-`] . (lambda () (interactive) (exwm-workspace-switch-create 0)))
,@(mapcar (lambda (i)
`(,(kbd(format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,i))))
(number-sequence 0 9))))
(setq exwm-input-simulation-keys
`((,(kbd "C-f") . [right])
(,(kbd "C-b") . [left])
(,(kbd "C-p") . [up])
(,(kbd "C-n") . [down])
(,(kbd "C-a") . [home])
(,(kbd "C-e") . [end])
(,(kbd "M-f") . [C-right])
(,(kbd "A-f") . [C-right])
(,(kbd "M-b") . [C-left])
(,(kbd "A-b") . [C-left])
(,(kbd "C-d") . [delete])
(,(kbd "C-k") . [S-end delete])
(,(kbd "M-<backspace>") . ,(kbd "C-<backspace>"))
(,(kbd "M-d") . ,(kbd "C-<delete>"))
(,(kbd "M-w") . [?\C-c])
(,(kbd "C-y") . [?\C-v])
(,(kbd "C-w") . [?\C-x])
(,(kbd "C-/") . [?\C-z])
(,(kbd "C-?") . ,(kbd "C-S-z"))))
(defun my/exwm-update-class ()
(exwm-workspace-rename-buffer exwm-class-name))
(add-hook 'exwm-update-class-hook #'my/exwm-update-class)
(require 'exwm-xim)
(exwm-xim-mode)
(exwm-wm-mode))
(use-package desktop-environment
:after exwm
:demand t
:init
(add-hook 'exwm-wm-mode-hook 'desktop-environment-mode)
:config
(advice-add 'desktop-environment-screenshot :after
(lambda (&rest _) (message "Saved fullscreen screenshot.")))
(advice-add 'desktop-environment-screenshot-part :after
(lambda (&rest _) (message "Saved partial screenshot.")))
:custom
(desktop-environment-screenshot-command
"import -window root ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png")
(desktop-environment-screenshot-partial-command
"import ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png"))
(add-hook 'exwm-init-hook
(lambda ()
(restart-fcitx5)
(my-desktop-init)))
(use-package xdg-launcher
:demand t
:after exwm
:straight
(xdg-launcher :type git
:host github
:repo "emacs-exwm/xdg-launcher")
:bind
(("s-SPC" . xdg-launcher-run-app))
:init
(with-eval-after-load 'consult
(unless (memq 'xdg-launcher-consult-source consult-buffer-sources)
(setq consult-buffer-sources
(append consult-buffer-sources '(xdg-launcher-consult-source)))))))
(when *is-mac*
;; launcher
(use-package launcher
:straight
(launcher
:type git
:host github
:repo "xiaoxinghu/launcher.el")
:bind
("s-SPC" . launcher)))
(provide 'init-exwm)
;;; init-exwm.el ends here