summaryrefslogtreecommitdiff
path: root/lisp/window-manager.el
diff options
context:
space:
mode:
authorJakob L. Kreuze2020-12-04 22:00:05 -0500
committerJakob L. Kreuze2020-12-04 22:02:39 -0500
commitf742b6df6d12e0f7484b248b841db18b82e46b1f (patch)
treeea2883a4509bf2d772512e62c53a4e9d2d924f22 /lisp/window-manager.el
parent6321baf35f3c106028fffeab599e508d0ab6fc6f (diff)
Fix multi-head and replace EXWM workspaces with eyebrowse.
Diffstat (limited to 'lisp/window-manager.el')
-rw-r--r--lisp/window-manager.el123
1 files changed, 104 insertions, 19 deletions
diff --git a/lisp/window-manager.el b/lisp/window-manager.el
index 1db8d46..a8931ac 100644
--- a/lisp/window-manager.el
+++ b/lisp/window-manager.el
@@ -13,8 +13,15 @@
:config
(exwm-enable)
- ;; I find that four workspaces is enough to start out with, and I like being
- ;; able to use my X windows across workspaces.
+ ;; Set the number of initial workspaces to the number of monitors attached to
+ ;; that machine.
+ (setq exwm-workspace-number
+ (choose-for-machine ("Epsilon" 2)
+ ("Upsilon" 1)
+ ("Lambda" 1)
+ (t 1)))
+
+ ;; I like being able to use my X windows across workspaces.
:init
(setq exwm-workspace-number 4
exwm-workspace-show-all-buffers t
@@ -24,25 +31,98 @@
;; that are currently in char mode. I've taken this as an opportunity to
;; incorporate windmove to my workflow, now that I have the super key at my
;; disposal.
- :init
+ :config
(require 'windmove)
;; Define some interactive functions for dealing with a multi-head setup.
(when (string= (system-name) "Epsilon")
- (defun my-windmove-right ()
- (interactive)
- (if (windmove-find-other-window 'right)
- (windmove-right)
- (if (= exwm-workspace-current-index 1)
- (exwm-workspace-switch 0)
- (exwm-workspace-switch 1))))
- (defun my-windmove-left ()
- (interactive)
- (if (windmove-find-other-window 'left)
- (windmove-left)
- (if (= exwm-workspace-current-index 1)
- (exwm-workspace-switch 0)
- (exwm-workspace-switch 1)))))
+ (cl-defmacro save-workspace-excursion (n &body body)
+ "Execute BODY in EXWM workspace N, then switch back to the
+selected workspace at the time of invocation."
+ (let ((old (gensym "old")))
+ `(let ((,old exwm-workspace-current-index))
+ (unwind-protect
+ (progn
+ (exwm-workspace-switch ,n)
+ ,@body)
+ (exwm-workspace-switch ,old)))))
+
+ (defvar exwm-randr-workspace-order '(0 1)
+ "An ordering of how the monitor associated with each
+ workspace appears on my desk, from left-to-right.")
+
+ ;; (defvar my-windmove-excursions
+ ;; (mapcar #'(lambda (workspace)
+ ;; (save-workspace-excursion workspace
+ ;; (cons workspace (selected-window))))
+ ;; exwm-randr-workspace-order)
+ ;; "State; last selected window for each monitor workspace.")
+
+ (defun my-windmove--left-workspace ()
+ "Return the workspace to the left of this one, according to
+`exwm-randr-workspace-order'."
+ (let ((index (cl-find exwm-workspace-current-index exwm-randr-workspace-order)))
+ (if (> 0 (1- index))
+ (car (last exwm-randr-workspace-order))
+ (nth (1- index) exwm-randr-workspace-order))))
+
+ (defun my-windmove--right-workspace ()
+ "Return the workspace to the right of this one, according to
+`exwm-randr-workspace-order'."
+ (let ((index (cl-find exwm-workspace-current-index exwm-randr-workspace-order)))
+ (if (= (length exwm-randr-workspace-order) (1+ index))
+ (cl-first exwm-randr-workspace-order)
+ (nth (1+ index) exwm-randr-workspace-order))))
+
+ (defun my-windmove--leftmost-window ()
+ "Return the window furthest left in the current workspace."
+ (let ((positions (mapcar #'(lambda (win)
+ (cons win (window-absolute-pixel-edges win)))
+ (window-list))))
+ (car
+ (cl-reduce #'(lambda (a b)
+ (cl-destructuring-bind
+ ((win1 x1 y1 w1 h1)
+ (win2 x2 y2 w2 h2))
+ (list a b)
+ (if (and (<= x1 x2)
+ (<= y1 y2))
+ a
+ b)))
+ positions))))
+
+ (defun my-windmove--rightmost-window ()
+ "Return the window furthest right in the current workspace."
+ (let ((positions (mapcar #'(lambda (win)
+ (cons win (window-absolute-pixel-edges win)))
+ (window-list))))
+ (car
+ (cl-reduce #'(lambda (a b)
+ (cl-destructuring-bind
+ ((win1 x1 y1 w1 h1)
+ (win2 x2 y2 w2 h2))
+ (list a b)
+ (if (and (<= x1 x2)
+ (<= y1 y2))
+ b
+ a)))
+ positions))))
+
+ (defun my-windmove-right ()
+ "`windmove-right' if the buffer to the immediate right is on
+the same frame, otherwise call out to `exwm-workspace-switch'."
+ (interactive)
+ (cond ((windmove-find-other-window 'right) (windmove-right))
+ (t (exwm-workspace-switch (my-windmove--right-workspace))
+ (select-window (my-windmove--leftmost-window)))))
+
+ (defun my-windmove-left ()
+ "`windmove-left' if the buffer to the immediate left is on
+the same frame, otherwise call out to `exwm-workspace-switch'."
+ (interactive)
+ (cond ((windmove-find-other-window 'left) (windmove-left))
+ (t (exwm-workspace-switch (my-windmove--left-workspace))
+ (select-window (my-windmove--rightmost-window))))))
;; And if we haven't defined those functions because we aren't on a multi-head
;; setup, define aliases to the underlying windmove functions.
@@ -73,8 +153,9 @@
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
- (exwm-workspace-switch-create ,(- i 1)))))
- (number-sequence 1 9))))
+ (exwm-workspace-switch
+ (elt exwm-randr-workspace-order ,(- i 1))))))
+ (number-sequence 1 exwm-workspace-number))))
;; Ah, yes. Simulation keys, the reason I decided to look at EXWM in the first
;; place.
@@ -179,3 +260,7 @@
:config
(setenv "INSIDE_EMACS" (format "%s,comint" emacs-version))
(pinentry-start))
+
+(use-package eyebrowse
+ :config
+ (eyebrowse-mode))

© 2015 - 2026 Jakob L. Kreuze