Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaning of covered-buffers when splitting window #15

Open
mobid opened this issue Feb 7, 2024 · 2 comments
Open

Meaning of covered-buffers when splitting window #15

mobid opened this issue Feb 7, 2024 · 2 comments

Comments

@mobid
Copy link

mobid commented Feb 7, 2024

Hi,

If have next case:

  1. Start in scratch buffer
  2. Open two X windows, one above the other
  3. Now when I split window I expect covered X window to be shown, instead scratch is displayed in other window.

As I saw in code https://github.com/emacs-exwm/exwm/blob/master/exwm-layout.el#L392 there is case which prevent my expected behavior. If I set there covered-buffers to nil it is working fine for me.

Is there any case when covered-buffers are meaningful?

@mobid mobid changed the title Meaning of covered-buffers when splitting windows Meaning of covered-buffers when splitting window Feb 7, 2024
@medranocalvo
Copy link
Contributor

Hmmm I see.

(Context.) Usual Emacs behaviour when splitting is to display the same buffer in the new window. In EXWM we disallow an exwm-mode buffer to be displayed in more than one window. After splitting the window we notice that two windows display our exwm-mode buffer so we vacate one of them. I believe that the (selected-window) gets to keep it. Now, this new window must display another buffer; we go out of our way to prevent this other buffer to be an exwm-mode buffer being covered:

exwm/exwm-layout.el

Lines 381 to 390 in 2bb9a57

;; Note any `exwm-mode' buffer is being covered by another
;; `exwm-mode' buffer. We want to avoid that `exwm-mode'
;; buffer to be reappear in any of the vacated windows.
(let ((prev-buffer (car-safe
(car-safe (window-prev-buffers window)))))
(and
prev-buffer
(with-current-buffer prev-buffer
(derived-mode-p 'exwm-mode))
(push prev-buffer covered-buffers)))))))))

Is there any case when covered-buffers are meaningful?

I should know because I implemented this... but didn't write an explanation in ch11ng/exwm#145. Let us... reconstruct a reason.

Please, edit

(let ((exwm-layout--other-buffer-exclude-buffers covered-buffers))
to have instead:

    (let ((exwm-layout--other-buffer-exclude-buffers nil))

Now perform the following steps:

  1. Start in scratch buffer
  2. Split vertically C-x 3
  3. Split vertically C-x 3
  4. Launch XEyes
  5. Launch XTerm
  6. Select middle window C-x o
  7. Switch to XEyes C-x b XEyes - xeyes
  8. Switch to XTerm C-x b XTerm - xterm

Why does XEyes suddenly display in the left window again? I just "moved" it to the middle one!

  1. Select right window C-x o
  2. Switch to XTerm C-x b XTerm - xterm

Shouldn't XEyes move back to the middle window, where I placed it?


I'm pretty sure that's the only reason I had for implementing this covered-buffers (mis?)feature. That is, although without covered-buffers our behaviour would be more similar to regular Emacs buffers, it kind of ends up being unintuitive. I think that something similar happens with your proposal above: will showing the prev-buffer on the split window match users' intuition?

(To clarify, I'm opening this for discussion. I'm not sure what's the better behaviour.)


Tangentially, I dislike that we are implementing this at all in EXWM: this should be a Display Buffer Action Function (https://www.gnu.org/software/emacs/manual/html_node/elisp/Buffer-Display-Action-Functions.html), e.g. display-buffer-unique-window. I'm not sure whether it is feasible. Also, this behaviour should in my opinion be optional: I believe that I would prefer having exwm-mode buffers displayed in multiple windows where only the selected one (or last selected) shows the actual X window and the others show, say, a caption or a screenshot (...). I'm also not sure whether this would be comfortable.

@mobid
Copy link
Author

mobid commented Feb 12, 2024

It make sense now. Maybe I didn't notice that, because I normally have only few X windows.

I'm fine with the both behaviours, which can be simply acomplished with checking last command in predicate:

(defun exwm-layout--other-buffer-predicate (buffer)
  (or (not (with-current-buffer buffer (derived-mode-p 'exwm-mode)))
      (and (not exwm-layout--other-buffer-exclude-exwm-mode-buffers)
           (or (not (memq buffer exwm-layout--other-buffer-exclude-buffers))
               (eq last-command #'split-window-below)
               (eq last-command #'split-window-right))
           ;; Do not select if already shown in some window.
           (not (get-buffer-window buffer t)))))

I understand that same X window cannot be shown in two places, but I rater see previous window instead of previous non-exwm buffer. (when splitting) Same split behaviour has StumpWM.

I believe that I would prefer having exwm-mode buffers displayed in multiple windows where only the selected one (or last selected) shows the actual X window and the others show, say, a caption or a screenshot

I like this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants