emacs-exwm / exwm

Emacs X Window Manager
https://elpa.gnu.org/packages/exwm.html
GNU General Public License v3.0
236 stars 10 forks source link

HOWTO: different setup for different machines #9

Closed port19x closed 2 months ago

port19x commented 8 months ago

Since this took me ages to figure out, I'll document it here for the next person.

Full config segment

(use-package exwm
  :init
  (setq worklaptop (= 8 (string-to-number (shell-command-to-string "nproc"))))
  (require 'exwm-randr)
  (exwm-randr-enable)
  (if 'worklaptop (progn
                    (start-process-shell-command "xrandr" nil "xrandr --output DP-1-1 --right-of eDP --output DP-1-2 --right-of DP-1-1")
                    (start-process-shell-command "xrandr" nil "xrandr --output DP-1-1 --rotate left --output DP-1-2 --rotate right"))
    (start-process-shell-command "xrandr" nil "xrandr --output DisplayPort-0 --mode 3840x2160 --left-of eDP"))
  (exwm-enable)
  :config
  (add-to-list 'exwm-input-prefix-keys ?\M- )
  :custom
  (exwm-workspace-number 3)
  (exwm-randr-workspace-monitor-plist (if 'worklaptop '(0 "eDP" 1 "DP-1-1" 2 "DP-1-2") '(0 "DisplayPort-0")))
  :hook
  (exwm-update-class . (lambda () (exwm-workspace-rename-buffer exwm-class-name))))

Commentary

First set a variable to a boolean that detects some unique difference in your work setup. (shell-command-to-string "<command>") will help. Think hostname, distro, number of cores or sth.

Then, branch accordingly for both the :init xrandr call and the :custom workspace-monitor-plist setting

port19x commented 8 months ago

I'll leave this open for now. If the new maintainers want me to fix https://github.com/emacs-exwm/exwm/wiki#randr-multi-screen, as the current documented setup is neither intuitive nor working, I'd be up for it

medranocalvo commented 8 months ago

Thank you for posting. As is I would suggest to add it to the Cookbook.

There's a typo:

(if 'worklaptop

Is always true.

If the new maintainers want me to fix https://github.com/emacs-exwm/exwm/wiki#randr-multi-screen, as the current documented setup is neither intuitive nor working, I'd be up for it

If the documented setup is not working then sure. What's wrong about it or how do you think would be right or more helpful? I seem to remember that @Stebalien uses multiple monitors, perhaps you can collaborate.

Stebalien commented 8 months ago

The logic in https://github.com/emacs-exwm/exwm/issues/8#issuecomment-1907145338 will work for any number of monitors on any system although it assumes that every screen is "stacked" top to bottom, not left to right.

When we add "better" multi-monitor support in #8, I plan on at least trying to find a better way to specify monitor layouts.

port19x commented 8 months ago

Thank you for posting. As is I would suggest to add it to the Cookbook.

There's a typo:

(if 'worklaptop

Is always true.

If the new maintainers want me to fix https://github.com/emacs-exwm/exwm/wiki#randr-multi-screen, as the current documented setup is neither intuitive nor working, I'd be up for it

If the documented setup is not working then sure. What's wrong about it or how do you think would be right or more helpful? I seem to remember that @Stebalien uses multiple monitors, perhaps you can collaborate.

You're right, thanks for the catch. I remember having issues with the exwm-scree-change-hook never doing anything when I first migrated to exwm. I'll try to reproduce the issue at my earliest convenience

port19x commented 8 months ago

In the following block I tried to do it as prescribed by the wiki, resulting in black screens for the two vertical monitors with a mouse on there, but no emacs frame. This could still be user error, but it's not apparent to me what causes this. Please have a look

(use-package exwm
  :init
  (when (= 8 (string-to-number (shell-command-to-string "nproc")))
    (require 'exwm-randr)
    (setq exwm-randr-workspace-monitor-plist '(0 "eDP" 1 "DP-1-1" 2 "DP-1-2"))
    (add-hook 'exwm-randr-screen-change-hook
              (lambda ()
                (start-process-shell-command 
                 "xrandr" nil "xrandr --output DP-1-1 --right-of eDP-1 --rotate left --output DP-1-2 --right-of DP-1-1 --rotate right")))
    (exwm-randr-enable))
  (exwm-enable)
  :config
  (add-to-list 'exwm-input-prefix-keys ?\M- )
  :hook
  (exwm-update-class . (lambda () (exwm-workspace-rename-buffer exwm-class-name))))
medranocalvo commented 7 months ago

I see nothing wrong. Maybe there's an error somewhere else. How do you start X? If you use a ~/.xinitrc I suggest that you substitute exec emacs for exec xterm. Do you see XTerm? If so, launch Emacs from within and run EXWM (should work with your config above, otherwise M-x exwm-init.

minad commented 7 months ago

Starting an xterm first and proceeding from there is a good idea. It is still a bit odd that @port19x does not see a frame at all. If there were configuration errors, wouldn't Emacs still display a frame and show some errors? Unfortunately I didn't yet have the opportunity to look into multi-monitor setups, but I hope to do this soon. This is particularly important when we start working on #8.

port19x commented 7 months ago

I'm currently back on one screen after building a desktop PC. Ignore the issue for now until I'm back at the office (after my upcoming theory semester) to reproduce the issue and give you something more concrete to work with

ArneBab commented 2 months ago

It looks like you added your active workspaces to the exwm-randr-workspace-monitor-plist, but that is only needed for workspaces that should not be on primary.

Also you use eDP-1 in the xrandr call, but eDP in the plist.

My setup looks like this:

;; Enable exwm-randr before exwm-init gets called
(use-package exwm-randr
  :after (exwm)
  :config
  (setq exwm-randr-workspace-monitor-plist '(1 "DisplayPort-0")) ;; only the workspaces that should not be on primary
  (setq exwm-workspace-show-all-buffers t)
  (setq exwm-layout-show-all-buffers t)
  (exwm-randr-enable)
  (add-hook 'exwm-randr-screen-change-hook
            (lambda ()
              (start-process-shell-command
               "xrandr" nil "xrandr --output HDMI-A-0 --mode 1920x1200 --primary --auto --pos 0x0 --output DisplayPort-0 --auto --pos 1920x120"))
            100))
port19x commented 2 months ago

Things work now, I'm not exactly sure what went wrong back then and unless you believe it to be valuable, I won't bother investigating further