exwm icon indicating copy to clipboard operation
exwm copied to clipboard

split-window / windmove doesn't work as expected with exwm windows

Open lsp-ableton opened this issue 5 years ago • 11 comments

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?

lsp-ableton avatar Nov 24 '19 17:11 lsp-ableton

it seems to be related to commit fec85bb72a2d93fb86949f3409327b0f88ae60bc.

zz0x avatar Nov 25 '19 01:11 zz0x

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 avatar Nov 27 '19 14:11 ch11ng

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

lsp-ableton avatar Nov 27 '19 18:11 lsp-ableton

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?

nawetimebomb avatar Nov 28 '19 17:11 nawetimebomb

@elnawe yes, that works for me. Maybe it's best to try and have this function changed in Spacemacs then?

lsp-ableton avatar Nov 28 '19 17:11 lsp-ableton

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.

nawetimebomb avatar Nov 28 '19 17:11 nawetimebomb

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

lsp-ableton avatar Nov 28 '19 17:11 lsp-ableton

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.

nawetimebomb avatar Nov 29 '19 00:11 nawetimebomb

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

lane-s avatar Nov 29 '19 10:11 lane-s

Hi, having the same problem. A workaround from the original message works well, while others don't.

Is there any nice solution to it?

ezemtsov avatar Sep 25 '20 23:09 ezemtsov

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

nagy avatar Jul 14 '21 13:07 nagy