summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-09-05 15:50:56 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-09-05 16:01:21 -0700
commita8def92abbdff8f569f3b7b0bc06c36b06938ff9 (patch)
tree5368744f49ec165a9074dfdd4b590fb94b421f9e
parentf02238f53c8e7a879e48c244ed4552c18002bc5b (diff)
downloaddotfiles-a8def92abbdff8f569f3b7b0bc06c36b06938ff9.tar.gz
try to detect i3 more cleanly
-rw-r--r--.emacs.d/init-spw.el46
1 files changed, 31 insertions, 15 deletions
diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el
index 8b9b44d0..bee751dd 100644
--- a/.emacs.d/init-spw.el
+++ b/.emacs.d/init-spw.el
@@ -124,6 +124,18 @@ add places the library might be available to `load-path'."
(substring string (length prefix))
string))
+(defun spw/get-wm ()
+ (when (executable-find "wmctrl")
+ (let (wm
+ (display-env (getenv "DISPLAY")))
+ (unwind-protect
+ (progn
+ (setenv "DISPLAY" (frame-parameter (selected-frame) 'display))
+ (setq wm (nth 1
+ (split-string (car (process-lines "wmctrl" "-m"))))))
+ (setenv "DISPLAY" display-env))
+ wm)))
+
;;;; Startup & basic preferences
@@ -162,21 +174,26 @@ add places the library might be available to `load-path'."
backup-by-copying-when-mismatch t
tramp-backup-directory-alist backup-directory-alist)
-(when (or (getenv "I3SOCK")
- (member (getenv "DESKTOP_SESSION") '("i3")))
- (setq mouse-autoselect-window t
- focus-follows-mouse t
- desktop-restore-forces-onscreen nil)
-
- ;; disable `mouse-autoselect-window' during `display-buffer', to avoid
- ;; surprise focus changes -- some code that calls `display-buffer'
- ;; does not expect `mouse-autoselect-window' to be on. E.g.
- ;; `magit-status' can leave focus in the wrong window without this
- (defun spw/disable-mouse-autoselect-window (orig-fun &rest args)
+(defun spw/disable-mouse-autoselect-window (orig-fun &rest args)
(let ((mouse-autoselect-window nil))
(apply orig-fun args)))
- (advice-add 'display-buffer
- :around #'spw/disable-mouse-autoselect-window))
+
+(defun spw/do-mouse-setup ()
+ (when (string= "i3" (spw/get-wm))
+ ;; only do this once, as if open any text terminal frames, don't want
+ ;; focus follow mouse to be turned off in graphical frames
+ (remove-function after-focus-change-function #'spw/do-mouse-setup)
+ (setq mouse-autoselect-window t
+ focus-follows-mouse t
+ desktop-restore-forces-onscreen nil)
+
+ ;; disable `mouse-autoselect-window' during `display-buffer', to avoid
+ ;; surprise focus changes -- some code that calls `display-buffer'
+ ;; does not expect `mouse-autoselect-window' to be on. E.g.
+ ;; `magit-status' can leave focus in the wrong window without this
+ (advice-add 'display-buffer
+ :around #'spw/disable-mouse-autoselect-window)))
+(add-function :after after-focus-change-function #'spw/do-mouse-setup)
;; this works only for self-insert chars and gets undone by changes in
;; window manager focus, but it's something (and
@@ -1470,8 +1487,7 @@ Should be t when do not have a good way to handle having lots of
open frames, as I do have under i3 with its tabbed layout (which
I use by default)."
(or (not (memq (framep (selected-frame)) '(x)))
- (not (or (getenv "I3SOCK")
- (member (getenv "DESKTOP_SESSION") '("i3"))))))
+ (not (string= "i3" (spw/get-wm)))))
;; if we're going to be using multiple frames, make `frame-title-format' not
;; depend on whether there are multiple frames right now