Skip to content

exwm gets lost when plugging in monitor #96

@xpusostomos

Description

@xpusostomos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions