summaryrefslogtreecommitdiff
path: root/emacs/inits/NO-00-exwm.el
blob: 647c5c17451cf233c2fbe15b8dc222465d967a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
;; Time-stamp: <2020-05-05 20:25:35 (tslil@bison)>

(defun banish-rat ()
  (interactive)
  (shell-command "xdotool mousemove 1280 800")
  (message "Rat banished."))

(use-package exwm
  :if (window-system)
  :ensure t
  :demand
  :config

  (setq exwm-workspace-number 1
        exwm-workspace-switch-create-limit 5
        exwm-workspace-show-all-buffers nil)

  (add-hook 'exwm-update-class-hook
            (lambda ()
              (exwm-workspace-rename-buffer exwm-class-name)))

  ;; -------------------------------------------------------------------
  ;; Global key binds

  (setq exwm-input-simulation-keys
        '(([?\C-b] . [left])
          ([?\C-f] . [right])
          ([?\C-p] . [up])
          ([?\C-n] . [down])
          ([?\C-a] . [home])
          ([?\C-e] . [end])
          ([?\M-v] . [prior])
          ([?\C-v] . [next])
          ([?\C-s] . [C-f])
          ;;([?\C-d] . [delete])
          ;;([?\C-k] . [S-end delete])
          ))

  ;; IME
  (defvar exwm-workman-intl t)
  (defun exwm-toggle-intl-ime ()
    (interactive)
    (let ((result (call-process-shell-command
                   (concat "setxkbmap -layout us -variant workman"
                           (if exwm-workman-intl "-intl" "")
                           " -option terminate:ctrl_alt_bksp -option ctrl:nocaps"))))
      (if (not (= 0 result))
          (message "Unable to switch keyboard layouts.")
        (message (concat (if exwm-workman-intl "INTERNATIONAL" "STANDARD") " layout selected."))
        (setq exwm-workman-intl (not exwm-workman-intl)))))

  (exwm-input-set-key (kbd "s-i") 'exwm-toggle-intl-ime)


  ;; reset
  (exwm-input-set-key (kbd "s-r") 'exwm-reset)

  ;; workspaces
  (exwm-input-set-key (kbd "s-e") 'exwm-workspace-switch)

  (dotimes (i 10)
    (exwm-input-set-key (kbd (format "s-%d" i))
                        `(lambda ()
                           (interactive)
                           (exwm-workspace-switch-create ,i))))

  ;; buffer and window management
  (exwm-input-set-key (kbd "s-SPC") 'switch-to-buffer)

  (defvar exwm-workspace-last-idx 0)
  (defvar exwm-workspace-current-idx 0)

  (defvar exwm-workspace-lighter "")

  (defun exwm-update-workspace-lighter ()
    (setq exwm-workspace-lighter (format (concat "@%d"
                                                 (when (/= exwm-workspace-current-idx exwm-workspace-last-idx)
                                                   " (*%d)"))
                                         exwm-workspace-current-idx exwm-workspace-last-idx)))

  (defun exwm-workspace-track-changes (frame-or-index &optional ignored)
    (when (/= exwm-workspace-current-index exwm-workspace-current-idx)
      (setq exwm-workspace-last-idx exwm-workspace-current-idx
            exwm-workspace-current-idx exwm-workspace-current-index)
      (exwm-update-workspace-lighter)))

  (exwm-update-workspace-lighter)

  (advice-add 'exwm-workspace-switch :after #'exwm-workspace-track-changes)
  (advice-add 'exwm-workspace-switch-create :after #'exwm-workspace-track-changes)

  (defun exwm-sanitise-workspace-last-index ()
    (when (and (< 0 (exwm-workspace--count))
               (> (1+ exwm-workspace-last-idx) (exwm-workspace--count)))
      (setq exwm-workspace-last-idx exwm-workspace-current-idx)
      (exwm-update-workspace-lighter)))

  (push #'exwm-sanitise-workspace-last-index exwm-workspace-list-change-hook)

  (defun exwm-last-workspace ()
    (interactive)
    (exwm-workspace-switch exwm-workspace-last-idx))

  (defun exwm-last-buffer ()
    (interactive)
    (switch-to-buffer (other-buffer (current-buffer) 1)))

  (exwm-input-set-key (kbd "s-o") 'exwm-last-buffer)
  (exwm-input-set-key (kbd "s-<tab>") 'exwm-last-workspace)

  (exwm-input-set-key (kbd "s-b") 'banish-rat)

  ;; run command
  (exwm-input-set-key (kbd "s-c") (lambda ()
                                    (interactive)
                                    (start-process "" nil "st")))
  (exwm-input-set-key (kbd "s-q") (lambda ()
                                    (interactive)
                                    (start-process "" nil "iceweasel")))
  (exwm-input-set-key (kbd "s-<f2>") (lambda ()
                                       (interactive)
                                       (start-process "" nil "lock")))
  (exwm-input-set-key (kbd "s-p") (lambda (command)
                                    (interactive (list (read-shell-command "$ ")))
                                    (start-process-shell-command command nil command)))

  ;; -------------------------------------------------------------------
  ;; Tray

  (require 'exwm-systemtray)
  (exwm-systemtray-enable)
  (setq exwm-systemtray-height 24)

  ;; -------------------------------------------------------------------
  ;; RandR

  (require 'exwm-randr)
  (exwm-randr-enable)

  (setq exwm-randr-workspace-monitor-plist
        '(1 "LVDS1" 0 "VGA1"))

  (exwm-enable))

;; -----------------------------------------------------------------------------
;; EXWM-edit

(use-package exwm-edit
  :ensure t
  :if (and exwm-state (window-system))
  :config
  (add-hook 'exwm-edit-compose-hook (lambda ()
                                      (text-mode))))

;; -----------------------------------------------------------------------------
;; Statusbar.el

(use-package posframe
  :defer 1 ;; HACK: why can't i just run this immediately after EXWM?
  :if (and (window-system) (fboundp 'exwm-systemtray-enable))
  :ensure t)

(use-package statusbar
  :if (and (window-system) (fboundp 'exwm-systemtray-enable))
  :after posframe
  :load-path "~/.emacs.d/scripts/statusbar.el/"
  :config
  (advice-add 'exwm-update-workspace-lighter :after #'statusbar-refresh)
  (setq statusbar-modeline-variables '(exwm-workspace-lighter display-time-string))
  (statusbar-mode +1))