24 ms·
TinyWM – A tiny window manager in around 50 lines of C
- nkkollaw 8y agoI wish there was a screenshot, just to gauge what it could do without installing.
- deleted 8y ago[deleted]
- majewsky 8y agoIn the second paragraph, the page lists the feature set. Basically, you have a keyboard binding to focus a window, and two mouse bindings to move and resize windows.
- mbrumlow 8y ago> Move windows interactively with Alt+Button1 drag (left mouse button) > Resize windows interactively with Alt+Button3 drag (right mouse button) > Raise windows with Alt+F1 (not high on usability I know, but I needed a keybinding in there somewhere) > Focus windows with the mouse pointer (X does this on its own) You really don't need a screen shot. It is well described. Its 50 lines of code, you can read them in a matter of seconds and determine it is simply your programs plopped on the screen, no chrome, no borders, nothing, other than the contents of the programs you started.
- rsync 8y ago"You really don't need a screen shot." ... "no borders" Well, actually, I would like to see that ... which is to say, I would like to see some GUI apps without borders, etc., since it is something I have never seen before.
- scbrg 8y agoCheck out some screenshots of ratpoison, dwm or something similar. Granted, dwm sticks a 1px border on windows by default, but it'll give you an idea of how it looks. https://www.nongnu.org/ratpoison/ https://www.nongnu.org/ratpoison/ https://dwm.suckless.org/ https://dwm.suckless.org/
- nkkollaw 8y agoVery cool, thanks.
- michaelmrose 8y agoYou can already have this on window managers like i3wm.
- pjc50 8y agoIt doesn't actually draw anything, it just provides a means to move your windows around and change their z-order.
- pjmlp 8y agoBasically even less than twm. https://en.wikipedia.org/wiki/Twm https://en.wikipedia.org/wiki/Twm
- jenscow 8y agoKill your current window manager, that's what it looks like.
- teddyh 8y agoToo bad it uses the old Xlib instead of XCB.
- amarant 8y agothis is so cool, I've been wanting to learn more about windowmanagers for a while now! Any chance anyone knows of something similar to this but using Wayland as opposed to X?
- Sir_Cmpwn 8y agoNot a snowball's chance in hell of doing a Wayland compositor in 50 lines. OP has the benefit of the X server doing most of the work. Wayland compositors also have to do all of the rendering, input dispatching, GPU setup, etc themselves. With wlroots you could probably get pretty small, though, but you still have to do rendering et al yourself: https://github.com/swaywm/wlroots https://github.com/swaywm/wlroots (note: I am the maintainer of this software)
- mrweasel 8y agoI tried reading the source code for wlroot, and Sway, to figure out how hard it would be to base a "non tiling" window manager of it. It's very readable in isolation, but I struggled figuring out how stuff fits together. Maybe the issue is my limited understanding of C. Do you have any pointers to getting started developing for with Wayland (and wlroot)?
- Sir_Cmpwn 8y agoI'm writing articles on this on my blog: https://drewdevault.com/2018/02/17/Writing-a-Wayland-compositor-1.html https://drewdevault.com/2018/02/17/Writing-a-Wayland-composi... https://drewdevault.com/2018/02/22/Writing-a-wayland-compositor-part-2.html https://drewdevault.com/2018/02/22/Writing-a-wayland-composi... https://drewdevault.com/2018/02/28/Writing-a-wayland-compositor-part-3.html https://drewdevault.com/2018/02/28/Writing-a-wayland-composi... https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html https://drewdevault.com/2018/07/17/Input-handling-in-wlroots... https://drewdevault.com/2018/07/29/Wayland-shells.html https://drewdevault.com/2018/07/29/Wayland-shells.html
- juliangoldsmith 8y agoHow much of wlroots is devoted to dealing with the Wayland protocol, versus rendering and input handling? Writing a heavily constrained, low-level compositor seems like an interesting project. Maybe something that only supports a single type of graphics output, and uses KMS and DRI directly.
- lunchables 8y agoFinally, a window manager for people who find dwm bloated!
- deleted 8y ago[deleted]
- keithpeter 8y agoOdd that you should say that... I'm after a 'window manager' that can help me load a single X application on top of an X session that can sense the size of the screen and render the window maximised. If you try something like startx /opt/openoffice4/program/soffice from a linux console without a desktop manager set, you get an openoffice (whatever app) window that is a bit smaller than the screen and offset. Googling around suggests that you have to rely on each application to set its window size. startx /usr/bin/chromium --kiosk will get you something close to what I'm after for all applications.
- craftyguy 8y agoYou can do this with i3 (or any tiling WM, I believe), since they automatically maximize any window if it's the only one on the workspace. Disable the panel/i3bar, and you would have what you seek. Start it with 'exec i3' in .xinitrc and running 'xinit' on login.
- jgtrosh 8y agoI have a work VM with a stripped out i3 that can't create new terminals other than a startup terminal with tmux (which calls shutdown now on EOF); and it can still do basic interaction with other new windows. This reduces problems with VirtualBox X integration and makes the VM simple and like a terminal with some X capabilities. I3 is really flexible for this kind of use case.
- AdamJacobMuller 8y agoawesome, with a minimal configuration, will do what you want. Just create a single desktop that is tiled with a single application launched on startup
- Y_Y 8y agoSpent some time trying to get this to run in a Xephyr window on an old ubuntu box, but it doesn't seem to be able to move windows or resize as advertised (whereas twm is fine, and xev sees all the keypresses). These tiny projects are often cursed by having very few resources when something goes wrong.
- teddyh 8y agoAs far as I can tell, not ICCCM (nor EWMH/NetWM) compliant.
- rikkus 8y agoThis is important. But it's still great for people to see that a minimal implementation (for playing with) only takes this much code. It's good when you're learning.
- ktm5j 8y agoDoes it annoy anyone else when someone says something like "I wrote X in 50 lines of C" And then the first non-comment line is: #include <X11/Xlib.h> Which itself is over 4000 lines and includes tons more code.. It's a pretty meaningless metric.
- StreamBright 8y agoAnd all of this runs on a 1M+ loc kernel ;)
- azinman2 8y agoExactly. Nothing is built in a vacuum. It’s also running on top of cpu firmware, etc
- nickpsecurity 8y agoThere are some counterexamples that worked, though. In Verisoft, they did a whole stack from verified CPU to microkernel to simple OS and compiler. Everything was necessarily simple. http://www.verisoft.de/PublicationPage.html http://www.verisoft.de/PublicationPage.html The high-assurance community also did a low-complexity GUI: https://www.acsac.org/2005/papers/54.pdf https://www.acsac.org/2005/papers/54.pdf
- proyb 8y agoFrom what I understand, it's precisely a "wm" for Window manager and you'll see a list of other wm. https://en.wikipedia.org/wiki/Comparison_of_X_window_managers https://en.wikipedia.org/wiki/Comparison_of_X_window_manager... Just as web developers could write x lines of code that run on any web browsers and engines.
- segmondy 8y agoYeah, it annoys me when it's actually 50 lines of C code and it's more than 50 opcodes /s
- deleted 8y ago[deleted]
- collinglass 8y agoI ported this to go for fun 3 years ago: https://github.com/collinglass/tinywm https://github.com/collinglass/tinywm
- rhymenoceros 8y agoNice! Ironically the Go version is much longer, mostly due to the interop overhead (and partially due to the code style).
- zeveb 8y agoI think that the real advantage of something like this is that it provides a minimal template to follow if one wants to start writing a window manager in one's language of choice (assuming that language already has some X bindings). One can start from there, & then add ICCCM, tiles, whatever else one wants. edit 1: accidentally a word edit 2: I'm at a loss at why this isn't considered a contribution to the conversation. Can anyone enlighten me?
- equalunique 8y agoI don't have a problem with your comment. FYI just wanted to let you know that the point you made is proven by the go port discussed here: https://news.ycombinator.com/item?id=17766249 https://news.ycombinator.com/item?id=17766249
- deleted 8y ago[deleted]
- danmg 8y agoThis reminds me of the mid-to-late 90s where everyone made their own window manager. You had the choice of 100s of them. But usually they lost interest after a version or two, and didn't implement much of the icccm.
- the_duke 8y agoicccm?
- hk__2 8y agohttps://en.wikipedia.org/wiki/Inter-Client_Communication_Conventions_Manual https://en.wikipedia.org/wiki/Inter-Client_Communication_Con...
- swiley 8y agoThere still are quite a few that are actively maintained and implement icccm. That's something that bothers me about wayland. There really is a lot of variance when it comes to people's preferences about window decorations and focus behavior and so on. Having the applications handle it themselves is going to result in a lot of lost functionality/configurabilty.
- squiggleblaz 8y agoIt's already dying on X. The new Gnome apps for instance don't respect standard interaction even when the window manager is Gnome. (For instance, if a window has a modal dialog box open, you can't move the window; I think I've also had issues with pushing windows back despite this being a configuration option.) If you use Chromium too, it doesn't respect your settings for where the minimise/maximise/close etc buttons go until you right click somewhere and say "let me forget that your developers think they're so special they have to remind me i'm using your app every time i want to immerse myself". Gnome people will probably say "it's a trivial bug which we will fix shortly". But in reality it's intrinsic to the design. Now instead of picking an application which does its job well and a window manager which does its job well, you have to pick an application which manages its own windows well and does its job well. All because someone thought it's prettier if title bars have menu bars in them.
- oh5nxo 8y agoStrange to use 0x0 instead of NULL in XOpenDisplay().
- erikb 8y agoIs the xlib here as framework really the right backend? I have not much skill in this area so I can't say. In web development when someone claims he's written the shortest version of A and imports library B then usually the actually important code is written in B and he simply used A to configure the library to give the corresponding outputs he desires. Like "I wrote the shortest calculator ever: import Windows.Calculator; new Windows.Calculator();"
- wk_end 8y agoxlib is effectively as low-level a library as a WM might possibly use. This is like writing a calculator using the raw Win32 API, not some calculator library.
- jstarks 8y agoWhat about XCB?
- wk_end 8y agowell, I said "effectively" didn't I...? ;) XCB is, per wikipedia, "comparable, but slightly lower-level"; read that with emphasis on "slightly". It's certainly better than xlib, and if you were to write a real WM from scratch these days you should probably use it, but I think bringing it up is sort of besides the point in this conversation: OP was wondering if any sort of cheating was going on by including an X protocol library, and the answer is "no": neither xlib nor XCB would be appreciably providing any sort of abstraction around the concept of "X window manager".
- amelius 8y agoIf it were more involved to write a WM, then I'd say that would be an opportunity for a library to fill the gap ...
- dmos62 8y agoFor anyone pondering minimal/unbloated window managers, checkout cwm [0][1]. I've been using it exclusively for quite some time now. It's quick to compile, has sane configuration and is the most ergonomic floating wm I've used. I don't see myself ever needing anything else, provided I don't see myself using a tiled wm. [0] https://github.com/chneukirchen/cwm https://github.com/chneukirchen/cwm [1] https://man.openbsd.org/cwm.1 https://man.openbsd.org/cwm.1
- cultus 8y agoI use it too. It gets out of my way better than other window managers/desktops I've used. It's amazing how much good stuff comes out of OpenBSD despite the limited manpower.
- rambojazz 8y agoThanks for sharing. I'm a GNOME user but I want to try something lighter so I'm learning everything about "windows managers". I have never heard of "cwm" before, the only "cwm" that I was aware of is the "closed world machine" [1] so I was very confused at first :) Going to try it now, I wonder how it compares with awesomewm. [1] https://dokk.org/manpages/cwm.1 https://dokk.org/manpages/cwm.1
- jstimpfle 8y agoI wrote something like this once, and had maybe 3-4 applications that I wanted to use with it. mplayer was one of them, and it broke with my straightforward and absolutely reasonable window manager. It did display only a quarter of the movies since it thought the video window was fullscreen but it was only a quarter of the screen. The reason was a bug in mplayer's source code. It did not expect to be resized once and only once and being mapped only afterwards. Another story, I've been an icewm user for many years and I absolutely loved it. But at some point the bitrot was too much. Windows that didn't gain focus because of newer unimplemented client<->WM protocols, clients that crashed for hard to debug reasons, and so on. There are still some patches being developed for icewm that try to make it work with some newer clients. And there are workarounds on top of workarounds for fighting with Java clients, but at some point I decided it was too buggy and switched. Writing a window manager could be such a nice project if wouldn't mean implementing terrible but necessary protocols, and fighting with all the bad X11 clients out there.
- znedw 8y agoI use a mix of wmutils[0] and windowchef[1] and they're great, lots of little programs (some < 10 LoC) but also some cool stuff like mouse support and borders etc. I've only ever had trouble with JAVA apps which is a simple fix (_JAVA_AWT_WM_NONREPARENTING=1) This is a screenshot of my Linux desktop [2], I use these on OpenBSD as well without too much issue. [0] https://github.com/wmutils https://github.com/wmutils [1] https://github.com/tudurom/windowchef https://github.com/tudurom/windowchef [2] https://i.redd.it/ql1id3rocnq01.png https://i.redd.it/ql1id3rocnq01.png
- microcolonel 8y agohttps://github.com/xorgy/ldwm/blob/master/ldwm.c#L1799 https://github.com/xorgy/ldwm/blob/master/ldwm.c#L1799 Found that one out after some digging, seems weird to me that AWT manages to screw this up, to this day, maybe I'll understand what cool trick they do which makes this a problem. > I use these on OpenBSD as well without too much issue. Portability is a major benefit of these little window managers, I even ran my dwm fork on Minix3 (on real hardware!), with some minor Make changes [0] as a bored teenager. [0]: https://github.com/xorgy/ldwm/blob/master/config.minix3.mk https://github.com/xorgy/ldwm/blob/master/config.minix3.mk
- drudru11 8y agoVery clean screenshot. How does your setup fare with GL/Vulkan, Chrome?
- __s 8y agoThis was a reference for me while initially developing nobox: https://github.com/serprex/nobox/blob/master/nobox.c https://github.com/serprex/nobox/blob/master/nobox.c