summaryrefslogtreecommitdiff
path: root/.config/emacs/modules/bd--exwm-windowing.el
blob: 1dc5056c306d65181f1be83791da56b60cd2cd5d (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
;;; -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:


;;;; utilities
;; desktop
(use-package desktop-environment
  :custom
  (desktop-environment-screenshot-directory (xdg-user-dir "PICTURES"))
  (desktop-environment-screenshot-command "flameshot full")
  (desktop-environment-screenshot-partial-command "flameshot launcher")
  (desktop-environment-volume-toggle-command "pactl set-sink-mute @DEFAULT_SINK@ toggle")
  (desktop-environment-volume-set-command "pactl set-sink-volume @DEFAULT_SINK@ %s")
  (desktop-environment-volume-get-command "pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,'")
  (desktop-environment-volume-normal-decrement "-4%")
  (desktop-environment-volume-normal-increment "+4%")
  (desktop-environment-volume-decrement-slowly "-2%")
  (desktop-environment-volume-increment-slowly "+2%")
  (desktop-environment-volume-toggle-regexp nil))


(defun bd/exwm-update-class ()
  "Changes the buffer name to reflect the class name for
that buffer."
  (exwm-workspace-rename-buffer exwm-class-name))

(defun bd/exwm-init-hook ()
  "Make workspace 1 the default startup workspace."
  (exwm-workspace-switch-create 1))


;;;; bookmarks, passwords
(defun insert-bookmark ()
  "Inserts a url or string from permanent
bookmark file. If an x window, place in kill-ring."
  ;; note xdotool had issues with repeated keys when sending to windowid
  (interactive)
  (let ((url (car (last (split-string (choose-line-from-file "~/.local/bin/bookmarks.txt"))))))
    (if (exwm--buffer->id (current-buffer))
        (kill-new url)
      (insert url))))

(defun choose-line-from-file (file)
  "Uses completion-framework to allow user to
select a line from a file."
  (let* ((choices (read-file-into-list file)))
    (completing-read "Recall: " choices)))

(defun read-file-into-list (file)
  (with-current-buffer
      (find-file-noselect file)
    (split-string
     (save-restriction
       (widen)
       (buffer-substring-no-properties
        (point-min)
        (point-max)))
     "\n" t)))

(use-package password-store
  :custom
  (password-store-time-before-clipboard-restore 20))

(use-package exwm
  :config
  (add-hook 'exwm-init-hook #'bd/exwm-init-hook)
  (add-hook 'exwm-update-class-hook #'bd/exwm-update-class)
  ;; order is important
  ;; (dolist (k '(("s-B" "icecat")))
  ;;   (let ((f (lambda () (interactive)
  ;;              (save-window-excursion
  ;;                (start-process-shell-command (cadr k) nil (cadr k))))))
  ;; (exwm-input-set-key (kbd (car k)) f)
  ;; (define-key exwm-mode-map (kbd (car k)) f)))

  (define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key)
  (exwm-enable)
  (server-start)
  :custom
  (exwm-workspace-number 2) ;; two workspaces
  (exwm-input-prefix-keys
   '(?\C-x
     ?\C-u
     ?\C-g
     ?\C-h
     ?\C-z
     ?\C-`
     ?\M-x
     ?\M-`
     ?\M-&
     ?\M-:
     ))
  (exwm-input-global-keys
   `(([?\s-n] . other-window)
     ([?\s-p] . (lambda ()
                  (interactive)
                  (other-window -1)))
     ([?\s-L] . desktop-environment-lock-screen)
     ([f2] . desktop-environment-brightness-decrement)
     ([f3] . desktop-environment-toggle-mute)
     ([f5] . desktop-environment-volume-decrement)
     ([f6] . desktop-environment-volume-increment)
     ([f8] . desktop-environment-brightness-decrement)
     ([f9] . desktop-environment-brightness-increment)
     ([f9] . emms-previous)
     ([f10] . emms-next)
     ([print] . desktop-environment-screenshot-part)
     ([S-print] . desktop-environment-screenshot)
     ([?\s-O] . insert-bookmark)
     ([?\s-P] . password-store-copy)
     ([?\s-r] . exwm-reset)
     ([?\s-d] . toggle-current-window-dedication)
     ([?\s-q] . kill-current-buffer)
     ([?\s-x] . (lambda (command)
                  (interactive (list (read-shell-command "s-x ")))
                  (start-process-shell-command command nil command)))
     ,@(mapcar (lambda (i)
                 `(,(kbd (format "s-%d" i)) .
                   (lambda ()
                     (interactive)
                     (exwm-workspace-switch-create ,i))))
               (number-sequence 0 9))))
  (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-d] . [delete])
     ([?\C-k] . [S-end delete])
     ([?\M-w] . [C-c])
     ([?\C-y] . [C-v])))

  (exwm-workspace-show-all-buffers t)
  (exwm-layout-show-all-buffers t))

(defvar new-mode-line nil)
(defun set-new-mode-line ()
  "Return the current value of my-custom-variable for the mode line."
  (setq new-mode-line
        (replace-regexp-in-string
         "%" "%%"
         (format " %s  %s  %s"
                 (shell-command-to-string "mail-string")
                 (shell-command-to-string "power-string")
                 (shell-command-to-string "t1-string")))))

(defvar-local bd/external-mode-line
    '(:eval (when new-mode-line
              new-mode-line)))

(run-with-timer t 30 #'set-new-mode-line)
(add-to-list 'global-mode-string bd/external-mode-line)

(provide 'bd--exwm-windowing)
;;; bd-exwm ends here