exwm
exwm copied to clipboard
split-window / windmove doesn't work as expected with exwm windows
Spacemacs defines commands for splitting a window into two and then focusing the new window:
(defun split-window-below-and-focus ()
"Split the window vertically and focus the new window."
(interactive)
(split-window-below)
(windmove-down))
For some reason, if I run this command in a Firefox window, the Firefox window gets moved to the bottom and focused, when normally it would stay at the top, and the new window at the bottom would have focus.
I've patched the command like this:
(defun split-window-below-and-focus ()
"Split the window vertically and focus the new window."
(interactive)
(split-window-below)
(run-at-time "0.1 seconds" nil (lambda ()
(windmove-down)
(when (and (boundp 'golden-ratio-mode)
(symbol-value golden-ratio-mode))
(golden-ratio)))))
Obviously this is a hack because I don't understand the behaviour. Why would (windmove-down)
do something different with a Firefox window as compared to a normal emacs buffer?
it seems to be related to commit fec85bb72a2d93fb86949f3409327b0f88ae60bc.
This is because unlike other buffers an exwm-mode
buffer can not be displayed in multiple Emacs windows, as it's not easy to replicate an X window without compositing. As a result, we must resolve the conflict after a window splitting and the first Emacs window returned by get-buffer-window-list
(the selected one in this case) would be used to actually display that buffer.
@ch11ng What would you think of caching the selected window when a split function is called and then using that to display the buffer instead of the window returned by get-buffer-window-list
?
I don't use Spacemacs but I have a similar custom function that works well in Firefox and any other EXWM buffer (without using windmove).
(defun nemacs-create-window-bottom-and-switch ()
"Creates a new window to the bottom and then switch to it."
(interactive)
(split-window-below)
(balance-windows)
(other-window 1))
(defun nemacs-create-window-right-and-switch ()
"Creates a new window to the right and then switch to it."
(interactive)
(split-window-right)
(balance-windows)
(other-window 1))
I replaced (other-window 1)
with (windmove-down)
and (windmove-right)
respectively and it works well, the Firefox window stays in the original position and cursor is moved to the new window. NOTE: This new window is not a Firefox window but the last opened buffer. Is that what you expect to see @lsp-ableton?
@elnawe yes, that works for me. Maybe it's best to try and have this function changed in Spacemacs then?
To be honest they are really similar functions and I cannot reproduce this on my Emacs configuration (again, not Spacemacs), even using windmove
. Maybe the issue is created by hooks or configurations that Spacemacs is doing and I'm not?
Have you tried my function? Just eval
it and run it on Firefox.
@elnawe Yep, I tried yours. It works well for me. It looks like it has the same result as the hacky function I made above to work around the issue. My concern is mainly for other Spacemacs users that try out exwm and run into this issue. The end goal here would be to get Spacemacs and exwm working together well enough that an exwm configuration layer would be accepted into Spacemacs and one could have 'SpacemacsOS' without doing much work at all.
Question: Are you using Spacemacs and installed EXWM by yourself or using SpacemacsOS?
I cloned and eval
that function from Spacemacs and still worked for me so I think the source of the problem is not Spacemacs function either.
The function is here.
(defun split-window-below-and-focus ()
"Split the window vertically and focus the new window."
(interactive)
(split-window-below)
(windmove-down)
(when (and (boundp 'golden-ratio-mode)
(symbol-value golden-ratio-mode))
(golden-ratio)))
I think this is not an EXWM problem but rather a configuration issue.
@einawe I'm using Spacemacs and installed EXWM by myself. I guess it sounds like maybe there are some kind of hooks installed by Spacemacs that are interfering with this.
Hi, having the same problem. A workaround from the original message works well, while others don't.
Is there any nice solution to it?
What has worked for me is putting a (redisplay)
inbetween the two commands like so:
(defun split-window-right-and-focus ()
"Split the window horizontally and focus the new window."
(interactive)
(split-window-right)
(redisplay) ; for exwm compatibility
(windmove-right))