5 ms·
TinyWM – A tiny window manager in around 50 lines of C
- rbanffy 4y agoThis kind of software really needs some screenshots.
- johannes1234321 4y agoFrom looking at the code there isn't much to screenshot. It doesn't seem to add decorations to the windows, just allows sizing and positioning. So a screenshot would show some windows from other applications without a frame. All value is in the source code showing principles. (I might have missed something)
- teucris 4y agoThe absence of frames or other elements is extremely valuable to understanding what the window manager does/does not have control over.
- skyyler 4y agoIt's like 50 lines, just imagine what it would look like :P It doesn't look like it's drawing any title bars or borders or decorations of any kind.
- teucris 4y agoIf I’m not already very familiar with X, how am I supposed to know that?
- guerrilla 4y agoEvery line of code has paragraphs of text describing what it does.
- rbanffy 4y agoWe read it, but, still it's hard for someone with little experience with X window managers (fun story - I built a minimal graphical WM for the Apple II that fit in 1K) to have an idea. Also, I'm a visual thinker - nothing picks my curiosity about software like a nice screenshot.
- mlyle 4y agoThe purpose of this code is not to provide a useful WM. It's to illustrate the minimum, in case you want to play with it and become very familiar with X.
- ranger_danger 4y agoHow to draw my own window decorations is exactly what I'd be interested in learning.
- Avshalom 4y agoTwm, dwm or aewm might be good places to start for that
- rbanffy 4y agoI would expect their code to be written in ancient C. Probably not an easy read (I once tried to figure out how to use non-bitmap fonts by reading xterm's code - so I could help Paul Mattes in adding my font to x3270, but came out with a headache).
- forgotpwd16 4y agoNot much to show. Running startx with .xinitrc containing: xterm & glxgears & exec /usr/bin/tinywm you get: https://files.catbox.moe/m0ejwr.png https://files.catbox.moe/m0ejwr.png (pointer isn't shown but it's there)
- quirino 4y agoI used this as a starting point when playing around with writing my own WM, was very surprised with how little there is to it
- TillE 4y agoEven without the comments, it's so great to have concise, fully functional sample code when you're trying to understand how something works. I love any time I can spend 2 minutes reading code instead of 20 minutes piecing together the basics from documentation.
- TrisMcC 4y agoFrom looking at the Issues on GitHub, it seems that someone ported it to XCB: https://github.com/rtyler/tinywm-ada/blob/master/tinywm-xcb.c https://github.com/rtyler/tinywm-ada/blob/master/tinywm-xcb....
- cestith 4y agoAlso, as the repo name suggests, the Xlib version is ported to Ada in there.
- esjeon 4y agoWayland version of TinyWM: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/tinywl/tinywl.c https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master...
- abhorrence 4y agoI'm really keen to hear from someone who knows a bunch about X and WL to hear why there's such a huge difference in line count here. Is this analogous to OpenGL vs Vulkan where WL is a much lighter layer than X is?
- FreeFull 4y agoTinyWM doesn't include an X server implementation, while TinyWL is a full wayland compositor (although most of the heavy lifting is done by wlroots)
- tjdetwiler 4y agoWith x you're just bringing a window manager that plugs into the x-server. With wayland there's no standard 'window manager' plugin to arbitrary wayland servers. So the wayland example is doing more things (lots is handled by wlroots though).
- yamtaddle 4y agoYeah Wayland takes like 90% of the features of X and goes "you're on your own, window managers / desktop environments!" and if you complain they just say that's out of spec, working as intended, wontfix. It's like the exact opposite of what the Linux desktop needed.
- inetknght 4y agoSo... why C instead of at least C++ or an even better memory safe language?
- cestith 4y agoThe page linked offers a Python version calling into Python's Xlib binding python-xlib. It's the third code box down, after the bare C version and the heavily commented C version. Xlib itself is in C.
- Beltalowda 4y agoBecause then it's no longer minimal. And as mentioned there's a Python version. This isn't a "real program", as such. It's a demo or "rainy Sunday fun to figure out a bit how X11 works".
- inetknght 4y ago> Because then it's no longer minimal. C "might" be minimal but it brings with it a whole lot of dangerous baggage. Other languages can be just as minimal without the baggage. > This isn't a "real program", as such. It's a demo I didn't mean to imply anything different. I was just curious why C was used in the modern day where we (all?) know that C is a language that _should not_ be used for demoing because less experienced devs will think they can use C too and continue to create dangerous code
- glouwbug 4y agoC is fine. It’s the programmer that makes mistakes
- inetknght 4y agoBut that's exactly my point! Other languages help to prevent the programmer from making mistakes that are common in C
- Beltalowda 4y ago
- auraham 4y agoWonder how hard could it be to add tiling support?
- ihatepython 4y agoNot very hard as long as you don't care about drawing window frames.
- Beltalowda 4y agoYou don't even strictly need it in the WM, as you can resize windows from other programs, even shell script with xdotool etc, although xdotool/shell quickly becomes somewhat unwieldy I once wrote a "tiling WM" like this. It actually worked fairly well, and I kind of liked the modularity of it. At any rate, I dug up the old thing: https://pastebin.com/i91yD96F https://pastebin.com/i91yD96F – I also had some other scripts to control window placement, movement, etc. I once planned to rewrite it to a "real" language and combine it with a "slightly less tiny wm" as a full release, but never really got around to it, and I also don't really use tiling any more (I just have one full-screen window all the time).
- tabtab 4y agoIt looks like X Window does most the of rendering, correct? (based on header: "#include <X11/Xlib.h>")
- avhon1 4y agoYes, that's sorta fundamental to how X works. Window managers aren't at all responsible for drawing the contents of the windows.
- Jasper_ 4y agoProbably worth pointing out that while this will appear to work, it's certainly not ICCCM [0] compatible, so a lot of toolkits and applications that assume ICCCM compatibility will break. [0] https://www.x.org/releases/current/doc/xorg-docs/icccm/icccm.html https://www.x.org/releases/current/doc/xorg-docs/icccm/icccm... , one of the standards for how WMs and X11 applications should communicate.
- mobilio 4y agoRepost: https://news.ycombinator.com/item?id=994794 https://news.ycombinator.com/item?id=994794 https://news.ycombinator.com/item?id=17765446 https://news.ycombinator.com/item?id=17765446
- deleted 4y ago[deleted]
- chris_armstrong 4y agoThat’s really minimal, even for x11: it doesn’t even do reparenting and setting up window borders or xdamage/xfixes compositing
- guenthert 4y agoCan I make a wish? I would like a wm which sends SIGSTOP to processes which window I minimized and SIGCONT when I un-minimize it. For processes which use multiple windows, I'd be OK with all being minimized when one is to allow above functionality. There was a time when it was desirable to make room on the visible desktop while keeping long running processes running, but today we have lots of desktop real-estate and few legitimate long running processes, instead web pages leaching CPU cycles (I look at you, github!).
- jolmg 4y agoOn i3, with `i3-msg -m -t subscribe '["window"]'` you can get events when you change focus. With that and possibly the aid of `i3-msg -t get_tree` or some generic X utility like `xdotool search --onlyvisible \^`, you should be able to figure out which windows are hidden and which aren't. With `wmctrl -lp` you can match window ids to process ids and send whatever signals you want from a daemon script. > There was a time when it was desirable to make room on the visible desktop while keeping long running processes running, but today we have lots of desktop real-estate and few legitimate long running processes, instead web pages leaching CPU cycles (I look at you, github!). That probably depends on the person. It's not weird for me to have a web server running in the foreground of a terminal that's sometimes hidden. If it's stopped, it's not going to respond to my requests. It's in the foreground because there are times where it'll provide me a console to inspect the running state of the backend. Same when I'm running an strace on a PID. Sometimes that terminal gets hidden. If that's stopped, the program whose PID I'm tracing is going to get frozen at some point.
- guenthert 4y agoYou could run the web server (or other long running processes) within screen in the terminal, but yeah, that's stretching it. I look into i3, thanks!
- jolmg 4y agoIf your concern are webpages, you should first try sending SIGSTOP manually to some PID. Stopping a particular webpage may not be doable by stopping PIDs. There's nothing stopping multiple processes being involved in managing multiple windows non-exclusively (i.e. not only can a process manage multiple windows, a window can be managed by multiple processes). Your web browser may be beast enough to really complicate what you're trying to do.