-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm.el
156 lines (134 loc) · 4.81 KB
/
wm.el
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
(require 'exwm)
(require 'exwm-config)
(require 'exwm-randr)
(require 'exwm-systemtray)
;; Define number of workspaces.
(setq exwm-workspace-number 10)
;; "C-c o" is for switching workspaces.
(exwm-input-set-key
(kbd "C-c o") #'exwm-workspace-switch)
;; "C-c m" is for moving the workspace number.
(exwm-input-set-key
(kbd "C-c m") #'exwm-workspace-move)
;; Make class name the buffer name
(add-hook 'exwm-update-class-hook
(lambda ()
(exwm-workspace-rename-buffer exwm-class-name)))
;; Enable emacs keybindings in selected apps based on their window class name.
(setq my-simulation-key-window-classes '("Google-chrome" "Firefox"))
(add-hook 'exwm-manage-finish-hook
(lambda ()
(when (and exwm-class-name (member exwm-class-name my-simulation-key-window-classes))
(exwm-input-set-local-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))))))
;; Enable two xrandr outputs one named 'default' and another named 'other'.
(defun my-exwm-xrandr-two-outputs (default other)
(shell-command
(concat "xrandr --output " other " --right-of " default " --auto")))
;; Enable only one xrandr output named 'default'.
(defun my-exwm-xrandr-one-output (default)
(shell-command (concat "xrandr --output " default " --auto")))
;; Disable xrandr output named 'output'.
(defun my-exwm-xrandr-off (output)
(if output (shell-command (concat "xrandr --output " output " --off"))))
;; Update exwm-randr-workspace-output-plist with two outputs named
;; 'default' and 'other'. If the 'other' output is same as 'default'
;; then all workspaces will be redirected to the 'default' output.
(defun my-exwm-xrandr-config (default other)
(setq exwm-randr-workspace-output-plist
(progn
(setq result (list 0 default))
(setq index 1)
(while (< index exwm-workspace-number)
(setq result (append result (list index other)))
(setq index (1+ index)))
result)))
;; Dynamically find the active xrandr outputs and update exwm
;; workspace configuration and enable xrandr outputs appropriately.
(defun my-exwm-xrandr-hook (default)
(let* ((connected-cmd "xrandr -q|awk '/ connected/ {print $1}'")
(connected (process-lines "bash" "-lc" connected-cmd))
(previous (delete-dups (seq-remove
'integerp
exwm-randr-workspace-output-plist))))
(cond ((member "DP-1" connected)
(progn (my-exwm-xrandr-config default "DP-1")
(my-exwm-xrandr-two-outputs default "DP-1")))
((member "DP-2" connected)
(progn (my-exwm-xrandr-config default "DP-2")
(my-exwm-xrandr-two-outputs default "DP-2")))
((member "HDMI-1" connected)
(progn (my-exwm-xrandr-config default "HDMI-1")
(my-exwm-xrandr-two-outputs default "HDMI-1")))
((member "HDMI-2" connected)
(progn (my-exwm-xrandr-config default "HDMI-2")
(my-exwm-xrandr-two-outputs default "HDMI-2")))
(t (progn (my-exwm-xrandr-config default default)
(mapcar 'my-exwm-xrandr-off
(delete default previous)))))))
(setq exwm-randr-screen-change-hook
(lambda () (my-exwm-xrandr-hook "eDP-1")))
;; Pick some height for the system tray. Some applet icons don't appear
;; otherwise.
(setq exwm-systemtray-height 24)
;; Disable floating windows completely.
;(setq exwm-manage-force-tiling t)
;; show mode-line on floating windows.
(add-hook 'exwm-floating-setup-hook #'exwm-layout-show-mode-line)
;; Enable exwm.
(exwm-enable)
(exwm-systemtray-enable)
(exwm-randr-enable)
;; "C-c t" is for terminal.
(exwm-input-set-key
(kbd "C-c t")
(lambda () (interactive)
(if (get-buffer "XTerm")
(switch-to-buffer "XTerm")
(start-process "xterm" "*Messages*"
"xterm"
"-fa" "xft:Ubuntu Mono-10:hintstyle=hintslight"
"-e" "bash"))))
;; "C-c T" is for terminal.
(exwm-input-set-key
(kbd "C-c T")
(lambda () (interactive)
(start-process "xterm" "*Messages*"
"xterm"
"-fa" "xft:Ubuntu Mono-16:hintstyle=hintslight"
"-e" "bash")))
;; "C-c i" is for internet browser.
(exwm-input-set-key
(kbd "C-c i")
(lambda () (interactive)
(start-process "browser" "*Messages*" "google-chrome")))
;; "C-c l" is for lock.
(exwm-input-set-key
(kbd "C-c l")
(lambda () (interactive)
(start-process "slock" "*Messages*" "slock")))
;; "C-c r" is for xrandr setup.
(exwm-input-set-key
(kbd "C-c r")
(lambda () (interactive)
(start-process "xrandr" "*Messages*" "xrandr" "-q")))
;; "C-c k" is to adjust keyboard repeat rate.
(exwm-input-set-key
(kbd "C-c k")
(lambda () (interactive)
(start-process "xset" "*Messages*" "xset" "r" "rate" "200" "60")))
;; restart network manager.
(defun my-restart-network-manager ()
"Restart network-manager service."
(interactive)
(start-process "nm" "*Messages*"
"sudo"
"service" "network-manager" "restart"))