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

exwm gets lost when plugging in monitor #96

Open
xpusostomos opened this issue Dec 17, 2024 · 2 comments
Open

exwm gets lost when plugging in monitor #96

xpusostomos opened this issue Dec 17, 2024 · 2 comments

Comments

@xpusostomos
Copy link

I'm finding that when I plug and unplug my monitor, into my laptop it doesn't restore a proper view or workspace, it just shows a blank screen. I can mouse around that screen and between screens, but it stays blank.

(defun cc/build-workspaces (l n)
  (cons
   (cons n (car l))
   (if (cdr l)
       (cc/build-workspaces (cdr l) (+ n 1))
     nil)))

(defun cc/exwm-randr-screen-change ()
  (setq cc/screen-list (process-lines "sh" "-c" "xrandr | sed -n  's:\\([^ ]\\) connected .*:\\1:p'"))
  (setq exwm-randr-workspace-monitor-alist (cc/build-workspaces cc/screen-list 0))
  (setq exwm-workspace-number (+ 1 (car (car (last exwm-randr-workspace-monitor-alist)))))
  (setq exwm-randr-workspace-monitor-plist (list-utils-flatten exwm-randr-workspace-monitor-alist))
  (let ((first (car cc/screen-list))
	(rest (cdr cc/screen-list)))
    (dolist (screen rest)
      (start-process-shell-command "xrandr" nil (format "xrandr --output %s --left-of %s --auto" screen first)))))

(add-hook 'exwm-randr-screen-change-hook #'cc/exwm-randr-screen-change)

Which seems to work. Every time I plug in my monitor and check the value of exwm-randr-workspace-monitor-plist it looks correct, which is (0 "eDP-1" 1 "DP-1") when it's plugged in, and (0 "eDP-1) when it's not plugged in.

But here is the odd thing, I've got s-0 - s-9 keys assigned to switch workspaces:

(setq exwm-input-global-keys
      `( ,@(mapcar (lambda (i)
                    `(,(kbd (format "s-%d" i)) .
                      (lambda ()
                        (interactive)
                        (exwm-workspace-switch-create ,i))))
                  (number-sequence 0 9))))

I find that if I flip workspace to one I didn't use before, say workspace 2, suddenly boom, my monitor starts showing what it is supposed to, as if it kicked it into reevaluating. That's despite that the monitor shows workspace 1 always, and s-1 still takes me to the monitor, not the new workspace. All these new workspaces still belong to my laptop screen, not the monitor.

But the thing is, every time I unplug and plug I've got to use a higher workspace number. The next time s-2 won't work, I'll have to go to s-4 or something. Eventually I run out of workspaces 0-9, and have to resort to manually creating them with (exwm-workspace-switch-create some-big-number) to get my screen working again.

@Stebalien
Copy link
Contributor

You probably need to run exwm-randr-refresh from your hook. Otherwise, EXWM has no way to know that the workspace/monitor mapping has changed. That function is run automatically whenever a workspace is added/removed, that's likely why you're seeing this behavior.

Fixes we should make:

  1. exwm-randr-workspace-monitor-plist should document this.
  2. exwm-randr-workspace-monitor-plist should call exwm-randr-refresh when customized (e.g., via setopt) exwm-randr-mode is enabled.

@xpusostomos
Copy link
Author

Thanks, that works.

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