ch11ng / exwm

Emacs X Window Manager
2.86k stars 137 forks source link

Displaying X buffers in a predefined fashion #906

Open nanjigen opened 1 year ago

nanjigen commented 1 year ago

I’m working to try and wrangle the x-windows of a wine program. I have some regexes that capture the exwm-titles and rename the buffers to what is seen below. As x-windows under EXWM are just emacs buffers, they should be controllable with the built-in display-buffer tooling via display-buffer-alist with the following layout in mind:

--------------------------------------------
| tree       |  sm-element-window   |
|                |                                                |
|                |                                                |
|                |                                                |
|                |                                                |
|                |                                                |
|                |-------------------------------|
|                |  sm-element-data          |
|                |                                                |
-------------------------------------------
    (add-to-list 'display-buffer-alist
                 '(("sm-frame"
                    (display-buffer-no-window))
                   ("sm-element-window"
                    (display-buffer-reuse-window display-buffer-same-window)
                    (window-width . 0.60))
                   ("sm-knowledge-tree"
                    (display-buffer-reuse-window display-buffer-in-side-window)
                    (side . left)
                    (slot . 0)
                    (window-width . 0.22))
                   ("sm-element-data"
                    (display-buffer-at-bottom)
                    (side . bottom)
                    (slot . 0)
                    (window-height . 0.24))))

However, this doesn’t work as expected, and we have to wrap these rules in an exwm hook:

    (add-hook 'exwm-manage-finish-hook
              (lambda ()
                (when (string-match-p "sm-frame" (buffer-name))
                  (display-buffer
                   (get-buffer-create "sm-frame")
                   '((display-buffer-same-window)
                     (allow-no-window . t))))
                (when (string-match-p "sm-element-window" (buffer-name))
                  (display-buffer
                   (get-buffer-create "sm-element-window")
                   ;; (doom-modeline-mode 1)
                   '((display-buffer-same-window) ;;FIXME maybe as race condition this doesn't work as expected
                     (window-height . 0.60))))
                (when (string-match-p "sm-knowledge-tree" (buffer-name))
                  (display-buffer
                   (get-buffer-create "sm-knowledge-tree")
                   '((display-buffer-in-side-window)
                     ;; (inhibit-same-window . t)
                     (side . left)
                     (slot . 0)
                     (window-width . 0.21))))
                (when (string-match-p "sm-element-data" (buffer-name))
                  (progn (exwm-layout-hide-mode-line)
                         (display-buffer
                          (get-buffer-create "sm-element-data")
                          '((display-buffer-in-side-window)
                            ;; (inhibit-same-window . t)
                            (side . bottom)
                            (slot . 1)
                            (window-height . 0.24)))))))

Unlike the alist attempt, the hook creates the correctly sized windows, and at least for some of the buffers, initially places them in the correct configuration. However, this approach seems to be triggered everytime I change workspaces, causing the hook to attempt to replace the buffers ending in a broken buffer layout.

I'd prefer to use the more idiomatic display-buffer-alist approach if possible.

What information should I be using to debug the issue?

If anyone has advice or working display-buffer-alist configurations for multi-window applications that would be greatly appreciated.