RubyWM – an X11 window manager in pure Ruby
rubyflow.com
rubyflow.com
My only gripe (and this goes for almost any open source project) is this: please include screenshots! Any program/service that has front-facing UI should have visual references, instead of making users build/run everything just to “see” it.
Then we don't need any screenshot. We can do this with TWM, FVWM and MWM (and others).
My favourite!
As a rubyist using xmonad for years now (no real clue about haskell) I am thrilled.
https://sourceforge.net/projects/perlwm/
Last updated in 2004, just needs a touch of polish and she will be as good as new.
I suspect full screen Emacs in gnome, while not brilliantly efficient, is close enough to this project that I may as well stick with the mostly inert gnome layer
That's a superpower (software that will not bitrot): last month for a new project, I hesitated between C and perl but chose perl.
There are a few deprecations and things which have been removed from the language…like idioms that relied on interpreter bugs and have been obsolete for 20 years.
But if you run a Perl script without use strict, use warnings, or new command line flags, you’ll get a Perl experience largely unchanged since the turn of the century.
That’s my understanding anyways…
Not dead, as in no one uses it, but dead as in it has stopped living and no longer moves around.
In the same way that sanskrit or latin, languages known by millions of people, are dead languages.
And finally a bit of snark. python2 also has the neat property that it does not rot.
(after thought edit: I didn't meant this as a snarky dismissal, just a funny observation)
I wonder if your ruby compiler project would benefit from the now official pure ruby parser? [1]
That said, lrama is "just" the parser generator, is it not? As far as I understand, the Prism parser built using Lrama still produces a C library, and requires Ruby's parse.y as input, and parse.y alone is twice the size of my entire compiler...
Both Lrama and Prism are great projects, and I might've be tempted if that was a "missing piece" to turn the compiler into something production-ready, but frankly updating the parser to handle more modern syntax is the easiest bit of what remains. The really big pieces are supporting Regex's and floats (Ruby's regexp implementation is roughly the size of my entire current compiler...), and a bunch of bug fixing. Whether I'll ever find time to get it there or not, we'll see.
It is however the wm I actually use since I got frustrated with bspwm and did a very minimalist rewrite of TinyWM [1] in Ruby [2] and expanded it from there. It was painful the first few days until I'd had time to add multiple desktops and the start of a tiling mode. But at this point, it's "almost" pleasant for me.
The warnings are real, though, apart from the initial hyperbole - this is likely to break for you in all kinds of horrible ways still.
[EDIT2: As for a real example of the ways it can/will break: Right now, for some reason, after a restart without changing a single line, it's failing to grab super+buttons to move/resize windows; it doesn't really matter as I have keybindings for it and mostly use those, but, yeah, I'm doing something wrong somewhere and last time this happened the problem just went away by itself]
I use very few applications beyond (my own) terminal, (my own) polybar replacement, (my own) file manager, and a browser, and so once Chrome and my own apps mostly started working ok I've had very little incentive to make sure it behaves nicely with anything else and I know the distinction between different EWMH window types is incomplete and broken - just not in ways that usually affect my own use.
EDIT: Also a couple of quick notes on "design choices" to the extent this has been "designed" rather than accreted: As you can see in e.g. desktop.rb, quite a few places I've chosen to query and filter the top-level WindowManager class for a list of windows matching a given set of criteria. I did that on an experimental basis out of the idea that it was a waste of time to track precise state across multiple objects given that the total set of windows will always remain "small".
So the Window objects know the bare minimum state of the underlying X11 window that it needs to track, and the WindowManager class knows how to map an X11 window id to a Window object.
Other than that I avoid tracking state as much as possible, and even where I track state I try to avoid the need for full precision.
The one other place I must track state is the layout classes. Currently, only the basic tiling layout, which keeps a tree (that is currently a binary tree, but the array of nodes is there because I at one point thought I might allow more nodes) where the leaves keep track of which nodes have a defined place in the layout.
But even there, on updating the layout, I then crudely diff the currently known set of windows vs. the set of windows the layout believes are present and remove/add as needed.
I make a best effort to place new windows on map requests, but if anything breaks for any reason, the layout will "catch" up automatically and new windows will be placed. Given I use this daily while it is in flux and often broken because I've made a change and is testing it "live" on my desktop, this has turned out to be very helpful on occasion.
I can't make up my mind if this method (of constantly querying for attributes of every window) is a crude hack or quite elegant, but it works.
Many other things are not "designed". This is mostly very far from a good example of how to actually do things. E.g. "find_closest" used to pick a window to move to when you want to move directionally in a tiling layout is pretty much guaranteed to be possible to do much better with fewer lines of code once I actually get around to sitting down and thinking about it - the current version was cobbled together in a hurry because I was tired of not having the functionality and it "mostly works" as expected even though it's stupid.
[1] https://github.com/mackstann/tinywm/blob/master/tinywm.c
[2] https://gist.github.com/vidarh/1cdbfcdf3cfd8d25a247243963e55...
Very basic though, you'd have to provide your own functionality to print any text..
Though I sympathise - the sheer amount of effort to work with these, be it X11 or Wayland, is really annoying; the pure Ruby X11 gem I use is more lines of code than the window manager itself...
Also since all the prepackaged wayland libs are heavy users of functions declared as `static inline` I have to create shims for those as they are not linkable. That part is a pain in the ass but pretty simple to resolve :)
And yeah, there is so much to set up just to get a bare minimum going. I guess that would be true in X11 too.
I like that there are no other dependencies, but I'd have sacrificed that if it was sufficiently much easier than the route I ended up taking (e.g. my terminal did start out linking to Xlib and using a tiny C extension; it's since been ripped out in favour of the pure Ruby bindings, since why not now that it's available, but it was a perfectly ok solution to start with).
Writing a Wayland compositor from scratch means writing the whole display server. Wlroots readme describes it as "about 60,000 lines of code you were going to write anyway".
For comparison my wm is <1k lines.
So they're not equivalent - writing a Wayland compositor from scratch is more like writing the whole X server first, before even starting the WM.
I could use wlroots or another compositor as a starting point. I did look at it, but I'm still on X, and have no compelling reason to switch. Yet, anyway, and that adds to the "cost" for me in terms of disruption.
Where I could translate TinyWM into a few dozen lines of Ruby in a couple of hours and switch to actually using it and build from there, and "just" suffer some nuisance that I can slowly chip away at when I have time, even getting a basic wlroots binding + minimal compositor running seemed like a far more complex project.
I'm itching to figure out how to eat my way further down the stack, but I can't justify spending time on it unless I see a viable way of doing it (relatively) piecemeal.
E.g. I can restart my wm without exiting my X session, and so without losing any open applications. That gets far more disruptive for replacing the X server (whether by another X server or a Wayland compositor), and also allows for a far faster cycle - I can spot a problem, fix it, restart the WM and keep working without having to close everything...
I think if I was to do a Waylabd compositor, a first step would be to put things like window management beyond an IPC boundary, just like with X.
Isn't that already the case, by protocol definition? At least compositor and clients talk to each other over a pipe of some sort. It is actually a bit problematic because the way it is done put noticeable restrictions on both sides on processing things in time, because if it is full then shit hit the fan.
With Wayland the compositor serves the same function as both the X server, wm, and compositor in one. There's nothing inherent stopping the addition of extensions to allow the same split as in X (but the server/compositor split probably wouldn't be worth keeping - the WM is easier to split out because it's far less latency sensitive)
> I can restart my wm without exiting my X session
Sway also has a "reload" feature that preserves all open applications.
TinyWM for X is 50 lines.
> Sway also has a "reload" feature that preserves all open applications.
As far as I understand, sway's reload just reloads the configuration. If Sway crashes, or you kill Sway's process, there's nothing left holding the sockets to the clients open, or managing the display - that's equivalent to killing the X server, not the wm.
With an X wm, as long as your x session isn't set up to quit when the wm quits, you can brutally shut down the wm, or it can crash, and the windows stay open, and you can restart your wm - or start another wm entirely - without losing any windows.
Of course, that's a new feature they're working on, only helps QT apps, and requires the toolkit to track state (and by the same virtue, looks like it would have worked fine with X11 if they wanted to). So this is more of an interesting related tidbit rather than a disagreement.
Whether X or Wayland it would certainly make experimenting less painful. Browsers doesn't matter that much given they're reasonably decent at restoring.
(Another option there is xpra - "screen for X")
Fewer and fewer reasons not to start writing an X server ;)
The cheap version of this is just using tmux/screen, but yeah honestly I suspect a lot of programs are easy to make recreate their GUI state if you care to bother, it's just that not everyone does (or should; it's a trade off and display servers aren't usually that crashy).
Afaik river does something in that direction https://github.com/riverwm/river
> Dynamic layouts generated by external, user-written executables. A default rivertile layout generator is provided.
> Scriptable configuration and control through a custom Wayland protocol and separate riverctl binary implementing it.
E.g. one of the things I disliked about bspwm was that while I could get a feed of events and act on them, I couldn't intercept and modify or reject requests, so e.g. when a new window opened, bspwm would place it, and issue an event, and before my script could reconfigure the window it'd already be visible, so to get a floating desktop the way I wanted I ended up with windows flashing up in one location and then moving.
Put another way: The plethora of Wayland compositors is a strong demonstration of how these compositors don't give sufficient control via their external APIs, or people would write window managers for one or more of those compositors instead of writing more compositors.
After all, a Wayland WM is not just a WM, it also has to run and handle display server including talking with HW if you want any sensible performance.
There was a time I'd absolutely have loved something like that (and had all the window effects turned on when the first compositors started arriving) and it looks very cool, but other than translucency I've progressively stripped back everything.
I'll never try to compete with something like that on either effects or features. I might add some very minor eye candy. But that's fine - one of the things I've always loved about the Linux/Unix desktop is how you can get everything from the most minimalist to the effects-laden, and I've used wm's pretty much everywhere on that spectrum myself too over the years.
I sympathise re: drivers - that or the browsers finally abandoning X would be the only things that'd give me enough reason to switch. But I'd be more likely to switch if I get around to scratching the itch of yet another homegrown minimalist step down the stack... (I have a weird urge to write a Frankencompositor that supports Wayland clients and enough to support an out-of-band X11 style window manager and the brutally insecure X11 style event snooping and injection; partly because it'd really irritate some Wayland purists - I'm resisting that urge for now because it'd be a massive time-suck)
They are optional: you can make them last 100 ms, or just remove them.
Such "eyecandy" enable new uses: for example, all my windows are full screen, on they own desktop. No titlebar, no nothing because that's a waste of space. A quick animation when I change desktop helps me keep a mental map.
Also, hyprland great strength is it makes it not just possible but very easy to have a keyboard-centric workflow: you mix the tiling window manager strength with the traditional "windows" you can move with your mouse. F1 gets me to desktop 1 where my terminals live, Shift+F1 can send whatever window I'm using on desktop 1 to share it with the terminal for a while, Win + Left lets me adjust the tiling and Win + J lets me change from horizontal to vertical tiling
Last year was my year of Linux on the desktop, and I think I'll stay on Linux if only for hyprland.
> I have a weird urge to write a Frankencompositor that supports Wayland clients and enough to support an out-of-band X11 style window manager and the brutally insecure X11 style event snooping and injection; partly because it'd really irritate some Wayland purists
Check hyprctl: you can get a list of windows. With hyprland key bindings + basic shell scripts using hyprctl and ydotool to send key or mouse events, it's already possible!
From one of my simple scripts: `hyprctl dispatch focuswindow $WINDOW_ID | wl-paste | wl-copy -c` replaced `ydotool type "`wl-paste`"`
I'd rather have a codebase that doesn't have them so that I can work on a codebase that is tiny and focused on what I want when I want to change something. And I would need to make changes to the code base for it to suit me - see below.
> Also, hyprland great strength is it makes it not just possible but very easy to have a keyboard-centric workflow:
I already have a keyboard-centric workflow that does the things you list. There's nothing new in any of that. I have a floating desktop; I can move and resize them with the keyboard. I can move the tiling windows with the keyboard. I can swap individual windows, or swap entire subtrees, or flip their direction. All of that is trivial on almost any tiling wm.
> Check hyprctl: you can get a list of windows. With hyprland key bindings + basic shell scripts using hyprctl and ydotool to send key or mouse events, it's already possible!
This has the same flaw that was one of the reasons why I ditched bspwm - it allows getting events from it's 2nd socket - but not to intercept requests and being able to rewrite and choose whether to honor the requests or not. It does not have the flexibility I had in mind.
It has a lot of great functionality, but none of the things that I care about provide more than I already have, and some would set me back to the point I'd have to rewrite stuff again - and frankly just the build process for hyprland makes me break out in hives...
So that leaves how long I will have a working X server, and frankly I suspect I'll have ended up writing a display server years before that becomes an issue (whether that'll be X or Wayland or a mix, who knows, but I doubt I'll be able to resist very long).
It's just not a concern that's anywhere near the top of my list (or the top 100 of my list)
E.g. I tested, and Firefox runs fine in Weston in kiosk mode w/X as the backend.
So even when Firefox drops X, it will still run on X as long as a single compositor with an X backend is still running.
Also, as sibling comment points out, a simple solution exists in the form of rootful xwayland; we can keep a working X11 environment and just swap out the actual rendering layer.
Or put differently: "Given that X11 is going away, the server (except for Xwayland) is unmaintained," just isn't true, and even if it was it wouldn't necessarily justify the claims you make on that basis.
If X dies, I assume we’re going to end up with Javascript or Wasm frontends to everything.
Which points to this GitHub: https://github.com/vidarh/rubywm/tree/master
I was hoping for some screenshots and I can't seem to find any easily. Would appreciate some screenshots/recording of it working to get a taste of it!
https://m.galaxybound.com/@vidar/111739055121708028
Here is one I did that shows a couple of file manager windows and my terminal and desktop switcher on my floating desktop:
Minimalism usually means fewer problems and bugs, it's not a bad thing.
> Here is one I did that shows a couple of file manager windows and my terminal and desktop switcher on my floating desktop:
Looks quite nice! I would suggest to add a few pictures to the GitHub.
> Looks quite nice! I would suggest to add a few pictures to the GitHub.
So many keeps asking, so I guess I've have to add some...
[1] https://www.uninformativ.de/git/katriawm/file/README.html
I love seeing these kinds of projects because it further validates that such an idea is feasible.
*it really would though
It was what made me fall in love with Ruby: There are so many spaces where the time is spent elsewhere and the time spent doing things slowly in Ruby (though much faster than it used to be) doesn't matter.
Like a window manager.
I've even made performance tradeoffs that makes it much slower: On every adjustment of the layout, I iterate over every single window the WM knows about to filter a list of the wm's on this desktop, that are visible, and compare that to a serialized list of every single window that exists in the layout tree.
Because it's fast enough, and it saves bothering to keep proper track of state, and makes some of the code simpler.
Knowing when you can afford to pick the slow options on purpose is powerful.
Knowing when you can't afford to, is also important.
Hard place: crowd of Wayland pitchforks thundering in the distance
Effort analysis: <negative beeping>
Itch: scratch?
Me: annoyed twitching
I imagine the vast optimisations that came in PHP7, likely at Meta and Wordpress's behest, would be to thank for that.
1) Startup time had to be fast because of how it worked in its most common use case (yes, yes, FPM, but still) which tends to encourage or require making everything fast.
2) Writing C modules for PHP is relatively easy and it has a culture of anything halfway important being in C, going back to the early days of the language. The answer for how to be really fast with real-world workloads in almost every scripting language is basically “get out of it and into C ASAP” but PHP’s culture embraces that more than most.
Sad that Microsoft is slowly degrading GitHub experience.