* .signature: Use new site address.
[~bandali/configs] / .emacs.d / lisp / bandali-exwm.el
index 4395d61..ab9d34f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; bandali-exwm.el --- bandali's EXWM configuration  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2018-2020  Amin Bandali
+;; Copyright (C) 2018-2021  Amin Bandali
 
 ;; Author: Amin Bandali <bandali@gnu.org>
 ;; Keywords: tools
@@ -27,6 +27,8 @@
 (add-to-list 'load-path (b/lisp "xelb"))
 (add-to-list 'load-path (b/lisp "exwm"))
 (require 'exwm)
+(csetq ;; exwm-replace t
+       exwm-workspace-show-all-buffers t)
 ;; make class name the buffer name, truncating beyond 60 characters
 (defun b/exwm-rename-buffer ()
   (interactive)
@@ -58,15 +60,43 @@ around if needed."
       0
     (1+ exwm-workspace-current-index)))
 
+(defun b/exwm-ws-prev ()
+  "Switch to previous EXWM workspace, wrapping around if needed."
+  (interactive)
+  (exwm-workspace-switch-create
+   (b/exwm-ws-prev-index)))
+
+(defun b/exwm-ws-next ()
+  "Switch to next EXWM workspace, wrapping around if needed."
+  (interactive)
+  (exwm-workspace-switch-create
+   (b/exwm-ws-next-index)))
+
 ;; shorten 'C-c C-q' to 'C-q'
 (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
 
-(csetq exwm-workspace-number 4
+;; scroll up/down/left/right on the echo area
+(define-key minibuffer-inactive-mode-map [mouse-4] #'b/exwm-ws-prev)
+(define-key minibuffer-inactive-mode-map [mouse-5] #'b/exwm-ws-next)
+(define-key minibuffer-inactive-mode-map [mouse-6] #'b/exwm-ws-prev)
+(define-key minibuffer-inactive-mode-map [mouse-7] #'b/exwm-ws-next)
+
+(defvar b/shifted-ws-names
+  '(0 \) 1 \! 2 \@ 3 \# 4 \$
+      5 \% 6 \^ 7 \& 8 \* 9 \()
+  "Mapping of shifted numbers on my keyboard.")
+
+(csetq exwm-workspace-number 10
        exwm-input-global-keys
        `(([?\s-R] . exwm-reset)
+         ([?\s-b] . exwm-workspace-switch-to-buffer)
          ([?\s-\\] . exwm-workspace-switch)
          ([?\s-\s] . dmenu)
-         ([?\S-\s-\s] . (lambda (command)
+         ;; ([?\s-\s] . (lambda ()
+         ;;               (interactive)
+         ;;               (start-process-shell-command
+         ;;                "rofi" nil "rofi -show run")))
+         ([?\S-\s-\s] . (lambda (command)    ; doesn't work in X windows
                           (interactive
                            (list (read-shell-command "➜ ")))
                           (start-process-shell-command
@@ -74,6 +104,10 @@ around if needed."
          ([s-return] . (lambda ()
                          (interactive)
                          (start-process "" nil "urxvt")))
+         ([S-s-return] . (lambda ()
+                           (interactive)
+                           (start-process "" nil "urxvt"
+                                          "-name" "floating")))
          ([?\C-\s-\s] . counsel-linux-app)
          ([?\M-\s-\s] . (lambda ()
                           (interactive)
@@ -87,18 +121,32 @@ around if needed."
          ([?\s-J] . windmove-swap-states-down)
          ([?\s-K] . windmove-swap-states-up)
          ([?\s-L] . windmove-swap-states-right)
+         ([?\s-N ?d] . (lambda ()
+                         (interactive)
+                         (start-process
+                          "" nil "dunstctl" "close")))
+         ([?\s-N ?D] . (lambda ()
+                         (interactive)
+                         (start-process
+                          "" nil "dunstctl" "close-all")))
+         ([?\s-N ?h] . (lambda ()
+                         (interactive)
+                         (start-process
+                          "" nil "dunstctl" "history-pop")))
+         ([?\s-N return] . (lambda ()
+                             (interactive)
+                             (start-process
+                              "" nil "dunstctl" "context")))
          ([?\M-\s-h] . shrink-window-horizontally)
          ([?\M-\s-l] . enlarge-window-horizontally)
          ([?\M-\s-k] . shrink-window)
          ([?\M-\s-j] . enlarge-window)
-         ([?\s-\[] . (lambda ()
-                       (interactive)
-                       (exwm-workspace-switch-create
-                        (b/exwm-ws-prev-index))))
-         ([?\s-\]] . (lambda ()
-                       (interactive)
-                       (exwm-workspace-switch-create
-                        (b/exwm-ws-next-index))))
+         ([?\s-\[] . b/exwm-ws-prev)
+         ([?\s-\]] . b/exwm-ws-next)
+         ([mode-line mouse-4] . b/exwm-ws-prev) ; up
+         ([mode-line mouse-5] . b/exwm-ws-next) ; down
+         ([mode-line mouse-6] . b/exwm-ws-prev) ; left
+         ([mode-line mouse-7] . b/exwm-ws-next) ; right
          ([?\s-{] . (lambda ()
                       (interactive)
                       (exwm-workspace-move-window
@@ -113,7 +161,16 @@ around if needed."
                          (interactive)
                          (exwm-workspace-switch-create ,i))))
                    (number-sequence 0 (1- exwm-workspace-number)))
-         ([?\s-t] . exwm-floating-toggle-floating)
+         ,@(mapcar
+            (lambda (i)
+              `(,(kbd (format "s-%s"
+                              (plist-get b/shifted-ws-names i)))
+                .
+                (lambda ()
+                  (interactive)
+                  (exwm-workspace-move-window ,i))))
+            (number-sequence 0 (1- exwm-workspace-number)))
+         ([?\s-F] . exwm-floating-toggle-floating)
          ([?\s-f] . exwm-layout-toggle-fullscreen)
          ([?\s-W] . (lambda ()
                       (interactive)
@@ -125,20 +182,29 @@ around if needed."
                        (interactive)
                        (start-process-shell-command
                         "rofi-light" nil "rofi-light")))
-         ([XF86AudioMute] .
+         ([XF86AudioMute] .             ; borken on my X200 :-(
+          (lambda ()
+            (interactive)
+            (start-process "" nil "pamixer" "--toggle-mute")))
+         ([XF86Launch1] .
+          (lambda ()
+            (interactive)
+            (start-process "" nil "pamixer" "--toggle-mute")))
+         ([\s-XF86Launch1] .            ; toggle mic mute
           (lambda ()
             (interactive)
-            (start-process "" nil "amixer" "set" "'Master',0" "toggle")))
+            (start-process
+             "" nil "pamixer" "--default-source" "--toggle-mute")))
          ([XF86AudioLowerVolume] .
           (lambda ()
             (interactive)
             (start-process
-             "" nil "amixer" "set" "'Master',0" "5%-")))
+             "" nil "pamixer" "--allow-boost" "--decrease" "5")))
          ([XF86AudioRaiseVolume] .
           (lambda ()
             (interactive)
             (start-process
-             "" nil "amixer" "set" "'Master',0" "5%+")))
+             "" nil "pamixer" "--allow-boost" "--increase" "5")))
          ([XF86AudioPlay] .
           (lambda ()
             (interactive)
@@ -151,6 +217,14 @@ around if needed."
           (lambda ()
             (interactive)
             (start-process "" nil "mpc" "next")))
+         ([XF86MonBrightnessDown] .
+          (lambda ()
+            (interactive)
+            (start-process "" nil "light" "-U" "5")))
+         ([XF86MonBrightnessUp] .
+          (lambda ()
+            (interactive)
+            (start-process "" nil "light" "-A" "5")))
          ([XF86ScreenSaver] .
           (lambda ()
                    (interactive)
@@ -190,15 +264,20 @@ around if needed."
          ([?\C-g] . [escape])))
 
 (require 'exwm-manage)
+(csetq
+ exwm-manage-configurations
+ '(((equal exwm-instance-name "floating")
+    floating t
+    floating-mode-line nil)))
 (add-hook 'exwm-manage-finish-hook
           (lambda ()
             (when exwm-class-name
               (cond
-               ((string= exwm-class-name "IceCat")
+               ((member exwm-class-name '("Abrowser" "IceCat" "Iceweasel"))
                 (exwm-input-set-local-simulation-keys
                  `(,@exwm-input-simulation-keys
                    ([?\C-\S-d] . [?\C-d]))))
-               ((string= exwm-class-name "URxvt")
+               ((member exwm-class-name '("URxvt" "Mate-terminal"))
                 (exwm-input-set-local-simulation-keys
                  '(([?\C-c ?\C-c] . [?\C-c])
                    ([?\C-c ?\C-u] . [?\C-u]))))
@@ -208,8 +287,19 @@ around if needed."
                    ([?\C-n] . [C-down]))))))))
 
 (require 'exwm-randr)
+(csetq
+ exwm-randr-workspace-monitor-plist
+ '(0 "eDP-1"
+     1 "eDP-1" 2 "eDP-1" 3 "eDP-1"
+     4 "eDP-1" 5 "eDP-1" 6 "eDP-1"
+     7 "HDMI-1" 8 "HDMI-1" 9 "HDMI-1"))
+;; (add-hook
+;;  'exwm-randr-screen-change-hook
+;;  (lambda ()
+;;    (start-process-shell-command
+;;     "xrandr" nil
+;;     "xrandr --output HDMI-1 --mode 1280x720 --above eDP-1 --auto")))
 (exwm-randr-enable)
-(csetq exwm-randr-workspace-monitor-plist '(1 "VGA-1"))
 
 (require 'exwm-systemtray)
 (exwm-systemtray-enable)