Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.

License

Notifications You must be signed in to change notification settings

nishantjr/tiny-wlhs

 
 

Repository files navigation

TinyWL Haskell Implementation

Project Overview

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.

The app can be configured in Config.hs

Features

  • Wayland compositor functionality with wlroots backend
  • Configurable key bindings through Haskell
  • Window management (move, resize, focus)
  • Dynamic terminal spawning
  • Window cycling
  • Support for application spawners like bemenu
  • Support for notification daemons like mako
  • support for simple bars like yambar (more complex bars like waybar is not support yet)
  • Can be run from an X11 session or a TTY

More features coming, the intention is to get feature parity with something like sway

DEMO

Example usage

System Architecture

The system is organized in multiple layers, providing a clean separation between Haskell control logic and low-level Wayland functionality:

graph TB
    subgraph "Haskell Layer"
        A[Haskell Main]
        B[TinyWL Server]
        H[Keybinding Handler]
    end
    subgraph "Bindings Layer"
        C[wlhs - Wayland Haskell Bindings]
    end
    subgraph "C Layer"
        D[TinyWL C Server]
        I[Key Event Handler]
    end
    subgraph "System Layer"
        E[wlroots]
        F[Wayland Protocol]
        G[Linux Kernel / Display Server]
    end
    A -->|starts| B
    B -->|uses| C
    B -->|configures| H
    H <-->|callback| I
    B -->|FFI calls| D
    C -->|binds to| E
    D -->|uses| E
    D -->|dispatches to| I
    E -->|implements| F
    F -->|interacts with| G

    classDef haskell fill:#f9f,stroke:#333,stroke-width:2px;
    classDef c fill:#9cf,stroke:#333,stroke-width:2px;
    classDef system fill:#fcf,stroke:#333,stroke-width:2px;
    class A,B,H haskell;
    class C,D,I c;
    class E,F,G system;
Loading

Layer Description

  • Haskell Layer: High-level control and configuration
  • Bindings Layer: Wayland protocol bindings for Haskell
  • C Layer: Core compositor functionality
  • System Layer: System-level Wayland and display server interaction

Getting Started

Prerequisites

  • Nix package manager (for development environment)
  • Git (for source code management)

Installation

  1. Clone the repository with submodules:
git clone --recurse-submodules https://github.com/l-Shane-l/tiny-wlhs.git
  1. Set up the development environment:
nix-shell  # Or use direnv: direnv allow
  1. Build and run:
cabal run

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

Configuration

You can make all customizations in Config.hs

In appConfig you can set:

  • Log Level
  • Application to run on start
  • The Mod Key
  • Terminal Emulator
appConfig :: Config -- Customize your app here, to help I placed the options in the comments
appConfig =
    Config
        { logLevel = WLR_DEBUG -- WLR_INFO | WLR_DEBUG | WLR_SILENT | WLR_ERROR
        , startupApplication = "" -- can be any app that works with wayland, Leave blank for no startup app
        , modKey = ModAlt -- ModAlt | ModCtrl | ModLogo | ModShift
        , terminalEmulator = "kitty" -- I use kitty as my emulator, alacritty is also a popular choice
        }

You can also set up your own Key even listeners to do any of the following:

  • spawn any process you like
  • interact and control the compositor by calling FFI and Haskell functions in the LibTinyWLHS library
  • change current key bindings to your preference
customKeybindings :: Ptr WlDisplay -> Ptr TinyWLServer -> IO (FunPtr (CUInt -> IO ()))
customKeybindings display server = do
    let handler :: CUInt -> IO ()
        handler sym = do
            -- Add your custom key event handler heres
            wlr_log WLR_INFO $ "Handler called with sym: " ++ show sym -- This will long as an int and key pressed while the mod key is held down
            when (sym == keySymToInt KEY_s) $ do
                -- simple match to key events defined in LibTinyWL.KeyBinding.KeySyms
                wlr_log WLR_INFO "Mod + s pressed, spawning a terminal emulator"
                _ <- spawnProcess (terminalEmulator appConfig) [] -- for this key event a process is spawned in Haskell
                pure ()
            when (sym == keySymToInt KEY_c) $ do
                -- the key Events just show up here as ints so you can also match against a raw int
                wlr_log WLR_INFO "Mod + c pressed closing server"
                FFI.c_wl_display_terminate display -- for this event we call a Wayland FFI function
                pure ()
            when (sym == keySymToInt KEY_d || sym == keySymToInt KEY_v) $ do
                -- You can also use logical OR
                wlr_log WLR_INFO "Mod + d pressed, cycling windows"
                result <- FFI.c_cycle_windows server
                (if result then wlr_log WLR_INFO "window cycled" else wlr_log WLR_INFO "Window cycling failed, Only one window")

                pure ()
    mkKeybindingHandler handler

Development Status

See TODO.md for current development status and planned features.

Contributing

While the project is in early stages, contributions are welcome. See CONTRIBUTING.md for guidelines.

Known Issues

  • Some key combinations may not be available on certain system configurations
  • Tested primarily on Debian with xmonad; other configurations may need adjustment

License

This project is licensed under LICENSE

Contact

For questions or suggestions:

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 65.5%
  • Haskell 22.8%
  • Nix 10.8%
  • Other 0.9%