11 ms·
Berry is a healthy, byte-sized window manager written in C for Unix systems
- iqkznnft 4y agoFeaturewise, I don't see why I would move away from i3wm. That said, I always feel love for any project that pitches its code base as being small and in C.
- kelnos 4y agoAs someone who spent many years writing C, every time I go back to it, I wonder why people still write things in C. (I'm exaggerating; of course I know why people still write things in C, but I would have a hard time justifying starting a new project in C these days.)
- uecker 4y agoI used C++ for some time, but then went back to C. Why? Fast compilation, lower complexity, long-term stability, wide support.
- 5e92cb50239222b 4y agoI can name a couple a new projects I'm using heavily myself where using C makes sense (to me at least). Portability might be the most reasonable argument, which is understandable when you're writing things like build systems, e.g.: https://git.sr.ht/~lattis/muon https://git.sr.ht/~lattis/muon Then there are small tools when using anything else just doesn't buy you much, and if you're familiar with C, why bother? e.g. https://git.sr.ht/~kennylevinsen/wlsunset https://git.sr.ht/~kennylevinsen/wlsunset And situations like this one where you need both C API (for maximum compatibility), and manual memory management is a much for various reasons (read the blog post) https://news.ycombinator.com/item?id=19778738 https://news.ycombinator.com/item?id=19778738 https://news.ycombinator.com/item?id=24753626 https://news.ycombinator.com/item?id=24753626
- hawski 4y agoI think that when the code base is small it can be really fitting. Ones I find my favorite do almost no memory allocations. Or allocations are done only for the workset. I do not like that nowadays it seems customary to heap allocate everything and tie object's lifetime to where it keeps its state. Modern C++ with unique_ptrs sprinkled everywhere is like that.
- Thorrez 4y ago>and tie object's lifetime to where it keeps its state What's the objection there? I want the state to be freed when the object's lifetime ends. For something only needed during a function, a local value variable makes sense. For something that needs to last longer, either give it a move operator, or put it on the heap and use unique_ptr. If your point is that people sometimes use unique_ptr<std::string> instead of std::string or std::optional<std::string>, then yeah I agree, that's generally not good.
- eska 4y agoThat’s not his point, but you demonstrated it quite well. C++ use leads to developers that conflate memory allocation and initialization. For contrast, objective C also differentiates between the two.
- hedora 4y agoAllocation and initialization should be atomic. Otherwise, the rest of the program has to deal with uninitialized objects and no invariants hold.
- qalmakka 4y agoIn well written modern C++ there are rarely memory allocations outside of STL containers. I have worked on big embedded projects that only use unique pointers in very few locations, you can do a lot of stuff without using the heap if you really want.
- FpUser 4y ago
- msla 4y agoC is the scripting language of the kernel and low-level system libraries. Other languages have approached that status, but in my experience none have gotten to the point of zero-friction integration with libc and kernel syscalls. I understand why (for one thing, not having a real string type is painful) but it helps keep C around for low-level system-call-centric code which doesn't hit on any of the things C does really poorly.
- IgorPartola 4y agoC is just fun. I do t know how else to say it. It feels like you get to really think about what you want the computer to do.
- kelnos 4y agoI don't find it fun at all. I want to focus on what I want my program to do, not on how the computer does it, as long as its doing it reasonably efficiently. I want a successful compile to give me a decent amount of confidence that my program is correct, and is free of some classes of bugs. Life is too short to waste time tracking down double frees, out-of-bounds writes, memory leaks, and weird concurrency issues.
- klyrs 4y agoKinda like riding a fixed-gear bike. To some, the sheer simplicity is a joy of its own. To others, little besides literal tooth-pulling even compares.
- enriquto 4y agoI love this analogy! (Being a fan of C and of bikes). How does it continue? Assembly=walking, fixie=C, regular bike=fortran, electrically assisted bike=C++, electric wheelchair=python, ...
- IYasha 4y ago> electric wheelchair=python :_D You made my day! I'd continue like this: barely moving eye-popping-graffiti-painted squeaky wheelchair with no bearings mounted with duck tape inside a rusty sea container, that is chained to a heavy truck with broken exhaust and flat tires = (you guessed it! :) )
- enriquto 4y ago> barely moving eye-popping-graffiti-painted squeaky wheelchair with no bearings mounted with duck tape inside a rusty sea container, that is chained to a heavy truck with broken exhaust and flat tires If you add a solid rocket booster to this contraption (so that it actually moves) that would be exactly javascript.
- pjmlp 4y agoOutside of UNIX clones due to symbiotic nature with C, and embedded anti-C++ cargo cult which won't even consider C99 in some cases, there is hardly a reason. However this is hardly going to change outside the domains where corporations push for blessed languages on their platform SDKs, people keep being educated that C maps 1:1 to Assembly language and thus the myth continues. Even Microsoft with all their security talk only allows on Azure Sphere OS and Azure RTOS, the reasoning being their target market doesn't wan't anything else.
- gustavorg 4y agoAfter working years in Java, C#, Python, Ruby, and others, I would have a hard time justifying starting a new project without C these days.
- encryptluks2 4y agoWhen it comes to build systems, creating lightweight and efficient binaries that integrate with libraries and couple nicely with package managers... I think C is still one of the best options, although Go has come a long way and Rust isn't too far behind. In terms of security, I believe Rust has an advantage, but I've yet to find any exploits in the C programs that I use that would have somehow been mitigated completely with Rust, and there are a lot of unsafe Rust programs out there as well.
- lionkor 4y agoDefinitely agree. For me these days it's Zig all the way. The flawless and painless C interop is insanely good.
- FpUser 4y agoI write firmware for microcontrollers in C and frankly for these relatively small project C feels just right. On desktops / servers I prefer other languages and would not want to mess with C, at least for the types of products I do.
- mdp2021 4y agoWhat would you have used to write a Window Manager?
- kelnos 4y agoRust, or maybe I'd try something new (to me) like Zig or Nim. Window managers don't do all that much most of the time; I bet you could even write one in Python and not see performance issues. Hell, Go would be more than performant enough.
- mdp2021 4y ago> and not see performance issues And energy efficiency?
- itsthecourier 4y ago
- 0x1062 4y agoWould anyone happen to have a reference or link for the background image in the example on their webpage?
- jlervin 4y agohttps://unsplash.com/photos/dxZfq6Xuz5c https://unsplash.com/photos/dxZfq6Xuz5c
- whitten 4y agoThe article says the berry window manager responds with a JSON string that can be handled by jq. Does anyone know the history of jq ?
- Avicebron 4y agois this rhetorical? Edit: Benefit of the doubt, it's a command line json processor written in 2013 mostly in C.
- thrdbndndn 4y agoWow, I don't know jq only existed since 2013. What do people use before that?
- pluc 4y agoJSON was first standardized in 2013[1], so I guess nothing [1] https://en.wikipedia.org/wiki/JSON#Standards https://en.wikipedia.org/wiki/JSON#Standards
- skybrian 4y agoIt was standardized fairly late. Before that it was a well-known informal standard and parsers existed for many languages. According to the Wayback machine, a web page with the JSON grammar was on Crockford's website in February 2003: https://web.archive.org/web/20030228034147/http://www.crockford.com/JSON/index.html https://web.archive.org/web/20030228034147/http://www.crockf...
- pluc 4y agoI really don't get the popularity of virtual desktops/workspaces. Like this thing has 5 features and one of them is it. Seems to come default in most distros/WMs out there and I just don't get it. One workspace/desktop has always been enough for me, and I find having to navigate to other workspaces/desktop just wastes time when you can just find the relevant window...
- xvedejas 4y agoIt makes a lot more sense if you have multiple screens, and want to effectively have certain windows open in particular groups.
- pluc 4y agoBut having multiple screens _is_ having additional workspaces already...
- michaelmrose 4y agoIt is but a given task may easily benefit from placement of its central tools on the primary monitor and subsidiary components on adjacent monitors. Without workspaces this means re-arranging even more windows yet to accomplish this task switching.
- shric 4y agoIt's useful when you have a large screen with multiple windows that are tiled and dedicated to a single work function. For example a terminal on one side and a browser on the other that's dedicated to specific work. You may then have another virtual desktop dedicated to messaging, video editing, whatever... In well designed WMs like i3 each desktop is typically bound to a key for instant switching, unlike the full screen atrocity of macOS where there is an unremovable delay when switching.
- JasonFruit 4y agoI really like to use virtual desktops to isolate windows for a particular task: one for programming, one for social media, one for music notation, one for writing. Sometimes I have one of my kids making a Minecraft texture pack or something like that on my computer, and I'll stick that on a desktop of its own. It may be that I'm easily distracted, but I really love that feature.
- alain_gilbert 4y agoWhat does "byte-sized" means here?
- pixelatedindex 4y agoI downloaded the latest release as a zip file here - https://github.com/JLErvin/berry/releases https://github.com/JLErvin/berry/releases FWIW, it’s 34KB and while it’s only the source, that seems pretty small. I haven’t gone through the build process to figure out the executable though.
- jlervin 4y agoIts also referring to the relatively small codebase (2300 lines of C). Something like i3, for instance (although that is certainly more feature complete) is around 25,000
- deleted 4y ago[deleted]
- downut 4y agoAlrighty. I am a geezer. FVWM for 25 years, mas o menos. I just upgraded to fvwm git, package or local, on both Debian and FreeBSD. Partly because of fvwm I know way too much about HiDPI, and I was very happily using j4-menu-desktop as my chooser. And then... rofi. Which I tried with fvmw3. I love you, whomever did this. I am not sure how to work with berry but I am going to give it a serious try. Two pieces of configuration information I will have to ferret out are: Can I have overlapping windows with automatic mouse focus and elevation, with configurable delays? How do I choose among the virtual desktops? rofi doesn't do these, it seems.
- themodelplumber 4y agoThat's really cool looking, thanks for sharing. I wonder, what do the previous 5-10 skill-building coding projects look like as one ramps up to writing a window manager?
- jlervin 4y agothis is my project, so I can speak to this :) I wrote this as a sophomore in college after finishing the intro computer science sequence (which goes into basic data structures/algs topics like binary trees, recursion, etc). This was my first real project outside of school, and to be honest didn't require a ton of pre-requisite knowledge. Mainly it just required a familiarity with event-based architecture and linked lists (all the window stacking is represented as linked lists). The difficult part with writing a window manager, imo, is getting familiar with the necessary specs and APIs. This is built using XLib, which relies on the X11 protocol. I also had to learn about ICCCM and EWMH, since many program rely on them as well. It was good practice learning and implementing specs. I also added features throughout college as I took more classes. The smart window placement feature, for example, is implemented using a dynamic programming algorithm I thought up after taking a formal algorithms class. You can read about it on my blog if you're curious: https://www.josherv.in/2019/06/27/dp/ https://www.josherv.in/2019/06/27/dp/.
- heavyset_go 4y agoAdd an RSS feed to your blog :)
- themodelplumber 4y agoThat's really cool to read, thanks for sharing your experiences.
- hedora 4y agoFor me: 1. Learn C. 2. Read the source code to evilwm.
- TheDesolate0 4y ago
- em-bee 4y agoit would be helpful to start designating whether window managers or desktop environments work with X11 or wayland (or both). berry appears to be for X11.
- Athas 4y agoUnless some abstraction layers have been added while I wasn't looking, Wayland doesn't have a notion of window manager - only of compositors. These compositors incidentally also manage windows (although that's not the Wayland term I think), but I think the correspondence of compositor and window manager is still 1:1. Thus it is safe to assume that anything called a "window manager" is for X11.
- em-bee 4y agofair point, but i think this distinction between compositor and window manager is going to go away. if the compositor manages windows, then technically it is a kind of window manager. calling it something else feels unnecessary technically pedantic. if the term compositor wins out, then fine, but i feel that that won't happen.
- rollcat 4y agoThe term "compositor" refers to a program that is significantly broader in scope than an X11 window manager. You can write the most basic but somewhat useful WM in about 50 lines of C, and literally *all* it has to do, is to respond to new windows being mapped. A Wayland compositor on the other hand has to do approximately half of the work of an actual full-blown X11 server. This is why almost every WL compositor out there is using wlroots - which continues to advertise itself as "60k lines of code that you'd have to write anyway". Calling WL compositors "window managers" is somewhat like asking where's the horse in that car.
- hedora 4y agoCalling WL compositors "window managers" is more like asking how to swap out the engine on that donkey.
- going_ham 4y agoWhile people are discussing window managers, one of the most overlooked window manager is: hersbtluftwm.[0] If you work with multiple monitors, give it a try (today is sunday)! It uses the monitor swapping feature from xmonad but comes with simplicity of editing the config (one doesn't need to learn new programming language to edit config). It's a pretty cool window manager. [0]: https://herbstluftwm.org/ https://herbstluftwm.org/
- renke1 4y agoI've actually met the author of HerbstluftWM at the Konferenz der Informatikfachschaften (national student association meeting in computer science). Very approachable person. Coincidentally, the original author of Rack (Ruby) and the kind of inventor of tumblelogs was also there. Then again, where else would you meet people like that!
- scooble 4y agoA really fun feature of herbstluftwm that I’ve not seen replicated is that monitors are virtual and can be reconfigured on the fly, so you can have e.g. a monitor that is bigger than your physical screen, or a little virtual monitor that you can pop in and out of your screen as a kind of notepad.
- redleader55 4y agoI'm bothered by the sensationalist "healthy". It is used only once on the site and it's not explained. "Byte-sized" is also an offender here, but let's say I can mentally replace it by "small". Do we really need to explain technology in terms that sound fancy without deeper meaning?
- TravelPiglet 4y agoPuns on the name.
- donatj 4y agoI had assumed it to mean “actively maintained”, but I think the other commenter is right, it’s just a joke about the name “Berry”.
- floor_ 4y agoI would like to see a comparison between Berry 34KB in C and DWM 26KB in C.
- marcodiego 4y agoThe first screenshot[0] is a good example on how not to implement a MAX[1] macro. [0] https://berrywm.org/assets/berry.png https://berrywm.org/assets/berry.png [1] https://gcc.gnu.org/onlinedocs/gcc/Typeof.html https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
- nwmcsween 4y agoIt's fine for most cases, just don't get clever with the calls to the macro.