Ever since DistroTube finished his Configuring Emacs series a couple of months ago, I moved from using (the somewhat monolithic and impenetrable in my opinion) Doom Emacs every now and then, to seriously using Emacs with his config about a month ago, and I've fallen in love. So much so that I clearly wanted to start using Emacs as my window manager.
I really like having a statusbar, so since I had been using dwm (also, if you want dwm-like window management, Edwina is the package for you), I figured it was finally time to set Polybar up. I did, but as many people experienced, Polybar had the issue of workspaces being off by one with the standard EMWH module. I looked around, and wasn't able to find the solution anywhere else, so I'll post my solution.
The crux of the problem lies in an assumption made in the code for switching workspaces, provided by the EXWM developers, namely the following code: I'm not even going to begin to fight Reddit's markdown on this one. The workspaces created are zero-indexed, which is all well and good for Polybar, but the bindings are where the problems come up. The code assigns workspace 0 to s-0, workspace 1 to s-1, etc. (and I don't claim to be any kind of Elisp guru, since as mentioned, I've only been seriously using Emacs for about a month or so). The problem is that the EWMH plugin counts workspace 0 as 1, workspace 1 as 2, etc., and also because of the way the bindings work, you end up with 10 total workspaces at the end.
The (mostly satisfying) solution I found is to change the last two lines of the mapping.... whatever you wanna call it. This maps workspace 0 to s-1, workspace 1 to s-2, etc. Naturally, this requires configuring exwm-workspace-number.
(exwm-workspace-switch-create ,(- i 1)))))
(number-sequence 1 exwm-workspace-number))
There is a resulting issue with this solution though: the ninth workspace. The mapping thingamabob gets a bit upset if 10 gets passed into it, so you need to map s-9 manually, but that's easy enough to do with a short helper function. Something like
(defun exwm-workspace-switch-to-9 () (interactive) (exwm-workspace-switch-create 8))
and then bind as you would any other global key. This allows the EWMH module to work just fine, without any need for any hooks or anything like that. Outside of having to define another function, this is about the most satisfying solution I've been able to come up with. Naturally, if anyone has any even-more-elegant solution, I'd love to hear it, but I'm plenty happy with this. This way, polybar is able to show what workspaces EXWM buffers are open on, alerts, etc.
Thanks for the tip! Going to come back to this next week when I get the chance to try exwm again...