.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 (5816B)


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