.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

init-exwm.el (6341B)


      1 ;;; init-exwm.el --- exwm config -*- lexical-binding: t -*-
      2 
      3 ;;; Commentary:
      4 
      5 ;;; Code:
      6 
      7 (when *is-linux*
      8   (use-package exwm
      9     :hook
     10     (exwm-init . restart-fcitx5)
     11     (exwm-init . my-desktop-init)
     12     :config
     13     (setq pop-up-windows nil)
     14     (setq exwm-workspace-number 1)
     15     (exwm-input-set-key (kbd "s-&")
     16                         (lambda (command)
     17                           (interactive (list (read-shell-command "$ ")))
     18                           (let ((display-buffer-alist
     19                                  '((".*" . (display-buffer-no-window . nil)))))
     20                             (async-shell-command command))))
     21 
     22     (defun my--exwm-switch-to-workspace (delta)
     23       (let ((target
     24              (mod (+ exwm-workspace-current-index delta)
     25                   (length exwm-workspace--list))))
     26         (exwm-workspace-switch target)))
     27 
     28     (defun my-exwm-next-workspace ()
     29       "Switch to next exwm workspace."
     30       (interactive)
     31       (my--exwm-switch-to-workspace 1)
     32       (if  (= 1 (length exwm-workspace--list))
     33           (message "No next workspace")))
     34 
     35     (defun my-exwm-previous-workspace ()
     36       "Switch to previous exwm workspace."
     37       (interactive)
     38       (my--exwm-switch-to-workspace -1)
     39       (if  (= 1 (length exwm-workspace--list))
     40           (message "No previous workspace")))
     41 
     42     (global-set-key (kbd "s-]") #'my-exwm-next-workspace)
     43     (global-set-key (kbd "s-[") #'my-exwm-previous-workspace)
     44 
     45     (add-to-list 'global-mode-string
     46                  '(:eval (propertize (format " WS:%d " exwm-workspace-current-index)
     47                                      'face 'mode-line-emphasis))
     48                  t)
     49 
     50     (setq exwm-input-prefix-keys
     51           '(?\C-x
     52             ?\C-u
     53             ?\C-c
     54             ?\C-h
     55             ?\M-x
     56             ?\M-o
     57             ?\M-[
     58                  ?\M-]
     59             ?\s-[
     60                  ?\s-]
     61             ?\s- 
     62             XF86AudioLowerVolume
     63             XF86AudioRaiseVolume
     64             XF86AudioMute
     65             ))
     66     (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
     67 
     68     (setq exwm-input-global-keys
     69           `(([?\s-r] . exwm-reset)
     70             ([?\s-b] . windmove-left)
     71             ([?\s-f] . windmove-right)
     72             ([?\s-p] . windmove-up)
     73             ([?\s-n] . windmove-down)
     74             ([?\s-S] . desktop-environment-screenshot)
     75             ([?\s-s] . desktop-environment-screenshot-part)
     76             ([?\s-w] . exwm-workspace-switch)
     77             ([?\s-o] . other-window)
     78             ([?\s-m] . exwm-layout-toggle-mode-line)
     79             ([?\s-`] . (lambda () (interactive) (exwm-workspace-switch-create 0)))
     80             ,@(mapcar (lambda (i)
     81                         `(,(kbd(format "s-%d" i)) .
     82                           (lambda ()
     83                             (interactive)
     84                             (exwm-workspace-switch-create ,i))))
     85                       (number-sequence 0 9))))
     86 
     87     (setq exwm-input-simulation-keys
     88           `((,(kbd "C-f") . [right])
     89             (,(kbd "C-b") . [left])
     90             (,(kbd "C-p") . [up])
     91             (,(kbd "C-n") . [down])
     92             (,(kbd "C-a") . [home])
     93             (,(kbd "C-e") . [end])
     94             (,(kbd "M-f") . [C-right])
     95             (,(kbd "A-f") . [C-right])
     96             (,(kbd "M-b") . [C-left])
     97             (,(kbd "A-b") . [C-left])
     98             (,(kbd "C-d") . [delete])
     99             (,(kbd "C-k") . [S-end delete])
    100             (,(kbd "M-<backspace>") . ,(kbd "C-<backspace>"))
    101             (,(kbd "M-d")  . ,(kbd "C-<delete>"))
    102             (,(kbd "M-w") . [?\C-c])
    103             (,(kbd "C-y") . [?\C-v])
    104             (,(kbd "C-w") . [?\C-x])
    105             (,(kbd "C-/") . [?\C-z])
    106             (,(kbd "C-?") . ,(kbd "C-S-z"))))
    107 
    108     (defun my-exwm-update-class ()
    109       (exwm-workspace-rename-buffer exwm-class-name))
    110     (add-hook 'exwm-update-class-hook #'my-exwm-update-class)
    111 
    112     (require 'exwm-xim)
    113     (exwm-xim-mode)
    114     (exwm-wm-mode))
    115 
    116   (use-package desktop-environment
    117     :after exwm
    118     :demand t
    119     :init
    120     (add-hook 'exwm-wm-mode-hook #'desktop-environment-mode)
    121     :config
    122     (advice-add 'desktop-environment-screenshot :after
    123                 (lambda (&rest _) (message "Saved fullscreen screenshot.")))
    124     (advice-add 'desktop-environment-screenshot-part :after
    125                 (lambda (&rest _) (message "Saved partial screenshot.")))
    126     :custom
    127     (desktop-environment-screenshot-command
    128      "import -window root ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png")
    129     (desktop-environment-screenshot-partial-command
    130      "import ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png"))
    131 
    132   (use-package xdg-launcher
    133     :demand t
    134     :after exwm
    135     :straight
    136     (xdg-launcher :type git
    137                   :host github
    138                   :repo "emacs-exwm/xdg-launcher")
    139     :bind
    140     (("s-SPC" . xdg-launcher-run-app))
    141     :init
    142     (with-eval-after-load 'consult
    143       (unless (memq 'xdg-launcher-consult-source consult-buffer-sources)
    144         (setq consult-buffer-sources
    145               (append consult-buffer-sources '(xdg-launcher-consult-source))))))
    146 
    147   (defun reboot ()
    148     "Execute loginctl reboot command."
    149     (interactive)
    150     (eshell-command "loginctl reboot"))
    151 
    152   (defun poweroff ()
    153     "Execute loginctl poweroff command"
    154     (interactive)
    155     (eshell-command "loginctl poweroff"))
    156 
    157   (defun suspend ()
    158     "Execute loginctl suspend command"
    159     (interactive)
    160     (eshell-command "loginctl suspend"))
    161 
    162   (defun my-desktop-init ()
    163     "Launch something for linux desktop."
    164     (interactive)
    165     (unless (zerop (shell-command "pgrep -x mihomo"))
    166       (start-process-shell-command "mihomo" nil "mihomo -d ~/.config/mihomo/"))
    167     (start-process-shell-command "xrandr-refresh" nil "xrandr --output DP-4 --mode 2560x1440 --rate 165.00")
    168     (start-process-shell-command "xinput" nil "xinput set-prop 12 'libinput Accel Speed' -0.45"))
    169 
    170   (defun restart-fcitx5 ()
    171     "Kill and restart fcitx5, to fix random issues in exwm."
    172     (interactive)
    173     (if (zerop (shell-command "pgrep fcitx5"))
    174         (progn
    175           (eshell-command "pkill fcitx5")
    176           (eshell-command "fcitx5 -d"))
    177       (eshell-command "fcitx5 -d"))))
    178 
    179 (when *is-mac*
    180   ;; launcher
    181   (use-package launcher
    182     :straight
    183     (launcher
    184      :type git
    185      :host github
    186      :repo "xiaoxinghu/launcher.el")
    187     :bind
    188     ("s-SPC" . launcher)))
    189 
    190 (provide 'init-exwm)
    191 ;;; init-exwm.el ends here