Tiny-wlhs, a hybrid haskell and C Wayland compositor

Tiny-wlhs: A Haskell-Driven Wayland Compositor (Seeking Contributors!)

This thread originated in the Haskell Wlroots Bindings discussion.

Introduction

tiny-wlhs began as an experiment to explore Haskell bindings for wlroots. We took the simple tinywl C compositor and turned it into a Haskell-controlled shared library. This approach lets us incrementally port C code to Haskell while keeping a working window manager. The immediate feedback from a functional compositor is invaluable during development and provides something solid to work with. You can find the project on GitHub: https://github.com/l-Shane-l/tiny-wlhs

tiny-wlhs currently creates a Wayland window and serves as a platform for testing future Wayland bindings. A pure Haskell compositor presents some key challenges and is an eventual goal but first we need robust bindings for wlroots and, crucially, a Haskell equivalent of the Wayland scanner (which converts Wayland protocols from XML to C).

Motivation: Towards a Haskell Wayland Daily Driver

While waiting for bindings and a scanner there is interest in a usable, Haskell-based Wayland compositor—a daily driver that we can use and refine every day. While work on bindings and a scanner continues, tiny-wlhs provides a valuable stepping stone with the following benefits:

  1. Hands-on Learning: Building a compositor is the best way to learn Wayland.
  2. Identifying Needs: A Haskell-based compositor clarifies the requirements for a pure Haskell implementation.
  3. Top-Down Approach: Starting with a working example and iteratively improving it is a lot easier than building from scratch.

Our primary goal is to make tiny-wlhs a practical daily driver. We’ll gradually port C components to Haskell, paving the way for a future pure Haskell version. This will require careful API design. tiny-wlhs is also a tool for developing and testing Haskell wlroots bindings and a Haskell-based Wayland scanner.

Why a Hybrid Approach?

Creating complete Haskell wlroots bindings and a Wayland scanner is a monumental task. wlroots is a large and complex C library. Building a Haskell Wayland scanner is equally challenging. Our hybrid approach allows us to make progress now with a functional compositor, learning as we go and using tiny-wlhs as a testbed for future pure Haskell solutions. The project uses nix so it should be quite fast to get started.

Next Steps and Features

tiny-wlhs currently has the same features as tinywl (tinywl documentation). We’re looking to add:

  1. Core Functionality: Start/stop server, server configuration.
  2. Output Management: List outputs, basic configuration.
  3. Window Management: Tiling, resizing, moving, focus, closing, fullscreen.
  4. Input Handling: Keyboard and mouse bindings.
  5. Application Launching: Spawning applications.
  6. Compositor Features: Basic decorations.
  7. Inter-Client Communication (Future): Advanced Wayland protocols.

Get Involved!

  • Feature Development: Build the features you want.
  • Haskell FFI: Improve the Haskell/C interface.
  • Create Wlroots bindings: Create and contribute wayland bindings
  • Wayland/Wlroots: Port C code to Haskell.
  • Build Systems: Enhance the build process.
  • Haskell GUI Libraries: Design the Haskell API.
  • Join the discussion: Contribute to everything from project naming to project managment

Collaboration

This thread is for updates and discussions. We may create a dedicated communication channel (Discord, Matrix, IRC - let us know your preference!). Documentation and project details are open for discussion.

Try building and running tiny-wlhs! Report any issues on GitHub. Create branches for development. We’re excited about this project and invite you to join us!

19 Likes

Update - Addition of Keybindings

Hi all, this post and thread will likely be a mix between devlog and announcements.

This weekend keybindings was added to Tiny-wlhs which is a key milestone on the path to getting something that can be used as a daily driver.

You can see a short demo on the README GitHub - l-Shane-l/tiny-wlhs: A Wayland compositor written in Haskell, providing a configurable and programmable window management system. This project implements the TinyWL reference compositor with Haskell bindings, allowing for dynamic configuration and control through Haskell.

Besides adding the key bindings support I restructured the project to make it easier to use. Now you can configure everything from the Config.hs file

This also is documented in the Readme.

Basic Usage

Default key bindings:

Mod + Left Click: Move window
Mod + Right Click: Resize window
Mod + Esc or Alt + C: Close server
Mod + s: Open new terminal (configurable, default: kitty)
Mod + d or Mod + v or Mod + F1: Cycle between windows

And of course all of these can be configured in Config.hs

Try it out

git clone --recurse-submodules https://github.com/l-Shane-l/tiny-wlhs.git
nix-shell  # Or use direnv: direnv allow
cabal run

Notes on the key bindings

I would have liked to use something like xkbcommon, however the bindings seem to be out of date(10 years i think) and the nix pkg broken. This is actually a nice project for anyone who was interested. It will likely be needed for any Wayland Haskell bindings.

Next steps

Window management is the next thing I want to address, some basic tiling would go a long way (for me at least) to start using this as a daily driver.

Beyond that I think multi-monitor support and integrating something like bemenu would be a real step forward, and must have features.

I’m pretty happy with the progress so far and I will likely post here next when I have something to show for the window management. :slightly_smiling_face:

7 Likes