TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How X Window Managers Work, and How to Write One (2014)

276 pointsby firefly284over 3 years ago

13 comments

ninjinover 3 years ago
Talk about timing, I took my first plunge into writing code for X just a week or so ago and this was some really good reading. If someone is interested in digging into a non-toy, C codebase I can highly recommended dwm [1,2]. Yes, it is a very opinionated WM, but the code is clean, brief, and hackable – even for someone like me that has not hacked C for anything serious for over a decade – for something that can be used as a daily driver. It only took me about an hour or two to develop two patches that changed the layout to my liking. Plus, I have found the people in #suckless over at the OFTC IRC network to be very kind and helpful.<p>[1]: <a href="https:&#x2F;&#x2F;dwm.suckless.org" rel="nofollow">https:&#x2F;&#x2F;dwm.suckless.org</a><p>[2]: <a href="https:&#x2F;&#x2F;git.suckless.org&#x2F;dwm&#x2F;files.html" rel="nofollow">https:&#x2F;&#x2F;git.suckless.org&#x2F;dwm&#x2F;files.html</a>
评论 #29091959 未加载
fmakunboundover 3 years ago
I used to write an X11 window managers as a kick-the-tires exercise when learning a new language. The most fun one was Common Lisp with CLX. You could stay in the WM and code it live. When something went wrong you could continue after making fixes. It’s what lead me to Common Lisp being my favorite language going on decades now.
评论 #29112869 未加载
评论 #29097884 未加载
nerdponxover 3 years ago
Even if you don&#x27;t intend to write your own WM, I think this article is a great reference for understanding how X works in general.
cunidevover 3 years ago
Is there anything similar for Wayland? Its protocol looks considerably more complex than Xorg&#x27;s, and so are most resources to learn it.
评论 #29094536 未加载
评论 #29094399 未加载
评论 #29092594 未加载
shadowfoxover 3 years ago
Slightly orthogonal to this: is there a good tutorial on writing your own simple Xserver?
评论 #29093690 未加载
评论 #29092204 未加载
liveprogrammingover 3 years ago
This is a great article and I remember reading it numerous times while I was implementing my own window manager.<p>For someone interested in working on a really fun and rewarding hobby project a WM is a great one to look into since there are so many resources starting from really small implementations:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;mackstann&#x2F;tinywm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mackstann&#x2F;tinywm</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;venam&#x2F;2bwm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;venam&#x2F;2bwm</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;dylanaraps&#x2F;sowm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dylanaraps&#x2F;sowm</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;dcat&#x2F;swm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dcat&#x2F;swm</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;JLErvin&#x2F;berry" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;JLErvin&#x2F;berry</a><p>Which are great at introducing the concepts and allowing you to grok the required libraries.<p>To larger more full featured packed window managers which will introduce you to more advanced topics:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;baskerville&#x2F;bspwm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;baskerville&#x2F;bspwm</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;herbstluftwm&#x2F;herbstluftwm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;herbstluftwm&#x2F;herbstluftwm</a><p>- <a href="https:&#x2F;&#x2F;www.nongnu.org&#x2F;ratpoison&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.nongnu.org&#x2F;ratpoison&#x2F;</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;conformal&#x2F;spectrwm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;conformal&#x2F;spectrwm</a><p>Gradually as you get more familiar with the ecosystem a few questions will come up:<p>Should I use X11 or XCB? - I personally used XCB and didn&#x27;t find it too difficult to interface with, and there are a large number of implementations which use it (2bwm, bspwm, ratpoison, etc) so you shouldn&#x27;t have an issue with learning more about it. But the documentation is pretty limited. If you are just wanting to write a toy WM than X11 is perfectly fine.<p>X or Wayland? - If you&#x27;re wanting to write your first WM as a hobby project than I would recommend X over wayland just due to the much larger amount of reference material and documentation. You will have a much easier time getting your feet wet. Ignore the comments about X dying as it doesn&#x27;t really matter for a hobby project, since the whole point is to have fun.<p>Feel free to check out my window manager which is an example of what just reading this blog post and getting inspired can result in: <a href="https:&#x2F;&#x2F;github.com&#x2F;cfrank&#x2F;natwm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cfrank&#x2F;natwm</a>
评论 #29094938 未加载
评论 #29095446 未加载
评论 #29099636 未加载
DonHopkinsover 3 years ago
<a href="https:&#x2F;&#x2F;donhopkins.medium.com&#x2F;the-x-windows-disaster-128d398ebd47" rel="nofollow">https:&#x2F;&#x2F;donhopkins.medium.com&#x2F;the-x-windows-disaster-128d398...</a><p>&gt;As a result, one of the most amazing pieces of literature to come out of the X Consortium is the “Inter Client Communication Conventions Manual,” more fondly known as the “ICCCM”, “Ice Cubed,” or “I39L” (short for “I, 39 letters, L”). It describes protocols that X clients must use to communicate with each other via the X server, including diverse topics like window management, selections, keyboard and colormap focus, and session management. In short, it tries to cover everything the X designers forgot and tries to fix everything they got wrong. But it was too late — by the time ICCCM was published, people were already writing window managers and toolkits, so each new version of the ICCCM was forced to bend over backwards to be backward compatible with the mistakes of the past.<p>&gt;The ICCCM is unbelievably dense, it must be followed to the last letter, and it still doesn’t work. ICCCM compliance is one of the most complex ordeals of implementing X toolkits, window managers, and even simple applications. It’s so difficult, that many of the benefits just aren’t worth the hassle of compliance. And when one program doesn’t comply, it screws up other programs. This is the reason cut-and-paste never works properly with X (unless you are cutting and pasting straight ASCII text), drag-and-drop locks up the system, colormaps flash wildly and are never installed at the right time, keyboard focus lags behind the cursor, keys go to the wrong window, and deleting a popup window can quit the whole application. If you want to write an interoperable ICCCM compliant application, you have to crossbar test it with every other application, and with all possible window managers, and then plead with the vendors to fix their problems in the next release.<p>&gt;In summary, ICCCM is a technological disaster: a toxic waste dump of broken protocols, backward compatibility nightmares, complex nonsolutions to obsolete nonproblems, a twisted mass of scabs and scar tissue intended to cover up the moral and intellectual depravity of the industry’s standard naked emperor.<p>&gt;Using these toolkits is like trying to make a bookshelf out of mashed potatoes. - Jamie Zawinski<p>Recreational Bugs talk [1989] by &quot;Sgt.&quot; David Rosenthal (author of the ICCCM, the Andrew Window Manager, and NeWS, and an old friend):<p><a href="https:&#x2F;&#x2F;blog.dshr.org&#x2F;2018&#x2F;05&#x2F;recreational-bugs.html" rel="nofollow">https:&#x2F;&#x2F;blog.dshr.org&#x2F;2018&#x2F;05&#x2F;recreational-bugs.html</a><p>&gt;&quot;You will get a better Gorilla effect if you use as big a piece of paper as possible.&quot; -Kunihiko Kasahara, Creative Origami.
评论 #29099350 未加载
评论 #29097030 未加载
thuccess129over 3 years ago
Plan 9&#x27;s rectangle multiplexer, rio, needs an X11 mouse gesture addon for consistent Desktop Environment Application clipboard with Emacs&#x27;s do&#x2F;undo versatility.
low_tech_loveover 3 years ago
Funny, yesterday someone posted an article about an Ada-based X implementation, and I thought “could be fun to write my own X”. I guess I wasn’t the only one!
评论 #29092517 未加载
arduinomancerover 3 years ago
So for someone who knows nothing about this stuff, how is Wayland different?
评论 #29092034 未加载
评论 #29095761 未加载
评论 #29091943 未加载
rnd0over 3 years ago
I did not know I needed this until I saw this headline. I feel a new personal tangent coming on -thanks!
phendrenad2over 3 years ago
No mention of sockets? I&#x27;m surprised. That&#x27;s the real tricky part of writing an X11 server...
评论 #29093241 未加载
评论 #29099782 未加载
fyrn-over 3 years ago
Maybe don&#x27;t write an Xorg window manager right as the replacemeant for Xorg starts to take off though
评论 #29091591 未加载
评论 #29092191 未加载
评论 #29091948 未加载
评论 #29092135 未加载
评论 #29093128 未加载
评论 #29092061 未加载
评论 #29092220 未加载