feat(desktop): improve window switching

This commit is contained in:
Pavel Korytov 2022-01-11 08:55:30 +03:00
parent fcca97d554
commit aff8463412
4 changed files with 48 additions and 26 deletions

View file

@ -3,3 +3,4 @@ channels:
- defaults
channel_priority: strict
changeps1: false
auto_activate_base: false

View file

@ -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

View file

@ -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)

View file

@ -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)