about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/wpcarro/emacs/.emacs.d/wpc/window-manager.el163
1 files changed, 61 insertions, 102 deletions
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/window-manager.el b/users/wpcarro/emacs/.emacs.d/wpc/window-manager.el
index f51db449bd98..6e0097926157 100644
--- a/users/wpcarro/emacs/.emacs.d/wpc/window-manager.el
+++ b/users/wpcarro/emacs/.emacs.d/wpc/window-manager.el
@@ -18,73 +18,58 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (require 'alert)
-(require 'al)
-(require 'prelude)
-(require 'string)
 (require 'cycle)
-(require 'set)
-(require 'kbd)
-(require 'ivy-helpers)
-(require 'display)
-(require 'vterm-mgt)
 (require 'dash)
+(require 'kbd)
+(require 's)
+(require 'exwm)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Library
+;; Variables
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(cl-defstruct window-manager--named-workspace label kbd display)
-(defgroup window-manager)
-
-(defconst window-manager--install-kbds? t
-  "When t, install the keybindings to switch between named-workspaces.")
-
-(defconst window-manager--named-workspaces
-  (list (make-window-manager--named-workspace
-         :label "Web Browsing"
-         :kbd "c"
-         :display display-4k-horizontal)
-        (make-window-manager--named-workspace
-         :label "Coding"
-         :kbd "d"
-         :display display-4k-horizontal)
-        (make-window-manager--named-workspace
-         :label "Vertical"
-         :kbd "h"
-         :display display-4k-vertical)
-        (make-window-manager--named-workspace
-         :label "Laptop"
-         :kbd "p"
-         :display display-laptop))
-  "List of `window-manager--named-workspace' structs.")
-
-;; Assert that no two workspaces share KBDs.
-(prelude-assert (= (list-length window-manager--named-workspaces)
-                   (->> window-manager--named-workspaces
-                        (list-map #'window-manager--named-workspace-kbd)
-                        set-from-list
-                        set-count)))
+(defgroup window-manager nil
+  "Customization options for `window-manager'.")
+
+(cl-defstruct window-manager-named-workspace
+  label kbd display)
+
+(defcustom window-manager-named-workspaces nil
+  "List of `window-manager-named-workspace' structs."
+  :group 'window-manager
+  :type (list 'window-manager-named-workspace))
+
+(defcustom window-manager-screenlocker "xsecurelock"
+  "Reference to a screen-locking executable."
+  :group 'window-manager
+  :type 'string)
+
+(defvar window-manager--workspaces nil
+  "Cycle of the my EXWM workspaces.")
+
+(defconst window-manager--modes
+  (cycle-from-list (list #'window-manager--char-mode
+                         #'window-manager--line-mode))
+  "Functions to switch exwm modes.")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Library
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun window-manager--alert (x)
   "Message X with a structured format."
-  (alert (string-concat "[exwm] " x)))
+  (alert (s-concat "[exwm] " x)))
 
-;; Use Emacs as my primary window manager.
-(use-package exwm
-  :config
+(cl-defun window-manager-init (&key init-hook)
+  "Call `exwm-enable' alongside other bootstrapping functions."
   (require 'exwm-config)
-
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-  ;; Multiple Displays
-  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   (require 'exwm-randr)
-  (exwm-randr-enable)
   (setq exwm-randr-workspace-monitor-plist
-        (->> window-manager--named-workspaces
+        (->> window-manager-named-workspaces
              (-map-indexed (lambda (i x)
-                             (list i (window-manager--named-workspace-display x))))
+                             (list i (window-manager-named-workspace-display x))))
              -flatten))
-  (setq exwm-workspace-number (list-length window-manager--named-workspaces))
+  (setq exwm-workspace-number (length window-manager-named-workspaces))
   (setq exwm-input-simulation-keys
         '(([?\C-b] . [left])
           ([?\M-b] . [C-left])
@@ -96,20 +81,18 @@
           ([?\C-e] . [end])
           ([?\C-d] . [delete])
           ([?\C-c] . [C-c])))
+  ;; Install workspace KBDs
+  (progn
+    (->> window-manager-named-workspaces
+         (list-map #'window-manager--register-kbd))
+    (window-manager--alert "Registered workspace KBDs!"))
+  ;; Ensure exwm apps open in char-mode.
+  (add-hook 'exwm-manage-finish-hook #'window-manager--char-mode)
+  (add-hook 'exwm-init-hook init-hook)
+  (setq window-manager--workspaces
+        (cycle-from-list window-manager-named-workspaces))
+  (exwm-randr-enable)
   (exwm-enable))
-(defcustom window-manager-screenlocker "xsecurelock"
-  "Reference to a screen-locking executable."
-  :group 'window-manager)
-
-;; Here is the code required to allow EXWM to cycle workspaces.
-(defconst window-manager--workspaces
-  (->> window-manager--named-workspaces
-       cycle-from-list)
-  "Cycle of the my EXWM workspaces.")
-
-(prelude-assert
- (= exwm-workspace-number
-    (list-length window-manager--named-workspaces)))
 
 (defun window-manager-next-workspace ()
   "Cycle forwards to the next workspace."
@@ -132,11 +115,6 @@
   (call-interactively #'exwm-input-release-keyboard)
   (window-manager--alert "Switched to char-mode"))
 
-(defconst window-manager--modes
-  (cycle-from-list (list #'window-manager--char-mode
-                         #'window-manager--line-mode))
-  "Functions to switch exwm modes.")
-
 (defun window-manager-toggle-mode ()
   "Switch between line- and char- mode."
   (interactive)
@@ -144,13 +122,9 @@
     (when (eq major-mode 'exwm-mode)
       (funcall (cycle-next window-manager--modes)))))
 
-;; Ensure exwm apps open in char-mode.
-(add-hook 'exwm-manage-finish-hook #'window-manager--char-mode)
-
-
 (defun window-manager--label->index (label workspaces)
   "Return the index of the workspace in WORKSPACES named LABEL."
-  (let ((index (-elem-index label (-map #'window-manager--named-workspace-label
+  (let ((index (-elem-index label (-map #'window-manager-named-workspace-label
                                         workspaces))))
     (if index index (error (format "No workspace found for label: %s" label)))))
 
@@ -160,8 +134,8 @@ Currently using super- as the prefix for switching workspaces."
   (let ((handler (lambda ()
                    (interactive)
                    (window-manager--switch
-                    (window-manager--named-workspace-label workspace))))
-        (key (window-manager--named-workspace-kbd workspace)))
+                    (window-manager-named-workspace-label workspace))))
+        (key (window-manager-named-workspace-kbd workspace)))
     (exwm-input-set-key
      (kbd-for 'workspace key)
      handler)))
@@ -170,17 +144,17 @@ Currently using super- as the prefix for switching workspaces."
   "Switch EXWM workspaces to the WORKSPACE struct."
   (exwm-workspace-switch
    (window-manager--label->index
-    (window-manager--named-workspace-label workspace)
-    window-manager--named-workspaces))
+    (window-manager-named-workspace-label workspace)
+    window-manager-named-workspaces))
   (window-manager--alert
-   (string-format "Switched to: %s"
-                  (window-manager--named-workspace-label workspace))))
+   (format "Switched to: %s"
+           (window-manager-named-workspace-label workspace))))
 
 (defun window-manager--switch (label)
   "Switch to a named workspaces using LABEL."
   (cycle-focus (lambda (x)
                  (equal label
-                        (window-manager--named-workspace-label x)))
+                        (window-manager-named-workspace-label x)))
                window-manager--workspaces)
   (window-manager--change-workspace (cycle-current window-manager--workspaces)))
 
@@ -216,23 +190,17 @@ predicate."
     (exwm-workspace-switch-to-buffer
      (al-get label buffer-alist))))
 
-(when window-manager--install-kbds?
-  (progn
-    (->> window-manager--named-workspaces
-         (list-map #'window-manager--register-kbd))
-    (window-manager--alert "Registered workspace KBDs!")))
-
 (defun window-manager-current-workspace ()
   "Output the label of the currently active workspace."
   (->> window-manager--workspaces
        cycle-current
-       window-manager--named-workspace-label))
+       window-manager-named-workspace-label))
 
 (defun window-manager-swap-workspaces ()
   "Prompt the user to switch the current workspace with another."
   (interactive)
-  (let* ((selection (->> window-manager--named-workspaces
-                         (-map #'window-manager--named-workspace-label)
+  (let* ((selection (->> window-manager-named-workspaces
+                         (-map #'window-manager-named-workspace-label)
                          (-reject
                           (lambda (x)
                             (s-equals? x (window-manager-current-workspace))))
@@ -240,18 +208,9 @@ predicate."
                           (format "Swap current workspace (i.e. \"%s\") with: "
                                   (window-manager-current-workspace)))))
          (i (-find-index (lambda (x)
-                           (s-equals? selection (window-manager--named-workspace-label x)))
-                                 window-manager--named-workspaces)))
+                           (s-equals? selection (window-manager-named-workspace-label x)))
+                                 window-manager-named-workspaces)))
     (exwm-workspace-swap exwm-workspace--current (elt exwm-workspace--list i))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Startup Applications in `window-manager--named-workspaces'
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(add-hook 'exwm-init-hook
-          (lambda ()
-            ;; (display-arrange-primary)
-            (window-manager--switch "Coding")))
-
 (provide 'window-manager)
 ;;; window-manager.el ends here