From aff8463412f03195747071c7d19e610487d5adee Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Tue, 11 Jan 2022 08:55:30 +0300 Subject: [PATCH] feat(desktop): improve window switching --- .condarc | 1 + .config/mimeapps.list | 2 ++ .emacs.d/desktop.el | 34 +++++++++++++++++++++------------- Desktop.org | 37 ++++++++++++++++++++++++------------- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/.condarc b/.condarc index 9281fa7..cdf5d2c 100644 --- a/.condarc +++ b/.condarc @@ -3,3 +3,4 @@ channels: - defaults channel_priority: strict changeps1: false +auto_activate_base: false diff --git a/.config/mimeapps.list b/.config/mimeapps.list index 9aa396e..282bb65 100644 --- a/.config/mimeapps.list +++ b/.config/mimeapps.list @@ -1,3 +1,4 @@ +# [[file:../Desktop.org::*MIME][MIME:1]] [Default Applications] text/html=firefox.desktop x-scheme-handler/http=firefox.desktop @@ -11,3 +12,4 @@ image/jpeg=feh.desktop [Added Associations] x-scheme-handler/tg=userapp-Telegram Desktop-7PVWF1.desktop; +# MIME:1 ends here diff --git a/.emacs.d/desktop.el b/.emacs.d/desktop.el index ce2fe25..b345e87 100644 --- a/.emacs.d/desktop.el +++ b/.emacs.d/desktop.el @@ -202,17 +202,18 @@ DIR is either 'left or 'right." "Switch to another monitor." (interactive) (my/exwm-last-workspaces-clear) - (exwm-workspace-switch - (cl-loop with other-monitor = (my/exwm-get-other-monitor (or dir 'right)) - for i in (append my/exwm-last-workspaces - (cl-loop for i from 0 - for _ in exwm-workspace--list - collect i)) - if (if other-monitor - (string-equal (plist-get exwm-randr-workspace-output-plist i) - other-monitor) - (not (plist-get exwm-randr-workspace-output-plist i))) - return i))) + (let ((mouse-autoselect-window nil)) + (exwm-workspace-switch + (cl-loop with other-monitor = (my/exwm-get-other-monitor (or dir 'right)) + for i in (append my/exwm-last-workspaces + (cl-loop for i from 0 + for _ in exwm-workspace--list + collect i)) + if (if other-monitor + (string-equal (plist-get exwm-randr-workspace-output-plist i) + other-monitor) + (not (plist-get exwm-randr-workspace-output-plist i))) + return i)))) (defun my/exwm-workspace-switch-monitor () "Move the current workspace to another monitor." @@ -245,10 +246,17 @@ DIR is either 'left or 'right." ('right 'left)))) (if other-window (windmove-do-window-select dir) - (my/exwm-switch-to-other-monitor dir) + (let ((mouse-autoselect-window nil)) + (my/exwm-switch-to-other-monitor dir)) (cl-loop while (windmove-find-other-window opposite-dir) do (windmove-do-window-select opposite-dir)))))) +(defun my/exwm-quit () + (interactive) + (when (or (not (eq (selected-window) (next-window))) + (y-or-n-p "This is the last window. Are you sure?")) + (evil-quit))) + (defun my/exwm-update-global-keys () (interactive) (setq exwm-input--global-keys nil) @@ -362,7 +370,7 @@ _d_: Discord (,(kbd "s-F") . exwm-floating-toggle-floating) ;; Quit - (,(kbd "s-Q") . evil-quit) + (,(kbd "s-Q") . my/exwm-quit) ;; Split windows (,(kbd "s-s") . evil-window-vsplit) diff --git a/Desktop.org b/Desktop.org index 8f971df..59ebe10 100644 --- a/Desktop.org +++ b/Desktop.org @@ -648,17 +648,18 @@ One caveat here is that on the startup the =my/exwm-last-workspaces= variable wo "Switch to another monitor." (interactive) (my/exwm-last-workspaces-clear) - (exwm-workspace-switch - (cl-loop with other-monitor = (my/exwm-get-other-monitor (or dir 'right)) - for i in (append my/exwm-last-workspaces - (cl-loop for i from 0 - for _ in exwm-workspace--list - collect i)) - if (if other-monitor - (string-equal (plist-get exwm-randr-workspace-output-plist i) - other-monitor) - (not (plist-get exwm-randr-workspace-output-plist i))) - return i))) + (let ((mouse-autoselect-window nil)) + (exwm-workspace-switch + (cl-loop with other-monitor = (my/exwm-get-other-monitor (or dir 'right)) + for i in (append my/exwm-last-workspaces + (cl-loop for i from 0 + for _ in exwm-workspace--list + collect i)) + if (if other-monitor + (string-equal (plist-get exwm-randr-workspace-output-plist i) + other-monitor) + (not (plist-get exwm-randr-workspace-output-plist i))) + return i)))) #+end_src I bind this function to =s-q=, as I'm used from i3. @@ -705,7 +706,8 @@ So here is my implementation of that. It always does =windmove-do-select-window= ('right 'left)))) (if other-window (windmove-do-window-select dir) - (my/exwm-switch-to-other-monitor dir) + (let ((mouse-autoselect-window nil)) + (my/exwm-switch-to-other-monitor dir)) (cl-loop while (windmove-find-other-window opposite-dir) do (windmove-do-window-select opposite-dir)))))) #+end_src @@ -743,6 +745,15 @@ Simulation keys. (,(kbd "M-c") . ,(kbd "C-c")))) #+end_src +A quit function with a confirmation. +#+begin_src emacs-lisp +(defun my/exwm-quit () + (interactive) + (when (or (not (eq (selected-window) (next-window))) + (y-or-n-p "This is the last window. Are you sure?")) + (evil-quit))) +#+end_src + And keybindings that are available in both =char-mode= and =line-mode=: #+begin_src emacs-lisp :tangle no :noweb-ref exwm-keybindings (setq exwm-input-global-keys @@ -772,7 +783,7 @@ And keybindings that are available in both =char-mode= and =line-mode=: (,(kbd "s-F") . exwm-floating-toggle-floating) ;; Quit - (,(kbd "s-Q") . evil-quit) + (,(kbd "s-Q") . my/exwm-quit) ;; Split windows (,(kbd "s-s") . evil-window-vsplit)