But yeah, the core issue here isn't really the office, it's attention and concentration. I recently read James Clear's Atomic Habits and am now about halfway through Cal Newport's Deep Work.
I think all developers should read these two books in order to gain an understanding of the psychology of concentration. The TLDR is simply that it's hard to stay focused, minor distractions cost you more productivity than you think, and the effect is even cumulative over long periods of time.
There's lots of research on the topic and there are many ways to address the problem. They all fundamentally relate to carving out time for working without distractions, as much and as routinely as possible.